Changeset 221920 in webkit


Ignore:
Timestamp:
Sep 12, 2017, 9:32:39 AM (8 years ago)
Author:
achristensen@apple.com
Message:

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

Reviewed by Tim Horton.

Source/WebKit:

Covered by a new API test.

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

(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::runBeforeUnloadConfirmPanel):
(WebKit::UIDelegate::UIClient::exceededDatabaseQuota):
(WebKit::UIDelegate::UIClient::decidePolicyForNotificationPermissionRequest):
(WebKit::UIDelegate::UIClient::reachedApplicationCacheOriginQuota):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:

(-[NotificationDelegate initWithAllowNotifications:]):
(-[NotificationDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(-[NotificationDelegate _webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:]):
(TEST):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r221907 r221920  
     12017-09-12  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add WKUIDelegatePrivate equivalent of WKPageUIClient's decidePolicyForNotificationPermissionRequest
     4        https://bugs.webkit.org/show_bug.cgi?id=176768
     5        <rdar://problem/29270035>
     6
     7        Reviewed by Tim Horton.
     8
     9        Covered by a new API test.
     10
     11        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
     12        * UIProcess/Cocoa/UIDelegate.h:
     13        * UIProcess/Cocoa/UIDelegate.mm:
     14        (WebKit::UIDelegate::setDelegate):
     15        (WebKit::UIDelegate::UIClient::runBeforeUnloadConfirmPanel):
     16        (WebKit::UIDelegate::UIClient::exceededDatabaseQuota):
     17        (WebKit::UIDelegate::UIClient::decidePolicyForNotificationPermissionRequest):
     18        (WebKit::UIDelegate::UIClient::reachedApplicationCacheOriginQuota):
     19
    1202017-09-11  Wenson Hsieh  <wenson_hsieh@apple.com>
    221
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h

    r221873 r221920  
    161161- (void)_webView:(WKWebView *)webView getToolbarsAreVisibleWithCompletionHandler:(void(^)(BOOL))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    162162- (void)_webView:(WKWebView *)webView saveDataToFile:(NSData *)data suggestedFilename:(NSString *)suggestedFilename mimeType:(NSString *)mimeType originatingURL:(NSURL *)url WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     163- (void)_webView:(WKWebView *)webView requestNotificationPermissionForSecurityOrigin:(WKSecurityOrigin *)securityOrigin decisionHandler:(void (^)(BOOL))decisionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    163164- (void)_webView:(WKWebView *)webview mouseDidMoveOverElement:(_WKHitTestResult *)hitTestResult withFlags:(NSEventModifierFlags)flags userInfo:(id <NSSecureCoding>)userInfo;
    164165- (void)_webView:(WKWebView *)webView didExceedBackgroundResourceLimitWhileInForeground:(_WKResourceLimit)limit WK_API_AVAILABLE(macosx(WK_MAC_TBA));
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h

    r221899 r221920  
    4141namespace API {
    4242class FrameInfo;
     43class SecurityOrigin;
    4344}
    4445
     
    100101        void pageDidScroll(WebPageProxy*) final;
    101102        void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&) final;
     103        void decidePolicyForNotificationPermissionRequest(WebPageProxy&, API::SecurityOrigin&, Function<void(bool)>&&) final;
    102104        void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
    103105        void unavailablePluginButtonClicked(WebPageProxy&, WKPluginUnavailabilityReason, API::Dictionary&) final;
     
    162164        bool webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL : 1;
    163165        bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
     166        bool webViewRequestNotificationPermissionForSecurityOriginDecisionHandler : 1;
    164167#endif
    165168        bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm

    r221899 r221920  
    121121    m_delegateMethods.webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL = [delegate respondsToSelector:@selector(_webView:saveDataToFile:suggestedFilename:mimeType:originatingURL:)];
    122122    m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
     123    m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:)];
    123124#endif
    124125    m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler = [delegate respondsToSelector:@selector(_webView:decideDatabaseQuotaForSecurityOrigin:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:)];
     
    341342    }
    342343
    343     RefPtr<CompletionHandlerCallChecker> checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:));
     344    auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:));
    344345    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView runBeforeUnloadConfirmPanelWithMessage:message initiatedByFrame:wrapper(API::FrameInfo::create(*webFrameProxy, securityOriginData.securityOrigin())) completionHandler:BlockPtr<void (BOOL)>::fromCallable([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](BOOL result) {
    345346        if (checker->completionHandlerHasBeenCalled())
     
    368369
    369370    ASSERT(securityOrigin);
    370     RefPtr<CompletionHandlerCallChecker> checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:decideDatabaseQuotaForSecurityOrigin:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:));
    371     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView decideDatabaseQuotaForSecurityOrigin:wrapper(*securityOrigin) currentQuota:currentQuota currentOriginUsage:currentOriginUsage currentDatabaseUsage:currentUsage expectedUsage:expectedUsage decisionHandler:BlockPtr<void (unsigned long long newQuota)>::fromCallable([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](unsigned long long newQuota) {
     371    auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:decideDatabaseQuotaForSecurityOrigin:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:));
     372    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView decideDatabaseQuotaForSecurityOrigin:wrapper(*securityOrigin) currentQuota:currentQuota currentOriginUsage:currentOriginUsage currentDatabaseUsage:currentUsage expectedUsage:expectedUsage decisionHandler:BlockPtr<void(unsigned long long newQuota)>::fromCallable([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](unsigned long long newQuota) {
    372373        if (checker->completionHandlerHasBeenCalled())
    373374            return;
     
    618619    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView saveDataToFile:wrapper(data) suggestedFilename:suggestedFilename mimeType:mimeType originatingURL:originatingURL];
    619620}
    620    
     621
     622void UIDelegate::UIClient::decidePolicyForNotificationPermissionRequest(WebKit::WebPageProxy&, API::SecurityOrigin& securityOrigin, WTF::Function<void(bool)>&& completionHandler)
     623{
     624    if (!m_uiDelegate.m_delegateMethods.webViewRequestNotificationPermissionForSecurityOriginDecisionHandler)
     625        return completionHandler(false);
     626   
     627    auto delegate = m_uiDelegate.m_delegate.get();
     628    if (!delegate)
     629        return completionHandler(false);
     630
     631    auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:));
     632    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView requestNotificationPermissionForSecurityOrigin:wrapper(securityOrigin) decisionHandler:BlockPtr<void(BOOL)>::fromCallable([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](BOOL result) {
     633        if (checker->completionHandlerHasBeenCalled())
     634            return;
     635        checker->didCallCompletionHandler();
     636        completionHandler(result);
     637    }).get()];
     638}
     639
    621640bool UIDelegate::UIClient::runOpenPanel(WebPageProxy*, WebFrameProxy* webFrameProxy, const WebCore::SecurityOriginData& securityOriginData, API::OpenPanelParameters* openPanelParameters, WebOpenPanelResultListenerProxy* listener)
    622641{
     
    811830    }
    812831
    813     RefPtr<CompletionHandlerCallChecker> checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:decideWebApplicationCacheQuotaForSecurityOrigin:currentQuota:totalBytesNeeded:decisionHandler:));
    814     RefPtr<API::SecurityOrigin> apiOrigin = API::SecurityOrigin::create(securityOrigin);
    815    
    816     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView decideWebApplicationCacheQuotaForSecurityOrigin:wrapper(*apiOrigin) currentQuota:currentQuota totalBytesNeeded:totalBytesNeeded decisionHandler:BlockPtr<void (unsigned long long)>::fromCallable([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](unsigned long long newQuota) {
     832    auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:decideWebApplicationCacheQuotaForSecurityOrigin:currentQuota:totalBytesNeeded:decisionHandler:));
     833    auto apiOrigin = API::SecurityOrigin::create(securityOrigin);
     834   
     835    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView decideWebApplicationCacheQuotaForSecurityOrigin:wrapper(apiOrigin.get()) currentQuota:currentQuota totalBytesNeeded:totalBytesNeeded decisionHandler:BlockPtr<void(unsigned long long)>::fromCallable([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](unsigned long long newQuota) {
    817836        if (checker->completionHandlerHasBeenCalled())
    818837            return;
  • trunk/Tools/ChangeLog

    r221917 r221920  
     12017-09-12  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add WKUIDelegatePrivate equivalent of WKPageUIClient's decidePolicyForNotificationPermissionRequest
     4        https://bugs.webkit.org/show_bug.cgi?id=176768
     5        <rdar://problem/29270035>
     6
     7        Reviewed by Tim Horton.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
     10        (-[NotificationDelegate initWithAllowNotifications:]):
     11        (-[NotificationDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
     12        (-[NotificationDelegate _webView:requestNotificationPermissionForSecurityOrigin:decisionHandler:]):
     13        (TEST):
     14
    1152017-09-12 Brent Fulgham  <bfulgham@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm

    r221873 r221920  
    203203}
    204204
     205@interface NotificationDelegate : NSObject <WKUIDelegatePrivate> {
     206    bool _allowNotifications;
     207}
     208- (id)initWithAllowNotifications:(bool)allowNotifications;
     209@end
     210
     211@implementation NotificationDelegate
     212
     213- (id)initWithAllowNotifications:(bool)allowNotifications
     214{
     215    if (!(self = [super init]))
     216        return nil;
     217    _allowNotifications = allowNotifications;
     218    return self;
     219}
     220
     221- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
     222{
     223    if (_allowNotifications)
     224        EXPECT_STREQ(message.UTF8String, "permission granted");
     225    else
     226        EXPECT_STREQ(message.UTF8String, "permission denied");
     227    completionHandler();
     228    done = true;
     229}
     230
     231- (void)_webView:(WKWebView *)webView requestNotificationPermissionForSecurityOrigin:(WKSecurityOrigin *)securityOrigin decisionHandler:(void (^)(BOOL))decisionHandler
     232{
     233    if (_allowNotifications)
     234        EXPECT_STREQ(securityOrigin.host.UTF8String, "example.org");
     235    else
     236        EXPECT_STREQ(securityOrigin.host.UTF8String, "example.com");
     237    decisionHandler(_allowNotifications);
     238}
     239
     240@end
     241
     242TEST(WebKit, NotificationPermission)
     243{
     244    NSString *html = @"<script>Notification.requestPermission(function(p){alert('permission '+p)})</script>";
     245    auto webView = adoptNS([[WKWebView alloc] init]);
     246    [webView setUIDelegate:[[[NotificationDelegate alloc] initWithAllowNotifications:YES] autorelease]];
     247    [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://example.org"]];
     248    TestWebKitAPI::Util::run(&done);
     249    done = false;
     250    [webView setUIDelegate:[[[NotificationDelegate alloc] initWithAllowNotifications:NO] autorelease]];
     251    [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://example.com"]];
     252    TestWebKitAPI::Util::run(&done);
     253}
    205254
    206255@interface PlugInDelegate : NSObject <WKUIDelegatePrivate>
Note: See TracChangeset for help on using the changeset viewer.