OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/debugger/debugger_api.h" | 7 #include "chrome/browser/extensions/api/debugger/debugger_api.h" |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 | 11 |
| 12 #include "base/command_line.h" |
12 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
13 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 20 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
20 #include "chrome/browser/api/infobars/infobar_service.h" | 21 #include "chrome/browser/api/infobars/infobar_service.h" |
21 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" | 22 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" |
22 #include "chrome/browser/extensions/event_router.h" | 23 #include "chrome/browser/extensions/event_router.h" |
| 24 #include "chrome/browser/extensions/extension_host.h" |
| 25 #include "chrome/browser/extensions/extension_service.h" |
23 #include "chrome/browser/extensions/extension_system.h" | 26 #include "chrome/browser/extensions/extension_system.h" |
24 #include "chrome/browser/extensions/extension_tab_util.h" | 27 #include "chrome/browser/extensions/extension_tab_util.h" |
25 #include "chrome/browser/infobars/infobar.h" | 28 #include "chrome/browser/infobars/infobar.h" |
26 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 30 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
28 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/extensions/api/debugger.h" | 32 #include "chrome/common/chrome_switches.h" |
30 #include "chrome/common/extensions/extension.h" | 33 #include "chrome/common/extensions/extension.h" |
31 #include "content/public/browser/devtools_agent_host.h" | 34 #include "content/public/browser/devtools_agent_host.h" |
32 #include "content/public/browser/devtools_client_host.h" | 35 #include "content/public/browser/devtools_client_host.h" |
33 #include "content/public/browser/devtools_manager.h" | 36 #include "content/public/browser/devtools_manager.h" |
34 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
35 #include "content/public/browser/notification_source.h" | 38 #include "content/public/browser/notification_source.h" |
| 39 #include "content/public/browser/render_process_host.h" |
36 #include "content/public/browser/render_view_host.h" | 40 #include "content/public/browser/render_view_host.h" |
| 41 #include "content/public/browser/render_widget_host.h" |
37 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
38 #include "content/public/common/content_client.h" | 43 #include "content/public/common/content_client.h" |
39 #include "content/public/common/url_constants.h" | 44 #include "content/public/common/url_constants.h" |
40 #include "extensions/common/error_utils.h" | 45 #include "extensions/common/error_utils.h" |
41 #include "grit/generated_resources.h" | 46 #include "grit/generated_resources.h" |
42 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
43 #include "webkit/glue/webkit_glue.h" | 48 #include "webkit/glue/webkit_glue.h" |
44 | 49 |
45 using content::DevToolsAgentHost; | 50 using content::DevToolsAgentHost; |
46 using content::DevToolsClientHost; | 51 using content::DevToolsClientHost; |
47 using content::DevToolsManager; | 52 using content::DevToolsManager; |
| 53 using content::RenderProcessHost; |
| 54 using content::RenderViewHost; |
| 55 using content::RenderWidgetHost; |
48 using content::WebContents; | 56 using content::WebContents; |
49 using extensions::api::debugger::Debuggee; | |
50 using extensions::ErrorUtils; | 57 using extensions::ErrorUtils; |
51 | 58 |
52 namespace keys = debugger_api_constants; | 59 namespace keys = debugger_api_constants; |
53 namespace Attach = extensions::api::debugger::Attach; | 60 namespace Attach = extensions::api::debugger::Attach; |
54 namespace Detach = extensions::api::debugger::Detach; | 61 namespace Detach = extensions::api::debugger::Detach; |
55 namespace OnDetach = extensions::api::debugger::OnDetach; | 62 namespace OnDetach = extensions::api::debugger::OnDetach; |
56 namespace OnEvent = extensions::api::debugger::OnEvent; | 63 namespace OnEvent = extensions::api::debugger::OnEvent; |
57 namespace SendCommand = extensions::api::debugger::SendCommand; | 64 namespace SendCommand = extensions::api::debugger::SendCommand; |
58 | 65 |
59 class ExtensionDevToolsClientHost; | 66 class ExtensionDevToolsClientHost; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 ExtensionDevToolsClientHost* client_host_; | 98 ExtensionDevToolsClientHost* client_host_; |
92 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate); | 99 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate); |
93 }; | 100 }; |
94 | 101 |
95 class ExtensionDevToolsClientHost : public DevToolsClientHost, | 102 class ExtensionDevToolsClientHost : public DevToolsClientHost, |
96 public content::NotificationObserver { | 103 public content::NotificationObserver { |
97 public: | 104 public: |
98 ExtensionDevToolsClientHost(WebContents* web_contents, | 105 ExtensionDevToolsClientHost(WebContents* web_contents, |
99 const std::string& extension_id, | 106 const std::string& extension_id, |
100 const std::string& extension_name, | 107 const std::string& extension_name, |
101 int tab_id); | 108 const Debuggee& debuggee); |
102 | 109 |
103 virtual ~ExtensionDevToolsClientHost(); | 110 virtual ~ExtensionDevToolsClientHost(); |
104 | 111 |
105 bool MatchesContentsAndExtensionId(WebContents* web_contents, | 112 bool MatchesContentsAndExtensionId(WebContents* web_contents, |
106 const std::string& extension_id); | 113 const std::string& extension_id); |
107 void Close(); | 114 void Close(); |
108 void SendMessageToBackend(DebuggerSendCommandFunction* function, | 115 void SendMessageToBackend(DebuggerSendCommandFunction* function, |
109 const std::string& method, | 116 const std::string& method, |
110 SendCommand::Params::CommandParams* command_params); | 117 SendCommand::Params::CommandParams* command_params); |
111 | 118 |
112 // Marks connection as to-be-terminated by the user. | 119 // Marks connection as to-be-terminated by the user. |
113 void MarkAsDismissed(); | 120 void MarkAsDismissed(); |
114 | 121 |
115 // DevToolsClientHost interface | 122 // DevToolsClientHost interface |
116 virtual void InspectedContentsClosing() OVERRIDE; | 123 virtual void InspectedContentsClosing() OVERRIDE; |
117 virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE; | 124 virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE; |
118 virtual void ReplacedWithAnotherClient() OVERRIDE; | 125 virtual void ReplacedWithAnotherClient() OVERRIDE; |
119 | 126 |
120 private: | 127 private: |
121 void SendDetachedEvent(); | 128 void SendDetachedEvent(); |
122 | 129 |
123 // content::NotificationObserver implementation. | 130 // content::NotificationObserver implementation. |
124 virtual void Observe(int type, | 131 virtual void Observe(int type, |
125 const content::NotificationSource& source, | 132 const content::NotificationSource& source, |
126 const content::NotificationDetails& details) OVERRIDE; | 133 const content::NotificationDetails& details) OVERRIDE; |
127 | 134 |
128 WebContents* web_contents_; | 135 WebContents* web_contents_; |
129 std::string extension_id_; | 136 std::string extension_id_; |
130 int tab_id_; | 137 Debuggee debuggee_; |
131 content::NotificationRegistrar registrar_; | 138 content::NotificationRegistrar registrar_; |
132 int last_request_id_; | 139 int last_request_id_; |
133 typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> > | 140 typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> > |
134 PendingRequests; | 141 PendingRequests; |
135 PendingRequests pending_requests_; | 142 PendingRequests pending_requests_; |
136 ExtensionDevToolsInfoBarDelegate* infobar_delegate_; | 143 ExtensionDevToolsInfoBarDelegate* infobar_delegate_; |
137 OnDetach::Reason detach_reason_; | 144 OnDetach::Reason detach_reason_; |
138 | 145 |
139 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); | 146 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); |
140 }; | 147 }; |
(...skipping 30 matching lines...) Expand all Loading... |
171 } | 178 } |
172 return NULL; | 179 return NULL; |
173 } | 180 } |
174 | 181 |
175 private: | 182 private: |
176 std::set<DevToolsClientHost*> client_hosts_; | 183 std::set<DevToolsClientHost*> client_hosts_; |
177 }; | 184 }; |
178 | 185 |
179 } // namespace | 186 } // namespace |
180 | 187 |
| 188 static void CopyDebuggee(Debuggee & dst, const Debuggee& src) { |
| 189 if (src.tab_id) |
| 190 dst.tab_id.reset(new int(*src.tab_id)); |
| 191 if (src.extension_id) |
| 192 dst.extension_id.reset(new std::string(*src.extension_id)); |
| 193 } |
| 194 |
181 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( | 195 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( |
182 WebContents* web_contents, | 196 WebContents* web_contents, |
183 const std::string& extension_id, | 197 const std::string& extension_id, |
184 const std::string& extension_name, | 198 const std::string& extension_name, |
185 int tab_id) | 199 const Debuggee& debuggee) |
186 : web_contents_(web_contents), | 200 : web_contents_(web_contents), |
187 extension_id_(extension_id), | 201 extension_id_(extension_id), |
188 tab_id_(tab_id), | |
189 last_request_id_(0), | 202 last_request_id_(0), |
190 infobar_delegate_(NULL), | 203 infobar_delegate_(NULL), |
191 detach_reason_(OnDetach::REASON_TARGET_CLOSED) { | 204 detach_reason_(OnDetach::REASON_TARGET_CLOSED) { |
| 205 CopyDebuggee(debuggee_, debuggee); |
| 206 |
192 AttachedClientHosts::GetInstance()->Add(this); | 207 AttachedClientHosts::GetInstance()->Add(this); |
193 | 208 |
194 // Detach from debugger when extension unloads. | 209 // Detach from debugger when extension unloads. |
195 Profile* profile = | 210 Profile* profile = |
196 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 211 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
197 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 212 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
198 content::Source<Profile>(profile)); | 213 content::Source<Profile>(profile)); |
199 | 214 |
200 // Attach to debugger and tell it we are ready. | 215 // Attach to debugger and tell it we are ready. |
201 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( | 216 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( |
202 web_contents_->GetRenderViewHost())); | 217 web_contents_->GetRenderViewHost())); |
203 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); | 218 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); |
204 | 219 |
205 InfoBarService* infobar_service = | 220 if (!CommandLine::ForCurrentProcess()-> |
206 InfoBarService::FromWebContents(web_contents_); | 221 HasSwitch(switches::kSilentDebuggerExtensionAPI)) { |
207 infobar_delegate_ = ExtensionDevToolsInfoBarDelegate::Create(infobar_service, | 222 InfoBarService* infobar_service = |
208 extension_name, | 223 InfoBarService::FromWebContents(web_contents_); |
209 this); | 224 infobar_delegate_ = ExtensionDevToolsInfoBarDelegate::Create( |
210 if (infobar_delegate_) { | 225 infobar_service, extension_name, this); |
211 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 226 if (infobar_delegate_) { |
212 content::Source<InfoBarService>(infobar_service)); | 227 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 228 content::Source<InfoBarService>(infobar_service)); |
| 229 } |
213 } | 230 } |
214 } | 231 } |
215 | 232 |
216 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { | 233 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { |
217 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to | 234 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to |
218 // Close() us. | 235 // Close() us. |
219 registrar_.RemoveAll(); | 236 registrar_.RemoveAll(); |
220 | 237 |
221 if (infobar_delegate_) { | 238 if (infobar_delegate_) { |
222 infobar_delegate_->DiscardClientHost(); | 239 infobar_delegate_->DiscardClientHost(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 287 |
271 void ExtensionDevToolsClientHost::MarkAsDismissed() { | 288 void ExtensionDevToolsClientHost::MarkAsDismissed() { |
272 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER; | 289 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER; |
273 } | 290 } |
274 | 291 |
275 void ExtensionDevToolsClientHost::SendDetachedEvent() { | 292 void ExtensionDevToolsClientHost::SendDetachedEvent() { |
276 Profile* profile = | 293 Profile* profile = |
277 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 294 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
278 if (profile != NULL && | 295 if (profile != NULL && |
279 extensions::ExtensionSystem::Get(profile)->event_router()) { | 296 extensions::ExtensionSystem::Get(profile)->event_router()) { |
280 Debuggee debuggee; | 297 scoped_ptr<base::ListValue> args(OnDetach::Create(debuggee_, |
281 debuggee.tab_id = tab_id_; | |
282 scoped_ptr<base::ListValue> args(OnDetach::Create(debuggee, | |
283 detach_reason_)); | 298 detach_reason_)); |
284 scoped_ptr<extensions::Event> event(new extensions::Event( | 299 scoped_ptr<extensions::Event> event(new extensions::Event( |
285 keys::kOnDetach, args.Pass())); | 300 keys::kOnDetach, args.Pass())); |
286 event->restrict_to_profile = profile; | 301 event->restrict_to_profile = profile; |
287 extensions::ExtensionSystem::Get(profile)->event_router()-> | 302 extensions::ExtensionSystem::Get(profile)->event_router()-> |
288 DispatchEventToExtension(extension_id_, event.Pass()); | 303 DispatchEventToExtension(extension_id_, event.Pass()); |
289 } | 304 } |
290 } | 305 } |
291 | 306 |
292 void ExtensionDevToolsClientHost::Observe( | 307 void ExtensionDevToolsClientHost::Observe( |
(...skipping 29 matching lines...) Expand all Loading... |
322 if (!result->IsType(Value::TYPE_DICTIONARY)) | 337 if (!result->IsType(Value::TYPE_DICTIONARY)) |
323 return; | 338 return; |
324 DictionaryValue* dictionary = static_cast<DictionaryValue*>(result.get()); | 339 DictionaryValue* dictionary = static_cast<DictionaryValue*>(result.get()); |
325 | 340 |
326 int id; | 341 int id; |
327 if (!dictionary->GetInteger("id", &id)) { | 342 if (!dictionary->GetInteger("id", &id)) { |
328 std::string method_name; | 343 std::string method_name; |
329 if (!dictionary->GetString("method", &method_name)) | 344 if (!dictionary->GetString("method", &method_name)) |
330 return; | 345 return; |
331 | 346 |
332 Debuggee debuggee; | |
333 debuggee.tab_id = tab_id_; | |
334 | |
335 OnEvent::Params params; | 347 OnEvent::Params params; |
336 DictionaryValue* params_value; | 348 DictionaryValue* params_value; |
337 if (dictionary->GetDictionary("params", ¶ms_value)) | 349 if (dictionary->GetDictionary("params", ¶ms_value)) |
338 params.additional_properties.Swap(params_value); | 350 params.additional_properties.Swap(params_value); |
339 | 351 |
340 scoped_ptr<ListValue> args(OnEvent::Create(debuggee, method_name, params)); | 352 scoped_ptr<ListValue> args(OnEvent::Create(debuggee_, method_name, params)); |
341 scoped_ptr<extensions::Event> event(new extensions::Event( | 353 scoped_ptr<extensions::Event> event(new extensions::Event( |
342 keys::kOnEvent, args.Pass())); | 354 keys::kOnEvent, args.Pass())); |
343 event->restrict_to_profile = profile; | 355 event->restrict_to_profile = profile; |
344 extensions::ExtensionSystem::Get(profile)->event_router()-> | 356 extensions::ExtensionSystem::Get(profile)->event_router()-> |
345 DispatchEventToExtension(extension_id_, event.Pass()); | 357 DispatchEventToExtension(extension_id_, event.Pass()); |
346 } else { | 358 } else { |
347 DebuggerSendCommandFunction* function = pending_requests_[id]; | 359 DebuggerSendCommandFunction* function = pending_requests_[id]; |
348 if (!function) | 360 if (!function) |
349 return; | 361 return; |
350 | 362 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 416 } |
405 | 417 |
406 bool ExtensionDevToolsInfoBarDelegate::Cancel() { | 418 bool ExtensionDevToolsInfoBarDelegate::Cancel() { |
407 if (client_host_) | 419 if (client_host_) |
408 client_host_->MarkAsDismissed(); | 420 client_host_->MarkAsDismissed(); |
409 return true; | 421 return true; |
410 } | 422 } |
411 | 423 |
412 DebuggerFunction::DebuggerFunction() | 424 DebuggerFunction::DebuggerFunction() |
413 : contents_(0), | 425 : contents_(0), |
414 tab_id_(0), | |
415 client_host_(0) { | 426 client_host_(0) { |
416 } | 427 } |
417 | 428 |
| 429 void DebuggerFunction::FormatErrorMessage(const std::string& format) { |
| 430 error_ = ErrorUtils::FormatErrorMessage( |
| 431 format, |
| 432 debuggee_.tab_id ? |
| 433 keys::kTabTargetType : |
| 434 keys::kExtensionTargetType, |
| 435 debuggee_.tab_id ? |
| 436 base::IntToString(*debuggee_.tab_id) : |
| 437 *debuggee_.extension_id); |
| 438 } |
| 439 |
418 bool DebuggerFunction::InitWebContents() { | 440 bool DebuggerFunction::InitWebContents() { |
419 // Find the WebContents that contains this tab id. | 441 // Find the WebContents that contains this tab id. |
420 contents_ = NULL; | 442 contents_ = NULL; |
421 WebContents* web_contents = NULL; | 443 if (debuggee_.tab_id) { |
422 bool result = ExtensionTabUtil::GetTabById( | 444 WebContents* web_contents = NULL; |
423 tab_id_, profile(), include_incognito(), NULL, NULL, &web_contents, NULL); | 445 bool result = ExtensionTabUtil::GetTabById( |
424 if (!result || !web_contents) { | 446 *debuggee_.tab_id, profile(), include_incognito(), NULL, NULL, |
425 error_ = ErrorUtils::FormatErrorMessage( | 447 &web_contents, NULL); |
426 keys::kNoTabError, | 448 if (!result || !web_contents) { |
427 base::IntToString(tab_id_)); | 449 FormatErrorMessage(keys::kNoTargetError); |
428 return false; | 450 return false; |
| 451 } |
| 452 contents_ = web_contents; |
| 453 |
| 454 if (content::HasWebUIScheme(contents_->GetURL())) { |
| 455 error_ = ErrorUtils::FormatErrorMessage( |
| 456 keys::kAttachToWebUIError, |
| 457 contents_->GetURL().scheme()); |
| 458 return false; |
| 459 } |
| 460 |
| 461 return true; |
429 } | 462 } |
430 contents_ = web_contents; | |
431 | 463 |
432 if (content::HasWebUIScheme(contents_->GetURL())) { | 464 if (debuggee_.extension_id) { |
433 error_ = ErrorUtils::FormatErrorMessage( | 465 if (!CommandLine::ForCurrentProcess()-> |
434 keys::kAttachToWebUIError, | 466 HasSwitch(switches::kSilentDebuggerExtensionAPI)) { |
435 contents_->GetURL().scheme()); | 467 error_ = ErrorUtils::FormatErrorMessage( |
| 468 keys::kSilentDebuggingRequired, |
| 469 switches::kSilentDebuggerExtensionAPI); |
| 470 return false; |
| 471 } |
| 472 |
| 473 extensions::ExtensionHost* host = |
| 474 extensions::ExtensionSystem::Get(profile())->process_manager()-> |
| 475 GetBackgroundHostForExtension(*debuggee_.extension_id); |
| 476 if (host) { |
| 477 contents_ = WebContents::FromRenderViewHost(host->render_view_host()); |
| 478 if (contents_) |
| 479 return true; |
| 480 } |
| 481 |
| 482 FormatErrorMessage(keys::kNoTargetError); |
436 return false; | 483 return false; |
437 } | 484 } |
438 | 485 |
439 return true; | 486 error_ = keys::kInvalidTargetError; |
| 487 return false; |
440 } | 488 } |
441 | 489 |
442 bool DebuggerFunction::InitClientHost() { | 490 bool DebuggerFunction::InitClientHost() { |
443 if (!InitWebContents()) | 491 if (!InitWebContents()) |
444 return false; | 492 return false; |
445 | 493 |
446 // Don't fetch rvh from the contents since it'll be wrong upon navigation. | 494 // Don't fetch rvh from the contents since it'll be wrong upon navigation. |
447 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_); | 495 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_); |
448 | 496 |
449 if (!client_host_ || | 497 if (!client_host_ || |
450 !client_host_->MatchesContentsAndExtensionId(contents_, | 498 !client_host_->MatchesContentsAndExtensionId(contents_, |
451 GetExtension()->id())) { | 499 GetExtension()->id())) { |
452 error_ = ErrorUtils::FormatErrorMessage( | 500 FormatErrorMessage(keys::kNotAttachedError); |
453 keys::kNotAttachedError, | |
454 base::IntToString(tab_id_)); | |
455 return false; | 501 return false; |
456 } | 502 } |
457 return true; | 503 return true; |
458 } | 504 } |
459 | 505 |
460 DebuggerAttachFunction::DebuggerAttachFunction() {} | 506 DebuggerAttachFunction::DebuggerAttachFunction() {} |
461 | 507 |
462 DebuggerAttachFunction::~DebuggerAttachFunction() {} | 508 DebuggerAttachFunction::~DebuggerAttachFunction() {} |
463 | 509 |
464 bool DebuggerAttachFunction::RunImpl() { | 510 bool DebuggerAttachFunction::RunImpl() { |
465 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_)); | 511 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_)); |
466 EXTENSION_FUNCTION_VALIDATE(params.get()); | 512 EXTENSION_FUNCTION_VALIDATE(params.get()); |
467 | 513 |
468 tab_id_ = params->target.tab_id; | 514 CopyDebuggee(debuggee_, params->target); |
469 if (!InitWebContents()) | 515 if (!InitWebContents()) |
470 return false; | 516 return false; |
471 | 517 |
472 if (!webkit_glue::IsInspectorProtocolVersionSupported( | 518 if (!webkit_glue::IsInspectorProtocolVersionSupported( |
473 params->required_version)) { | 519 params->required_version)) { |
474 error_ = ErrorUtils::FormatErrorMessage( | 520 error_ = ErrorUtils::FormatErrorMessage( |
475 keys::kProtocolVersionNotSupportedError, | 521 keys::kProtocolVersionNotSupportedError, |
476 params->required_version); | 522 params->required_version); |
477 return false; | 523 return false; |
478 } | 524 } |
479 | 525 |
480 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( | 526 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( |
481 contents_->GetRenderViewHost())); | 527 contents_->GetRenderViewHost())); |
482 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> | 528 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> |
483 GetDevToolsClientHostFor(agent); | 529 GetDevToolsClientHostFor(agent); |
484 | 530 |
485 if (client_host != NULL) { | 531 if (client_host != NULL) { |
486 error_ = ErrorUtils::FormatErrorMessage( | 532 FormatErrorMessage(keys::kAlreadyAttachedError); |
487 keys::kAlreadyAttachedError, | |
488 base::IntToString(tab_id_)); | |
489 return false; | 533 return false; |
490 } | 534 } |
491 | 535 |
492 new ExtensionDevToolsClientHost(contents_, | 536 new ExtensionDevToolsClientHost(contents_, |
493 GetExtension()->id(), | 537 GetExtension()->id(), |
494 GetExtension()->name(), | 538 GetExtension()->name(), |
495 tab_id_); | 539 debuggee_); |
496 SendResponse(true); | 540 SendResponse(true); |
497 return true; | 541 return true; |
498 } | 542 } |
499 | 543 |
500 DebuggerDetachFunction::DebuggerDetachFunction() {} | 544 DebuggerDetachFunction::DebuggerDetachFunction() {} |
501 | 545 |
502 DebuggerDetachFunction::~DebuggerDetachFunction() {} | 546 DebuggerDetachFunction::~DebuggerDetachFunction() {} |
503 | 547 |
504 bool DebuggerDetachFunction::RunImpl() { | 548 bool DebuggerDetachFunction::RunImpl() { |
505 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_)); | 549 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_)); |
506 EXTENSION_FUNCTION_VALIDATE(params.get()); | 550 EXTENSION_FUNCTION_VALIDATE(params.get()); |
507 | 551 |
508 tab_id_ = params->target.tab_id; | 552 CopyDebuggee(debuggee_, params->target); |
509 if (!InitClientHost()) | 553 if (!InitClientHost()) |
510 return false; | 554 return false; |
511 | 555 |
512 client_host_->Close(); | 556 client_host_->Close(); |
513 SendResponse(true); | 557 SendResponse(true); |
514 return true; | 558 return true; |
515 } | 559 } |
516 | 560 |
517 DebuggerSendCommandFunction::DebuggerSendCommandFunction() {} | 561 DebuggerSendCommandFunction::DebuggerSendCommandFunction() {} |
518 | 562 |
519 DebuggerSendCommandFunction::~DebuggerSendCommandFunction() {} | 563 DebuggerSendCommandFunction::~DebuggerSendCommandFunction() {} |
520 | 564 |
521 bool DebuggerSendCommandFunction::RunImpl() { | 565 bool DebuggerSendCommandFunction::RunImpl() { |
522 scoped_ptr<SendCommand::Params> params(SendCommand::Params::Create(*args_)); | 566 scoped_ptr<SendCommand::Params> params(SendCommand::Params::Create(*args_)); |
523 EXTENSION_FUNCTION_VALIDATE(params.get()); | 567 EXTENSION_FUNCTION_VALIDATE(params.get()); |
524 | 568 |
525 tab_id_ = params->target.tab_id; | 569 CopyDebuggee(debuggee_, params->target); |
526 if (!InitClientHost()) | 570 if (!InitClientHost()) |
527 return false; | 571 return false; |
528 | 572 |
529 client_host_->SendMessageToBackend(this, params->method, | 573 client_host_->SendMessageToBackend(this, params->method, |
530 params->command_params.get()); | 574 params->command_params.get()); |
531 return true; | 575 return true; |
532 } | 576 } |
533 | 577 |
534 void DebuggerSendCommandFunction::SendResponseBody( | 578 void DebuggerSendCommandFunction::SendResponseBody( |
535 DictionaryValue* response) { | 579 DictionaryValue* response) { |
536 Value* error_body; | 580 Value* error_body; |
537 if (response->Get("error", &error_body)) { | 581 if (response->Get("error", &error_body)) { |
538 base::JSONWriter::Write(error_body, &error_); | 582 base::JSONWriter::Write(error_body, &error_); |
539 SendResponse(false); | 583 SendResponse(false); |
540 return; | 584 return; |
541 } | 585 } |
542 | 586 |
543 DictionaryValue* result_body; | 587 DictionaryValue* result_body; |
544 SendCommand::Results::Result result; | 588 SendCommand::Results::Result result; |
545 if (response->GetDictionary("result", &result_body)) | 589 if (response->GetDictionary("result", &result_body)) |
546 result.additional_properties.Swap(result_body); | 590 result.additional_properties.Swap(result_body); |
547 | 591 |
548 results_ = SendCommand::Results::Create(result); | 592 results_ = SendCommand::Results::Create(result); |
549 SendResponse(true); | 593 SendResponse(true); |
550 } | 594 } |
OLD | NEW |