| 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/public/browser/devtools/devtools_agent_host_registry.h" |
| 26 #include "content/browser/debugger/devtools_manager.h" | 26 #include "content/public/browser/devtools/devtools_client_host.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::DevToolsAgentHost; |
| 34 using content::DevToolsAgentHostRegistry; |
| 35 using content::DevToolsClientHost; |
| 36 using content::DevToolsManager; |
| 37 |
| 32 namespace keys = extension_debugger_api_constants; | 38 namespace keys = extension_debugger_api_constants; |
| 33 | 39 |
| 34 class ExtensionDevToolsClientHost : public DevToolsClientHost, | 40 class ExtensionDevToolsClientHost : public DevToolsClientHost, |
| 35 public content::NotificationObserver { | 41 public content::NotificationObserver { |
| 36 public: | 42 public: |
| 37 ExtensionDevToolsClientHost(TabContents* tab_contents, | 43 ExtensionDevToolsClientHost(TabContents* tab_contents, |
| 38 const std::string& extension_id, | 44 const std::string& extension_id, |
| 39 int tab_id); | 45 int tab_id); |
| 40 | 46 |
| 41 ~ExtensionDevToolsClientHost(); | 47 ~ExtensionDevToolsClientHost(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 97 |
| 92 void Add(ExtensionDevToolsClientHost* client_host) { | 98 void Add(ExtensionDevToolsClientHost* client_host) { |
| 93 client_hosts_.insert(client_host); | 99 client_hosts_.insert(client_host); |
| 94 } | 100 } |
| 95 | 101 |
| 96 void Remove(ExtensionDevToolsClientHost* client_host) { | 102 void Remove(ExtensionDevToolsClientHost* client_host) { |
| 97 client_hosts_.erase(client_host); | 103 client_hosts_.erase(client_host); |
| 98 } | 104 } |
| 99 | 105 |
| 100 ExtensionDevToolsClientHost* Lookup(RenderViewHost* rvh) { | 106 ExtensionDevToolsClientHost* Lookup(RenderViewHost* rvh) { |
| 107 if (!DevToolsAgentHostRegistry::HasDevToolsAgentHost(rvh)) |
| 108 return NULL; |
| 109 DevToolsAgentHost* agent = |
| 110 DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh); |
| 101 DevToolsClientHost* client_host = | 111 DevToolsClientHost* client_host = |
| 102 DevToolsManager::GetInstance()->GetDevToolsClientHostFor(rvh); | 112 DevToolsManager::GetInstance()->GetDevToolsClientHostFor(agent); |
| 103 std::set<DevToolsClientHost*>::iterator it = | 113 std::set<DevToolsClientHost*>::iterator it = |
| 104 client_hosts_.find(client_host); | 114 client_hosts_.find(client_host); |
| 105 if (it == client_hosts_.end()) | 115 if (it == client_hosts_.end()) |
| 106 return NULL; | 116 return NULL; |
| 107 return static_cast<ExtensionDevToolsClientHost*>(client_host); | 117 return static_cast<ExtensionDevToolsClientHost*>(client_host); |
| 108 } | 118 } |
| 109 | 119 |
| 110 private: | 120 private: |
| 111 std::set<DevToolsClientHost*> client_hosts_; | 121 std::set<DevToolsClientHost*> client_hosts_; |
| 112 }; | 122 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 123 last_request_id_(0) { | 133 last_request_id_(0) { |
| 124 AttachedClientHosts::GetInstance()->Add(this); | 134 AttachedClientHosts::GetInstance()->Add(this); |
| 125 | 135 |
| 126 // Detach from debugger when extension unloads. | 136 // Detach from debugger when extension unloads. |
| 127 Profile* profile = | 137 Profile* profile = |
| 128 Profile::FromBrowserContext(tab_contents_->browser_context()); | 138 Profile::FromBrowserContext(tab_contents_->browser_context()); |
| 129 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 139 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 130 content::Source<Profile>(profile)); | 140 content::Source<Profile>(profile)); |
| 131 | 141 |
| 132 // Attach to debugger and tell it we are ready. | 142 // Attach to debugger and tell it we are ready. |
| 133 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 143 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 134 tab_contents_->render_view_host(), | 144 tab_contents_->render_view_host()); |
| 135 this); | 145 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); |
| 136 DevToolsManager::GetInstance()->ForwardToDevToolsAgent( | 146 DevToolsManager::GetInstance()->ForwardToDevToolsAgent( |
| 137 this, | 147 this, |
| 138 DevToolsAgentMsg_FrontendLoaded(MSG_ROUTING_NONE)); | 148 DevToolsAgentMsg_FrontendLoaded(MSG_ROUTING_NONE)); |
| 139 } | 149 } |
| 140 | 150 |
| 141 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { | 151 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { |
| 142 AttachedClientHosts::GetInstance()->Remove(this); | 152 AttachedClientHosts::GetInstance()->Remove(this); |
| 143 } | 153 } |
| 144 | 154 |
| 145 bool ExtensionDevToolsClientHost::MatchesContentsAndExtensionId( | 155 bool ExtensionDevToolsClientHost::MatchesContentsAndExtensionId( |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 std::string version; | 320 std::string version; |
| 311 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &version)); | 321 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &version)); |
| 312 | 322 |
| 313 if (!webkit_glue::IsInspectorProtocolVersionSupported(version)) { | 323 if (!webkit_glue::IsInspectorProtocolVersionSupported(version)) { |
| 314 error_ = ExtensionErrorUtils::FormatErrorMessage( | 324 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 315 keys::kProtocolVersionNotSupportedError, | 325 keys::kProtocolVersionNotSupportedError, |
| 316 version); | 326 version); |
| 317 return false; | 327 return false; |
| 318 } | 328 } |
| 319 | 329 |
| 330 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 331 contents_->render_view_host()); |
| 320 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> | 332 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> |
| 321 GetDevToolsClientHostFor(contents_->render_view_host()); | 333 GetDevToolsClientHostFor(agent); |
| 322 | 334 |
| 323 if (client_host != NULL) { | 335 if (client_host != NULL) { |
| 324 error_ = ExtensionErrorUtils::FormatErrorMessage( | 336 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 325 keys::kAlreadyAttachedError, | 337 keys::kAlreadyAttachedError, |
| 326 base::IntToString(tab_id_)); | 338 base::IntToString(tab_id_)); |
| 327 return false; | 339 return false; |
| 328 } | 340 } |
| 329 | 341 |
| 330 new ExtensionDevToolsClientHost(contents_, GetExtension()->id(), tab_id_); | 342 new ExtensionDevToolsClientHost(contents_, GetExtension()->id(), tab_id_); |
| 331 SendResponse(true); | 343 SendResponse(true); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 return; | 386 return; |
| 375 } | 387 } |
| 376 | 388 |
| 377 Value* result_body; | 389 Value* result_body; |
| 378 if (dictionary->Get("result", &result_body)) | 390 if (dictionary->Get("result", &result_body)) |
| 379 result_.reset(result_body->DeepCopy()); | 391 result_.reset(result_body->DeepCopy()); |
| 380 else | 392 else |
| 381 result_.reset(new DictionaryValue()); | 393 result_.reset(new DictionaryValue()); |
| 382 SendResponse(true); | 394 SendResponse(true); |
| 383 } | 395 } |
| OLD | NEW |