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

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

Issue 12377047: Add chrome.debugger.getTargets method to discover available debug targets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@targets
Patch Set: Rebase Created 7 years, 9 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>
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/infobars/infobar.h" 27 #include "chrome/browser/infobars/infobar.h"
28 #include "chrome/browser/infobars/infobar_service.h" 28 #include "chrome/browser/infobars/infobar_service.h"
29 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 30 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
31 #include "chrome/common/chrome_notification_types.h" 31 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/chrome_switches.h" 32 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/extensions/extension.h" 33 #include "chrome/common/extensions/extension.h"
34 #include "content/public/browser/devtools_agent_host.h" 34 #include "content/public/browser/devtools_agent_host.h"
35 #include "content/public/browser/devtools_client_host.h" 35 #include "content/public/browser/devtools_client_host.h"
36 #include "content/public/browser/devtools_manager.h" 36 #include "content/public/browser/devtools_manager.h"
37 #include "content/public/browser/favicon_status.h"
38 #include "content/public/browser/navigation_entry.h"
37 #include "content/public/browser/notification_service.h" 39 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/notification_source.h" 40 #include "content/public/browser/notification_source.h"
39 #include "content/public/browser/render_process_host.h" 41 #include "content/public/browser/render_process_host.h"
40 #include "content/public/browser/render_view_host.h" 42 #include "content/public/browser/render_view_host.h"
41 #include "content/public/browser/render_widget_host.h" 43 #include "content/public/browser/render_widget_host.h"
42 #include "content/public/browser/web_contents.h" 44 #include "content/public/browser/web_contents.h"
43 #include "content/public/common/content_client.h" 45 #include "content/public/common/content_client.h"
44 #include "content/public/common/url_constants.h" 46 #include "content/public/common/url_constants.h"
45 #include "extensions/common/error_utils.h" 47 #include "extensions/common/error_utils.h"
46 #include "grit/generated_resources.h" 48 #include "grit/generated_resources.h"
(...skipping 16 matching lines...) Expand all
63 namespace OnEvent = extensions::api::debugger::OnEvent; 65 namespace OnEvent = extensions::api::debugger::OnEvent;
64 namespace SendCommand = extensions::api::debugger::SendCommand; 66 namespace SendCommand = extensions::api::debugger::SendCommand;
65 67
66 class ExtensionDevToolsClientHost; 68 class ExtensionDevToolsClientHost;
67 69
68 class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate { 70 class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate {
69 public: 71 public:
70 // Creates an extension dev tools delegate and adds it to |infobar_service|. 72 // Creates an extension dev tools delegate and adds it to |infobar_service|.
71 // Returns a pointer to the delegate if it was successfully added. 73 // Returns a pointer to the delegate if it was successfully added.
72 static ExtensionDevToolsInfoBarDelegate* Create( 74 static ExtensionDevToolsInfoBarDelegate* Create(
73 InfoBarService* infobar_service, 75 WebContents* web_contents,
74 const std::string& client_name, 76 const std::string& client_name);
75 ExtensionDevToolsClientHost* client_host); 77
78 // Associates DevToolsClientHost with this infobar delegate.
79 void AttachClientHost(ExtensionDevToolsClientHost* client_host);
76 80
77 // Notifies infobar delegate that associated DevToolsClientHost will be 81 // Notifies infobar delegate that associated DevToolsClientHost will be
78 // destroyed. 82 // destroyed.
79 void DiscardClientHost(); 83 void DiscardClientHost();
80 84
81 private: 85 private:
82 ExtensionDevToolsInfoBarDelegate( 86 ExtensionDevToolsInfoBarDelegate(InfoBarService* infobar_service,
83 InfoBarService* infobar_service, 87 const std::string& client_name);
84 const std::string& client_name,
85 ExtensionDevToolsClientHost* client_host);
86 virtual ~ExtensionDevToolsInfoBarDelegate(); 88 virtual ~ExtensionDevToolsInfoBarDelegate();
87 89
88 // ConfirmInfoBarDelegate: 90 // ConfirmInfoBarDelegate:
89 virtual int GetButtons() const OVERRIDE; 91 virtual int GetButtons() const OVERRIDE;
90 virtual Type GetInfoBarType() const OVERRIDE; 92 virtual Type GetInfoBarType() const OVERRIDE;
91 virtual bool ShouldExpireInternal( 93 virtual bool ShouldExpireInternal(
92 const content::LoadCommittedDetails& details) const OVERRIDE; 94 const content::LoadCommittedDetails& details) const OVERRIDE;
93 virtual string16 GetMessageText() const OVERRIDE; 95 virtual string16 GetMessageText() const OVERRIDE;
94 virtual void InfoBarDismissed() OVERRIDE; 96 virtual void InfoBarDismissed() OVERRIDE;
95 virtual bool Cancel() OVERRIDE; 97 virtual bool Cancel() OVERRIDE;
96 98
97 std::string client_name_; 99 std::string client_name_;
98 ExtensionDevToolsClientHost* client_host_; 100 ExtensionDevToolsClientHost* client_host_;
99 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate); 101 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate);
100 }; 102 };
101 103
102 class ExtensionDevToolsClientHost : public DevToolsClientHost, 104 class ExtensionDevToolsClientHost : public DevToolsClientHost,
103 public content::NotificationObserver { 105 public content::NotificationObserver {
104 public: 106 public:
105 ExtensionDevToolsClientHost(WebContents* web_contents, 107 ExtensionDevToolsClientHost(
106 const std::string& extension_id, 108 WebContents* web_contents,
107 const std::string& extension_name, 109 const std::string& extension_id,
108 const Debuggee& debuggee); 110 const std::string& extension_name,
111 const Debuggee& debuggee,
112 ExtensionDevToolsInfoBarDelegate* infobar_delegate);
109 113
110 virtual ~ExtensionDevToolsClientHost(); 114 virtual ~ExtensionDevToolsClientHost();
111 115
112 bool MatchesContentsAndExtensionId(WebContents* web_contents, 116 bool MatchesContentsAndExtensionId(WebContents* web_contents,
113 const std::string& extension_id); 117 const std::string& extension_id);
114 void Close(); 118 void Close();
115 void SendMessageToBackend(DebuggerSendCommandFunction* function, 119 void SendMessageToBackend(DebuggerSendCommandFunction* function,
116 const std::string& method, 120 const std::string& method,
117 SendCommand::Params::CommandParams* command_params); 121 SendCommand::Params::CommandParams* command_params);
118 122
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 if (rvh && WebContents::FromRenderViewHost(rvh) == contents) 180 if (rvh && WebContents::FromRenderViewHost(rvh) == contents)
177 return static_cast<ExtensionDevToolsClientHost*>(*it); 181 return static_cast<ExtensionDevToolsClientHost*>(*it);
178 } 182 }
179 return NULL; 183 return NULL;
180 } 184 }
181 185
182 private: 186 private:
183 std::set<DevToolsClientHost*> client_hosts_; 187 std::set<DevToolsClientHost*> client_hosts_;
184 }; 188 };
185 189
190 static extensions::ExtensionHost* GetExtensionBackgroundHost(
191 WebContents* web_contents) {
192 Profile* profile =
193 Profile::FromBrowserContext(web_contents->GetBrowserContext());
194 if (!profile)
195 return NULL;
196
197 extensions::ExtensionHost* extension_host =
198 extensions::ExtensionSystem::Get(profile)->process_manager()->
199 GetBackgroundHostForExtension(web_contents->GetURL().host());
200
201 if (extension_host && extension_host->host_contents() == web_contents)
202 return extension_host;
203
204 return NULL;
205 }
206
207 static const char kTargetIdField[] = "id";
208 static const char kTargetTypeField[] = "type";
209 static const char kTargetTitleField[] = "title";
210 static const char kTargetAttachedField[] = "attached";
211 static const char kTargetUrlField[] = "url";
212 static const char kTargetFaviconUrlField[] = "favicon_url";
213
214 static const char kTargetTypePage[] = "page";
215 static const char kTargetTypeBackgroundPage[] = "background_page";
Matt Perry 2013/03/27 23:29:56 this is redundant with the debugger_api_constants,
Vladislav Kaznacheev 2013/03/28 15:07:41 Not really. This one is sort of an enum value, the
216
217 static base::Value* SerializePageInfo(RenderViewHost* rvh) {
218 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
219 if (!web_contents)
220 return NULL;
221
222 DevToolsAgentHost* agent_host = DevToolsAgentHost::GetOrCreateFor(rvh);
223
224 base::DictionaryValue* dictionary = new base::DictionaryValue();
225
226 dictionary->SetString(kTargetIdField, agent_host->GetId());
227 dictionary->SetBoolean(kTargetAttachedField,
228 !!DevToolsManager::GetInstance()->GetDevToolsClientHostFor(agent_host));
229 dictionary->SetString(kTargetUrlField, web_contents->GetURL().spec());
230
231
232 extensions::ExtensionHost* extension_host =
233 GetExtensionBackgroundHost(web_contents);
234 if (extension_host) {
235 // This RenderViewHost belongs to a background page.
236 dictionary->SetString(kTargetTypeField, kTargetTypeBackgroundPage);
237 dictionary->SetString(kTargetTitleField,
238 extension_host->extension()->name());
239 } else {
240 // This RenderViewHost belongs to a regular page.
241 dictionary->SetString(kTargetTypeField, kTargetTypePage);
242 dictionary->SetString(kTargetTitleField,
243 UTF16ToUTF8(net::EscapeForHTML(web_contents->GetTitle())));
244
245 content::NavigationController& controller = web_contents->GetController();
246 content::NavigationEntry* entry = controller.GetActiveEntry();
247 if (entry != NULL && entry->GetURL().is_valid()) {
248 dictionary->SetString(kTargetFaviconUrlField,
249 entry->GetFavicon().url.spec());
250 }
251 }
252
253 return dictionary;
254 }
255
186 } // namespace 256 } // namespace
187 257
188 static void CopyDebuggee(Debuggee & dst, const Debuggee& src) { 258 static void CopyDebuggee(Debuggee & dst, const Debuggee& src) {
189 if (src.tab_id) 259 if (src.tab_id)
190 dst.tab_id.reset(new int(*src.tab_id)); 260 dst.tab_id.reset(new int(*src.tab_id));
191 if (src.extension_id) 261 if (src.extension_id)
192 dst.extension_id.reset(new std::string(*src.extension_id)); 262 dst.extension_id.reset(new std::string(*src.extension_id));
263 if (src.target_id)
264 dst.target_id.reset(new std::string(*src.target_id));
193 } 265 }
194 266
195 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( 267 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost(
196 WebContents* web_contents, 268 WebContents* web_contents,
197 const std::string& extension_id, 269 const std::string& extension_id,
198 const std::string& extension_name, 270 const std::string& extension_name,
199 const Debuggee& debuggee) 271 const Debuggee& debuggee,
272 ExtensionDevToolsInfoBarDelegate* infobar_delegate)
200 : web_contents_(web_contents), 273 : web_contents_(web_contents),
201 extension_id_(extension_id), 274 extension_id_(extension_id),
202 last_request_id_(0), 275 last_request_id_(0),
203 infobar_delegate_(NULL), 276 infobar_delegate_(infobar_delegate),
204 detach_reason_(OnDetach::REASON_TARGET_CLOSED) { 277 detach_reason_(OnDetach::REASON_TARGET_CLOSED) {
205 CopyDebuggee(debuggee_, debuggee); 278 CopyDebuggee(debuggee_, debuggee);
206 279
207 AttachedClientHosts::GetInstance()->Add(this); 280 AttachedClientHosts::GetInstance()->Add(this);
208 281
209 // Detach from debugger when extension unloads. 282 // Detach from debugger when extension unloads.
210 Profile* profile = 283 Profile* profile =
211 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 284 Profile::FromBrowserContext(web_contents_->GetBrowserContext());
212 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 285 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
213 content::Source<Profile>(profile)); 286 content::Source<Profile>(profile));
214 287
215 // Attach to debugger and tell it we are ready. 288 // Attach to debugger and tell it we are ready.
216 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor( 289 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor(
217 web_contents_->GetRenderViewHost())); 290 web_contents_->GetRenderViewHost()));
218 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); 291 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this);
219 292
220 if (!CommandLine::ForCurrentProcess()-> 293 if (infobar_delegate_) {
221 HasSwitch(switches::kSilentDebuggerExtensionAPI)) { 294 infobar_delegate_->AttachClientHost(this);
222 InfoBarService* infobar_service = 295 registrar_.Add(this,
223 InfoBarService::FromWebContents(web_contents_); 296 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
224 infobar_delegate_ = ExtensionDevToolsInfoBarDelegate::Create( 297 content::Source<InfoBarService>(infobar_delegate_->owner()));
225 infobar_service, extension_name, this);
226 if (infobar_delegate_) {
227 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
228 content::Source<InfoBarService>(infobar_service));
229 }
230 } 298 }
231 } 299 }
232 300
233 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { 301 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() {
234 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to 302 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to
235 // Close() us. 303 // Close() us.
236 registrar_.RemoveAll(); 304 registrar_.RemoveAll();
237 305
238 if (infobar_delegate_) { 306 if (infobar_delegate_) {
239 infobar_delegate_->DiscardClientHost(); 307 infobar_delegate_->DiscardClientHost();
240 InfoBarService* infobar_service = 308 if (infobar_delegate_->owner())
241 InfoBarService::FromWebContents(web_contents_); 309 infobar_delegate_->owner()->RemoveInfoBar(infobar_delegate_);
242 if (infobar_service)
243 infobar_service->RemoveInfoBar(infobar_delegate_);
244 } 310 }
245 AttachedClientHosts::GetInstance()->Remove(this); 311 AttachedClientHosts::GetInstance()->Remove(this);
246 } 312 }
247 313
248 bool ExtensionDevToolsClientHost::MatchesContentsAndExtensionId( 314 bool ExtensionDevToolsClientHost::MatchesContentsAndExtensionId(
249 WebContents* web_contents, 315 WebContents* web_contents,
250 const std::string& extension_id) { 316 const std::string& extension_id) {
251 return web_contents == web_contents_ && extension_id_ == extension_id; 317 return web_contents == web_contents_ && extension_id_ == extension_id;
252 } 318 }
253 319
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 if (!function) 426 if (!function)
361 return; 427 return;
362 428
363 function->SendResponseBody(dictionary); 429 function->SendResponseBody(dictionary);
364 pending_requests_.erase(id); 430 pending_requests_.erase(id);
365 } 431 }
366 } 432 }
367 433
368 // static 434 // static
369 ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create( 435 ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create(
370 InfoBarService* infobar_service, 436 WebContents* web_contents,
371 const std::string& client_name, 437 const std::string& client_name) {
372 ExtensionDevToolsClientHost* client_host) { 438 InfoBarService* infobar_service =
439 InfoBarService::FromWebContents(web_contents);
440 if (!infobar_service)
441 return NULL;
373 return static_cast<ExtensionDevToolsInfoBarDelegate*>( 442 return static_cast<ExtensionDevToolsInfoBarDelegate*>(
374 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( 443 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
375 new ExtensionDevToolsInfoBarDelegate(infobar_service, client_name, 444 new ExtensionDevToolsInfoBarDelegate(infobar_service, client_name))));
376 client_host)))); 445 }
446
447 void ExtensionDevToolsInfoBarDelegate::AttachClientHost(
448 ExtensionDevToolsClientHost* client_host) {
449 client_host_ = client_host;
377 } 450 }
378 451
379 void ExtensionDevToolsInfoBarDelegate::DiscardClientHost() { 452 void ExtensionDevToolsInfoBarDelegate::DiscardClientHost() {
380 client_host_ = NULL; 453 client_host_ = NULL;
381 } 454 }
382 455
383 ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate( 456 ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate(
384 InfoBarService* infobar_service, 457 InfoBarService* infobar_service,
385 const std::string& client_name, 458 const std::string& client_name)
386 ExtensionDevToolsClientHost* client_host)
387 : ConfirmInfoBarDelegate(infobar_service), 459 : ConfirmInfoBarDelegate(infobar_service),
388 client_name_(client_name), 460 client_name_(client_name),
389 client_host_(client_host) { 461 client_host_(NULL) {
390 } 462 }
391 463
392 ExtensionDevToolsInfoBarDelegate::~ExtensionDevToolsInfoBarDelegate() { 464 ExtensionDevToolsInfoBarDelegate::~ExtensionDevToolsInfoBarDelegate() {
393 } 465 }
394 466
395 int ExtensionDevToolsInfoBarDelegate::GetButtons() const { 467 int ExtensionDevToolsInfoBarDelegate::GetButtons() const {
396 return BUTTON_CANCEL; 468 return BUTTON_CANCEL;
397 } 469 }
398 470
399 InfoBarDelegate::Type ExtensionDevToolsInfoBarDelegate::GetInfoBarType() const { 471 InfoBarDelegate::Type ExtensionDevToolsInfoBarDelegate::GetInfoBarType() const {
(...skipping 20 matching lines...) Expand all
420 client_host_->MarkAsDismissed(); 492 client_host_->MarkAsDismissed();
421 return true; 493 return true;
422 } 494 }
423 495
424 DebuggerFunction::DebuggerFunction() 496 DebuggerFunction::DebuggerFunction()
425 : contents_(0), 497 : contents_(0),
426 client_host_(0) { 498 client_host_(0) {
427 } 499 }
428 500
429 void DebuggerFunction::FormatErrorMessage(const std::string& format) { 501 void DebuggerFunction::FormatErrorMessage(const std::string& format) {
430 error_ = ErrorUtils::FormatErrorMessage( 502 if (debuggee_.tab_id)
431 format, 503 error_ = ErrorUtils::FormatErrorMessage(
432 debuggee_.tab_id ? 504 format, keys::kTabTargetType, base::IntToString(*debuggee_.tab_id));
433 keys::kTabTargetType : 505 else if (debuggee_.extension_id)
434 keys::kExtensionTargetType, 506 error_ = ErrorUtils::FormatErrorMessage(
435 debuggee_.tab_id ? 507 format, keys::kBackgroundPageTargetType, *debuggee_.extension_id);
436 base::IntToString(*debuggee_.tab_id) : 508 else
437 *debuggee_.extension_id); 509 error_ = ErrorUtils::FormatErrorMessage(
510 format, keys::kOpaqueTargetType, *debuggee_.target_id);
438 } 511 }
439 512
440 bool DebuggerFunction::InitWebContents() { 513 bool DebuggerFunction::InitWebContents() {
441 // Find the WebContents that contains this tab id.
442 contents_ = NULL;
443 if (debuggee_.tab_id) { 514 if (debuggee_.tab_id) {
444 WebContents* web_contents = NULL; 515 WebContents* web_contents = NULL;
445 bool result = ExtensionTabUtil::GetTabById( 516 bool result = ExtensionTabUtil::GetTabById(
446 *debuggee_.tab_id, profile(), include_incognito(), NULL, NULL, 517 *debuggee_.tab_id, profile(), include_incognito(), NULL, NULL,
447 &web_contents, NULL); 518 &web_contents, NULL);
448 if (!result || !web_contents) { 519 if (result && web_contents) {
449 FormatErrorMessage(keys::kNoTargetError); 520 if (content::HasWebUIScheme(web_contents->GetURL())) {
450 return false; 521 error_ = ErrorUtils::FormatErrorMessage(
522 keys::kAttachToWebUIError,
523 web_contents->GetURL().scheme());
524 return false;
525 }
526 contents_ = web_contents;
451 } 527 }
452 contents_ = web_contents; 528 } else if (debuggee_.extension_id) {
453 529 extensions::ExtensionHost* extension_host =
454 if (content::HasWebUIScheme(contents_->GetURL())) { 530 extensions::ExtensionSystem::Get(profile())->process_manager()->
455 error_ = ErrorUtils::FormatErrorMessage( 531 GetBackgroundHostForExtension(*debuggee_.extension_id);
456 keys::kAttachToWebUIError, 532 if (extension_host) {
457 contents_->GetURL().scheme()); 533 contents_ = WebContents::FromRenderViewHost(
458 return false; 534 extension_host->render_view_host());
459 } 535 }
460 536 } else if (debuggee_.target_id) {
461 return true; 537 DevToolsAgentHost* agent_host =
538 DevToolsAgentHost::GetForId(*debuggee_.target_id);
539 if (agent_host) {
540 contents_ = WebContents::FromRenderViewHost(
541 agent_host->GetRenderViewHost());
542 }
543 } else {
544 error_ = keys::kInvalidTargetError;
545 return false;
462 } 546 }
463 547
464 if (debuggee_.extension_id) { 548 if (!contents_) {
465 if (!CommandLine::ForCurrentProcess()->
466 HasSwitch(switches::kSilentDebuggerExtensionAPI)) {
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); 549 FormatErrorMessage(keys::kNoTargetError);
483 return false; 550 return false;
484 } 551 }
485 552 return true;
486 error_ = keys::kInvalidTargetError;
487 return false;
488 } 553 }
489 554
490 bool DebuggerFunction::InitClientHost() { 555 bool DebuggerFunction::InitClientHost() {
491 if (!InitWebContents()) 556 if (!InitWebContents())
492 return false; 557 return false;
493 558
494 // Don't fetch rvh from the contents since it'll be wrong upon navigation. 559 // Don't fetch rvh from the contents since it'll be wrong upon navigation.
495 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_); 560 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_);
496 561
497 if (!client_host_ || 562 if (!client_host_ ||
(...skipping 28 matching lines...) Expand all
526 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor( 591 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor(
527 contents_->GetRenderViewHost())); 592 contents_->GetRenderViewHost()));
528 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> 593 DevToolsClientHost* client_host = DevToolsManager::GetInstance()->
529 GetDevToolsClientHostFor(agent); 594 GetDevToolsClientHostFor(agent);
530 595
531 if (client_host != NULL) { 596 if (client_host != NULL) {
532 FormatErrorMessage(keys::kAlreadyAttachedError); 597 FormatErrorMessage(keys::kAlreadyAttachedError);
533 return false; 598 return false;
534 } 599 }
535 600
601 ExtensionDevToolsInfoBarDelegate* infobar_delegate = NULL;
602
603 if (!CommandLine::ForCurrentProcess()->
604 HasSwitch(switches::kSilentDebuggerExtensionAPI)) {
605 // Do not attach to the target if for any reason the infobar cannot be shown
606 // for this WebContents instance.
607 infobar_delegate = ExtensionDevToolsInfoBarDelegate::Create(
608 contents_, GetExtension()->name());
609 if (!infobar_delegate) {
610 error_ = ErrorUtils::FormatErrorMessage(
611 keys::kSilentDebuggingRequired,
612 switches::kSilentDebuggerExtensionAPI);
613 return false;
614 }
615 }
616
536 new ExtensionDevToolsClientHost(contents_, 617 new ExtensionDevToolsClientHost(contents_,
537 GetExtension()->id(), 618 GetExtension()->id(),
538 GetExtension()->name(), 619 GetExtension()->name(),
539 debuggee_); 620 debuggee_,
621 infobar_delegate);
540 SendResponse(true); 622 SendResponse(true);
541 return true; 623 return true;
542 } 624 }
543 625
544 DebuggerDetachFunction::DebuggerDetachFunction() {} 626 DebuggerDetachFunction::DebuggerDetachFunction() {}
545 627
546 DebuggerDetachFunction::~DebuggerDetachFunction() {} 628 DebuggerDetachFunction::~DebuggerDetachFunction() {}
547 629
548 bool DebuggerDetachFunction::RunImpl() { 630 bool DebuggerDetachFunction::RunImpl() {
549 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_)); 631 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 } 667 }
586 668
587 DictionaryValue* result_body; 669 DictionaryValue* result_body;
588 SendCommand::Results::Result result; 670 SendCommand::Results::Result result;
589 if (response->GetDictionary("result", &result_body)) 671 if (response->GetDictionary("result", &result_body))
590 result.additional_properties.Swap(result_body); 672 result.additional_properties.Swap(result_body);
591 673
592 results_ = SendCommand::Results::Create(result); 674 results_ = SendCommand::Results::Create(result);
593 SendResponse(true); 675 SendResponse(true);
594 } 676 }
677
678 DebuggerGetTargetsFunction::DebuggerGetTargetsFunction() {}
679
680 DebuggerGetTargetsFunction::~DebuggerGetTargetsFunction() {}
681
682 bool DebuggerGetTargetsFunction::RunImpl() {
683 base::ListValue* results_list = new ListValue();
684
685 std::vector<RenderViewHost*> rvh_list =
686 DevToolsAgentHost::GetValidRenderViewHosts();
687 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin();
688 it != rvh_list.end(); ++it) {
689 base::Value* value = SerializePageInfo(*it);
690 if (value)
691 results_list->Append(value);
692 }
693
694 SetResult(results_list);
695 SendResponse(true);
696 return true;
697 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698