Title: [243243] trunk/Source
Revision
243243
Author
[email protected]
Date
2019-03-20 14:53:06 -0700 (Wed, 20 Mar 2019)

Log Message

Web Inspector: Runtime: lazily create the agent
https://bugs.webkit.org/show_bug.cgi?id=195972
<rdar://problem/49039655>

Reviewed by Timothy Hatcher.

Source/_javascript_Core:

* 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.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (243242 => 243243)


--- trunk/Source/_javascript_Core/ChangeLog	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-03-20 21:53:06 UTC (rev 243243)
@@ -1,3 +1,25 @@
+2019-03-20  Devin Rousso  <[email protected]>
+
+        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  <[email protected]>
 
         JSC test crash: stress/dont-strength-reduce-regexp-with-compile-error.js.default

Modified: trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.cpp (243242 => 243243)


--- trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.cpp	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/_javascript_Core/inspector/JSGlobalObjectInspectorController.cpp	2019-03-20 21:53:06 UTC (rev 243243)
@@ -72,7 +72,6 @@
     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 @@
     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 @@
 
     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);

Modified: trunk/Source/_javascript_Core/inspector/agents/InspectorRuntimeAgent.cpp (243242 => 243243)


--- trunk/Source/_javascript_Core/inspector/agents/InspectorRuntimeAgent.cpp	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/_javascript_Core/inspector/agents/InspectorRuntimeAgent.cpp	2019-03-20 21:53:06 UTC (rev 243243)
@@ -332,10 +332,17 @@
         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&)

Modified: trunk/Source/_javascript_Core/inspector/agents/InspectorRuntimeAgent.h (243242 => 243243)


--- trunk/Source/_javascript_Core/inspector/agents/InspectorRuntimeAgent.h	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/_javascript_Core/inspector/agents/InspectorRuntimeAgent.h	2019-03-20 21:53:06 UTC (rev 243243)
@@ -53,6 +53,7 @@
 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 @@
     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&);
 

Modified: trunk/Source/_javascript_Core/inspector/agents/JSGlobalObjectRuntimeAgent.cpp (243242 => 243243)


--- trunk/Source/_javascript_Core/inspector/agents/JSGlobalObjectRuntimeAgent.cpp	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/_javascript_Core/inspector/agents/JSGlobalObjectRuntimeAgent.cpp	2019-03-20 21:53:06 UTC (rev 243243)
@@ -42,10 +42,6 @@
 {
 }
 
-void JSGlobalObjectRuntimeAgent::didCreateFrontendAndBackend(FrontendRouter*, BackendDispatcher*)
-{
-}
-
 InjectedScript JSGlobalObjectRuntimeAgent::injectedScriptForEval(ErrorString& errorString, const int* executionContextId)
 {
     ASSERT_UNUSED(executionContextId, !executionContextId);

Modified: trunk/Source/_javascript_Core/inspector/agents/JSGlobalObjectRuntimeAgent.h (243242 => 243243)


--- trunk/Source/_javascript_Core/inspector/agents/JSGlobalObjectRuntimeAgent.h	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/_javascript_Core/inspector/agents/JSGlobalObjectRuntimeAgent.h	2019-03-20 21:53:06 UTC (rev 243243)
@@ -40,8 +40,6 @@
 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

Modified: trunk/Source/WebCore/ChangeLog (243242 => 243243)


--- trunk/Source/WebCore/ChangeLog	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/WebCore/ChangeLog	2019-03-20 21:53:06 UTC (rev 243243)
@@ -1,3 +1,36 @@
+2019-03-20  Devin Rousso  <[email protected]>
+
+        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  <[email protected]>
 
         [CSS OM] StyledElementInlineStylePropertyMap creates a Ref cycle with its owner element

Modified: trunk/Source/WebCore/inspector/InspectorController.cpp (243242 => 243243)


--- trunk/Source/WebCore/inspector/InspectorController.cpp	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/WebCore/inspector/InspectorController.cpp	2019-03-20 21:53:06 UTC (rev 243243)
@@ -115,10 +115,6 @@
     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 @@
 
     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(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));

Modified: trunk/Source/WebCore/inspector/WorkerInspectorController.cpp (243242 => 243243)


--- trunk/Source/WebCore/inspector/WorkerInspectorController.cpp	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/WebCore/inspector/WorkerInspectorController.cpp	2019-03-20 21:53:06 UTC (rev 243243)
@@ -71,8 +71,6 @@
 
     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 @@
 
     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));

Modified: trunk/Source/WebCore/inspector/agents/page/PageRuntimeAgent.cpp (243242 => 243243)


--- trunk/Source/WebCore/inspector/agents/page/PageRuntimeAgent.cpp	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/WebCore/inspector/agents/page/PageRuntimeAgent.cpp	2019-03-20 21:53:06 UTC (rev 243243)
@@ -53,45 +53,30 @@
 
 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);
 }
@@ -98,13 +83,12 @@
 
 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::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);

Modified: trunk/Source/WebCore/inspector/agents/page/PageRuntimeAgent.h (243242 => 243243)


--- trunk/Source/WebCore/inspector/agents/page/PageRuntimeAgent.h	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/WebCore/inspector/agents/page/PageRuntimeAgent.h	2019-03-20 21:53:06 UTC (rev 243243)
@@ -41,7 +41,6 @@
 
 namespace WebCore {
 
-class InspectorPageAgent;
 class Frame;
 class Page;
 class SecurityOrigin;
@@ -51,11 +50,10 @@
     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 @@
 
     std::unique_ptr<Inspector::RuntimeFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::RuntimeBackendDispatcher> m_backendDispatcher;
-    InspectorPageAgent* m_pageAgent;
 
+    InstrumentingAgents& m_instrumentingAgents;
+
     Page& m_inspectedPage;
-
-    bool m_mainWorldContextCreated { false };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp (243242 => 243243)


--- trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.cpp	2019-03-20 21:53:06 UTC (rev 243243)
@@ -49,15 +49,6 @@
     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) {

Modified: trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.h (243242 => 243243)


--- trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.h	2019-03-20 21:49:13 UTC (rev 243242)
+++ trunk/Source/WebCore/inspector/agents/worker/WorkerRuntimeAgent.h	2019-03-20 21:53:06 UTC (rev 243243)
@@ -46,9 +46,6 @@
     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;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to