Title: [292216] trunk
Revision
292216
Author
[email protected]
Date
2022-04-01 04:48:47 -0700 (Fri, 01 Apr 2022)

Log Message

Notification should be exposed to ServiceWorker contexts
https://bugs.webkit.org/show_bug.cgi?id=238548

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/notifications/idlharness.https.any.serviceworker-expected.txt:

Source/WebCore:

Mark Notification as exposed in ServiceWorker (not yet Worker as it would not be functional).
Add a dedicated createForServiceWorker routine that takes a registration URL to create persistent permissions.
Throw an exception in case of calling Notification constructor directly in a ServiceWorkerGlobalScope, as per spec.

Covered by updated and existing tests.

* Modules/notifications/Notification.cpp:
* Modules/notifications/Notification.h:
* Modules/notifications/Notification.idl:
* workers/service/ServiceWorkerRegistration.cpp:

LayoutTests:

* http/tests/workers/service/resources/shownotification-worker.js:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (292215 => 292216)


--- trunk/LayoutTests/ChangeLog	2022-04-01 11:00:28 UTC (rev 292215)
+++ trunk/LayoutTests/ChangeLog	2022-04-01 11:48:47 UTC (rev 292216)
@@ -1,3 +1,12 @@
+2022-04-01  Youenn Fablet  <[email protected]>
+
+        Notification should be exposed to ServiceWorker contexts
+        https://bugs.webkit.org/show_bug.cgi?id=238548
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/workers/service/resources/shownotification-worker.js:
+
 2022-04-01  Carlos Garcia Campos  <[email protected]>
 
         Add support for element.computedStyleMap()

Modified: trunk/LayoutTests/http/tests/workers/service/resources/shownotification-worker.js (292215 => 292216)


--- trunk/LayoutTests/http/tests/workers/service/resources/shownotification-worker.js	2022-04-01 11:00:28 UTC (rev 292215)
+++ trunk/LayoutTests/http/tests/workers/service/resources/shownotification-worker.js	2022-04-01 11:48:47 UTC (rev 292216)
@@ -29,8 +29,26 @@
         body = components[2];
         tag = components[3];
     }
