Title: [258850] trunk
Revision
258850
Author
[email protected]
Date
2020-03-23 09:51:24 -0700 (Mon, 23 Mar 2020)

Log Message

Port window.postMessage to the HTML event loop
https://bugs.webkit.org/show_bug.cgi?id=209359

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline test now that the logging ordering is slightly different.

* web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects-expected.txt:

Source/WebCore:

Port window.postMessage to the HTML event loop instead of using a 0-timer.

* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::willPostMessageImpl):
(WebCore::InspectorInstrumentation::didPostMessageImpl):
(WebCore::InspectorInstrumentation::didFailPostMessageImpl):
(WebCore::InspectorInstrumentation::willDispatchPostMessageImpl):
(WebCore::InspectorInstrumentation::didDispatchPostMessageImpl):
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::willPostMessage):
(WebCore::InspectorInstrumentation::didPostMessage):
(WebCore::InspectorInstrumentation::didFailPostMessage):
(WebCore::InspectorInstrumentation::willDispatchPostMessage):
(WebCore::InspectorInstrumentation::didDispatchPostMessage):
* inspector/agents/WebDebuggerAgent.cpp:
(WebCore::WebDebuggerAgent::willPostMessage):
(WebCore::WebDebuggerAgent::didPostMessage):
(WebCore::WebDebuggerAgent::didFailPostMessage):
(WebCore::WebDebuggerAgent::willDispatchPostMessage):
(WebCore::WebDebuggerAgent::didDispatchPostMessage):
(WebCore::WebDebuggerAgent::didClearAsyncStackTraceData):
* inspector/agents/WebDebuggerAgent.h:
* page/DOMWindow.cpp:
(WebCore::DOMWindow::postMessage):
(WebCore::PostMessageTimer::PostMessageTimer): Deleted.
(WebCore::PostMessageTimer::event): Deleted.
(WebCore::PostMessageTimer::targetOrigin const): Deleted.
(WebCore::PostMessageTimer::stackTrace const): Deleted.
(WebCore::DOMWindow::postMessageTimerFired): Deleted.
* page/DOMWindow.h:

LayoutTests:

Update tests so that it does not run postMessage tests in parallel on the 2 different-origin iframes,
since the ordering would not be guaranteed and it would cause flakiness.

* http/tests/security/postMessage/resources/recv.js:
(recv):
* http/tests/security/postMessage/target-origin-expected.txt:
* http/tests/security/postMessage/target-origin.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (258849 => 258850)


--- trunk/LayoutTests/ChangeLog	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/LayoutTests/ChangeLog	2020-03-23 16:51:24 UTC (rev 258850)
@@ -1,3 +1,18 @@
+2020-03-23  Chris Dumez  <[email protected]>
+
+        Port window.postMessage to the HTML event loop
+        https://bugs.webkit.org/show_bug.cgi?id=209359
+
+        Reviewed by Alex Christensen.
+
+        Update tests so that it does not run postMessage tests in parallel on the 2 different-origin iframes,
+        since the ordering would not be guaranteed and it would cause flakiness.
+
+        * http/tests/security/postMessage/resources/recv.js:
+        (recv):
+        * http/tests/security/postMessage/target-origin-expected.txt:
+        * http/tests/security/postMessage/target-origin.html:
+
 2020-03-23  Per Arne Vollan  <[email protected]>
 
         [iOS] Deny mach lookup access to icon services

Modified: trunk/LayoutTests/http/tests/security/postMessage/resources/recv.js (258849 => 258850)


--- trunk/LayoutTests/http/tests/security/postMessage/resources/recv.js	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/LayoutTests/http/tests/security/postMessage/resources/recv.js	2020-03-23 16:51:24 UTC (rev 258850)
@@ -9,6 +9,9 @@
 
     log(msg);
 
