summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-09 16:09:43 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-09 16:09:43 +0000
commit90ca36995f2484d10a68115b798c10f51d70fca4 (patch)
treed69bfe14150a811ae5260b95127ab5c3a28f005a
parentc38aeeeb04c53a4d1c53673ec5575562d3bfe313 (diff)
downloadchromium_src-90ca36995f2484d10a68115b798c10f51d70fca4.zip
chromium_src-90ca36995f2484d10a68115b798c10f51d70fca4.tar.gz
chromium_src-90ca36995f2484d10a68115b798c10f51d70fca4.tar.bz2
DevTools: Cache resources before attach, hide agents behind the flag.
Review URL: http://codereview.chromium.org/65010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13423 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc1
-rw-r--r--chrome/renderer/devtools_agent.cc1
-rw-r--r--chrome/renderer/render_view.cc23
-rw-r--r--webkit/glue/devtools/js/net_agent.js19
-rw-r--r--webkit/glue/devtools/net_agent.h3
-rw-r--r--webkit/glue/devtools/net_agent_impl.cc84
-rw-r--r--webkit/glue/devtools/net_agent_impl.h23
-rw-r--r--webkit/glue/webdevtoolsagent_impl.cc10
-rw-r--r--webkit/glue/webview_impl.cc11
9 files changed, 112 insertions, 63 deletions
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index 2082c0c..141bf3e 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -270,6 +270,7 @@ bool BrowserRenderProcessHost::Init() {
switches::kEnableWebWorkers,
switches::kEnableStatsTable,
switches::kEnableExtensions,
+ switches::kEnableOutOfProcessDevTools,
};
for (size_t i = 0; i < arraysize(switch_names); ++i) {
diff --git a/chrome/renderer/devtools_agent.cc b/chrome/renderer/devtools_agent.cc
index 633203c..046b755 100644
--- a/chrome/renderer/devtools_agent.cc
+++ b/chrome/renderer/devtools_agent.cc
@@ -61,6 +61,7 @@ void DevToolsAgent::OnRpcMessage(const std::string& raw_msg) {
void DevToolsAgent::OnInspectElement(int x, int y) {
WebDevToolsAgent* web_agent = GetWebAgent();
if (web_agent) {
+ web_agent->Attach();
web_agent->InspectElement(x, y);
}
}
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index b4fc6d5..9cebf46 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -212,7 +212,8 @@ RenderView::~RenderView() {
}
render_thread_->RemoveFilter(debug_message_handler_);
- render_thread_->RemoveFilter(devtools_agent_filter_);
+ if (devtools_agent_filter_.get())
+ render_thread_->RemoveFilter(devtools_agent_filter_);
#ifdef CHROME_PERSONALIZATION
Personalization::CleanupRendererPersonalization(personalization_);
@@ -299,13 +300,19 @@ void RenderView::Init(gfx::NativeViewId parent_hwnd,
decrement_shared_popup_at_destruction_ = false;
}
- devtools_agent_.reset(new DevToolsAgent(routing_id, this));
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+
+ bool dev_tools_enabled = command_line.HasSwitch(
+ switches::kEnableOutOfProcessDevTools);
+ if (dev_tools_enabled)
+ devtools_agent_.reset(new DevToolsAgent(routing_id, this));
webwidget_ = WebView::Create(this, webkit_prefs);
- devtools_agent_filter_ = new DevToolsAgentFilter(
- webview()->GetWebDevToolsAgent(),
- routing_id);
+ if (dev_tools_enabled)
+ devtools_agent_filter_ = new DevToolsAgentFilter(
+ webview()->GetWebDevToolsAgent(),
+ routing_id);
#if defined(OS_LINUX)
// We have to enable ourselves as the editor delegate on linux so we can copy
@@ -334,7 +341,6 @@ void RenderView::Init(gfx::NativeViewId parent_hwnd,
host_window_ = parent_hwnd;
modal_dialog_event_.reset(modal_dialog_event);
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kDomAutomationController))
enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
disable_popup_blocking_ =
@@ -342,7 +348,8 @@ void RenderView::Init(gfx::NativeViewId parent_hwnd,
debug_message_handler_ = new DebugMessageHandler(this);
render_thread_->AddFilter(debug_message_handler_);
- render_thread_->AddFilter(devtools_agent_filter_);
+ if (dev_tools_enabled)
+ render_thread_->AddFilter(devtools_agent_filter_);
}
void RenderView::OnMessageReceived(const IPC::Message& message) {
@@ -353,7 +360,7 @@ void RenderView::OnMessageReceived(const IPC::Message& message) {
// If this is developer tools renderer intercept tools messages first.
if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
return;
- if (devtools_agent_->OnMessageReceived(message))
+ if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
return;
IPC_BEGIN_MESSAGE_MAP(RenderView, message)
diff --git a/webkit/glue/devtools/js/net_agent.js b/webkit/glue/devtools/js/net_agent.js
index 00b511c..64ef4a6 100644
--- a/webkit/glue/devtools/js/net_agent.js
+++ b/webkit/glue/devtools/js/net_agent.js
@@ -21,8 +21,6 @@ devtools.NetAgent = function() {
goog.bind(this.didReceiveResponse, this);
RemoteNetAgent.DidFinishLoading =
goog.bind(this.didFinishLoading, this);
- RemoteNetAgent.DidFailLoading =
- goog.bind(this.didFailLoading, this);
};
@@ -138,20 +136,5 @@ devtools.NetAgent.prototype.didFinishLoading = function(identifier, value) {
}
resource.endTime = value.endTime;
resource.finished = true;
- resource.failed = false;
-};
-
-
-/**
- * @see NetAgentDelegate.
- * {@inheritDoc}.
- */
-devtools.NetAgent.prototype.didFailLoading = function(identifier, value) {
- var resource = this.resources_[identifier];
- if (!resource) {
- return;
- }
- resource.endTime = value.endTime;
- resource.finished = false;
- resource.failed = true;
+ resource.failed = !!value.errorCode;
};
diff --git a/webkit/glue/devtools/net_agent.h b/webkit/glue/devtools/net_agent.h
index 87459f0..38db57d 100644
--- a/webkit/glue/devtools/net_agent.h
+++ b/webkit/glue/devtools/net_agent.h
@@ -31,9 +31,6 @@ DEFINE_RPC_CLASS(NetAgent, NET_AGENT_STRUCT)
errors */ \
METHOD2(DidFinishLoading, int /* identifier */, Value /* response */) \
\
- /* Notifies the delegate that resource loading has failed. */ \
- METHOD2(DidFailLoading, int /* identifier */, Value /* response */) \
- \
/* Response to the async call. */ \
METHOD2(GetResourceContentResult, int /* call_id */, std::string /* content */)
diff --git a/webkit/glue/devtools/net_agent_impl.cc b/webkit/glue/devtools/net_agent_impl.cc
index a34667f..5aba9bb 100644
--- a/webkit/glue/devtools/net_agent_impl.cc
+++ b/webkit/glue/devtools/net_agent_impl.cc
@@ -33,28 +33,47 @@ using namespace WebCore;
NetAgentImpl::NetAgentImpl(NetAgentDelegate* delegate)
: delegate_(delegate),
document_(NULL),
- last_cached_identifier_(-2) {
+ main_loader_(NULL),
+ last_cached_identifier_(-2),
+ attached_(false) {
}
NetAgentImpl::~NetAgentImpl() {
SetDocument(NULL);
- for (CachedResources::iterator it = pending_resources_.begin();
- it != pending_resources_.end(); ++it) {
- delete it->second;
- }
+ DidCommitMainResourceLoad();
+ deleteAllValues(pending_resources_);
pending_resources_.clear();
}
void NetAgentImpl::SetDocument(Document* doc) {
-// loaders_.clear();
document_ = doc;
}
+void NetAgentImpl::Attach() {
+ for (FinishedResources::iterator it = finished_resources_.begin();
+ it != finished_resources_.end(); ++it) {
+ delegate_->DidFinishLoading(it->first, *it->second);
+ }
+ attached_ = true;
+}
+
+void NetAgentImpl::Detach() {
+ attached_ = false;
+}
+
+void NetAgentImpl::DidCommitMainResourceLoad() {
+ for (FinishedResources::iterator it = finished_resources_.begin();
+ it != finished_resources_.end(); ++it) {
+ delete it->second;
+ }
+ finished_resources_.clear();
+ main_loader_ = NULL;
+}
+
void NetAgentImpl::AssignIdentifierToRequest(
DocumentLoader* loader,
int identifier,
const ResourceRequest& request) {
- loaders_.set(identifier, loader);
}
void NetAgentImpl::WillSendRequest(
@@ -72,18 +91,22 @@ void NetAgentImpl::WillSendRequest(
webkit_glue::StringToStdString(url.lastPathComponent()));
resource->Set(L"requestHeaders",
BuildValueForHeaders(request.httpHeaderFields()));
- delegate_->WillSendRequest(identifier, *resource);
pending_resources_.set(identifier, resource);
+
+ if (attached_) {
+ delegate_->WillSendRequest(identifier, *resource);
+ }
}
void NetAgentImpl::DidReceiveResponse(
DocumentLoader* loader,
int identifier,
const ResourceResponse &response) {
- KURL url = response.url();
if (!pending_resources_.contains(identifier)) {
return;
}
+
+ KURL url = response.url();
DictionaryValue* resource = pending_resources_.get(identifier);
resource->SetReal(L"responseReceivedTime", WTF::currentTime());
resource->SetString(L"url",
@@ -98,7 +121,9 @@ void NetAgentImpl::DidReceiveResponse(
resource->Set(L"responseHeaders",
BuildValueForHeaders(response.httpHeaderFields()));
- delegate_->DidReceiveResponse(identifier, *resource);
+ if (attached_) {
+ delegate_->DidReceiveResponse(identifier, *resource);
+ }
}
void NetAgentImpl::DidReceiveContentLength(
@@ -113,11 +138,31 @@ void NetAgentImpl::DidFinishLoading(
if (!pending_resources_.contains(identifier)) {
return;
}
+
+ // This is the first command being dispatched after
+ // DidCommitMainResourceLoad, we know that the first resource to be reported
+ // as loaded is main resource.
+ if (!main_loader_.get()) {
+ main_loader_ = loader;
+ }
+
DictionaryValue* resource = pending_resources_.get(identifier);
resource->SetReal(L"endTime", WTF::currentTime());
- delegate_->DidFinishLoading(identifier, *resource);
+
pending_resources_.remove(identifier);
- delete resource;
+ finished_resources_.append(std::make_pair(identifier, resource));
+
+ // 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) {
+ delete finished_resources_[i].second;
+ }
+ finished_resources_.remove(0, 50);
+ }
+
+ if (attached_) {
+ delegate_->DidFinishLoading(identifier, *resource);
+ }
}
void NetAgentImpl::DidFailLoading(
@@ -128,13 +173,10 @@ void NetAgentImpl::DidFailLoading(
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, *resource);
- pending_resources_.remove(identifier);
- delete resource;
+ DidFinishLoading(loader, identifier);
}
void NetAgentImpl::DidLoadResourceFromMemoryCache(
@@ -143,7 +185,6 @@ void NetAgentImpl::DidLoadResourceFromMemoryCache(
const ResourceResponse& response,
int length) {
int identifier = last_cached_identifier_--;
- loaders_.set(identifier, loader);
}
void NetAgentImpl::GetResourceContent(
@@ -153,16 +194,11 @@ void NetAgentImpl::GetResourceContent(
if (!document_) {
return;
}
- CachedLoaders::iterator it = loaders_.find(identifier);
- if (it == loaders_.end() || !it->second) {
- return;
- }
- RefPtr<DocumentLoader> loader = it->second;
String source;
- if (url == loader->requestURL()) {
- RefPtr<SharedBuffer> buffer = loader->mainResourceData();
+ if (main_loader_.get() && main_loader_->requestURL() == url) {
+ RefPtr<SharedBuffer> buffer = main_loader_->mainResourceData();
String text_encoding_name = document_->inputEncoding();
if (buffer) {
WebCore::TextEncoding encoding(text_encoding_name);
diff --git a/webkit/glue/devtools/net_agent_impl.h b/webkit/glue/devtools/net_agent_impl.h
index 94f5e20..893c4b5 100644
--- a/webkit/glue/devtools/net_agent_impl.h
+++ b/webkit/glue/devtools/net_agent_impl.h
@@ -5,9 +5,12 @@
#ifndef WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_
#define WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_
+#include <utility>
+
#include <wtf/HashMap.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
#include "webkit/glue/devtools/net_agent.h"
@@ -35,6 +38,15 @@ class NetAgentImpl : public NetAgent {
// Initializes net agent with the given document.
void SetDocument(WebCore::Document* document);
+ // Tells agent it has attached client.
+ void Attach();
+
+ // Tells agent it has no attached client.
+ void Detach();
+
+ // Tells agent that new load has been committed.
+ void DidCommitMainResourceLoad();
+
// NetAgent implementation.
void GetResourceContent(int call_id, int identifier,
const WebCore::String& request_url);
@@ -73,13 +85,14 @@ class NetAgentImpl : public NetAgent {
NetAgentDelegate* delegate_;
WebCore::Document* document_;
+ RefPtr<WebCore::DocumentLoader> main_loader_;
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_;
+ WTF::UnsignedWithZeroKeyHashTraits<int> > ResourcesMap;
+ typedef Vector<std::pair<int, DictionaryValue*> > FinishedResources;
+ ResourcesMap pending_resources_;
+ FinishedResources finished_resources_;
int last_cached_identifier_;
+ bool attached_;
DISALLOW_COPY_AND_ASSIGN(NetAgentImpl);
};
diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc
index 4a6201f..5602f45 100644
--- a/webkit/glue/webdevtoolsagent_impl.cc
+++ b/webkit/glue/webdevtoolsagent_impl.cc
@@ -49,6 +49,9 @@ WebDevToolsAgentImpl::WebDevToolsAgentImpl(
dom_agent_delegate_stub_.set(new DomAgentDelegateStub(this));
net_agent_delegate_stub_.set(new NetAgentDelegateStub(this));
tools_agent_delegate_stub_.set(new ToolsAgentDelegateStub(this));
+
+ // Sniff for requests from the beginning, do not wait for attach.
+ net_agent_impl_.set(new NetAgentImpl(net_agent_delegate_stub_.get()));
}
WebDevToolsAgentImpl::~WebDevToolsAgentImpl() {
@@ -63,7 +66,6 @@ void WebDevToolsAgentImpl::Attach() {
debugger_agent_delegate_stub_.get(),
this));
dom_agent_impl_.set(new DomAgentImpl(dom_agent_delegate_stub_.get()));
- net_agent_impl_.set(new NetAgentImpl(net_agent_delegate_stub_.get()));
// We are potentially attaching to the running page -> init agents with
// Document if any.
@@ -84,13 +86,14 @@ void WebDevToolsAgentImpl::Attach() {
it->line_no);
}
+ net_agent_impl_->Attach();
attached_ = true;
}
void WebDevToolsAgentImpl::Detach() {
debugger_agent_impl_.set(NULL);
dom_agent_impl_.set(NULL);
- net_agent_impl_.set(NULL);
+ net_agent_impl_->Detach();
attached_ = false;
}
@@ -116,6 +119,9 @@ void WebDevToolsAgentImpl::DidCommitLoadForFrame(
WebViewImpl* webview,
WebFrame* frame,
bool is_new_navigation) {
+ if (webview->GetMainFrame() == frame) {
+ net_agent_impl_->DidCommitMainResourceLoad();
+ }
if (!attached_) {
return;
}
diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc
index c98ac6f..78ae88b 100644
--- a/webkit/glue/webview_impl.cc
+++ b/webkit/glue/webview_impl.cc
@@ -332,9 +332,14 @@ WebView* WebView::Create(WebViewDelegate* delegate,
// Set the delegate after initializing the main frame, to avoid trying to
// respond to notifications before we're fully initialized.
instance->delegate_ = delegate;
- instance->devtools_agent_.reset(
- new WebDevToolsAgentImpl(instance,
- delegate->GetWebDevToolsAgentDelegate()));
+
+ WebDevToolsAgentDelegate* tools_delegate =
+ delegate->GetWebDevToolsAgentDelegate();
+ if (tools_delegate) {
+ instance->devtools_agent_.reset(
+ new WebDevToolsAgentImpl(instance, tools_delegate));
+ }
+
// Restrict the access to the local file system
// (see WebView.mm WebView::_commonInitializationWithFrameName).
FrameLoader::setLocalLoadPolicy(