Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: chrome/browser/extensions/api/debugger/debugger_api.cc

Issue 12304021: Allow chrome.debugger API to attach to extension background pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/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/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" 19 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
20 #include "chrome/browser/api/infobars/infobar_service.h" 20 #include "chrome/browser/api/infobars/infobar_service.h"
21 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h" 21 #include "chrome/browser/extensions/api/debugger/debugger_api_constants.h"
22 #include "chrome/browser/extensions/event_router.h" 22 #include "chrome/browser/extensions/event_router.h"
23 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/extension_system.h" 24 #include "chrome/browser/extensions/extension_system.h"
24 #include "chrome/browser/extensions/extension_tab_util.h" 25 #include "chrome/browser/extensions/extension_tab_util.h"
25 #include "chrome/browser/infobars/infobar.h" 26 #include "chrome/browser/infobars/infobar.h"
26 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 28 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
28 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/extensions/api/debugger.h" 30 #include "chrome/common/extensions/api/debugger.h"
30 #include "chrome/common/extensions/extension.h" 31 #include "chrome/common/extensions/extension.h"
31 #include "content/public/browser/devtools_agent_host.h" 32 #include "content/public/browser/devtools_agent_host.h"
32 #include "content/public/browser/devtools_client_host.h" 33 #include "content/public/browser/devtools_client_host.h"
33 #include "content/public/browser/devtools_manager.h" 34 #include "content/public/browser/devtools_manager.h"
34 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
35 #include "content/public/browser/notification_source.h" 36 #include "content/public/browser/notification_source.h"
37 #include "content/public/browser/render_process_host.h"
36 #include "content/public/browser/render_view_host.h" 38 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/render_widget_host.h"
37 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
38 #include "content/public/common/content_client.h" 41 #include "content/public/common/content_client.h"
39 #include "content/public/common/url_constants.h" 42 #include "content/public/common/url_constants.h"
40 #include "extensions/common/error_utils.h" 43 #include "extensions/common/error_utils.h"
41 #include "grit/generated_resources.h" 44 #include "grit/generated_resources.h"
42 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
43 #include "webkit/glue/webkit_glue.h" 46 #include "webkit/glue/webkit_glue.h"
44 47
45 using content::DevToolsAgentHost; 48 using content::DevToolsAgentHost;
46 using content::DevToolsClientHost; 49 using content::DevToolsClientHost;
47 using content::DevToolsManager; 50 using content::DevToolsManager;
51 using content::RenderProcessHost;
52 using content::RenderViewHost;
53 using content::RenderWidgetHost;
48 using content::WebContents; 54 using content::WebContents;
49 using extensions::api::debugger::Debuggee; 55 using extensions::api::debugger::Debuggee;
50 using extensions::ErrorUtils; 56 using extensions::ErrorUtils;
51 57
52 namespace keys = debugger_api_constants; 58 namespace keys = debugger_api_constants;
53 namespace Attach = extensions::api::debugger::Attach; 59 namespace Attach = extensions::api::debugger::Attach;
54 namespace Detach = extensions::api::debugger::Detach; 60 namespace Detach = extensions::api::debugger::Detach;
55 namespace OnDetach = extensions::api::debugger::OnDetach; 61 namespace OnDetach = extensions::api::debugger::OnDetach;
56 namespace OnEvent = extensions::api::debugger::OnEvent; 62 namespace OnEvent = extensions::api::debugger::OnEvent;
57 namespace SendCommand = extensions::api::debugger::SendCommand; 63 namespace SendCommand = extensions::api::debugger::SendCommand;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 ExtensionDevToolsClientHost* client_host_; 97 ExtensionDevToolsClientHost* client_host_;
92 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate); 98 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate);
93 }; 99 };
94 100
95 class ExtensionDevToolsClientHost : public DevToolsClientHost, 101 class ExtensionDevToolsClientHost : public DevToolsClientHost,
96 public content::NotificationObserver { 102 public content::NotificationObserver {
97 public: 103 public:
98 ExtensionDevToolsClientHost(WebContents* web_contents, 104 ExtensionDevToolsClientHost(WebContents* web_contents,
99 const std::string& extension_id, 105 const std::string& extension_id,
100 const std::string& extension_name, 106 const std::string& extension_name,
101 int tab_id); 107 int debuggee_tab_id,
108 const std::string& debuggee_extension_id);
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
181 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( 188 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost(
182 WebContents* web_contents, 189 WebContents* web_contents,
183 const std::string& extension_id, 190 const std::string& extension_id,
184 const std::string& extension_name, 191 const std::string& extension_name,
185 int tab_id) 192 int debuggee_tab_id,
193 const std::string& debuggee_extension_id)
186 : web_contents_(web_contents), 194 : web_contents_(web_contents),
187 extension_id_(extension_id), 195 extension_id_(extension_id),
188 tab_id_(tab_id),
189 last_request_id_(0), 196 last_request_id_(0),
190 infobar_delegate_(NULL), 197 infobar_delegate_(NULL),
191 detach_reason_(OnDetach::REASON_TARGET_CLOSED) { 198 detach_reason_(OnDetach::REASON_TARGET_CLOSED) {
199 if (debuggee_tab_id)
200 debuggee_.tab_id.reset(new int(debuggee_tab_id));
201 else
202 debuggee_.extension_id.reset(new std::string(debuggee_extension_id));
203
192 AttachedClientHosts::GetInstance()->Add(this); 204 AttachedClientHosts::GetInstance()->Add(this);
193 205
194 // Detach from debugger when extension unloads. 206 // Detach from debugger when extension unloads.
195 Profile* profile = 207 Profile* profile =
196 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 208 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
197 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 209 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
198 content::Source<Profile>(profile)); 210 content::Source<Profile>(profile));
199 211
200 // Attach to debugger and tell it we are ready. 212 // Attach to debugger and tell it we are ready.
201 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( 213 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor(
202 web_contents_->GetRenderViewHost())); 214 web_contents_->GetRenderViewHost()));
203 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); 215 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this);
204 216
205 InfoBarService* infobar_service = 217 InfoBarService* infobar_service =
206 InfoBarService::FromWebContents(web_contents_); 218 InfoBarService::FromWebContents(web_contents_);
207 infobar_delegate_ = ExtensionDevToolsInfoBarDelegate::Create(infobar_service, 219 if (infobar_service) {
208 extension_name, 220 infobar_delegate_ = ExtensionDevToolsInfoBarDelegate::Create(
209 this); 221 infobar_service, extension_name, this);
210 if (infobar_delegate_) { 222 if (infobar_delegate_) {
211 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 223 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
212 content::Source<InfoBarService>(infobar_service)); 224 content::Source<InfoBarService>(infobar_service));
225 }
213 } 226 }
214 } 227 }
215 228
216 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { 229 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() {
217 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to 230 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to
218 // Close() us. 231 // Close() us.
219 registrar_.RemoveAll(); 232 registrar_.RemoveAll();
220 233
221 if (infobar_delegate_) { 234 if (infobar_delegate_) {
222 infobar_delegate_->DiscardClientHost(); 235 infobar_delegate_->DiscardClientHost();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 283
271 void ExtensionDevToolsClientHost::MarkAsDismissed() { 284 void ExtensionDevToolsClientHost::MarkAsDismissed() {
272 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER; 285 detach_reason_ = OnDetach::REASON_CANCELED_BY_USER;
273 } 286 }
274 287
275 void ExtensionDevToolsClientHost::SendDetachedEvent() { 288 void ExtensionDevToolsClientHost::SendDetachedEvent() {
276 Profile* profile = 289 Profile* profile =
277 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 290 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
278 if (profile != NULL && 291 if (profile != NULL &&
279 extensions::ExtensionSystem::Get(profile)->event_router()) { 292 extensions::ExtensionSystem::Get(profile)->event_router()) {
280 Debuggee debuggee; 293 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_)); 294 detach_reason_));
284 scoped_ptr<extensions::Event> event(new extensions::Event( 295 scoped_ptr<extensions::Event> event(new extensions::Event(
285 keys::kOnDetach, args.Pass())); 296 keys::kOnDetach, args.Pass()));
286 event->restrict_to_profile = profile; 297 event->restrict_to_profile = profile;
287 extensions::ExtensionSystem::Get(profile)->event_router()-> 298 extensions::ExtensionSystem::Get(profile)->event_router()->
288 DispatchEventToExtension(extension_id_, event.Pass()); 299 DispatchEventToExtension(extension_id_, event.Pass());
289 } 300 }
290 } 301 }
291 302
292 void ExtensionDevToolsClientHost::Observe( 303 void ExtensionDevToolsClientHost::Observe(
(...skipping 29 matching lines...) Expand all
322 if (!result->IsType(Value::TYPE_DICTIONARY)) 333 if (!result->IsType(Value::TYPE_DICTIONARY))
323 return; 334 return;
324 DictionaryValue* dictionary = static_cast<DictionaryValue*>(result.get()); 335 DictionaryValue* dictionary = static_cast<DictionaryValue*>(result.get());
325 336
326 int id; 337 int id;
327 if (!dictionary->GetInteger("id", &id)) { 338 if (!dictionary->GetInteger("id", &id)) {
328 std::string method_name; 339 std::string method_name;
329 if (!dictionary->GetString("method", &method_name)) 340 if (!dictionary->GetString("method", &method_name))
330 return; 341 return;
331 342
332 Debuggee debuggee;
333 debuggee.tab_id = tab_id_;
334
335 OnEvent::Params params; 343 OnEvent::Params params;
336 DictionaryValue* params_value; 344 DictionaryValue* params_value;
337 if (dictionary->GetDictionary("params", &params_value)) 345 if (dictionary->GetDictionary("params", &params_value))
338 params.additional_properties.Swap(params_value); 346 params.additional_properties.Swap(params_value);
339 347
340 scoped_ptr<ListValue> args(OnEvent::Create(debuggee, method_name, params)); 348 scoped_ptr<ListValue> args(OnEvent::Create(debuggee_, method_name, params));
341 scoped_ptr<extensions::Event> event(new extensions::Event( 349 scoped_ptr<extensions::Event> event(new extensions::Event(
342 keys::kOnEvent, args.Pass())); 350 keys::kOnEvent, args.Pass()));
343 event->restrict_to_profile = profile; 351 event->restrict_to_profile = profile;
344 extensions::ExtensionSystem::Get(profile)->event_router()-> 352 extensions::ExtensionSystem::Get(profile)->event_router()->
345 DispatchEventToExtension(extension_id_, event.Pass()); 353 DispatchEventToExtension(extension_id_, event.Pass());
346 } else { 354 } else {
347 DebuggerSendCommandFunction* function = pending_requests_[id]; 355 DebuggerSendCommandFunction* function = pending_requests_[id];
348 if (!function) 356 if (!function)
349 return; 357 return;
350 358
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 412 }
405 413
406 bool ExtensionDevToolsInfoBarDelegate::Cancel() { 414 bool ExtensionDevToolsInfoBarDelegate::Cancel() {
407 if (client_host_) 415 if (client_host_)
408 client_host_->MarkAsDismissed(); 416 client_host_->MarkAsDismissed();
409 return true; 417 return true;
410 } 418 }
411 419
412 DebuggerFunction::DebuggerFunction() 420 DebuggerFunction::DebuggerFunction()
413 : contents_(0), 421 : contents_(0),
414 tab_id_(0), 422 debuggee_tab_id_(0),
415 client_host_(0) { 423 client_host_(0) {
416 } 424 }
417 425
426 std::string DebuggerFunction::GetTargetTypeString() {
pfeldman 2013/02/20 10:01:05 You only use these two to report the error. You co
Vladislav Kaznacheev 2013/02/20 12:02:26 Done.
427 if (debuggee_tab_id_)
428 return keys::kTabTargetType;
429 else
430 return keys::kExtensionTargetType;
431 }
432
433 std::string DebuggerFunction::GetTargetIdString() {
434 if (debuggee_tab_id_)
435 return base::IntToString(debuggee_tab_id_);
436 else
437 return debuggee_extension_id_;
438 }
439
440 WebContents* FindWebContentsForExtension(
pfeldman 2013/02/20 10:01:05 static
Vladislav Kaznacheev 2013/02/20 12:02:26 Done.
441 const extensions::Extension* extension) {
442 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
pfeldman 2013/02/20 10:01:05 Ok, this is the 3rd time it is used for inspector.
Vladislav Kaznacheev 2013/02/20 12:02:26 Filed a separate bug for that: https://code.google
443 !it.IsAtEnd(); it.Advance()) {
444 RenderProcessHost* render_process_host = it.GetCurrentValue();
445 DCHECK(render_process_host);
446
447 // Ignore processes that don't have a connection, such as crashed tabs.
448 if (!render_process_host->HasConnection())
449 continue;
450
451 RenderProcessHost::RenderWidgetHostsIterator rwit(
452 render_process_host->GetRenderWidgetHostsIterator());
453 for (; !rwit.IsAtEnd(); rwit.Advance()) {
454 const RenderWidgetHost* widget = rwit.GetCurrentValue();
455 DCHECK(widget);
456 if (!widget || !widget->IsRenderView())
457 continue;
458
459 RenderViewHost* rvh =
460 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
461
462 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
463 if (web_contents) {
464 GURL url = web_contents->GetURL();
465 if (url.host() == extension->id()) {
466 return web_contents;
467 }
468 }
469 }
470 }
471 return NULL;
472 }
473
418 bool DebuggerFunction::InitWebContents() { 474 bool DebuggerFunction::InitWebContents() {
419 // Find the WebContents that contains this tab id. 475 // Find the WebContents that contains this tab id.
420 contents_ = NULL; 476 contents_ = NULL;
421 WebContents* web_contents = NULL; 477 if (debuggee_tab_id_) {
422 bool result = ExtensionTabUtil::GetTabById( 478 WebContents* web_contents = NULL;
pfeldman 2013/02/20 10:01:05 This could be extracted as FindWebContentsForTabId
Vladislav Kaznacheev 2013/02/20 12:02:26 As discussed offline it does not really provide an
423 tab_id_, profile(), include_incognito(), NULL, NULL, &web_contents, NULL); 479 bool result = ExtensionTabUtil::GetTabById(debuggee_tab_id_, profile(),
424 if (!result || !web_contents) { 480 include_incognito(), NULL, NULL, &web_contents, NULL);
481 if (!result || !web_contents) {
482 error_ = ErrorUtils::FormatErrorMessage(
483 keys::kNoTargetError,
484 GetTargetTypeString(),
485 GetTargetIdString());
486 return false;
487 }
488 contents_ = web_contents;
489
490 if (content::HasWebUIScheme(contents_->GetURL())) {
491 error_ = ErrorUtils::FormatErrorMessage(
492 keys::kAttachToWebUIError,
493 contents_->GetURL().scheme());
494 return false;
495 }
496
497 return true;
498 }
499
500 if (debuggee_extension_id_.size()) {
501 const extensions::Extension* extension = profile()->GetExtensionService()->
502 extensions()->GetByID(debuggee_extension_id_);
503 if (extension) {
504 contents_ = FindWebContentsForExtension(extension);
505 if (contents_)
506 return true;
507 }
508
425 error_ = ErrorUtils::FormatErrorMessage( 509 error_ = ErrorUtils::FormatErrorMessage(
426 keys::kNoTabError, 510 keys::kNoTargetError,
427 base::IntToString(tab_id_)); 511 GetTargetTypeString(),
428 return false; 512 GetTargetIdString());
429 }
430 contents_ = web_contents;
431
432 if (content::HasWebUIScheme(contents_->GetURL())) {
433 error_ = ErrorUtils::FormatErrorMessage(
434 keys::kAttachToWebUIError,
435 contents_->GetURL().scheme());
436 return false; 513 return false;
437 } 514 }
438 515
439 return true; 516 error_ = keys::kInvalidTargetError;
517 return false;
440 } 518 }
441 519
442 bool DebuggerFunction::InitClientHost() { 520 bool DebuggerFunction::InitClientHost() {
443 if (!InitWebContents()) 521 if (!InitWebContents())
444 return false; 522 return false;
445 523
446 // Don't fetch rvh from the contents since it'll be wrong upon navigation. 524 // Don't fetch rvh from the contents since it'll be wrong upon navigation.
447 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_); 525 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_);
448 526
449 if (!client_host_ || 527 if (!client_host_ ||
450 !client_host_->MatchesContentsAndExtensionId(contents_, 528 !client_host_->MatchesContentsAndExtensionId(contents_,
451 GetExtension()->id())) { 529 GetExtension()->id())) {
452 error_ = ErrorUtils::FormatErrorMessage( 530 error_ = ErrorUtils::FormatErrorMessage(
453 keys::kNotAttachedError, 531 keys::kNotAttachedError,
454 base::IntToString(tab_id_)); 532 GetTargetTypeString(),
533 GetTargetIdString());
455 return false; 534 return false;
456 } 535 }
457 return true; 536 return true;
458 } 537 }
459 538
460 DebuggerAttachFunction::DebuggerAttachFunction() {} 539 DebuggerAttachFunction::DebuggerAttachFunction() {}
461 540
462 DebuggerAttachFunction::~DebuggerAttachFunction() {} 541 DebuggerAttachFunction::~DebuggerAttachFunction() {}
463 542
464 bool DebuggerAttachFunction::RunImpl() { 543 bool DebuggerAttachFunction::RunImpl() {
465 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_)); 544 scoped_ptr<Attach::Params> params(Attach::Params::Create(*args_));
466 EXTENSION_FUNCTION_VALIDATE(params.get()); 545 EXTENSION_FUNCTION_VALIDATE(params.get());
467 546
468 tab_id_ = params->target.tab_id; 547 if (params->target.tab_id)
548 debuggee_tab_id_ = *params->target.tab_id;
549 if (params->target.extension_id)
550 debuggee_extension_id_ = *params->target.extension_id;
469 if (!InitWebContents()) 551 if (!InitWebContents())
470 return false; 552 return false;
471 553
472 if (!webkit_glue::IsInspectorProtocolVersionSupported( 554 if (!webkit_glue::IsInspectorProtocolVersionSupported(
473 params->required_version)) { 555 params->required_version)) {
474 error_ = ErrorUtils::FormatErrorMessage( 556 error_ = ErrorUtils::FormatErrorMessage(
475 keys::kProtocolVersionNotSupportedError, 557 keys::kProtocolVersionNotSupportedError,
476 params->required_version); 558 params->required_version);
477 return false; 559 return false;
478 } 560 }
479 561
480 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( 562 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor(
481 contents_->GetRenderViewHost())); 563 contents_->GetRenderViewHost()));
482 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> 564 DevToolsClientHost* client_host = DevToolsManager::GetInstance()->
483 GetDevToolsClientHostFor(agent); 565 GetDevToolsClientHostFor(agent);
484 566
485 if (client_host != NULL) { 567 if (client_host != NULL) {
486 error_ = ErrorUtils::FormatErrorMessage( 568 error_ = ErrorUtils::FormatErrorMessage(
487 keys::kAlreadyAttachedError, 569 keys::kAlreadyAttachedError,
488 base::IntToString(tab_id_)); 570 GetTargetTypeString(),
571 GetTargetIdString());
489 return false; 572 return false;
490 } 573 }
491 574
492 new ExtensionDevToolsClientHost(contents_, 575 new ExtensionDevToolsClientHost(contents_,
pfeldman 2013/02/20 10:01:05 Can't you clone the target? Isn't it the Debuggee
Vladislav Kaznacheev 2013/02/20 12:02:26 I tried. The copy constructor of this class is pri
493 GetExtension()->id(), 576 GetExtension()->id(),
494 GetExtension()->name(), 577 GetExtension()->name(),
495 tab_id_); 578 debuggee_tab_id_,
579 debuggee_extension_id_);
496 SendResponse(true); 580 SendResponse(true);
497 return true; 581 return true;
498 } 582 }
499 583
500 DebuggerDetachFunction::DebuggerDetachFunction() {} 584 DebuggerDetachFunction::DebuggerDetachFunction() {}
501 585
502 DebuggerDetachFunction::~DebuggerDetachFunction() {} 586 DebuggerDetachFunction::~DebuggerDetachFunction() {}
503 587
504 bool DebuggerDetachFunction::RunImpl() { 588 bool DebuggerDetachFunction::RunImpl() {
505 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_)); 589 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_));
506 EXTENSION_FUNCTION_VALIDATE(params.get()); 590 EXTENSION_FUNCTION_VALIDATE(params.get());
507 591
508 tab_id_ = params->target.tab_id; 592 if (params->target.tab_id)
593 debuggee_tab_id_ = *params->target.tab_id;
594 if (params->target.extension_id)
595 debuggee_extension_id_ = *params->target.extension_id;
509 if (!InitClientHost()) 596 if (!InitClientHost())
510 return false; 597 return false;
511 598
512 client_host_->Close(); 599 client_host_->Close();
513 SendResponse(true); 600 SendResponse(true);
514 return true; 601 return true;
515 } 602 }
516 603
517 DebuggerSendCommandFunction::DebuggerSendCommandFunction() {} 604 DebuggerSendCommandFunction::DebuggerSendCommandFunction() {}
518 605
519 DebuggerSendCommandFunction::~DebuggerSendCommandFunction() {} 606 DebuggerSendCommandFunction::~DebuggerSendCommandFunction() {}
520 607
521 bool DebuggerSendCommandFunction::RunImpl() { 608 bool DebuggerSendCommandFunction::RunImpl() {
522 scoped_ptr<SendCommand::Params> params(SendCommand::Params::Create(*args_)); 609 scoped_ptr<SendCommand::Params> params(SendCommand::Params::Create(*args_));
523 EXTENSION_FUNCTION_VALIDATE(params.get()); 610 EXTENSION_FUNCTION_VALIDATE(params.get());
524 611
525 tab_id_ = params->target.tab_id; 612 if (params->target.tab_id)
613 debuggee_tab_id_ = *params->target.tab_id;
614 if (params->target.extension_id)
615 debuggee_extension_id_ = *params->target.extension_id;
526 if (!InitClientHost()) 616 if (!InitClientHost())
527 return false; 617 return false;
528 618
529 client_host_->SendMessageToBackend(this, params->method, 619 client_host_->SendMessageToBackend(this, params->method,
530 params->command_params.get()); 620 params->command_params.get());
531 return true; 621 return true;
532 } 622 }
533 623
534 void DebuggerSendCommandFunction::SendResponseBody( 624 void DebuggerSendCommandFunction::SendResponseBody(
535 DictionaryValue* response) { 625 DictionaryValue* response) {
536 Value* error_body; 626 Value* error_body;
537 if (response->Get("error", &error_body)) { 627 if (response->Get("error", &error_body)) {
538 base::JSONWriter::Write(error_body, &error_); 628 base::JSONWriter::Write(error_body, &error_);
539 SendResponse(false); 629 SendResponse(false);
540 return; 630 return;
541 } 631 }
542 632
543 DictionaryValue* result_body; 633 DictionaryValue* result_body;
544 SendCommand::Results::Result result; 634 SendCommand::Results::Result result;
545 if (response->GetDictionary("result", &result_body)) 635 if (response->GetDictionary("result", &result_body))
546 result.additional_properties.Swap(result_body); 636 result.additional_properties.Swap(result_body);
547 637
548 results_ = SendCommand::Results::Create(result); 638 results_ = SendCommand::Results::Create(result);
549 SendResponse(true); 639 SendResponse(true);
550 } 640 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/debugger/debugger_api.h ('k') | chrome/browser/extensions/api/debugger/debugger_api_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698