+    if (e.data.match(/data=""
+        runNextTest();
+
     if (e.data.match(/data="" && window.testRunner)
         testRunner.notifyDone();
 }

Modified: trunk/LayoutTests/http/tests/security/postMessage/target-origin-expected.txt (258849 => 258850)


--- trunk/LayoutTests/http/tests/security/postMessage/target-origin-expected.txt	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/LayoutTests/http/tests/security/postMessage/target-origin-expected.txt	2020-03-23 16:51:24 UTC (rev 258850)
@@ -17,7 +17,6 @@
 window.location.href = ""
 
 waiting...
-Error sending message to //. SyntaxError: The string did not match the expected pattern.
 Received message: data="" message: data="" origin=http://localhost:8000" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
 Received message: data="" message: data="" origin=http://localhost:8000/" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
 Received message: data="" message: data="" origin=http://localhost:8000/foo" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
@@ -25,5 +24,7 @@
 Received message: data="" message: data="" origin=http://localhost:8000/foo?bar#baz" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
 Received message: data="" message: data="" origin=http://user:pass@localhost:8000/foo?bar#baz" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
 Received message: data="" message: data="" origin=*" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
+Received message: data="" message: data="" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
+Error sending message to //. SyntaxError: The string did not match the expected pattern.
 Received message: data="" message: data="" origin=/" origin="http://127.0.0.1:8000"" origin="http://127.0.0.1:8000"
-Received message: data="" message: data="" origin="http://127.0.0.1:8000"" origin="http://localhost:8000"
+Received message: data="" message: data="" origin="http://127.0.0.1:8000"" origin="http://127.0.0.1:8000"

Modified: trunk/LayoutTests/http/tests/security/postMessage/target-origin.html (258849 => 258850)


--- trunk/LayoutTests/http/tests/security/postMessage/target-origin.html	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/LayoutTests/http/tests/security/postMessage/target-origin.html	2020-03-23 16:51:24 UTC (rev 258850)
@@ -18,9 +18,20 @@
     }
 }
 
+function runNextTest() {
+    var win127 = document.getElementById('iframe-127').contentWindow;
+
+    // Should succeed:
+    tryPostMessage(win127, "/");
+
+    // Should throw syntax error:
+    tryPostMessage(win127, "//");
+
+    win127.postMessage('done', '*');
+}
+
 function test() {
     var winLocalhost = document.getElementById('iframe-localhost').contentWindow;
-    var win127= document.getElementById('iframe-127').contentWindow;
 
     // Should succeed:
     tryPostMessage(winLocalhost, "http://localhost:8000");
@@ -30,7 +41,6 @@
     tryPostMessage(winLocalhost, "http://localhost:8000/foo?bar#baz");
     tryPostMessage(winLocalhost, "http://user:pass@localhost:8000/foo?bar#baz");
     tryPostMessage(winLocalhost, "*");
-    tryPostMessage(win127, "/");
 
     // Should fail:
     tryPostMessage(winLocalhost, "/");
@@ -43,9 +53,8 @@
     // Should throw syntax error:
     tryPostMessage(winLocalhost, null);
     tryPostMessage(winLocalhost, undefined);
-    tryPostMessage(win127, "//");
-
-    winLocalhost.postMessage('done', '*');
+    
+    winLocalhost.postMessage('runNextTest', '*');
 }
 </script>
 <body _onload_="test()">

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (258849 => 258850)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-03-23 16:51:24 UTC (rev 258850)
@@ -1,3 +1,14 @@
+2020-03-23  Chris Dumez  <[email protected]>
+
+        Port window.postMessage to the HTML event loop
+        https://bugs.webkit.org/show_bug.cgi?id=209359
+
+        Reviewed by Alex Christensen.
+
+        Rebaseline test now that the logging ordering is slightly different.
+
+        * web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects-expected.txt:
+
 2020-03-20  youenn fablet  <[email protected]>
 
         Add routines to check about:blank and about:srcdoc URLs

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects-expected.txt (258849 => 258850)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects-expected.txt	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects-expected.txt	2020-03-23 16:51:24 UTC (rev 258850)
@@ -7,12 +7,12 @@
 CONSOLE MESSAGE: line 287: Blocked a frame with origin "http://localhost:8800" from accessing a frame with origin "http://127.0.0.1:8800". Protocols, domains, and ports must match.
 CONSOLE MESSAGE: line 302: Blocked a frame with origin "http://localhost:8800" from accessing a frame with origin "http://127.0.0.1:8800". Protocols, domains, and ports must match.
 CONSOLE MESSAGE: line 302: Blocked a frame with origin "http://localhost:8800" from accessing a frame with origin "http://127.0.0.1:8800". Protocols, domains, and ports must match.
