2011-02-10 Pavel Feldman <pfeldman@chromium.org>
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Feb 2011 15:23:26 +0000 (15:23 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Feb 2011 15:23:26 +0000 (15:23 +0000)
        Reviewed by Yury Semikhatsky.

        Web Inspector: make InspectorAgent own sub-agents, align agent creation/deletion routines.
        https://bugs.webkit.org/show_bug.cgi?id=54227

        * dom/Document.cpp:
        (WebCore::Document::finishedParsing):
        * inspector/InspectorAgent.cpp:
        (WebCore::InspectorAgent::restoreInspectorStateFromCookie):
        (WebCore::InspectorAgent::setFrontend):
        (WebCore::InspectorAgent::disconnectFrontend):
        (WebCore::InspectorAgent::releaseFrontendLifetimeAgents):
        (WebCore::InspectorAgent::didCommitLoad):
        (WebCore::InspectorAgent::domContentLoadedEventFired):
        (WebCore::InspectorAgent::loadEventFired):
        (WebCore::InspectorAgent::startTimelineProfiler):
        (WebCore::InspectorAgent::stopTimelineProfiler):
        * inspector/InspectorAgent.h:
        * inspector/InspectorCSSAgent.cpp:
        * inspector/InspectorDOMAgent.cpp:
        (WebCore::InspectorDOMAgent::InspectorDOMAgent):
        (WebCore::InspectorDOMAgent::startListening):
        (WebCore::InspectorDOMAgent::stopListening):
        (WebCore::InspectorDOMAgent::mainDOMContentLoaded):
        (WebCore::InspectorDOMAgent::loadEventFired):
        * inspector/InspectorDOMAgent.h:
        (WebCore::InspectorDOMAgent::create):
        * inspector/InspectorDOMStorageAgent.cpp:
        (WebCore::InspectorDOMStorageAgent::~InspectorDOMStorageAgent):
        * inspector/InspectorDOMStorageAgent.h:
        (WebCore::InspectorDOMStorageAgent::create):
        * inspector/InspectorDOMStorageResource.h:
        * inspector/InspectorDatabaseAgent.cpp:
        (WebCore::InspectorDatabaseAgent::~InspectorDatabaseAgent):
        (WebCore::InspectorDatabaseAgent::executeSQL):
        (WebCore::InspectorDatabaseAgent::selectDatabase):
        (WebCore::InspectorDatabaseAgent::InspectorDatabaseAgent):
        * inspector/InspectorDatabaseAgent.h:
        (WebCore::InspectorDatabaseAgent::FrontendProvider::create):
        (WebCore::InspectorDatabaseAgent::FrontendProvider::~FrontendProvider):
        (WebCore::InspectorDatabaseAgent::FrontendProvider::frontend):
        (WebCore::InspectorDatabaseAgent::FrontendProvider::clearFrontend):
        (WebCore::InspectorDatabaseAgent::FrontendProvider::FrontendProvider):
        (WebCore::InspectorDatabaseAgent::create):
        * inspector/InspectorDatabaseResource.cpp:
        (WebCore::InspectorDatabaseResource::InspectorDatabaseResource):
        (WebCore::InspectorDatabaseResource::bind):
        * inspector/InspectorDatabaseResource.h:
        * inspector/InspectorInstrumentation.cpp:
        (WebCore::InspectorInstrumentation::domContentLoadedEventFiredImpl):
        (WebCore::InspectorInstrumentation::loadEventFiredImpl):
        * inspector/InspectorInstrumentation.h:
        (WebCore::InspectorInstrumentation::domContentLoadedEventFired):
        (WebCore::InspectorInstrumentation::loadEventFired):
        * inspector/InspectorState.cpp:
        (WebCore::InspectorState::InspectorState):
        (WebCore::InspectorState::mute):
        (WebCore::InspectorState::updateCookie):
        * inspector/InspectorState.h:
        (WebCore::InspectorState::~InspectorState):
        * inspector/InspectorTimelineAgent.cpp:
        (WebCore::InspectorTimelineAgent::restore):
        (WebCore::InspectorTimelineAgent::~InspectorTimelineAgent):
        (WebCore::InspectorTimelineAgent::didCommitLoad):
        (WebCore::InspectorTimelineAgent::setFrontend):
        (WebCore::InspectorTimelineAgent::InspectorTimelineAgent):
        * inspector/InspectorTimelineAgent.h:
        (WebCore::InspectorTimelineAgent::create):
        * page/DOMWindow.cpp:
        (WebCore::DOMWindow::dispatchLoadEvent):

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

21 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/inspector/InspectorAgent.cpp
Source/WebCore/inspector/InspectorAgent.h
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorDOMAgent.h
Source/WebCore/inspector/InspectorDOMStorageAgent.cpp
Source/WebCore/inspector/InspectorDOMStorageAgent.h
Source/WebCore/inspector/InspectorDOMStorageResource.h
Source/WebCore/inspector/InspectorDatabaseAgent.cpp
Source/WebCore/inspector/InspectorDatabaseAgent.h
Source/WebCore/inspector/InspectorDatabaseResource.cpp
Source/WebCore/inspector/InspectorDatabaseResource.h
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/InspectorState.cpp
Source/WebCore/inspector/InspectorState.h
Source/WebCore/inspector/InspectorTimelineAgent.cpp
Source/WebCore/inspector/InspectorTimelineAgent.h
Source/WebCore/page/DOMWindow.cpp

index 01c7451..8993dcb 100644 (file)
@@ -1,3 +1,76 @@
+2011-02-10  Pavel Feldman  <pfeldman@chromium.org>
+
+        Reviewed by Yury Semikhatsky.
+
+        Web Inspector: make InspectorAgent own sub-agents, align agent creation/deletion routines.
+        https://bugs.webkit.org/show_bug.cgi?id=54227
+
+        * dom/Document.cpp:
+        (WebCore::Document::finishedParsing):
+        * inspector/InspectorAgent.cpp:
+        (WebCore::InspectorAgent::restoreInspectorStateFromCookie):
+        (WebCore::InspectorAgent::setFrontend):
+        (WebCore::InspectorAgent::disconnectFrontend):
+        (WebCore::InspectorAgent::releaseFrontendLifetimeAgents):
+        (WebCore::InspectorAgent::didCommitLoad):
+        (WebCore::InspectorAgent::domContentLoadedEventFired):
+        (WebCore::InspectorAgent::loadEventFired):
+        (WebCore::InspectorAgent::startTimelineProfiler):
+        (WebCore::InspectorAgent::stopTimelineProfiler):
+        * inspector/InspectorAgent.h:
+        * inspector/InspectorCSSAgent.cpp:
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::InspectorDOMAgent):
+        (WebCore::InspectorDOMAgent::startListening):
+        (WebCore::InspectorDOMAgent::stopListening):
+        (WebCore::InspectorDOMAgent::mainDOMContentLoaded):
+        (WebCore::InspectorDOMAgent::loadEventFired):
+        * inspector/InspectorDOMAgent.h:
+        (WebCore::InspectorDOMAgent::create):
+        * inspector/InspectorDOMStorageAgent.cpp:
+        (WebCore::InspectorDOMStorageAgent::~InspectorDOMStorageAgent):
+        * inspector/InspectorDOMStorageAgent.h:
+        (WebCore::InspectorDOMStorageAgent::create):
+        * inspector/InspectorDOMStorageResource.h:
+        * inspector/InspectorDatabaseAgent.cpp:
+        (WebCore::InspectorDatabaseAgent::~InspectorDatabaseAgent):
+        (WebCore::InspectorDatabaseAgent::executeSQL):
+        (WebCore::InspectorDatabaseAgent::selectDatabase):
+        (WebCore::InspectorDatabaseAgent::InspectorDatabaseAgent):
+        * inspector/InspectorDatabaseAgent.h:
+        (WebCore::InspectorDatabaseAgent::FrontendProvider::create):
+        (WebCore::InspectorDatabaseAgent::FrontendProvider::~FrontendProvider):
+        (WebCore::InspectorDatabaseAgent::FrontendProvider::frontend):
+        (WebCore::InspectorDatabaseAgent::FrontendProvider::clearFrontend):
+        (WebCore::InspectorDatabaseAgent::FrontendProvider::FrontendProvider):
+        (WebCore::InspectorDatabaseAgent::create):
+        * inspector/InspectorDatabaseResource.cpp:
+        (WebCore::InspectorDatabaseResource::InspectorDatabaseResource):
+        (WebCore::InspectorDatabaseResource::bind):
+        * inspector/InspectorDatabaseResource.h:
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::domContentLoadedEventFiredImpl):
+        (WebCore::InspectorInstrumentation::loadEventFiredImpl):
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::domContentLoadedEventFired):
+        (WebCore::InspectorInstrumentation::loadEventFired):
+        * inspector/InspectorState.cpp:
+        (WebCore::InspectorState::InspectorState):
+        (WebCore::InspectorState::mute):
+        (WebCore::InspectorState::updateCookie):
+        * inspector/InspectorState.h:
+        (WebCore::InspectorState::~InspectorState):
+        * inspector/InspectorTimelineAgent.cpp:
+        (WebCore::InspectorTimelineAgent::restore):
+        (WebCore::InspectorTimelineAgent::~InspectorTimelineAgent):
+        (WebCore::InspectorTimelineAgent::didCommitLoad):
+        (WebCore::InspectorTimelineAgent::setFrontend):
+        (WebCore::InspectorTimelineAgent::InspectorTimelineAgent):
+        * inspector/InspectorTimelineAgent.h:
+        (WebCore::InspectorTimelineAgent::create):
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::dispatchLoadEvent):
+
 2011-02-11  Pavel Feldman  <pfeldman@chromium.org>
 
         Reviewed by Yury Semikhatsky.
