| Index: chrome/browser/extensions/api/debugger/debugger_api.cc
|
| diff --git a/chrome/browser/extensions/api/debugger/debugger_api.cc b/chrome/browser/extensions/api/debugger/debugger_api.cc
|
| index e2330f84f498724989aa98994c00fb88ed2e5c79..7ef6aad7630511ba58189ecc93b098ffbb7e14b5 100644
|
| --- a/chrome/browser/extensions/api/debugger/debugger_api.cc
|
| +++ b/chrome/browser/extensions/api/debugger/debugger_api.cc
|
| @@ -55,13 +55,20 @@ namespace OnDetach = extensions::api::debugger::OnDetach;
|
| namespace OnEvent = extensions::api::debugger::OnEvent;
|
| namespace SendCommand = extensions::api::debugger::SendCommand;
|
|
|
| +class ExtensionDevToolsClientHost;
|
| +
|
| class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate {
|
| public:
|
| ExtensionDevToolsInfoBarDelegate(
|
| InfoBarTabHelper* infobar_helper,
|
| - const std::string& client_name);
|
| + const std::string& client_name,
|
| + ExtensionDevToolsClientHost* client_host);
|
| virtual ~ExtensionDevToolsInfoBarDelegate();
|
|
|
| + // Notifies infobar delegate that associated DevToolsClientHost will be
|
| + // destroyed.
|
| + void DiscardClientHost();
|
| +
|
| private:
|
| // ConfirmInfoBarDelegate:
|
| virtual bool ShouldExpire(
|
| @@ -69,8 +76,11 @@ class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate {
|
| virtual int GetButtons() const OVERRIDE;
|
| virtual Type GetInfoBarType() const OVERRIDE;
|
| virtual string16 GetMessageText() const OVERRIDE;
|
| + virtual void InfoBarDismissed() OVERRIDE;
|
| + virtual bool Cancel() OVERRIDE;
|
|
|
| std::string client_name_;
|
| + ExtensionDevToolsClientHost* client_host_;
|
| DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsInfoBarDelegate);
|
| };
|
|
|
| @@ -91,6 +101,10 @@ class ExtensionDevToolsClientHost : public DevToolsClientHost,
|
| const std::string& method,
|
| SendCommand::Params::CommandParams* command_params);
|
|
|
| + // Mark methods below determine the connection termination reason.
|
| + void MarkAsReplaced();
|
| + void MarkAsDismissed();
|
| +
|
| // DevToolsClientHost interface
|
| virtual void InspectedContentsClosing() OVERRIDE;
|
| virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE;
|
| @@ -114,6 +128,7 @@ class ExtensionDevToolsClientHost : public DevToolsClientHost,
|
| PendingRequests;
|
| PendingRequests pending_requests_;
|
| ExtensionDevToolsInfoBarDelegate* infobar_delegate_;
|
| + OnDetach::Reason detach_reason_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost);
|
| };
|
| @@ -137,6 +152,16 @@ class AttachedClientHosts {
|
| client_hosts_.erase(client_host);
|
| }
|
|
|
| + ExtensionDevToolsClientHost* AsExtensionDevToolsClientHost(
|
| + DevToolsClientHost* client_host) {
|
| + for (std::set<DevToolsClientHost*>::iterator it = client_hosts_.begin();
|
| + it != client_hosts_.end(); ++it) {
|
| + if (client_host == *it)
|
| + return static_cast<ExtensionDevToolsClientHost*>(*it);
|
| + }
|
| + return NULL;
|
| + }
|
| +
|
| ExtensionDevToolsClientHost* Lookup(WebContents* contents) {
|
| for (std::set<DevToolsClientHost*>::iterator it = client_hosts_.begin();
|
| it != client_hosts_.end(); ++it) {
|
| @@ -167,7 +192,8 @@ ExtensionDevToolsClientHost::ExtensionDevToolsClientHost(
|
| extension_id_(extension_id),
|
| tab_id_(tab_id),
|
| last_request_id_(0),
|
| - infobar_delegate_(NULL) {
|
| + infobar_delegate_(NULL),
|
| + detach_reason_(OnDetach::REASON_TARGET_CLOSED) {
|
| AttachedClientHosts::GetInstance()->Add(this);
|
|
|
| // Detach from debugger when extension unloads.
|
| @@ -183,8 +209,9 @@ ExtensionDevToolsClientHost::ExtensionDevToolsClientHost(
|
|
|
| InfoBarTabHelper* infobar_helper =
|
| TabContents::FromWebContents(web_contents_)->infobar_tab_helper();
|
| - infobar_delegate_ =
|
| - new ExtensionDevToolsInfoBarDelegate(infobar_helper, extension_name);
|
| + infobar_delegate_ = new ExtensionDevToolsInfoBarDelegate(infobar_helper,
|
| + extension_name,
|
| + this);
|
| if (infobar_helper->AddInfoBar(infobar_delegate_)) {
|
| registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
|
| content::Source<InfoBarTabHelper>(infobar_helper));
|
| @@ -199,6 +226,7 @@ ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() {
|
| registrar_.RemoveAll();
|
|
|
| if (infobar_delegate_) {
|
| + infobar_delegate_->DiscardClientHost();
|
| TabContents* tab_contents = TabContents::FromWebContents(web_contents_);
|
| InfoBarTabHelper* helper = tab_contents->infobar_tab_helper();
|
| if (helper)
|
| @@ -247,14 +275,22 @@ void ExtensionDevToolsClientHost::SendMessageToBackend(
|
| DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this, json_args);
|
| }
|
|
|
| +void ExtensionDevToolsClientHost::MarkAsReplaced() {
|
| + detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS;
|
| +}
|
| +
|
| +void ExtensionDevToolsClientHost::MarkAsDismissed() {
|
| + detach_reason_ = OnDetach::REASON_CANCELED_BY_USER;
|
| +}
|
| +
|
| void ExtensionDevToolsClientHost::SendDetachedEvent() {
|
| Profile* profile =
|
| Profile::FromBrowserContext(web_contents_->GetBrowserContext());
|
| if (profile != NULL && profile->GetExtensionEventRouter()) {
|
| Debuggee debuggee;
|
| debuggee.tab_id = tab_id_;
|
| -
|
| - scoped_ptr<base::ListValue> args(OnDetach::Create(debuggee));
|
| + scoped_ptr<base::ListValue> args(OnDetach::Create(debuggee,
|
| + detach_reason_));
|
| profile->GetExtensionEventRouter()->DispatchEventToExtension(
|
| extension_id_, keys::kOnDetach, args.Pass(), profile, GURL());
|
| }
|
| @@ -322,14 +358,20 @@ void ExtensionDevToolsClientHost::DispatchOnInspectorFrontend(
|
|
|
| ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate(
|
| InfoBarTabHelper* infobar_helper,
|
| - const std::string& client_name)
|
| + const std::string& client_name,
|
| + ExtensionDevToolsClientHost* client_host)
|
| : ConfirmInfoBarDelegate(infobar_helper),
|
| - client_name_(client_name) {
|
| + client_name_(client_name),
|
| + client_host_(client_host) {
|
| }
|
|
|
| ExtensionDevToolsInfoBarDelegate::~ExtensionDevToolsInfoBarDelegate() {
|
| }
|
|
|
| +void ExtensionDevToolsInfoBarDelegate::DiscardClientHost() {
|
| + client_host_ = NULL;
|
| +}
|
| +
|
| bool ExtensionDevToolsInfoBarDelegate::ShouldExpire(
|
| const content::LoadCommittedDetails& details) const {
|
| return false;
|
| @@ -348,6 +390,17 @@ string16 ExtensionDevToolsInfoBarDelegate::GetMessageText() const {
|
| UTF8ToUTF16(client_name_));
|
| }
|
|
|
| +void ExtensionDevToolsInfoBarDelegate::InfoBarDismissed() {
|
| + if (client_host_)
|
| + client_host_->MarkAsDismissed();
|
| +}
|
| +
|
| +bool ExtensionDevToolsInfoBarDelegate::Cancel() {
|
| + if (client_host_)
|
| + client_host_->MarkAsDismissed();
|
| + return true;
|
| +}
|
| +
|
| DebuggerFunction::DebuggerFunction()
|
| : contents_(0),
|
| tab_id_(0),
|
| @@ -488,3 +541,12 @@ void SendCommandDebuggerFunction::SendResponseBody(
|
| results_ = SendCommand::Results::Create(result);
|
| SendResponse(true);
|
| }
|
| +
|
| +// static
|
| +void DebuggerApi::MarkDevToolsClientHostAsReplaced(
|
| + DevToolsClientHost* client_host) {
|
| + ExtensionDevToolsClientHost* host = AttachedClientHosts::GetInstance()->
|
| + AsExtensionDevToolsClientHost(client_host);
|
| + if (host)
|
| + host->MarkAsReplaced();
|
| +}
|
|
|