Skip to content
  • jonlee@apple.com's avatar
    Allow notification origin permission request when no js callback is provided · 2ee4bbe6
    jonlee@apple.com authored
    https://bugs.webkit.org/show_bug.cgi?id=63615
    <rdar://problem/11059590>
    
    Reviewed by Sam Weinig.
    
    Source/WebCore:
    
    Instead of throwing a type error when no callback is provided, we pass a null callback.
    
    Test: http/tests/notifications/legacy/request-no-callback.html
    
    * bindings/js/JSDesktopNotificationsCustom.cpp:
    (WebCore::JSNotificationCenter::requestPermission):
    
    Source/WebKit/mac:
    
    Introduce a boolean to determine whether the request was using the legacy or standard API. This way,
    we do not fall through to calling the standard API's callback if the legacy API's callback is null.
    
    * WebCoreSupport/WebNotificationClient.mm:
    (WebCore):
    (-[WebNotificationPolicyListener initWithVoidCallback:]):
    (-[WebNotificationPolicyListener allow]):
    (-[WebNotificationPolicyListener deny]):
    
    Source/WebKit2:
    
    Null checks already exist for both standard and legacy API callbacks, so no changes are needed here
    like there are in WebKit 1. The checks existed because the callbacks are held in a hash map used to keep
    track of pending requests.
    
    Also, add a check for a null callback when short circuiting.
    
    * WebProcess/Notifications/NotificationPermissionRequestManager.cpp:
    (WebKit::NotificationPermissionRequestManager::startRequest):
    
    Tools:
    
    Teach DRT to look at the existing entries in the permission hash map when permission is requested.
    
    * DumpRenderTree/mac/MockWebNotificationProvider.h: Expose policyForOrigin.
    * DumpRenderTree/mac/MockWebNotificationProvider.mm:
    (-[MockWebNotificationProvider setWebNotificationOrigin:permission:]):
    * DumpRenderTree/mac/UIDelegate.mm:
    (-[UIDelegate webView:decidePolicyForNotificationRequestFromOrigin:listener:]): Look at whether a
    policy for the origin already exists. If so, accept or deny the request as appropriate. Otherwise,
    accept by default.
    
    LayoutTests:
    
    * http/tests/notifications/legacy/request-expected.txt:
    * http/tests/notifications/legacy/request-no-callback-expected.txt: Added.
    * http/tests/notifications/legacy/request-no-callback.html: Calls webkitNotifications.requestPermission()
    with no callback, with default and denied permission. For WebKit2, if the permission is not default, it
    will short circuit instead of creating a pending request.
    * http/tests/notifications/legacy/request.html: The test mistakenly uses the standard API instead of
    the legacy API. The results don't change, but we make sure that we call
    webkitNotifications.requestPermission() with a callback to test full coverage of the legacy API. We also
    expand the test to cover both default and denied permissions.
    * http/tests/notifications/request-expected.txt:
    * http/tests/notifications/request.html: Expand test to cover both default and denied permissions.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@131280 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    2ee4bbe6