| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Implements the Chrome Extensions Debugger API. | 5 // Implements the Chrome Extensions Debugger API. |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_debugger_api.h" | 7 #include "chrome/browser/extensions/extension_debugger_api.h" |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 | 11 |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/extensions/extension_debugger_api_constants.h" | 17 #include "chrome/browser/extensions/extension_debugger_api_constants.h" |
| 18 #include "chrome/browser/extensions/extension_event_router.h" | 18 #include "chrome/browser/extensions/extension_event_router.h" |
| 19 #include "chrome/browser/extensions/extension_tab_util.h" | 19 #include "chrome/browser/extensions/extension_tab_util.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 24 #include "chrome/common/extensions/extension_error_utils.h" | 24 #include "chrome/common/extensions/extension_error_utils.h" |
| 25 #include "content/browser/debugger/devtools_client_host.h" | 25 #include "content/browser/debugger/devtools_client_host.h" |
| 26 #include "content/browser/debugger/devtools_manager.h" | 26 #include "content/public/browser/devtools/devtools_agent_host_registry.h" |
| 27 #include "content/public/browser/devtools/devtools_manager.h" |
| 27 #include "content/browser/tab_contents/tab_contents.h" | 28 #include "content/browser/tab_contents/tab_contents.h" |
| 28 #include "content/common/devtools_messages.h" | 29 #include "content/common/devtools_messages.h" |
| 29 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
| 30 #include "webkit/glue/webkit_glue.h" | 31 #include "webkit/glue/webkit_glue.h" |
| 31 | 32 |
| 33 using content::DevToolsAgentHostRegistry; |
| 34 using content::DevToolsManager; |
| 35 |
| 32 namespace keys = extension_debugger_api_constants; | 36 namespace keys = extension_debugger_api_constants; |
| 33 | 37 |
| 34 class ExtensionDevToolsClientHost : public DevToolsClientHost, | 38 class ExtensionDevToolsClientHost : public DevToolsClientHost, |
| 35 public content::NotificationObserver { | 39 public content::NotificationObserver { |
| 36 public: | 40 public: |
| 37 ExtensionDevToolsClientHost(TabContents* tab_contents, | 41 ExtensionDevToolsClientHost(TabContents* tab_contents, |
| 38 const std::string& extension_id, | 42 const std::string& extension_id, |
| 39 int tab_id); | 43 int tab_id); |
| 40 | 44 |
| 41 ~ExtensionDevToolsClientHost(); | 45 ~ExtensionDevToolsClientHost(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 95 |
| 92 void Add(ExtensionDevToolsClientHost* client_host) { | 96 void Add(ExtensionDevToolsClientHost* client_host) { |
| 93 client_hosts_.insert(client_host); | 97 client_hosts_.insert(client_host); |
| 94 } | 98 } |
| 95 | 99 |
| 96 void Remove(ExtensionDevToolsClientHost* client_host) { | 100 void Remove(ExtensionDevToolsClientHost* client_host) { |
| 97 client_hosts_.erase(client_host); | 101 client_hosts_.erase(client_host); |
| 98 } | 102 } |
| 99 | 103 |
| 100 ExtensionDevToolsClientHost* Lookup(RenderViewHost* rvh) { | 104 ExtensionDevToolsClientHost* Lookup(RenderViewHost* rvh) { |
| 105 DevToolsAgentHost* agent = |
| 106 DevToolsAgentHostRegistry::FindDevToolsAgentHost(rvh); |
| 107 if (!agent) |
| 108 return NULL; |
| 101 DevToolsClientHost* client_host = | 109 DevToolsClientHost* client_host = |
| 102 DevToolsManager::GetInstance()->GetDevToolsClientHostFor(rvh); | 110 DevToolsManager::GetInstance()->GetDevToolsClientHostFor(agent); |
| 103 std::set<DevToolsClientHost*>::iterator it = | 111 std::set<DevToolsClientHost*>::iterator it = |
| 104 client_hosts_.find(client_host); | 112 client_hosts_.find(client_host); |
| 105 if (it == client_hosts_.end()) | 113 if (it == client_hosts_.end()) |
| 106 return NULL; | 114 return NULL; |
| 107 return static_cast<ExtensionDevToolsClientHost*>(client_host); | 115 return static_cast<ExtensionDevToolsClientHost*>(client_host); |
| 108 } | 116 } |
| 109 | 117 |
| 110 private: | 118 private: |
| 111 std::set<DevToolsClientHost*> client_hosts_; | 119 std::set<DevToolsClientHost*> client_hosts_; |
| 112 }; | 120 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 123 last_request_id_(0) { | 131 last_request_id_(0) { |
| 124 AttachedClientHosts::GetInstance()->Add(this); | 132 AttachedClientHosts::GetInstance()->Add(this); |
| 125 | 133 |
| 126 // Detach from debugger when extension unloads. | 134 // Detach from debugger when extension unloads. |
| 127 Profile* profile = | 135 Profile* profile = |
| 128 Profile::FromBrowserContext(tab_contents_->browser_context()); | 136 Profile::FromBrowserContext(tab_contents_->browser_context()); |
| 129 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 137 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 130 content::Source<Profile>(profile)); | 138 content::Source<Profile>(profile)); |
| 131 | 139 |
| 132 // Attach to debugger and tell it we are ready. | 140 // Attach to debugger and tell it we are ready. |
| 133 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 141 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 134 tab_contents_->render_view_host(), | 142 tab_contents_->render_view_host()); |
| 135 this); | 143 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); |
| 136 DevToolsManager::GetInstance()->ForwardToDevToolsAgent( | 144 DevToolsManager::GetInstance()->ForwardToDevToolsAgent( |
| 137 this, | 145 this, |
| 138 DevToolsAgentMsg_FrontendLoaded(MSG_ROUTING_NONE)); | 146 DevToolsAgentMsg_FrontendLoaded(MSG_ROUTING_NONE)); |
| 139 } | 147 } |
| 140 | 148 |
| 141 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { | 149 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { |
| 142 AttachedClientHosts::GetInstance()->Remove(this); | 150 AttachedClientHosts::GetInstance()->Remove(this); |
| 143 } | 151 } |
| 144 | 152 |
| 145 bool ExtensionDevToolsClientHost::MatchesContentsAndExtensionId( | 153 bool ExtensionDevToolsClientHost::MatchesContentsAndExtensionId( |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 std::string version; | 318 std::string version; |
| 311 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &version)); | 319 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &version)); |
| 312 | 320 |
| 313 if (!webkit_glue::IsInspectorProtocolVersionSupported(version)) { | 321 if (!webkit_glue::IsInspectorProtocolVersionSupported(version)) { |
| 314 error_ = ExtensionErrorUtils::FormatErrorMessage( | 322 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 315 keys::kProtocolVersionNotSupportedError, | 323 keys::kProtocolVersionNotSupportedError, |
| 316 version); | 324 version); |
| 317 return false; | 325 return false; |
| 318 } | 326 } |
| 319 | 327 |
| 328 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 329 contents_->render_view_host()); |
| 320 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> | 330 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> |
| 321 GetDevToolsClientHostFor(contents_->render_view_host()); | 331 GetDevToolsClientHostFor(agent); |
| 322 | 332 |
| 323 if (client_host != NULL) { | 333 if (client_host != NULL) { |
| 324 error_ = ExtensionErrorUtils::FormatErrorMessage( | 334 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 325 keys::kAlreadyAttachedError, | 335 keys::kAlreadyAttachedError, |
| 326 base::IntToString(tab_id_)); | 336 base::IntToString(tab_id_)); |
| 327 return false; | 337 return false; |
| 328 } | 338 } |
| 329 | 339 |
| 330 new ExtensionDevToolsClientHost(contents_, GetExtension()->id(), tab_id_); | 340 new ExtensionDevToolsClientHost(contents_, GetExtension()->id(), tab_id_); |
| 331 SendResponse(true); | 341 SendResponse(true); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 return; | 384 return; |
| 375 } | 385 } |
| 376 | 386 |
| 377 Value* result_body; | 387 Value* result_body; |
| 378 if (dictionary->Get("result", &result_body)) | 388 if (dictionary->Get("result", &result_body)) |
| 379 result_.reset(result_body->DeepCopy()); | 389 result_.reset(result_body->DeepCopy()); |
| 380 else | 390 else |
| 381 result_.reset(new DictionaryValue()); | 391 result_.reset(new DictionaryValue()); |
| 382 SendResponse(true); | 392 SendResponse(true); |
| 383 } | 393 } |
| OLD | NEW |