Title: [230643] trunk/Source
Revision
230643
Author
cdu...@apple.com
Date
2018-04-13 14:23:54 -0700 (Fri, 13 Apr 2018)

Log Message

Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame
https://bugs.webkit.org/show_bug.cgi?id=184591

Reviewed by Sam Weinig.

Source/WebCore:

Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame.
RemoteFrames do not need a ScriptController but do need to maintain WindowProxies.
This is work towards fixing Bug 184515.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/DOMWrapperWorld.cpp:
(WebCore::DOMWrapperWorld::~DOMWrapperWorld):
(WebCore::DOMWrapperWorld::clearWrappers):
* bindings/js/DOMWrapperWorld.h:
(WebCore::DOMWrapperWorld::didCreateWindowProxy):
(WebCore::DOMWrapperWorld::didDestroyWindowProxy):
* bindings/js/JSBindingsAllInOne.cpp:
* bindings/js/JSDOMWindowBase.cpp:
(WebCore::toJSDOMWindow):
* bindings/js/JSDOMWindowProxy.cpp:
(WebCore::toJS):
(WebCore::toJSDOMWindowProxy):
* bindings/js/ScriptCachedFrameData.cpp:
(WebCore::ScriptCachedFrameData::ScriptCachedFrameData):
(WebCore::ScriptCachedFrameData::restore):
* bindings/js/ScriptController.cpp:
(WebCore::ScriptController::~ScriptController):
(WebCore::ScriptController::evaluateInWorld):
(WebCore::ScriptController::loadModuleScriptInWorld):
(WebCore::ScriptController::linkAndEvaluateModuleScriptInWorld):
(WebCore::ScriptController::evaluateModule):
(WebCore::ScriptController::clearWindowProxiesNotMatchingDOMWindow):
(WebCore::ScriptController::setDOMWindowForWindowProxy):
(WebCore::ScriptController::initScriptForWindowProxy):
(WebCore::ScriptController::setupModuleScriptHandlers):
(WebCore::ScriptController::windowProxyController):
(WebCore::ScriptController::enableEval):
(WebCore::ScriptController::enableWebAssembly):
(WebCore::ScriptController::disableEval):
(WebCore::ScriptController::disableWebAssembly):
(WebCore::ScriptController::attachDebugger):
(WebCore::ScriptController::updateDocument):
(WebCore::ScriptController::collectIsolatedContexts):
(WebCore::ScriptController::windowScriptNPObject):
(WebCore::ScriptController::executeIfJavaScriptURL):
* bindings/js/ScriptController.h:
(WebCore::ScriptController::globalObject):
* bindings/js/ScriptControllerMac.mm:
(WebCore::ScriptController::windowScriptObject):
* bindings/js/ScriptState.cpp:
(WebCore::mainWorldExecState):
* bindings/js/WindowProxyController.cpp: Added.
(WebCore::WindowProxyController::WindowProxyController):
(WebCore::WindowProxyController::destroyWindowProxy):
(WebCore::WindowProxyController::createWindowProxy):
(WebCore::WindowProxyController::windowProxies):
(WebCore::WindowProxyController::createWindowProxyWithInitializedScript):
* bindings/js/WindowProxyController.h: Added.
(WebCore::WindowProxyController::releaseWindowProxies):
(WebCore::WindowProxyController::setWindowProxies):
(WebCore::WindowProxyController::windowProxy):
(WebCore::WindowProxyController::existingWindowProxy const):
(WebCore::WindowProxyController::globalObject):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::dispatchDidClearWindowObjectInWorld):
* page/AbstractFrame.cpp:
(WebCore::AbstractFrame::AbstractFrame):
* page/AbstractFrame.h:
(WebCore::AbstractFrame::windowProxyController):
(WebCore::AbstractFrame::windowProxyController const):

Source/WebKit:

Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame.
RemoteFrames do not need a ScriptController but do need to maintain WindowProxies.
This is work towards fixing Bug 184515.

* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::windowScriptNPObject):

Source/WebKitLegacy/mac:

Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame.
RemoteFrames do not need a ScriptController but do need to maintain WindowProxies.
This is work towards fixing Bug 184515.

* Plugins/Hosted/NetscapePluginInstanceProxy.mm:
(WebKit::NetscapePluginInstanceProxy::getWindowNPObject):
* WebView/WebFrame.mm:
(-[WebFrame _attachScriptDebugger]):

Source/WTF:

Add isEmpty() convenience method to SizedIteratorRange.

* wtf/IteratorRange.h:
(WTF::SizedIteratorRange::isEmpty const):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (230642 => 230643)


--- trunk/Source/WTF/ChangeLog	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WTF/ChangeLog	2018-04-13 21:23:54 UTC (rev 230643)
@@ -1,3 +1,15 @@
+2018-04-13  Chris Dumez  <cdu...@apple.com>
+
+        Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame
+        https://bugs.webkit.org/show_bug.cgi?id=184591
+
+        Reviewed by Sam Weinig.
+
+        Add isEmpty() convenience method to SizedIteratorRange.
+
+        * wtf/IteratorRange.h:
+        (WTF::SizedIteratorRange::isEmpty const):
+
 2018-04-13  Brady Eidson  <beid...@apple.com>
 
         Introduce SuspendedPageProxy to keep old web processes around after their WebPageProxy has been swapped to a new one.

Modified: trunk/Source/WTF/wtf/IteratorRange.h (230642 => 230643)


--- trunk/Source/WTF/wtf/IteratorRange.h	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WTF/wtf/IteratorRange.h	2018-04-13 21:23:54 UTC (rev 230643)
@@ -62,6 +62,7 @@
     }
 
     auto size() const -> decltype(std::declval<Container>().size()) { return m_container.size(); }
+    bool isEmpty() const { return m_container.isEmpty(); }
     Iterator begin() const { return m_begin; }
     Iterator end() const { return m_end; }
 

Modified: trunk/Source/WebCore/ChangeLog (230642 => 230643)