+CONSOLE MESSAGE: Unable to post message to http://does-not.exist. Recipient has origin http://localhost:8800.
+
 CONSOLE MESSAGE: Unable to post message to http://does-not.exist. Recipient has origin http://127.0.0.1:8800.
 
 CONSOLE MESSAGE: Unable to post message to http://localhost:8800. Recipient has origin http://127.0.0.1:8800.
 
-CONSOLE MESSAGE: Unable to post message to http://does-not.exist. Recipient has origin http://localhost:8800.
-
 CONSOLE MESSAGE: Unable to post message to http://does-not.exist. Recipient has origin http://127.0.0.1:8800.
 
 CONSOLE MESSAGE: Unable to post message to http://localhost:8800. Recipient has origin http://127.0.0.1:8800.

Modified: trunk/Source/WebCore/ChangeLog (258849 => 258850)


--- trunk/Source/WebCore/ChangeLog	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/Source/WebCore/ChangeLog	2020-03-23 16:51:24 UTC (rev 258850)
@@ -1,3 +1,41 @@
+2020-03-23  Chris Dumez  <[email protected]>
+
+        Port window.postMessage to the HTML event loop
+        https://bugs.webkit.org/show_bug.cgi?id=209359
+
+        Reviewed by Alex Christensen.
+
+        Port window.postMessage to the HTML event loop instead of using a 0-timer.
+
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::willPostMessageImpl):
+        (WebCore::InspectorInstrumentation::didPostMessageImpl):
+        (WebCore::InspectorInstrumentation::didFailPostMessageImpl):
+        (WebCore::InspectorInstrumentation::willDispatchPostMessageImpl):
+        (WebCore::InspectorInstrumentation::didDispatchPostMessageImpl):
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::willPostMessage):
+        (WebCore::InspectorInstrumentation::didPostMessage):
+        (WebCore::InspectorInstrumentation::didFailPostMessage):
+        (WebCore::InspectorInstrumentation::willDispatchPostMessage):
+        (WebCore::InspectorInstrumentation::didDispatchPostMessage):
+        * inspector/agents/WebDebuggerAgent.cpp:
+        (WebCore::WebDebuggerAgent::willPostMessage):
+        (WebCore::WebDebuggerAgent::didPostMessage):
+        (WebCore::WebDebuggerAgent::didFailPostMessage):
+        (WebCore::WebDebuggerAgent::willDispatchPostMessage):
+        (WebCore::WebDebuggerAgent::didDispatchPostMessage):
+        (WebCore::WebDebuggerAgent::didClearAsyncStackTraceData):
+        * inspector/agents/WebDebuggerAgent.h:
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::postMessage):
+        (WebCore::PostMessageTimer::PostMessageTimer): Deleted.
+        (WebCore::PostMessageTimer::event): Deleted.
+        (WebCore::PostMessageTimer::targetOrigin const): Deleted.
+        (WebCore::PostMessageTimer::stackTrace const): Deleted.
+        (WebCore::DOMWindow::postMessageTimerFired): Deleted.
+        * page/DOMWindow.h:
+
 2020-03-23  Zalan Bujtas  <[email protected]>
 
         [LFC] Layout::Box::initialContainingBlock() should return const InitialContainingBlock&

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (258849 => 258850)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2020-03-23 16:51:24 UTC (rev 258850)
@@ -361,30 +361,37 @@
     return false;
 }
 
-void InspectorInstrumentation::didPostMessageImpl(InstrumentingAgents& instrumentingAgents, const TimerBase& timer, JSC::JSGlobalObject& state)
+int InspectorInstrumentation::willPostMessageImpl(InstrumentingAgents& instrumentingAgents)
 {
     if (auto* webDebuggerAgent = instrumentingAgents.webDebuggerAgent())
-        webDebuggerAgent->didPostMessage(timer, state);
+        return webDebuggerAgent->willPostMessage();
+    return 0;
 }
 
