Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add support to the Permissions API for Service Workers and Shared Wor…
…kers https://bugs.webkit.org/show_bug.cgi?id=244241 Reviewed by Chris Dumez and Sihui Liu. Permissions::query() should be exposed for both window and workers. Currently, it is only exposed for window and dedicated workers. This patch adds support for service and shared workers. * LayoutTests/http/tests/notifications/permission/service-worker-permissions-query-expected.txt: Added. * LayoutTests/http/tests/notifications/permission/service-worker-permissions-query.html: Added. * LayoutTests/http/tests/notifications/permission/service-worker-permissions-query.js: Added. (self.onmessage): * LayoutTests/http/tests/notifications/permission/shared-worker-permission-query.js: Added. (port.onmessage): (onconnect): * LayoutTests/http/tests/notifications/permission/shared-worker-permissions-query-expected.txt: Added. * LayoutTests/http/tests/notifications/permission/shared-worker-permissions-query.html: Added. * Source/WTF/wtf/ObjectIdentifier.h: (WTF::ObjectIdentifier::operator> const): * Source/WebCore/Headers.cmake: * Source/WebCore/Modules/permissions/PermissionController.h: * Source/WebCore/Modules/permissions/PermissionQuerySource.h: Copied from Source/WebKit/UIProcess/WebPermissionControllerProxy.messages.in. * Source/WebCore/Modules/permissions/Permissions.cpp: (WebCore::sourceFromContext): (WebCore::Permissions::query): * Source/WebCore/Modules/permissions/Permissions.idl: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebKit/UIProcess/WebPermissionControllerProxy.cpp: (WebKit::WebPermissionControllerProxy::query): (WebKit::WebPermissionControllerProxy::mostReasonableWebPageProxy const): * Source/WebKit/UIProcess/WebPermissionControllerProxy.h: * Source/WebKit/UIProcess/WebPermissionControllerProxy.messages.in: * Source/WebKit/UIProcess/WebProcessProxy.cpp: (WebKit::WebProcessProxy::serviceWorkerClientProcesses const): (WebKit::WebProcessProxy::sharedWorkerClientProcesses const): * Source/WebKit/UIProcess/WebProcessProxy.h: * Source/WebKit/WebProcess/WebCoreSupport/WebPermissionController.cpp: (WebKit::WebPermissionController::query): (WebKit::WebPermissionController::tryProcessingRequests): * Source/WebKit/WebProcess/WebCoreSupport/WebPermissionController.h: Canonical link: https://commits.webkit.org/253752@main
- Loading branch information
1 parent
e468229
commit f4b9245
Showing
20 changed files
with
380 additions
and
24 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...utTests/http/tests/notifications/permission/service-worker-permissions-query-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
This test checks that Permissions::query() works for service workers | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS message.data is "prompt" | ||
PASS receivedPostMessageResponse became true | ||
PASS requestPermissionResult is "granted" | ||
PASS message.data is "granted" | ||
PASS receivedPostMessageResponse became true | ||
PASS requestPermissionResult is "denied" | ||
PASS message.data is "denied" | ||
PASS receivedPostMessageResponse became true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
78 changes: 78 additions & 0 deletions
78
LayoutTests/http/tests/notifications/permission/service-worker-permissions-query.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="/resources/js-test-pre.js"></script> | ||
<script src="/resources/notifications-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
|
||
description("This test checks that Permissions::query() works for service workers") | ||
|
||
jsTestIsAsync = true; | ||
|
||
var expectedData = null; | ||
var receivedPostMessageResponse = true; | ||
|
||
navigator.serviceWorker.register('service-worker-permissions-query.js'); | ||
navigator.serviceWorker.addEventListener('message', (message) => { | ||
window.message = message; | ||
shouldBeEqualToString("message.data", expectedData); | ||
receivedPostMessageResponse = true; | ||
}); | ||
|
||
async function defaultTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "prompt"; | ||
navigator.serviceWorker.ready.then((registration) => { | ||
registration.active.postMessage(1); | ||
}); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
async function grantTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "granted"; | ||
internals.withUserGesture(() => { | ||
// Permission is granted by default when requestPermission() is called. | ||
window.Notification.requestPermission().then((result)=> { | ||
requestPermissionResult = result; | ||
shouldBeEqualToString("requestPermissionResult", "granted"); | ||
navigator.serviceWorker.ready.then((registration) => { | ||
registration.active.postMessage(2); | ||
}); | ||
}); | ||
}); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
async function denyTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "denied"; | ||
internals.withUserGesture(() => { | ||
testRunner.denyWebNotificationPermissionOnPrompt(testURL); | ||
window.Notification.requestPermission().then((result)=> { | ||
requestPermissionResult = result; | ||
shouldBeEqualToString("requestPermissionResult", "denied"); | ||
navigator.serviceWorker.ready.then((registration) => { | ||
registration.active.postMessage(3); | ||
}); | ||
}); | ||
}); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
(async function () { | ||
await defaultTest(); | ||
await grantTest(); | ||
await denyTest(); | ||
finishJSTest(); | ||
})(); | ||
|
||
</script> | ||
<script src="/resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
5 changes: 5 additions & 0 deletions
5
LayoutTests/http/tests/notifications/permission/service-worker-permissions-query.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
self.onmessage = (event) => { | ||
navigator.permissions.query({ name: "notifications" }).then((status) => { | ||
event.source.postMessage(status.state); | ||
}); | ||
}; |
9 changes: 9 additions & 0 deletions
9
LayoutTests/http/tests/notifications/permission/shared-worker-permission-query.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
onconnect = function (e) { | ||
var port = e.ports[0]; | ||
|
||
port.onmessage = function (e) { | ||
navigator.permissions.query({ name: "notifications" }).then((status) => { | ||
port.postMessage(status.state); | ||
}); | ||
}; | ||
} |
17 changes: 17 additions & 0 deletions
17
LayoutTests/http/tests/notifications/permission/shared-worker-permissions-query-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
This test checks that Permissions::query() works for shared workers | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS message.data is "prompt" | ||
PASS receivedPostMessageResponse became true | ||
PASS requestPermissionResult is "granted" | ||
PASS message.data is "granted" | ||
PASS receivedPostMessageResponse became true | ||
PASS requestPermissionResult is "denied" | ||
PASS message.data is "denied" | ||
PASS receivedPostMessageResponse became true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
72 changes: 72 additions & 0 deletions
72
LayoutTests/http/tests/notifications/permission/shared-worker-permissions-query.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="/resources/js-test-pre.js"></script> | ||
<script src="/resources/notifications-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
|
||
description("This test checks that Permissions::query() works for shared workers") | ||
|
||
jsTestIsAsync = true; | ||
|
||
var expectedData = null; | ||
var receivedPostMessageResponse = true; | ||
|
||
var worker = new SharedWorker('shared-worker-permission-query.js'); | ||
worker.port.onmessage = function(message) { | ||
window.message = message; | ||
shouldBeEqualToString("message.data", expectedData); | ||
receivedPostMessageResponse = true; | ||
} | ||
|
||
async function defaultTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "prompt"; | ||
worker.port.postMessage(1); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
async function grantTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "granted"; | ||
internals.withUserGesture(() => { | ||
// Permission is granted by default when requestPermission() is called. | ||
window.Notification.requestPermission().then((result)=> { | ||
requestPermissionResult = result; | ||
shouldBeEqualToString("requestPermissionResult", "granted"); | ||
worker.port.postMessage(2); | ||
}); | ||
}); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
async function denyTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "denied"; | ||
internals.withUserGesture(() => { | ||
testRunner.denyWebNotificationPermissionOnPrompt(testURL); | ||
window.Notification.requestPermission().then((result)=> { | ||
requestPermissionResult = result; | ||
shouldBeEqualToString("requestPermissionResult", "denied"); | ||
worker.port.postMessage(3); | ||
}); | ||
}); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
(async function () { | ||
await defaultTest(); | ||
await grantTest(); | ||
await denyTest(); | ||
finishJSTest(); | ||
})(); | ||
|
||
</script> | ||
<script src="/resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Source/WebCore/Modules/permissions/PermissionQuerySource.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) 2022 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <wtf/EnumTraits.h> | ||
|
||
namespace WebCore { | ||
|
||
enum class PermissionQuerySource : uint8_t { | ||
Window, | ||
DedicatedWorker, | ||
SharedWorker, | ||
ServiceWorker | ||
}; | ||
|
||
} // namespace WebCore | ||
|
||
namespace WTF { | ||
|
||
template<> struct EnumTraits<WebCore::PermissionQuerySource> { | ||
using values = EnumValues< | ||
WebCore::PermissionQuerySource, | ||
WebCore::PermissionQuerySource::Window, | ||
WebCore::PermissionQuerySource::DedicatedWorker, | ||
WebCore::PermissionQuerySource::SharedWorker, | ||
WebCore::PermissionQuerySource::ServiceWorker | ||
>; | ||
}; | ||
|
||
} // namespace WTF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.