2011-04-04 Yury Semikhatsky <yurys@chromium.org>
authoryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Apr 2011 17:32:51 +0000 (17:32 +0000)
committeryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Apr 2011 17:32:51 +0000 (17:32 +0000)
        Reviewed by Pavel Feldman.

        Web Inspector: InspectorRuntimeAgent should not depend on Page
        https://bugs.webkit.org/show_bug.cgi?id=57759

        Descendants of InspectorRuntimeAgent should implement a method providing access to the default
        inspected state used for console evaluations.

        * inspector/InspectorAgent.cpp:
        (WebCore::InspectorAgent::InspectorAgent): runtime agent is created and deleted along with other agents.
        (WebCore::InspectorAgent::setFrontend):
        * inspector/InspectorAgent.h:
        * inspector/InspectorRuntimeAgent.cpp:
        (WebCore::InspectorRuntimeAgent::create):
        (WebCore::InspectorRuntimeAgent::InspectorRuntimeAgent):
        (WebCore::InspectorRuntimeAgent::evaluate):
        * inspector/InspectorRuntimeAgent.h:
        (WebCore::InspectorRuntimeAgent::InspectedStateProvider::~InspectedStateProvider):

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

Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorAgent.cpp
Source/WebCore/inspector/InspectorAgent.h
Source/WebCore/inspector/InspectorRuntimeAgent.cpp
Source/WebCore/inspector/InspectorRuntimeAgent.h

index 7b39188..e8c9ee8 100644 (file)
@@ -1,3 +1,24 @@
+2011-04-04  Yury Semikhatsky  <yurys@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: InspectorRuntimeAgent should not depend on Page
+        https://bugs.webkit.org/show_bug.cgi?id=57759
+
+        Descendants of InspectorRuntimeAgent should implement a method providing access to the default
+        inspected state used for console evaluations.
+
+        * inspector/InspectorAgent.cpp:
+        (WebCore::InspectorAgent::InspectorAgent): runtime agent is created and deleted along with other agents.
+        (WebCore::InspectorAgent::setFrontend):
+        * inspector/InspectorAgent.h:
+        * inspector/InspectorRuntimeAgent.cpp:
+        (WebCore::InspectorRuntimeAgent::create):
+        (WebCore::InspectorRuntimeAgent::InspectorRuntimeAgent):
+        (WebCore::InspectorRuntimeAgent::evaluate):
+        * inspector/InspectorRuntimeAgent.h:
+        (WebCore::InspectorRuntimeAgent::InspectedStateProvider::~InspectedStateProvider):
+
 2011-04-04  Yong Li  <yoli@rim.com>
 
         Reviewed by Antonio Gomes.
index beac507..8a9d1d5 100644 (file)
@@ -89,6 +89,22 @@ static const char scriptsPanelName[] = "scripts";
 static const char consolePanelName[] = "console";
 static const char profilesPanelName[] = "profiles";
 
+namespace {
+
+class PageRuntimeAgent : public InspectorRuntimeAgent {
+public:
+    PageRuntimeAgent(InjectedScriptManager* injectedScriptManager, Page* page)
+        : InspectorRuntimeAgent(injectedScriptManager)
+        , m_inspectedPage(page) { }
+    virtual ~PageRuntimeAgent() { }
+
+private:
+    virtual ScriptState* getDefaultInspectedState() { return mainWorldScriptState(m_inspectedPage->mainFrame()); }
+    Page* m_inspectedPage;
+};
+
+}
+
 InspectorAgent::InspectorAgent(Page* page, InspectorClient* client, InjectedScriptManager* injectedScriptManager)
     : m_inspectedPage(page)
     , m_client(client)
@@ -110,6 +126,7 @@ InspectorAgent::InspectorAgent(Page* page, InspectorClient* client, InjectedScri
     , m_applicationCacheAgent(new InspectorApplicationCacheAgent(m_instrumentingAgents.get(), page))
 #endif
     , m_resourceAgent(InspectorResourceAgent::create(m_instrumentingAgents.get(), page, m_state.get()))
+    , m_runtimeAgent(adoptPtr(new PageRuntimeAgent(m_injectedScriptManager, page)))
     , m_consoleAgent(new InspectorConsoleAgent(m_instrumentingAgents.get(), this, m_state.get(), injectedScriptManager, m_domAgent.get()))
 #if ENABLE(JAVASCRIPT_DEBUGGER)
     , m_debuggerAgent(PageDebuggerAgent::create(m_instrumentingAgents.get(), m_state.get(), page, injectedScriptManager))
@@ -162,7 +179,6 @@ void InspectorAgent::inspectedPageDestroyed()
     InspectorInstrumentation::unbindInspectorAgent(m_inspectedPage);
     m_inspectedPage = 0;
 
-    releaseFrontendLifetimeAgents();
     m_injectedScriptManager->disconnect();
 
     m_client->inspectorDestroyed();
@@ -201,7 +217,6 @@ void InspectorAgent::setFrontend(InspectorFrontend* inspectorFrontend)
     m_state->unmute();
 
     m_frontend = inspectorFrontend;
-    createFrontendLifetimeAgents();
 
 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
     m_applicationCacheAgent->setFrontend(m_frontend);
@@ -272,18 +287,6 @@ void InspectorAgent::disconnectFrontend()
     m_domStorageAgent->clearFrontend();
 #endif
     m_pageAgent->clearFrontend();
-
-    releaseFrontendLifetimeAgents();
-}
-
-void InspectorAgent::createFrontendLifetimeAgents()
-{
-    m_runtimeAgent = InspectorRuntimeAgent::create(m_injectedScriptManager, m_inspectedPage);
-}
-
-void InspectorAgent::releaseFrontendLifetimeAgents()
-{
-    m_runtimeAgent.clear();
 }
 
 void InspectorAgent::didCommitLoad()