-void InspectorInstrumentation::didFailPostMessageImpl(InstrumentingAgents& instrumentingAgents, const TimerBase& timer)
+void InspectorInstrumentation::didPostMessageImpl(InstrumentingAgents& instrumentingAgents, int postMessageIdentifier, JSC::JSGlobalObject& state)
 {
     if (auto* webDebuggerAgent = instrumentingAgents.webDebuggerAgent())
-        webDebuggerAgent->didFailPostMessage(timer);
+        webDebuggerAgent->didPostMessage(postMessageIdentifier, state);
 }
 
-void InspectorInstrumentation::willDispatchPostMessageImpl(InstrumentingAgents& instrumentingAgents, const TimerBase& timer)
+void InspectorInstrumentation::didFailPostMessageImpl(InstrumentingAgents& instrumentingAgents, int postMessageIdentifier)
 {
     if (auto* webDebuggerAgent = instrumentingAgents.webDebuggerAgent())
-        webDebuggerAgent->willDispatchPostMessage(timer);
+        webDebuggerAgent->didFailPostMessage(postMessageIdentifier);
 }
 
-void InspectorInstrumentation::didDispatchPostMessageImpl(InstrumentingAgents& instrumentingAgents, const TimerBase& timer)
+void InspectorInstrumentation::willDispatchPostMessageImpl(InstrumentingAgents& instrumentingAgents, int postMessageIdentifier)
 {
     if (auto* webDebuggerAgent = instrumentingAgents.webDebuggerAgent())
-        webDebuggerAgent->didDispatchPostMessage(timer);
+        webDebuggerAgent->willDispatchPostMessage(postMessageIdentifier);
 }
 
+void InspectorInstrumentation::didDispatchPostMessageImpl(InstrumentingAgents& instrumentingAgents, int postMessageIdentifier)
+{
+    if (auto* webDebuggerAgent = instrumentingAgents.webDebuggerAgent())
+        webDebuggerAgent->didDispatchPostMessage(postMessageIdentifier);
+}
+
 void InspectorInstrumentation::willCallFunctionImpl(InstrumentingAgents& instrumentingAgents, const String& scriptName, int scriptLine, int scriptColumn, ScriptExecutionContext* context)
 {
     if (auto* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (258849 => 258850)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2020-03-23 16:51:24 UTC (rev 258850)
@@ -155,10 +155,11 @@
     static void didInstallTimer(ScriptExecutionContext&, int timerId, Seconds timeout, bool singleShot);
     static void didRemoveTimer(ScriptExecutionContext&, int timerId);
 
-    static void didPostMessage(Frame&, TimerBase&, JSC::JSGlobalObject&);
-    static void didFailPostMessage(Frame&, TimerBase&);
-    static void willDispatchPostMessage(Frame&, TimerBase&);
-    static void didDispatchPostMessage(Frame&, TimerBase&);
+    static int willPostMessage(Frame&);
+    static void didPostMessage(Frame&, int postTimerIdentifier, JSC::JSGlobalObject&);
+    static void didFailPostMessage(Frame&, int postTimerIdentifier);
+    static void willDispatchPostMessage(Frame&, int postTimerIdentifier);
+    static void didDispatchPostMessage(Frame&, int postTimerIdentifier);
 
     static void willCallFunction(ScriptExecutionContext*, const String& scriptName, int scriptLine, int scriptColumn);
     static void didCallFunction(ScriptExecutionContext*);
@@ -373,10 +374,11 @@
     static void didInstallTimerImpl(InstrumentingAgents&, int timerId, Seconds timeout, bool singleShot, ScriptExecutionContext&);
     static void didRemoveTimerImpl(InstrumentingAgents&, int timerId, ScriptExecutionContext&);
 
-    static void didPostMessageImpl(InstrumentingAgents&, const TimerBase&, JSC::JSGlobalObject&);
-    static void didFailPostMessageImpl(InstrumentingAgents&, const TimerBase&);
-    static void willDispatchPostMessageImpl(InstrumentingAgents&, const TimerBase&);
-    static void didDispatchPostMessageImpl(InstrumentingAgents&, const TimerBase&);
+    static int willPostMessageImpl(InstrumentingAgents&);
+    static void didPostMessageImpl(InstrumentingAgents&, int postMessageIdentifier, JSC::JSGlobalObject&);
+    static void didFailPostMessageImpl(InstrumentingAgents&, int postMessageIdentifier);
+    static void willDispatchPostMessageImpl(InstrumentingAgents&, int postMessageIdentifier);
+    static void didDispatchPostMessageImpl(InstrumentingAgents&, int postMessageIdentifier);
 
     static void willCallFunctionImpl(InstrumentingAgents&, const String& scriptName, int scriptLine, int scriptColumn, ScriptExecutionContext*);
     static void didCallFunctionImpl(InstrumentingAgents&, ScriptExecutionContext*);
@@ -807,32 +809,40 @@
     return false;
 }
 
-inline void InspectorInstrumentation::didPostMessage(Frame& frame, TimerBase& timer, JSC::JSGlobalObject& state)
+inline int InspectorInstrumentation::willPostMessage(Frame& frame)
 {
+    FAST_RETURN_IF_NO_FRONTENDS(0);
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
+        return willPostMessageImpl(*instrumentingAgents);
+    return 0;
+}
+
+inline void InspectorInstrumentation::didPostMessage(Frame& frame, int postMessageIdentifier, JSC::JSGlobalObject& state)
+{
     FAST_RETURN_IF_NO_FRONTENDS(void());
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
-        didPostMessageImpl(*instrumentingAgents, timer, state);
+        didPostMessageImpl(*instrumentingAgents, postMessageIdentifier, state);
 }
 
-inline void InspectorInstrumentation::didFailPostMessage(Frame& frame, TimerBase& timer)
+inline void InspectorInstrumentation::didFailPostMessage(Frame& frame, int postMessageIdentifier)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
-        didFailPostMessageImpl(*instrumentingAgents, timer);
+        didFailPostMessageImpl(*instrumentingAgents, postMessageIdentifier);
 }
 
