| 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_tabs_module.h" | 19 #include "chrome/browser/extensions/extension_tabs_module.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/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_error_utils.h" | 23 #include "chrome/common/extensions/extension_error_utils.h" |
| 24 #include "content/browser/debugger/devtools_client_host.h" | 24 #include "content/browser/debugger/devtools_client_host.h" |
| 25 #include "content/browser/debugger/devtools_manager.h" | 25 #include "content/browser/debugger/devtools_manager.h" |
| 26 #include "content/browser/tab_contents/tab_contents.h" | 26 #include "content/browser/tab_contents/tab_contents.h" |
| 27 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "content/common/devtools_messages.h" | 28 #include "content/common/devtools_messages.h" |
| 28 #include "content/common/notification_service.h" | 29 #include "content/common/notification_service.h" |
| 29 | 30 |
| 30 namespace keys = extension_debugger_api_constants; | 31 namespace keys = extension_debugger_api_constants; |
| 31 | 32 |
| 32 class ExtensionDevToolsClientHost : public DevToolsClientHost, | 33 class ExtensionDevToolsClientHost : public DevToolsClientHost, |
| 33 public NotificationObserver { | 34 public NotificationObserver { |
| 34 public: | 35 public: |
| 35 ExtensionDevToolsClientHost(TabContents* tab_contents, | 36 ExtensionDevToolsClientHost(TabContents* tab_contents, |
| 36 const std::string& extension_id, | 37 const std::string& extension_id, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 TabContents* tab_contents, | 110 TabContents* tab_contents, |
| 110 const std::string& extension_id, | 111 const std::string& extension_id, |
| 111 int tab_id) | 112 int tab_id) |
| 112 : tab_contents_(tab_contents), | 113 : tab_contents_(tab_contents), |
| 113 extension_id_(extension_id), | 114 extension_id_(extension_id), |
| 114 tab_id_(tab_id), | 115 tab_id_(tab_id), |
| 115 last_request_id_(0) { | 116 last_request_id_(0) { |
| 116 AttachedClientHosts::GetInstance()->Add(this); | 117 AttachedClientHosts::GetInstance()->Add(this); |
| 117 | 118 |
| 118 // Detach from debugger when extension unloads. | 119 // Detach from debugger when extension unloads. |
| 119 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 120 registrar_.Add(this, chrome::EXTENSION_UNLOADED, |
| 120 Source<Profile>(tab_contents_->profile())); | 121 Source<Profile>(tab_contents_->profile())); |
| 121 | 122 |
| 122 // Attach to debugger and tell it we are ready. | 123 // Attach to debugger and tell it we are ready. |
| 123 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 124 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
| 124 tab_contents_->render_view_host(), | 125 tab_contents_->render_view_host(), |
| 125 this); | 126 this); |
| 126 DevToolsManager::GetInstance()->ForwardToDevToolsAgent( | 127 DevToolsManager::GetInstance()->ForwardToDevToolsAgent( |
| 127 this, | 128 this, |
| 128 DevToolsAgentMsg_FrontendLoaded()); | 129 DevToolsAgentMsg_FrontendLoaded()); |
| 129 } | 130 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 base::JSONWriter::Write(&protocol_request, false, &json_args); | 191 base::JSONWriter::Write(&protocol_request, false, &json_args); |
| 191 DevToolsManager::GetInstance()->ForwardToDevToolsAgent( | 192 DevToolsManager::GetInstance()->ForwardToDevToolsAgent( |
| 192 this, | 193 this, |
| 193 DevToolsAgentMsg_DispatchOnInspectorBackend(json_args)); | 194 DevToolsAgentMsg_DispatchOnInspectorBackend(json_args)); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void ExtensionDevToolsClientHost::Observe( | 197 void ExtensionDevToolsClientHost::Observe( |
| 197 NotificationType type, | 198 NotificationType type, |
| 198 const NotificationSource& source, | 199 const NotificationSource& source, |
| 199 const NotificationDetails& details) { | 200 const NotificationDetails& details) { |
| 200 DCHECK(type == NotificationType::EXTENSION_UNLOADED); | 201 DCHECK(type == chrome::EXTENSION_UNLOADED); |
| 201 Close(); | 202 Close(); |
| 202 } | 203 } |
| 203 | 204 |
| 204 void ExtensionDevToolsClientHost::OnDispatchOnInspectorFrontend( | 205 void ExtensionDevToolsClientHost::OnDispatchOnInspectorFrontend( |
| 205 const std::string& data) { | 206 const std::string& data) { |
| 206 Profile* profile = tab_contents_->profile(); | 207 Profile* profile = tab_contents_->profile(); |
| 207 if (profile == NULL || !profile->GetExtensionEventRouter()) | 208 if (profile == NULL || !profile->GetExtensionEventRouter()) |
| 208 return; | 209 return; |
| 209 | 210 |
| 210 scoped_ptr<Value> result(base::JSONReader::Read(data, false)); | 211 scoped_ptr<Value> result(base::JSONReader::Read(data, false)); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 return; | 353 return; |
| 353 } | 354 } |
| 354 | 355 |
| 355 Value* result_body; | 356 Value* result_body; |
| 356 if (dictionary->Get("result", &result_body)) | 357 if (dictionary->Get("result", &result_body)) |
| 357 result_.reset(result_body->DeepCopy()); | 358 result_.reset(result_body->DeepCopy()); |
| 358 else | 359 else |
| 359 result_.reset(new DictionaryValue()); | 360 result_.reset(new DictionaryValue()); |
| 360 SendResponse(true); | 361 SendResponse(true); |
| 361 } | 362 } |
| OLD | NEW |