Title: [260653] trunk/Source
Revision
260653
Author
[email protected]
Date
2020-04-24 10:50:41 -0700 (Fri, 24 Apr 2020)

Log Message

Web Automation: timeout underneath Automation.evaluateJavaScriptFunction in Selenium test frame_switching_tests.py::testShouldNotBeAbleToDoAnythingTheFrameIsDeletedFromUnderUs[Safari]
https://bugs.webkit.org/show_bug.cgi?id=210162
<rdar://problem/60561009>

Reviewed by Devin Rousso.

Source/WebCore:

* page/DOMWindow.h: Expose DOMWindow::{register, unregister}Observer.

Source/WebKit:

When an iframe is detached from the DOM, it is no longer exposed as a browsing context
and it's not possible to Evaluate _javascript_ or perform other commands with it. This
patch adds frame lifecycle monitoring so that pending script evaluations are cancelled
with FrameNotFound as soon as the iframe is detached from the DOM. This change also avoids
running more commands with the frame if it's detached from its DOMWindow and ready to be GC'd.

* Sources.txt:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Automation/WebAutomationDOMWindowObserver.h: Added.
* WebProcess/Automation/WebAutomationDOMWindowObserver.cpp: Added.
(WebKit::WebAutomationDOMWindowObserver::WebAutomationDOMWindowObserver):
(WebKit::WebAutomationDOMWindowObserver::~WebAutomationDOMWindowObserver):
(WebKit::WebAutomationDOMWindowObserver::frame const):
(WebKit::WebAutomationDOMWindowObserver::willDestroyGlobalObjectInCachedFrame):
(WebKit::WebAutomationDOMWindowObserver::willDestroyGlobalObjectInFrame):
(WebKit::WebAutomationDOMWindowObserver::willDetachGlobalObjectFromFrame):
This class is a stripped-down copy of DOMWindowExtension, which is the only other
client of DOMWindow::Observer interface. When a frame is detached, destroyed, or
navigates (global object detached), then call the callback and unregister.

* WebProcess/Automation/WebAutomationSessionProxy.h:
* WebProcess/Automation/WebAutomationSessionProxy.cpp:
(WebKit::WebAutomationSessionProxy::~WebAutomationSessionProxy):
(WebKit::WebAutomationSessionProxy::didClearWindowObjectForFrame):
(WebKit::WebAutomationSessionProxy::willDestroyGlobalObjectForFrame):
(WebKit::WebAutomationSessionProxy::evaluateJavaScriptFunction):
(WebKit::WebAutomationSessionProxy::ensureObserverForFrame): For non-main frames,
ensure we add a frame observer if we are about to evaluate _javascript_ upon the frame.
This acts as a watchdog in case the frame becomes detached while waiting for pending
JS evaluations. When a frame is detached, the JS evaluation may or may not complete.

(WebKit::WebAutomationSessionProxy::selectOptionElement): Fix hilarious typo.

* WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp:
* WebProcess/GPU/media/WebMediaStrategy.cpp:
(WebKit::WebMediaStrategy::clearNowPlayingInfo):
(WebKit::WebMediaStrategy::setNowPlayingInfo):
Adding a new file seems to have exposed a few missing includes and namespace qualifiers.
This is due to unified sources chunking.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (260652 => 260653)


--- trunk/Source/WebCore/ChangeLog	2020-04-24 17:25:31 UTC (rev 260652)
+++ trunk/Source/WebCore/ChangeLog	2020-04-24 17:50:41 UTC (rev 260653)
@@ -1,3 +1,13 @@
+2020-04-24  Brian Burg  <[email protected]>
+
+        Web Automation: timeout underneath Automation.evaluateJavaScriptFunction in Selenium test frame_switching_tests.py::testShouldNotBeAbleToDoAnythingTheFrameIsDeletedFromUnderUs[Safari]
+        https://bugs.webkit.org/show_bug.cgi?id=210162
+        <rdar://problem/60561009>
+
+        Reviewed by Devin Rousso.
+
+        * page/DOMWindow.h: Expose DOMWindow::{register, unregister}Observer.
+
 2020-04-24  Zalan Bujtas  <[email protected]>
 
         [LFC][TFC] Take first in-flow table-row baseline into account when computing cell baseline

