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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 namespace Attach = extensions::api::debugger::Attach; | 52 namespace Attach = extensions::api::debugger::Attach; |
53 namespace Detach = extensions::api::debugger::Detach; | 53 namespace Detach = extensions::api::debugger::Detach; |
54 namespace OnDetach = extensions::api::debugger::OnDetach; | 54 namespace OnDetach = extensions::api::debugger::OnDetach; |
55 namespace OnEvent = extensions::api::debugger::OnEvent; | 55 namespace OnEvent = extensions::api::debugger::OnEvent; |
56 namespace SendCommand = extensions::api::debugger::SendCommand; | 56 namespace SendCommand = extensions::api::debugger::SendCommand; |
57 | 57 |
58 class ExtensionDevToolsClientHost; | 58 class ExtensionDevToolsClientHost; |
59 | 59 |
60 class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate { | 60 class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate { |
61 public: | 61 public: |
| 62 // Creates an extension dev tools delegate and adds it to |infobar_service|. |
| 63 // Returns a pointer to the delegate if it was successfully added. |
| 64 static ExtensionDevToolsInfoBarDelegate* Create( |
| 65 InfoBarService* infobar_service, |
| 66 const std::string& client_name, |
| 67 ExtensionDevToolsClientHost* client_host); |
| 68 |
| 69 // Notifies infobar delegate that associated DevToolsClientHost will be |
| 70 // destroyed. |
| 71 void DiscardClientHost(); |
| 72 |
| 73 private: |
62 ExtensionDevToolsInfoBarDelegate( | 74 ExtensionDevToolsInfoBarDelegate( |
63 InfoBarService* infobar_service, | 75 InfoBarService* infobar_service, |
64 const std::string& client_name, | 76 const std::string& client_name, |
65 ExtensionDevToolsClientHost* client_host); | 77 ExtensionDevToolsClientHost* client_host); |
66 virtual ~ExtensionDevToolsInfoBarDelegate(); | 78 virtual ~ExtensionDevToolsInfoBarDelegate(); |
67 | 79 |
68 // Notifies infobar delegate that associated DevToolsClientHost will be | |
69 // destroyed. | |
70 void DiscardClientHost(); | |
71 | |
72 private: | |
73 // ConfirmInfoBarDelegate: | 80 // ConfirmInfoBarDelegate: |
74 virtual int GetButtons() const OVERRIDE; | 81 virtual int GetButtons() const OVERRIDE; |
75 virtual Type GetInfoBarType() const OVERRIDE; | 82 virtual Type GetInfoBarType() const OVERRIDE; |
76 virtual bool ShouldExpireInternal( | 83 virtual bool ShouldExpireInternal( |
77 const content::LoadCommittedDetails& details) const OVERRIDE; | 84 const content::LoadCommittedDetails& details) const OVERRIDE; |
78 virtual string16 GetMessageText() const OVERRIDE; | 85 virtual string16 GetMessageText() const OVERRIDE; |
79 virtual void InfoBarDismissed() OVERRIDE; | 86 virtual void InfoBarDismissed() OVERRIDE; |
80 virtual bool Cancel() OVERRIDE; | 87 virtual bool Cancel() OVERRIDE; |
81 | 88 |
82 std::string client_name_; | 89 std::string client_name_; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 196 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
190 content::Source<Profile>(profile)); | 197 content::Source<Profile>(profile)); |
191 | 198 |
192 // Attach to debugger and tell it we are ready. | 199 // Attach to debugger and tell it we are ready. |
193 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( | 200 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor( |
194 web_contents_->GetRenderViewHost())); | 201 web_contents_->GetRenderViewHost())); |
195 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); | 202 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent, this); |
196 | 203 |
197 InfoBarService* infobar_service = | 204 InfoBarService* infobar_service = |
198 InfoBarService::FromWebContents(web_contents_); | 205 InfoBarService::FromWebContents(web_contents_); |
199 infobar_delegate_ = new ExtensionDevToolsInfoBarDelegate(infobar_service, | 206 infobar_delegate_ = ExtensionDevToolsInfoBarDelegate::Create(infobar_service, |
200 extension_name, | 207 extension_name, |
201 this); | 208 this); |
202 if (infobar_service->AddInfoBar(infobar_delegate_)) { | 209 if (infobar_delegate_) { |
203 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 210 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
204 content::Source<InfoBarService>(infobar_service)); | 211 content::Source<InfoBarService>(infobar_service)); |
205 } else { | |
206 infobar_delegate_ = NULL; | |
207 } | 212 } |
208 } | 213 } |
209 | 214 |
210 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { | 215 ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { |
211 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to | 216 // Ensure calling RemoveInfoBar() below won't result in Observe() trying to |
212 // Close() us. | 217 // Close() us. |
213 registrar_.RemoveAll(); | 218 registrar_.RemoveAll(); |
214 | 219 |
215 if (infobar_delegate_) { | 220 if (infobar_delegate_) { |
216 infobar_delegate_->DiscardClientHost(); | 221 infobar_delegate_->DiscardClientHost(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 } else { | 345 } else { |
341 SendCommandDebuggerFunction* function = pending_requests_[id]; | 346 SendCommandDebuggerFunction* function = pending_requests_[id]; |
342 if (!function) | 347 if (!function) |
343 return; | 348 return; |
344 | 349 |
345 function->SendResponseBody(dictionary); | 350 function->SendResponseBody(dictionary); |
346 pending_requests_.erase(id); | 351 pending_requests_.erase(id); |
347 } | 352 } |
348 } | 353 } |
349 | 354 |
| 355 // static |
| 356 ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create( |
| 357 InfoBarService* infobar_service, |
| 358 const std::string& client_name, |
| 359 ExtensionDevToolsClientHost* client_host) { |
| 360 return static_cast<ExtensionDevToolsInfoBarDelegate*>( |
| 361 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 362 new ExtensionDevToolsInfoBarDelegate(infobar_service, client_name, |
| 363 client_host)))); |
| 364 } |
| 365 |
| 366 void ExtensionDevToolsInfoBarDelegate::DiscardClientHost() { |
| 367 client_host_ = NULL; |
| 368 } |
| 369 |
350 ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate( | 370 ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate( |
351 InfoBarService* infobar_service, | 371 InfoBarService* infobar_service, |
352 const std::string& client_name, | 372 const std::string& client_name, |
353 ExtensionDevToolsClientHost* client_host) | 373 ExtensionDevToolsClientHost* client_host) |
354 : ConfirmInfoBarDelegate(infobar_service), | 374 : ConfirmInfoBarDelegate(infobar_service), |
355 client_name_(client_name), | 375 client_name_(client_name), |
356 client_host_(client_host) { | 376 client_host_(client_host) { |
357 } | 377 } |
358 | 378 |
359 ExtensionDevToolsInfoBarDelegate::~ExtensionDevToolsInfoBarDelegate() { | 379 ExtensionDevToolsInfoBarDelegate::~ExtensionDevToolsInfoBarDelegate() { |
360 } | 380 } |
361 | 381 |
362 void ExtensionDevToolsInfoBarDelegate::DiscardClientHost() { | |
363 client_host_ = NULL; | |
364 } | |
365 | |
366 int ExtensionDevToolsInfoBarDelegate::GetButtons() const { | 382 int ExtensionDevToolsInfoBarDelegate::GetButtons() const { |
367 return BUTTON_CANCEL; | 383 return BUTTON_CANCEL; |
368 } | 384 } |
369 | 385 |
370 InfoBarDelegate::Type ExtensionDevToolsInfoBarDelegate::GetInfoBarType() const { | 386 InfoBarDelegate::Type ExtensionDevToolsInfoBarDelegate::GetInfoBarType() const { |
371 return WARNING_TYPE; | 387 return WARNING_TYPE; |
372 } | 388 } |
373 | 389 |
374 bool ExtensionDevToolsInfoBarDelegate::ShouldExpireInternal( | 390 bool ExtensionDevToolsInfoBarDelegate::ShouldExpireInternal( |
375 const content::LoadCommittedDetails& details) const { | 391 const content::LoadCommittedDetails& details) const { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 541 } |
526 | 542 |
527 DictionaryValue* result_body; | 543 DictionaryValue* result_body; |
528 SendCommand::Results::Result result; | 544 SendCommand::Results::Result result; |
529 if (response->GetDictionary("result", &result_body)) | 545 if (response->GetDictionary("result", &result_body)) |
530 result.additional_properties.Swap(result_body); | 546 result.additional_properties.Swap(result_body); |
531 | 547 |
532 results_ = SendCommand::Results::Create(result); | 548 results_ = SendCommand::Results::Create(result); |
533 SendResponse(true); | 549 SendResponse(true); |
534 } | 550 } |
OLD | NEW |