-inline void InspectorInstrumentation::willDispatchPostMessage(Frame& frame, TimerBase& timer)
+inline void InspectorInstrumentation::willDispatchPostMessage(Frame& frame, int postMessageIdentifier)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
-        willDispatchPostMessageImpl(*instrumentingAgents, timer);
+        willDispatchPostMessageImpl(*instrumentingAgents, postMessageIdentifier);
 }
 
-inline void InspectorInstrumentation::didDispatchPostMessage(Frame& frame, TimerBase& timer)
+inline void InspectorInstrumentation::didDispatchPostMessage(Frame& frame, int postMessageIdentifier)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
-        didDispatchPostMessageImpl(*instrumentingAgents, timer);
+        didDispatchPostMessageImpl(*instrumentingAgents, postMessageIdentifier);
 }
 
 inline void InspectorInstrumentation::willCallFunction(ScriptExecutionContext* context, const String& scriptName, int scriptLine, int scriptColumn)

Modified: trunk/Source/WebCore/inspector/agents/WebDebuggerAgent.cpp (258849 => 258850)


--- trunk/Source/WebCore/inspector/agents/WebDebuggerAgent.cpp	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/Source/WebCore/inspector/agents/WebDebuggerAgent.cpp	2020-03-23 16:51:24 UTC (rev 258850)
@@ -112,55 +112,67 @@
     willDispatchAsyncCall(InspectorDebuggerAgent::AsyncCallType::EventListener, it->value);
 }
 
