#include "chrome/browser/extensions/api/debugger/debugger_api_constants.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
-#include "chrome/browser/infobars/confirm_infobar_delegate.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar.h"
#include "content/public/browser/devtools_agent_host.h"
-#include "content/public/browser/devtools_client_host.h"
#include "content/public/browser/devtools_http_handler.h"
-#include "content/public/browser/devtools_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_process_host.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
-#include "extensions/browser/extension_system.h"
+#include "extensions/common/constants.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
-#include "grit/generated_resources.h"
+#include "extensions/common/manifest_constants.h"
+#include "extensions/common/permissions/permissions_data.h"
+#include "extensions/common/switches.h"
#include "ui/base/l10n/l10n_util.h"
using content::DevToolsAgentHost;
-using content::DevToolsClientHost;
using content::DevToolsHttpHandler;
-using content::DevToolsManager;
using content::RenderProcessHost;
using content::RenderViewHost;
using content::RenderWidgetHost;
// ExtensionDevToolsClientHost ------------------------------------------------
-class ExtensionDevToolsClientHost : public DevToolsClientHost,
+class ExtensionDevToolsClientHost : public content::DevToolsAgentHostClient,
public content::NotificationObserver,
public ExtensionRegistryObserver {
public:
const Debuggee& debuggee,
infobars::InfoBar* infobar);
- virtual ~ExtensionDevToolsClientHost();
+ ~ExtensionDevToolsClientHost() override;
const std::string& extension_id() { return extension_id_; }
+ DevToolsAgentHost* agent_host() { return agent_host_.get(); }
void Close();
void SendMessageToBackend(DebuggerSendCommandFunction* function,
const std::string& method,
// Marks connection as to-be-terminated by the user.
void MarkAsDismissed();
- // DevToolsClientHost interface
- virtual void InspectedContentsClosing() OVERRIDE;
- virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE;
- virtual void ReplacedWithAnotherClient() OVERRIDE;
+ // DevToolsAgentHostClient interface.
+ void AgentHostClosed(DevToolsAgentHost* agent_host,
+ bool replaced_with_another_client) override;
+ void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
+ const std::string& message) override;
private:
void SendDetachedEvent();
// content::NotificationObserver implementation.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
// ExtensionRegistryObserver implementation.
- virtual void OnExtensionUnloaded(
- content::BrowserContext* browser_context,
- const Extension* extension,
- UnloadedExtensionInfo::Reason reason) OVERRIDE;
+ void OnExtensionUnloaded(content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) override;
Profile* profile_;
scoped_refptr<DevToolsAgentHost> agent_host_;
// Creates an extension dev tools infobar and delegate and adds the infobar to
// the InfoBarService associated with |rvh|. Returns the infobar if it was
// successfully added.
- static infobars::InfoBar* Create(RenderViewHost* rvh,
+ static infobars::InfoBar* Create(WebContents* web_contents,
const std::string& client_name);
void set_client_host(ExtensionDevToolsClientHost* client_host) {
private:
explicit ExtensionDevToolsInfoBarDelegate(const std::string& client_name);
- virtual ~ExtensionDevToolsInfoBarDelegate();
+ ~ExtensionDevToolsInfoBarDelegate() override;
// ConfirmInfoBarDelegate:
- virtual void InfoBarDismissed() OVERRIDE;
- virtual Type GetInfoBarType() const OVERRIDE;
- virtual bool ShouldExpireInternal(
- const NavigationDetails& details) const OVERRIDE;
- virtual base::string16 GetMessageText() const OVERRIDE;
- virtual int GetButtons() const OVERRIDE;
- virtual bool Cancel() OVERRIDE;
+ void InfoBarDismissed() override;
+ Type GetInfoBarType() const override;
+ bool ShouldExpireInternal(const NavigationDetails& details) const override;
+ base::string16 GetMessageText() const override;
+ int GetButtons() const override;
+ bool Cancel() override;
std::string client_name_;
ExtensionDevToolsClientHost* client_host_;
// static
infobars::InfoBar* ExtensionDevToolsInfoBarDelegate::Create(
- RenderViewHost* rvh,
+ WebContents* web_contents,
const std::string& client_name) {
- if (!rvh)
- return NULL;
-
- WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
if (!web_contents)
return NULL;
ExtensionDevToolsClientHost* AttachedClientHosts::Lookup(
DevToolsAgentHost* agent_host,
const std::string& extension_id) {
- DevToolsManager* manager = DevToolsManager::GetInstance();
for (ClientHosts::iterator it = client_hosts_.begin();
it != client_hosts_.end(); ++it) {
ExtensionDevToolsClientHost* client_host = *it;
- if (manager->GetDevToolsAgentHostFor(client_host) == agent_host &&
+ if (client_host->agent_host() == agent_host &&
client_host->extension_id() == extension_id)
return client_host;
}
content::NotificationService::AllSources());
// Attach to debugger and tell it we are ready.
- DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
- agent_host_.get(), this);
+ agent_host_->AttachClient(this);
if (infobar_) {
static_cast<ExtensionDevToolsInfoBarDelegate*>(
infobar_->delegate())->set_client_host(this);
registrar_.Add(
- this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
- content::Source<InfoBarService>(InfoBarService::FromWebContents(
- WebContents::FromRenderViewHost(
- agent_host_->GetRenderViewHost()))));
+ this,
+ chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
+ content::Source<InfoBarService>(
+ InfoBarService::FromWebContents(agent_host_->GetWebContents())));
}
}
if (infobar_) {
static_cast<ExtensionDevToolsInfoBarDelegate*>(
infobar_->delegate())->set_client_host(NULL);
- InfoBarService* infobar_service = InfoBarService::FromWebContents(
- WebContents::FromRenderViewHost(agent_host_->GetRenderViewHost()));
+ InfoBarService* infobar_service =
+ InfoBarService::FromWebContents(agent_host_->GetWebContents());
infobar_service->RemoveInfoBar(infobar_);
}
AttachedClientHosts::GetInstance()->Remove(this);
}
-// DevToolsClientHost interface
-void ExtensionDevToolsClientHost::InspectedContentsClosing() {
+// DevToolsAgentHostClient implementation.
+void ExtensionDevToolsClientHost::AgentHostClosed(
+ DevToolsAgentHost* agent_host, bool replaced_with_another_client) {
+ DCHECK(agent_host == agent_host_.get());
+ if (replaced_with_another_client)
+ detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS;
SendDetachedEvent();
delete this;
}
-void ExtensionDevToolsClientHost::ReplacedWithAnotherClient() {
- detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS;
-}
-
void ExtensionDevToolsClientHost::Close() {
- DevToolsManager::GetInstance()->ClientHostClosing(this);
+ agent_host_->DetachClient();
delete this;
}
std::string json_args;
base::JSONWriter::Write(&protocol_request, &json_args);
- DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this, json_args);
+ agent_host_->DispatchProtocolMessage(json_args);
}
void ExtensionDevToolsClientHost::MarkAsDismissed() {
}
}
-void ExtensionDevToolsClientHost::DispatchOnInspectorFrontend(
- const std::string& message) {
+void ExtensionDevToolsClientHost::DispatchProtocolMessage(
+ DevToolsAgentHost* agent_host, const std::string& message) {
+ DCHECK(agent_host == agent_host_.get());
if (!EventRouter::Get(profile_))
return;
&web_contents,
NULL);
if (result && web_contents) {
- if (content::HasWebUIScheme(web_contents->GetURL())) {
- error_ = ErrorUtils::FormatErrorMessage(
- keys::kAttachToWebUIError,
- web_contents->GetURL().scheme());
+ // TODO(rdevlin.cronin) This should definitely be GetLastCommittedURL().
+ GURL url = web_contents->GetVisibleURL();
+ if (PermissionsData::IsRestrictedUrl(url, url, extension(), &error_))
return false;
- }
agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents);
}
} else if (debuggee_.extension_id) {
ExtensionHost* extension_host =
- ExtensionSystem::Get(GetProfile())
- ->process_manager()
+ ProcessManager::Get(GetProfile())
->GetBackgroundHostForExtension(*debuggee_.extension_id);
if (extension_host) {
- agent_host_ = DevToolsAgentHost::GetOrCreateFor(
- extension_host->render_view_host());
+ if (PermissionsData::IsRestrictedUrl(extension_host->GetURL(),
+ extension_host->GetURL(),
+ extension(),
+ &error_)) {
+ return false;
+ }
+ agent_host_ =
+ DevToolsAgentHost::GetOrCreateFor(extension_host->host_contents());
}
} else if (debuggee_.target_id) {
agent_host_ = DevToolsAgentHost::GetForId(*debuggee_.target_id);
if (!InitAgentHost())
return false;
- client_host_ = AttachedClientHosts::GetInstance()->Lookup(
- agent_host_.get(), GetExtension()->id());
+ client_host_ = AttachedClientHosts::GetInstance()->Lookup(agent_host_.get(),
+ extension()->id());
if (!client_host_) {
FormatErrorMessage(keys::kNotAttachedError);
infobars::InfoBar* infobar = NULL;
if (!CommandLine::ForCurrentProcess()->
- HasSwitch(switches::kSilentDebuggerExtensionAPI)) {
+ HasSwitch(::switches::kSilentDebuggerExtensionAPI)) {
// Do not attach to the target if for any reason the infobar cannot be shown
// for this WebContents instance.
infobar = ExtensionDevToolsInfoBarDelegate::Create(
- agent_host_->GetRenderViewHost(), GetExtension()->name());
+ agent_host_->GetWebContents(), extension()->name());
if (!infobar) {
error_ = ErrorUtils::FormatErrorMessage(
keys::kSilentDebuggingRequired,
- switches::kSilentDebuggerExtensionAPI);
+ ::switches::kSilentDebuggerExtensionAPI);
return false;
}
}
new ExtensionDevToolsClientHost(GetProfile(),
agent_host_.get(),
- GetExtension()->id(),
- GetExtension()->name(),
+ extension()->id(),
+ extension()->name(),
debuggee_,
infobar);
SendResponse(true);