Index: chrome/browser/extensions/api/debugger/debugger_api.cc |
diff --git a/chrome/browser/extensions/api/debugger/debugger_api.cc b/chrome/browser/extensions/api/debugger/debugger_api.cc |
index 9d1da2c6de3a6153cb44d712bc9bf94fc3d9b800..2ad6dcb7855459f5b1d337aa608882067a351021 100644 |
--- a/chrome/browser/extensions/api/debugger/debugger_api.cc |
+++ b/chrome/browser/extensions/api/debugger/debugger_api.cc |
@@ -34,6 +34,7 @@ |
#include "content/public/browser/devtools_agent_host.h" |
#include "content/public/browser/devtools_client_host.h" |
#include "content/public/browser/devtools_manager.h" |
+#include "content/public/browser/devtools_target_list.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/notification_source.h" |
#include "content/public/browser/render_process_host.h" |
@@ -50,6 +51,7 @@ |
using content::DevToolsAgentHost; |
using content::DevToolsClientHost; |
using content::DevToolsManager; |
+using content::DevToolsTargetList; |
using content::RenderProcessHost; |
using content::RenderViewHost; |
using content::RenderWidgetHost; |
@@ -183,6 +185,49 @@ class AttachedClientHosts { |
std::set<DevToolsClientHost*> client_hosts_; |
}; |
+static extensions::ExtensionHost* GetExtensionBackgroundHost( |
+ WebContents* web_contents) { |
+ Profile* profile = |
+ Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
+ if (!profile) |
+ return NULL; |
+ |
+ extensions::ExtensionHost* extension_host = |
+ extensions::ExtensionSystem::Get(profile)->process_manager()-> |
+ GetBackgroundHostForExtension(web_contents->GetURL().host()); |
+ |
+ if (extension_host && extension_host->host_contents() == web_contents) |
+ return extension_host; |
+ |
+ return NULL; |
+} |
+ |
+static base::DictionaryValue* SerializeTargetInfo(DevToolsAgentHost* agent) { |
+ base::DictionaryValue* dictionary = new base::DictionaryValue; |
+ |
+ dictionary->SetString("id", |
+ DevToolsTargetList::GetInstance()->GetIdentifier(agent)); |
+ |
+ WebContents* web_contents = |
+ WebContents::FromRenderViewHost(agent->GetRenderViewHost()); |
+ extensions::ExtensionHost* extension_host = |
+ GetExtensionBackgroundHost(web_contents); |
+ if (extension_host) { |
+ dictionary->SetString("type", "extension"); |
pfeldman
2013/03/01 08:49:30
So remote debugging won't know that it is extensio
Vladislav Kaznacheev
2013/03/01 12:58:35
When I was adding 'type' to the remote debugging p
|
+ dictionary->SetString("title", extension_host->extension()->name()); |
+ } else { |
+ dictionary->SetString("type", "page"); |
+ dictionary->SetString("title", agent->title()); |
+ } |
+ |
+ dictionary->SetBoolean("attached", agent->attached()); |
+ dictionary->SetString("url", agent->url().spec()); |
+ dictionary->SetString("thumbnailUrl", agent->thumbnail_url().spec()); |
+ dictionary->SetString("faviconUrl", agent->favicon_url().spec()); |
+ |
+ return dictionary; |
+} |
+ |
} // namespace |
static void CopyDebuggee(Debuggee & dst, const Debuggee& src) { |
@@ -190,6 +235,8 @@ static void CopyDebuggee(Debuggee & dst, const Debuggee& src) { |
dst.tab_id.reset(new int(*src.tab_id)); |
if (src.extension_id) |
dst.extension_id.reset(new std::string(*src.extension_id)); |
+ if (src.target_id) |
+ dst.target_id.reset(new std::string(*src.target_id)); |
} |
ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( |
@@ -431,10 +478,14 @@ void DebuggerFunction::FormatErrorMessage(const std::string& format) { |
format, |
debuggee_.tab_id ? |
keys::kTabTargetType : |
- keys::kExtensionTargetType, |
+ debuggee_.extension_id ? |
+ keys::kExtensionTargetType : |
+ keys::kOpaqueTargetType, |
debuggee_.tab_id ? |
base::IntToString(*debuggee_.tab_id) : |
- *debuggee_.extension_id); |
+ debuggee_.extension_id ? |
+ *debuggee_.extension_id : |
+ *debuggee_.target_id); |
} |
bool DebuggerFunction::InitWebContents() { |
@@ -483,6 +534,27 @@ bool DebuggerFunction::InitWebContents() { |
return false; |
} |
+ if (debuggee_.target_id) { |
+ DevToolsAgentHost* agent_host = |
+ DevToolsTargetList::GetInstance()->ForIdentifier(*debuggee_.target_id); |
+ if (agent_host) { |
+ contents_ = WebContents::FromRenderViewHost( |
+ agent_host->GetRenderViewHost()); |
+ |
+ if (GetExtensionBackgroundHost(contents_) && |
+ !CommandLine::ForCurrentProcess()-> |
+ HasSwitch(switches::kSilentDebuggerExtensionAPI)) { |
+ error_ = ErrorUtils::FormatErrorMessage( |
+ keys::kSilentDebuggingRequired, |
+ switches::kSilentDebuggerExtensionAPI); |
+ return false; |
+ } |
+ return true; |
+ } |
+ FormatErrorMessage(keys::kNoTargetError); |
+ return false; |
+ } |
+ |
error_ = keys::kInvalidTargetError; |
return false; |
} |
@@ -592,3 +664,22 @@ void DebuggerSendCommandFunction::SendResponseBody( |
results_ = SendCommand::Results::Create(result); |
SendResponse(true); |
} |
+ |
+DebuggerGetTargetsFunction::DebuggerGetTargetsFunction() {} |
+ |
+DebuggerGetTargetsFunction::~DebuggerGetTargetsFunction() {} |
+ |
+bool DebuggerGetTargetsFunction::RunImpl() { |
+ base::ListValue* results_list = new ListValue(); |
+ |
+ DevToolsTargetList::AgentsMap& agents_map = |
+ DevToolsTargetList::GetInstance()->GetAgentsMap(); |
+ |
+ for (DevToolsTargetList::iterator i = agents_map.begin(); |
+ i != agents_map.end(); ++i) |
+ results_list->Append(SerializeTargetInfo(i->second)); |
+ |
+ SetResult(results_list); |
+ SendResponse(true); |
+ return true; |
+} |