diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-06 14:01:45 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-06 14:01:45 +0000 |
commit | 449be361bb402d93a2bfa59dc61c72beafac6959 (patch) | |
tree | 13978441ed9c6de996972897c57a59d5bee8b5db /webkit | |
parent | b75b7d079cffabab306e5701645f8d6a3c595873 (diff) | |
download | chromium_src-449be361bb402d93a2bfa59dc61c72beafac6959.zip chromium_src-449be361bb402d93a2bfa59dc61c72beafac6959.tar.gz chromium_src-449be361bb402d93a2bfa59dc61c72beafac6959.tar.bz2 |
DevTools: Glue part for the 'attach early' functionality.
- Establish 2 main scenarios for attach: 'attach to live' and 'start attached'
- Make WebFrameLoaderImpl call setMainFrameDocumentReady only for main frame document.
Review URL: http://codereview.chromium.org/62038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13154 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/devtools/dom_agent_impl.cc | 35 | ||||
-rw-r--r-- | webkit/glue/devtools/dom_agent_impl.h | 8 | ||||
-rw-r--r-- | webkit/glue/devtools/dom_agent_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.cc | 32 | ||||
-rw-r--r-- | webkit/glue/webframeloaderclient_impl.cc | 15 |
5 files changed, 62 insertions, 30 deletions
diff --git a/webkit/glue/devtools/dom_agent_impl.cc b/webkit/glue/devtools/dom_agent_impl.cc index 54e4445..f67dfdd 100644 --- a/webkit/glue/devtools/dom_agent_impl.cc +++ b/webkit/glue/devtools/dom_agent_impl.cc @@ -71,11 +71,11 @@ DomAgentImpl::DomAgentImpl(DomAgentDelegate* delegate) } DomAgentImpl::~DomAgentImpl() { - SetDocument(NULL); + SetDocument(NULL, false); } -void DomAgentImpl::SetDocument(Document* doc) { - if (documents_.size() && doc == documents_.begin()->get()) { +void DomAgentImpl::SetDocument(Document* doc, bool loaded) { + if (doc == GetMainFrameDocument()) { return; } @@ -85,12 +85,12 @@ void DomAgentImpl::SetDocument(Document* doc) { StopListening((*it).get()); } ASSERT(documents_.size() == 0); + ASSERT(loaded_documents_.size() == 0); if (doc) { StartListening(doc); - if (document_element_requested_) { - GetDocumentElement(); - document_element_requested_ = false; + if (loaded) { + loaded_documents_.add(doc); } } else { DiscardBindings(); @@ -125,6 +125,7 @@ void DomAgentImpl::StopListening(Document* doc) { doc->removeEventListener(eventNames().DOMAttrModifiedEvent, event_listener_.get(), false); documents_.remove(doc); + loaded_documents_.remove(doc); } int DomAgentImpl::Bind(Node* node) { @@ -153,7 +154,7 @@ void DomAgentImpl::Unbind(Node* node) { } void DomAgentImpl::PushDocumentElementToClient() { - Element* doc_elem = (*documents_.begin())->documentElement(); + Element* doc_elem = GetMainFrameDocument()->documentElement(); if (!node_to_id_.contains(doc_elem)) { OwnPtr<Value> value(BuildValueForNode(doc_elem, 0)); delegate_->SetDocumentElement(*value.get()); @@ -249,12 +250,18 @@ void DomAgentImpl::handleEvent(Event* event, bool isWindowEvent) { delegate_->ChildNodeRemoved(parent_id, id); } } else if (type == eventNames().DOMContentLoadedEvent) { - //TODO(pfeldman): handle content load event. + Document* doc = static_cast<Document*>(node); + loaded_documents_.add(doc); + if (document_element_requested_ && + loaded_documents_.contains(GetMainFrameDocument())) { + GetDocumentElement(); + document_element_requested_ = false; + } } } void DomAgentImpl::GetDocumentElement() { - if (documents_.size() > 0) { + if (loaded_documents_.contains(GetMainFrameDocument())) { PushDocumentElementToClient(); } else { document_element_requested_ = true; @@ -390,7 +397,7 @@ void DomAgentImpl::PerformSearch(int call_id, const String& query) { ExceptionCode ec = 0; Vector<Document*> search_documents; - Document* main_document = (*documents_.begin()).get(); + Document* main_document = GetMainFrameDocument(); search_documents.append(main_document); // Find all frames, iframes and object elements to search their documents. @@ -646,3 +653,11 @@ Element* DomAgentImpl::InnerParentElement(Node* node) { } return element; } + +Document* DomAgentImpl::GetMainFrameDocument() { + ListHashSet<RefPtr<WebCore::Document> >::iterator it = documents_.begin(); + if (it != documents_.end()) { + return it->get(); + } + return NULL; +} diff --git a/webkit/glue/devtools/dom_agent_impl.h b/webkit/glue/devtools/dom_agent_impl.h index 5a959eb..88a251c 100644 --- a/webkit/glue/devtools/dom_agent_impl.h +++ b/webkit/glue/devtools/dom_agent_impl.h @@ -55,7 +55,11 @@ class DomAgentImpl : public DomAgent { void DiscardBindings(); // Initializes dom agent with the given document. - void SetDocument(WebCore::Document* document); + // 'loaded' must be set to true iff main resource has been loaded + // and document has been parsed. Otherwise, 'loaded' should be + // false. DomAgent will then add itself as a listener to the + // DOMContentLoaded event and will track document loading by itself. + void SetDocument(WebCore::Document* document, bool loaded); // Returns node for given id according to the present binding. WebCore::Node* GetNodeForId(int id); @@ -134,6 +138,7 @@ class DomAgentImpl : public DomAgent { WebCore::Node* InnerFirstChild(WebCore::Node* node); int InnerChildNodeCount(WebCore::Node* node); WebCore::Element* InnerParentElement(WebCore::Node* node); + WebCore::Document* GetMainFrameDocument(); DomAgentDelegate* delegate_; HashMap<WebCore::Node*, int> node_to_id_; @@ -141,6 +146,7 @@ class DomAgentImpl : public DomAgent { HashSet<int> children_requested_; int last_node_id_; ListHashSet<RefPtr<WebCore::Document> > documents_; + HashSet<RefPtr<WebCore::Document> > loaded_documents_; RefPtr<WebCore::EventListener> event_listener_; // Captures pending document element request's call id. // Defaults to 0 meaning no pending request. diff --git a/webkit/glue/devtools/dom_agent_unittest.cc b/webkit/glue/devtools/dom_agent_unittest.cc index b88a183..0f31abc 100644 --- a/webkit/glue/devtools/dom_agent_unittest.cc +++ b/webkit/glue/devtools/dom_agent_unittest.cc @@ -66,7 +66,7 @@ class DomAgentTests : public TestShellTest { mock_delegate_.set(new MockDomAgentDelegate()); dom_agent_.set(new DomAgentImpl(mock_delegate_.get())); - dom_agent_->SetDocument(document_.get()); + dom_agent_->SetDocument(document_.get(), true); } virtual void TearDown() { diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc index 05984f4..690858c 100644 --- a/webkit/glue/webdevtoolsagent_impl.cc +++ b/webkit/glue/webdevtoolsagent_impl.cc @@ -59,10 +59,15 @@ void WebDevToolsAgentImpl::Attach() { new DebuggerAgentImpl(debugger_agent_delegate_stub_.get())); dom_agent_impl_.set(new DomAgentImpl(dom_agent_delegate_stub_.get())); net_agent_impl_.set(new NetAgentImpl(net_agent_delegate_stub_.get())); - if (document_) { - debugger_agent_impl_->SetDocument(document_); - dom_agent_impl_->SetDocument(document_); - net_agent_impl_->SetDocument(document_); + + // We are potentially attaching to the running page -> init agents with + // Document if any. + Page* page = web_view_impl_->page(); + Document* doc = page->mainFrame()->document(); + if (doc) { + debugger_agent_impl_->SetDocument(doc); + dom_agent_impl_->SetDocument(doc, true); + net_agent_impl_->SetDocument(doc); } attached_ = true; } @@ -75,18 +80,21 @@ void WebDevToolsAgentImpl::Detach() { } void WebDevToolsAgentImpl::SetMainFrameDocumentReady(bool ready) { - // Store document reference no matter if client is attached. + if (!attached_) { + return; + } + + // We were attached prior to the page load -> init agents with Document. + Document* doc; if (ready) { Page* page = web_view_impl_->page(); - document_ = page->mainFrame()->document(); + doc = page->mainFrame()->document(); } else { - document_ = NULL; - } - if (attached_) { - debugger_agent_impl_->SetDocument(document_); - dom_agent_impl_->SetDocument(document_); - net_agent_impl_->SetDocument(document_); + doc = NULL; } + debugger_agent_impl_->SetDocument(doc); + dom_agent_impl_->SetDocument(doc, false); + net_agent_impl_->SetDocument(doc); } void WebDevToolsAgentImpl::DidCommitLoadForFrame( diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index e66157d..34f1763 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -1107,12 +1107,15 @@ void WebFrameLoaderClient::postProgressFinishedNotification() { } void WebFrameLoaderClient::setMainFrameDocumentReady(bool ready) { - if (hasWebView()) { - WebDevToolsAgentImpl* tools_agent = - webframe_->webview_impl()->GetWebDevToolsAgentImpl(); - if (tools_agent) { - tools_agent->SetMainFrameDocumentReady(ready); - } + WebViewImpl* web_view = webframe_->webview_impl(); + if (!web_view) + return; + WebDevToolsAgentImpl* tools_agent = web_view->GetWebDevToolsAgentImpl(); + if (!tools_agent) + return; + + if (webframe_ == web_view->GetMainFrame()) { + tools_agent->SetMainFrameDocumentReady(ready); } } |