summaryrefslogtreecommitdiffstats
path: root/content/browser
diff options
context:
space:
mode:
authormarshall@chromium.org <marshall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-25 20:06:51 +0000
committermarshall@chromium.org <marshall@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-25 20:06:51 +0000
commit0c30f204c08416d146c19a3f72e45f4b216092ac (patch)
treefb88c1061a5230d25db6917db4e1b4b28bde0cde /content/browser
parentb82c42c45ee1b113377a2800b36d6e5e05b8b8e1 (diff)
downloadchromium_src-0c30f204c08416d146c19a3f72e45f4b216092ac.zip
chromium_src-0c30f204c08416d146c19a3f72e45f4b216092ac.tar.gz
chromium_src-0c30f204c08416d146c19a3f72e45f4b216092ac.tar.bz2
Allow customization of remote debugger URL targets. Add a new DevToolsHttpHandler::RenderViewHostBinding interface to allow customizable mapping of page identifiers to/from RenderViewHost instances.
BUG=124395 TEST=DevTools still works Review URL: http://codereview.chromium.org/10169043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133962 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r--content/browser/debugger/devtools_http_handler_impl.cc88
-rw-r--r--content/browser/debugger/devtools_http_handler_impl.h10
2 files changed, 58 insertions, 40 deletions
diff --git a/content/browser/debugger/devtools_http_handler_impl.cc b/content/browser/debugger/devtools_http_handler_impl.cc
index 2a5ac67..bbe45a4 100644
--- a/content/browser/debugger/devtools_http_handler_impl.cc
+++ b/content/browser/debugger/devtools_http_handler_impl.cc
@@ -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 @@ const int kBufferSize = 16 * 1024;
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 {
+ size_t 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 @@ void DevToolsHttpHandlerImpl::Stop() {
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 @@ void DevToolsHttpHandlerImpl::OnClose(int connection_id) {
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 @@ bool DevToolsHttpHandlerImpl::SortPageListByTime(const PageInfo& info1,
}
DevToolsHttpHandlerImpl::PageList DevToolsHttpHandlerImpl::GeneratePageList() {
- ResetRenderViewHostBinding();
PageList page_list;
for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
!it.IsAtEnd(); it.Advance()) {
@@ -313,7 +350,7 @@ DevToolsHttpHandlerImpl::PageList DevToolsHttpHandlerImpl::GeneratePageList() {
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 @@ void DevToolsHttpHandlerImpl::OnJsonRequestUI(
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 @@ void DevToolsHttpHandlerImpl::OnJsonRequestUI(
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 @@ void DevToolsHttpHandlerImpl::OnWebSocketRequestUI(
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);
+ std::string page_id = request.path.substr(prefix.length());
+ RenderViewHost* rvh = binding_->ForIdentifier(page_id);
if (!rvh) {
Send500(connection_id, "No such target id: " + page_id);
return;
@@ -510,6 +541,9 @@ DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl(
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 @@ void DevToolsHttpHandlerImpl::AcceptWebSocket(
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
diff --git a/content/browser/debugger/devtools_http_handler_impl.h b/content/browser/debugger/devtools_http_handler_impl.h
index 30148a4..9cf3e9b 100644
--- a/content/browser/debugger/devtools_http_handler_impl.h
+++ b/content/browser/debugger/devtools_http_handler_impl.h
@@ -15,6 +15,7 @@
#include "base/memory/scoped_ptr.h"
#include "content/common/content_export.h"
#include "content/public/browser/devtools_http_handler.h"
+#include "content/public/browser/devtools_http_handler_delegate.h"
#include "net/server/http_server.h"
#include "net/url_request/url_request.h"
@@ -50,6 +51,8 @@ class DevToolsHttpHandlerImpl
// DevToolsHttpHandler implementation.
virtual void Stop() OVERRIDE;
+ virtual void SetRenderViewHostBinding(
+ RenderViewHostBinding* binding) OVERRIDE;
// net::HttpServer::Delegate implementation.
virtual void OnHttpRequest(int connection_id,
@@ -89,9 +92,6 @@ class DevToolsHttpHandlerImpl
const std::string& message);
void AcceptWebSocket(int connection_id,
const net::HttpServerRequestInfo& request);
- size_t BindRenderViewHost(RenderViewHost* rvh);
- RenderViewHost* GetBoundRenderViewHost(size_t id);
- void ResetRenderViewHostBinding();
std::string ip_;
int port_;
@@ -111,8 +111,8 @@ class DevToolsHttpHandlerImpl
ConnectionToClientHostMap connection_to_client_host_ui_;
net::URLRequestContextGetter* request_context_getter_;
scoped_ptr<DevToolsHttpHandlerDelegate> delegate_;
- typedef std::pair<int, int> Target;
- std::vector<Target> targets_;
+ RenderViewHostBinding* binding_;
+ scoped_ptr<RenderViewHostBinding> default_binding_;
DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandlerImpl);
};