Web Inspector: DOMStorage: lazily create the agent
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Mar 2019 19:11:07 +0000 (19:11 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Mar 2019 19:11:07 +0000 (19:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195588
<rdar://problem/48791878>

Reviewed by Joseph Pecoraro.

No change in functionality.

Make functions used by `CommandLineAPIHost` static so that an `InspectorDOMStorageAgent`
doesn't need to be created to call them.

* inspector/agents/InspectorDOMStorageAgent.h:
* inspector/agents/InspectorDOMStorageAgent.cpp:
(WebCore::InspectorDOMStorageAgent::InspectorDOMStorageAgent):
(WebCore::InspectorDOMStorageAgent::enable):
(WebCore::InspectorDOMStorageAgent::disable):
(WebCore::InspectorDOMStorageAgent::storageId):
(WebCore::InspectorDOMStorageAgent::didDispatchDOMStorageEvent):
(WebCore::InspectorDOMStorageAgent::findStorageArea):
(WebCore::InspectorDOMStorageAgent::~InspectorDOMStorageAgent): Deleted.

* inspector/CommandLineAPIHost.h:
(WebCore::CommandLineAPIHost::init):
* inspector/CommandLineAPIHost.cpp:
(WebCore::CommandLineAPIHost::disconnect):
(WebCore::CommandLineAPIHost::storageId):

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

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

Source/WebCore/ChangeLog
Source/WebCore/inspector/CommandLineAPIHost.cpp
Source/WebCore/inspector/CommandLineAPIHost.h
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/WorkerInspectorController.cpp
Source/WebCore/inspector/agents/InspectorDOMStorageAgent.cpp
Source/WebCore/inspector/agents/InspectorDOMStorageAgent.h

index c129a41..9fca32e 100644 (file)
@@ -1,3 +1,38 @@
+2019-03-19  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: DOMStorage: lazily create the agent
+        https://bugs.webkit.org/show_bug.cgi?id=195588
+        <rdar://problem/48791878>
+
+        Reviewed by Joseph Pecoraro.
+
+        No change in functionality.
+
+        Make functions used by `CommandLineAPIHost` static so that an `InspectorDOMStorageAgent`
+        doesn't need to be created to call them.
+
+        * inspector/agents/InspectorDOMStorageAgent.h:
+        * inspector/agents/InspectorDOMStorageAgent.cpp:
+        (WebCore::InspectorDOMStorageAgent::InspectorDOMStorageAgent):
+        (WebCore::InspectorDOMStorageAgent::enable):
+        (WebCore::InspectorDOMStorageAgent::disable):
+        (WebCore::InspectorDOMStorageAgent::storageId):
+        (WebCore::InspectorDOMStorageAgent::didDispatchDOMStorageEvent):
+        (WebCore::InspectorDOMStorageAgent::findStorageArea):
+        (WebCore::InspectorDOMStorageAgent::~InspectorDOMStorageAgent): Deleted.
+
+        * inspector/CommandLineAPIHost.h:
+        (WebCore::CommandLineAPIHost::init):
+        * inspector/CommandLineAPIHost.cpp:
+        (WebCore::CommandLineAPIHost::disconnect):
+        (WebCore::CommandLineAPIHost::storageId):
+
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        (WebCore::InspectorController::createLazyAgents):
+        * inspector/WorkerInspectorController.cpp:
+        (WebCore::WorkerInspectorController::WorkerInspectorController):
+
 2019-03-19  Youenn Fablet  <youenn@apple.com>
 
         REGRESSION: Layout Test http/tests/security/cross-origin-indexeddb.html is crashing
index 3f983fa..69e434a 100644 (file)
@@ -71,7 +71,6 @@ void CommandLineAPIHost::disconnect()
 {
     m_inspectorAgent = nullptr;
     m_consoleAgent = nullptr;
-    m_domStorageAgent = nullptr;
     m_databaseAgent = nullptr;
 }
 
@@ -167,9 +166,7 @@ String CommandLineAPIHost::databaseId(Database& database)
 
 String CommandLineAPIHost::storageId(Storage& storage)
 {
-    if (m_domStorageAgent)
-        return m_domStorageAgent->storageId(storage);
-    return { };
+    return InspectorDOMStorageAgent::storageId(storage);
 }
 
 JSValue CommandLineAPIHost::wrapper(ExecState* exec, JSDOMGlobalObject* globalObject)
index f0d2062..2dcc7ac 100644 (file)
@@ -47,7 +47,6 @@ namespace WebCore {
 
 class Database;
 class EventTarget;
-class InspectorDOMStorageAgent;
 class InspectorDatabaseAgent;
 class JSDOMGlobalObject;
 class Storage;
@@ -61,13 +60,11 @@ public:
 
     void init(Inspector::InspectorAgent* inspectorAgent
         , Inspector::InspectorConsoleAgent* consoleAgent
-        , InspectorDOMStorageAgent* domStorageAgent
         , InspectorDatabaseAgent* databaseAgent
         )
     {
         m_inspectorAgent = inspectorAgent;
         m_consoleAgent = consoleAgent;
-        m_domStorageAgent = domStorageAgent;
         m_databaseAgent = databaseAgent;
     }
 
@@ -107,7 +104,6 @@ private:
 
     Inspector::InspectorAgent* m_inspectorAgent { nullptr };
     Inspector::InspectorConsoleAgent* m_consoleAgent { nullptr };
-    InspectorDOMStorageAgent* m_domStorageAgent { nullptr };
     InspectorDatabaseAgent* m_databaseAgent { nullptr };
 
     std::unique_ptr<InspectableObject> m_inspectedObject; // $0
index d6e8997..ce62107 100644 (file)
@@ -127,10 +127,6 @@ InspectorController::InspectorController(Page& page, InspectorClient* inspectorC
     InspectorDatabaseAgent* databaseAgent = databaseAgentPtr.get();
     m_agents.append(WTFMove(databaseAgentPtr));
 
-    auto domStorageAgentPtr = std::make_unique<InspectorDOMStorageAgent>(pageContext, m_pageAgent);
-    InspectorDOMStorageAgent* domStorageAgent = domStorageAgentPtr.get();
-    m_agents.append(WTFMove(domStorageAgentPtr));
-
     auto scriptProfilerAgentPtr = std::make_unique<InspectorScriptProfilerAgent>(pageContext);
     m_instrumentingAgents->setInspectorScriptProfilerAgent(scriptProfilerAgentPtr.get());
     m_agents.append(WTFMove(scriptProfilerAgentPtr));
@@ -142,7 +138,7 @@ InspectorController::InspectorController(Page& page, InspectorClient* inspectorC
 
     ASSERT(m_injectedScriptManager->commandLineAPIHost());
     if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
-        commandLineAPIHost->init(m_inspectorAgent, consoleAgent, domStorageAgent, databaseAgent);
+        commandLineAPIHost->init(m_inspectorAgent, consoleAgent, databaseAgent);
 }
 
 InspectorController::~InspectorController()
@@ -192,14 +188,15 @@ void InspectorController::createLazyAgents()
     m_agents.append(std::make_unique<InspectorApplicationCacheAgent>(pageContext, m_pageAgent));
     m_agents.append(std::make_unique<InspectorLayerTreeAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorWorkerAgent>(pageContext));
+    m_agents.append(std::make_unique<InspectorDOMStorageAgent>(pageContext));
 #if ENABLE(INDEXED_DATABASE)
     m_agents.append(std::make_unique<InspectorIndexedDBAgent>(pageContext, m_pageAgent));
 #endif
 #if ENABLE(RESOURCE_USAGE)
     m_agents.append(std::make_unique<InspectorCPUProfilerAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorMemoryAgent>(pageContext));
-    m_agents.append(std::make_unique<PageHeapAgent>(pageContext));
 #endif
+    m_agents.append(std::make_unique<PageHeapAgent>(pageContext));
     m_agents.append(std::make_unique<PageAuditAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorCanvasAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorTimelineAgent>(pageContext));
index b8ee440..0c98bc7 100644 (file)
@@ -77,7 +77,7 @@ WorkerInspectorController::WorkerInspectorController(WorkerGlobalScope& workerGl
     m_agents.append(WTFMove(consoleAgent));
 
     if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
-        commandLineAPIHost->init(nullptr, m_instrumentingAgents->webConsoleAgent(), nullptr, nullptr);
+        commandLineAPIHost->init(nullptr, m_instrumentingAgents->webConsoleAgent(), nullptr);
 }
 
 WorkerInspectorController::~WorkerInspectorController()
index 6a7a874..f096ea9 100644 (file)
@@ -54,18 +54,11 @@ namespace WebCore {
 
 using namespace Inspector;
 
-InspectorDOMStorageAgent::InspectorDOMStorageAgent(WebAgentContext& context, InspectorPageAgent* pageAgent)
+InspectorDOMStorageAgent::InspectorDOMStorageAgent(WebAgentContext& context)
     : InspectorAgentBase("DOMStorage"_s, context)
     , m_frontendDispatcher(std::make_unique<Inspector::DOMStorageFrontendDispatcher>(context.frontendRouter))
     , m_backendDispatcher(Inspector::DOMStorageBackendDispatcher::create(context.backendDispatcher, this))
-    , m_pageAgent(pageAgent)
 {
-    m_instrumentingAgents.setInspectorDOMStorageAgent(this);
-}
-
-InspectorDOMStorageAgent::~InspectorDOMStorageAgent()
-{
-    m_instrumentingAgents.setInspectorDOMStorageAgent(nullptr);
 }
 
 void InspectorDOMStorageAgent::didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*)
@@ -80,12 +73,12 @@ void InspectorDOMStorageAgent::willDestroyFrontendAndBackend(Inspector::Disconne
 
 void InspectorDOMStorageAgent::enable(ErrorString&)
 {
-    m_enabled = true;
+    m_instrumentingAgents.setInspectorDOMStorageAgent(this);
 }
 
 void InspectorDOMStorageAgent::disable(ErrorString&)
 {
-    m_enabled = false;
+    m_instrumentingAgents.setInspectorDOMStorageAgent(nullptr);
 }
 
 void InspectorDOMStorageAgent::getDOMStorageItems(ErrorString& errorString, const JSON::Object& storageId, RefPtr<JSON::ArrayOf<JSON::ArrayOf<String>>>& items)
@@ -147,7 +140,7 @@ String InspectorDOMStorageAgent::storageId(Storage& storage)
     ASSERT(window);
     Ref<SecurityOrigin> securityOrigin = document->securityOrigin();
     bool isLocalStorage = window->optionalLocalStorage() == &storage;
-    return storageId(securityOrigin.ptr(), isLocalStorage)->toJSONString();
+    return InspectorDOMStorageAgent::storageId(securityOrigin.ptr(), isLocalStorage)->toJSONString();
 }
 
 RefPtr<Inspector::Protocol::DOMStorage::StorageId> InspectorDOMStorageAgent::storageId(SecurityOrigin* securityOrigin, bool isLocalStorage)
@@ -160,10 +153,7 @@ RefPtr<Inspector::Protocol::DOMStorage::StorageId> InspectorDOMStorageAgent::sto
 
 void InspectorDOMStorageAgent::didDispatchDOMStorageEvent(const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin)
 {
-    if (!m_enabled)
-        return;
-
-    RefPtr<Inspector::Protocol::DOMStorage::StorageId> id = storageId(securityOrigin, storageType == StorageType::Local);
+    RefPtr<Inspector::Protocol::DOMStorage::StorageId> id = InspectorDOMStorageAgent::storageId(securityOrigin, storageType == StorageType::Local);
 
     if (key.isNull())
         m_frontendDispatcher->domStorageItemsCleared(id);
@@ -188,15 +178,22 @@ RefPtr<StorageArea> InspectorDOMStorageAgent::findStorageArea(ErrorString& error
         return nullptr;
     }
 
-    targetFrame = m_pageAgent->findFrameWithSecurityOrigin(securityOrigin);
+    auto* pageAgent = m_instrumentingAgents.inspectorPageAgent();
+    ASSERT(pageAgent);
+    if (!pageAgent) {
+        errorString = "Missing Page agent"_s;
+        return nullptr;
+    }
+
+    targetFrame = pageAgent->findFrameWithSecurityOrigin(securityOrigin);
     if (!targetFrame) {
         errorString = "Frame not found for the given security origin"_s;
         return nullptr;
     }
 
     if (!isLocalStorage)
-        return m_pageAgent->page().sessionStorage()->storageArea(targetFrame->document()->securityOrigin().data());
-    return m_pageAgent->page().storageNamespaceProvider().localStorageArea(*targetFrame->document());
+        return pageAgent->page().sessionStorage()->storageArea(targetFrame->document()->securityOrigin().data());
+    return pageAgent->page().storageNamespaceProvider().localStorageArea(*targetFrame->document());
 }
 
 } // namespace WebCore
index 1de872e..5d4ff63 100644 (file)
@@ -41,7 +41,6 @@ class DOMStorageFrontendDispatcher;
 namespace WebCore {
 
 class Frame;
-class InspectorPageAgent;
 class Page;
 class SecurityOrigin;
 class Storage;
@@ -52,8 +51,8 @@ class InspectorDOMStorageAgent final : public InspectorAgentBase, public Inspect
     WTF_MAKE_NONCOPYABLE(InspectorDOMStorageAgent);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    InspectorDOMStorageAgent(WebAgentContext&, InspectorPageAgent*);
-    virtual ~InspectorDOMStorageAgent();
+    InspectorDOMStorageAgent(WebAgentContext&);
+    virtual ~InspectorDOMStorageAgent() = default;
 
     void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
     void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override;
@@ -66,8 +65,8 @@ public:
     void removeDOMStorageItem(ErrorString&, const JSON::Object& storageId, const String& key) override;
 
     // Called from the injected script.
-    String storageId(Storage&);
-    RefPtr<Inspector::Protocol::DOMStorage::StorageId> storageId(SecurityOrigin*, bool isLocalStorage);
+    static String storageId(Storage&);
+    static RefPtr<Inspector::Protocol::DOMStorage::StorageId> storageId(SecurityOrigin*, bool isLocalStorage);
 
     // InspectorInstrumentation
     void didDispatchDOMStorageEvent(const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*);
@@ -77,9 +76,6 @@ private:
 
     std::unique_ptr<Inspector::DOMStorageFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::DOMStorageBackendDispatcher> m_backendDispatcher;
-    InspectorPageAgent* m_pageAgent { nullptr };
-
-    bool m_enabled { false };
 };
 
 } // namespace WebCore