Changeset 221873 in webkit


Ignore:
Timestamp:
Sep 11, 2017 1:45:26 PM (7 years ago)
Author:
achristensen@apple.com
Message:

Add WKUIDelegatePrivate equivalent of WKPageUIClient's decidePolicyForGeolocationPermissionRequest
https://bugs.webkit.org/show_bug.cgi?id=176642
<rdar://problem/29270035>

Reviewed by Darin Adler.

Source/WebKit:

  • UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
  • UIProcess/Cocoa/UIDelegate.h:
  • UIProcess/Cocoa/UIDelegate.mm:

(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::runJavaScriptPrompt):
(WebKit::Function<void):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:

(-[GeolocationDelegate initWithAllowGeolocation:]):
(-[GeolocationDelegate _webView:requestGeolocationPermissionForFrame:decisionHandler:]):
(-[GeolocationDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TEST):

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r221870 r221873  
     12017-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
    1162017-09-11  Wenson Hsieh  <wenson_hsieh@apple.com>
    217
  • trunk/Source/WebKit/UIProcess/API/APIUIClient.h

    r221787 r221873  
    127127
    128128    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)>&) { }
    130130    virtual bool decidePolicyForUserMediaPermissionRequest(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, SecurityOrigin&, WebKit::UserMediaPermissionRequestProxy&) { return false; }
    131131    virtual bool checkUserMediaPermissionForOrigin(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, SecurityOrigin&, WebKit::UserMediaPermissionCheckProxy&) { return false; }
  • trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp

    r221787 r221873  
    19541954        }
    19551955
    1956         Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>&& completionHandler) final
     1956        void decidePolicyForGeolocationPermissionRequest(WebPageProxy& page, WebFrameProxy& frame, API::SecurityOrigin& origin, Function<void(bool)>& completionHandler) final
    19571957        {
    19581958            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);
    19631962        }
    19641963
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r221714 r221873  
    106106- (WKDragDestinationAction)_webView:(WKWebView *)webView dragDestinationActionMaskForDraggingInfo:(id)draggingInfo WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    107107- (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));
    108109
    109110- (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  
    183183    }
    184184
    185     Function<void(bool)> decidePolicyForGeolocationPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&& completionHandler) final
    186     {
    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()));
    188188        webkitWebViewMakePermissionRequest(m_webView, WEBKIT_PERMISSION_REQUEST(geolocationPermissionRequest.get()));
    189         return nullptr;
    190189    }
    191190
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h

    r221787 r221873  
    9191        void runJavaScriptAlert(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void()>&& completionHandler) final;
    9292        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;
    9495        bool canRunBeforeUnloadConfirmPanel() const final;
    9596        void runBeforeUnloadConfirmPanel(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(bool)>&& completionHandler) final;
     
    104105        void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&) final;
    105106        void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
    106         void unavailablePluginButtonClicked(WebKit::WebPageProxy&, WKPluginUnavailabilityReason, API::Dictionary&) final;
     107        void unavailablePluginButtonClicked(WebPageProxy&, WKPluginUnavailabilityReason, API::Dictionary&) final;
    107108        void mouseDidMoveOverElement(WebPageProxy&, const WebHitTestResultData&, WebEvent::Modifiers, API::Object*);
    108109        void didClickAutoFillButton(WebPageProxy&, API::Object*) final;
    109         void toolbarsAreVisible(WebKit::WebPageProxy&, Function<void(bool)>&&) final;
     110        void toolbarsAreVisible(WebPageProxy&, Function<void(bool)>&&) final;
    110111        bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
    111112        void didExceedBackgroundResourceLimitWhileInForeground(WebPageProxy&, WKResourceLimit) final;
     
    149150        bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1;
    150151        bool webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
     152        bool webViewRequestGeolocationPermissionForFrameDecisionHandler : 1;
    151153#if PLATFORM(MAC)
    152154        bool showWebView : 1;
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm

    r221787 r221873  
    104104    m_delegateMethods.webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:)];
    105105    m_delegateMethods.webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(_webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:)];
     106    m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestGeolocationPermissionForFrame:decisionHandler:)];
    106107
    107108#if PLATFORM(MAC)
     
    325326    }
    326327
    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:));
    328329    [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) {
    329330        if (checker->completionHandlerHasBeenCalled())
     
    331332        completionHandler(result);
    332333        checker->didCallCompletionHandler();
     334    }).get()];
     335}
     336
     337void 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);
    333352    }).get()];
    334353}
  • trunk/Source/WebKit/UIProcess/PageClient.h

    r221764 r221873  
    144144#if PLATFORM(IOS)
    145145    // 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;
    147147#endif
    148148
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r221787 r221873  
    58235823    // if there is no delegate instead of returning the completionHandler
    58245824    // 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);
    58265826#if PLATFORM(IOS)
    58275827    if (completionHandler)
    5828         completionHandler = m_pageClient.decidePolicyForGeolocationPermissionRequest(*frame, origin.get(), WTFMove(completionHandler));
     5828        m_pageClient.decidePolicyForGeolocationPermissionRequest(*frame, origin.get(), completionHandler);
    58295829#endif
    58305830    if (completionHandler)
  • trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h

    r221764 r221873  
    6464    void preferencesDidChange() override;
    6565    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;
    6767    void didStartProvisionalLoadForMainFrame() override;
    6868    void didFailProvisionalLoadForMainFrame() override;
  • trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm

    r221766 r221873  
    238238}
    239239
    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;
     240void 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];
    244243}
    245244
  • trunk/Tools/ChangeLog

    r221870 r221873  
     12017-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
    1152017-09-11  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm

    r221714 r221873  
    2828#if WK_API_ENABLED
    2929
     30#import "PlatformUtilities.h"
    3031#import "TestWKWebView.h"
    3132#import "Utilities.h"
    3233#import "WKWebViewConfigurationExtras.h"
     34#import <WebKit/WKContext.h>
    3335#import <WebKit/WKContextPrivateMac.h>
     36#import <WebKit/WKGeolocationManager.h>
     37#import <WebKit/WKGeolocationPosition.h>
    3438#import <WebKit/WKPreferencesPrivate.h>
    3539#import <WebKit/WKRetainPtr.h>
     
    7276    TestWebKitAPI::Util::run(&done);
    7377}
     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
     119TEST(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
    74151
    75152#if PLATFORM(MAC)
Note: See TracChangeset for help on using the changeset viewer.