index 64b8043..a3dcb64 100644 (file)
@@ -4200,7 +4200,7 @@ void Document::finishedParsing()
 
         f->loader()->finishedParsing();
 
-        InspectorInstrumentation::mainResourceFiredDOMContentEvent(f, url());
+        InspectorInstrumentation::domContentLoadedEventFired(f, url());
     }
 }
 
index e4bdf10..9559099 100644 (file)
@@ -191,16 +191,14 @@ bool InspectorAgent::searchingForNodeInPage() const
 
 void InspectorAgent::restoreInspectorStateFromCookie(const String& inspectorStateCookie)
 {
-    m_state->restoreFromInspectorCookie(inspectorStateCookie);
+    m_state = new InspectorState(m_client, inspectorStateCookie);
 
     m_frontend->frontendReused();
     m_frontend->inspectedURLChanged(inspectedURL().string());
     pushDataCollectedOffline();
 
     m_resourceAgent = InspectorResourceAgent::restore(m_inspectedPage, m_state.get(), m_frontend);
-
-    if (m_state->getBoolean(InspectorAgentState::timelineProfilerEnabled))
-        startTimelineProfiler();
+    m_timelineAgent = InspectorTimelineAgent::restore(m_state.get(), m_frontend);
 
 #if ENABLE(JAVASCRIPT_DEBUGGER)
     restoreDebugger(false);
@@ -334,15 +332,10 @@ void InspectorAgent::setSearchingForNode(bool enabled, bool* newState)
 
 void InspectorAgent::setFrontend(InspectorFrontend* inspectorFrontend)
 {
-    releaseFrontendLifetimeAgents();
     m_frontend = inspectorFrontend;
     createFrontendLifetimeAgents();
 
     m_cssAgent->setDOMAgent(m_domAgent.get());
-
-    if (m_timelineAgent)
-        m_timelineAgent->resetFrontendProxyObject(m_frontend);
-
     m_consoleAgent->setFrontend(m_frontend);
 
     // Initialize Web Inspector title.
@@ -354,6 +347,10 @@ void InspectorAgent::disconnectFrontend()
     if (!m_frontend)
         return;
 
+    // Destroying agents would change the state, but we don't want that.
+    // Pre-disconnect state will be used to restore inspector agents.
+    m_state->mute();
+
     m_frontend = 0;
 
 #if ENABLE(JAVASCRIPT_DEBUGGER)
@@ -363,7 +360,6 @@ void InspectorAgent::disconnectFrontend()
     disableDebugger();
 #endif
     setSearchingForNode(false);
-    unbindAllResources();
 
     hideHighlight();
 
@@ -371,10 +367,10 @@ void InspectorAgent::disconnectFrontend()
     m_profilerAgent->setFrontend(0);
     m_profilerAgent->stopUserInitiatedProfiling(true);
 #endif
+
     m_consoleAgent->setFrontend(0);
 
     releaseFrontendLifetimeAgents();
-    m_timelineAgent.clear();
     m_userAgentOverride = "";
 }
 
@@ -407,19 +403,9 @@ void InspectorAgent::releaseFrontendLifetimeAgents()
 {
     m_resourceAgent.clear();
     m_runtimeAgent.clear();
-
-    // This should be invoked prior to m_domAgent destruction.
-    m_cssAgent->setDOMAgent(0);
-
-    // m_domAgent is RefPtr. Remove DOM listeners first to ensure that there are
-    // no references to the DOM agent from the DOM tree.
-    if (m_domAgent)
-        m_domAgent->reset();
-    m_domAgent.clear();
+    m_timelineAgent.clear();
 
 #if ENABLE(DATABASE)
-    if (m_databaseAgent)
-        m_databaseAgent->clearFrontend();
     m_databaseAgent.clear();
 #endif
 
@@ -431,7 +417,9 @@ void InspectorAgent::releaseFrontendLifetimeAgents()
     m_applicationCacheAgent.clear();
 #endif
 
-    stopTimelineProfiler();
+    // This should be invoked prior to m_domAgent destruction.
+    m_cssAgent->setDOMAgent(0);
+    m_domAgent.clear();
 }
 
 void InspectorAgent::populateScriptObjects()
@@ -508,22 +496,6 @@ void InspectorAgent::restoreProfiler(ProfilerRestoreAction action)
 #endif
 }
 
-void InspectorAgent::unbindAllResources()
-{
-#if ENABLE(DATABASE)
-    DatabaseResourcesMap::iterator databasesEnd = m_databaseResources.end();
-    for (DatabaseResourcesMap::iterator it = m_databaseResources.begin(); it != databasesEnd; ++it)
-        it->second->unbind();
-#endif
-#if ENABLE(DOM_STORAGE)
-    DOMStorageResourcesMap::iterator domStorageEnd = m_domStorageResources.end();
-    for (DOMStorageResourcesMap::iterator it = m_domStorageResources.begin(); it != domStorageEnd; ++it)
-        it->second->unbind();
-#endif
-    if (m_timelineAgent)
-        m_timelineAgent->reset();
-}
-
 void InspectorAgent::didCommitLoad(DocumentLoader* loader)
 {
     if (!enabled())
@@ -541,6 +513,9 @@ void InspectorAgent::didCommitLoad(DocumentLoader* loader)
         m_injectedScriptHost->discardInjectedScripts();
         m_consoleAgent->reset();
 
+        if (m_timelineAgent)
+            m_timelineAgent->didCommitLoad();
+
 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
         if (m_applicationCacheAgent)
             m_applicationCacheAgent->didCommitLoad(loader);
@@ -560,10 +535,6 @@ void InspectorAgent::didCommitLoad(DocumentLoader* loader)
         m_profilerAgent->resetState();
 #endif
 
-        // unbindAllResources should be called before database and DOM storage
-        // resources are cleared so that it has a chance to unbind them.
-        unbindAllResources();
-
         if (m_frontend) {
             m_frontend->reset();
             m_domAgent->reset();
@@ -584,20 +555,28 @@ void InspectorAgent::didCommitLoad(DocumentLoader* loader)
     }
 }
 
