Title: [275407] trunk/Source/WebKit
Revision
275407
Author
[email protected]
Date
2021-04-02 01:07:28 -0700 (Fri, 02 Apr 2021)

Log Message

Pass the main frame URL to requestGeolocationAuthorizationForURL delegate SPI
https://bugs.webkit.org/show_bug.cgi?id=224045

Reviewed by Alex Christensen.

Simplify code path using requestGeolocationAuthorizationForURL SPI.
We store the URL in the GeolocationRequestData since it might change over time given the requests may be processed asynchronously.
Once geolocation access check is done, we then process each request one at a time using a Deque.
We pass the main frame URL instead of the URL of the frame that called the API, following getUserMedia and device motion orientation.
Manually tested in the simulator.

* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
Remove shouldRequestGeolocationAuthorizationForURL SPI that is not used.
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::decidePolicyForGeolocationPermissionRequest):
Remove unneeded origin creation.
* UIProcess/ios/WKGeolocationProviderIOS.mm:
(-[WKGeolocationProviderIOS decidePolicyForGeolocationRequestFromOrigin:completionHandler:view:]):
(-[WKGeolocationProviderIOS geolocationAuthorizationGranted]):
(-[WKGeolocationProviderIOS geolocationAuthorizationDenied]):
* UIProcess/ios/WKGeolocationProviderIOSObjCSecurityOrigin.mm:
(WebKit::decidePolicyForGeolocationRequestFromOrigin):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (275406 => 275407)


--- trunk/Source/WebKit/ChangeLog	2021-04-02 06:12:48 UTC (rev 275406)
+++ trunk/Source/WebKit/ChangeLog	2021-04-02 08:07:28 UTC (rev 275407)
@@ -1,3 +1,28 @@
+2021-04-02  Youenn Fablet  <[email protected]>
+
+        Pass the main frame URL to requestGeolocationAuthorizationForURL delegate SPI
+        https://bugs.webkit.org/show_bug.cgi?id=224045
+
+        Reviewed by Alex Christensen.
+
+        Simplify code path using requestGeolocationAuthorizationForURL SPI.
+        We store the URL in the GeolocationRequestData since it might change over time given the requests may be processed asynchronously.
+        Once geolocation access check is done, we then process each request one at a time using a Deque.
+        We pass the main frame URL instead of the URL of the frame that called the API, following getUserMedia and device motion orientation. 
+        Manually tested in the simulator.
+
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        Remove shouldRequestGeolocationAuthorizationForURL SPI that is not used.
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::decidePolicyForGeolocationPermissionRequest):
+        Remove unneeded origin creation.
+        * UIProcess/ios/WKGeolocationProviderIOS.mm:
+        (-[WKGeolocationProviderIOS decidePolicyForGeolocationRequestFromOrigin:completionHandler:view:]):
+        (-[WKGeolocationProviderIOS geolocationAuthorizationGranted]):
+        (-[WKGeolocationProviderIOS geolocationAuthorizationDenied]):
+        * UIProcess/ios/WKGeolocationProviderIOSObjCSecurityOrigin.mm:
+        (WebKit::decidePolicyForGeolocationRequestFromOrigin):
+
 2021-04-01  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r275387.

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (275406 => 275407)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2021-04-02 06:12:48 UTC (rev 275406)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2021-04-02 08:07:28 UTC (rev 275407)
@@ -162,7 +162,6 @@
 - (BOOL)_webView:(WKWebView *)webView shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element WK_API_AVAILABLE(ios(9.0));
 - (NSArray *)_webView:(WKWebView *)webView actionsForElement:(_WKActivatedElementInfo *)element defaultActions:(NSArray<_WKElementAction *> *)defaultActions;
 - (void)_webView:(WKWebView *)webView didNotHandleTapAsClickAtPoint:(CGPoint)point;
-- (BOOL)_webView:(WKWebView *)webView shouldRequestGeolocationAuthorizationForURL:(NSURL *)url isMainFrame:(BOOL)isMainFrame mainFrameURL:(NSURL *)mainFrameURL;
 - (void)_webView:(WKWebView *)webView requestGeolocationAuthorizationForURL:(NSURL *)url frame:(WKFrameInfo *)frame decisionHandler:(void (^)(BOOL authorized))decisionHandler WK_API_AVAILABLE(ios(11.0));
 - (BOOL)_webView:(WKWebView *)webView fileUploadPanelContentIsManagedWithInitiatingFrame:(WKFrameInfo *)frame;
 

Modified: trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm (275406 => 275407)


--- trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2021-04-02 06:12:48 UTC (rev 275406)
+++ trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm	2021-04-02 08:07:28 UTC (rev 275407)
@@ -238,7 +238,6 @@
 
 void PageClientImpl::decidePolicyForGeolocationPermissionRequest(WebFrameProxy& frame, const FrameInfoData& frameInfo, Function<void(bool)>& completionHandler)
 {
-    auto origin = API::SecurityOrigin::create(frameInfo.securityOrigin.protocol, frameInfo.securityOrigin.host, frameInfo.securityOrigin.port);
     [[wrapper(m_webView.get()->_page->process().processPool()) _geolocationProvider] decidePolicyForGeolocationRequestFromOrigin:FrameInfoData { frameInfo } completionHandler:std::exchange(completionHandler, nullptr) view:m_webView.get().get()];
 }
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKGeolocationProviderIOS.mm (275406 => 275407)


--- trunk/Source/WebKit/UIProcess/ios/WKGeolocationProviderIOS.mm	2021-04-02 06:12:48 UTC (rev 275406)
+++ trunk/Source/WebKit/UIProcess/ios/WKGeolocationProviderIOS.mm	2021-04-02 08:07:28 UTC (rev 275407)
@@ -68,10 +68,11 @@
 @end
 
 namespace WebKit {
-void decidePolicyForGeolocationRequestFromOrigin(WebCore::SecurityOrigin*, const URL&, id<WebAllowDenyPolicyListener>, UIView*);
+void decidePolicyForGeolocationRequestFromOrigin(WebCore::SecurityOrigin&, const URL&, id<WebAllowDenyPolicyListener>, UIView*);
 };
 
 struct GeolocationRequestData {
+    URL url;
     WebKit::FrameInfoData frameInfo;
     Function<void(bool)> completionHandler;
     RetainPtr<WKWebView> view;
@@ -82,7 +83,7 @@
     RetainPtr<id <_WKGeolocationCoreLocationProvider>> _coreLocationProvider;
     BOOL _isWebCoreGeolocationActive;
     RefPtr<WebKit::WebGeolocationPosition> _lastActivePosition;
-    Vector<GeolocationRequestData> _requestsWaitingForCoreLocationAuthorization;
+    Deque<GeolocationRequestData> _requestsWaitingForCoreLocationAuthorization;
 }
 
 #pragma mark - WKGeolocationProvider callbacks implementation.
@@ -161,10 +162,7 @@
 - (void)decidePolicyForGeolocationRequestFromOrigin:(WebKit::FrameInfoData&&)frameInfo completionHandler:(Function<void(bool)>&&)completionHandler view:(WKWebView *)contentView
 {
     // Step 1: ask the user if the app can use Geolocation.
-    GeolocationRequestData geolocationRequestData;
-    geolocationRequestData.frameInfo = WTFMove(frameInfo);
-    geolocationRequestData.completionHandler = WTFMove(completionHandler);
-    geolocationRequestData.view = contentView;
+    GeolocationRequestData geolocationRequestData { [contentView URL], WTFMove(frameInfo), WTFMove(completionHandler), contentView };
     _requestsWaitingForCoreLocationAuthorization.append(WTFMove(geolocationRequestData));
     [_coreLocationProvider requestGeolocationAuthorization];
 }
