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,43 @@ |
namespace { |
+class DevToolsDefaultBindingHandler |
+ : public DevToolsHttpHandlerDelegate::BindingHandler { |
+ public: |
+ DevToolsDefaultBindingHandler() { |
+ } |
+ |
+ virtual std::string GetRenderViewHostIdentifier( |
+ RenderViewHost* rvh) OVERRIDE { |
+ Target target = std::make_pair(rvh->GetProcess()->GetID(), |
+ rvh->GetRoutingID()); |
+ targets_.push_back(target); |
+ size_t index = targets_.size() - 1; |
+ return base::StringPrintf("%lu", index); |
pfeldman
2012/04/25 05:45:15
Nit: it might be a good time to migrate to the "<p
Marshall
2012/04/25 15:14:57
Done.
|
+ } |
+ |
+ virtual RenderViewHost* GetRenderViewHostBinding( |
+ const std::string& identifier) OVERRIDE { |
+ size_t index; |
+ if (!base::StringToSizeT(identifier, &index)) |
+ return NULL; |
+ if (index >= targets_.size()) |
+ return NULL; |
+ |
+ return RenderViewHost::FromID(targets_[index].first, |
+ targets_[index].second); |
+ } |
+ |
+ virtual void ResetRenderViewHostBinding() OVERRIDE { |
+ targets_.clear(); |
+ } |
+ |
+ private: |
+ typedef std::pair<int, int> Target; |
+ std::vector<Target> targets_; |
+}; |
+ |
+ |
// An internal implementation of DevToolsClientHost that delegates |
// messages sent for DevToolsClient to a DebuggerShell instance. |
class DevToolsClientHostImpl : public DevToolsClientHost { |
@@ -262,14 +300,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 +321,7 @@ |
} |
DevToolsHttpHandlerImpl::PageList DevToolsHttpHandlerImpl::GeneratePageList() { |
- ResetRenderViewHostBinding(); |
+ binding_handler_->ResetRenderViewHostBinding(); |
PageList page_list; |
for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
!it.IsAtEnd(); it.Advance()) { |
@@ -313,7 +349,7 @@ |
DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> |
GetDevToolsClientHostFor(agent); |
PageInfo page_info; |
- page_info.id = BindRenderViewHost(host); |
+ page_info.id = binding_handler_->GetRenderViewHostIdentifier(host); |
page_info.attached = client_host != NULL; |
page_info.url = host_delegate->GetURL().spec(); |
@@ -345,7 +381,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 +389,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 +418,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_handler_->GetRenderViewHostBinding(page_id); |
if (!rvh) { |
Send500(connection_id, "No such target id: " + page_id); |
return; |
@@ -510,6 +540,10 @@ |
if (overridden_frontend_url_.empty()) |
overridden_frontend_url_ = "/devtools/devtools.html"; |
+ binding_handler_.reset(delegate_->GetBindingHandler()); |
+ if (!binding_handler_.get()) |
+ binding_handler_.reset(new DevToolsDefaultBindingHandler); |
+ |
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 |