Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1039)

Unified Diff: content/browser/debugger/devtools_http_handler_impl.cc

Issue 10169043: Allow customization of remote debugger URL targets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/debugger/devtools_http_handler_impl.cc
===================================================================
--- content/browser/debugger/devtools_http_handler_impl.cc (revision 133430)
+++ content/browser/debugger/devtools_http_handler_impl.cc (working copy)
@@ -4,6 +4,7 @@
#include "content/browser/debugger/devtools_http_handler_impl.h"
+#include <algorithm>
#include <utility>
#include "base/bind.h"
@@ -44,6 +45,37 @@
namespace {
+class DevToolsDefaultBindingHandler
+ : public DevToolsHttpHandler::RenderViewHostBinding {
+ public:
+ DevToolsDefaultBindingHandler() {
+ }
+
+ virtual std::string GetIdentifier(RenderViewHost* rvh) OVERRIDE {
+ int process_id = rvh->GetProcess()->GetID();
+ int routing_id = rvh->GetRoutingID();
+ return base::StringPrintf("%d_%d", process_id, routing_id);
+ }
+
+ virtual RenderViewHost* ForIdentifier(
+ const std::string& identifier) OVERRIDE {
+ int pos = identifier.find("_");
+ if (pos == std::string::npos)
+ return NULL;
+
+ int process_id;
+ if (!base::StringToInt(identifier.substr(0, pos), &process_id))
+ return NULL;
+
+ int routing_id;
+ if (!base::StringToInt(identifier.substr(pos+1), &routing_id))
+ return NULL;
+
+ return RenderViewHost::FromID(process_id, routing_id);
+ }
+};
+
+
// An internal implementation of DevToolsClientHost that delegates
// messages sent for DevToolsClient to a DebuggerShell instance.
class DevToolsClientHostImpl : public DevToolsClientHost {
@@ -128,6 +160,14 @@
base::Bind(&DevToolsHttpHandlerImpl::TeardownAndRelease, this));
}
+void DevToolsHttpHandlerImpl::SetRenderViewHostBinding(
+ RenderViewHostBinding* binding) {
+ if (binding)
+ binding_ = binding;
+ else
+ binding_ = default_binding_.get();
+}
+
static std::string PathWithoutParams(const std::string& path) {
size_t query_position = path.find("?");
if (query_position != std::string::npos)
@@ -262,14 +302,12 @@
connection_id));
}
-struct DevToolsHttpHandlerImpl::PageInfo
-{
+struct DevToolsHttpHandlerImpl::PageInfo {
PageInfo()
- : id(0),
- attached(false) {
+ : attached(false) {
}
- int id;
+ std::string id;
std::string url;
bool attached;
std::string title;
@@ -285,7 +323,6 @@
}
DevToolsHttpHandlerImpl::PageList DevToolsHttpHandlerImpl::GeneratePageList() {
- ResetRenderViewHostBinding();
PageList page_list;
for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
!it.IsAtEnd(); it.Advance()) {
@@ -313,7 +350,7 @@
DevToolsClientHost* client_host = DevToolsManager::GetInstance()->
GetDevToolsClientHostFor(agent);
PageInfo page_info;
- page_info.id = BindRenderViewHost(host);
+ page_info.id = binding_->GetIdentifier(host);
page_info.attached = client_host != NULL;
page_info.url = host_delegate->GetURL().spec();
@@ -345,7 +382,6 @@
std::string host = info.headers["Host"];
for (PageList::iterator i = page_list.begin();
i != page_list.end(); ++i) {
-
DictionaryValue* page_info = new DictionaryValue;
json_pages_list.Append(page_info);
page_info->SetString("title", i->title);
@@ -354,15 +390,15 @@
page_info->SetString("faviconUrl", i->favicon_url);
if (!i->attached) {
page_info->SetString("webSocketDebuggerUrl",
- base::StringPrintf("ws://%s/devtools/page/%d",
+ base::StringPrintf("ws://%s/devtools/page/%s",
host.c_str(),
- i->id));
+ i->id.c_str()));
std::string devtools_frontend_url = base::StringPrintf(
- "%s%sws=%s/devtools/page/%d",
+ "%s%sws=%s/devtools/page/%s",
overridden_frontend_url_.c_str(),
overridden_frontend_url_.find("?") == std::string::npos ? "?" : "&",
host.c_str(),
- i->id);
+ i->id.c_str());
page_info->SetString("devtoolsFrontendUrl", devtools_frontend_url);
}
}
@@ -383,14 +419,9 @@
Send404(connection_id);
return;
}
+
std::string page_id = request.path.substr(prefix.length());
- int id = 0;
- if (!base::StringToInt(page_id, &id)) {
- Send500(connection_id, "Invalid page id: " + page_id);
- return;
- }
-
- RenderViewHost* rvh = GetBoundRenderViewHost(id);
+ RenderViewHost* rvh = binding_->ForIdentifier(page_id);
if (!rvh) {
Send500(connection_id, "No such target id: " + page_id);
return;
@@ -510,6 +541,9 @@
if (overridden_frontend_url_.empty())
overridden_frontend_url_ = "/devtools/devtools.html";
+ default_binding_.reset(new DevToolsDefaultBindingHandler);
+ binding_ = default_binding_.get();
+
AddRef();
}
@@ -589,20 +623,4 @@
connection_id, request));
}
-size_t DevToolsHttpHandlerImpl::BindRenderViewHost(RenderViewHost* rvh) {
- Target target = std::make_pair(rvh->GetProcess()->GetID(),
- rvh->GetRoutingID());
- targets_.push_back(target);
- return targets_.size() - 1;
-}
-
-RenderViewHost* DevToolsHttpHandlerImpl::GetBoundRenderViewHost(size_t id) {
- return RenderViewHost::FromID(targets_[id].first,
- targets_[id].second);
-}
-
-void DevToolsHttpHandlerImpl::ResetRenderViewHostBinding() {
- targets_.clear();
-}
-
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698