@@ -176,47 +174,36 @@
 
 - (void)geolocationAuthorizationGranted
 {
-    // Step 2: ask the user if the this particular page can use gelocation.
-    Vector<GeolocationRequestData> requests = WTFMove(_requestsWaitingForCoreLocationAuthorization);
-    for (auto& request : requests) {
-        bool requiresUserAuthorization = true;
+    // Step 2: ask the user if this particular page can use gelocation.
+    if (_requestsWaitingForCoreLocationAuthorization.isEmpty())
+        return;
 
-        id<WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([request.view UIDelegate]);
-        if ([uiDelegate respondsToSelector:@selector(_webView:requestGeolocationAuthorizationForURL:frame:decisionHandler:)]) {
-            URL requestFrameURL = request.frameInfo.request.url();
-            RetainPtr<WKFrameInfo> frameInfo = wrapper(API::FrameInfo::create(WTFMove(request.frameInfo), request.view->_page.get()));
-            auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector(_webView:requestGeolocationAuthorizationForURL:frame:decisionHandler:));
-            WKWebView *viewFromRequest = request.view.get();
-            [uiDelegate _webView:viewFromRequest requestGeolocationAuthorizationForURL:requestFrameURL frame:frameInfo.get() decisionHandler:makeBlockPtr([request = WTFMove(request), checker = WTFMove(checker)](BOOL authorized) {
-                if (checker->completionHandlerHasBeenCalled())
-                    return;
-                checker->didCallCompletionHandler();
-                request.completionHandler(authorized);
-            }).get()];
-            return;
-        }
+    auto request = _requestsWaitingForCoreLocationAuthorization.takeFirst();
+    Function<void(bool)> decisionHandler = [completionHandler = WTFMove(request.completionHandler), protectedSelf = retainPtr(self)](bool result) {
+        completionHandler(result);
+        [protectedSelf geolocationAuthorizationGranted];
+    };
 
-        if ([uiDelegate respondsToSelector:@selector(_webView:shouldRequestGeolocationAuthorizationForURL:isMainFrame:mainFrameURL:)]) {
-            bool isMainFrame = request.frameInfo.isMainFrame;
-            URL requestFrameURL = request.frameInfo.request.url();
-            URL mainFrameURL = request.view.get().URL;
-            requiresUserAuthorization = [uiDelegate _webView:request.view.get()
-                 shouldRequestGeolocationAuthorizationForURL:requestFrameURL
-                                                 isMainFrame:isMainFrame
-                                                mainFrameURL:mainFrameURL];
-        }
+    id<WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([request.view UIDelegate]);
+    if ([uiDelegate respondsToSelector:@selector(_webView:requestGeolocationAuthorizationForURL:frame:decisionHandler:)]) {
+        RetainPtr<WKFrameInfo> frameInfo = wrapper(API::FrameInfo::create(WTFMove(request.frameInfo), request.view->_page.get()));
+        auto checker = WebKit::CompletionHandlerCallChecker::create(uiDelegate, @selector(_webView:requestGeolocationAuthorizationForURL:frame:decisionHandler:));
+        [uiDelegate _webView:request.view.get() requestGeolocationAuthorizationForURL:request.url frame:frameInfo.get() decisionHandler:makeBlockPtr([decisionHandler = WTFMove(decisionHandler), checker = WTFMove(checker)](BOOL authorized) {
+            if (checker->completionHandlerHasBeenCalled())
+                return;
+            checker->didCallCompletionHandler();
+            decisionHandler(!!authorized);
+        }).get()];
+        return;
+    }
 
-        if (requiresUserAuthorization) {
-            RetainPtr<WKWebAllowDenyPolicyListener> policyListener = adoptNS([[WKWebAllowDenyPolicyListener alloc] initWithCompletionHandler:WTFMove(request.completionHandler)]);
-            WebKit::decidePolicyForGeolocationRequestFromOrigin(request.frameInfo.securityOrigin.securityOrigin().ptr(), request.frameInfo.request.url(), policyListener.get(), request.view.get());
-        } else
-            request.completionHandler(true);
-    }
+    auto policyListener = adoptNS([[WKWebAllowDenyPolicyListener alloc] initWithCompletionHandler:WTFMove(request.completionHandler)]);
+    WebKit::decidePolicyForGeolocationRequestFromOrigin(WebCore::SecurityOrigin::create(request.url).get(), request.url, policyListener.get(), request.view.get());
 }
 
 - (void)geolocationAuthorizationDenied
 {
-    Vector<GeolocationRequestData> requests = WTFMove(_requestsWaitingForCoreLocationAuthorization);
+    auto requests = WTFMove(_requestsWaitingForCoreLocationAuthorization);
     for (const auto& requestData : requests)
         requestData.completionHandler(false);
 }

Modified: trunk/Source/WebKit/UIProcess/ios/WKGeolocationProviderIOSObjCSecurityOrigin.mm (275406 => 275407)


--- trunk/Source/WebKit/UIProcess/ios/WKGeolocationProviderIOSObjCSecurityOrigin.mm	2021-04-02 06:12:48 UTC (rev 275406)
+++ trunk/Source/WebKit/UIProcess/ios/WKGeolocationProviderIOSObjCSecurityOrigin.mm	2021-04-02 08:07:28 UTC (rev 275407)
@@ -44,11 +44,11 @@
 
 namespace WebKit {
 
-void decidePolicyForGeolocationRequestFromOrigin(WebCore::SecurityOrigin*, const URL&, id<WebAllowDenyPolicyListener>, UIView *);
+void decidePolicyForGeolocationRequestFromOrigin(WebCore::SecurityOrigin&, const URL&, id<WebAllowDenyPolicyListener>, UIView *);
 
-void decidePolicyForGeolocationRequestFromOrigin(WebCore::SecurityOrigin* origin, const URL& url, id<WebAllowDenyPolicyListener> listener, UIView *view)
+void decidePolicyForGeolocationRequestFromOrigin(WebCore::SecurityOrigin& origin, const URL& url, id<WebAllowDenyPolicyListener> listener, UIView *view)
 {
-    RetainPtr<WebSecurityOrigin> securityOrigin = adoptNS([[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:origin]);
+    auto securityOrigin = adoptNS([[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:&origin]);
     RetainPtr<UIWebGeolocationPolicyDecider> decider = [UIWebGeolocationPolicyDecider sharedPolicyDecider];
     if ([decider respondsToSelector:@selector(decidePolicyForGeolocationRequestFromOrigin:requestingURL:view:listener:)])
         [decider decidePolicyForGeolocationRequestFromOrigin:securityOrigin.get() requestingURL:url view:view listener:listener];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to