--- trunk/Source/WebCore/ChangeLog	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/ChangeLog	2018-04-13 21:23:54 UTC (rev 230643)
@@ -1,3 +1,77 @@
+2018-04-13  Chris Dumez  <cdu...@apple.com>
+
+        Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame
+        https://bugs.webkit.org/show_bug.cgi?id=184591
+
+        Reviewed by Sam Weinig.
+
+        Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame.
+        RemoteFrames do not need a ScriptController but do need to maintain WindowProxies.
+        This is work towards fixing Bug 184515.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/DOMWrapperWorld.cpp:
+        (WebCore::DOMWrapperWorld::~DOMWrapperWorld):
+        (WebCore::DOMWrapperWorld::clearWrappers):
+        * bindings/js/DOMWrapperWorld.h:
+        (WebCore::DOMWrapperWorld::didCreateWindowProxy):
+        (WebCore::DOMWrapperWorld::didDestroyWindowProxy):
+        * bindings/js/JSBindingsAllInOne.cpp:
+        * bindings/js/JSDOMWindowBase.cpp:
+        (WebCore::toJSDOMWindow):
+        * bindings/js/JSDOMWindowProxy.cpp:
+        (WebCore::toJS):
+        (WebCore::toJSDOMWindowProxy):
+        * bindings/js/ScriptCachedFrameData.cpp:
+        (WebCore::ScriptCachedFrameData::ScriptCachedFrameData):
+        (WebCore::ScriptCachedFrameData::restore):
+        * bindings/js/ScriptController.cpp:
+        (WebCore::ScriptController::~ScriptController):
+        (WebCore::ScriptController::evaluateInWorld):
+        (WebCore::ScriptController::loadModuleScriptInWorld):
+        (WebCore::ScriptController::linkAndEvaluateModuleScriptInWorld):
+        (WebCore::ScriptController::evaluateModule):
+        (WebCore::ScriptController::clearWindowProxiesNotMatchingDOMWindow):
+        (WebCore::ScriptController::setDOMWindowForWindowProxy):
+        (WebCore::ScriptController::initScriptForWindowProxy):
+        (WebCore::ScriptController::setupModuleScriptHandlers):
+        (WebCore::ScriptController::windowProxyController):
+        (WebCore::ScriptController::enableEval):
+        (WebCore::ScriptController::enableWebAssembly):
+        (WebCore::ScriptController::disableEval):
+        (WebCore::ScriptController::disableWebAssembly):
+        (WebCore::ScriptController::attachDebugger):
+        (WebCore::ScriptController::updateDocument):
+        (WebCore::ScriptController::collectIsolatedContexts):
+        (WebCore::ScriptController::windowScriptNPObject):
+        (WebCore::ScriptController::executeIfJavaScriptURL):
+        * bindings/js/ScriptController.h:
+        (WebCore::ScriptController::globalObject):
+        * bindings/js/ScriptControllerMac.mm:
+        (WebCore::ScriptController::windowScriptObject):
+        * bindings/js/ScriptState.cpp:
+        (WebCore::mainWorldExecState):
+        * bindings/js/WindowProxyController.cpp: Added.
+        (WebCore::WindowProxyController::WindowProxyController):
+        (WebCore::WindowProxyController::destroyWindowProxy):
+        (WebCore::WindowProxyController::createWindowProxy):
+        (WebCore::WindowProxyController::windowProxies):
+        (WebCore::WindowProxyController::createWindowProxyWithInitializedScript):
+        * bindings/js/WindowProxyController.h: Added.
+        (WebCore::WindowProxyController::releaseWindowProxies):
+        (WebCore::WindowProxyController::setWindowProxies):
+        (WebCore::WindowProxyController::windowProxy):
+        (WebCore::WindowProxyController::existingWindowProxy const):
+        (WebCore::WindowProxyController::globalObject):
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::dispatchDidClearWindowObjectInWorld):
+        * page/AbstractFrame.cpp:
+        (WebCore::AbstractFrame::AbstractFrame):
+        * page/AbstractFrame.h:
+        (WebCore::AbstractFrame::windowProxyController):
+        (WebCore::AbstractFrame::windowProxyController const):
+
 2018-04-13  Brady Eidson  <beid...@apple.com>
 
         Introduce SuspendedPageProxy to keep old web processes around after their WebPageProxy has been swapped to a new one.

Modified: trunk/Source/WebCore/Sources.txt (230642 => 230643)


--- trunk/Source/WebCore/Sources.txt	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/Sources.txt	2018-04-13 21:23:54 UTC (rev 230643)
@@ -468,6 +468,7 @@
 bindings/js/SerializedScriptValue.cpp
 bindings/js/WebCoreJSClientData.cpp
 bindings/js/WebCoreTypedArrayController.cpp
+bindings/js/WindowProxyController.cpp
 bindings/js/WorkerScriptController.cpp
 
 bridge/IdentifierRep.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (230642 => 230643)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-04-13 21:23:54 UTC (rev 230643)
@@ -1191,6 +1191,7 @@
 		460BB6161D0A1BF000221812 /* Base64Utilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 460BB6141D0A1BEC00221812 /* Base64Utilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		460CBF361D4BCD0E0092E88E /* JSDOMWindowProperties.h in Headers */ = {isa = PBXBuildFile; fileRef = 460CBF341D4BCCFE0092E88E /* JSDOMWindowProperties.h */; };
 		46218ACB1F72D64E00574FBE /* DOMHighResTimeStamp.h in Headers */ = {isa = PBXBuildFile; fileRef = 46E016AD1F72D61E00282B2C /* DOMHighResTimeStamp.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		463521AD2081092A00C28922 /* WindowProxyController.h in Headers */ = {isa = PBXBuildFile; fileRef = 463521AA2081090B00C28922 /* WindowProxyController.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		463EB6231B8789E00096ED51 /* TagCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 463EB6211B8789CB0096ED51 /* TagCollection.h */; };
 		465307D01DB6EE4800E4137C /* JSUIEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E045EF1DAA104F00B0D8B9 /* JSUIEventInit.h */; };
 		46658DC91FA24B8700F7DD54 /* SWContextManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4672413B1FA24B140088BD6D /* SWContextManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -7425,6 +7426,8 @@
 		460CBF341D4BCCFE0092E88E /* JSDOMWindowProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMWindowProperties.h; sourceTree = "<group>"; };
 		460D19441FCE21DD00C3DB85 /* JSServiceWorkerGlobalScopeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSServiceWorkerGlobalScopeCustom.cpp; sourceTree = "<group>"; };
 		4634592B1AC2271000ECB71C /* PowerObserverMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PowerObserverMac.cpp; sourceTree = "<group>"; };
+		463521AA2081090B00C28922 /* WindowProxyController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowProxyController.h; sourceTree = "<group>"; };
+		463521AC2081090E00C28922 /* WindowProxyController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WindowProxyController.cpp; sourceTree = "<group>"; };
 		463EB6201B8789CB0096ED51 /* TagCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TagCollection.cpp; sourceTree = "<group>"; };
 		463EB6211B8789CB0096ED51 /* TagCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TagCollection.h; sourceTree = "<group>"; };
 		465A8E781C8A24CE00E7D3E4 /* RuntimeApplicationChecksCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RuntimeApplicationChecksCocoa.mm; sourceTree = "<group>"; };
@@ -23708,6 +23711,8 @@
 				BC53D910114310CC000D817E /* WebCoreJSClientData.h */,
 				0F099D0617B968A100FF84B9 /* WebCoreTypedArrayController.cpp */,
 				0F099D0717B968A100FF84B9 /* WebCoreTypedArrayController.h */,