Modified: trunk/Source/WebCore/page/DOMWindow.h (260652 => 260653)


--- trunk/Source/WebCore/page/DOMWindow.h	2020-04-24 17:25:31 UTC (rev 260652)
+++ trunk/Source/WebCore/page/DOMWindow.h	2020-04-24 17:50:41 UTC (rev 260653)
@@ -140,8 +140,8 @@
         virtual void willDetachGlobalObjectFromFrame() { }
     };
 
-    void registerObserver(Observer&);
-    void unregisterObserver(Observer&);
+    WEBCORE_EXPORT void registerObserver(Observer&);
+    WEBCORE_EXPORT void unregisterObserver(Observer&);
 
     void resetUnlessSuspendedForDocumentSuspension();
     void suspendForBackForwardCache();

Modified: trunk/Source/WebKit/ChangeLog (260652 => 260653)


--- trunk/Source/WebKit/ChangeLog	2020-04-24 17:25:31 UTC (rev 260652)
+++ trunk/Source/WebKit/ChangeLog	2020-04-24 17:50:41 UTC (rev 260653)
@@ -1,3 +1,51 @@
+2020-04-24  Brian Burg  <[email protected]>
+
+        Web Automation: timeout underneath Automation.evaluateJavaScriptFunction in Selenium test frame_switching_tests.py::testShouldNotBeAbleToDoAnythingTheFrameIsDeletedFromUnderUs[Safari]
+        https://bugs.webkit.org/show_bug.cgi?id=210162
+        <rdar://problem/60561009>
+
+        Reviewed by Devin Rousso.
+
+        When an iframe is detached from the DOM, it is no longer exposed as a browsing context
+        and it's not possible to Evaluate _javascript_ or perform other commands with it. This
+        patch adds frame lifecycle monitoring so that pending script evaluations are cancelled
+        with FrameNotFound as soon as the iframe is detached from the DOM. This change also avoids
+        running more commands with the frame if it's detached from its DOMWindow and ready to be GC'd.
+
+        * Sources.txt:
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/Automation/WebAutomationDOMWindowObserver.h: Added.
+        * WebProcess/Automation/WebAutomationDOMWindowObserver.cpp: Added.
+        (WebKit::WebAutomationDOMWindowObserver::WebAutomationDOMWindowObserver):
+        (WebKit::WebAutomationDOMWindowObserver::~WebAutomationDOMWindowObserver):
+        (WebKit::WebAutomationDOMWindowObserver::frame const):
+        (WebKit::WebAutomationDOMWindowObserver::willDestroyGlobalObjectInCachedFrame):
+        (WebKit::WebAutomationDOMWindowObserver::willDestroyGlobalObjectInFrame):
+        (WebKit::WebAutomationDOMWindowObserver::willDetachGlobalObjectFromFrame):
+        This class is a stripped-down copy of DOMWindowExtension, which is the only other
+        client of DOMWindow::Observer interface. When a frame is detached, destroyed, or
+        navigates (global object detached), then call the callback and unregister.
+
+        * WebProcess/Automation/WebAutomationSessionProxy.h:
+        * WebProcess/Automation/WebAutomationSessionProxy.cpp:
+        (WebKit::WebAutomationSessionProxy::~WebAutomationSessionProxy):
+        (WebKit::WebAutomationSessionProxy::didClearWindowObjectForFrame):
+        (WebKit::WebAutomationSessionProxy::willDestroyGlobalObjectForFrame):
+        (WebKit::WebAutomationSessionProxy::evaluateJavaScriptFunction):
+        (WebKit::WebAutomationSessionProxy::ensureObserverForFrame): For non-main frames,
+        ensure we add a frame observer if we are about to evaluate _javascript_ upon the frame.
+        This acts as a watchdog in case the frame becomes detached while waiting for pending
+        JS evaluations. When a frame is detached, the JS evaluation may or may not complete.
+
+        (WebKit::WebAutomationSessionProxy::selectOptionElement): Fix hilarious typo.
+
+        * WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp:
+        * WebProcess/GPU/media/WebMediaStrategy.cpp:
+        (WebKit::WebMediaStrategy::clearNowPlayingInfo):
+        (WebKit::WebMediaStrategy::setNowPlayingInfo):
+        Adding a new file seems to have exposed a few missing includes and namespace qualifiers.
+        This is due to unified sources chunking.
+
 2020-04-24  Alex Christensen  <[email protected]>
 
         Use sendWithAsyncReply for ShareSheet related messages

