Source/WebKit:
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Jul 2019 00:44:58 +0000 (00:44 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Jul 2019 00:44:58 +0000 (00:44 +0000)
Allow Clients to Add Fields to the AutoFillContext Dictionary
https://bugs.webkit.org/show_bug.cgi?id=199326
rdar://problem/42816957

Patch by Priyanka Agarwal <pagarwal999@apple.com> on 2019-07-24
Reviewed by Wenson Hsieh.

* UIProcess/API/Cocoa/_WKInputDelegate.h:
Added function declaration for function which returns additional dictionary for autofillcontext

* UIProcess/ios/WKContentViewInteraction.h:
Created dictionary for additional autofillcontext

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]):
Populating additional dictionary for autofillcontext

(-[WKContentView _autofillContext]):
Adding new dictionary to the returned autofillcontext

Tools:
Allow Clients to Add Fields to the AutoFillContext Dictionary.
https://bugs.webkit.org/show_bug.cgi?id=199326
rdar://problem/42816957

Patch by Priyanka Agarwal <pagarwal999@apple.com> on 2019-07-24
Reviewed by Wenson Hsieh.

* TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
(TestWebKitAPI::TEST): Created a test to check that the auto fill context
is being properly populated with additional context dictionary.

* TestWebKitAPI/Tests/ios/TestInputDelegate.h:
* TestWebKitAPI/Tests/ios/TestInputDelegate.mm:
(-[TestInputDelegate setWebViewAdditionalContextForStrongPasswordAssistanceHandler:]): Setting the handler for the function
which will populate the additional autofill context dictionary.

(-[TestInputDelegate webViewAdditionalContextForStrongPasswordAssistanceHandler]): Returns the handler for the function which
populates the additional autofill context dictionary.

(-[TestInputDelegate _webViewAdditionalContextForStrongPasswordAssistance:]): Function which populates the additional autofill
context dictionary.

(-[TestInputDelegate setFocusRequiresStrongPasswordAssistanceHandler:]): Setting the handler for the function which checks if the
input field requires strong password work.

(-[TestInputDelegate focusRequiresStrongPasswordAssistanceHandler]): Returns the handler for the function which checks if the
input field requires strong password work.

(-[TestInputDelegate _webView:focusRequiresStrongPasswordAssistance:]): Function which checks if the input field requires strong
password work.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247804 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/_WKInputDelegate.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm
Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h
Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm

index 0c0ed61..b019ea6 100644 (file)
@@ -1,3 +1,24 @@
+2019-07-24  Priyanka Agarwal  <pagarwal999@apple.com>
+
+        Allow Clients to Add Fields to the AutoFillContext Dictionary
+        https://bugs.webkit.org/show_bug.cgi?id=199326
+        rdar://problem/42816957
+
+        Reviewed by Wenson Hsieh.
+
+        * UIProcess/API/Cocoa/_WKInputDelegate.h:
+        Added function declaration for function which returns additional dictionary for autofillcontext
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        Created dictionary for additional autofillcontext
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]):
+        Populating additional dictionary for autofillcontext
+
+        (-[WKContentView _autofillContext]):
+        Adding new dictionary to the returned autofillcontext
+
 2019-07-24  Chris Dumez  <cdumez@apple.com>
 
         Regression(r247400): Unable to log into AIB Mobile Banking App
