Web Inspector: Runtime: lazily create the agent
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Mar 2019 21:53:06 +0000 (21:53 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Mar 2019 21:53:06 +0000 (21:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195972
<rdar://problem/49039655>

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* inspector/JSGlobalObjectInspectorController.cpp:
(Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController):
(Inspector::JSGlobalObjectInspectorController::createLazyAgents):

* inspector/agents/InspectorRuntimeAgent.h:
(Inspector::InspectorRuntimeAgent::enabled): Deleted.
* inspector/agents/InspectorRuntimeAgent.cpp:
(Inspector::InspectorRuntimeAgent::didCreateFrontendAndBackend): Added.
(Inspector::InspectorRuntimeAgent::willDestroyFrontendAndBackend):

* inspector/agents/JSGlobalObjectRuntimeAgent.h:
* inspector/agents/JSGlobalObjectRuntimeAgent.cpp:
(Inspector::JSGlobalObjectRuntimeAgent::didCreateFrontendAndBackend): Deleted.

Source/WebCore:

No change in functionality.

* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
(WebCore::InspectorController::createLazyAgents):

* inspector/WorkerInspectorController.cpp:
(WebCore::WorkerInspectorController::WorkerInspectorController):
(WebCore::WorkerInspectorController::createLazyAgents):

* inspector/agents/page/PageRuntimeAgent.h:
* inspector/agents/page/PageRuntimeAgent.cpp:
(WebCore::PageRuntimeAgent::PageRuntimeAgent):
(WebCore::PageRuntimeAgent::enable):
(WebCore::PageRuntimeAgent::disable):
(WebCore::PageRuntimeAgent::didCreateMainWorldContext):
(WebCore::PageRuntimeAgent::reportExecutionContextCreation):
(WebCore::PageRuntimeAgent::didCreateFrontendAndBackend): Deleted.
(WebCore::PageRuntimeAgent::willDestroyFrontendAndBackend): Deleted.

* inspector/agents/worker/WorkerRuntimeAgent.h:
* inspector/agents/worker/WorkerRuntimeAgent.cpp:
(WebCore::WorkerRuntimeAgent::didCreateFrontendAndBackend): Deleted.
(WebCore::WorkerRuntimeAgent::willDestroyFrontendAndBackend): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243243 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.cpp
Source/JavaScriptCore/inspector/agents/InspectorRuntimeAgent.cpp
Source/JavaScriptCore/inspector/agents/InspectorRuntimeAgent.h
Source/JavaScriptCore/inspector/agents/JSGlobalObjectRuntimeAgent.cpp
Source/JavaScriptCore/inspector/agents/JSGlobalObjectRuntimeAgent.h
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/WorkerInspectorController.cpp
Source/WebCore/inspector/agents/page/PageRuntimeAgent.cpp
Source/WebCore/inspector/agents/page/PageRuntimeAgent.h
Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp
Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.h

index ac71ce7..66ec261 100644 (file)
@@ -1,3 +1,25 @@
+2019-03-20  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Runtime: lazily create the agent
+        https://bugs.webkit.org/show_bug.cgi?id=195972
+        <rdar://problem/49039655>
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/JSGlobalObjectInspectorController.cpp:
+        (Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController):
+        (Inspector::JSGlobalObjectInspectorController::createLazyAgents):
+
+        * inspector/agents/InspectorRuntimeAgent.h:
+        (Inspector::InspectorRuntimeAgent::enabled): Deleted.
+        * inspector/agents/InspectorRuntimeAgent.cpp:
+        (Inspector::InspectorRuntimeAgent::didCreateFrontendAndBackend): Added.
+        (Inspector::InspectorRuntimeAgent::willDestroyFrontendAndBackend):
+
+        * inspector/agents/JSGlobalObjectRuntimeAgent.h:
+        * inspector/agents/JSGlobalObjectRuntimeAgent.cpp:
+        (Inspector::JSGlobalObjectRuntimeAgent::didCreateFrontendAndBackend): Deleted.
+
 2019-03-20  Michael Saboff  <msaboff@apple.com>
 
         JSC test crash: stress/dont-strength-reduce-regexp-with-compile-error.js.default
index 7bc921c..d306eb6 100644 (file)
@@ -72,7 +72,6 @@ JSGlobalObjectInspectorController::JSGlobalObjectInspectorController(JSGlobalObj
     auto context = jsAgentContext();
 
     auto inspectorAgent = std::make_unique<InspectorAgent>(context);
-    auto runtimeAgent = std::make_unique<JSGlobalObjectRuntimeAgent>(context);
     auto consoleAgent = std::make_unique<InspectorConsoleAgent>(context);
 
     m_inspectorAgent = inspectorAgent.get();
@@ -80,7 +79,6 @@ JSGlobalObjectInspectorController::JSGlobalObjectInspectorController(JSGlobalObj
     m_consoleClient = std::make_unique<JSGlobalObjectConsoleClient>(m_consoleAgent);
 
     m_agents.append(WTFMove(inspectorAgent));
-    m_agents.append(WTFMove(runtimeAgent));
     m_agents.append(WTFMove(consoleAgent));
 
     m_executionStopwatch->start();
@@ -309,6 +307,8 @@ void JSGlobalObjectInspectorController::createLazyAgents()
 
     auto context = jsAgentContext();
 
+    m_agents.append(std::make_unique<JSGlobalObjectRuntimeAgent>(context));
+
     auto debuggerAgent = std::make_unique<JSGlobalObjectDebuggerAgent>(context, m_consoleAgent);
     m_debuggerAgent = debuggerAgent.get();
     m_consoleClient->setInspectorDebuggerAgent(m_debuggerAgent);
index 89bc203..1f01b10 100644 (file)
@@ -332,10 +332,17 @@ void InspectorRuntimeAgent::getRuntimeTypesForVariablesAtOffsets(ErrorString& er
         dataLogF("Inspector::getRuntimeTypesForVariablesAtOffsets took %lfms\n", (end - start).milliseconds());
 }
 
+void InspectorRuntimeAgent::didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*)
+{
+}
+
 void InspectorRuntimeAgent::willDestroyFrontendAndBackend(DisconnectReason reason)
 {
     if (reason != DisconnectReason::InspectedTargetDestroyed && m_isTypeProfilingEnabled)
         setTypeProfilerEnabledState(false);
+
+    String unused;
+    disable(unused);
 }
 
 void InspectorRuntimeAgent::enableTypeProfiler(ErrorString&)
index ea63d0b..038f616 100644 (file)
@@ -53,6 +53,7 @@ class JS_EXPORT_PRIVATE InspectorRuntimeAgent : public InspectorAgentBase, publi
 public:
     virtual ~InspectorRuntimeAgent();
 
+    void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
     void willDestroyFrontendAndBackend(DisconnectReason) override;
 
     void enable(ErrorString&) override { m_enabled = true; }
@@ -75,8 +76,6 @@ public:
     void disableControlFlowProfiler(ErrorString&) override;
     void getBasicBlocks(ErrorString&, const String& in_sourceID, RefPtr<JSON::ArrayOf<Protocol::Runtime::BasicBlock>>& out_basicBlocks) override;
 
-    bool enabled() const { return m_enabled; }
-
 protected:
     InspectorRuntimeAgent(AgentContext&);
 
index 3fdc9af..145d051 100644 (file)
@@ -42,10 +42,6 @@ JSGlobalObjectRuntimeAgent::JSGlobalObjectRuntimeAgent(JSAgentContext& context)
 {
 }
 
-void JSGlobalObjectRuntimeAgent::didCreateFrontendAndBackend(FrontendRouter*, BackendDispatcher*)
-{
-}
-
 InjectedScript JSGlobalObjectRuntimeAgent::injectedScriptForEval(ErrorString& errorString, const int* executionContextId)
 {
     ASSERT_UNUSED(executionContextId, !executionContextId);
index eda4fbb..66cd2d2 100644 (file)
@@ -40,8 +40,6 @@ class JSGlobalObjectRuntimeAgent final : public InspectorRuntimeAgent {
 public:
     JSGlobalObjectRuntimeAgent(JSAgentContext&);
 
-    void didCreateFrontendAndBackend(FrontendRouter*, BackendDispatcher*) override;
-
     InjectedScript injectedScriptForEval(ErrorString&, const int* executionContextId) override;
 
     // NOTE: JavaScript inspector does not yet need to mute a console because no messages
index 978b211..c91cb80 100644 (file)
@@ -1,3 +1,36 @@
+2019-03-20  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Runtime: lazily create the agent
+        https://bugs.webkit.org/show_bug.cgi?id=195972
+        <rdar://problem/49039655>
+
+        Reviewed by Timothy Hatcher.
+
+        No change in functionality.
+
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        (WebCore::InspectorController::createLazyAgents):
+
+        * inspector/WorkerInspectorController.cpp:
+        (WebCore::WorkerInspectorController::WorkerInspectorController):
+        (WebCore::WorkerInspectorController::createLazyAgents):
+
+        * inspector/agents/page/PageRuntimeAgent.h:
+        * inspector/agents/page/PageRuntimeAgent.cpp:
+        (WebCore::PageRuntimeAgent::PageRuntimeAgent):
+        (WebCore::PageRuntimeAgent::enable):
+        (WebCore::PageRuntimeAgent::disable):
+        (WebCore::PageRuntimeAgent::didCreateMainWorldContext):
+        (WebCore::PageRuntimeAgent::reportExecutionContextCreation):
+        (WebCore::PageRuntimeAgent::didCreateFrontendAndBackend): Deleted.
+        (WebCore::PageRuntimeAgent::willDestroyFrontendAndBackend): Deleted.
+
+        * inspector/agents/worker/WorkerRuntimeAgent.h:
+        * inspector/agents/worker/WorkerRuntimeAgent.cpp:
+        (WebCore::WorkerRuntimeAgent::didCreateFrontendAndBackend): Deleted.
+        (WebCore::WorkerRuntimeAgent::willDestroyFrontendAndBackend): Deleted.
+
 2019-03-19  Ryosuke Niwa  <rniwa@webkit.org>
 
         [CSS OM] StyledElementInlineStylePropertyMap creates a Ref cycle with its owner element
index 05f1961..831e773 100644 (file)
@@ -115,10 +115,6 @@ InspectorController::InspectorController(Page& page, InspectorClient* inspectorC
     m_pageAgent = pageAgentPtr.get();
     m_agents.append(WTFMove(pageAgentPtr));
 
-    auto runtimeAgent = std::make_unique<PageRuntimeAgent>(pageContext, pageAgent);
-    m_instrumentingAgents->setPageRuntimeAgent(runtimeAgent.get());
-    m_agents.append(WTFMove(runtimeAgent));
-
     auto domAgentPtr = std::make_unique<InspectorDOMAgent>(pageContext, pageAgent, m_overlay.get());
     m_domAgent = domAgentPtr.get();
     m_agents.append(WTFMove(domAgentPtr));
@@ -169,10 +165,12 @@ void InspectorController::createLazyAgents()
 
     auto pageContext = pageAgentContext();
 
+    m_agents.append(std::make_unique<PageRuntimeAgent>(pageContext));
+
     auto debuggerAgent = std::make_unique<PageDebuggerAgent>(pageContext, m_pageAgent);
     auto debuggerAgentPtr = debuggerAgent.get();
-
     m_agents.append(WTFMove(debuggerAgent));
+
     m_agents.append(std::make_unique<PageNetworkAgent>(pageContext, m_pageAgent));
     m_agents.append(std::make_unique<InspectorCSSAgent>(pageContext, m_domAgent));
     m_agents.append(std::make_unique<InspectorDOMDebuggerAgent>(pageContext, m_domAgent, debuggerAgentPtr));
index c54b55d..de89ee2 100644 (file)
@@ -71,8 +71,6 @@ WorkerInspectorController::WorkerInspectorController(WorkerGlobalScope& workerGl
 
     auto consoleAgent = std::make_unique<WorkerConsoleAgent>(workerContext);
     m_instrumentingAgents->setWebConsoleAgent(consoleAgent.get());
-
-    m_agents.append(std::make_unique<WorkerRuntimeAgent>(workerContext));
     m_agents.append(WTFMove(consoleAgent));
 
     if (auto* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
@@ -167,6 +165,8 @@ void WorkerInspectorController::createLazyAgents()
 
     auto workerContext = workerAgentContext();
 
+    m_agents.append(std::make_unique<WorkerRuntimeAgent>(workerContext));
+
 #if ENABLE(SERVICE_WORKER)
     if (is<ServiceWorkerGlobalScope>(m_workerGlobalScope)) {
         m_agents.append(std::make_unique<ServiceWorkerAgent>(workerContext));
index 68b4996..82d87dc 100644 (file)
@@ -53,58 +53,42 @@ namespace WebCore {
 
 using namespace Inspector;
 
-PageRuntimeAgent::PageRuntimeAgent(PageAgentContext& context, InspectorPageAgent* pageAgent)
+PageRuntimeAgent::PageRuntimeAgent(PageAgentContext& context)
     : InspectorRuntimeAgent(context)
     , m_frontendDispatcher(std::make_unique<Inspector::RuntimeFrontendDispatcher>(context.frontendRouter))
     , m_backendDispatcher(Inspector::RuntimeBackendDispatcher::create(context.backendDispatcher, this))
-    , m_pageAgent(pageAgent)
+    , m_instrumentingAgents(context.instrumentingAgents)
     , m_inspectedPage(context.inspectedPage)
 {
 }
 
-void PageRuntimeAgent::didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*)
-{
-}
-
-void PageRuntimeAgent::willDestroyFrontendAndBackend(Inspector::DisconnectReason reason)
-{
-    String unused;
-    disable(unused);
-
-    InspectorRuntimeAgent::willDestroyFrontendAndBackend(reason);
-}
-
 void PageRuntimeAgent::enable(ErrorString& errorString)
 {
-    if (enabled())
-        return;
+    bool enabled = m_instrumentingAgents.pageRuntimeAgent() == this;
 
     InspectorRuntimeAgent::enable(errorString);
 
-    // Only report existing contexts if the page did commit load, otherwise we may
-    // unintentionally initialize contexts in the frames which may trigger some listeners
-    // that are expected to be triggered only after the load is committed, see http://crbug.com/131623
-    if (m_mainWorldContextCreated)
+    m_instrumentingAgents.setPageRuntimeAgent(this);
+
+    if (!enabled)
         reportExecutionContextCreation();
 }
 
 void PageRuntimeAgent::disable(ErrorString& errorString)
 {
-    if (!enabled())
-        return;
+    m_instrumentingAgents.setPageRuntimeAgent(nullptr);
 
     InspectorRuntimeAgent::disable(errorString);
 }
 
 void PageRuntimeAgent::didCreateMainWorldContext(Frame& frame)
 {
-    m_mainWorldContextCreated = true;
-
-    if (!enabled())
+    auto* pageAgent = m_instrumentingAgents.inspectorPageAgent();
+    if (!pageAgent)
         return;
 
-    String frameId = m_pageAgent->frameId(&frame);
-    JSC::ExecState* scriptState = mainWorldExecState(&frame);
+    auto frameId = pageAgent->frameId(&frame);
+    auto* scriptState = mainWorldExecState(&frame);
     notifyContextCreated(frameId, scriptState, nullptr, true);
 }
 
@@ -136,11 +120,15 @@ void PageRuntimeAgent::unmuteConsole()
 
 void PageRuntimeAgent::reportExecutionContextCreation()
 {
+    auto* pageAgent = m_instrumentingAgents.inspectorPageAgent();
+    if (!pageAgent)
+        return;
+
     Vector<std::pair<JSC::ExecState*, SecurityOrigin*>> isolatedContexts;
     for (Frame* frame = &m_inspectedPage.mainFrame(); frame; frame = frame->tree().traverseNext()) {
         if (!frame->script().canExecuteScripts(NotAboutToExecuteScript))
             continue;
-        String frameId = m_pageAgent->frameId(frame);
+        String frameId = pageAgent->frameId(frame);
 
         JSC::ExecState* scriptState = mainWorldExecState(frame);
         notifyContextCreated(frameId, scriptState, nullptr, true);
index 72a4b6c..93a76cc 100644 (file)
@@ -41,7 +41,6 @@ class ExecState;
 
 namespace WebCore {
 
-class InspectorPageAgent;
 class Frame;
 class Page;
 class SecurityOrigin;
@@ -51,11 +50,10 @@ class PageRuntimeAgent final : public Inspector::InspectorRuntimeAgent {
     WTF_MAKE_NONCOPYABLE(PageRuntimeAgent);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    PageRuntimeAgent(PageAgentContext&, InspectorPageAgent*);
+    PageRuntimeAgent(PageAgentContext&);
     virtual ~PageRuntimeAgent() = default;
 
-    void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
-    void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override;
+    // RuntimeBackendDispatcherHandler
     void enable(ErrorString&) override;
     void disable(ErrorString&) override;
     void evaluate(ErrorString&, const String& expression, const String* objectGroup, const bool* includeCommandLineAPI, const bool* doNotPauseOnExceptionsAndMuteConsole, const int* executionContextId, const bool* returnByValue, const bool* generatePreview, const bool* saveResult, const bool* emulateUserGesture, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result, Optional<bool>& wasThrown, Optional<int>& savedResultIndex) final;
@@ -72,11 +70,10 @@ private:
 
     std::unique_ptr<Inspector::RuntimeFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::RuntimeBackendDispatcher> m_backendDispatcher;
-    InspectorPageAgent* m_pageAgent;
 
-    Page& m_inspectedPage;
+    InstrumentingAgents& m_instrumentingAgents;
 
-    bool m_mainWorldContextCreated { false };
+    Page& m_inspectedPage;
 };
 
 } // namespace WebCore
index 8c32148..1b0f7d0 100644 (file)
@@ -49,15 +49,6 @@ WorkerRuntimeAgent::WorkerRuntimeAgent(WorkerAgentContext& context)
     ASSERT(context.workerGlobalScope.isContextThread());
 }
 
-void WorkerRuntimeAgent::didCreateFrontendAndBackend(FrontendRouter*, BackendDispatcher*)
-{
-}
-
-void WorkerRuntimeAgent::willDestroyFrontendAndBackend(DisconnectReason reason)
-{
-    InspectorRuntimeAgent::willDestroyFrontendAndBackend(reason);
-}
-
 InjectedScript WorkerRuntimeAgent::injectedScriptForEval(ErrorString& errorString, const int* executionContextId)
 {
     if (executionContextId) {
index 78d4f14..e75fc9b 100644 (file)
@@ -46,9 +46,6 @@ public:
     WorkerRuntimeAgent(WorkerAgentContext&);
     ~WorkerRuntimeAgent() = default;
 
-    void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
-    void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override;
-
 private:
     Inspector::InjectedScript injectedScriptForEval(ErrorString&, const int* executionContextId) override;