-    
+
+    if (!self.Notification) {
+        await messageClients("showFailed due to Notification not being exposed");
+        return;
+    }
     try {
+         new Notification(title, {
+            body: body,
+            tag: tag
+        });
+        await messageClients("showFailed due to Notification created from constructor");
+        return;
+    } catch(error) {
+        if (!(error instanceof TypeError)) {
+            await messageClients("Notification constructor should throw a TypeError");
+            return;
+        }
+    }
+
+    try {
         await registration.showNotification(title, {
             body: body,
             tag: tag

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (292215 => 292216)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-04-01 11:00:28 UTC (rev 292215)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-04-01 11:48:47 UTC (rev 292216)
@@ -1,3 +1,12 @@
+2022-04-01  Youenn Fablet  <[email protected]>
+
+        Notification should be exposed to ServiceWorker contexts
+        https://bugs.webkit.org/show_bug.cgi?id=238548
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/notifications/idlharness.https.any.serviceworker-expected.txt:
+
 2022-04-01  Carlos Garcia Campos  <[email protected]>
 
         Add support for element.computedStyleMap()

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/notifications/idlharness.https.any.serviceworker-expected.txt (292215 => 292216)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/notifications/idlharness.https.any.serviceworker-expected.txt	2022-04-01 11:00:28 UTC (rev 292215)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/notifications/idlharness.https.any.serviceworker-expected.txt	2022-04-01 11:48:47 UTC (rev 292216)
@@ -6,35 +6,35 @@
 PASS Partial interface ServiceWorkerGlobalScope: original interface defined
 PASS Partial interface ServiceWorkerGlobalScope: member names are unique
 PASS WorkerGlobalScope includes WindowOrWorkerGlobalScope: member names are unique
-FAIL Notification interface: existence and properties of interface object assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface object length assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface object name assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: existence and properties of interface prototype object assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute permission assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: member requestPermission undefined is not an Object. (evaluating 'member.name in this.get_interface_object()')
-FAIL Notification interface: attribute maxActions assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute onclick assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute onshow assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute onerror assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute onclose assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute title assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute dir assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute lang assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute body assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute tag assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute image assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute icon assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute badge assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute vibrate assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute timestamp assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute renotify assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute silent assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute requireInteraction assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute data assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: attribute actions assert_own_property: self does not have own property "Notification" expected property "Notification" missing
-FAIL Notification interface: operation close() assert_own_property: self does not have own property "Notification" expected property "Notification" missing
+PASS Notification interface: existence and properties of interface object
+PASS Notification interface object length
+PASS Notification interface object name
+PASS Notification interface: existence and properties of interface prototype object
+PASS Notification interface: existence and properties of interface prototype object's "constructor" property
+PASS Notification interface: existence and properties of interface prototype object's @@unscopables property
+PASS Notification interface: attribute permission
+PASS Notification interface: member requestPermission
+FAIL Notification interface: attribute maxActions assert_own_property: The interface object must have a property "maxActions" expected property "maxActions" missing
+PASS Notification interface: attribute onclick
+PASS Notification interface: attribute onshow
+PASS Notification interface: attribute onerror
+PASS Notification interface: attribute onclose
+PASS Notification interface: attribute title
+PASS Notification interface: attribute dir
+PASS Notification interface: attribute lang
+PASS Notification interface: attribute body
+PASS Notification interface: attribute tag
+FAIL Notification interface: attribute image assert_true: The prototype object must have a property "image" expected true got false
+PASS Notification interface: attribute icon
+FAIL Notification interface: attribute badge assert_true: The prototype object must have a property "badge" expected true got false
+FAIL Notification interface: attribute vibrate assert_true: The prototype object must have a property "vibrate" expected true got false
+FAIL Notification interface: attribute timestamp assert_true: The prototype object must have a property "timestamp" expected true got false
+FAIL Notification interface: attribute renotify assert_true: The prototype object must have a property "renotify" expected true got false
+FAIL Notification interface: attribute silent assert_true: The prototype object must have a property "silent" expected true got false
+FAIL Notification interface: attribute requireInteraction assert_true: The prototype object must have a property "requireInteraction" expected true got false
+FAIL Notification interface: attribute data assert_true: The prototype object must have a property "data" expected true got false
+FAIL Notification interface: attribute actions assert_true: The prototype object must have a property "actions" expected true got false
+PASS Notification interface: operation close()
 PASS NotificationEvent interface: existence and properties of interface object
 PASS NotificationEvent interface object length
 PASS NotificationEvent interface object name

Modified: trunk/Source/WebCore/ChangeLog (292215 => 292216)


--- trunk/Source/WebCore/ChangeLog	2022-04-01 11:00:28 UTC (rev 292215)
+++ trunk/Source/WebCore/ChangeLog	2022-04-01 11:48:47 UTC (rev 292216)
@@ -1,3 +1,21 @@
+2022-04-01  Youenn Fablet  <[email protected]>
+
+        Notification should be exposed to ServiceWorker contexts
+        https://bugs.webkit.org/show_bug.cgi?id=238548
+
+        Reviewed by Chris Dumez.
+
+        Mark Notification as exposed in ServiceWorker (not yet Worker as it would not be functional).
+        Add a dedicated createForServiceWorker routine that takes a registration URL to create persistent permissions.
+        Throw an exception in case of calling Notification constructor directly in a ServiceWorkerGlobalScope, as per spec.
+
+        Covered by updated and existing tests.
+
+        * Modules/notifications/Notification.cpp:
+        * Modules/notifications/Notification.h:
+        * Modules/notifications/Notification.idl:
+        * workers/service/ServiceWorkerRegistration.cpp:
+
 2022-04-01  Philippe Normand  <[email protected]>
 
         [GStreamer][WebRTC] Improve RTP stats gathering

Modified: trunk/Source/WebCore/Modules/notifications/Notification.cpp (292215 => 292216)


--- trunk/Source/WebCore/Modules/notifications/Notification.cpp	2022-04-01 11:00:28 UTC (rev 292215)
+++ trunk/Source/WebCore/Modules/notifications/Notification.cpp	2022-04-01 11:48:47 UTC (rev 292216)
@@ -53,15 +53,25 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(Notification);
 
-Ref<Notification> Notification::create(ScriptExecutionContext& context, String&& title, Options&& options, const URL& serviceWorkerRegistrationURL)
+ExceptionOr<Ref<Notification>> Notification::create(ScriptExecutionContext& context, String&& title, Options&& options)
 {
+    if (context.isServiceWorkerGlobalScope())
+        return Exception { TypeError, "Notification cannot be directly created in a ServiceWorkerGlobalScope"_s };
+
     auto notification = adoptRef(*new Notification(context, WTFMove(title), WTFMove(options)));
-    notification->m_serviceWorkerRegistrationURL = serviceWorkerRegistrationURL;
     notification->suspendIfNeeded();
     notification->showSoon();
     return notification;
 }
 
+Ref<Notification> Notification::createForServiceWorker(ScriptExecutionContext& context, String&& title, Options&& options, const URL& serviceWorkerRegistrationURL)
+{
+    auto notification = adoptRef(*new Notification(context, WTFMove(title), WTFMove(options)));
+    notification->m_serviceWorkerRegistrationURL = serviceWorkerRegistrationURL;
+    notification->suspendIfNeeded();
+    return notification;
+}
+
 Ref<Notification> Notification::create(ScriptExecutionContext& context, NotificationData&& data)
 {
     Options options { data.direction, WTFMove(data.language), WTFMove(data.body), WTFMove(data.tag), WTFMove(data.iconURL) };

Modified: trunk/Source/WebCore/Modules/notifications/Notification.h (292215 => 292216)


--- trunk/Source/WebCore/Modules/notifications/Notification.h	2022-04-01 11:00:28 UTC (rev 292215)
+++ trunk/Source/WebCore/Modules/notifications/Notification.h	2022-04-01 11:48:47 UTC (rev 292216)
@@ -64,7 +64,10 @@
         String tag;
         String icon;
     };
-    static Ref<Notification> create(ScriptExecutionContext&, String&& title, Options&&, const URL& serviceWorkerRegistrationURL = { });
+    // For JS constructor only.
+    static ExceptionOr<Ref<Notification>> create(ScriptExecutionContext&, String&& title, Options&&);
+
+    static Ref<Notification> createForServiceWorker(ScriptExecutionContext&, String&& title, Options&&, const URL&);
     static Ref<Notification> create(ScriptExecutionContext&, NotificationData&&);
 
     WEBCORE_EXPORT virtual ~Notification();

Modified: trunk/Source/WebCore/Modules/notifications/Notification.idl (292215 => 292216)


--- trunk/Source/WebCore/Modules/notifications/Notification.idl	2022-04-01 11:00:28 UTC (rev 292215)
+++ trunk/Source/WebCore/Modules/notifications/Notification.idl	2022-04-01 11:48:47 UTC (rev 292216)
@@ -29,7 +29,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-// FIXME: Notification is specified to be exposed on both Window and Worker.
+// FIXME: Notification should be exposed to all Worker contexts, not just ServiceWorker.
 // https://notifications.spec.whatwg.org/#notification
 [
     Conditional=NOTIFICATIONS,
@@ -36,12 +36,12 @@
     ActiveDOMObject,
     EnabledBySetting=NotificationsEnabled,
     ExportMacro=WEBCORE_EXPORT,
-    Exposed=Window,
+    Exposed=(Window,ServiceWorker)
 ] interface Notification : EventTarget {
-    [CallWith=CurrentDocument] constructor(DOMString title, optional NotificationOptions options);
+    [CallWith=CurrentScriptExecutionContext] constructor(DOMString title, optional NotificationOptions options);
 
-    [CallWith=CurrentDocument] static readonly attribute NotificationPermission permission;
-    [CallWith=CurrentDocument] static Promise<NotificationPermission> requestPermission(optional NotificationPermissionCallback? deprecatedCallback);
+    [CallWith=CurrentScriptExecutionContext] static readonly attribute NotificationPermission permission;
+    [Exposed=Window, CallWith=CurrentDocument] static Promise<NotificationPermission> requestPermission(optional NotificationPermissionCallback? deprecatedCallback);
 
     // static readonly attribute unsigned long maxActions;
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp (292215 => 292216)


--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp	2022-04-01 11:00:28 UTC (rev 292215)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp	2022-04-01 11:48:47 UTC (rev 292216)
@@ -292,7 +292,8 @@
 
     // The Notification is kept alive by virtue of being show()'n soon.
     // FIXME: When implementing getNotifications(), store this Notification in the registration's notification list.
-    auto notification = Notification::create(context, WTFMove(title), WTFMove(options), m_registrationData.scopeURL);
+    auto notification = Notification::createForServiceWorker(context, WTFMove(title), WTFMove(options), m_registrationData.scopeURL);
+    notification->showSoon();
 
     context.eventLoop().queueTask(TaskSource::DOMManipulation, [promise = WTFMove(promise)]() mutable {
         promise.resolve();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to