-void WebDebuggerAgent::didPostMessage(const TimerBase& timer, JSC::JSGlobalObject& state)
+int WebDebuggerAgent::willPostMessage()
 {
     if (!breakpointsActive())
+        return 0;
+
+    auto postMessageIdentifier = m_nextPostMessageIdentifier++;
+    m_postMessageTasks.add(postMessageIdentifier);
+    return postMessageIdentifier;
+}
+
+void WebDebuggerAgent::didPostMessage(int postMessageIdentifier, JSC::JSGlobalObject& state)
+{
+    if (!breakpointsActive())
         return;
 
-    if (m_postMessageTimers.contains(&timer))
+    if (!postMessageIdentifier || !m_postMessageTasks.contains(postMessageIdentifier))
         return;
 
-    int postMessageIdentifier = m_nextPostMessageIdentifier++;
-    m_postMessageTimers.set(&timer, postMessageIdentifier);
-
     didScheduleAsyncCall(&state, InspectorDebuggerAgent::AsyncCallType::PostMessage, postMessageIdentifier, true);
 }
 
-void WebDebuggerAgent::didFailPostMessage(const TimerBase& timer)
+void WebDebuggerAgent::didFailPostMessage(int postMessageIdentifier)
 {
-    auto it = m_postMessageTimers.find(&timer);
-    if (it == m_postMessageTimers.end())
+    if (!postMessageIdentifier)
         return;
 
-    didCancelAsyncCall(InspectorDebuggerAgent::AsyncCallType::PostMessage, it->value);
+    auto it = m_postMessageTasks.find(postMessageIdentifier);
+    if (it == m_postMessageTasks.end())
+        return;
 
-    m_postMessageTimers.remove(it);
+    didCancelAsyncCall(InspectorDebuggerAgent::AsyncCallType::PostMessage, postMessageIdentifier);
+
+    m_postMessageTasks.remove(it);
 }
 
-void WebDebuggerAgent::willDispatchPostMessage(const TimerBase& timer)
+void WebDebuggerAgent::willDispatchPostMessage(int postMessageIdentifier)
 {
-    auto it = m_postMessageTimers.find(&timer);
-    if (it == m_postMessageTimers.end())
+    if (!postMessageIdentifier || !m_postMessageTasks.contains(postMessageIdentifier))
         return;
 
-    willDispatchAsyncCall(InspectorDebuggerAgent::AsyncCallType::PostMessage, it->value);
+    willDispatchAsyncCall(InspectorDebuggerAgent::AsyncCallType::PostMessage, postMessageIdentifier);
 }
 
-void WebDebuggerAgent::didDispatchPostMessage(const TimerBase& timer)
+void WebDebuggerAgent::didDispatchPostMessage(int postMessageIdentifier)
 {
-    auto it = m_postMessageTimers.find(&timer);
-    if (it == m_postMessageTimers.end())
+    if (!postMessageIdentifier)
         return;
 
+    auto it = m_postMessageTasks.find(postMessageIdentifier);
+    if (it == m_postMessageTasks.end())
+        return;
+
     didDispatchAsyncCall();
 
-    m_postMessageTimers.remove(it);
+    m_postMessageTasks.remove(it);
 }
 
 void WebDebuggerAgent::didClearAsyncStackTraceData()
 {
     m_registeredEventListeners.clear();
-    m_postMessageTimers.clear();
+    m_postMessageTasks.clear();
     m_nextEventListenerIdentifier = 1;
     m_nextPostMessageIdentifier = 1;
 }

Modified: trunk/Source/WebCore/inspector/agents/WebDebuggerAgent.h (258849 => 258850)


--- trunk/Source/WebCore/inspector/agents/WebDebuggerAgent.h	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/Source/WebCore/inspector/agents/WebDebuggerAgent.h	2020-03-23 16:51:24 UTC (rev 258850)
@@ -48,10 +48,11 @@
     void didAddEventListener(EventTarget&, const AtomString& eventType, EventListener&, bool capture);
     void willRemoveEventListener(EventTarget&, const AtomString& eventType, EventListener&, bool capture);
     void willHandleEvent(const RegisteredEventListener&);
-    void didPostMessage(const TimerBase&, JSC::JSGlobalObject&);
-    void didFailPostMessage(const TimerBase&);
-    void willDispatchPostMessage(const TimerBase&);
-    void didDispatchPostMessage(const TimerBase&);
+    int willPostMessage();
+    void didPostMessage(int postMessageIdentifier, JSC::JSGlobalObject&);
+    void didFailPostMessage(int postMessageIdentifier);
+    void willDispatchPostMessage(int postMessageIdentifier);
+    void didDispatchPostMessage(int postMessageIdentifier);
 
 protected:
     WebDebuggerAgent(WebAgentContext&);
