From 4cc874f542d307a0c24469ffc8e89ed4e3650eb6 Mon Sep 17 00:00:00 2001 From: "pfeldman@chromium.org" Date: Mon, 4 May 2009 09:22:32 +0000 Subject: DevTools: Support XmlHTTPRequests sniffing. Review URL: http://codereview.chromium.org/100262 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15198 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/glue/devtools/net_agent_impl.cc | 13 ++++++++++++- webkit/glue/devtools/net_agent_impl.h | 9 +++++++++ webkit/glue/webframeloaderclient_impl.cc | 9 +++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) (limited to 'webkit/glue') diff --git a/webkit/glue/devtools/net_agent_impl.cc b/webkit/glue/devtools/net_agent_impl.cc index 5aba9bb..5b04662 100644 --- a/webkit/glue/devtools/net_agent_impl.cc +++ b/webkit/glue/devtools/net_agent_impl.cc @@ -18,6 +18,7 @@ #include "ResourceError.h" #include "ResourceRequest.h" #include "ResourceResponse.h" +#include "ScriptString.h" #include "TextEncoding.h" #include #undef LOG @@ -155,6 +156,7 @@ void NetAgentImpl::DidFinishLoading( // Start removing resources from the cache once there are too many of them. if (finished_resources_.size() > 200) { for (int i = 0; i < 50; ++i) { + xml_http_sources_.remove(finished_resources_[i].first); delete finished_resources_[i].second; } finished_resources_.remove(0, 50); @@ -187,6 +189,12 @@ void NetAgentImpl::DidLoadResourceFromMemoryCache( int identifier = last_cached_identifier_--; } +void NetAgentImpl::DidLoadResourceByXMLHttpRequest( + int identifier, + const WebCore::ScriptString& source) { + xml_http_sources_.set(identifier, source); +} + void NetAgentImpl::GetResourceContent( int call_id, int identifier, @@ -197,7 +205,10 @@ void NetAgentImpl::GetResourceContent( String source; - if (main_loader_.get() && main_loader_->requestURL() == url) { + WebCore::ScriptString script = xml_http_sources_.get(identifier); + if (!script.isNull()) { + source = String(script); + } else if (main_loader_.get() && main_loader_->requestURL() == url) { RefPtr buffer = main_loader_->mainResourceData(); String text_encoding_name = document_->inputEncoding(); if (buffer) { diff --git a/webkit/glue/devtools/net_agent_impl.h b/webkit/glue/devtools/net_agent_impl.h index 893c4b5..e1d882b 100644 --- a/webkit/glue/devtools/net_agent_impl.h +++ b/webkit/glue/devtools/net_agent_impl.h @@ -20,6 +20,7 @@ class DocumentLoader; class HTTPHeaderMap; class ResourceError; class ResourceResponse; +class ScriptString; class String; struct ResourceRequest; } @@ -78,6 +79,10 @@ class NetAgentImpl : public NetAgent { const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, int length); + void DidLoadResourceByXMLHttpRequest( + int identifier, + const WebCore::ScriptString& source); + private: // Serializes headers map into a value. @@ -89,8 +94,12 @@ class NetAgentImpl : public NetAgent { typedef HashMap::Hash, WTF::UnsignedWithZeroKeyHashTraits > ResourcesMap; typedef Vector > FinishedResources; + typedef HashMap::Hash, + WTF::UnsignedWithZeroKeyHashTraits > XmlHttpSources; + ResourcesMap pending_resources_; FinishedResources finished_resources_; + XmlHttpSources xml_http_sources_; int last_cached_identifier_; bool attached_; DISALLOW_COPY_AND_ASSIGN(NetAgentImpl); diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index 24843ba..b2cdae9 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -468,8 +468,13 @@ bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache( void WebFrameLoaderClient::dispatchDidLoadResourceByXMLHttpRequest( unsigned long identifier, - const ScriptString&) { - //TODO(pfeldman): Wire to net_agent. + const ScriptString& source) { + NetAgentImpl* net_agent = GetNetAgentImpl(); + if (net_agent) { + net_agent->DidLoadResourceByXMLHttpRequest( + identifier, + source); + } } void WebFrameLoaderClient::dispatchDidHandleOnloadEvents() { -- cgit v1.1