-void InspectorAgent::mainResourceFiredDOMContentEvent(DocumentLoader* loader, const KURL& url)
+void InspectorAgent::domContentLoadedEventFired(DocumentLoader* loader, const KURL& url)
 {
     if (!enabled() || !isMainResourceLoader(loader, url))
         return;
 
+    if (m_domAgent)
+        m_domAgent->mainFrameDOMContentLoaded();
     if (m_timelineAgent)
         m_timelineAgent->didMarkDOMContentEvent();
     if (m_frontend)
         m_frontend->domContentEventFired(currentTime());
 }
 
-void InspectorAgent::mainResourceFiredLoadEvent(DocumentLoader* loader, const KURL& url)
+void InspectorAgent::loadEventFired(DocumentLoader* loader, const KURL& url)
 {
-    if (!enabled() || !isMainResourceLoader(loader, url))
+    if (!enabled())
+        return;
+
+    if (m_domAgent)
+        m_domAgent->loadEventFired(loader->frame()->document());
+
+    if (!isMainResourceLoader(loader, url))
         return;
 
     if (m_timelineAgent)
@@ -624,32 +603,15 @@ void InspectorAgent::applyUserAgentOverride(String* userAgent) const
 
 void InspectorAgent::startTimelineProfiler()
 {
-    if (!enabled())
+    if (m_timelineAgent || !enabled() || !m_frontend)
         return;
 
-    if (m_timelineAgent)
-        return;
-
-    m_timelineAgent = new InspectorTimelineAgent(m_frontend);
-    if (m_frontend)
-        m_frontend->timelineProfilerWasStarted();
-
-    m_state->setBoolean(InspectorAgentState::timelineProfilerEnabled, true);
+    m_timelineAgent = InspectorTimelineAgent::create(m_state.get(), m_frontend);
 }
 
 void InspectorAgent::stopTimelineProfiler()
 {
-    if (!enabled())
-        return;
-
-    if (!m_timelineAgent)
-        return;
-
-    m_timelineAgent = 0;
-    if (m_frontend)
-        m_frontend->timelineProfilerWasStopped();
-
-    m_state->setBoolean(InspectorAgentState::timelineProfilerEnabled, false);
+    m_timelineAgent.clear();
 }
 
 #if ENABLE(WORKERS)
index 26f7c14..1f14dd9 100644 (file)
@@ -172,8 +172,8 @@ public:
     void getCookies(RefPtr<InspectorArray>* cookies, WTF::String* cookiesString);
     void deleteCookie(const String& cookieName, const String& domain);
 
-    void mainResourceFiredLoadEvent(DocumentLoader*, const KURL&);
-    void mainResourceFiredDOMContentEvent(DocumentLoader*, const KURL&);
+    void domContentLoadedEventFired(DocumentLoader*, const KURL&);
+    void loadEventFired(DocumentLoader*, const KURL&);
 
 #if ENABLE(WORKERS)
     enum WorkerAction { WorkerCreated, WorkerDestroyed };
@@ -271,14 +271,14 @@ private:
     InspectorClient* m_client;
     InspectorFrontend* m_frontend;
     OwnPtr<InspectorCSSAgent> m_cssAgent;
-    RefPtr<InspectorDOMAgent> m_domAgent;
+    OwnPtr<InspectorDOMAgent> m_domAgent;
 
 #if ENABLE(DATABASE)
-    RefPtr<InspectorDatabaseAgent> m_databaseAgent;
+    OwnPtr<InspectorDatabaseAgent> m_databaseAgent;
 #endif
 
 #if ENABLE(DOM_STORAGE)
-    RefPtr<InspectorDOMStorageAgent> m_domStorageAgent;
+    OwnPtr<InspectorDOMStorageAgent> m_domStorageAgent;
 #endif
 
     OwnPtr<InspectorTimelineAgent> m_timelineAgent;
index 9184b24..f49f89c 100644 (file)
 #include "InspectorFrontend.h"
 #include "InspectorValues.h"
 #include "Node.h"
+#include "NodeList.h"
 #include "StyleSheetList.h"
 
 #include <wtf/HashSet.h>
-#include <wtf/ListHashSet.h>
 #include <wtf/Vector.h>
 #include <wtf/text/CString.h>
 
@@ -254,8 +254,8 @@ void InspectorCSSAgent::getComputedStyleForNode(long nodeId, RefPtr<InspectorVal
 
 void InspectorCSSAgent::getAllStyles(RefPtr<InspectorArray>* styles)
 {
-    const ListHashSet<RefPtr<Document> >& documents = m_domAgent->documents();
-    for (ListHashSet<RefPtr<Document> >::const_iterator it = documents.begin(); it != documents.end(); ++it) {
+    Vector<Document*> documents = m_domAgent->documents();
+    for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it) {
         StyleSheetList* list = (*it)->styleSheets();
         for (unsigned i = 0; i < list->length(); ++i) {
             StyleSheet* styleSheet = list->item(i);
index c00884c..e222edb 100644 (file)
@@ -208,8 +208,7 @@ public:
 }
 
 InspectorDOMAgent::InspectorDOMAgent(InjectedScriptHost* injectedScriptHost, InspectorFrontend* frontend)
-    : EventListener(InspectorDOMAgentType)
-    , m_injectedScriptHost(injectedScriptHost)
+    : m_injectedScriptHost(injectedScriptHost)
     , m_frontend(frontend)
     , m_domListener(0)
     , m_lastNodeId(1)
@@ -222,16 +221,22 @@ InspectorDOMAgent::~InspectorDOMAgent()
     reset();
 }
 
+Vector<Document*> InspectorDOMAgent::documents()
+{
+    Vector<Document*> result;
+    for (Frame* frame = m_document->frame(); frame; frame = frame->tree()->traverseNext()) {
+        Document* document = frame->document();
+        if (!document)
+            continue;
+        result.append(document);
+    }
+    return result;
+}
+
 void InspectorDOMAgent::reset()
 {
     searchCanceled();
     discardBindings();
-
-    ListHashSet<RefPtr<Document> > copy = m_documents;
-    for (ListHashSet<RefPtr<Document> >::iterator it = copy.begin(); it != copy.end(); ++it)
-        stopListening((*it).get());
-
-    ASSERT(!m_documents.size());
 }
 
 void InspectorDOMAgent::setDOMListener(DOMListener* listener)
@@ -241,13 +246,14 @@ void InspectorDOMAgent::setDOMListener(DOMListener* listener)
 
 void InspectorDOMAgent::setDocument(Document* doc)
 {
-    if (doc == mainFrameDocument())
+    if (doc == m_document.get())
         return;
 
     reset();
 
+    m_document = doc;
+
     if (doc) {
-        startListening(doc);
         if (doc->documentElement())
             pushDocumentToFrontend();
     } else
@@ -260,66 +266,6 @@ void InspectorDOMAgent::releaseDanglingNodes()
     m_danglingNodeToIdMaps.clear();
 }
 
-void InspectorDOMAgent::startListeningFrameDocument(Node* frameOwnerNode)
-{
-    ASSERT(frameOwnerNode->isFrameOwnerElement());
-    HTMLFrameOwnerElement* frameOwner = static_cast<HTMLFrameOwnerElement*>(frameOwnerNode);
-    Document* doc = frameOwner->contentDocument();
-    if (doc)
-        startListening(doc);
-}
-
-void InspectorDOMAgent::startListening(Document* doc)
-{
-    if (m_documents.contains(doc))
-        return;
-
-    doc->addEventListener(eventNames().DOMContentLoadedEvent, this, false);
-    doc->addEventListener(eventNames().loadEvent, this, true);
-    m_documents.add(doc);
-}
-
-void InspectorDOMAgent::stopListening(Document* doc)
-{
-    if (!m_documents.contains(doc))
-        return;
-
-    doc->removeEventListener(eventNames().DOMContentLoadedEvent, this, false);
-    doc->removeEventListener(eventNames().loadEvent, this, true);
-    m_documents.remove(doc);
-}
-
-void InspectorDOMAgent::handleEvent(ScriptExecutionContext*, Event* event)
-{
-    AtomicString type = event->type();
-    Node* node = event->target()->toNode();
-
-    if (type == eventNames().DOMContentLoadedEvent) {
-        // Re-push document once it is loaded.
-        discardBindings();
-        pushDocumentToFrontend();
-    } else if (type == eventNames().loadEvent) {
-        long frameOwnerId = m_documentNodeToIdMap.get(node);
-        if (!frameOwnerId)
-            return;
-
-        if (!m_childrenRequested.contains(frameOwnerId)) {
-            // No children are mapped yet -> only notify on changes of hasChildren.
-            m_frontend->childNodeCountUpdated(frameOwnerId, innerChildNodeCount(node));
-        } else {
-            // Re-add frame owner element together with its new children.
-            long parentId = m_documentNodeToIdMap.get(innerParentNode(node));
-            m_frontend->childNodeRemoved(parentId, frameOwnerId);
-            RefPtr<InspectorObject> value = buildObjectForNode(node, 0, &m_documentNodeToIdMap);
-            Node* previousSibling = innerPreviousSibling(node);
-            long prevId = previousSibling ? m_documentNodeToIdMap.get(previousSibling) : 0;
-            m_frontend->childNodeInserted(parentId, prevId, value.release());
-            // Invalidate children requested flag for the element.
-            m_childrenRequested.remove(m_childrenRequested.find(frameOwnerId));
-        }
-    }
-}
-
 long InspectorDOMAgent::bind(Node* node, NodeToIdMap* nodesMap)
 {
     long id = nodesMap->get(node);
@@ -336,7 +282,6 @@ void InspectorDOMAgent::unbind(Node* node, NodeToIdMap* nodesMap)
 {
     if (node->isFrameOwnerElement()) {
         const HTMLFrameOwnerElement* frameOwner = static_cast<const HTMLFrameOwnerElement*>(node);
-        stopListening(frameOwner->contentDocument());
         if (m_domListener)
             m_domListener->didRemoveDocument(frameOwner->contentDocument());
     }
@@ -360,11 +305,10 @@ void InspectorDOMAgent::unbind(Node* node, NodeToIdMap* nodesMap)
 
 bool InspectorDOMAgent::pushDocumentToFrontend()
 {
-    Document* document = mainFrameDocument();
-    if (!document)
+    if (!m_document)
         return false;
-    if (!m_documentNodeToIdMap.contains(document))
-        m_frontend->setDocument(buildObjectForNode(document, 2, &m_documentNodeToIdMap));
+    if (!m_documentNodeToIdMap.contains(m_document))
+        m_frontend->setDocument(buildObjectForNode(m_document.get(), 2, &m_documentNodeToIdMap));
     return true;
 }
 
@@ -559,9 +503,9 @@ void InspectorDOMAgent::setOuterHTML(long nodeId, const String& outerHTML, long*
         return;
 
     if (requiresTotalUpdate) {
-        Document* document = mainFrameDocument();
+        RefPtr<Document> document = m_document;
         reset();
-        setDocument(document);
+        setDocument(document.get());
         *newId = 0;
         return;
     }
@@ -693,10 +637,9 @@ void InspectorDOMAgent::performSearch(const String& whitespaceTrimmedQuery, bool
     searchCanceled();
 
     // Find all frames, iframes and object elements to search their documents.
-    for (Frame* frame = mainFrameDocument()->frame(); frame; frame = frame->tree()->traverseNext()) {
-        Document* document = frame->document();
-        if (!document)
-            continue;
+    Vector<Document*> docs = documents();
+    for (Vector<Document*>::iterator it = docs.begin(); it != docs.end(); ++it) {
+        Document* document = *it;
 
         if (!tagNameQuery.isEmpty() && startTagFound && endTagFound) {
             m_pendingMatchJobs.append(new MatchExactTagNamesJob(document, tagNameQuery));
@@ -891,9 +834,6 @@ PassRefPtr<InspectorArray> InspectorDOMAgent::buildArrayForContainerChildren(Nod
         depth--;
     }
 
-    if (container->isFrameOwnerElement())
-        startListeningFrameDocument(container);
-
     while (child) {
         children->pushObject(buildObjectForNode(child, depth, nodesMap));
         child = innerNextSibling(child);
@@ -974,19 +914,37 @@ bool InspectorDOMAgent::isWhitespace(Node* node)
     return node && node->nodeType() == Node::TEXT_NODE && node->nodeValue().stripWhiteSpace().length() == 0;
 }
 
-Document* InspectorDOMAgent::mainFrameDocument() const
+void InspectorDOMAgent::mainFrameDOMContentLoaded()
 {
-    ListHashSet<RefPtr<Document> >::const_iterator it = m_documents.begin();
-    if (it != m_documents.end())
-        return it->get();
-    return 0;
+    // Re-push document once it is loaded.
+    discardBindings();
+    pushDocumentToFrontend();
 }
 
-bool InspectorDOMAgent::operator==(const EventListener& listener)
+void InspectorDOMAgent::loadEventFired(Document* document)
 {
-    if (const InspectorDOMAgent* inspectorDOMAgentListener = InspectorDOMAgent::cast(&listener))
-        return mainFrameDocument() == inspectorDOMAgentListener->mainFrameDocument();
-    return false;
+    Element* frameOwner = document->ownerElement();
+    if (!frameOwner)
+        return;
+
+    long frameOwnerId = m_documentNodeToIdMap.get(frameOwner);
+    if (!frameOwnerId)
+        return;
+
+    if (!m_childrenRequested.contains(frameOwnerId)) {
+        // No children are mapped yet -> only notify on changes of hasChildren.
+        m_frontend->childNodeCountUpdated(frameOwnerId, innerChildNodeCount(frameOwner));
+    } else {
+        // Re-add frame owner element together with its new children.
+        long parentId = m_documentNodeToIdMap.get(innerParentNode(frameOwner));
+        m_frontend->childNodeRemoved(parentId, frameOwnerId);
+        RefPtr<InspectorObject> value = buildObjectForNode(frameOwner, 0, &m_documentNodeToIdMap);
+        Node* previousSibling = innerPreviousSibling(frameOwner);
+        long prevId = previousSibling ? m_documentNodeToIdMap.get(previousSibling) : 0;
+        m_frontend->childNodeInserted(parentId, prevId, value.release());
+        // Invalidate children requested flag for the element.
+        m_childrenRequested.remove(m_childrenRequested.find(frameOwnerId));
+    }
 }
 
 void InspectorDOMAgent::didInsertDOMNode(Node* node)
@@ -1062,10 +1020,10 @@ void InspectorDOMAgent::characterDataModified(CharacterData* characterData)
 Node* InspectorDOMAgent::nodeForPath(const String& path)
 {
     // The path is of form "1,HTML,2,BODY,1,DIV"
-    Node* node = mainFrameDocument();
-    if (!node)
+    if (!m_document)
         return 0;
 
+    Node* node = m_document.get();
     Vector<String> pathTokens;
     path.split(",", false, pathTokens);
     if (!pathTokens.size())
@@ -1153,7 +1111,7 @@ InjectedScript InspectorDOMAgent::injectedScriptForNodeId(long nodeId)
                 frame = document->frame();
         }
     } else
-        frame = mainFrameDocument()->frame();
+        frame = m_document->frame();
 
     if (frame)
         return m_injectedScriptHost->injectedScriptFor(mainWorldScriptState(frame));
index e4edf5d..4e603da 100644 (file)
 #ifndef InspectorDOMAgent_h
 #define InspectorDOMAgent_h
 
-#include "EventListener.h"
-#include "EventTarget.h"
 #include "InjectedScript.h"
 #include "InjectedScriptHost.h"
 #include "InspectorValues.h"
-#include "NodeList.h"
 #include "Timer.h"
 
 #include <wtf/Deque.h>
 #include <wtf/ListHashSet.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
-#include <wtf/PassRefPtr.h>
+#include <wtf/PassOwnPtr.h>
 #include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
 #include <wtf/text/AtomicString.h>
 
 namespace WebCore {
 class ContainerNode;
-class CSSRule;
-class CSSRuleList;
-class CSSStyleDeclaration;
-class CSSStyleRule;
-class CSSStyleSheet;
 class CharacterData;
 class Document;
 class Element;
@@ -79,7 +72,7 @@ struct EventListenerInfo {
     const EventListenerVector eventListenerVector;
 };
 
-class InspectorDOMAgent : public EventListener {
+class InspectorDOMAgent {
 public:
     struct DOMListener {
         virtual ~DOMListener()
@@ -90,25 +83,17 @@ public:
         virtual void didModifyDOMAttr(Element*) = 0;
     };
 
-    static PassRefPtr<InspectorDOMAgent> create(InjectedScriptHost* injectedScriptHost, InspectorFrontend* frontend)
+    static PassOwnPtr<InspectorDOMAgent> create(InjectedScriptHost* injectedScriptHost, InspectorFrontend* frontend)
     {
-        return adoptRef(new InspectorDOMAgent(injectedScriptHost, frontend));
-    }
-
-    static const InspectorDOMAgent* cast(const EventListener* listener)
-    {
-        return listener->type() == InspectorDOMAgentType
-            ? static_cast<const InspectorDOMAgent*>(listener)
-            : 0;
+        return adoptPtr(new InspectorDOMAgent(injectedScriptHost, frontend));
     }
 
     InspectorDOMAgent(InjectedScriptHost*, InspectorFrontend*);
     ~InspectorDOMAgent();
 
+    Vector<Document*> documents();
     void reset();
 
-    virtual bool operator==(const EventListener& other);
-
     // Methods called from the frontend for DOM nodes inspection.
     void getChildNodes(long nodeId);
     void setAttribute(long elementId, const String& name, const String& value, bool* success);
@@ -131,6 +116,9 @@ public:
     void setDocument(Document*);
     void releaseDanglingNodes();
 
+    void mainFrameDOMContentLoaded();
+    void loadEventFired(Document*);
+
     void didInsertDOMNode(Node*);
     void didRemoveDOMNode(Node*);
     void didModifyDOMAttr(Element*);
@@ -142,7 +130,6 @@ public:
     void pushNodeByPathToFrontend(const String& path, long* nodeId);
     long inspectedNode(unsigned long num);
     void copyNode(long nodeId);
-    const ListHashSet<RefPtr<Document> >& documents() { return m_documents; }
     void setDOMListener(DOMListener*);
 
     String documentURLString(Document*) const;
@@ -157,12 +144,6 @@ public:
     static bool isWhitespace(Node*);
 
 private:
-    void startListeningFrameDocument(Node* frameOwnerNode);
-    void startListening(Document*);
-    void stopListening(Document*);
-
-    virtual void handleEvent(ScriptExecutionContext*, Event*);
-
     // Node-related methods.
     typedef HashMap<RefPtr<Node>, long> NodeToIdMap;
     long bind(Node*, NodeToIdMap*);
@@ -179,8 +160,6 @@ private:
     PassRefPtr<InspectorArray> buildArrayForContainerChildren(Node* container, int depth, NodeToIdMap* nodesMap);
     PassRefPtr<InspectorObject> buildObjectForEventListener(const RegisteredEventListener&, const AtomicString& eventType, Node*);
 
-    Document* mainFrameDocument() const;
-
     void onMatchJobsTimer(Timer<InspectorDOMAgent>*);
     void reportNodesAsSearchResults(ListHashSet<Node*>& resultCollector);
 
@@ -201,7 +180,7 @@ private:
     HashMap<long, NodeToIdMap*> m_idToNodesMap;
     HashSet<long> m_childrenRequested;
     long m_lastNodeId;
-    ListHashSet<RefPtr<Document> > m_documents;
+    RefPtr<Document> m_document;
     Deque<MatchJob*> m_pendingMatchJobs;
     Timer<InspectorDOMAgent> m_matchJobsTimer;
     HashSet<RefPtr<Node> > m_searchResults;
index 2241a16..0919b64 100644 (file)
@@ -48,6 +48,9 @@ namespace WebCore {
 
 InspectorDOMStorageAgent::~InspectorDOMStorageAgent()
 {
+    DOMStorageResourcesMap::iterator domStorageEnd = m_domStorageResources->end();
+    for (DOMStorageResourcesMap::iterator it = m_domStorageResources->begin(); it != domStorageEnd; ++it)
+        it->second->unbind();
 }
 
 void InspectorDOMStorageAgent::getDOMStorageEntries(long storageId, RefPtr<InspectorArray>* entries)
index f1d4d5c..987c530 100644 (file)
@@ -30,8 +30,8 @@
 #define InspectorDOMStorageAgent_h
 
 #include "PlatformString.h"
-#include "wtf/HashMap.h"
-#include "wtf/PassRefPtr.h"
+#include <wtf/HashMap.h>
+#include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
 
@@ -40,13 +40,13 @@ class InspectorDOMStorageResource;
 class InspectorFrontend;
 class Storage;
 
-class InspectorDOMStorageAgent : public RefCounted<InspectorDOMStorageAgent> {
+class InspectorDOMStorageAgent {
 public:
     typedef HashMap<int, RefPtr<InspectorDOMStorageResource> > DOMStorageResourcesMap;
 
-    static PassRefPtr<InspectorDOMStorageAgent> create(DOMStorageResourcesMap* domStorageResources, InspectorFrontend* frontend)
+    static PassOwnPtr<InspectorDOMStorageAgent> create(DOMStorageResourcesMap* domStorageResources, InspectorFrontend* frontend)
     {
-        return adoptRef(new InspectorDOMStorageAgent(domStorageResources, frontend));
+        return adoptPtr(new InspectorDOMStorageAgent(domStorageResources, frontend));
     }
 
     virtual ~InspectorDOMStorageAgent();
@@ -59,8 +59,6 @@ public:
     // Called from the injected script.
     void selectDOMStorage(Storage* storage);
 
-    InspectorFrontend* frontend() { return m_frontend; }
-
 private:
     InspectorDOMStorageAgent(DOMStorageResourcesMap*, InspectorFrontend*);
 
index ee09974..f0975ba 100644 (file)
@@ -51,6 +51,7 @@ namespace WebCore {
         {
             return adoptRef(new InspectorDOMStorageResource(domStorage, isLocalStorage, frame));
         }
+
         static const InspectorDOMStorageResource* cast(const EventListener* listener)
         {
             return listener->type() == InspectorDOMStorageResourceType ? static_cast<const InspectorDOMStorageResource*>(listener) : 0;
index 385400f..221bdf2 100644 (file)
 
 namespace WebCore {
 
+class InspectorDatabaseAgent::FrontendProvider : public RefCounted<InspectorDatabaseAgent::FrontendProvider> {
+public:
+    static PassRefPtr<FrontendProvider> create(InspectorFrontend* inspectorFrontend)
+    {
+        return adoptRef(new FrontendProvider(inspectorFrontend));
+    }
+
+    virtual ~FrontendProvider() { }
+
+    InspectorFrontend* frontend() { return m_inspectorFrontend; }
+    void clearFrontend() { m_inspectorFrontend = 0; }
+private:
+    FrontendProvider(InspectorFrontend* inspectorFrontend) : m_inspectorFrontend(inspectorFrontend) { }
+    InspectorFrontend* m_inspectorFrontend;
+};
+
 namespace {
 
 long lastTransactionId = 0;
 
-void reportTransactionFailed(InspectorDatabaseAgent* agent, long transactionId, SQLError* error)
+void reportTransactionFailed(InspectorFrontend* frontend, long transactionId, SQLError* error)
 {
-    if (!agent->frontend())
+    if (!frontend)
         return;
     RefPtr<InspectorObject> errorObject = InspectorObject::create();
     errorObject->setString("message", error->message());
     errorObject->setNumber("code", error->code());
-    agent->frontend()->sqlTransactionFailed(transactionId, errorObject);
+    frontend->sqlTransactionFailed(transactionId, errorObject);
 }
 
 class StatementCallback : public SQLStatementCallback {
 public:
-    static PassRefPtr<StatementCallback> create(long transactionId, PassRefPtr<InspectorDatabaseAgent> agent)
+    static PassRefPtr<StatementCallback> create(long transactionId, PassRefPtr<InspectorDatabaseAgent::FrontendProvider> frontendProvider)
     {
-        return adoptRef(new StatementCallback(transactionId, agent));
+        return adoptRef(new StatementCallback(transactionId, frontendProvider));
     }
 
     virtual ~StatementCallback() { }
 
     virtual bool handleEvent(SQLTransaction*, SQLResultSet* resultSet)
     {
-        if (!m_agent->frontend())
+        if (!m_frontendProvider->frontend())
             return true;
 
         SQLResultSetRowList* rowList = resultSet->rows();
@@ -97,92 +113,92 @@ public:
                 case SQLValue::NullValue: values->pushValue(InspectorValue::null()); break;
             }
         }
-        m_agent->frontend()->sqlTransactionSucceeded(m_transactionId, columnNames, values);
+        m_frontendProvider->frontend()->sqlTransactionSucceeded(m_transactionId, columnNames, values);
         return true;
     }
 
 private:
-    StatementCallback(long transactionId, PassRefPtr<InspectorDatabaseAgent> agent)
+    StatementCallback(long transactionId, PassRefPtr<InspectorDatabaseAgent::FrontendProvider> frontendProvider)
         : m_transactionId(transactionId)
-        , m_agent(agent) { }
+        , m_frontendProvider(frontendProvider) { }
     long m_transactionId;
-    RefPtr<InspectorDatabaseAgent> m_agent;
+    RefPtr<InspectorDatabaseAgent::FrontendProvider> m_frontendProvider;
 };
 
 class StatementErrorCallback : public SQLStatementErrorCallback {
 public:
-    static PassRefPtr<StatementErrorCallback> create(long transactionId, PassRefPtr<InspectorDatabaseAgent> agent)
+    static PassRefPtr<StatementErrorCallback> create(long transactionId, PassRefPtr<InspectorDatabaseAgent::FrontendProvider> frontendProvider)
     {
-        return adoptRef(new StatementErrorCallback(transactionId, agent));
+        return adoptRef(new StatementErrorCallback(transactionId, frontendProvider));
     }
 
     virtual ~StatementErrorCallback() { }
 
     virtual bool handleEvent(SQLTransaction*, SQLError* error)
     {
-        reportTransactionFailed(m_agent.get(), m_transactionId, error);
+        reportTransactionFailed(m_frontendProvider->frontend(), m_transactionId, error);
         return true;  
     }
 
 private:
-    StatementErrorCallback(long transactionId, RefPtr<InspectorDatabaseAgent> agent)
+    StatementErrorCallback(long transactionId, PassRefPtr<InspectorDatabaseAgent::FrontendProvider> frontendProvider)
         : m_transactionId(transactionId)
-        , m_agent(agent) { }
+        , m_frontendProvider(frontendProvider) { }
     long m_transactionId;
-    RefPtr<InspectorDatabaseAgent> m_agent;
+    RefPtr<InspectorDatabaseAgent::FrontendProvider> m_frontendProvider;
 };
 
 class TransactionCallback : public SQLTransactionCallback {
 public:
-    static PassRefPtr<TransactionCallback> create(const String& sqlStatement, long transactionId, PassRefPtr<InspectorDatabaseAgent> agent)
+    static PassRefPtr<TransactionCallback> create(const String& sqlStatement, long transactionId, PassRefPtr<InspectorDatabaseAgent::FrontendProvider> frontendProvider)
     {
-        return adoptRef(new TransactionCallback(sqlStatement, transactionId, agent));
+        return adoptRef(new TransactionCallback(sqlStatement, transactionId, frontendProvider));
     }
 
     virtual ~TransactionCallback() { }
 
     virtual bool handleEvent(SQLTransaction* transaction)
     {
-        if (!m_agent->frontend())
+        if (!m_frontendProvider->frontend())
             return true;
 
         Vector<SQLValue> sqlValues;
-        RefPtr<SQLStatementCallback> callback(StatementCallback::create(m_transactionId, m_agent));
-        RefPtr<SQLStatementErrorCallback> errorCallback(StatementErrorCallback::create(m_transactionId, m_agent));
+        RefPtr<SQLStatementCallback> callback(StatementCallback::create(m_transactionId, m_frontendProvider));
+        RefPtr<SQLStatementErrorCallback> errorCallback(StatementErrorCallback::create(m_transactionId, m_frontendProvider));
         ExceptionCode ec = 0;
         transaction->executeSQL(m_sqlStatement, sqlValues, callback.release(), errorCallback.release(), ec);
         return true;
     }
 private:
-    TransactionCallback(const String& sqlStatement, long transactionId, PassRefPtr<InspectorDatabaseAgent> agent)
+    TransactionCallback(const String& sqlStatement, long transactionId, PassRefPtr<InspectorDatabaseAgent::FrontendProvider> frontendProvider)
         : m_sqlStatement(sqlStatement)
         , m_transactionId(transactionId)
-        , m_agent(agent) { }
+        , m_frontendProvider(frontendProvider) { }
     String m_sqlStatement;
     long m_transactionId;
-    RefPtr<InspectorDatabaseAgent> m_agent;
+    RefPtr<InspectorDatabaseAgent::FrontendProvider> m_frontendProvider;
 };
 
 class TransactionErrorCallback : public SQLTransactionErrorCallback {
 public:
-    static PassRefPtr<TransactionErrorCallback> create(long transactionId, PassRefPtr<InspectorDatabaseAgent> agent)
+    static PassRefPtr<TransactionErrorCallback> create(long transactionId, PassRefPtr<InspectorDatabaseAgent::FrontendProvider> frontendProvider)
     {
-        return adoptRef(new TransactionErrorCallback(transactionId, agent));
+        return adoptRef(new TransactionErrorCallback(transactionId, frontendProvider));
     }
 
     virtual ~TransactionErrorCallback() { }
 
     virtual bool handleEvent(SQLError* error)
     {
-        reportTransactionFailed(m_agent.get(), m_transactionId, error);
+        reportTransactionFailed(m_frontendProvider->frontend(), m_transactionId, error);
         return true;
     }
 private:
-    TransactionErrorCallback(long transactionId, PassRefPtr<InspectorDatabaseAgent> agent)
+    TransactionErrorCallback(long transactionId, PassRefPtr<InspectorDatabaseAgent::FrontendProvider> frontendProvider)
         : m_transactionId(transactionId)
-        , m_agent(agent) { }
+        , m_frontendProvider(frontendProvider) { }
     long m_transactionId;
-    RefPtr<InspectorDatabaseAgent> m_agent;
+    RefPtr<InspectorDatabaseAgent::FrontendProvider> m_frontendProvider;
 };
 
 class TransactionSuccessCallback : public VoidCallback {
@@ -204,6 +220,7 @@ private:
 
 InspectorDatabaseAgent::~InspectorDatabaseAgent()
 {
+    m_frontendProvider->clearFrontend();
 }
 
 void InspectorDatabaseAgent::getDatabaseTableNames(long databaseId, RefPtr<InspectorArray>* names)
@@ -226,8 +243,8 @@ void InspectorDatabaseAgent::executeSQL(long databaseId, const String& query, bo
     }
 
     *transactionId = ++lastTransactionId;
-    RefPtr<SQLTransactionCallback> callback(TransactionCallback::create(query, *transactionId, this));
-    RefPtr<SQLTransactionErrorCallback> errorCallback(TransactionErrorCallback::create(*transactionId, this));
+    RefPtr<SQLTransactionCallback> callback(TransactionCallback::create(query, *transactionId, m_frontendProvider));
+    RefPtr<SQLTransactionErrorCallback> errorCallback(TransactionErrorCallback::create(*transactionId, m_frontendProvider));
     RefPtr<VoidCallback> successCallback(TransactionSuccessCallback::create());
     database->transaction(callback.release(), errorCallback.release(), successCallback.release());
     *success = true;
@@ -243,25 +260,20 @@ Database* InspectorDatabaseAgent::databaseForId(long databaseId)
 
 void InspectorDatabaseAgent::selectDatabase(Database* database)
 {
-    if (!m_frontend)
+    if (!m_frontendProvider->frontend())
         return;
 
     for (DatabaseResourcesMap::iterator it = m_databaseResources->begin(); it != m_databaseResources->end(); ++it) {
         if (it->second->database() == database) {
-            m_frontend->selectDatabase(it->first);
+            m_frontendProvider->frontend()->selectDatabase(it->first);
             break;
         }
     }
 }
 
-void InspectorDatabaseAgent::clearFrontend()
-{
-    m_frontend = 0;
-}
-
 InspectorDatabaseAgent::InspectorDatabaseAgent(DatabaseResourcesMap* databaseResources, InspectorFrontend* frontend)
     : m_databaseResources(databaseResources)
-    , m_frontend(frontend)
+    , m_frontendProvider(FrontendProvider::create(frontend))
 {
 }
 
index a9e9a5d..4ad3e62 100644 (file)
@@ -30,8 +30,8 @@
 #define InspectorDatabaseAgent_h
 
 #include "PlatformString.h"
-#include "wtf/HashMap.h"
-#include "wtf/PassRefPtr.h"
+#include <wtf/HashMap.h>
+#include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
 
@@ -40,13 +40,15 @@ class InspectorArray;
 class InspectorDatabaseResource;
 class InspectorFrontend;
 
-class InspectorDatabaseAgent : public RefCounted<InspectorDatabaseAgent> {
+class InspectorDatabaseAgent {
 public:
+    class FrontendProvider;
+
     typedef HashMap<int, RefPtr<InspectorDatabaseResource> > DatabaseResourcesMap;
 
-    static PassRefPtr<InspectorDatabaseAgent> create(DatabaseResourcesMap* databaseResources, InspectorFrontend* frontend)
+    static PassOwnPtr<InspectorDatabaseAgent> create(DatabaseResourcesMap* databaseResources, InspectorFrontend* frontend)
     {
-        return adoptRef(new InspectorDatabaseAgent(databaseResources, frontend));
+        return adoptPtr(new InspectorDatabaseAgent(databaseResources, frontend));
     }
 
     virtual ~InspectorDatabaseAgent();
@@ -59,14 +61,11 @@ public:
     Database* databaseForId(long databaseId);
     void selectDatabase(Database* database);
 
-    InspectorFrontend* frontend() { return m_frontend; }
-    void clearFrontend();
-
 private:
     InspectorDatabaseAgent(DatabaseResourcesMap*, InspectorFrontend*);
 
     DatabaseResourcesMap* m_databaseResources;
-    InspectorFrontend* m_frontend;
+    RefPtr<FrontendProvider> m_frontendProvider;
 };
 
 } // namespace WebCore
index ba67818..e2d2f81 100644 (file)
@@ -51,28 +51,17 @@ InspectorDatabaseResource::InspectorDatabaseResource(PassRefPtr<Database> databa
     , m_domain(domain)
     , m_name(name)
     , m_version(version)
-    , m_scriptObjectCreated(false)
 {
 }
 
 void InspectorDatabaseResource::bind(InspectorFrontend* frontend)
 {
-    if (m_scriptObjectCreated)
-        return;
-
     RefPtr<InspectorObject> jsonObject = InspectorObject::create();
     jsonObject->setNumber("id", m_id);
     jsonObject->setString("domain", m_domain);
     jsonObject->setString("name", m_name);
     jsonObject->setString("version", m_version);
-
     frontend->addDatabase(jsonObject);
-    m_scriptObjectCreated = true;
-}
-
-void InspectorDatabaseResource::unbind()
-{
-    m_scriptObjectCreated = false;
 }
 
 } // namespace WebCore
index 203995b..24d4f1c 100644 (file)
@@ -46,7 +46,6 @@ public:
     static PassRefPtr<InspectorDatabaseResource> create(PassRefPtr<Database> database, const String& domain, const String& name, const String& version);
 
     void bind(InspectorFrontend* frontend);
-    void unbind();
     Database* database() { return m_database.get(); }
     long id() const { return m_id; }
 private:
@@ -57,7 +56,6 @@ private:
     String m_domain;
     String m_name;
     String m_version;
-    bool m_scriptObjectCreated;
 };
 
 } // namespace WebCore
index 399926f..e7bb1eb 100644 (file)
@@ -482,14 +482,14 @@ void InspectorInstrumentation::scriptImportedImpl(InspectorAgent* inspectorAgent
         resourceAgent->setInitialContent(identifier, sourceString, "Script");
 }
 
-void InspectorInstrumentation::mainResourceFiredLoadEventImpl(InspectorAgent* inspectorAgent, Frame* frame, const KURL& url)
+void InspectorInstrumentation::domContentLoadedEventFiredImpl(InspectorAgent* inspectorAgent, Frame* frame, const KURL& url)
 {
-    inspectorAgent->mainResourceFiredLoadEvent(frame->loader()->documentLoader(), url);
+    inspectorAgent->domContentLoadedEventFired(frame->loader()->documentLoader(), url);
 }
 
-void InspectorInstrumentation::mainResourceFiredDOMContentEventImpl(InspectorAgent* inspectorAgent, Frame* frame, const KURL& url)
+void InspectorInstrumentation::loadEventFiredImpl(InspectorAgent* inspectorAgent, Frame* frame, const KURL& url)
 {
-    inspectorAgent->mainResourceFiredDOMContentEvent(frame->loader()->documentLoader(), url);
+    inspectorAgent->loadEventFired(frame->loader()->documentLoader(), url);
 }
 
 void InspectorInstrumentation::frameDetachedFromParentImpl(InspectorAgent* inspectorAgent, Frame* frame)
index 576d1f5..e406e40 100644 (file)
@@ -122,8 +122,8 @@ public:
     static void didFailLoading(Frame*, unsigned long identifier, const ResourceError&);
     static void resourceRetrievedByXMLHttpRequest(ScriptExecutionContext*, unsigned long identifier, const String& sourceString, const String& url, const String& sendURL, unsigned sendLineNumber);
     static void scriptImported(ScriptExecutionContext*, unsigned long identifier, const String& sourceString);
-    static void mainResourceFiredLoadEvent(Frame*, const KURL&);
-    static void mainResourceFiredDOMContentEvent(Frame*, const KURL&);
+    static void domContentLoadedEventFired(Frame*, const KURL&);
+    static void loadEventFired(Frame*, const KURL&);
     static void frameDetachedFromParent(Frame*);
     static void didCommitLoad(Frame*, DocumentLoader*);
 
@@ -238,8 +238,8 @@ private:
     static void didFailLoadingImpl(InspectorAgent*, unsigned long identifier, const ResourceError&);
     static void resourceRetrievedByXMLHttpRequestImpl(InspectorAgent*, unsigned long identifier, const String& sourceString, const String& url, const String& sendURL, unsigned sendLineNumber);
     static void scriptImportedImpl(InspectorAgent*, unsigned long identifier, const String& sourceString);
-    static void mainResourceFiredLoadEventImpl(InspectorAgent*, Frame*, const KURL&);
-    static void mainResourceFiredDOMContentEventImpl(InspectorAgent*, Frame*, const KURL&);
+    static void domContentLoadedEventFiredImpl(InspectorAgent*, Frame*, const KURL&);
+    static void loadEventFiredImpl(InspectorAgent*, Frame*, const KURL&);
     static void frameDetachedFromParentImpl(InspectorAgent*, Frame*);
     static void didCommitLoadImpl(InspectorAgent*, DocumentLoader*);
 
@@ -706,19 +706,19 @@ inline void InspectorInstrumentation::scriptImported(ScriptExecutionContext* con
 #endif
 }
 
-inline void InspectorInstrumentation::mainResourceFiredLoadEvent(Frame* frame, const KURL& url)
+inline void InspectorInstrumentation::domContentLoadedEventFired(Frame* frame, const KURL& url)
 {
 #if ENABLE(INSPECTOR)
     if (InspectorAgent* inspectorAgent = inspectorAgentWithFrontendForFrame(frame))
-        mainResourceFiredLoadEventImpl(inspectorAgent, frame, url);
+        domContentLoadedEventFiredImpl(inspectorAgent, frame, url);
 #endif
 }
 
-inline void InspectorInstrumentation::mainResourceFiredDOMContentEvent(Frame* frame, const KURL& url)
+inline void InspectorInstrumentation::loadEventFired(Frame* frame, const KURL& url)
 {
 #if ENABLE(INSPECTOR)
     if (InspectorAgent* inspectorAgent = inspectorAgentWithFrontendForFrame(frame))
-        mainResourceFiredDOMContentEventImpl(inspectorAgent, frame, url);
+        loadEventFiredImpl(inspectorAgent, frame, url);
 #endif
 }
 
index b7e66e5..290ffc2 100644 (file)
@@ -38,10 +38,14 @@ namespace WebCore {
 InspectorState::InspectorState(InspectorClient* client)
     : m_client(client)
     , m_properties(InspectorObject::create())
+    , m_isOnMute(false)
 {
 }
 
-void InspectorState::restoreFromInspectorCookie(const String& json)
+InspectorState::InspectorState(InspectorClient* client, const String& json)
+    : m_client(client)
+    , m_properties(InspectorObject::create())
+    , m_isOnMute(false)
 {
     RefPtr<InspectorValue> jsonValue = InspectorValue::parseJSON(json);
     if (jsonValue)
@@ -50,9 +54,15 @@ void InspectorState::restoreFromInspectorCookie(const String& json)
         m_properties = InspectorObject::create();
 }
 
+void InspectorState::mute()
+{
+    m_isOnMute = true;
+}
+
 void InspectorState::updateCookie()
 {
-    m_client->updateInspectorStateCookie(m_properties->toJSONString());
+    if (!m_isOnMute)
+        m_client->updateInspectorStateCookie(m_properties->toJSONString());
 }
 
 void InspectorState::setValue(const String& propertyName, PassRefPtr<InspectorValue> value)
index 2683a08..3a9c3ed 100644 (file)
@@ -45,9 +45,11 @@ class InspectorClient;
 
 class InspectorState {
 public:
-    InspectorState(InspectorClient* client);
+    InspectorState(InspectorClient*);
+    InspectorState(InspectorClient*, const String& jsonString);
+    virtual ~InspectorState() {}
 
-    void restoreFromInspectorCookie(const String& jsonString);
+    void mute();
 
     bool getBoolean(const String& propertyName);
     String getString(const String& propertyName);
@@ -65,6 +67,7 @@ private:
 
     InspectorClient* m_client;
     RefPtr<InspectorObject> m_properties;
+    bool m_isOnMute;
 };
 
 } // namespace WebCore
index 1e23622..dd0a119 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "Event.h"
 #include "InspectorFrontend.h"
+#include "InspectorState.h"
 #include "IntRect.h"
 #include "ResourceRequest.h"
 #include "ResourceResponse.h"
 
 namespace WebCore {
 
+namespace TimelineAgentState {
+static const char timelineAgentEnabled[] = "timelineAgentEnabled";
+}
+
 int InspectorTimelineAgent::s_id = 0;
 
-InspectorTimelineAgent::InspectorTimelineAgent(InspectorFrontend* frontend)
-    : m_frontend(frontend)
-    , m_id(++s_id)
+PassOwnPtr<InspectorTimelineAgent> InspectorTimelineAgent::restore(InspectorState* state, InspectorFrontend* frontend)
 {
-    ScriptGCEvent::addEventListener(this);
-    ASSERT(m_frontend);
+    if (state->getBoolean(TimelineAgentState::timelineAgentEnabled))
+        return create(state, frontend);
+    return 0;
 }
 
 void InspectorTimelineAgent::pushGCEventRecords()
@@ -76,7 +80,9 @@ void InspectorTimelineAgent::didGC(double startTime, double endTime, size_t coll
 
 InspectorTimelineAgent::~InspectorTimelineAgent()
 {
+    m_frontend->timelineProfilerWasStopped();
     ScriptGCEvent::removeEventListener(this);
+    m_state->setBoolean(TimelineAgentState::timelineAgentEnabled, false);
 }
 
 void InspectorTimelineAgent::willCallFunction(const String& scriptName, int scriptLine)
@@ -272,15 +278,15 @@ void InspectorTimelineAgent::didMarkLoadEvent()
     addRecordToTimeline(record.release(), MarkLoadEventType);
 }
 
-void InspectorTimelineAgent::reset()
+void InspectorTimelineAgent::didCommitLoad()
 {
     m_recordStack.clear();
 }
 
-void InspectorTimelineAgent::resetFrontendProxyObject(InspectorFrontend* frontend)
+void InspectorTimelineAgent::setFrontend(InspectorFrontend* frontend)
 {
     ASSERT(frontend);
-    reset();
+    m_recordStack.clear();
     m_frontend = frontend;
 }
 
@@ -323,6 +329,16 @@ void InspectorTimelineAgent::didCompleteCurrentRecord(TimelineRecordType type)
     }
 }
 
+InspectorTimelineAgent::InspectorTimelineAgent(InspectorState* state, InspectorFrontend* frontend)
+    : m_state(state)
+    , m_frontend(frontend)
+    , m_id(++s_id)
+{
+    ScriptGCEvent::addEventListener(this);
+    m_frontend->timelineProfilerWasStarted();
+    m_state->setBoolean(TimelineAgentState::timelineAgentEnabled, true);
+}
+
 void InspectorTimelineAgent::pushCurrentRecord(PassRefPtr<InspectorObject> data, TimelineRecordType type)
 {
     pushGCEventRecords();
index cae5aad..36c2df2 100644 (file)
 #include "InspectorValues.h"
 #include "ScriptGCEvent.h"
 #include "ScriptGCEventListener.h"
+#include <wtf/PassOwnPtr.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
 class Event;
 class InspectorFrontend;
+class InspectorState;
 class IntRect;
 class ResourceRequest;
 class ResourceResponse;
@@ -71,15 +73,21 @@ enum TimelineRecordType {
 };
 
 class InspectorTimelineAgent : ScriptGCEventListener {
-    WTF_MAKE_NONCOPYABLE(InspectorTimelineAgent); WTF_MAKE_FAST_ALLOCATED;
+    WTF_MAKE_NONCOPYABLE(InspectorTimelineAgent);
 public:
-    InspectorTimelineAgent(InspectorFrontend* frontend);
+    static PassOwnPtr<InspectorTimelineAgent> create(InspectorState* state, InspectorFrontend* frontend)
+    {
+        return adoptPtr(new InspectorTimelineAgent(state, frontend));
+    }
+
+    static PassOwnPtr<InspectorTimelineAgent> restore(InspectorState*, InspectorFrontend*);
+
     ~InspectorTimelineAgent();
 
     int id() const { return m_id; }
 
-    void reset();
-    void resetFrontendProxyObject(InspectorFrontend*);
+    void didCommitLoad();
+    void setFrontend(InspectorFrontend*);
 
     // Methods called from WebCore.
     void willCallFunction(const String& scriptName, int scriptLine);
@@ -141,6 +149,8 @@ private:
         TimelineRecordType type;
     };
         
+    InspectorTimelineAgent(InspectorState*, InspectorFrontend*);
+
     void pushCurrentRecord(PassRefPtr<InspectorObject>, TimelineRecordType);
     void setHeapSizeStatistic(InspectorObject* record);
         
@@ -150,6 +160,7 @@ private:
 
     void pushGCEventRecords();
 
+    InspectorState* m_state;
     InspectorFrontend* m_frontend;
 
     Vector<TimelineRecordEntry> m_recordStack;
index 560af91..ed6d057 100644 (file)
@@ -1535,7 +1535,7 @@ void DOMWindow::dispatchLoadEvent()
         ownerElement->dispatchGenericEvent(ownerEvent.release());
     }
 
-    InspectorInstrumentation::mainResourceFiredLoadEvent(frame(), url());
+    InspectorInstrumentation::loadEventFired(frame(), url());
 }
 
 bool DOMWindow::dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget)