Changeset 291737 in webkit
- Timestamp:
- Mar 22, 2022, 11:47:41 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 19 edited
- 1 copied
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/http/tests/notifications/notification-request-permission-no-callback.html (modified) (1 diff)
-
LayoutTests/http/tests/notifications/notification-request-permission.html (modified) (1 diff)
-
LayoutTests/http/tests/notifications/request-consumes-activation-expected.txt (added)
-
LayoutTests/http/tests/notifications/request-consumes-activation.html (added)
-
LayoutTests/http/tests/push-api/resources/subscribe-tests.js (modified) (2 diffs)
-
LayoutTests/http/tests/push-api/subscribe-deny-permissions-expected.txt (modified) (1 diff)
-
LayoutTests/http/tests/push-api/subscribe-deny-permissions-on-prompt-expected.txt (copied) (copied from trunk/LayoutTests/http/tests/push-api/subscribe-deny-permissions-expected.txt ) (1 diff)
-
LayoutTests/http/tests/push-api/subscribe-deny-permissions-on-prompt.html (added)
-
LayoutTests/http/tests/push-api/subscribe-deny-permissions.html (modified) (1 diff)
-
LayoutTests/platform/gtk/TestExpectations (modified) (1 diff)
-
LayoutTests/platform/mac-wk1/TestExpectations (modified) (1 diff)
-
LayoutTests/platform/win/TestExpectations (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/Modules/notifications/Notification.cpp (modified) (3 diffs)
-
Source/WebCore/Modules/push-api/PushManager.cpp (modified) (4 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (modified) (1 diff)
-
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (modified) (1 diff)
-
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (modified) (1 diff)
-
Tools/WebKitTestRunner/TestController.cpp (modified) (5 diffs)
-
Tools/WebKitTestRunner/TestController.h (modified) (2 diffs)
-
Tools/WebKitTestRunner/TestInvocation.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r291727 r291737 1 2022-03-22 Ben Nham <nham@apple.com> 2 3 Only show notification permission prompt on transient activation 4 https://bugs.webkit.org/show_bug.cgi?id=238188 5 6 Reviewed by Youenn Fablet. 7 8 Add test cases to make sure that showing a permission prompt consumes a user gesture. 9 10 * http/tests/notifications/notification-request-permission-no-callback.html: 11 * http/tests/notifications/notification-request-permission.html: 12 * http/tests/notifications/request-consumes-activation-expected.txt: Added. 13 * http/tests/notifications/request-consumes-activation.html: Added. 14 * http/tests/push-api/resources/subscribe-tests.js: 15 (async testDocumentSubscribeWithUserGesture): 16 (async testDocumentSubscribeWithoutUserGesture): 17 (async testDocumentSubscribeImpl): 18 * http/tests/push-api/subscribe-deny-permissions-expected.txt: 19 * http/tests/push-api/subscribe-deny-permissions-on-prompt-expected.txt: 20 * http/tests/push-api/subscribe-deny-permissions-on-prompt.html: Added. 21 * http/tests/push-api/subscribe-deny-permissions.html: 22 * platform/gtk/TestExpectations: 23 * platform/mac-wk1/TestExpectations: 24 * platform/win/TestExpectations: 25 1 26 2022-03-22 Tyler Wilcock <tyler_w@apple.com> 2 27 -
trunk/LayoutTests/http/tests/notifications/notification-request-permission-no-callback.html
r291414 r291737 16 16 window.Notification.requestPermission(); 17 17 testPassed("Notification.requestPermission does not crash."); 18 }); 18 19 20 internals.withUserGesture(() => { 19 21 testRunner.grantWebNotificationPermission(testURL); 20 22 window.Notification.requestPermission(); 21 23 testPassed("Notification.requestPermission does not crash."); 24 }); 22 25 26 internals.withUserGesture(() => { 23 27 testRunner.denyWebNotificationPermission(testURL); 24 28 window.Notification.requestPermission(); -
trunk/LayoutTests/http/tests/notifications/notification-request-permission.html
r291414 r291737 16 16 window.Notification.requestPermission(function() { }); 17 17 testPassed("Notification.requestPermission does not crash."); 18 }); 18 19 20 internals.withUserGesture(() => { 19 21 testRunner.grantWebNotificationPermission(testURL); 20 22 window.Notification.requestPermission(function() { }); 21 23 testPassed("Notification.requestPermission does not crash."); 24 }); 22 25 26 internals.withUserGesture(() => { 23 27 testRunner.denyWebNotificationPermission(testURL); 24 28 window.Notification.requestPermission(function() { }); -
trunk/LayoutTests/http/tests/push-api/resources/subscribe-tests.js
r291414 r291737 39 39 } 40 40 41 async function testDocumentSubscribeWithUserGesture(registration, domExceptionName )41 async function testDocumentSubscribeWithUserGesture(registration, domExceptionName, domMessage) 42 42 { 43 await testDocumentSubscribeImpl(registration, domExceptionName, true);43 await testDocumentSubscribeImpl(registration, domExceptionName, domMessage, true); 44 44 } 45 45 46 async function testDocumentSubscribeWithoutUserGesture(registration, domExceptionName )46 async function testDocumentSubscribeWithoutUserGesture(registration, domExceptionName, domMessage) 47 47 { 48 await testDocumentSubscribeImpl(registration, domExceptionName, false);48 await testDocumentSubscribeImpl(registration, domExceptionName, domMessage, false); 49 49 } 50 50 51 async function testDocumentSubscribeImpl(registration, domExceptionName, withUserGesture)51 async function testDocumentSubscribeImpl(registration, domExceptionName, domMessage, withUserGesture) 52 52 { 53 let expected = domExceptionName ? `error: ${domExceptionName}` : "successful"; 53 let expected = "successful"; 54 if (domMessage) 55 expected = `error: ${domExceptionName}: ${domMessage}` 56 else if (domExceptionName) 57 expected = `error: ${domExceptionName}` 58 54 59 let result = null; 55 60 … … 80 85 if (e.name == 'AbortError') 81 86 result = 'successful'; 87 else if (domMessage) 88 result = `error: ${e?.name}: ${e?.message}` 82 89 else 83 result = 'error: ' + (e ? e.name : null);90 result = `error: ${e?.name}`; 84 91 } 85 92 -
trunk/LayoutTests/http/tests/push-api/subscribe-deny-permissions-expected.txt
r291414 r291737 2 2 PASS: document permissionState was denied 3 3 PASS: service worker subscribe was error: NotAllowedError 4 PASS: document subscribe without user gesture was error: NotAllowedError 4 PASS: document subscribe without user gesture was error: NotAllowedError: User denied push permission 5 5 PASS: document subscribe with user gesture was error: NotAllowedError 6 6 -
trunk/LayoutTests/http/tests/push-api/subscribe-deny-permissions-on-prompt-expected.txt
r291736 r291737 1 PASS: service worker permissionState was denied2 PASS: document permissionState was denied1 PASS: service worker permissionState was prompt 2 PASS: document permissionState was prompt 3 3 PASS: service worker subscribe was error: NotAllowedError 4 4 PASS: document subscribe without user gesture was error: NotAllowedError 5 5 PASS: document subscribe with user gesture was error: NotAllowedError 6 PASS: document subscribe with consumed user gesture failed with user gesture error 6 7 -
trunk/LayoutTests/http/tests/push-api/subscribe-deny-permissions.html
r291414 r291737 15 15 await testDocumentPermissionState(registration, 'denied'); 16 16 await testServiceWorkerSubscribe(registration, 'NotAllowedError'); 17 await testDocumentSubscribeWithoutUserGesture(registration, 'NotAllowedError' );17 await testDocumentSubscribeWithoutUserGesture(registration, 'NotAllowedError', 'User denied push permission'); 18 18 await testDocumentSubscribeWithUserGesture(registration, 'NotAllowedError'); 19 19 } catch (e) { -
trunk/LayoutTests/platform/gtk/TestExpectations
r291471 r291737 1874 1874 http/tests/push-api/subscribe-default-permissions-iframe-same-origin.html [ Failure ] 1875 1875 http/tests/push-api/subscribe-default-permissions.html [ Failure ] 1876 http/tests/push-api/subscribe-deny-permissions-on-prompt.html [ Failure ] 1876 1877 http/tests/push-api/subscribe-deny-permissions.html [ Failure ] 1877 1878 http/tests/push-api/subscribe-grant-permissions.html [ Failure ] -
trunk/LayoutTests/platform/mac-wk1/TestExpectations
r291724 r291737 1789 1789 http/tests/push-api/subscribe-default-permissions-iframe-same-origin.html [ Skip ] 1790 1790 http/tests/push-api/subscribe-default-permissions.html [ Skip ] 1791 http/tests/push-api/subscribe-deny-permissions-on-prompt.html [ Failure ] 1791 1792 http/tests/push-api/subscribe-deny-permissions.html [ Skip ] 1792 1793 http/tests/push-api/subscribe-grant-permissions.html [ Skip ] -
trunk/LayoutTests/platform/win/TestExpectations
r291600 r291737 5016 5016 http/tests/push-api/subscribe-default-permissions-iframe-same-origin.html [ Failure ] 5017 5017 http/tests/push-api/subscribe-default-permissions.html [ Failure ] 5018 http/tests/push-api/subscribe-deny-permissions-on-prompt.html [ Failure ] 5018 5019 http/tests/push-api/subscribe-deny-permissions.html [ Failure ] 5019 5020 http/tests/push-api/subscribe-grant-permissions.html [ Failure ] -
trunk/Source/WebCore/ChangeLog
r291735 r291737 1 2022-03-22 Ben Nham <nham@apple.com> 2 3 Only show notification permission prompt on transient activation 4 https://bugs.webkit.org/show_bug.cgi?id=238188 5 6 Reviewed by Youenn Fablet. 7 8 In r291427, we changed Notification.requestPermission and PushManager.subscribe to only show 9 a permission prompt when processing a user gesture. This ended up being too restrictive and 10 causes compatibility problems with some large sites. 11 12 Instead, match Chrome and Firefox by allowing these prompts after a transient activiation, 13 i.e. a user gesture within the past second. 14 15 Per Maciej's suggestion, we also consume the activation to help combat prompt spam. 16 17 Covered by new and existing layout tests. 18 19 * Modules/notifications/Notification.cpp: 20 (WebCore::Notification::requestPermission): 21 * Modules/push-api/PushManager.cpp: 22 (WebCore::PushManager::subscribe): 23 1 24 2022-03-22 Alex Christensen <achristensen@webkit.org> 2 25 -
trunk/Source/WebCore/Modules/notifications/Notification.cpp
r291414 r291737 36 36 #include "Notification.h" 37 37 38 #include "DOMWindow.h" 38 39 #include "Event.h" 39 40 #include "EventNames.h" … … 44 45 #include "NotificationPermissionCallback.h" 45 46 #include "ServiceWorkerGlobalScope.h" 46 #include "UserGestureIndicator.h"47 47 #include "WindowEventLoop.h" 48 48 #include "WindowFocusAllowedIndicator.h" … … 298 298 } 299 299 300 if (!UserGestureIndicator::processingUserGesture()) { 300 auto* window = document.frame() ? document.frame()->window() : nullptr; 301 if (!window || !window->consumeTransientActivation()) { 301 302 document.addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Notification prompting can only be done from a user gesture."_s); 302 303 return resolvePromiseAndCallback(Permission::Denied); -
trunk/Source/WebCore/Modules/push-api/PushManager.cpp
r291414 r291737 29 29 #if ENABLE(SERVICE_WORKER) 30 30 31 #include "DOMWindow.h" 31 32 #include "DocumentInlines.h" 32 33 #include "EventLoop.h" … … 38 39 #include "ScriptExecutionContext.h" 39 40 #include "ServiceWorkerRegistration.h" 40 #include "UserGestureIndicator.h"41 41 #include <wtf/IsoMallocInlines.h> 42 42 #include <wtf/Vector.h> … … 73 73 RELEASE_ASSERT(context.isSecureContext()); 74 74 75 context.eventLoop().queueTask(TaskSource::Networking, [this, protectedThis = Ref { *this }, context = Ref { context }, options = WTFMove(options), promise = WTFMove(promise) , processingUserGesture = UserGestureIndicator::processingUserGesture()]() mutable {75 context.eventLoop().queueTask(TaskSource::Networking, [this, protectedThis = Ref { *this }, context = Ref { context }, options = WTFMove(options), promise = WTFMove(promise)]() mutable { 76 76 if (!options || !options->userVisibleOnly) { 77 77 promise.reject(Exception { NotAllowedError, "Subscribing for push requires userVisibleOnly to be true"_s }); … … 132 132 RELEASE_ASSERT(context->isDocument()); 133 133 134 if (!downcast<Document>(context.get()).isSameOriginAsTopDocument()) { 134 auto& document = downcast<Document>(context.get()); 135 if (!document.isSameOriginAsTopDocument()) { 135 136 promise.reject(Exception { NotAllowedError, "Cannot request permission from cross-origin iframe"_s }); 136 137 return; 137 138 } 138 139 139 if (!processingUserGesture) { 140 auto* window = document.frame() ? document.frame()->window() : nullptr; 141 if (!window || !window->consumeTransientActivation()) { 140 142 promise.reject(Exception { NotAllowedError, "Push notification prompting can only be done from a user gesture"_s }); 141 143 return; -
trunk/Tools/ChangeLog
r291736 r291737 1 2022-03-22 Ben Nham <nham@apple.com> 2 3 Only show notification permission prompt on transient activation 4 https://bugs.webkit.org/show_bug.cgi?id=238188 5 6 Reviewed by Youenn Fablet. 7 8 Add an internal API denyWebNotificationPermissionOnPrompt to WebKitTestRunner that allows a 9 notification permission prompt to first be displayed and then rejected. This differs from 10 the existing denyNotificationPermission call, which denied notification permissions before 11 prompting. 12 13 * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: 14 * WebKitTestRunner/InjectedBundle/TestRunner.cpp: 15 (WTR::TestRunner::denyWebNotificationPermission): 16 (WTR::TestRunner::denyWebNotificationPermissionOnPrompt): 17 * WebKitTestRunner/InjectedBundle/TestRunner.h: 18 * WebKitTestRunner/TestController.cpp: 19 (WTR::originUserVisibleName): 20 (WTR::TestController::denyNotificationPermissionOnPrompt): 21 (WTR::TestController::resetStateToConsistentValues): 22 (WTR::TestController::decidePolicyForNotificationPermissionRequest): 23 * WebKitTestRunner/TestController.h: 24 * WebKitTestRunner/TestInvocation.cpp: 25 (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle): 26 1 27 2022-03-22 Yusuke Suzuki <ysuzuki@apple.com> 2 28 -
trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
r290985 r291737 207 207 undefined grantWebNotificationPermission(DOMString origin); 208 208 undefined denyWebNotificationPermission(DOMString origin); 209 undefined denyWebNotificationPermissionOnPrompt(DOMString origin); 209 210 undefined removeAllWebNotificationPermissions(); 210 211 undefined simulateWebNotificationClick(object notification); -
trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
r290985 r291737 877 877 } 878 878 879 void TestRunner::denyWebNotificationPermissionOnPrompt(JSStringRef origin) 880 { 881 postSynchronousPageMessageWithReturnValue("DenyNotificationPermissionOnPrompt", toWK(origin)); 882 } 883 879 884 void TestRunner::removeAllWebNotificationPermissions() 880 885 { -
trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
r290985 r291737 293 293 static void grantWebNotificationPermission(JSStringRef origin); 294 294 static void denyWebNotificationPermission(JSStringRef origin); 295 static void denyWebNotificationPermissionOnPrompt(JSStringRef origin); 295 296 static void removeAllWebNotificationPermissions(); 296 297 static void simulateWebNotificationClick(JSValueRef notification); -
trunk/Tools/WebKitTestRunner/TestController.cpp
r290985 r291737 720 720 } 721 721 722 static String originUserVisibleName(WKSecurityOriginRef origin) 723 { 724 if (!origin) 725 return emptyString(); 726 727 auto host = toWTFString(adoptWK(WKSecurityOriginCopyHost(origin))); 728 auto protocol = toWTFString(adoptWK(WKSecurityOriginCopyProtocol(origin))); 729 730 if (host.isEmpty() || protocol.isEmpty()) 731 return emptyString(); 732 733 if (int port = WKSecurityOriginGetPort(origin)) 734 return makeString(protocol, "://", host, ':', port); 735 736 return makeString(protocol, "://", host); 737 } 738 722 739 bool TestController::grantNotificationPermission(WKStringRef originString) 723 740 { … … 735 752 auto origin = adoptWK(WKSecurityOriginCreateFromString(originString)); 736 753 WKNotificationManagerProviderDidUpdateNotificationPolicy(WKNotificationManagerGetSharedServiceWorkerNotificationManager(), origin.get(), false); 754 return true; 755 } 756 757 bool TestController::denyNotificationPermissionOnPrompt(WKStringRef originString) 758 { 759 auto origin = adoptWK(WKSecurityOriginCreateFromString(originString)); 760 auto originName = originUserVisibleName(origin.get()); 761 m_notificationOriginsToDenyOnPrompt.add(originName); 737 762 return true; 738 763 } … … 1047 1072 // Reset notification permissions 1048 1073 m_webNotificationProvider.reset(); 1074 m_notificationOriginsToDenyOnPrompt.clear(); 1049 1075 1050 1076 // Reset Geolocation permissions. … … 2413 2439 } 2414 2440 2415 static String originUserVisibleName(WKSecurityOriginRef origin)2416 {2417 if (!origin)2418 return emptyString();2419 2420 auto host = toWTFString(adoptWK(WKSecurityOriginCopyHost(origin)));2421 auto protocol = toWTFString(adoptWK(WKSecurityOriginCopyProtocol(origin)));2422 2423 if (host.isEmpty() || protocol.isEmpty())2424 return emptyString();2425 2426 if (int port = WKSecurityOriginGetPort(origin))2427 return makeString(protocol, "://", host, ':', port);2428 2429 return makeString(protocol, "://", host);2430 }2431 2432 2441 static String userMediaOriginHash(WKSecurityOriginRef userMediaDocumentOrigin, WKSecurityOriginRef topLevelDocumentOrigin) 2433 2442 { … … 2652 2661 } 2653 2662 2654 void TestController::decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef, WKNotificationPermissionRequestRef request) 2655 { 2663 void TestController::decidePolicyForNotificationPermissionRequest(WKPageRef, WKSecurityOriginRef origin, WKNotificationPermissionRequestRef request) 2664 { 2665 auto originName = originUserVisibleName(origin); 2666 if (m_notificationOriginsToDenyOnPrompt.contains(originName)) { 2667 WKNotificationPermissionRequestDeny(request); 2668 return; 2669 } 2670 2656 2671 WKNotificationPermissionRequestAllow(request); 2657 2672 } -
trunk/Tools/WebKitTestRunner/TestController.h
r290985 r291737 377 377 bool grantNotificationPermission(WKStringRef origin); 378 378 bool denyNotificationPermission(WKStringRef origin); 379 bool denyNotificationPermissionOnPrompt(WKStringRef origin); 379 380 380 381 private: … … 576 577 577 578 WebNotificationProvider m_webNotificationProvider; 579 HashSet<String> m_notificationOriginsToDenyOnPrompt; 578 580 579 581 std::unique_ptr<PlatformWebView> m_mainWebView; -
trunk/Tools/WebKitTestRunner/TestInvocation.cpp
r290985 r291737 1040 1040 return adoptWK(WKBooleanCreate(TestController::singleton().denyNotificationPermission(stringValue(messageBody)))); 1041 1041 1042 if (WKStringIsEqualToUTF8CString(messageName, "DenyNotificationPermissionOnPrompt")) 1043 return adoptWK(WKBooleanCreate(TestController::singleton().denyNotificationPermissionOnPrompt(stringValue(messageBody)))); 1044 1042 1045 if (WKStringIsEqualToUTF8CString(messageName, "IsDoingMediaCapture")) 1043 1046 return adoptWK(WKBooleanCreate(TestController::singleton().isDoingMediaCapture()));
Note:
See TracChangeset
for help on using the changeset viewer.