@@ -64,7 +65,7 @@
 
 private:
     HashMap<const RegisteredEventListener*, int> m_registeredEventListeners;
-    HashMap<const TimerBase*, int> m_postMessageTimers;
+    HashSet<int> m_postMessageTasks;
     int m_nextEventListenerIdentifier { 1 };
     int m_nextPostMessageIdentifier { 1 };
 };

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (258849 => 258850)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2020-03-23 16:51:24 UTC (rev 258850)
@@ -164,46 +164,6 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(DOMWindow);
 
-class PostMessageTimer : public TimerBase {
-public:
-    PostMessageTimer(DOMWindow& window, MessageWithMessagePorts&& message, const String& sourceOrigin, RefPtr<WindowProxy>&& source, RefPtr<SecurityOrigin>&& targetOrigin, RefPtr<ScriptCallStack>&& stackTrace)
-        : m_window(window)
-        , m_message(WTFMove(message))
-        , m_origin(sourceOrigin)
-        , m_source(source)
-        , m_targetOrigin(WTFMove(targetOrigin))
-        , m_stackTrace(stackTrace)
-        , m_userGestureToForward(UserGestureIndicator::currentUserGesture())
-    {
-    }
-
-    Ref<MessageEvent> event(ScriptExecutionContext& context)
-    {
-        return MessageEvent::create(MessagePort::entanglePorts(context, WTFMove(m_message.transferredPorts)), m_message.message.releaseNonNull(), m_origin, { }, m_source ? makeOptional(MessageEventSource(WTFMove(m_source))) : WTF::nullopt);
-    }
-
-    SecurityOrigin* targetOrigin() const { return m_targetOrigin.get(); }
-    ScriptCallStack* stackTrace() const { return m_stackTrace.get(); }
-
-private:
-    void fired() override
-    {
-        // This object gets deleted when std::unique_ptr falls out of scope..
-        std::unique_ptr<PostMessageTimer> timer(this);
-        
-        UserGestureIndicator userGestureIndicator(m_userGestureToForward);
-        m_window->postMessageTimerFired(*timer);
-    }
-
-    Ref<DOMWindow> m_window;
-    MessageWithMessagePorts m_message;
-    String m_origin;
-    RefPtr<WindowProxy> m_source;
-    RefPtr<SecurityOrigin> m_targetOrigin;
-    RefPtr<ScriptCallStack> m_stackTrace;
-    RefPtr<UserGestureToken> m_userGestureToForward;
-};
-
 typedef HashCountedSet<DOMWindow*> DOMWindowSet;
 
 static DOMWindowSet& windowsWithUnloadEventListeners()
@@ -930,45 +890,47 @@
     if (InspectorInstrumentation::consoleAgentEnabled(sourceDocument))
         stackTrace = createScriptCallStack(JSExecState::currentState());
 
+    auto postMessageIdentifier = InspectorInstrumentation::willPostMessage(*frame());
+
     MessageWithMessagePorts message { messageData.releaseReturnValue(), disentangledPorts.releaseReturnValue() };
 
     // Schedule the message.
     RefPtr<WindowProxy> incumbentWindowProxy = incumbentWindow.frame() ? &incumbentWindow.frame()->windowProxy() : nullptr;
-    auto* timer = new PostMessageTimer(*this, WTFMove(message), sourceOrigin, WTFMove(incumbentWindowProxy), WTFMove(target), WTFMove(stackTrace));
-    timer->startOneShot(0_s);
+    auto userGestureToForward = UserGestureIndicator::currentUserGesture();
 
