Title: [224000] trunk/Source/WebCore
Revision
224000
Author
[email protected]
Date
2017-10-25 19:57:08 -0700 (Wed, 25 Oct 2017)

Log Message

messageEvent.source can also be a ServiceWorker
https://bugs.webkit.org/show_bug.cgi?id=178839

Reviewed by Brady Eidson.

messageEvent.source can also be a ServiceWorker:
- https://html.spec.whatwg.org/multipage/comms.html#messageeventsource

This enables calling postMessage() from a ServiceWorker via Bug 178794.

* dom/MessageEvent.cpp:
(WebCore::MessageEvent::source const): Deleted.
* dom/MessageEvent.h:
* dom/MessageEvent.idl:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (223999 => 224000)


--- trunk/Source/WebCore/ChangeLog	2017-10-26 00:30:03 UTC (rev 223999)
+++ trunk/Source/WebCore/ChangeLog	2017-10-26 02:57:08 UTC (rev 224000)
@@ -1,3 +1,20 @@
+2017-10-25  Chris Dumez  <[email protected]>
+
+        messageEvent.source can also be a ServiceWorker
+        https://bugs.webkit.org/show_bug.cgi?id=178839
+
+        Reviewed by Brady Eidson.
+
+        messageEvent.source can also be a ServiceWorker:
+        - https://html.spec.whatwg.org/multipage/comms.html#messageeventsource
+
+        This enables calling postMessage() from a ServiceWorker via Bug 178794.
+
+        * dom/MessageEvent.cpp:
+        (WebCore::MessageEvent::source const): Deleted.
+        * dom/MessageEvent.h:
+        * dom/MessageEvent.idl:
+
 2017-10-25  Ryosuke Niwa  <[email protected]>
 
         Style::Scope::flushPendingUpdate() can replace the entire document in XSLTProcessor::createDocumentFromSource

Modified: trunk/Source/WebCore/dom/MessageEvent.cpp (223999 => 224000)


--- trunk/Source/WebCore/dom/MessageEvent.cpp	2017-10-26 00:30:03 UTC (rev 223999)
+++ trunk/Source/WebCore/dom/MessageEvent.cpp	2017-10-26 02:57:08 UTC (rev 224000)
@@ -150,17 +150,6 @@
     m_ports = WTFMove(ports);
 }
 
-EventTarget* MessageEvent::source() const
-{
-    if (!m_source)
-        return nullptr;
-
-    return WTF::switchOn(m_source.value(),
-        [] (const RefPtr<DOMWindow>& window) -> EventTarget* { return const_cast<DOMWindow*>(window.get()); },
-        [] (const RefPtr<MessagePort>& messagePort) -> EventTarget* { return const_cast<MessagePort*>(messagePort.get()); }
-    );
-}
-
 RefPtr<SerializedScriptValue> MessageEvent::trySerializeData(ExecState* exec)
 {
     ASSERT(!m_dataAsScriptValue.hasNoValue());

Modified: trunk/Source/WebCore/dom/MessageEvent.h (223999 => 224000)


--- trunk/Source/WebCore/dom/MessageEvent.h	2017-10-26 00:30:03 UTC (rev 223999)
+++ trunk/Source/WebCore/dom/MessageEvent.h	2017-10-26 02:57:08 UTC (rev 224000)
@@ -31,6 +31,7 @@
 #include "Event.h"
 #include "MessagePort.h"
 #include "SerializedScriptValue.h"
+#include "ServiceWorker.h"
 #include <bindings/ScriptValue.h>
 #include <wtf/Variant.h>
 
@@ -38,7 +39,11 @@
 
 class Blob;
 
+#if ENABLE(SERVICE_WORKER)
+using MessageEventSource = Variant<RefPtr<DOMWindow>, RefPtr<MessagePort>, RefPtr<ServiceWorker>>;
+#else
 using MessageEventSource = Variant<RefPtr<DOMWindow>, RefPtr<MessagePort>>;
+#endif
 
 class MessageEvent final : public Event {
 public:
@@ -64,7 +69,7 @@
 
     const String& origin() const { return m_origin; }
     const String& lastEventId() const { return m_lastEventId; }
-    EventTarget* source() const;
+    const std::optional<MessageEventSource>& source() const { return m_source; }
     const Vector<RefPtr<MessagePort>>& ports() const { return m_ports; }
 
     // FIXME: Remove this when we have custom ObjC binding support.

Modified: trunk/Source/WebCore/dom/MessageEvent.idl (223999 => 224000)


--- trunk/Source/WebCore/dom/MessageEvent.idl	2017-10-26 00:30:03 UTC (rev 223999)
+++ trunk/Source/WebCore/dom/MessageEvent.idl	2017-10-26 02:57:08 UTC (rev 224000)
@@ -26,6 +26,12 @@
  *
  */
 
+#if defined(ENABLE_SERVICE_WORKER) && ENABLE_SERVICE_WORKER
+typedef (DOMWindow or MessagePort or ServiceWorker) MessageEventSource;
+#else
+typedef (DOMWindow or MessagePort) MessageEventSource;
+#endif
+
 [
     Constructor(DOMString type, optional MessageEventInit eventInitDict),
     ConstructorCallWith=ScriptState,
@@ -33,12 +39,12 @@
 ] interface MessageEvent : Event {
     readonly attribute USVString origin;
     readonly attribute DOMString lastEventId;
-    readonly attribute EventTarget? source;
+    readonly attribute MessageEventSource? source;
     [CachedAttribute, CustomGetter] readonly attribute any data;
     readonly attribute FrozenArray<MessagePort> ports;
 
     [CallWith=ScriptState] void initMessageEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false,
-        optional any data = "" optional USVString originArg = "", optional DOMString lastEventId = "", optional (DOMWindow or MessagePort)? source = null,
+        optional any data = "" optional USVString originArg = "", optional DOMString lastEventId = "", optional MessageEventSource? source = null,
         optional sequence<MessagePort> messagePorts = []);
 };
 
@@ -46,6 +52,6 @@
       any data = ""
       USVString origin = "";
       DOMString lastEventId = "";
-      (DOMWindow or MessagePort)? source = null;
+      MessageEventSource? source = null;
       sequence<MessagePort> ports = [];
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to