Modified: trunk/Source/WebKit/Sources.txt (260652 => 260653)


--- trunk/Source/WebKit/Sources.txt	2020-04-24 17:25:31 UTC (rev 260652)
+++ trunk/Source/WebKit/Sources.txt	2020-04-24 17:50:41 UTC (rev 260653)
@@ -485,6 +485,7 @@
 
 // FIXME(206266): AutomationProtocolObjects.h's "namespace Protocol" conflicts with objc/runtime.h's "typedef struct objc_object Protocol"
 WebProcess/Automation/WebAutomationSessionProxy.cpp @no-unify
+WebProcess/Automation/WebAutomationDOMWindowObserver.cpp
 
 WebProcess/Cache/WebCacheStorageConnection.cpp
 WebProcess/Cache/WebCacheStorageProvider.cpp

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (260652 => 260653)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-04-24 17:25:31 UTC (rev 260652)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-04-24 17:50:41 UTC (rev 260653)
@@ -1392,6 +1392,7 @@
 		990D28B11C65208D00986977 /* _WKAutomationSessionInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 990D28AF1C65203900986977 /* _WKAutomationSessionInternal.h */; };
 		990D28BB1C6539D300986977 /* AutomationSessionClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 990D28B71C6539A000986977 /* AutomationSessionClient.h */; };
 		990D28C01C6553F100986977 /* APIAutomationSessionClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 990D28B31C6526D400986977 /* APIAutomationSessionClient.h */; };
+		990D39F5243BE64800199388 /* WebAutomationDOMWindowObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 990D39F3243BE64700199388 /* WebAutomationDOMWindowObserver.h */; };
 		990E1E092384AA57004602DF /* _WKRemoteWebInspectorViewControllerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 990E1E082384A88B004602DF /* _WKRemoteWebInspectorViewControllerPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		991F492F23A812C60054642B /* _WKInspectorDebuggableInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 991F492D23A812C50054642B /* _WKInspectorDebuggableInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		99249AD51F1F1E5600B62FBB /* AutomationFrontendDispatchers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 99249AD31F1F1E3300B62FBB /* AutomationFrontendDispatchers.cpp */; };