index 1665279..1d3044e 100644 (file)
@@ -55,6 +55,8 @@ typedef NS_ENUM(NSInteger, _WKFocusStartsInputSessionPolicy) {
 - (void)_webView:(WKWebView *)webView willStartInputSession:(id <_WKFormInputSession>)inputSession WK_API_AVAILABLE(ios(12.0));
 - (BOOL)_webView:(WKWebView *)webView focusRequiresStrongPasswordAssistance:(id <_WKFocusedElementInfo>)info WK_API_AVAILABLE(ios(12.0));
 
+- (NSDictionary<id, NSString *> *)_webViewAdditionalContextForStrongPasswordAssistance:(WKWebView *)webView WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
 - (BOOL)_webView:(WKWebView *)webView shouldRevealFocusOverlayForInputSession:(id <_WKFormInputSession>)inputSession WK_API_AVAILABLE(ios(12.0));
 - (CGFloat)_webView:(WKWebView *)webView focusedElementContextViewHeightForFittingSize:(CGSize)fittingSize inputSession:(id <_WKFormInputSession>)inputSession WK_API_AVAILABLE(ios(12.0));
 - (UIView *)_webView:(WKWebView *)webView focusedElementContextViewForInputSession:(id <_WKFormInputSession>)inputSession WK_API_AVAILABLE(ios(12.0));
index fd8ae9e..1b91b81 100644 (file)
@@ -356,6 +356,8 @@ struct WKAutoCorrectionData {
     CompletionHandler<void(WebCore::DOMPasteAccessResponse)> _domPasteRequestHandler;
     BlockPtr<void(UIWKAutocorrectionContext *)> _pendingAutocorrectionContextHandler;
 
+    RetainPtr<NSDictionary> _additionalContextForStrongPasswordAssistance;
+
 #if ENABLE(DATA_INTERACTION)
     WebKit::DragDropInteractionState _dragDropInteractionState;
     RetainPtr<UIDragInteraction> _dragInteraction;
index 9f55128..675af7b 100644 (file)
@@ -849,6 +849,7 @@ static inline bool hasFocusedElement(WebKit::FocusedElementInformation focusedEl
     _outstandingPositionInformationRequest = WTF::nullopt;
 
     _focusRequiresStrongPasswordAssistance = NO;
+    _additionalContextForStrongPasswordAssistance = nil;
     _waitingForEditDragSnapshot = NO;
 
 #if USE(UIKIT_KEYBOARD_ADDITIONS)
@@ -5313,9 +5314,15 @@ static RetainPtr<NSObject <WKFormPeripheral>> createInputPeripheralWithView(WebK
     [_webView _resetFocusPreservationCount];
 
     _focusRequiresStrongPasswordAssistance = NO;
+    _additionalContextForStrongPasswordAssistance = nil;
     if ([inputDelegate respondsToSelector:@selector(_webView:focusRequiresStrongPasswordAssistance:)])
         _focusRequiresStrongPasswordAssistance = [inputDelegate _webView:_webView focusRequiresStrongPasswordAssistance:focusedElementInfo.get()];
 
+    if ([inputDelegate respondsToSelector:@selector(_webViewAdditionalContextForStrongPasswordAssistance:)])
+        _additionalContextForStrongPasswordAssistance = [inputDelegate _webViewAdditionalContextForStrongPasswordAssistance:_webView];
+    else
+        _additionalContextForStrongPasswordAssistance = @{ };
+
     bool delegateImplementsWillStartInputSession = [inputDelegate respondsToSelector:@selector(_webView:willStartInputSession:)];
     bool delegateImplementsDidStartInputSession = [inputDelegate respondsToSelector:@selector(_webView:didStartInputSession:)];
 
@@ -5403,6 +5410,7 @@ static RetainPtr<NSObject <WKFormPeripheral>> createInputPeripheralWithView(WebK
     _focusedElementInformation.shouldAvoidScrollingWhenFocusedContentIsVisible = false;
     _inputPeripheral = nil;
     _focusRequiresStrongPasswordAssistance = NO;
+    _additionalContextForStrongPasswordAssistance = nil;
 
 #if USE(UIKIT_KEYBOARD_ADDITIONS)
     // When defocusing an editable element reset a seen keydown before calling -_hideKeyboard so that we
@@ -6777,7 +6785,7 @@ static NSArray<NSItemProvider *> *extractItemProvidersFromDropSession(id <UIDrop
         return nil;
 
     if (provideStrongPasswordAssistance)
-        return @{ @"_automaticPasswordKeyboard" : @YES };
+        return @{ @"_automaticPasswordKeyboard" : @YES, @"strongPasswordAdditionalContext" : _additionalContextForStrongPasswordAssistance.get() };
 
     NSURL *platformURL = _focusedElementInformation.representingPageURL;
     if (platformURL)
index 68a9bc5..3fea230 100644 (file)
@@ -1,3 +1,35 @@
+2019-07-24  Priyanka Agarwal  <pagarwal999@apple.com>
+
+        Allow Clients to Add Fields to the AutoFillContext Dictionary.
+        https://bugs.webkit.org/show_bug.cgi?id=199326
+        rdar://problem/42816957
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
+        (TestWebKitAPI::TEST): Created a test to check that the auto fill context
+        is being properly populated with additional context dictionary.
+
+        * TestWebKitAPI/Tests/ios/TestInputDelegate.h:
+        * TestWebKitAPI/Tests/ios/TestInputDelegate.mm:
+        (-[TestInputDelegate setWebViewAdditionalContextForStrongPasswordAssistanceHandler:]): Setting the handler for the function
+        which will populate the additional autofill context dictionary.
+
+        (-[TestInputDelegate webViewAdditionalContextForStrongPasswordAssistanceHandler]): Returns the handler for the function which
+        populates the additional autofill context dictionary.
+
+        (-[TestInputDelegate _webViewAdditionalContextForStrongPasswordAssistance:]): Function which populates the additional autofill
+        context dictionary.
+
+        (-[TestInputDelegate setFocusRequiresStrongPasswordAssistanceHandler:]): Setting the handler for the function which checks if the 
+        input field requires strong password work.
+
+        (-[TestInputDelegate focusRequiresStrongPasswordAssistanceHandler]): Returns the handler for the function which checks if the
+        input field requires strong password work.
+
+        (-[TestInputDelegate _webView:focusRequiresStrongPasswordAssistance:]): Function which checks if the input field requires strong
+        password work.
+
 2019-07-24  Zhifei Fang  <zhifei_fang@apple.com>
 
         run-javascriptcore-tests won't report test results for testmasm, testair, testb3, testdfg and test api
index 256182d..b53ff28 100644 (file)
@@ -527,6 +527,34 @@ TEST(KeyboardInputTests, SelectionClipRectsWhenPresentingInputView)
     EXPECT_EQ(20, selectionClipRect.size.height);
 }
 
+TEST(KeyboardInputTests, TestWebViewAdditionalContextForStrongPasswordAssistance)
+{
+    NSDictionary *expected = @{ @"strongPasswordAdditionalContext" : @"testUUID" };
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
+
+    [inputDelegate setFocusStartsInputSessionPolicyHandler:[&] (WKWebView *, id <_WKFocusedElementInfo>) -> _WKFocusStartsInputSessionPolicy {
+        return _WKFocusStartsInputSessionPolicyAllow;
+    }];
+
+    [inputDelegate setWebViewAdditionalContextForStrongPasswordAssistanceHandler:[&] (WKWebView *) {
+        return expected;
+    }];
+
+    [inputDelegate setFocusRequiresStrongPasswordAssistanceHandler:[&] (WKWebView *, id <_WKFocusedElementInfo>) {
+        return YES;
+    }];
+
+    [webView _setInputDelegate:inputDelegate.get()];
+
+    [webView synchronouslyLoadHTMLString:@"<input type='password' id='input'>"];
+    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.getElementById('input').focus()"];
+
+    NSDictionary *actual = [[webView textInputContentView] _autofillContext];
+    EXPECT_TRUE([[actual allValues] containsObject:expected]);
+}
+
 } // namespace TestWebKitAPI
 
 #endif // PLATFORM(IOS_FAMILY)
index 366a42a..b288237 100644 (file)
@@ -37,6 +37,8 @@
 @property (nonatomic, copy) _WKFocusStartsInputSessionPolicy (^focusStartsInputSessionPolicyHandler)(WKWebView *, id <_WKFocusedElementInfo>);
 @property (nonatomic, copy) void (^willStartInputSessionHandler)(WKWebView *, id <_WKFormInputSession>);
 @property (nonatomic, copy) void (^didStartInputSessionHandler)(WKWebView *, id <_WKFormInputSession>);
+@property (nonatomic, copy) NSDictionary<id, NSString *> * (^webViewAdditionalContextForStrongPasswordAssistanceHandler)(WKWebView *);
+@property (nonatomic, copy) BOOL (^focusRequiresStrongPasswordAssistanceHandler)(WKWebView *, id <_WKFocusedElementInfo>);
 @end
 
 #endif
index 5ef4dd2..0b5a31d 100644 (file)
@@ -34,6 +34,8 @@
     BlockPtr<_WKFocusStartsInputSessionPolicy(WKWebView *, id <_WKFocusedElementInfo>)> _focusStartsInputSessionPolicyHandler;
     BlockPtr<void(WKWebView *, id <_WKFormInputSession>)> _willStartInputSessionHandler;
     BlockPtr<void(WKWebView *, id <_WKFormInputSession>)> _didStartInputSessionHandler;
+    BlockPtr<NSDictionary<id, NSString *> *(WKWebView *)> _webViewAdditionalContextForStrongPasswordAssistanceHandler;
+    BlockPtr<BOOL(WKWebView *, id <_WKFocusedElementInfo>)> _focusRequiresStrongPasswordAssistanceHandler;
 }
 
 - (void)setFocusStartsInputSessionPolicyHandler:(_WKFocusStartsInputSessionPolicy (^)(WKWebView *, id <_WKFocusedElementInfo>))handler
         _didStartInputSessionHandler(webView, inputSession);
 }
 
+- (void)setWebViewAdditionalContextForStrongPasswordAssistanceHandler:(NSDictionary<id, NSString *> * (^)(WKWebView *))webViewAdditionalContextForStrongPasswordAssistanceHandler
+{
+    _webViewAdditionalContextForStrongPasswordAssistanceHandler = makeBlockPtr(webViewAdditionalContextForStrongPasswordAssistanceHandler);
+}
+
+- (NSDictionary<id, NSString *> * (^)(WKWebView *))webViewAdditionalContextForStrongPasswordAssistanceHandler
+{
+    return _webViewAdditionalContextForStrongPasswordAssistanceHandler.get();
+}
+
+- (NSDictionary<id, NSString *> *)_webViewAdditionalContextForStrongPasswordAssistance:(WKWebView *)webView
+{
+    if (_webViewAdditionalContextForStrongPasswordAssistanceHandler)
+        return _webViewAdditionalContextForStrongPasswordAssistanceHandler(webView);
+    return @{ };
+}
+
+- (void)setFocusRequiresStrongPasswordAssistanceHandler:(BOOL (^)(WKWebView *, id <_WKFocusedElementInfo>))handler
+{
+    _focusRequiresStrongPasswordAssistanceHandler = makeBlockPtr(handler);
+}
+
+- (BOOL (^)(WKWebView *, id <_WKFocusedElementInfo>))focusRequiresStrongPasswordAssistanceHandler
+{
+    return _focusRequiresStrongPasswordAssistanceHandler.get();
+}
+
+- (BOOL)_webView:(WKWebView *)webView focusRequiresStrongPasswordAssistance:(id <_WKFocusedElementInfo>)info
+{
+    if (_focusRequiresStrongPasswordAssistanceHandler)
+        return _focusRequiresStrongPasswordAssistanceHandler(webView, info);
+    return NO;
+}
+
 @end
 
 #endif // PLATFORM(IOS_FAMILY)