diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-02 13:07:03 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-02 13:07:03 +0000 |
commit | 51996efd0e452dc7cea81616783958cb3fbf81e2 (patch) | |
tree | db60636fbdd6668d24add5183e42c4d844cf2b8d /webkit | |
parent | ce99295021b01038cd03d67e98b920c58c250578 (diff) | |
download | chromium_src-51996efd0e452dc7cea81616783958cb3fbf81e2.zip chromium_src-51996efd0e452dc7cea81616783958cb3fbf81e2.tar.gz chromium_src-51996efd0e452dc7cea81616783958cb3fbf81e2.tar.bz2 |
DevTools: add support for provisional load tracking.
Review URL: http://codereview.chromium.org/56149
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13008 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/devtools/js/devtools.js | 9 | ||||
-rw-r--r-- | webkit/glue/devtools/js/inspector_controller_impl.js | 3 | ||||
-rw-r--r-- | webkit/glue/devtools/js/net_agent.js | 21 | ||||
-rw-r--r-- | webkit/glue/devtools/net_agent_impl.cc | 75 | ||||
-rw-r--r-- | webkit/glue/devtools/net_agent_impl.h | 7 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.cc | 45 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.h | 17 |
7 files changed, 117 insertions, 60 deletions
diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js index 78f47da..c7b4777 100644 --- a/webkit/glue/devtools/js/devtools.js +++ b/webkit/glue/devtools/js/devtools.js @@ -33,6 +33,7 @@ devtools.ToolsAgent = function() { */ devtools.ToolsAgent.prototype.reset = function() { this.domAgent_.reset(); + this.netAgent_.reset(); this.domAgent_.getDocumentElementAsync(); }; @@ -114,11 +115,15 @@ devtools.ToolsAgent.prototype.updateFocusedNode = function(nodeId) { /** + * @param {string} url Url frame navigated to. + * @param {bool} topLevel True iff top level navigation occurred. * @see tools_agent.h */ devtools.ToolsAgent.prototype.frameNavigate = function(url, topLevel) { - this.reset(); - WebInspector.reset(); + if (topLevel) { + this.reset(); + WebInspector.reset(); + } }; diff --git a/webkit/glue/devtools/js/inspector_controller_impl.js b/webkit/glue/devtools/js/inspector_controller_impl.js index 2ce61f5..72897f5 100644 --- a/webkit/glue/devtools/js/inspector_controller_impl.js +++ b/webkit/glue/devtools/js/inspector_controller_impl.js @@ -61,7 +61,8 @@ devtools.InspectorControllerImpl.prototype.addSourceToFrame = devtools.InspectorControllerImpl.prototype.addResourceSourceToFrame = function(identifier, element) { var self = this; - tools.getNetAgent().getResourceContentAsync(identifier, function(source) { + var netAgent = devtools.tools.getNetAgent(); + netAgent.getResourceContentAsync(identifier, function(source) { var resource = netAgent.getResource(identifier); self.addSourceToFrame(resource.mimeType, source, element); }); diff --git a/webkit/glue/devtools/js/net_agent.js b/webkit/glue/devtools/js/net_agent.js index 0c0d9fe..2e54f58 100644 --- a/webkit/glue/devtools/js/net_agent.js +++ b/webkit/glue/devtools/js/net_agent.js @@ -27,6 +27,15 @@ devtools.NetAgent = function() { /** + * Resets dom agent to its initial state. + */ +devtools.NetAgent.prototype.reset = function() { + this.resources_ = {}; + this.id_for_url_ = {}; +}; + + +/** * Returns resource object for given identifier. * @param {number} identifier Identifier to get resource for. * @return {WebInspector.Resouce} Resulting resource. @@ -63,6 +72,12 @@ devtools.NetAgent.prototype.getResourceContentAsync = function(identifier, * {@inheritDoc}. */ devtools.NetAgent.prototype.willSendRequest = function(identifier, request) { + // Resource object is already created. + var resource = this.resources_[identifier]; + if (resource) { + return; + } + var mainResource = false; var cached = false; var resource = new WebInspector.Resource(request.requestHeaders, @@ -84,6 +99,7 @@ devtools.NetAgent.prototype.didReceiveResponse = function(identifier, response) if (!resource) { return; } + resource.expectedContentLength = response.expectedContentLength; resource.responseStatusCode = response.responseStatusCode; resource.mimeType = response.mimeType; @@ -108,6 +124,11 @@ devtools.NetAgent.prototype.didReceiveResponse = function(identifier, response) * {@inheritDoc}. */ devtools.NetAgent.prototype.didFinishLoading = function(identifier, value) { + // When loading main resource we are only getting the didFinishLoading + // that is happening after the reset. Replay previous commands here. + this.willSendRequest(identifier, value); + this.didReceiveResponse(identifier, value); + var resource = this.resources_[identifier]; if (!resource) { return; diff --git a/webkit/glue/devtools/net_agent_impl.cc b/webkit/glue/devtools/net_agent_impl.cc index 2202bd0..d4c1cd7 100644 --- a/webkit/glue/devtools/net_agent_impl.cc +++ b/webkit/glue/devtools/net_agent_impl.cc @@ -38,6 +38,11 @@ NetAgentImpl::NetAgentImpl(NetAgentDelegate* delegate) NetAgentImpl::~NetAgentImpl() { SetDocument(NULL); + for (CachedResources::iterator it = pending_resources_.begin(); + it != pending_resources_.end(); ++it) { + delete it->second; + } + pending_resources_.clear(); } void NetAgentImpl::SetDocument(Document* doc) { @@ -57,42 +62,43 @@ void NetAgentImpl::WillSendRequest( int identifier, const ResourceRequest& request) { KURL url = request.url(); - DictionaryValue value; - value.SetReal(L"startTime", WTF::currentTime()); - value.SetString(L"url", webkit_glue::StringToStdString(url.string())); - value.SetString(L"domain", webkit_glue::StringToStdString(url.host())); - value.SetString(L"path", webkit_glue::StringToStdString(url.path())); - value.SetString(L"lastPathComponent", + DictionaryValue* resource = new DictionaryValue(); + + resource->SetReal(L"startTime", WTF::currentTime()); + resource->SetString(L"url", webkit_glue::StringToStdString(url.string())); + resource->SetString(L"domain", webkit_glue::StringToStdString(url.host())); + resource->SetString(L"path", webkit_glue::StringToStdString(url.path())); + resource->SetString(L"lastPathComponent", webkit_glue::StringToStdString(url.lastPathComponent())); - value.Set(L"requestHeaders", + resource->Set(L"requestHeaders", BuildValueForHeaders(request.httpHeaderFields())); - delegate_->WillSendRequest(identifier, value); + delegate_->WillSendRequest(identifier, *resource); + pending_resources_.set(identifier, resource); } void NetAgentImpl::DidReceiveResponse( DocumentLoader* loader, int identifier, const ResourceResponse &response) { - if (!document_) { + KURL url = response.url(); + if (!pending_resources_.contains(identifier)) { return; } - KURL url = response.url(); - - DictionaryValue value; - value.SetReal(L"responseReceivedTime", WTF::currentTime()); - value.SetString(L"url", + DictionaryValue* resource = pending_resources_.get(identifier); + resource->SetReal(L"responseReceivedTime", WTF::currentTime()); + resource->SetString(L"url", webkit_glue::StringToStdWString(url.string())); - value.SetInteger(L"expectedContentLength", + resource->SetInteger(L"expectedContentLength", static_cast<int>(response.expectedContentLength())); - value.SetInteger(L"responseStatusCode", response.httpStatusCode()); - value.SetString(L"mimeType", + resource->SetInteger(L"responseStatusCode", response.httpStatusCode()); + resource->SetString(L"mimeType", webkit_glue::StringToStdWString(response.mimeType())); - value.SetString(L"suggestedFilename", + resource->SetString(L"suggestedFilename", webkit_glue::StringToStdWString(response.suggestedFilename())); - value.Set(L"responseHeaders", + resource->Set(L"responseHeaders", BuildValueForHeaders(response.httpHeaderFields())); - delegate_->DidReceiveResponse(identifier, value); + delegate_->DidReceiveResponse(identifier, *resource); } void NetAgentImpl::DidReceiveContentLength( @@ -104,21 +110,31 @@ void NetAgentImpl::DidReceiveContentLength( void NetAgentImpl::DidFinishLoading( DocumentLoader* loader, int identifier) { - DictionaryValue value; - value.SetReal(L"endTime", WTF::currentTime()); - delegate_->DidFinishLoading(identifier, value); + if (!pending_resources_.contains(identifier)) { + return; + } + DictionaryValue* resource = pending_resources_.get(identifier); + resource->SetReal(L"endTime", WTF::currentTime()); + delegate_->DidFinishLoading(identifier, *resource); + pending_resources_.remove(identifier); + delete resource; } void NetAgentImpl::DidFailLoading( DocumentLoader* loader, int identifier, const ResourceError& error) { - DictionaryValue value; - value.SetReal(L"endTime", WTF::currentTime()); - value.SetInteger(L"errorCode", error.errorCode()); - value.SetString(L"localizedDescription", + if (!pending_resources_.contains(identifier)) { + return; + } + DictionaryValue* resource = pending_resources_.get(identifier); + resource->SetReal(L"endTime", WTF::currentTime()); + resource->SetInteger(L"errorCode", error.errorCode()); + resource->SetString(L"localizedDescription", webkit_glue::StringToStdString(error.localizedDescription())); - delegate_->DidFailLoading(identifier, value); + delegate_->DidFailLoading(identifier, *resource); + pending_resources_.remove(identifier); + delete resource; } void NetAgentImpl::DidLoadResourceFromMemoryCache( @@ -137,8 +153,7 @@ void NetAgentImpl::GetResourceContent( if (!document_) { return; } - HashMap<int, RefPtr<DocumentLoader> >::iterator it = - loaders_.find(identifier); + CachedLoaders::iterator it = loaders_.find(identifier); if (it == loaders_.end() || !it->second) { return; } diff --git a/webkit/glue/devtools/net_agent_impl.h b/webkit/glue/devtools/net_agent_impl.h index 661ecb5..94f5e20 100644 --- a/webkit/glue/devtools/net_agent_impl.h +++ b/webkit/glue/devtools/net_agent_impl.h @@ -73,7 +73,12 @@ class NetAgentImpl : public NetAgent { NetAgentDelegate* delegate_; WebCore::Document* document_; - HashMap<int, RefPtr<WebCore::DocumentLoader> > loaders_; + typedef HashMap<int, DictionaryValue*, DefaultHash<int>::Hash, + WTF::UnsignedWithZeroKeyHashTraits<int> > CachedResources; + typedef HashMap<int, RefPtr<WebCore::DocumentLoader>, DefaultHash<int>::Hash, + WTF::UnsignedWithZeroKeyHashTraits<int> > CachedLoaders; + CachedResources pending_resources_; + CachedLoaders loaders_; int last_cached_identifier_; DISALLOW_COPY_AND_ASSIGN(NetAgentImpl); }; diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc index 8d3ae90..05984f4 100644 --- a/webkit/glue/webdevtoolsagent_impl.cc +++ b/webkit/glue/webdevtoolsagent_impl.cc @@ -42,10 +42,10 @@ WebDevToolsAgentImpl::WebDevToolsAgentImpl( web_view_impl_(web_view_impl), document_(NULL), attached_(false) { - debugger_agent_delegate_stub_.reset(new DebuggerAgentDelegateStub(this)); - dom_agent_delegate_stub_.reset(new DomAgentDelegateStub(this)); - net_agent_delegate_stub_.reset(new NetAgentDelegateStub(this)); - tools_agent_delegate_stub_.reset(new ToolsAgentDelegateStub(this)); + debugger_agent_delegate_stub_.set(new DebuggerAgentDelegateStub(this)); + dom_agent_delegate_stub_.set(new DomAgentDelegateStub(this)); + net_agent_delegate_stub_.set(new NetAgentDelegateStub(this)); + tools_agent_delegate_stub_.set(new ToolsAgentDelegateStub(this)); } WebDevToolsAgentImpl::~WebDevToolsAgentImpl() { @@ -55,10 +55,10 @@ void WebDevToolsAgentImpl::Attach() { if (attached_) { return; } - debugger_agent_impl_.reset( + debugger_agent_impl_.set( new DebuggerAgentImpl(debugger_agent_delegate_stub_.get())); - dom_agent_impl_.reset(new DomAgentImpl(dom_agent_delegate_stub_.get())); - net_agent_impl_.reset(new NetAgentImpl(net_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_); @@ -68,13 +68,14 @@ void WebDevToolsAgentImpl::Attach() { } void WebDevToolsAgentImpl::Detach() { - debugger_agent_impl_.reset(NULL); - dom_agent_impl_.reset(NULL); - net_agent_impl_.reset(NULL); + debugger_agent_impl_.set(NULL); + dom_agent_impl_.set(NULL); + net_agent_impl_.set(NULL); attached_ = false; } void WebDevToolsAgentImpl::SetMainFrameDocumentReady(bool ready) { + // Store document reference no matter if client is attached. if (ready) { Page* page = web_view_impl_->page(); document_ = page->mainFrame()->document(); @@ -106,11 +107,13 @@ void WebDevToolsAgentImpl::DidCommitLoadForFrame( } void WebDevToolsAgentImpl::HighlightDOMNode(int node_id) { - if (!attached_) + if (!attached_) { return; + } Node* node = dom_agent_impl_->GetNodeForId(node_id); - if (!node) + if (!node) { return; + } Page* page = web_view_impl_->page(); page->inspectorController()->highlight(node); } @@ -152,28 +155,34 @@ void WebDevToolsAgentImpl::DispatchMessageFromClient( const std::string& raw_msg) { OwnPtr<ListValue> message( static_cast<ListValue*>(DevToolsRpc::ParseMessage(raw_msg))); - if (ToolsAgentDispatch::Dispatch(this, *message.get())) + if (ToolsAgentDispatch::Dispatch(this, *message.get())) { return; + } - if (!attached_) + if (!attached_) { return; + } if (debugger_agent_impl_.get() && DebuggerAgentDispatch::Dispatch( debugger_agent_impl_.get(), - *message.get())) + *message.get())) { return; + } - if (DomAgentDispatch::Dispatch(dom_agent_impl_.get(), *message.get())) + if (DomAgentDispatch::Dispatch(dom_agent_impl_.get(), *message.get())) { return; - if (NetAgentDispatch::Dispatch(net_agent_impl_.get(), *message.get())) + } + if (NetAgentDispatch::Dispatch(net_agent_impl_.get(), *message.get())) { return; + } } void WebDevToolsAgentImpl::InspectElement(int x, int y) { Node* node = web_view_impl_->GetNodeForWindowPos(x, y); - if (!node) + if (!node) { return; + } int node_id = dom_agent_impl_->PushNodePathToClient(node); tools_agent_delegate_stub_->UpdateFocusedNode(node_id); diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h index 85e89b5..cb8fb86 100644 --- a/webkit/glue/webdevtoolsagent_impl.h +++ b/webkit/glue/webdevtoolsagent_impl.h @@ -7,7 +7,8 @@ #include <string> -#include "base/scoped_ptr.h" +#include <wtf/OwnPtr.h> + #include "webkit/glue/devtools/devtools_rpc.h" #include "webkit/glue/devtools/dom_agent.h" #include "webkit/glue/devtools/net_agent.h" @@ -70,13 +71,13 @@ class WebDevToolsAgentImpl WebDevToolsAgentDelegate* delegate_; WebViewImpl* web_view_impl_; WebCore::Document* document_; - scoped_ptr<DebuggerAgentDelegateStub> debugger_agent_delegate_stub_; - scoped_ptr<DomAgentDelegateStub> dom_agent_delegate_stub_; - scoped_ptr<NetAgentDelegateStub> net_agent_delegate_stub_; - scoped_ptr<ToolsAgentDelegateStub> tools_agent_delegate_stub_; - scoped_ptr<DebuggerAgentImpl> debugger_agent_impl_; - scoped_ptr<DomAgentImpl> dom_agent_impl_; - scoped_ptr<NetAgentImpl> net_agent_impl_; + OwnPtr<DebuggerAgentDelegateStub> debugger_agent_delegate_stub_; + OwnPtr<DomAgentDelegateStub> dom_agent_delegate_stub_; + OwnPtr<NetAgentDelegateStub> net_agent_delegate_stub_; + OwnPtr<ToolsAgentDelegateStub> tools_agent_delegate_stub_; + OwnPtr<DebuggerAgentImpl> debugger_agent_impl_; + OwnPtr<DomAgentImpl> dom_agent_impl_; + OwnPtr<NetAgentImpl> net_agent_impl_; bool attached_; DISALLOW_COPY_AND_ASSIGN(WebDevToolsAgentImpl); }; |