@@ -4441,6 +4442,8 @@
 		990D28B31C6526D400986977 /* APIAutomationSessionClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIAutomationSessionClient.h; sourceTree = "<group>"; };
 		990D28B71C6539A000986977 /* AutomationSessionClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationSessionClient.h; sourceTree = "<group>"; };
 		990D28B81C6539A000986977 /* AutomationSessionClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutomationSessionClient.mm; sourceTree = "<group>"; };
+		990D39F2243BE64700199388 /* WebAutomationDOMWindowObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebAutomationDOMWindowObserver.cpp; sourceTree = "<group>"; };
+		990D39F3243BE64700199388 /* WebAutomationDOMWindowObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAutomationDOMWindowObserver.h; sourceTree = "<group>"; };
 		990E1E082384A88B004602DF /* _WKRemoteWebInspectorViewControllerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKRemoteWebInspectorViewControllerPrivate.h; sourceTree = "<group>"; };
 		991F492D23A812C50054642B /* _WKInspectorDebuggableInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKInspectorDebuggableInfo.h; sourceTree = "<group>"; };
 		991F492E23A812C60054642B /* _WKInspectorDebuggableInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKInspectorDebuggableInfo.mm; sourceTree = "<group>"; };
@@ -6459,6 +6462,8 @@
 		1C0A19431C8FF1A800FE0EBB /* Automation */ = {
 			isa = PBXGroup;
 			children = (
+				990D39F2243BE64700199388 /* WebAutomationDOMWindowObserver.cpp */,
+				990D39F3243BE64700199388 /* WebAutomationDOMWindowObserver.h */,
 				1C0A19441C8FF1A800FE0EBB /* WebAutomationSessionProxy.cpp */,
 				1C0A19451C8FF1A800FE0EBB /* WebAutomationSessionProxy.h */,
 				1C0A195A1C91669500FE0EBB /* WebAutomationSessionProxy.js */,
@@ -11167,6 +11172,7 @@
 				57DCEDB3214C60530016B847 /* WebAuthenticatorCoordinatorProxy.h in Headers */,
 				57DCED712142EE6C0016B847 /* WebAuthenticatorCoordinatorProxyMessages.h in Headers */,
 				F42D634122A0EFDF00D2FB3A /* WebAutocorrectionData.h in Headers */,
+				990D39F5243BE64800199388 /* WebAutomationDOMWindowObserver.h in Headers */,
 				9955A6EC1C7980C200EB6A93 /* WebAutomationSession.h in Headers */,
 				99C3AE2D1DADA6AD00AF5C16 /* WebAutomationSessionMacros.h in Headers */,
 				1C0A19581C90068F00FE0EBB /* WebAutomationSessionMessages.h in Headers */,

Added: trunk/Source/WebKit/WebProcess/Automation/WebAutomationDOMWindowObserver.cpp (0 => 260653)


--- trunk/Source/WebKit/WebProcess/Automation/WebAutomationDOMWindowObserver.cpp	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/Automation/WebAutomationDOMWindowObserver.cpp	2020-04-24 17:50:41 UTC (rev 260653)
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#include "config.h"
+#include "WebAutomationDOMWindowObserver.h"
+
+#include <WebCore/Element.h>
+#include <WebCore/Frame.h>
+
+namespace WebKit {
+
+WebAutomationDOMWindowObserver::WebAutomationDOMWindowObserver(DOMWindow& window, WTF::Function<void(WebAutomationDOMWindowObserver&)>&& callback)
+    : m_window(makeWeakPtr(window))
+    , m_callback(WTFMove(callback))
+{
+    ASSERT(m_window->frame());
+    m_window->registerObserver(*this);
+}
+
+WebAutomationDOMWindowObserver::~WebAutomationDOMWindowObserver()
+{
+    if (m_window)
+        m_window->unregisterObserver(*this);
+}
+
+void WebAutomationDOMWindowObserver::willDestroyGlobalObjectInCachedFrame()
+{
+    Ref<WebAutomationDOMWindowObserver> protectedThis(*this);
+
+    if (!m_wasDetached) {
+        ASSERT(m_window && m_window->frame());
+        m_callback(*this);
+    }
+
+    ASSERT(m_window);
+    if (m_window)
+        m_window->unregisterObserver(*this);
+    m_window = nullptr;
+}
+
+void WebAutomationDOMWindowObserver::willDestroyGlobalObjectInFrame()
+{
+    Ref<WebAutomationDOMWindowObserver> protectedThis(*this);
+
+    if (!m_wasDetached) {
+        ASSERT(m_window && m_window->frame());
+        m_callback(*this);
+    }
+
+    ASSERT(m_window);
+    if (m_window)
+        m_window->unregisterObserver(*this);
+    m_window = nullptr;
+}
+
+void WebAutomationDOMWindowObserver::willDetachGlobalObjectFromFrame()
+{
+    ASSERT(!m_wasDetached);
+
+    Ref<WebAutomationDOMWindowObserver> protectedThis(*this);
+
+    m_wasDetached = true;
+
+    m_callback(*this);
+
+    ASSERT(m_window);
+    if (m_window)
+        m_window->unregisterObserver(*this);
+    m_window = nullptr;
+}
+
+} // namespace WebKit

Added: trunk/Source/WebKit/WebProcess/Automation/WebAutomationDOMWindowObserver.h (0 => 260653)


--- trunk/Source/WebKit/WebProcess/Automation/WebAutomationDOMWindowObserver.h	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/Automation/WebAutomationDOMWindowObserver.h	2020-04-24 17:50:41 UTC (rev 260653)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2020 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 <WebCore/DOMWindow.h>
+#include <wtf/Forward.h>
+
+namespace WebCore {
+class Frame;
+}
+
+namespace WebKit {
+
+class WebAutomationDOMWindowObserver final : public RefCounted<WebAutomationDOMWindowObserver>, public WebCore::DOMWindow::Observer {
+public:
+    static Ref<WebAutomationDOMWindowObserver> create(WebCore::DOMWindow& window, WTF::Function<void(WebAutomationDOMWindowObserver&)>&& callback)
+    {
+        return adoptRef(*new WebAutomationDOMWindowObserver(window, WTFMove(callback)));
+    }
+
+    ~WebAutomationDOMWindowObserver();
+
+    // All of these observer callbacks are interpreted as a signal that a frame has been detached and
+    // can no longer accept new commands nor finish pending commands (eg, evaluating _javascript_).
+    void willDestroyGlobalObjectInCachedFrame() final;
+    void willDestroyGlobalObjectInFrame() final;
+    void willDetachGlobalObjectFromFrame() final;
+
+private:
+    WebAutomationDOMWindowObserver(WebCore::DOMWindow&, WTF::Function<void(WebAutomationDOMWindowObserver&)>&&);
+
+    WeakPtr<WebCore::DOMWindow> m_window;
+    bool m_wasDetached { false };
+    WTF::Function<void(WebAutomationDOMWindowObserver&)> m_callback;
+};
+
+} // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp (260652 => 260653)


--- trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp	2020-04-24 17:25:31 UTC (rev 260652)
+++ trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp	2020-04-24 17:50:41 UTC (rev 260653)
@@ -28,6 +28,7 @@
 
 #include "AutomationProtocolObjects.h"
 #include "CoordinateSystem.h"
+#include "WebAutomationDOMWindowObserver.h"
 #include "WebAutomationSessionMessages.h"
 #include "WebAutomationSessionProxyMessages.h"
 #include "WebAutomationSessionProxyScriptSource.h"
@@ -64,6 +65,8 @@
 #include <WebCore/HTMLDataListElement.h>
 #endif
 
+using namespace WebCore;
+
 namespace WebKit {
 
 template <typename T>
@@ -116,6 +119,8 @@
 
 WebAutomationSessionProxy::~WebAutomationSessionProxy()
 {
+    m_frameObservers.clear();
+
     WebProcess::singleton().removeMessageReceiver(Messages::WebAutomationSessionProxy::messageReceiverName());
 }
 
@@ -298,12 +303,37 @@
     return &elementWrapper->wrapped();
 }
 
+void WebAutomationSessionProxy::ensureObserverForFrame(WebFrame& frame)
+{
+    // If the frame and DOMWindow have become disconnected, then frame is already being destroyed
+    // and there is no way to get access to the frame from the observer's DOMWindow reference.
+    if (!frame.coreFrame()->window() || !frame.coreFrame()->window()->frame())
+        return;
+
+    if (m_frameObservers.contains(frame.frameID()))
+        return;
+
+    auto frameID = frame.frameID();
+    m_frameObservers.set(frameID, WebAutomationDOMWindowObserver::create(*frame.coreFrame()->window(), [this, frameID] (WebAutomationDOMWindowObserver&) {
+        willDestroyGlobalObjectForFrame(frameID);
+    }));
+}
+
 void WebAutomationSessionProxy::didClearWindowObjectForFrame(WebFrame& frame)
 {
+    willDestroyGlobalObjectForFrame(frame.frameID());
+}
+
+void WebAutomationSessionProxy::willDestroyGlobalObjectForFrame(WebCore::FrameIdentifier frameID)
+{
+    // The observer is no longer needed, let it become GC'd and unregister itself from DOMWindow.
+    if (m_frameObservers.contains(frameID))
+        m_frameObservers.remove(frameID);
+
     String errorMessage = "Callback was not called before the unload event."_s;
-    String errorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::_javascript_Error);
+    String errorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::FrameNotFound);
 
-    auto pendingFrameCallbacks = m_webFramePendingEvaluateJavaScriptCallbacksMap.take(frame.frameID());
+    auto pendingFrameCallbacks = m_webFramePendingEvaluateJavaScriptCallbacksMap.take(frameID);
     for (uint64_t callbackID : pendingFrameCallbacks)
         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidEvaluateJavaScriptFunction(callbackID, errorMessage, errorType), 0);
 }
@@ -317,12 +347,16 @@
         return;
     }
     auto* frame = optionalFrameID ? WebProcess::singleton().webFrame(*optionalFrameID) : &page->mainWebFrame();
-    if (!frame) {
+    if (!frame || !frame->coreFrame()->window() || !frame->coreFrame()->window()->frame()) {
         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidEvaluateJavaScriptFunction(callbackID, { },
             Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::FrameNotFound)), 0);
         return;
     }
 
+    // No need to track the main frame, this is handled by didClearWindowObjectForFrame.
+    if (!frame->coreFrame()->isMainFrame())
+        ensureObserverForFrame(*frame);
+
     JSObjectRef scriptObject = scriptObjectForFrame(*frame);
     ASSERT(scriptObject);
 
@@ -735,8 +769,8 @@
     }
 
     if (!isValidNodeHandle(nodeHandle)) {
-        String invalidNodeIdentifierrrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InvalidNodeIdentifier);
-        completionHandler(invalidNodeIdentifierrrorType);
+        String invalidNodeIdentifierErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::InvalidNodeIdentifier);
+        completionHandler(invalidNodeIdentifierErrorType);
         return;
     }
 

Modified: trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.h (260652 => 260653)


--- trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.h	2020-04-24 17:25:31 UTC (rev 260652)
+++ trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.h	2020-04-24 17:50:41 UTC (rev 260653)
@@ -43,6 +43,7 @@
 
 class WebFrame;
 class WebPage;