+				463521AC2081090E00C28922 /* WindowProxyController.cpp */,
+				463521AA2081090B00C28922 /* WindowProxyController.h */,
 				E1A643FC0EC097A000779668 /* WorkerScriptController.cpp */,
 				E1A643F10EC0972500779668 /* WorkerScriptController.h */,
 			);
@@ -30608,6 +30613,7 @@
 				0F15ED5C1B7EC7C500EDDFEB /* WillChangeData.h in Headers */,
 				BC8243E90D0CFD7500460C8F /* WindowFeatures.h in Headers */,
 				7E99AF530B13846468FB01A5 /* WindowFocusAllowedIndicator.h in Headers */,
+				463521AD2081092A00C28922 /* WindowProxyController.h in Headers */,
 				E1E1BF00115FF6FB006F52CA /* WindowsKeyboardCodes.h in Headers */,
 				501BAAA913950E2C00F7ACEB /* WindRule.h in Headers */,
 				A14832BE187F64CC00DA63A6 /* WKContentObservation.h in Headers */,

Modified: trunk/Source/WebCore/bindings/js/DOMWrapperWorld.cpp (230642 => 230643)


--- trunk/Source/WebCore/bindings/js/DOMWrapperWorld.cpp	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/bindings/js/DOMWrapperWorld.cpp	2018-04-13 21:23:54 UTC (rev 230643)
@@ -23,8 +23,8 @@
 
 #include "CommonVM.h"
 #include "JSDOMWindow.h"
-#include "ScriptController.h"
 #include "WebCoreJSClientData.h"
+#include "WindowProxyController.h"
 #include <wtf/MainThread.h>
 
 
@@ -47,8 +47,8 @@
     static_cast<JSVMClientData*>(clientData)->forgetWorld(*this);
 
     // These items are created lazily.
-    while (!m_scriptControllersWithWindowProxies.isEmpty())
-        (*m_scriptControllersWithWindowProxies.begin())->destroyWindowProxy(*this);
+    while (!m_windowProxyControllers.isEmpty())
+        (*m_windowProxyControllers.begin())->destroyWindowProxy(*this);
 }
 
 void DOMWrapperWorld::clearWrappers()
@@ -56,8 +56,8 @@
     m_wrappers.clear();
 
     // These items are created lazily.
-    while (!m_scriptControllersWithWindowProxies.isEmpty())
-        (*m_scriptControllersWithWindowProxies.begin())->destroyWindowProxy(*this);
+    while (!m_windowProxyControllers.isEmpty())
+        (*m_windowProxyControllers.begin())->destroyWindowProxy(*this);
 }
 
 DOMWrapperWorld& normalWorld(JSC::VM& vm)

Modified: trunk/Source/WebCore/bindings/js/DOMWrapperWorld.h (230642 => 230643)


