Changeset 221873 in webkit
- Timestamp:
- Sep 11, 2017 1:45:26 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r221870 r221873 1 2017-09-11 Alex Christensen <achristensen@webkit.org> 2 3 Add WKUIDelegatePrivate equivalent of WKPageUIClient's decidePolicyForGeolocationPermissionRequest 4 https://bugs.webkit.org/show_bug.cgi?id=176642 5 <rdar://problem/29270035> 6 7 Reviewed by Darin Adler. 8 9 * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: 10 * UIProcess/Cocoa/UIDelegate.h: 11 * UIProcess/Cocoa/UIDelegate.mm: 12 (WebKit::UIDelegate::setDelegate): 13 (WebKit::UIDelegate::UIClient::runJavaScriptPrompt): 14 (WebKit::Function<void): 15 1 16 2017-09-11 Wenson Hsieh <wenson_hsieh@apple.com> 2 17 -
trunk/Source/WebKit/UIProcess/API/APIUIClient.h
r221787 r221873 127 127 128 128 virtual bool runOpenPanel(WebKit::WebPageProxy*, WebKit::WebFrameProxy*, const WebCore::SecurityOriginData&, OpenPanelParameters*, WebKit::WebOpenPanelResultListenerProxy*) { return false; } 129 virtual Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, Function<void(bool)>&& completionHandler) { return WTFMove(completionHandler);}129 virtual void decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, Function<void(bool)>&) { } 130 130 virtual bool decidePolicyForUserMediaPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, SecurityOrigin&, WebKit::UserMediaPermissionRequestProxy&) { return false; } 131 131 virtual bool checkUserMediaPermissionForOrigin(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, SecurityOrigin&, WebKit::UserMediaPermissionCheckProxy&) { return false; } -
trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp
r221787 r221873 1954 1954 } 1955 1955 1956 Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>&& completionHandler) final1956 void decidePolicyForGeolocationPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>& completionHandler) final 1957 1957 { 1958 1958 if (!m_client.decidePolicyForGeolocationPermissionRequest) 1959 return WTFMove(completionHandler); 1960 1961 m_client.decidePolicyForGeolocationPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&origin), toAPI(GeolocationPermissionRequest::create(WTFMove(completionHandler)).ptr()), m_client.base.clientInfo); 1962 return nullptr; 1959 return; 1960 1961 m_client.decidePolicyForGeolocationPermissionRequest(toAPI(&page), toAPI(&frame), toAPI(&origin), toAPI(GeolocationPermissionRequest::create(std::exchange(completionHandler, nullptr)).ptr()), m_client.base.clientInfo); 1963 1962 } 1964 1963 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
r221714 r221873 106 106 - (WKDragDestinationAction)_webView:(WKWebView *)webView dragDestinationActionMaskForDraggingInfo:(id)draggingInfo WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 107 107 - (void)_webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures completionHandler:(void (^)(WKWebView *webView))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 108 - (void)_webView:(WKWebView *)webView requestGeolocationPermissionForFrame:(WKFrameInfo *)frame decisionHandler:(void (^)(BOOL allowed))decisionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 108 109 109 110 - (void)_webView:(WKWebView *)webView runBeforeUnloadConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); -
trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp
r221787 r221873 183 183 } 184 184 185 Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&& completionHandler) final186 { 187 GRefPtr<WebKitGeolocationPermissionRequest> geolocationPermissionRequest = adoptGRef(webkitGeolocationPermissionRequestCreate(GeolocationPermissionRequest::create( WTFMove(completionHandler)).ptr()));185 void decidePolicyForGeolocationPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>& completionHandler) final 186 { 187 GRefPtr<WebKitGeolocationPermissionRequest> geolocationPermissionRequest = adoptGRef(webkitGeolocationPermissionRequestCreate(GeolocationPermissionRequest::create(std::exchange(completionHandler, nullptr)).ptr())); 188 188 webkitWebViewMakePermissionRequest(m_webView, WEBKIT_PERMISSION_REQUEST(geolocationPermissionRequest.get())); 189 return nullptr;190 189 } 191 190 -
trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h
r221787 r221873 91 91 void runJavaScriptAlert(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void()>&& completionHandler) final; 92 92 void runJavaScriptConfirm(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(bool)>&& completionHandler) final; 93 void runJavaScriptPrompt(WebPageProxy*, const WTF::String&, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(const WTF::String&)>&& completionHandler) final; 93 void runJavaScriptPrompt(WebPageProxy*, const WTF::String&, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(const WTF::String&)>&&) final; 94 void decidePolicyForGeolocationPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&) final; 94 95 bool canRunBeforeUnloadConfirmPanel() const final; 95 96 void runBeforeUnloadConfirmPanel(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(bool)>&& completionHandler) final; … … 104 105 void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&) final; 105 106 void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final; 106 void unavailablePluginButtonClicked(Web Kit::WebPageProxy&, WKPluginUnavailabilityReason, API::Dictionary&) final;107 void unavailablePluginButtonClicked(WebPageProxy&, WKPluginUnavailabilityReason, API::Dictionary&) final; 107 108 void mouseDidMoveOverElement(WebPageProxy&, const WebHitTestResultData&, WebEvent::Modifiers, API::Object*); 108 109 void didClickAutoFillButton(WebPageProxy&, API::Object*) final; 109 void toolbarsAreVisible(Web Kit::WebPageProxy&, Function<void(bool)>&&) final;110 void toolbarsAreVisible(WebPageProxy&, Function<void(bool)>&&) final; 110 111 bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final; 111 112 void didExceedBackgroundResourceLimitWhileInForeground(WebPageProxy&, WKResourceLimit) final; … … 149 150 bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1; 150 151 bool webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1; 152 bool webViewRequestGeolocationPermissionForFrameDecisionHandler : 1; 151 153 #if PLATFORM(MAC) 152 154 bool showWebView : 1; -
trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
r221787 r221873 104 104 m_delegateMethods.webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:)]; 105 105 m_delegateMethods.webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(_webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:)]; 106 m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestGeolocationPermissionForFrame:decisionHandler:)]; 106 107 107 108 #if PLATFORM(MAC) … … 325 326 } 326 327 327 RefPtr<CompletionHandlerCallChecker>checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:));328 auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:)); 328 329 [delegate webView:m_uiDelegate.m_webView runJavaScriptTextInputPanelWithPrompt:message defaultText:defaultValue initiatedByFrame:wrapper(API::FrameInfo::create(*webFrameProxy, securityOriginData.securityOrigin())) completionHandler:BlockPtr<void (NSString *)>::fromCallable([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](NSString *result) { 329 330 if (checker->completionHandlerHasBeenCalled()) … … 331 332 completionHandler(result); 332 333 checker->didCallCompletionHandler(); 334 }).get()]; 335 } 336 337 void UIDelegate::UIClient::decidePolicyForGeolocationPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy& frame, API::SecurityOrigin& securityOrigin, Function<void(bool)>& completionHandler) 338 { 339 if (!m_uiDelegate.m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler) 340 return; 341 342 auto delegate = m_uiDelegate.m_delegate.get(); 343 if (!delegate) 344 return; 345 346 auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestGeolocationPermissionForFrame:decisionHandler:)); 347 [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView requestGeolocationPermissionForFrame:wrapper(API::FrameInfo::create(frame, securityOrigin.securityOrigin())) decisionHandler:BlockPtr<void(BOOL)>::fromCallable([completionHandler = std::exchange(completionHandler, nullptr), checker = WTFMove(checker)](BOOL result) { 348 if (checker->completionHandlerHasBeenCalled()) 349 return; 350 checker->didCallCompletionHandler(); 351 completionHandler(result); 333 352 }).get()]; 334 353 } -
trunk/Source/WebKit/UIProcess/PageClient.h
r221764 r221873 144 144 #if PLATFORM(IOS) 145 145 // FIXME: Adopt the WKUIDelegatePrivate callback on iOS and remove this. 146 virtual Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&&) = 0;146 virtual void decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&) = 0; 147 147 #endif 148 148 -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r221787 r221873 5823 5823 // if there is no delegate instead of returning the completionHandler 5824 5824 // for other code paths to try. 5825 completionHandler = m_uiClient->decidePolicyForGeolocationPermissionRequest(*this, *frame, origin.get(), WTFMove(completionHandler));5825 m_uiClient->decidePolicyForGeolocationPermissionRequest(*this, *frame, origin.get(), completionHandler); 5826 5826 #if PLATFORM(IOS) 5827 5827 if (completionHandler) 5828 completionHandler = m_pageClient.decidePolicyForGeolocationPermissionRequest(*frame, origin.get(), WTFMove(completionHandler));5828 m_pageClient.decidePolicyForGeolocationPermissionRequest(*frame, origin.get(), completionHandler); 5829 5829 #endif 5830 5830 if (completionHandler) -
trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h
r221764 r221873 64 64 void preferencesDidChange() override; 65 65 void toolTipChanged(const String&, const String&) override; 66 Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&&) override;66 void decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&) override; 67 67 void didStartProvisionalLoadForMainFrame() override; 68 68 void didFailProvisionalLoadForMainFrame() override; -
trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm
r221766 r221873 238 238 } 239 239 240 Function<void(bool)> PageClientImpl::decidePolicyForGeolocationPermissionRequest(WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>&& completionHandler) 241 { 242 [[wrapper(m_webView->_page->process().processPool()) _geolocationProvider] decidePolicyForGeolocationRequestFromOrigin:origin.securityOrigin() frame:frame completionHandler:WTFMove(completionHandler) view:m_webView]; 243 return nullptr; 240 void PageClientImpl::decidePolicyForGeolocationPermissionRequest(WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>& completionHandler) 241 { 242 [[wrapper(m_webView->_page->process().processPool()) _geolocationProvider] decidePolicyForGeolocationRequestFromOrigin:origin.securityOrigin() frame:frame completionHandler:std::exchange(completionHandler, nullptr) view:m_webView]; 244 243 } 245 244 -
trunk/Tools/ChangeLog
r221870 r221873 1 2017-09-11 Alex Christensen <achristensen@webkit.org> 2 3 Add WKUIDelegatePrivate equivalent of WKPageUIClient's decidePolicyForGeolocationPermissionRequest 4 https://bugs.webkit.org/show_bug.cgi?id=176642 5 <rdar://problem/29270035> 6 7 Reviewed by Darin Adler. 8 9 * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm: 10 (-[GeolocationDelegate initWithAllowGeolocation:]): 11 (-[GeolocationDelegate _webView:requestGeolocationPermissionForFrame:decisionHandler:]): 12 (-[GeolocationDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]): 13 (TEST): 14 1 15 2017-09-11 Wenson Hsieh <wenson_hsieh@apple.com> 2 16 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm
r221714 r221873 28 28 #if WK_API_ENABLED 29 29 30 #import "PlatformUtilities.h" 30 31 #import "TestWKWebView.h" 31 32 #import "Utilities.h" 32 33 #import "WKWebViewConfigurationExtras.h" 34 #import <WebKit/WKContext.h> 33 35 #import <WebKit/WKContextPrivateMac.h> 36 #import <WebKit/WKGeolocationManager.h> 37 #import <WebKit/WKGeolocationPosition.h> 34 38 #import <WebKit/WKPreferencesPrivate.h> 35 39 #import <WebKit/WKRetainPtr.h> … … 72 76 TestWebKitAPI::Util::run(&done); 73 77 } 78 79 @interface GeolocationDelegate : NSObject <WKUIDelegatePrivate> { 80 bool _allowGeolocation; 81 } 82 83 - (id)initWithAllowGeolocation:(bool)allowGeolocation; 84 85 @end 86 87 @implementation GeolocationDelegate 88 89 - (id)initWithAllowGeolocation:(bool)allowGeolocation 90 { 91 if (!(self = [super init])) 92 return nil; 93 _allowGeolocation = allowGeolocation; 94 return self; 95 } 96 97 - (void)_webView:(WKWebView *)webView requestGeolocationPermissionForFrame:(WKFrameInfo *)frame decisionHandler:(void (^)(BOOL allowed))decisionHandler 98 { 99 EXPECT_TRUE(frame.isMainFrame); 100 EXPECT_STREQ(frame.request.URL.absoluteString.UTF8String, _allowGeolocation ? "https://example.org/" : "https://example.com/"); 101 EXPECT_EQ(frame.securityOrigin.port, 0); 102 EXPECT_STREQ(frame.securityOrigin.protocol.UTF8String, "https"); 103 EXPECT_STREQ(frame.securityOrigin.host.UTF8String, _allowGeolocation ? "example.org" : "example.com"); 104 decisionHandler(_allowGeolocation); 105 } 106 107 - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler 108 { 109 if (_allowGeolocation) 110 EXPECT_STREQ(message.UTF8String, "position 50.644358 3.345453"); 111 else 112 EXPECT_STREQ(message.UTF8String, "error 1 User denied Geolocation"); 113 completionHandler(); 114 done = true; 115 } 116 117 @end 118 119 TEST(WebKit, GeolocationPermission) 120 { 121 NSString *html = @"<script>navigator.geolocation.watchPosition(" 122 "function(p) { alert('position ' + p.coords.latitude + ' ' + p.coords.longitude) }," 123 "function(e) { alert('error ' + e.code + ' ' + e.message) })" 124 "</script>"; 125 126 auto pool = adoptNS([[WKProcessPool alloc] init]); 127 128 WKGeolocationProviderV1 providerCallback; 129 memset(&providerCallback, 0, sizeof(WKGeolocationProviderV1)); 130 providerCallback.base.version = 1; 131 providerCallback.startUpdating = [] (WKGeolocationManagerRef manager, const void*) { 132 WKGeolocationManagerProviderDidChangePosition(manager, adoptWK(WKGeolocationPositionCreate(0, 50.644358, 3.345453, 2.53)).get()); 133 }; 134 WKGeolocationManagerSetProvider(WKContextGetGeolocationManager((WKContextRef)pool.get()), &providerCallback.base); 135 136 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 137 configuration.get().processPool = pool.get(); 138 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]); 139 auto delegate1 = adoptNS([[GeolocationDelegate alloc] initWithAllowGeolocation:false]); 140 [webView setUIDelegate:delegate1.get()]; 141 [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"https://example.com/"]]; 142 TestWebKitAPI::Util::run(&done); 143 144 done = false; 145 auto delegate2 = adoptNS([[GeolocationDelegate alloc] initWithAllowGeolocation:true]); 146 [webView setUIDelegate:delegate2.get()]; 147 [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"https://example.org/"]]; 148 TestWebKitAPI::Util::run(&done); 149 } 150 74 151 75 152 #if PLATFORM(MAC)
Note: See TracChangeset
for help on using the changeset viewer.