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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 | 156 |
157 | 157 |
158 // ExtensionDevToolsInfoBarDelegate ------------------------------------------- | 158 // ExtensionDevToolsInfoBarDelegate ------------------------------------------- |
159 | 159 |
160 class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate { | 160 class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate { |
161 public: | 161 public: |
162 // Creates an extension dev tools infobar and delegate and adds the infobar to | 162 // Creates an extension dev tools infobar and delegate and adds the infobar to |
163 // the InfoBarService associated with |rvh|. Returns the infobar if it was | 163 // the InfoBarService associated with |rvh|. Returns the infobar if it was |
164 // successfully added. | 164 // successfully added. |
165 static infobars::InfoBar* Create(RenderViewHost* rvh, | 165 static infobars::InfoBar* Create(WebContents* web_contents, |
166 const std::string& client_name); | 166 const std::string& client_name); |
167 | 167 |
168 void set_client_host(ExtensionDevToolsClientHost* client_host) { | 168 void set_client_host(ExtensionDevToolsClientHost* client_host) { |
169 client_host_ = client_host; | 169 client_host_ = client_host; |
170 } | 170 } |
171 | 171 |
172 private: | 172 private: |
173 explicit ExtensionDevToolsInfoBarDelegate(const std::string& client_name); | 173 explicit ExtensionDevToolsInfoBarDelegate(const std::string& client_name); |
174 virtual ~ExtensionDevToolsInfoBarDelegate(); | 174 virtual ~ExtensionDevToolsInfoBarDelegate(); |
175 | 175 |
176 // ConfirmInfoBarDelegate: | 176 // ConfirmInfoBarDelegate: |
177 virtual void InfoBarDismissed() OVERRIDE; | 177 virtual void InfoBarDismissed() OVERRIDE; |
178 virtual Type GetInfoBarType() const OVERRIDE; | 178 virtual Type GetInfoBarType() const OVERRIDE; |
179 virtual bool ShouldExpireInternal( | 179 virtual bool ShouldExpireInternal( |
180 const NavigationDetails& details) const OVERRIDE; | 180 const NavigationDetails& details) const OVERRIDE; |
181 virtual base::string16 GetMessageText() const OVERRIDE; | 181 virtual base::string16 GetMessageText() const OVERRIDE; |
182 virtual int GetButtons() const OVERRIDE; | 182 virtual int GetButtons() const OVERRIDE; |
183 virtual bool Cancel() OVERRIDE; | 183 virtual bool Cancel() OVERRIDE; |
184 | 184 |
185 std::string client_name_; | 185 std::string client_name_; |
186 ExtensionDevToolsClientHost* client_host_; | 186 ExtensionDevToolsClientHost* client_host_; |
187 | 187 |
188 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate); | 188 DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate); |
189 }; | 189 }; |
190 | 190 |
191 // static | 191 // static |
192 infobars::InfoBar* ExtensionDevToolsInfoBarDelegate::Create( | 192 infobars::InfoBar* ExtensionDevToolsInfoBarDelegate::Create( |
193 RenderViewHost* rvh, | 193 WebContents* web_contents, |
194 const std::string& client_name) { | 194 const std::string& client_name) { |
195 if (!rvh) | |
196 return NULL; | |
197 | |
198 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | |
199 if (!web_contents) | 195 if (!web_contents) |
200 return NULL; | 196 return NULL; |
201 | 197 |
202 InfoBarService* infobar_service = | 198 InfoBarService* infobar_service = |
203 InfoBarService::FromWebContents(web_contents); | 199 InfoBarService::FromWebContents(web_contents); |
204 if (!infobar_service) | 200 if (!infobar_service) |
205 return NULL; | 201 return NULL; |
206 | 202 |
207 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | 203 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( |
208 scoped_ptr<ConfirmInfoBarDelegate>( | 204 scoped_ptr<ConfirmInfoBarDelegate>( |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 content::NotificationService::AllSources()); | 334 content::NotificationService::AllSources()); |
339 | 335 |
340 // Attach to debugger and tell it we are ready. | 336 // Attach to debugger and tell it we are ready. |
341 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 337 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
342 agent_host_.get(), this); | 338 agent_host_.get(), this); |
343 | 339 |
344 if (infobar_) { | 340 if (infobar_) { |
345 static_cast<ExtensionDevToolsInfoBarDelegate*>( | 341 static_cast<ExtensionDevToolsInfoBarDelegate*>( |
346 infobar_->delegate())->set_client_host(this); | 342 infobar_->delegate())->set_client_host(this); |
347 registrar_.Add( | 343 registrar_.Add( |
348 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 344 this, |
349 content::Source<InfoBarService>(InfoBarService::FromWebContents( | 345 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
350 WebContents::FromRenderViewHost( | 346 content::Source<InfoBarService>( |
351 agent_host_->GetRenderViewHost())))); | 347 InfoBarService::FromWebContents(agent_host_->GetWebContents()))); |
352 } | 348 } |
353 } | 349 } |
354 | 350 |
355 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { | 351 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { |
356 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to | 352 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to |
357 // Close() us. | 353 // Close() us. |
358 registrar_.RemoveAll(); | 354 registrar_.RemoveAll(); |
359 | 355 |
360 if (infobar_) { | 356 if (infobar_) { |
361 static_cast<ExtensionDevToolsInfoBarDelegate*>( | 357 static_cast<ExtensionDevToolsInfoBarDelegate*>( |
362 infobar_->delegate())->set_client_host(NULL); | 358 infobar_->delegate())->set_client_host(NULL); |
363 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 359 InfoBarService* infobar_service = |
364 WebContents::FromRenderViewHost(agent_host_->GetRenderViewHost())); | 360 InfoBarService::FromWebContents(agent_host_->GetWebContents()); |
365 infobar_service->RemoveInfoBar(infobar_); | 361 infobar_service->RemoveInfoBar(infobar_); |
366 } | 362 } |
367 AttachedClientHosts::GetInstance()->Remove(this); | 363 AttachedClientHosts::GetInstance()->Remove(this); |
368 } | 364 } |
369 | 365 |
370 // DevToolsClientHost interface | 366 // DevToolsClientHost interface |
371 void ExtensionDevToolsClientHost::InspectedContentsClosing() { | 367 void ExtensionDevToolsClientHost::InspectedContentsClosing() { |
372 SendDetachedEvent(); | 368 SendDetachedEvent(); |
373 delete this; | 369 delete this; |
374 } | 370 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 ExtensionSystem::Get(GetProfile()) | 524 ExtensionSystem::Get(GetProfile()) |
529 ->process_manager() | 525 ->process_manager() |
530 ->GetBackgroundHostForExtension(*debuggee_.extension_id); | 526 ->GetBackgroundHostForExtension(*debuggee_.extension_id); |
531 if (extension_host) { | 527 if (extension_host) { |
532 if (PermissionsData::IsRestrictedUrl(extension_host->GetURL(), | 528 if (PermissionsData::IsRestrictedUrl(extension_host->GetURL(), |
533 extension_host->GetURL(), | 529 extension_host->GetURL(), |
534 extension(), | 530 extension(), |
535 &error_)) { | 531 &error_)) { |
536 return false; | 532 return false; |
537 } | 533 } |
538 agent_host_ = DevToolsAgentHost::GetOrCreateFor( | 534 agent_host_ = |
539 extension_host->render_view_host()); | 535 DevToolsAgentHost::GetOrCreateFor(extension_host->host_contents()); |
540 } | 536 } |
541 } else if (debuggee_.target_id) { | 537 } else if (debuggee_.target_id) { |
542 agent_host_ = DevToolsAgentHost::GetForId(*debuggee_.target_id); | 538 agent_host_ = DevToolsAgentHost::GetForId(*debuggee_.target_id); |
543 } else { | 539 } else { |
544 error_ = keys::kInvalidTargetError; | 540 error_ = keys::kInvalidTargetError; |
545 return false; | 541 return false; |
546 } | 542 } |
547 | 543 |
548 if (!agent_host_.get()) { | 544 if (!agent_host_.get()) { |
549 FormatErrorMessage(keys::kNoTargetError); | 545 FormatErrorMessage(keys::kNoTargetError); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 FormatErrorMessage(keys::kAlreadyAttachedError); | 591 FormatErrorMessage(keys::kAlreadyAttachedError); |
596 return false; | 592 return false; |
597 } | 593 } |
598 | 594 |
599 infobars::InfoBar* infobar = NULL; | 595 infobars::InfoBar* infobar = NULL; |
600 if (!CommandLine::ForCurrentProcess()-> | 596 if (!CommandLine::ForCurrentProcess()-> |
601 HasSwitch(::switches::kSilentDebuggerExtensionAPI)) { | 597 HasSwitch(::switches::kSilentDebuggerExtensionAPI)) { |
602 // Do not attach to the target if for any reason the infobar cannot be shown | 598 // Do not attach to the target if for any reason the infobar cannot be shown |
603 // for this WebContents instance. | 599 // for this WebContents instance. |
604 infobar = ExtensionDevToolsInfoBarDelegate::Create( | 600 infobar = ExtensionDevToolsInfoBarDelegate::Create( |
605 agent_host_->GetRenderViewHost(), extension()->name()); | 601 agent_host_->GetWebContents(), extension()->name()); |
606 if (!infobar) { | 602 if (!infobar) { |
607 error_ = ErrorUtils::FormatErrorMessage( | 603 error_ = ErrorUtils::FormatErrorMessage( |
608 keys::kSilentDebuggingRequired, | 604 keys::kSilentDebuggingRequired, |
609 ::switches::kSilentDebuggerExtensionAPI); | 605 ::switches::kSilentDebuggerExtensionAPI); |
610 return false; | 606 return false; |
611 } | 607 } |
612 } | 608 } |
613 | 609 |
614 new ExtensionDevToolsClientHost(GetProfile(), | 610 new ExtensionDevToolsClientHost(GetProfile(), |
615 agent_host_.get(), | 611 agent_host_.get(), |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 const std::vector<DevToolsTargetImpl*>& target_list) { | 741 const std::vector<DevToolsTargetImpl*>& target_list) { |
746 scoped_ptr<base::ListValue> result(new base::ListValue()); | 742 scoped_ptr<base::ListValue> result(new base::ListValue()); |
747 for (size_t i = 0; i < target_list.size(); ++i) | 743 for (size_t i = 0; i < target_list.size(); ++i) |
748 result->Append(SerializeTarget(*target_list[i])); | 744 result->Append(SerializeTarget(*target_list[i])); |
749 STLDeleteContainerPointers(target_list.begin(), target_list.end()); | 745 STLDeleteContainerPointers(target_list.begin(), target_list.end()); |
750 SetResult(result.release()); | 746 SetResult(result.release()); |
751 SendResponse(true); | 747 SendResponse(true); |
752 } | 748 } |
753 | 749 |
754 } // namespace extensions | 750 } // namespace extensions |
OLD | NEW |