-    InspectorInstrumentation::didPostMessage(*frame(), *timer, lexicalGlobalObject);
+    document()->eventLoop().queueTask(TaskSource::PostedMessageQueue, [this, protectedThis = makeRef(*this), message = WTFMove(message), incumbentWindowProxy = WTFMove(incumbentWindowProxy), sourceOrigin = WTFMove(sourceOrigin), userGestureToForward = WTFMove(userGestureToForward), postMessageIdentifier, stackTrace = WTFMove(stackTrace), targetOrigin = WTFMove(target)]() mutable {
+        if (!isCurrentlyDisplayedInFrame())
+            return;
 
-    return { };
-}
+        Ref<Frame> frame = *this->frame();
+        if (targetOrigin) {
+            // Check target origin now since the target document may have changed since the timer was scheduled.
+            if (!targetOrigin->isSameSchemeHostPort(document()->securityOrigin())) {
+                if (auto* pageConsole = console()) {
+                    String message = makeString("Unable to post message to ", targetOrigin->toString(), ". Recipient has origin ", document()->securityOrigin().toString(), ".\n");
+                    if (stackTrace)
+                        pageConsole->addMessage(MessageSource::Security, MessageLevel::Error, message, *stackTrace);
+                    else
+                        pageConsole->addMessage(MessageSource::Security, MessageLevel::Error, message);
+                }
 
-void DOMWindow::postMessageTimerFired(PostMessageTimer& timer)
-{
-    if (!document() || !isCurrentlyDisplayedInFrame())
-        return;
-
-    Ref<Frame> frame = *this->frame();
-    if (auto* intendedTargetOrigin = timer.targetOrigin()) {
-        // Check target origin now since the target document may have changed since the timer was scheduled.
-        if (!intendedTargetOrigin->isSameSchemeHostPort(document()->securityOrigin())) {
-            if (auto* pageConsole = console()) {
-                String message = makeString("Unable to post message to ", intendedTargetOrigin->toString(), ". Recipient has origin ", document()->securityOrigin().toString(), ".\n");
-                if (timer.stackTrace())
-                    pageConsole->addMessage(MessageSource::Security, MessageLevel::Error, message, *timer.stackTrace());
-                else
-                    pageConsole->addMessage(MessageSource::Security, MessageLevel::Error, message);
+                InspectorInstrumentation::didFailPostMessage(frame, postMessageIdentifier);
+                return;
             }
-
-            InspectorInstrumentation::didFailPostMessage(frame, timer);
-            return;
         }
-    }
 
-    InspectorInstrumentation::willDispatchPostMessage(frame, timer);
+        UserGestureIndicator userGestureIndicator(userGestureToForward);
+        InspectorInstrumentation::willDispatchPostMessage(frame, postMessageIdentifier);
 
-    dispatchEvent(timer.event(*document()));
+        auto event = MessageEvent::create(MessagePort::entanglePorts(*document(), WTFMove(message.transferredPorts)), message.message.releaseNonNull(), sourceOrigin, { }, incumbentWindowProxy ? makeOptional(MessageEventSource(WTFMove(incumbentWindowProxy))) : WTF::nullopt);
+        dispatchEvent(event);
 
-    InspectorInstrumentation::didDispatchPostMessage(frame, timer);
+        InspectorInstrumentation::didDispatchPostMessage(frame, postMessageIdentifier);
+    });
+
+    InspectorInstrumentation::didPostMessage(*frame(), postMessageIdentifier, lexicalGlobalObject);
+
+    return { };
 }
 
 DOMSelection* DOMWindow::getSelection()

Modified: trunk/Source/WebCore/page/DOMWindow.h (258849 => 258850)


--- trunk/Source/WebCore/page/DOMWindow.h	2020-03-23 16:43:38 UTC (rev 258849)
+++ trunk/Source/WebCore/page/DOMWindow.h	2020-03-23 16:51:24 UTC (rev 258850)
@@ -75,7 +75,6 @@
 class Page;
 class PageConsoleClient;
 class Performance;
-class PostMessageTimer;
 class RequestAnimationFrameCallback;
 class RequestIdleCallback;
 class ScheduledAction;
@@ -276,8 +275,6 @@
         return postMessage(globalObject, incumbentWindow, message, WindowPostMessageOptions { WTFMove(targetOrigin), WTFMove(transfer) });
     }
 
-    void postMessageTimerFired(PostMessageTimer&);
-
     void languagesChanged();
 
     void scrollBy(const ScrollToOptions&) const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to