index cda9137..85cedb6 100644 (file)
@@ -177,9 +177,6 @@ private:
     void showPanel(const String& panel);
     void unbindAllResources();
 
-    void releaseFrontendLifetimeAgents();
-    void createFrontendLifetimeAgents();
-
 #if ENABLE(JAVASCRIPT_DEBUGGER)
     void toggleRecordButton(bool);
 #endif
index 1dd2c21..850bf70 100644 (file)
 #include "InjectedScript.h"
 #include "InjectedScriptManager.h"
 #include "InspectorValues.h"
-#include "Page.h"
-#include <wtf/PassOwnPtr.h>
 #include <wtf/PassRefPtr.h>
 
 namespace WebCore {
 
-PassOwnPtr<InspectorRuntimeAgent> InspectorRuntimeAgent::create(InjectedScriptManager* injectedScriptManager, Page* inspectedPage)
-{
-    return adoptPtr(new InspectorRuntimeAgent(injectedScriptManager, inspectedPage));
-}
-
-InspectorRuntimeAgent::InspectorRuntimeAgent(InjectedScriptManager* injectedScriptManager, Page* inspectedPage)
+InspectorRuntimeAgent::InspectorRuntimeAgent(InjectedScriptManager* injectedScriptManager)
     : m_injectedScriptManager(injectedScriptManager)
-    , m_inspectedPage(inspectedPage)
 {
 }
 
@@ -59,8 +51,7 @@ InspectorRuntimeAgent::~InspectorRuntimeAgent()
 
 void InspectorRuntimeAgent::evaluate(ErrorString* errorString, const String& expression, const String& objectGroup, const bool* const optionalIncludeCommandLineAPI, RefPtr<InspectorObject>* result)
 {
-    ScriptState* scriptState = mainWorldScriptState(m_inspectedPage->mainFrame());
-    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(scriptState);
+    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(getDefaultInspectedState());
     if (!injectedScript.hasNoValue())
         injectedScript.evaluate(errorString, expression, objectGroup, optionalIncludeCommandLineAPI ? *optionalIncludeCommandLineAPI : false, result);
 }
index 9fef02f..a5c9880 100644 (file)
@@ -33,6 +33,7 @@
 
 #if ENABLE(INSPECTOR)
 
+#include "ScriptState.h"
 #include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
 
@@ -42,15 +43,13 @@ class InjectedScriptManager;
 class InspectorArray;
 class InspectorObject;
 class InspectorValue;
-class Page;
 
 typedef String ErrorString;
 
 class InspectorRuntimeAgent {
     WTF_MAKE_NONCOPYABLE(InspectorRuntimeAgent);
 public:
-    static PassOwnPtr<InspectorRuntimeAgent> create(InjectedScriptManager*, Page*);
-    ~InspectorRuntimeAgent();
+    virtual ~InspectorRuntimeAgent();
 
     // Part of the protocol.
     void evaluate(ErrorString*, const String& expression, const String& objectGroup, const bool* const optionalIncludeCommandLineAPI, RefPtr<InspectorObject>* result);
@@ -60,11 +59,12 @@ public:
     void setPropertyValue(ErrorString*, const String& objectId, const String& propertyName, const String& expression);
     void releaseObjectGroup(ErrorString*, const String& objectGroup);
 
-private:
-    InspectorRuntimeAgent(InjectedScriptManager*, Page*);
+protected:
+    explicit InspectorRuntimeAgent(InjectedScriptManager*);
+    virtual ScriptState* getDefaultInspectedState() = 0;
 
+private:
     InjectedScriptManager* m_injectedScriptManager;
-    Page* m_inspectedPage;
 };
 
 } // namespace WebCore