+class WebAutomationDOMWindowObserver;
 
 class WebAutomationSessionProxy : public IPC::MessageReceiver {
     WTF_MAKE_FAST_ALLOCATED;
@@ -53,6 +54,7 @@
     String sessionIdentifier() const { return m_sessionIdentifier; }
 
     void didClearWindowObjectForFrame(WebFrame&);
+    void willDestroyGlobalObjectForFrame(WebCore::FrameIdentifier);
 
     void didEvaluateJavaScriptFunction(WebCore::FrameIdentifier, uint64_t callbackID, const String& result, const String& errorType);
 
@@ -62,6 +64,8 @@
     JSObjectRef scriptObjectForFrame(WebFrame&);
     WebCore::Element* elementForNodeHandle(WebFrame&, const String&);
 
+    void ensureObserverForFrame(WebFrame&);
+
     // Implemented in generated WebAutomationSessionProxyMessageReceiver.cpp
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
 
@@ -84,6 +88,7 @@
     JSC::PrivateName m_scriptObjectIdentifier;
 
     HashMap<WebCore::FrameIdentifier, Vector<uint64_t>> m_webFramePendingEvaluateJavaScriptCallbacksMap;
+    HashMap<WebCore::FrameIdentifier, RefPtr<WebAutomationDOMWindowObserver>> m_frameObservers;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp (260652 => 260653)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp	2020-04-24 17:25:31 UTC (rev 260652)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/cocoa/ImageBufferShareableIOSurfaceBackend.cpp	2020-04-24 17:50:41 UTC (rev 260653)
@@ -29,6 +29,7 @@
 #if ENABLE(GPU_PROCESS)
 #if HAVE(IOSURFACE)
 
+#include <WebCore/GraphicsContextCG.h>
 #include <wtf/IsoMallocInlines.h>
 #include <wtf/StdLibExtras.h>
 

Modified: trunk/Source/WebKit/WebProcess/GPU/media/WebMediaStrategy.cpp (260652 => 260653)


--- trunk/Source/WebKit/WebProcess/GPU/media/WebMediaStrategy.cpp	2020-04-24 17:25:31 UTC (rev 260652)
+++ trunk/Source/WebKit/WebProcess/GPU/media/WebMediaStrategy.cpp	2020-04-24 17:50:41 UTC (rev 260653)
@@ -66,7 +66,7 @@
         return;
     }
 #endif
-    MediaSessionManagerCocoa::clearNowPlayingInfo();
+    WebCore::MediaSessionManagerCocoa::clearNowPlayingInfo();
 }
 
 void WebMediaStrategy::setNowPlayingInfo(bool setAsNowPlayingApplication, const WebCore::NowPlayingInfo& nowPlayingInfo)
@@ -78,7 +78,7 @@
         return;
     }
 #endif
-    MediaSessionManagerCocoa::setNowPlayingInfo(setAsNowPlayingApplication, nowPlayingInfo);
+    WebCore::MediaSessionManagerCocoa::setNowPlayingInfo(setAsNowPlayingApplication, nowPlayingInfo);
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to