--- trunk/Source/WebCore/bindings/js/DOMWrapperWorld.h	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/bindings/js/DOMWrapperWorld.h	2018-04-13 21:23:54 UTC (rev 230643)
@@ -26,7 +26,7 @@
 
 namespace WebCore {
 
-class ScriptController;
+class WindowProxyController;
 
 typedef HashMap<void*, JSC::Weak<JSC::JSObject>> DOMObjectWrapperMap;
 
@@ -41,8 +41,8 @@
     // Free as much memory held onto by this world as possible.
     WEBCORE_EXPORT void clearWrappers();
 
-    void didCreateWindowProxy(ScriptController* scriptController) { m_scriptControllersWithWindowProxies.add(scriptController); }
-    void didDestroyWindowProxy(ScriptController* scriptController) { m_scriptControllersWithWindowProxies.remove(scriptController); }
+    void didCreateWindowProxy(WindowProxyController* controller) { m_windowProxyControllers.add(controller); }
+    void didDestroyWindowProxy(WindowProxyController* controller) { m_windowProxyControllers.remove(controller); }
 
     void setShadowRootIsAlwaysOpen() { m_shadowRootIsAlwaysOpen = true; }
     bool shadowRootIsAlwaysOpen() const { return m_shadowRootIsAlwaysOpen; }
@@ -61,7 +61,7 @@
 
 private:
     JSC::VM& m_vm;
-    HashSet<ScriptController*> m_scriptControllersWithWindowProxies;
+    HashSet<WindowProxyController*> m_windowProxyControllers;
     DOMObjectWrapperMap m_wrappers;
 
     bool m_isNormal;

Modified: trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp (230642 => 230643)


--- trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp	2018-04-13 21:23:54 UTC (rev 230643)
@@ -109,4 +109,5 @@
 #include "ScriptState.cpp"
 #include "SerializedScriptValue.cpp"
 #include "WebCoreTypedArrayController.cpp"
+#include "WindowProxyController.cpp"
 #include "WorkerScriptController.cpp"

Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp (230642 => 230643)


--- trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp	2018-04-13 21:23:54 UTC (rev 230643)
@@ -267,7 +267,7 @@
 
 JSDOMWindow* toJSDOMWindow(Frame& frame, DOMWrapperWorld& world)
 {
-    return frame.script().windowProxy(world)->window();
+    return frame.script().globalObject(world);
 }
 
 JSDOMWindow* toJSDOMWindow(JSC::VM& vm, JSValue value)

Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowProxy.cpp (230642 => 230643)


--- trunk/Source/WebCore/bindings/js/JSDOMWindowProxy.cpp	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowProxy.cpp	2018-04-13 21:23:54 UTC (rev 230643)
@@ -118,12 +118,12 @@
 
 JSValue toJS(ExecState* state, Frame& frame)
 {
-    return frame.script().windowProxy(currentWorld(*state));
+    return &frame.windowProxyController().windowProxy(currentWorld(*state));
 }
 
-JSDOMWindowProxy* toJSDOMWindowProxy(Frame& frame, DOMWrapperWorld& world)
+JSDOMWindowProxy& toJSDOMWindowProxy(Frame& frame, DOMWrapperWorld& world)
 {
-    return frame.script().windowProxy(world);
+    return frame.windowProxyController().windowProxy(world);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/JSDOMWindowProxy.h (230642 => 230643)


--- trunk/Source/WebCore/bindings/js/JSDOMWindowProxy.h	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/bindings/js/JSDOMWindowProxy.h	2018-04-13 21:23:54 UTC (rev 230643)
@@ -64,7 +64,7 @@
 JSC::JSValue toJS(JSC::ExecState*, Frame&);
 inline JSC::JSValue toJS(JSC::ExecState* state, Frame* frame) { return frame ? toJS(state, *frame) : JSC::jsNull(); }
 
-JSDOMWindowProxy* toJSDOMWindowProxy(Frame&, DOMWrapperWorld&);
-inline JSDOMWindowProxy* toJSDOMWindowProxy(Frame* frame, DOMWrapperWorld& world) { return frame ? toJSDOMWindowProxy(*frame, world) : nullptr; }
+JSDOMWindowProxy& toJSDOMWindowProxy(Frame&, DOMWrapperWorld&);
+inline JSDOMWindowProxy* toJSDOMWindowProxy(Frame* frame, DOMWrapperWorld& world) { return frame ? &toJSDOMWindowProxy(*frame, world) : nullptr; }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/ScriptCachedFrameData.cpp (230642 => 230643)


--- trunk/Source/WebCore/bindings/js/ScriptCachedFrameData.cpp	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/bindings/js/ScriptCachedFrameData.cpp	2018-04-13 21:23:54 UTC (rev 230643)
@@ -51,15 +51,13 @@
 {
     JSLockHolder lock(commonVM());
 
-    auto& scriptController = frame.script();
-
-    for (auto windowProxy : scriptController.windowProxies()) {
+    for (auto windowProxy : frame.windowProxyController().windowProxiesAsVector()) {
         auto* window = windowProxy->window();
         m_windows.add(&windowProxy->world(), Strong<JSDOMWindow>(window->vm(), window));
         window->setConsoleClient(nullptr);
     }
 
-    scriptController.attachDebugger(nullptr);
+    frame.script().attachDebugger(nullptr);
 }
 
 ScriptCachedFrameData::~ScriptCachedFrameData()
@@ -74,7 +72,7 @@
     Page* page = frame.page();
     auto& scriptController = frame.script();
 
-    for (auto windowProxy : scriptController.windowProxies()) {
+    for (auto windowProxy : frame.windowProxyController().windowProxiesAsVector()) {
         auto* world = &windowProxy->world();
 
         if (auto* window = m_windows.get(world).get())

Modified: trunk/Source/WebCore/bindings/js/ScriptController.cpp (230642 => 230643)


--- trunk/Source/WebCore/bindings/js/ScriptController.cpp	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/bindings/js/ScriptController.cpp	2018-04-13 21:23:54 UTC (rev 230643)
@@ -117,38 +117,17 @@
         m_cacheableBindingRootObject = nullptr;
     }
 
-    // It's likely that destroying m_windowProxies will create a lot of garbage.
-    if (!m_windowProxies.isEmpty()) {
-        while (!m_windowProxies.isEmpty()) {
-            auto iter = m_windowProxies.begin();
-            iter->value->window()->setConsoleClient(nullptr);
-            destroyWindowProxy(*iter->key);
+    // It's likely that destroying windowProxies will create a lot of garbage.
+    if (!windowProxyController().windowProxies().isEmpty()) {
+        while (!windowProxyController().windowProxies().isEmpty()) {
+            auto windowProxy = *windowProxyController().windowProxies().begin();
+            windowProxy.get()->window()->setConsoleClient(nullptr);
+            windowProxyController().destroyWindowProxy(windowProxy.get()->world());
         }
         collectGarbageAfterWindowProxyDestruction();
     }
 }
 
-void ScriptController::destroyWindowProxy(DOMWrapperWorld& world)
-{
-    ASSERT(m_windowProxies.contains(&world));
-    m_windowProxies.remove(&world);
-    world.didDestroyWindowProxy(this);
-}
-
-JSDOMWindowProxy& ScriptController::createWindowProxy(DOMWrapperWorld& world)
-{
-    ASSERT(!m_windowProxies.contains(&world));
-    ASSERT(m_frame.document()->domWindow());
-
-    VM& vm = world.vm();
-
-    Strong<JSDOMWindowProxy> windowProxy(vm, &JSDOMWindowProxy::create(vm, *m_frame.document()->domWindow(), world));
-    Strong<JSDOMWindowProxy> windowProxy2(windowProxy);
-    m_windowProxies.add(&world, windowProxy);
-    world.didCreateWindowProxy(this);
-    return *windowProxy.get();
-}
-
 JSValue ScriptController::evaluateInWorld(const ScriptSourceCode& sourceCode, DOMWrapperWorld& world, ExceptionDetails* exceptionDetails)
 {
     JSLockHolder lock(world.vm());
@@ -163,7 +142,7 @@
     // and false for <script>doSomething()</script>. Check if it has the
     // expected value in all cases.
     // See smart window.open policy for where this is used.
-    auto& proxy = *windowProxy(world);
+    auto& proxy = windowProxyController().windowProxy(world);
     auto& exec = *proxy.window()->globalExec();
     const String* savedSourceURL = m_sourceURL;
     m_sourceURL = &sourceURL;
@@ -196,7 +175,7 @@
 {
     JSLockHolder lock(world.vm());
 
-    auto& proxy = *windowProxy(world);
+    auto& proxy = windowProxyController().windowProxy(world);
     auto& state = *proxy.window()->globalExec();
 
     auto& promise = JSMainThreadExecState::loadModule(state, moduleName, JSC::JSScriptFetchParameters::create(state.vm(), WTFMove(topLevelFetchParameters)), JSC::JSScriptFetcher::create(state.vm(), { &moduleScript }));
@@ -212,7 +191,7 @@
 {
     JSLockHolder lock(world.vm());
 
-    auto& proxy = *windowProxy(world);
+    auto& proxy = windowProxyController().windowProxy(world);
     auto& state = *proxy.window()->globalExec();
 
     auto& promise = JSMainThreadExecState::loadModule(state, sourceCode.jsSourceCode(), JSC::JSScriptFetcher::create(state.vm(), { &moduleScript }));
@@ -228,7 +207,7 @@
 {
     JSLockHolder lock(world.vm());
 
-    auto& proxy = *windowProxy(world);
+    auto& proxy = windowProxyController().windowProxy(world);
     auto& state = *proxy.window()->globalExec();
 
     // FIXME: Preventing Frame from being destroyed is essentially unnecessary.
@@ -257,7 +236,7 @@
 
     const auto& jsSourceCode = moduleRecord.sourceCode();
 
-    auto& proxy = *windowProxy(world);
+    auto& proxy = windowProxyController().windowProxy(world);
     auto& state = *proxy.window()->globalExec();
     SetForScope<const String*> sourceURLScope(m_sourceURL, &sourceURL.string());
 
@@ -281,11 +260,6 @@
     return DOMWrapperWorld::create(commonVM());
 }
 
-Vector<JSC::Strong<JSDOMWindowProxy>> ScriptController::windowProxies()
-{
-    return copyToVector(m_windowProxies.values());
-}
-
 void ScriptController::getAllWorlds(Vector<Ref<DOMWrapperWorld>>& worlds)
 {
     static_cast<JSVMClientData*>(commonVM().clientData)->getAllWorlds(worlds);
@@ -293,13 +267,13 @@
 
 void ScriptController::clearWindowProxiesNotMatchingDOMWindow(DOMWindow* newDOMWindow, bool goingIntoPageCache)
 {
-    if (m_windowProxies.isEmpty())
+    if (windowProxyController().windowProxies().isEmpty())
         return;
 
     JSLockHolder lock(commonVM());
 
-    for (auto& windowProxy : windowProxies()) {
-        if (&windowProxy->window()->wrapped() == newDOMWindow)
+    for (auto& windowProxy : windowProxyController().windowProxiesAsVector()) {
+        if (&windowProxy->wrapped() == newDOMWindow)
             continue;
 
         // Clear the debugger and console from the current window before setting the new window.
@@ -318,13 +292,13 @@
 {
     ASSERT(newDOMWindow);
 
-    if (m_windowProxies.isEmpty())
+    if (windowProxyController().windowProxies().isEmpty())
         return;
     
     JSLockHolder lock(commonVM());
     
-    for (auto& windowProxy : windowProxies()) {
-        if (&windowProxy->window()->wrapped() == newDOMWindow)
+    for (auto& windowProxy : windowProxyController().windowProxiesAsVector()) {
+        if (&windowProxy->wrapped() == newDOMWindow)
             continue;
         
         windowProxy->setWindow(*newDOMWindow);
@@ -342,14 +316,10 @@
     }
 }
 
-JSDOMWindowProxy* ScriptController::initScript(DOMWrapperWorld& world)
+void ScriptController::initScriptForWindowProxy(JSDOMWindowProxy& windowProxy)
 {
-    ASSERT(!m_windowProxies.contains(&world));
+    auto& world = windowProxy.world();
 
-    JSLockHolder lock(world.vm());
-
-    auto& windowProxy = createWindowProxy(world);
-
     windowProxy.window()->updateDocument();
 
     if (Document* document = m_frame.document())
@@ -362,8 +332,6 @@
     }
 
     m_frame.loader().dispatchDidClearWindowObjectInWorld(world);
-
-    return &windowProxy;
 }
 
 static Identifier jsValueToModuleKey(ExecState* exec, JSValue value)
@@ -376,7 +344,7 @@
 
 void ScriptController::setupModuleScriptHandlers(LoadableModuleScript& moduleScriptRef, JSInternalPromise& promise, DOMWrapperWorld& world)
 {
-    auto& proxy = *windowProxy(world);
+    auto& proxy = windowProxyController().windowProxy(world);
     auto& state = *proxy.window()->globalExec();
 
     // It is not guaranteed that either fulfillHandler or rejectHandler is eventually called.
@@ -428,6 +396,11 @@
     promise.then(&state, &fulfillHandler, &rejectHandler);
 }
 
+WindowProxyController& ScriptController::windowProxyController()
+{
+    return m_frame.windowProxyController();
+}
+
 TextPosition ScriptController::eventHandlerPosition() const
 {
     // FIXME: If we are not currently parsing, we should use our current location
@@ -443,7 +416,7 @@
 
 void ScriptController::enableEval()
 {
-    auto* windowProxy = existingWindowProxy(mainThreadNormalWorld());
+    auto* windowProxy = windowProxyController().existingWindowProxy(mainThreadNormalWorld());
     if (!windowProxy)
         return;
     windowProxy->window()->setEvalEnabled(true);
@@ -451,7 +424,7 @@
 
 void ScriptController::enableWebAssembly()
 {
-    auto* windowProxy = existingWindowProxy(mainThreadNormalWorld());
+    auto* windowProxy = windowProxyController().existingWindowProxy(mainThreadNormalWorld());
     if (!windowProxy)
         return;
     windowProxy->window()->setWebAssemblyEnabled(true);
@@ -459,7 +432,7 @@
 
 void ScriptController::disableEval(const String& errorMessage)
 {
-    auto* windowProxy = existingWindowProxy(mainThreadNormalWorld());
+    auto* windowProxy = windowProxyController().existingWindowProxy(mainThreadNormalWorld());
     if (!windowProxy)
         return;
     windowProxy->window()->setEvalEnabled(false, errorMessage);
@@ -467,7 +440,7 @@
 
 void ScriptController::disableWebAssembly(const String& errorMessage)
 {
-    auto* windowProxy = existingWindowProxy(mainThreadNormalWorld());
+    auto* windowProxy = windowProxyController().existingWindowProxy(mainThreadNormalWorld());
     if (!windowProxy)
         return;
     windowProxy->window()->setWebAssemblyEnabled(false, errorMessage);
@@ -486,7 +459,7 @@
 
 void ScriptController::attachDebugger(JSC::Debugger* debugger)
 {
-    for (auto& windowProxy : windowProxies())
+    for (auto& windowProxy : windowProxyController().windowProxies())
         attachDebugger(windowProxy.get(), debugger);
 }
 
@@ -506,7 +479,7 @@
 
 void ScriptController::updateDocument()
 {
-    for (auto& windowProxy : windowProxies()) {
+    for (auto& windowProxy : windowProxyController().windowProxiesAsVector()) {
         JSLockHolder lock(windowProxy->world().vm());
         windowProxy->window()->updateDocument();
     }
@@ -550,7 +523,7 @@
 
 void ScriptController::collectIsolatedContexts(Vector<std::pair<JSC::ExecState*, SecurityOrigin*>>& result)
 {
-    for (auto& windowProxy : m_windowProxies.values()) {
+    for (auto& windowProxy : windowProxyController().windowProxiesAsVector()) {
         auto* exec = windowProxy->window()->globalExec();
         auto* origin = &windowProxy->window()->wrapped().document()->securityOrigin();
         result.append(std::make_pair(exec, origin));
@@ -565,7 +538,7 @@
         if (canExecuteScripts(NotAboutToExecuteScript)) {
             // _javascript_ is enabled, so there is a _javascript_ window object.
             // Return an NPObject bound to the window object.
-            auto* window = windowProxy(pluginWorld())->window();
+            auto* window = windowProxyController().windowProxy(pluginWorld()).window();
             ASSERT(window);
             Bindings::RootObject* root = bindingRootObject();
             m_windowScriptNPObject = _NPN_CreateScriptObject(0, window, root);
@@ -726,7 +699,7 @@
         return true;
 
     String scriptResult;
-    if (!result || !result.getString(windowProxy(mainThreadNormalWorld())->window()->globalExec(), scriptResult))
+    if (!result || !result.getString(windowProxyController().windowProxy(mainThreadNormalWorld()).window()->globalExec(), scriptResult))
         return true;
 
     // FIXME: We should always replace the document, but doing so

Modified: trunk/Source/WebCore/bindings/js/ScriptController.h (230642 => 230643)


--- trunk/Source/WebCore/bindings/js/ScriptController.h	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/bindings/js/ScriptController.h	2018-04-13 21:23:54 UTC (rev 230643)
@@ -23,6 +23,7 @@
 
 #include "FrameLoaderTypes.h"
 #include "JSDOMWindowProxy.h"
+#include "WindowProxyController.h"
 #include <_javascript_Core/JSBase.h>
 #include <_javascript_Core/Strong.h>
 #include <wtf/Forward.h>
@@ -72,7 +73,6 @@
 class ScriptController {
     WTF_MAKE_FAST_ALLOCATED;
 
-    using ProxyMap = HashMap<RefPtr<DOMWrapperWorld>, JSC::Strong<JSDOMWindowProxy>>;
     using RootObjectMap = HashMap<void*, Ref<JSC::Bindings::RootObject>>;
 
 public:
@@ -81,24 +81,9 @@
 
     WEBCORE_EXPORT static Ref<DOMWrapperWorld> createWorld();
 
-    JSDOMWindowProxy& createWindowProxy(DOMWrapperWorld&);
-    void destroyWindowProxy(DOMWrapperWorld&);
-
-    Vector<JSC::Strong<JSDOMWindowProxy>> windowProxies();
-
-    JSDOMWindowProxy* windowProxy(DOMWrapperWorld& world)
-    {
-        auto iter = m_windowProxies.find(&world);
-        return (iter != m_windowProxies.end()) ? iter->value.get() : initScript(world);
-    }
-    JSDOMWindowProxy* existingWindowProxy(DOMWrapperWorld& world) const
-    {
-        auto iter = m_windowProxies.find(&world);
-        return (iter != m_windowProxies.end()) ? iter->value.get() : 0;
-    }
     JSDOMWindow* globalObject(DOMWrapperWorld& world)
     {
-        return windowProxy(world)->window();
+        return windowProxyController().windowProxy(world).window();
     }
 
     static void getAllWorlds(Vector<Ref<DOMWrapperWorld>>&);
@@ -148,7 +133,7 @@
     const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script
 
     void clearWindowProxiesNotMatchingDOMWindow(DOMWindow*, bool goingIntoPageCache);
-    void setDOMWindowForWindowProxy(DOMWindow*);
+    WEBCORE_EXPORT void setDOMWindowForWindowProxy(DOMWindow*);
     void updateDocument();
 
     void namedItemAdded(HTMLDocument*, const AtomicString&) { }
@@ -178,13 +163,15 @@
     WEBCORE_EXPORT NPObject* windowScriptNPObject();
 #endif
 
+    void initScriptForWindowProxy(JSDOMWindowProxy&);
+
 private:
-    WEBCORE_EXPORT JSDOMWindowProxy* initScript(DOMWrapperWorld&);
     void setupModuleScriptHandlers(LoadableModuleScript&, JSC::JSInternalPromise&, DOMWrapperWorld&);
 
     void disconnectPlatformScriptObjects();
 
-    ProxyMap m_windowProxies;
+    WEBCORE_EXPORT WindowProxyController& windowProxyController();
+
     Frame& m_frame;
     const String* m_sourceURL;
 

Modified: trunk/Source/WebCore/bindings/js/ScriptControllerMac.mm (230642 => 230643)


--- trunk/Source/WebCore/bindings/js/ScriptControllerMac.mm	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/bindings/js/ScriptControllerMac.mm	2018-04-13 21:23:54 UTC (rev 230643)
@@ -103,7 +103,7 @@
     if (!m_windowScriptObject) {
         JSC::JSLockHolder lock(commonVM());
         JSC::Bindings::RootObject* root = bindingRootObject();
-        m_windowScriptObject = [WebScriptObject scriptObjectForJSObject:toRef(windowProxy(pluginWorld())) originRootObject:root rootObject:root];
+        m_windowScriptObject = [WebScriptObject scriptObjectForJSObject:toRef(&windowProxyController().windowProxy(pluginWorld())) originRootObject:root rootObject:root];
     }
 
     return m_windowScriptObject.get();

Modified: trunk/Source/WebCore/bindings/js/ScriptState.cpp (230642 => 230643)


--- trunk/Source/WebCore/bindings/js/ScriptState.cpp	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/bindings/js/ScriptState.cpp	2018-04-13 21:23:54 UTC (rev 230643)
@@ -75,7 +75,7 @@
 {
     if (!frame)
         return nullptr;
-    return frame->script().windowProxy(mainThreadNormalWorld())->window()->globalExec();
+    return frame->windowProxyController().windowProxy(mainThreadNormalWorld()).window()->globalExec();
 }
 
 JSC::ExecState* execStateFromNode(DOMWrapperWorld& world, Node* node)

Added: trunk/Source/WebCore/bindings/js/WindowProxyController.cpp (0 => 230643)


--- trunk/Source/WebCore/bindings/js/WindowProxyController.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/WindowProxyController.cpp	2018-04-13 21:23:54 UTC (rev 230643)
@@ -0,0 +1,74 @@
+/*
+ *  Copyright (C) 1999-2001 Harri Porten (por...@kde.org)
+ *  Copyright (C) 2001 Peter Kelly (p...@post.com)
+ *  Copyright (C) 2006-2018 Apple Inc. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "WindowProxyController.h"
+
+#include "Frame.h"
+#include "RemoteFrame.h"
+#include "ScriptController.h"
+#include <_javascript_Core/JSLock.h>
+
+namespace WebCore {
+
+WindowProxyController::WindowProxyController(AbstractFrame& frame)
+    : m_frame(frame)
+{
+}
+
+void WindowProxyController::destroyWindowProxy(DOMWrapperWorld& world)
+{
+    ASSERT(m_windowProxies.contains(&world));
+    m_windowProxies.remove(&world);
+    world.didDestroyWindowProxy(this);
+}
+
+JSDOMWindowProxy& WindowProxyController::createWindowProxy(DOMWrapperWorld& world)
+{
+    ASSERT(!m_windowProxies.contains(&world));
+    ASSERT(m_frame.window());
+
+    VM& vm = world.vm();
+
+    // FIXME: We do not support constructing a JSDOMWindowProxy for a RemoteDOMWindow yet.
+    RELEASE_ASSERT(is<DOMWindow>(m_frame.window()));
+
+    Strong<JSDOMWindowProxy> windowProxy(vm, &JSDOMWindowProxy::create(vm, *downcast<DOMWindow>(m_frame.window()), world));
+    Strong<JSDOMWindowProxy> windowProxy2(windowProxy);
+    m_windowProxies.add(&world, windowProxy);
+    world.didCreateWindowProxy(this);
+    return *windowProxy.get();
+}
+
+Vector<JSC::Strong<JSDOMWindowProxy>> WindowProxyController::windowProxiesAsVector() const
+{
+    return copyToVector(m_windowProxies.values());
+}
+
+JSDOMWindowProxy& WindowProxyController::createWindowProxyWithInitializedScript(DOMWrapperWorld& world)
+{
+    JSLockHolder lock(world.vm());
+    auto& windowProxy = createWindowProxy(world);
+    if (is<Frame>(m_frame))
+        downcast<Frame>(m_frame).script().initScriptForWindowProxy(windowProxy);
+    return windowProxy;
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/bindings/js/WindowProxyController.h (0 => 230643)


--- trunk/Source/WebCore/bindings/js/WindowProxyController.h	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/WindowProxyController.h	2018-04-13 21:23:54 UTC (rev 230643)
@@ -0,0 +1,74 @@
+/*
+ *  Copyright (C) 1999-2001 Harri Porten (por...@kde.org)
+ *  Copyright (C) 2001 Peter Kelly (p...@post.com)
+ *  Copyright (C) 2006-2018 Apple Inc. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#pragma once
+
+#include "JSDOMWindowProxy.h"
+#include <_javascript_Core/Strong.h>
+#include <wtf/HashMap.h>
+
+namespace WebCore {
+
+class AbstractFrame;
+
+class WindowProxyController {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    using ProxyMap = HashMap<RefPtr<DOMWrapperWorld>, JSC::Strong<JSDOMWindowProxy>>;
+
+    explicit WindowProxyController(AbstractFrame&);
+
+    void destroyWindowProxy(DOMWrapperWorld&);
+
+    ProxyMap::ValuesConstIteratorRange windowProxies() const { return m_windowProxies.values(); }
+    Vector<JSC::Strong<JSDOMWindowProxy>> windowProxiesAsVector() const;
+
+    ProxyMap releaseWindowProxies() { return std::exchange(m_windowProxies, ProxyMap()); }
+    void setWindowProxies(ProxyMap&& windowProxies) { m_windowProxies = WTFMove(windowProxies); }
+
+    JSDOMWindowProxy& windowProxy(DOMWrapperWorld& world)
+    {
+        auto it = m_windowProxies.find(&world);
+        if (it != m_windowProxies.end())
+            return *it->value.get();
+
+        return createWindowProxyWithInitializedScript(world);
+    }
+
+    JSDOMWindowProxy* existingWindowProxy(DOMWrapperWorld& world) const
+    {
+        auto it = m_windowProxies.find(&world);
+        return (it != m_windowProxies.end()) ? it->value.get() : nullptr;
+    }
+
+    JSDOMGlobalObject* globalObject(DOMWrapperWorld& world)
+    {
+        return windowProxy(world).window();
+    }
+
+private:
+    JSDOMWindowProxy& createWindowProxy(DOMWrapperWorld&);
+    WEBCORE_EXPORT JSDOMWindowProxy& createWindowProxyWithInitializedScript(DOMWrapperWorld&);
+
+    AbstractFrame& m_frame;
+    ProxyMap m_windowProxies;
+};
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (230642 => 230643)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2018-04-13 21:23:54 UTC (rev 230643)
@@ -3665,7 +3665,7 @@
 
 void FrameLoader::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld& world)
 {
-    if (!m_frame.script().canExecuteScripts(NotAboutToExecuteScript) || !m_frame.script().existingWindowProxy(world))
+    if (!m_frame.script().canExecuteScripts(NotAboutToExecuteScript) || !m_frame.windowProxyController().existingWindowProxy(world))
         return;
 
     m_client.dispatchDidClearWindowObjectInWorld(world);

Modified: trunk/Source/WebCore/page/AbstractFrame.cpp (230642 => 230643)


--- trunk/Source/WebCore/page/AbstractFrame.cpp	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/page/AbstractFrame.cpp	2018-04-13 21:23:54 UTC (rev 230643)
@@ -26,9 +26,12 @@
 #include "config.h"
 #include "AbstractFrame.h"
 
+#include "WindowProxyController.h"
+
 namespace WebCore {
 
 AbstractFrame::AbstractFrame()
+    : m_windowProxyController(makeUniqueRef<WindowProxyController>(*this))
 {
 }
 

Modified: trunk/Source/WebCore/page/AbstractFrame.h (230642 => 230643)


--- trunk/Source/WebCore/page/AbstractFrame.h	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebCore/page/AbstractFrame.h	2018-04-13 21:23:54 UTC (rev 230643)
@@ -41,6 +41,9 @@
     virtual bool isLocalFrame() const = 0;
     virtual bool isRemoteFrame() const = 0;
 
+    WindowProxyController& windowProxyController() { return m_windowProxyController; }
+    const WindowProxyController& windowProxyController() const { return m_windowProxyController; }
+
     AbstractDOMWindow* window() const { return virtualWindow(); }
 
 protected:
@@ -48,6 +51,8 @@
 
 private:
     virtual AbstractDOMWindow* virtualWindow() const = 0;
+
+    UniqueRef<WindowProxyController> m_windowProxyController;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit/ChangeLog (230642 => 230643)


--- trunk/Source/WebKit/ChangeLog	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebKit/ChangeLog	2018-04-13 21:23:54 UTC (rev 230643)
@@ -1,3 +1,17 @@
+2018-04-13  Chris Dumez  <cdu...@apple.com>
+
+        Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame
+        https://bugs.webkit.org/show_bug.cgi?id=184591
+
+        Reviewed by Sam Weinig.
+
+        Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame.
+        RemoteFrames do not need a ScriptController but do need to maintain WindowProxies.
+        This is work towards fixing Bug 184515.
+
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::windowScriptNPObject):
+
 2018-04-13  Brady Eidson  <beid...@apple.com>
 
         Introduce SuspendedPageProxy to keep old web processes around after their WebPageProxy has been swapped to a new one.

Modified: trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp (230642 => 230643)


--- trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp	2018-04-13 21:23:54 UTC (rev 230643)
@@ -1441,14 +1441,14 @@
 NPObject* PluginView::windowScriptNPObject()
 {
     if (!frame())
-        return 0;
+        return nullptr;
 
     if (!frame()->script().canExecuteScripts(NotAboutToExecuteScript)) {
         // FIXME: Investigate if other browsers allow plug-ins to access _javascript_ objects even if _javascript_ is disabled.
-        return 0;
+        return nullptr;
     }
 
-    return m_npRuntimeObjectMap.getOrCreateNPObject(pluginWorld().vm(), frame()->script().windowProxy(pluginWorld())->window());
+    return m_npRuntimeObjectMap.getOrCreateNPObject(pluginWorld().vm(), frame()->windowProxyController().windowProxy(pluginWorld()).window());
 }
 
 NPObject* PluginView::pluginElementNPObject()

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (230642 => 230643)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2018-04-13 21:23:54 UTC (rev 230643)
@@ -1,3 +1,19 @@
+2018-04-13  Chris Dumez  <cdu...@apple.com>
+
+        Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame
+        https://bugs.webkit.org/show_bug.cgi?id=184591
+
+        Reviewed by Sam Weinig.
+
+        Split WindowProxy handling out of ScriptController and into a new class owned by AbstractFrame.
+        RemoteFrames do not need a ScriptController but do need to maintain WindowProxies.
+        This is work towards fixing Bug 184515.
+
+        * Plugins/Hosted/NetscapePluginInstanceProxy.mm:
+        (WebKit::NetscapePluginInstanceProxy::getWindowNPObject):
+        * WebView/WebFrame.mm:
+        (-[WebFrame _attachScriptDebugger]):
+
 2018-04-12  Antoine Quint  <grao...@apple.com>
 
         [Web Animations] Turn CSS Animations and CSS Transitions as Web Animations on by default

Modified: trunk/Source/WebKitLegacy/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm (230642 => 230643)


--- trunk/Source/WebKitLegacy/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebKitLegacy/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm	2018-04-13 21:23:54 UTC (rev 230643)
@@ -839,7 +839,7 @@
     if (!frame->script().canExecuteScripts(NotAboutToExecuteScript))
         objectID = 0;
     else
-        objectID = m_localObjects.idForObject(pluginWorld().vm(), frame->script().windowProxy(pluginWorld())->window());
+        objectID = m_localObjects.idForObject(pluginWorld().vm(), frame->windowProxyController().windowProxy(pluginWorld()).window());
         
     return true;
 }

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm (230642 => 230643)


--- trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm	2018-04-13 18:40:07 UTC (rev 230642)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm	2018-04-13 21:23:54 UTC (rev 230643)
@@ -360,15 +360,15 @@
 
 - (void)_attachScriptDebugger
 {
-    ScriptController& scriptController = _private->coreFrame->script();
+    auto& windowProxyController = _private->coreFrame->windowProxyController();
 
     // Calling ScriptController::globalObject() would create a window proxy, and dispatch corresponding callbacks, which may be premature
     // if the script debugger is attached before a document is created.  These calls use the debuggerWorld(), we will need to pass a world
     // to be able to debug isolated worlds.
-    if (!scriptController.existingWindowProxy(debuggerWorld()))
+    if (!windowProxyController.existingWindowProxy(debuggerWorld()))
         return;
 
-    JSGlobalObject* globalObject = scriptController.globalObject(debuggerWorld());
+    auto* globalObject = windowProxyController.globalObject(debuggerWorld());
     if (!globalObject)
         return;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to