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> |
(...skipping 16 matching lines...) Expand all Loading... |
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 Loading... |
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 Loading... |
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[] = "faviconUrl"; |
| 213 |
| 214 static const char kTargetTypePage[] = "page"; |
| 215 static const char kTargetTypeBackgroundPage[] = "background_page"; |
| 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, agent_host->IsAttached()); |
| 228 dictionary->SetString(kTargetUrlField, web_contents->GetURL().spec()); |
| 229 |
| 230 extensions::ExtensionHost* extension_host = |
| 231 GetExtensionBackgroundHost(web_contents); |
| 232 if (extension_host) { |
| 233 // This RenderViewHost belongs to a background page. |
| 234 dictionary->SetString(kTargetTypeField, kTargetTypeBackgroundPage); |
| 235 dictionary->SetString(kTargetTitleField, |
| 236 extension_host->extension()->name()); |
| 237 } else { |
| 238 // This RenderViewHost belongs to a regular page. |
| 239 dictionary->SetString(kTargetTypeField, kTargetTypePage); |
| 240 dictionary->SetString(kTargetTitleField, |
| 241 UTF16ToUTF8(net::EscapeForHTML(web_contents->GetTitle()))); |
| 242 |
| 243 content::NavigationController& controller = web_contents->GetController(); |
| 244 content::NavigationEntry* entry = controller.GetActiveEntry(); |
| 245 if (entry != NULL && entry->GetURL().is_valid()) { |
| 246 dictionary->SetString(kTargetFaviconUrlField, |
| 247 entry->GetFavicon().url.spec()); |
| 248 } |
| 249 } |
| 250 |
| 251 return dictionary; |
| 252 } |
| 253 |
186 } // namespace | 254 } // namespace |
187 | 255 |
188 static void CopyDebuggee(Debuggee & dst, const Debuggee& src) { | 256 static void CopyDebuggee(Debuggee & dst, const Debuggee& src) { |
189 if (src.tab_id) | 257 if (src.tab_id) |
190 dst.tab_id.reset(new int(*src.tab_id)); | 258 dst.tab_id.reset(new int(*src.tab_id)); |
191 if (src.extension_id) | 259 if (src.extension_id) |
192 dst.extension_id.reset(new std::string(*src.extension_id)); | 260 dst.extension_id.reset(new std::string(*src.extension_id)); |
| 261 if (src.target_id) |
| 262 dst.target_id.reset(new std::string(*src.target_id)); |
193 } | 263 } |
194 | 264 |
195 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( | 265 ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( |
196 WebContents* web_contents, | 266 WebContents* web_contents, |
197 const std::string& extension_id, | 267 const std::string& extension_id, |
198 const std::string& extension_name, | 268 const std::string& extension_name, |
199 const Debuggee& debuggee) | 269 const Debuggee& debuggee, |
| 270 ExtensionDevToolsInfoBarDelegate* infobar_delegate) |
200 : web_contents_(web_contents), | 271 : web_contents_(web_contents), |
201 extension_id_(extension_id), | 272 extension_id_(extension_id), |
202 last_request_id_(0), | 273 last_request_id_(0), |
203 infobar_delegate_(NULL), | 274 infobar_delegate_(infobar_delegate), |
204 detach_reason_(OnDetach::REASON_TARGET_CLOSED) { | 275 detach_reason_(OnDetach::REASON_TARGET_CLOSED) { |
205 CopyDebuggee(debuggee_, debuggee); | 276 CopyDebuggee(debuggee_, debuggee); |
206 | 277 |
207 AttachedClientHosts::GetInstance()->Add(this); | 278 AttachedClientHosts::GetInstance()->Add(this); |
208 | 279 |
209 // Detach from debugger when extension unloads. | 280 // Detach from debugger when extension unloads. |
210 Profile* profile = | 281 Profile* profile = |
211 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 282 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
212 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 283 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
213 content::Source<Profile>(profile)); | 284 content::Source<Profile>(profile)); |
214 | 285 |
215 // Attach to debugger and tell it we are ready. | 286 // Attach to debugger and tell it we are ready. |
216 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor( | 287 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor( |
217 web_contents_->GetRenderViewHost())); | 288 web_contents_->GetRenderViewHost())); |
218 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); | 289 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); |
219 | 290 |
220 if (!CommandLine::ForCurrentProcess()-> | 291 if (infobar_delegate_) { |
221 HasSwitch(switches::kSilentDebuggerExtensionAPI)) { | 292 infobar_delegate_->AttachClientHost(this); |
222 InfoBarService* infobar_service = | 293 registrar_.Add(this, |
223 InfoBarService::FromWebContents(web_contents_); | 294 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
224 infobar_delegate_ = ExtensionDevToolsInfoBarDelegate::Create( | 295 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 } | 296 } |
231 } | 297 } |
232 | 298 |
233 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { | 299 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { |
234 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to | 300 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to |
235 // Close() us. | 301 // Close() us. |
236 registrar_.RemoveAll(); | 302 registrar_.RemoveAll(); |
237 | 303 |
238 if (infobar_delegate_) { | 304 if (infobar_delegate_) { |
239 infobar_delegate_->DiscardClientHost(); | 305 infobar_delegate_->DiscardClientHost(); |
240 InfoBarService* infobar_service = | 306 if (infobar_delegate_->owner()) |
241 InfoBarService::FromWebContents(web_contents_); | 307 infobar_delegate_->owner()->RemoveInfoBar(infobar_delegate_); |
242 if (infobar_service) | |
243 infobar_service->RemoveInfoBar(infobar_delegate_); | |
244 } | 308 } |
245 AttachedClientHosts::GetInstance()->Remove(this); | 309 AttachedClientHosts::GetInstance()->Remove(this); |
246 } | 310 } |
247 | 311 |
248 bool ExtensionDevToolsClientHost::MatchesContentsAndExtensionId( | 312 bool ExtensionDevToolsClientHost::MatchesContentsAndExtensionId( |
249 WebContents* web_contents, | 313 WebContents* web_contents, |
250 const std::string& extension_id) { | 314 const std::string& extension_id) { |
251 return web_contents == web_contents_ && extension_id_ == extension_id; | 315 return web_contents == web_contents_ && extension_id_ == extension_id; |
252 } | 316 } |
253 | 317 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 if (!function) | 424 if (!function) |
361 return; | 425 return; |
362 | 426 |
363 function->SendResponseBody(dictionary); | 427 function->SendResponseBody(dictionary); |
364 pending_requests_.erase(id); | 428 pending_requests_.erase(id); |
365 } | 429 } |
366 } | 430 } |
367 | 431 |
368 // static | 432 // static |
369 ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create( | 433 ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create( |
370 InfoBarService* infobar_service, | 434 WebContents* web_contents, |
371 const std::string& client_name, | 435 const std::string& client_name) { |
372 ExtensionDevToolsClientHost* client_host) { | 436 InfoBarService* infobar_service = |
| 437 InfoBarService::FromWebContents(web_contents); |
| 438 if (!infobar_service) |
| 439 return NULL; |
373 return static_cast<ExtensionDevToolsInfoBarDelegate*>( | 440 return static_cast<ExtensionDevToolsInfoBarDelegate*>( |
374 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 441 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
375 new ExtensionDevToolsInfoBarDelegate(infobar_service, client_name, | 442 new ExtensionDevToolsInfoBarDelegate(infobar_service, client_name)))); |
376 client_host)))); | 443 } |
| 444 |
| 445 void ExtensionDevToolsInfoBarDelegate::AttachClientHost( |
| 446 ExtensionDevToolsClientHost* client_host) { |
| 447 client_host_ = client_host; |
377 } | 448 } |
378 | 449 |
379 void ExtensionDevToolsInfoBarDelegate::DiscardClientHost() { | 450 void ExtensionDevToolsInfoBarDelegate::DiscardClientHost() { |
380 client_host_ = NULL; | 451 client_host_ = NULL; |
381 } | 452 } |
382 | 453 |
383 ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate( | 454 ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate( |
384 InfoBarService* infobar_service, | 455 InfoBarService* infobar_service, |
385 const std::string& client_name, | 456 const std::string& client_name) |
386 ExtensionDevToolsClientHost* client_host) | |
387 : ConfirmInfoBarDelegate(infobar_service), | 457 : ConfirmInfoBarDelegate(infobar_service), |
388 client_name_(client_name), | 458 client_name_(client_name), |
389 client_host_(client_host) { | 459 client_host_(NULL) { |
390 } | 460 } |
391 | 461 |
392 ExtensionDevToolsInfoBarDelegate::~ExtensionDevToolsInfoBarDelegate() { | 462 ExtensionDevToolsInfoBarDelegate::~ExtensionDevToolsInfoBarDelegate() { |
393 } | 463 } |
394 | 464 |
395 int ExtensionDevToolsInfoBarDelegate::GetButtons() const { | 465 int ExtensionDevToolsInfoBarDelegate::GetButtons() const { |
396 return BUTTON_CANCEL; | 466 return BUTTON_CANCEL; |
397 } | 467 } |
398 | 468 |
399 InfoBarDelegate::Type ExtensionDevToolsInfoBarDelegate::GetInfoBarType() const { | 469 InfoBarDelegate::Type ExtensionDevToolsInfoBarDelegate::GetInfoBarType() const { |
(...skipping 20 matching lines...) Expand all Loading... |
420 client_host_->MarkAsDismissed(); | 490 client_host_->MarkAsDismissed(); |
421 return true; | 491 return true; |
422 } | 492 } |
423 | 493 |
424 DebuggerFunction::DebuggerFunction() | 494 DebuggerFunction::DebuggerFunction() |
425 : contents_(0), | 495 : contents_(0), |
426 client_host_(0) { | 496 client_host_(0) { |
427 } | 497 } |
428 | 498 |
429 void DebuggerFunction::FormatErrorMessage(const std::string& format) { | 499 void DebuggerFunction::FormatErrorMessage(const std::string& format) { |
430 error_ = ErrorUtils::FormatErrorMessage( | 500 if (debuggee_.tab_id) |
431 format, | 501 error_ = ErrorUtils::FormatErrorMessage( |
432 debuggee_.tab_id ? | 502 format, keys::kTabTargetType, base::IntToString(*debuggee_.tab_id)); |
433 keys::kTabTargetType : | 503 else if (debuggee_.extension_id) |
434 keys::kExtensionTargetType, | 504 error_ = ErrorUtils::FormatErrorMessage( |
435 debuggee_.tab_id ? | 505 format, keys::kBackgroundPageTargetType, *debuggee_.extension_id); |
436 base::IntToString(*debuggee_.tab_id) : | 506 else |
437 *debuggee_.extension_id); | 507 error_ = ErrorUtils::FormatErrorMessage( |
| 508 format, keys::kOpaqueTargetType, *debuggee_.target_id); |
438 } | 509 } |
439 | 510 |
440 bool DebuggerFunction::InitWebContents() { | 511 bool DebuggerFunction::InitWebContents() { |
441 // Find the WebContents that contains this tab id. | |
442 contents_ = NULL; | |
443 if (debuggee_.tab_id) { | 512 if (debuggee_.tab_id) { |
444 WebContents* web_contents = NULL; | 513 WebContents* web_contents = NULL; |
445 bool result = ExtensionTabUtil::GetTabById( | 514 bool result = ExtensionTabUtil::GetTabById( |
446 *debuggee_.tab_id, profile(), include_incognito(), NULL, NULL, | 515 *debuggee_.tab_id, profile(), include_incognito(), NULL, NULL, |
447 &web_contents, NULL); | 516 &web_contents, NULL); |
448 if (!result || !web_contents) { | 517 if (result && web_contents) { |
449 FormatErrorMessage(keys::kNoTargetError); | 518 if (content::HasWebUIScheme(web_contents->GetURL())) { |
450 return false; | 519 error_ = ErrorUtils::FormatErrorMessage( |
| 520 keys::kAttachToWebUIError, |
| 521 web_contents->GetURL().scheme()); |
| 522 return false; |
| 523 } |
| 524 contents_ = web_contents; |
451 } | 525 } |
452 contents_ = web_contents; | 526 } else if (debuggee_.extension_id) { |
453 | 527 extensions::ExtensionHost* extension_host = |
454 if (content::HasWebUIScheme(contents_->GetURL())) { | 528 extensions::ExtensionSystem::Get(profile())->process_manager()-> |
455 error_ = ErrorUtils::FormatErrorMessage( | 529 GetBackgroundHostForExtension(*debuggee_.extension_id); |
456 keys::kAttachToWebUIError, | 530 if (extension_host) { |
457 contents_->GetURL().scheme()); | 531 contents_ = WebContents::FromRenderViewHost( |
458 return false; | 532 extension_host->render_view_host()); |
459 } | 533 } |
460 | 534 } else if (debuggee_.target_id) { |
461 return true; | 535 DevToolsAgentHost* agent_host = |
| 536 DevToolsAgentHost::GetForId(*debuggee_.target_id); |
| 537 if (agent_host) { |
| 538 contents_ = WebContents::FromRenderViewHost( |
| 539 agent_host->GetRenderViewHost()); |
| 540 } |
| 541 } else { |
| 542 error_ = keys::kInvalidTargetError; |
| 543 return false; |
462 } | 544 } |
463 | 545 |
464 if (debuggee_.extension_id) { | 546 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); | 547 FormatErrorMessage(keys::kNoTargetError); |
483 return false; | 548 return false; |
484 } | 549 } |
485 | 550 return true; |
486 error_ = keys::kInvalidTargetError; | |
487 return false; | |
488 } | 551 } |
489 | 552 |
490 bool DebuggerFunction::InitClientHost() { | 553 bool DebuggerFunction::InitClientHost() { |
491 if (!InitWebContents()) | 554 if (!InitWebContents()) |
492 return false; | 555 return false; |
493 | 556 |
494 // Don't fetch rvh from the contents since it'll be wrong upon navigation. | 557 // Don't fetch rvh from the contents since it'll be wrong upon navigation. |
495 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_); | 558 client_host_ = AttachedClientHosts::GetInstance()->Lookup(contents_); |
496 | 559 |
497 if (!client_host_ || | 560 if (!client_host_ || |
(...skipping 25 matching lines...) Expand all Loading... |
523 return false; | 586 return false; |
524 } | 587 } |
525 | 588 |
526 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor( | 589 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetOrCreateFor( |
527 contents_->GetRenderViewHost())); | 590 contents_->GetRenderViewHost())); |
528 if (agent->IsAttached()) { | 591 if (agent->IsAttached()) { |
529 FormatErrorMessage(keys::kAlreadyAttachedError); | 592 FormatErrorMessage(keys::kAlreadyAttachedError); |
530 return false; | 593 return false; |
531 } | 594 } |
532 | 595 |
| 596 ExtensionDevToolsInfoBarDelegate* infobar_delegate = NULL; |
| 597 |
| 598 if (!CommandLine::ForCurrentProcess()-> |
| 599 HasSwitch(switches::kSilentDebuggerExtensionAPI)) { |
| 600 // Do not attach to the target if for any reason the infobar cannot be shown |
| 601 // for this WebContents instance. |
| 602 infobar_delegate = ExtensionDevToolsInfoBarDelegate::Create( |
| 603 contents_, GetExtension()->name()); |
| 604 if (!infobar_delegate) { |
| 605 error_ = ErrorUtils::FormatErrorMessage( |
| 606 keys::kSilentDebuggingRequired, |
| 607 switches::kSilentDebuggerExtensionAPI); |
| 608 return false; |
| 609 } |
| 610 } |
| 611 |
533 new ExtensionDevToolsClientHost(contents_, | 612 new ExtensionDevToolsClientHost(contents_, |
534 GetExtension()->id(), | 613 GetExtension()->id(), |
535 GetExtension()->name(), | 614 GetExtension()->name(), |
536 debuggee_); | 615 debuggee_, |
| 616 infobar_delegate); |
537 SendResponse(true); | 617 SendResponse(true); |
538 return true; | 618 return true; |
539 } | 619 } |
540 | 620 |
541 DebuggerDetachFunction::DebuggerDetachFunction() {} | 621 DebuggerDetachFunction::DebuggerDetachFunction() {} |
542 | 622 |
543 DebuggerDetachFunction::~DebuggerDetachFunction() {} | 623 DebuggerDetachFunction::~DebuggerDetachFunction() {} |
544 | 624 |
545 bool DebuggerDetachFunction::RunImpl() { | 625 bool DebuggerDetachFunction::RunImpl() { |
546 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_)); | 626 scoped_ptr<Detach::Params> params(Detach::Params::Create(*args_)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 662 } |
583 | 663 |
584 DictionaryValue* result_body; | 664 DictionaryValue* result_body; |
585 SendCommand::Results::Result result; | 665 SendCommand::Results::Result result; |
586 if (response->GetDictionary("result", &result_body)) | 666 if (response->GetDictionary("result", &result_body)) |
587 result.additional_properties.Swap(result_body); | 667 result.additional_properties.Swap(result_body); |
588 | 668 |
589 results_ = SendCommand::Results::Create(result); | 669 results_ = SendCommand::Results::Create(result); |
590 SendResponse(true); | 670 SendResponse(true); |
591 } | 671 } |
| 672 |
| 673 DebuggerGetTargetsFunction::DebuggerGetTargetsFunction() {} |
| 674 |
| 675 DebuggerGetTargetsFunction::~DebuggerGetTargetsFunction() {} |
| 676 |
| 677 bool DebuggerGetTargetsFunction::RunImpl() { |
| 678 base::ListValue* results_list = new ListValue(); |
| 679 |
| 680 std::vector<RenderViewHost*> rvh_list = |
| 681 DevToolsAgentHost::GetValidRenderViewHosts(); |
| 682 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin(); |
| 683 it != rvh_list.end(); ++it) { |
| 684 base::Value* value = SerializePageInfo(*it); |
| 685 if (value) |
| 686 results_list->Append(value); |
| 687 } |
| 688 |
| 689 SetResult(results_list); |
| 690 SendResponse(true); |
| 691 return true; |
| 692 } |
OLD | NEW |