Modified: trunk/Source/WebCore/ChangeLog (272447 => 272448)
--- trunk/Source/WebCore/ChangeLog 2021-02-05 23:26:15 UTC (rev 272447)
+++ trunk/Source/WebCore/ChangeLog 2021-02-05 23:32:39 UTC (rev 272448)
@@ -1,3 +1,24 @@
+2021-02-05 Ricky Mondello <[email protected]>
+
+ Allow Password AutoFill in more text field configurations
+
+ https://bugs.webkit.org/show_bug.cgi?id=221429
+ rdar://problem/73899947
+
+ Reviewed by Wenson Hsieh.
+
+ Extend where we'll offer Password AutoFill in web views. Allow all type=password fields. Allow in situations
+ with back-to-back type=password fields, but only attempt to fill the second password field when it's empty,
+ to flexibly accomodate account creation and password change scenarios.
+
+ I did a round of manual testing with the related existing OS feature.
+
+ * editing/cocoa/AutofillElements.cpp:
+ (WebCore::AutofillElements::AutofillElements): Add secondPassword to initializer.
+ (WebCore::AutofillElements::computeAutofillElements): Change the algorithm as described above.
+ (WebCore::AutofillElements::autofill): Also fill the secondPassword, if applicable.
+ * editing/cocoa/AutofillElements.h: Change constructor and add member variable.
+
2021-02-05 Eric Carlson <[email protected]>
[Mac] Connect MediaSession with MediaRemote and NowPlaying
Modified: trunk/Source/WebCore/editing/cocoa/AutofillElements.cpp (272447 => 272448)
--- trunk/Source/WebCore/editing/cocoa/AutofillElements.cpp 2021-02-05 23:26:15 UTC (rev 272447)
+++ trunk/Source/WebCore/editing/cocoa/AutofillElements.cpp 2021-02-05 23:32:39 UTC (rev 272448)
@@ -72,9 +72,10 @@
return &downcast<HTMLInputElement>(*previousElement);
}
-AutofillElements::AutofillElements(RefPtr<HTMLInputElement>&& username, RefPtr<HTMLInputElement>&& password)
+AutofillElements::AutofillElements(RefPtr<HTMLInputElement>&& username, RefPtr<HTMLInputElement>&& password, RefPtr<HTMLInputElement>&& secondPassword)
: m_username(username)
, m_password(password)
+ , m_secondPassword(secondPassword)
{
}
@@ -84,36 +85,26 @@
return WTF::nullopt;
FocusController& focusController = start->document().page()->focusController();
if (start->isPasswordField()) {
- RefPtr<HTMLInputElement> previousElement = previousAutofillableElement(start.ptr(), focusController);
- RefPtr<HTMLInputElement> nextElement = nextAutofillableElement(start.ptr(), focusController);
- bool hasDuplicatePasswordElements = (nextElement && nextElement->isPasswordField()) || (previousElement && previousElement->isPasswordField());
- if (hasDuplicatePasswordElements)
- return WTF::nullopt;
+ auto previousElement = previousAutofillableElement(start.ptr(), focusController);
+ auto nextElement = nextAutofillableElement(start.ptr(), focusController);
- if (previousElement && is<HTMLInputElement>(*previousElement)) {
- if (previousElement->isTextField())
- return AutofillElements(WTFMove(previousElement), WTFMove(start));
- }
+ bool previousFieldIsTextField = previousElement && !previousElement->isPasswordField();
+ bool hasSecondPasswordFieldToFill = nextElement && nextElement->isPasswordField() && nextElement->value().isEmpty();
+
+ // Always allow AutoFill in a password field, even if we fill information only into it.
+ return {{ previousFieldIsTextField ? WTFMove(previousElement) : nullptr, WTFMove(start), hasSecondPasswordFieldToFill ? WTFMove(nextElement) : nullptr }};
} else {
RefPtr<HTMLInputElement> nextElement = nextAutofillableElement(start.ptr(), focusController);
if (nextElement && is<HTMLInputElement>(*nextElement)) {
if (nextElement->isPasswordField()) {
- RefPtr<HTMLInputElement> elementAfternextElement = nextAutofillableElement(nextElement.get(), focusController);
- bool hasDuplicatePasswordElements = elementAfternextElement && elementAfternextElement->isPasswordField();
- if (hasDuplicatePasswordElements)
- return WTF::nullopt;
+ auto elementAfterNextElement = nextAutofillableElement(nextElement.get(), focusController);
+ bool hasSecondPasswordFieldToFill = elementAfterNextElement && elementAfterNextElement->isPasswordField() && elementAfterNextElement->value().isEmpty();
- return AutofillElements(WTFMove(start), WTFMove(nextElement));
+ return {{ WTFMove(start), WTFMove(nextElement), hasSecondPasswordFieldToFill ? WTFMove(elementAfterNextElement) : nullptr }};
}
}
}
- if (start->isPasswordField()) {
- RefPtr<HTMLInputElement> previousElement = previousAutofillableElement(start.ptr(), focusController);
- RefPtr<HTMLInputElement> nextElement = nextAutofillableElement(start.ptr(), focusController);
- if (!previousElement && !nextElement)
- return AutofillElements(nullptr, start.ptr());
- }
return WTF::nullopt;
}
@@ -123,6 +114,8 @@
m_username->setValueForUser(username);
if (m_password)
m_password->setValueForUser(password);
+ if (m_secondPassword)
+ m_secondPassword->setValueForUser(password);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/editing/cocoa/AutofillElements.h (272447 => 272448)
--- trunk/Source/WebCore/editing/cocoa/AutofillElements.h 2021-02-05 23:26:15 UTC (rev 272447)
+++ trunk/Source/WebCore/editing/cocoa/AutofillElements.h 2021-02-05 23:32:39 UTC (rev 272448)
@@ -37,9 +37,10 @@
const HTMLInputElement* username() const { return m_username.get(); }
private:
- AutofillElements(RefPtr<HTMLInputElement>&&, RefPtr<HTMLInputElement>&&);
+ AutofillElements(RefPtr<HTMLInputElement>&&, RefPtr<HTMLInputElement>&&, RefPtr<HTMLInputElement>&&);
RefPtr<HTMLInputElement> m_username;
RefPtr<HTMLInputElement> m_password;
+ RefPtr<HTMLInputElement> m_secondPassword;
};
} // namespace WebCore
Modified: trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm (272447 => 272448)
--- trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm 2021-02-05 23:26:15 UTC (rev 272447)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewAutofillTests.mm 2021-02-05 23:32:39 UTC (rev 272448)
@@ -159,13 +159,13 @@
auto webView = adoptNS([[AutoFillTestView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
[webView synchronouslyLoadHTMLString:@"<input id='user' type='email'><input id='password' type='password'><input id='confirm_password' type='password'>"];
[webView evaluateJavaScriptAndWaitForInputSessionToChange:@"user.focus()"];
- EXPECT_FALSE([webView textInputHasAutoFillContext]);
+ EXPECT_TRUE([webView textInputHasAutoFillContext]);
[webView evaluateJavaScriptAndWaitForInputSessionToChange:@"password.focus()"];
- EXPECT_FALSE([webView textInputHasAutoFillContext]);
+ EXPECT_TRUE([webView textInputHasAutoFillContext]);
[webView evaluateJavaScriptAndWaitForInputSessionToChange:@"confirm_password.focus()"];
- EXPECT_FALSE([webView textInputHasAutoFillContext]);
+ EXPECT_TRUE([webView textInputHasAutoFillContext]);
}
static BOOL overrideIsInHardwareKeyboardMode()