Commit 252e18d2 authored by dgozman's avatar dgozman Committed by Commit bot

[DevTools] Move target-related methods from DevToolsHttpHandlerDelegate to DevToolsManagerDelegate.

This decouples targets discovery from remote debugging in preparation
of moving discovery to the protocol.

BUG=398049

Review URL: https://codereview.chromium.org/560323005

Cr-Commit-Position: refs/heads/master@{#295953}
parent 9b46fe68
......@@ -98,6 +98,8 @@
'browser/aw_contents_io_thread_client.h',
'browser/aw_cookie_access_policy.cc',
'browser/aw_cookie_access_policy.h',
'browser/aw_dev_tools_manager_delegate.cc',
'browser/aw_dev_tools_manager_delegate.h',
'browser/aw_download_manager_delegate.cc',
'browser/aw_download_manager_delegate.h',
'browser/aw_form_database_service.cc',
......
......@@ -10,6 +10,7 @@
#include "android_webview/browser/aw_contents_client_bridge_base.h"
#include "android_webview/browser/aw_contents_io_thread_client.h"
#include "android_webview/browser/aw_cookie_access_policy.h"
#include "android_webview/browser/aw_dev_tools_manager_delegate.h"
#include "android_webview/browser/aw_quota_permission_context.h"
#include "android_webview/browser/aw_web_preferences_populater.h"
#include "android_webview/browser/jni_dependency_factory.h"
......@@ -580,4 +581,9 @@ AwContentBrowserClient::OverrideCreateExternalVideoSurfaceContainer(
}
#endif
content::DevToolsManagerDelegate*
AwContentBrowserClient::GetDevToolsManagerDelegate() {
return new AwDevToolsManagerDelegate();
}
} // namespace android_webview
......@@ -175,6 +175,8 @@ class AwContentBrowserClient : public content::ContentBrowserClient {
OverrideCreateExternalVideoSurfaceContainer(
content::WebContents* web_contents) OVERRIDE;
#endif
virtual content::DevToolsManagerDelegate*
GetDevToolsManagerDelegate() OVERRIDE;
private:
// Android WebView currently has a single global (non-off-the-record) browser
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "android_webview/browser/aw_dev_tools_manager_delegate.h"
#include "android_webview/native/aw_contents.h"
#include "base/bind.h"
#include "base/json/json_writer.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_target.h"
#include "content/public/browser/web_contents.h"
using content::DevToolsAgentHost;
using content::RenderViewHost;
using content::WebContents;
namespace {
const char kTargetTypePage[] = "page";
const char kTargetTypeServiceWorker[] = "service_worker";
const char kTargetTypeOther[] = "other";
std::string GetViewDescription(WebContents* web_contents);
class Target : public content::DevToolsTarget {
public:
explicit Target(scoped_refptr<DevToolsAgentHost> agent_host);
virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); }
virtual std::string GetParentId() const OVERRIDE { return std::string(); }
virtual std::string GetType() const OVERRIDE {
switch (agent_host_->GetType()) {
case DevToolsAgentHost::TYPE_WEB_CONTENTS:
return kTargetTypePage;
case DevToolsAgentHost::TYPE_SERVICE_WORKER:
return kTargetTypeServiceWorker;
default:
break;
}
return kTargetTypeOther;
}
virtual std::string GetTitle() const OVERRIDE {
return agent_host_->GetTitle();
}
virtual std::string GetDescription() const OVERRIDE { return description_; }
virtual GURL GetURL() const OVERRIDE { return agent_host_->GetURL(); }
virtual GURL GetFaviconURL() const OVERRIDE { return GURL(); }
virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
return last_activity_time_;
}
virtual bool IsAttached() const OVERRIDE {
return agent_host_->IsAttached();
}
virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
return agent_host_;
}
virtual bool Activate() const OVERRIDE { return agent_host_->Activate(); }
virtual bool Close() const OVERRIDE { return agent_host_->Close(); }
private:
scoped_refptr<DevToolsAgentHost> agent_host_;
std::string description_;
base::TimeTicks last_activity_time_;
};
Target::Target(scoped_refptr<DevToolsAgentHost> agent_host)
: agent_host_(agent_host) {
if (WebContents* web_contents = agent_host->GetWebContents()) {
description_ = GetViewDescription(web_contents);
last_activity_time_ = web_contents->GetLastActiveTime();
}
}
std::string GetViewDescription(WebContents* web_contents) {
const android_webview::BrowserViewRenderer* bvr =
android_webview::AwContents::FromWebContents(web_contents)
->GetBrowserViewRenderer();
if (!bvr) return "";
base::DictionaryValue description;
description.SetBoolean("attached", bvr->attached_to_window());
description.SetBoolean("visible", bvr->IsVisible());
gfx::Rect screen_rect = bvr->GetScreenRect();
description.SetInteger("screenX", screen_rect.x());
description.SetInteger("screenY", screen_rect.y());
description.SetBoolean("empty", screen_rect.size().IsEmpty());
if (!screen_rect.size().IsEmpty()) {
description.SetInteger("width", screen_rect.width());
description.SetInteger("height", screen_rect.height());
}
std::string json;
base::JSONWriter::Write(&description, &json);
return json;
}
} // namespace
namespace android_webview {
AwDevToolsManagerDelegate::AwDevToolsManagerDelegate() {
}
AwDevToolsManagerDelegate::~AwDevToolsManagerDelegate() {
}
base::DictionaryValue* AwDevToolsManagerDelegate::HandleCommand(
content::DevToolsAgentHost* agent_host,
base::DictionaryValue* command_dict) {
return NULL;
}
void AwDevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) {
TargetList targets;
DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
for (DevToolsAgentHost::List::iterator it = agents.begin();
it != agents.end(); ++it) {
targets.push_back(new Target(*it));
}
callback.Run(targets);
}
std::string AwDevToolsManagerDelegate::GetPageThumbnailData(const GURL&) {
return "";
}
scoped_ptr<content::DevToolsTarget> AwDevToolsManagerDelegate::CreateNewTarget(
const GURL&) {
return scoped_ptr<content::DevToolsTarget>();
}
} // namespace android_webview
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ANDROID_WEBVIEW_BROWSER_AW_DEV_TOOLS_MANAGER_DELEGATE_H_
#define ANDROID_WEBVIEW_BROWSER_AW_DEV_TOOLS_MANAGER_DELEGATE_H_
#include "base/basictypes.h"
#include "content/public/browser/devtools_manager_delegate.h"
namespace android_webview {
class AwDevToolsManagerDelegate : public content::DevToolsManagerDelegate {
public:
AwDevToolsManagerDelegate();
virtual ~AwDevToolsManagerDelegate();
// content::DevToolsManagerDelegate implementation.
virtual void Inspect(
content::BrowserContext* browser_context,
content::DevToolsAgentHost* agent_host) OVERRIDE {}
virtual void DevToolsAgentStateChanged(
content::DevToolsAgentHost* agent_host,
bool attached) OVERRIDE {}
virtual base::DictionaryValue* HandleCommand(
content::DevToolsAgentHost* agent_host,
base::DictionaryValue* command_dict) OVERRIDE;
virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget(
const GURL& url) OVERRIDE;
virtual void EnumerateTargets(TargetCallback callback) OVERRIDE;
virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(AwDevToolsManagerDelegate);
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_AW_DEV_TOOLS_MANAGER_DELEGATE_H_
......@@ -31,61 +31,6 @@ const char kFrontEndURL[] =
"http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html";
const char kSocketNameFormat[] = "webview_devtools_remote_%d";
const char kTargetTypePage[] = "page";
const char kTargetTypeServiceWorker[] = "service_worker";
const char kTargetTypeOther[] = "other";
std::string GetViewDescription(WebContents* web_contents);
class Target : public content::DevToolsTarget {
public:
explicit Target(scoped_refptr<DevToolsAgentHost> agent_host);
virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); }
virtual std::string GetParentId() const OVERRIDE { return std::string(); }
virtual std::string GetType() const OVERRIDE {
switch (agent_host_->GetType()) {
case DevToolsAgentHost::TYPE_WEB_CONTENTS:
return kTargetTypePage;
case DevToolsAgentHost::TYPE_SERVICE_WORKER:
return kTargetTypeServiceWorker;
default:
break;
}
return kTargetTypeOther;
}
virtual std::string GetTitle() const OVERRIDE {
return agent_host_->GetTitle();
}
virtual std::string GetDescription() const OVERRIDE { return description_; }
virtual GURL GetURL() const OVERRIDE { return agent_host_->GetURL(); }
virtual GURL GetFaviconURL() const OVERRIDE { return GURL(); }
virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
return last_activity_time_;
}
virtual bool IsAttached() const OVERRIDE {
return agent_host_->IsAttached();
}
virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
return agent_host_;
}
virtual bool Activate() const OVERRIDE { return agent_host_->Activate(); }
virtual bool Close() const OVERRIDE { return agent_host_->Close(); }
private:
scoped_refptr<DevToolsAgentHost> agent_host_;
std::string description_;
base::TimeTicks last_activity_time_;
};
Target::Target(scoped_refptr<DevToolsAgentHost> agent_host)
: agent_host_(agent_host) {
if (WebContents* web_contents = agent_host->GetWebContents()) {
description_ = GetViewDescription(web_contents);
last_activity_time_ = web_contents->GetLastActiveTime();
}
}
// Delegate implementation for the devtools http handler for WebView. A new
// instance of this gets created each time web debugging is enabled.
class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
......@@ -104,25 +49,6 @@ class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
return base::FilePath();
}
virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE {
return "";
}
virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget(
const GURL&) OVERRIDE {
return scoped_ptr<content::DevToolsTarget>();
}
virtual void EnumerateTargets(TargetCallback callback) OVERRIDE {
TargetList targets;
DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
for (DevToolsAgentHost::List::iterator it = agents.begin();
it != agents.end(); ++it) {
targets.push_back(new Target(*it));
}
callback.Run(targets);
}
virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
net::StreamListenSocket::Delegate* delegate,
std::string* name) OVERRIDE {
......@@ -144,27 +70,6 @@ std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() {
return html;
}
std::string GetViewDescription(WebContents* web_contents) {
const android_webview::BrowserViewRenderer* bvr =
android_webview::AwContents::FromWebContents(web_contents)
->GetBrowserViewRenderer();
if (!bvr) return "";
base::DictionaryValue description;
description.SetBoolean("attached", bvr->attached_to_window());
description.SetBoolean("visible", bvr->IsVisible());
gfx::Rect screen_rect = bvr->GetScreenRect();
description.SetInteger("screenX", screen_rect.x());
description.SetInteger("screenY", screen_rect.y());
description.SetBoolean("empty", screen_rect.size().IsEmpty());
if (!screen_rect.size().IsEmpty()) {
description.SetInteger("width", screen_rect.width());
description.SetInteger("height", screen_rect.height());
}
std::string json;
base::JSONWriter::Write(&description, &json);
return json;
}
// Factory for UnixDomainServerSocket.
class UnixDomainServerSocketFactory
: public content::DevToolsHttpHandler::ServerSocketFactory {
......
This diff is collapsed.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_DEV_TOOLS_MANAGER_DELEGATE_ANDROID_H_
#define CHROME_BROWSER_ANDROID_DEV_TOOLS_MANAGER_DELEGATE_ANDROID_H_
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/devtools/devtools_network_protocol_handler.h"
#include "content/public/browser/devtools_manager_delegate.h"
class DevToolsManagerDelegateAndroid : public content::DevToolsManagerDelegate {
public:
DevToolsManagerDelegateAndroid();
virtual ~DevToolsManagerDelegateAndroid();
// content::DevToolsManagerDelegate implementation.
virtual void Inspect(content::BrowserContext* browser_context,
content::DevToolsAgentHost* agent_host) OVERRIDE;
virtual void DevToolsAgentStateChanged(content::DevToolsAgentHost* agent_host,
bool attached) OVERRIDE;
virtual base::DictionaryValue* HandleCommand(
content::DevToolsAgentHost* agent_host,
base::DictionaryValue* command_dict) OVERRIDE;
virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget(
const GURL& url) OVERRIDE;
virtual void EnumerateTargets(TargetCallback callback) OVERRIDE;
virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE;
private:
scoped_ptr<DevToolsNetworkProtocolHandler> network_protocol_handler_;
DISALLOW_COPY_AND_ASSIGN(DevToolsManagerDelegateAndroid);
};
#endif // CHROME_BROWSER_ANDROID_DEV_TOOLS_MANAGER_DELEGATE_ANDROID_H_
This diff is collapsed.
......@@ -32,7 +32,6 @@
#include "chrome/browser/content_settings/permission_request_id.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/font_family_cache.h"
#include "chrome/browser/geolocation/chrome_access_token_store.h"
......@@ -174,6 +173,12 @@
#include "ui/gfx/android/device_display_info.h"
#endif
#if defined(OS_ANDROID)
#include "chrome/browser/android/dev_tools_manager_delegate_android.h"
#else
#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
#endif
#if !defined(OS_CHROMEOS)
#include "chrome/browser/signin/chrome_signin_client.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
......@@ -2504,7 +2509,11 @@ bool ChromeContentBrowserClient::CheckMediaAccessPermission(
content::DevToolsManagerDelegate*
ChromeContentBrowserClient::GetDevToolsManagerDelegate() {
#if defined(OS_ANDROID)
return new DevToolsManagerDelegateAndroid();
#else
return new ChromeDevToolsManagerDelegate();
#endif
}
bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
......
......@@ -23,8 +23,6 @@ action("devtools_protocol_constants") {
static_library("devtools") {
# Note: new sources and deps should be generally added in (!is_android) below.
sources = [
"chrome_devtools_manager_delegate.cc",
"chrome_devtools_manager_delegate.h",
"devtools_network_conditions.cc",
"devtools_network_conditions.h",
"devtools_network_controller.cc",
......@@ -101,6 +99,8 @@ static_library("devtools") {
"device/usb/usb_device_provider.h",
"browser_list_tabcontents_provider.cc",
"browser_list_tabcontents_provider.h",
"chrome_devtools_manager_delegate.cc",
"chrome_devtools_manager_delegate.h",
"devtools_contents_resizing_strategy.cc",
"devtools_contents_resizing_strategy.h",
"devtools_embedder_message_dispatcher.cc",
......
......@@ -6,29 +6,18 @@
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/devtools/devtools_target_impl.h"
#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "grit/browser_resources.h"
#include "net/socket/tcp_listen_socket.h"
#include "net/url_request/url_request_context_getter.h"
#include "ui/base/resource/resource_bundle.h"
using content::DevToolsTarget;
using content::RenderViewHost;
using content::WebContents;
namespace {
const int kMinTetheringPort = 9333;
......@@ -85,38 +74,6 @@ base::FilePath BrowserListTabContentsProvider::GetDebugFrontendDir() {
#endif
}
std::string BrowserListTabContentsProvider::GetPageThumbnailData(
const GURL& url) {
for (chrome::BrowserIterator it; !it.done(); it.Next()) {
Profile* profile = (*it)->profile();
history::TopSites* top_sites = profile->GetTopSites();
if (!top_sites)
continue;
scoped_refptr<base::RefCountedMemory> data;
if (top_sites->GetPageThumbnail(url, false, &data))
return std::string(data->front_as<char>(), data->size());
}
return std::string();
}
scoped_ptr<DevToolsTarget>
BrowserListTabContentsProvider::CreateNewTarget(const GURL& url) {
chrome::NavigateParams params(ProfileManager::GetLastUsedProfile(),
url, ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
params.disposition = NEW_FOREGROUND_TAB;
chrome::Navigate(&params);
if (!params.target_contents)
return scoped_ptr<DevToolsTarget>();
return scoped_ptr<DevToolsTarget>(
DevToolsTargetImpl::CreateForWebContents(params.target_contents, true));
}
void BrowserListTabContentsProvider::EnumerateTargets(TargetCallback callback) {
DevToolsTargetImpl::EnumerateAllTargets(
*reinterpret_cast<DevToolsTargetImpl::Callback*>(&callback));
}
scoped_ptr<net::StreamListenSocket>
BrowserListTabContentsProvider::CreateSocketForTethering(
net::StreamListenSocket::Delegate* delegate,
......
......@@ -26,10 +26,6 @@ class BrowserListTabContentsProvider
virtual std::string GetDiscoveryPageHTML() OVERRIDE;
virtual bool BundlesFrontendResources() OVERRIDE;
virtual base::FilePath GetDebugFrontendDir() OVERRIDE;
virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE;
virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget(
const GURL& url) OVERRIDE;
virtual void EnumerateTargets(TargetCallback callback) OVERRIDE;
virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
net::StreamListenSocket::Delegate* delegate,
std::string* name) OVERRIDE;
......
......@@ -5,9 +5,16 @@
#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
#include "base/values.h"
#include "chrome/browser/devtools/devtools_target_impl.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_iterator.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/web_contents.h"
ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate()
: network_protocol_handler_(new DevToolsNetworkProtocolHandler()) {
......@@ -23,10 +30,8 @@ void ChromeDevToolsManagerDelegate::Inspect(
// TODO(horo): Support other types of DevToolsAgentHost when necessary.
NOTREACHED() << "Inspect() only supports workers.";
}
#if !defined(OS_ANDROID)
if (Profile* profile = Profile::FromBrowserContext(browser_context))
DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host);
#endif
}
base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand(
......@@ -40,3 +45,35 @@ void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged(
bool attached) {
network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached);
}
std::string ChromeDevToolsManagerDelegate::GetPageThumbnailData(
const GURL& url) {
for (chrome::BrowserIterator it; !it.done(); it.Next()) {
Profile* profile = (*it)->profile();
history::TopSites* top_sites = profile->GetTopSites();
if (!top_sites)
continue;
scoped_refptr<base::RefCountedMemory> data;
if (top_sites->GetPageThumbnail(url, false, &data))
return std::string(data->front_as<char>(), data->size());
}
return std::string();
}
scoped_ptr<content::DevToolsTarget>
ChromeDevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
chrome::NavigateParams params(ProfileManager::GetLastUsedProfile(),
url, ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
params.disposition = NEW_FOREGROUND_TAB;
chrome::Navigate(&params);
if (!params.target_contents)
return scoped_ptr<content::DevToolsTarget>();
return scoped_ptr<content::DevToolsTarget>(
DevToolsTargetImpl::CreateForWebContents(params.target_contents, true));
}
void ChromeDevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) {
DevToolsTargetImpl::EnumerateAllTargets(
*reinterpret_cast<DevToolsTargetImpl::Callback*>(&callback));
}
......@@ -9,18 +9,14 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/devtools/devtools_network_protocol_handler.h"
#include "chrome/browser/devtools/devtools_protocol.h"
#include "content/public/browser/devtools_manager_delegate.h"
class DevToolsNetworkConditions;
class Profile;
class ChromeDevToolsManagerDelegate : public content::DevToolsManagerDelegate {
public:
ChromeDevToolsManagerDelegate();
virtual ~ChromeDevToolsManagerDelegate();
// content::DevToolsManagerDelegate overrides:
// content::DevToolsManagerDelegate implementation.
virtual void Inspect(content::BrowserContext* browser_context,
content::DevToolsAgentHost* agent_host) OVERRIDE;
virtual void DevToolsAgentStateChanged(content::DevToolsAgentHost* agent_host,
......@@ -28,6 +24,10 @@ class ChromeDevToolsManagerDelegate : public content::DevToolsManagerDelegate {
virtual base::DictionaryValue* HandleCommand(
content::DevToolsAgentHost* agent_host,
base::DictionaryValue* command_dict) OVERRIDE;
virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget(
const GURL& url) OVERRIDE;
virtual void EnumerateTargets(TargetCallback callback) OVERRIDE;
virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE;
private:
scoped_ptr<DevToolsNetworkProtocolHandler> network_protocol_handler_;
......
......@@ -45,6 +45,8 @@
'browser/android/content_view_util.h',
'browser/android/dev_tools_server.cc',
'browser/android/dev_tools_server.h',
'browser/android/dev_tools_manager_delegate_android.cc',
'browser/android/dev_tools_manager_delegate_android.h',
'browser/android/dom_distiller/feedback_reporter_android.cc',
'browser/android/dom_distiller/feedback_reporter_android.h',
'browser/android/favicon_helper.cc',
......
......@@ -19,8 +19,6 @@
'..',
],
'sources': [
'browser/devtools/chrome_devtools_manager_delegate.cc',
'browser/devtools/chrome_devtools_manager_delegate.h',
'browser/devtools/devtools_network_conditions.cc',
'browser/devtools/devtools_network_conditions.h',
'browser/devtools/devtools_network_controller.cc',
......@@ -80,6 +78,8 @@
'browser/devtools/device/usb/usb_device_provider.h',
'browser/devtools/browser_list_tabcontents_provider.cc',
'browser/devtools/browser_list_tabcontents_provider.h',
'browser/devtools/chrome_devtools_manager_delegate.cc',
'browser/devtools/chrome_devtools_manager_delegate.h',
'browser/devtools/devtools_contents_resizing_strategy.cc',
'browser/devtools/devtools_contents_resizing_strategy.h',
'browser/devtools/devtools_embedder_message_dispatcher.cc',
......
......@@ -12,6 +12,7 @@
#include "chromecast/shell/browser/cast_browser_context.h"
#include "chromecast/shell/browser/cast_browser_main_parts.h"
#include "chromecast/shell/browser/cast_browser_process.h"
#include "chromecast/shell/browser/devtools/cast_dev_tools_delegate.h"
#include "chromecast/shell/browser/geolocation/cast_access_token_store.h"
#include "chromecast/shell/browser/url_request_context_factory.h"
#include "content/public/browser/browser_thread.h"
......@@ -149,6 +150,11 @@ bool CastContentBrowserClient::CanCreateWindow(
return false;
}
content::DevToolsManagerDelegate*
CastContentBrowserClient::GetDevToolsManagerDelegate() {
return new CastDevToolsManagerDelegate();
}
void CastContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
const base::CommandLine& command_line,
int child_process_id,
......
......@@ -65,6 +65,8 @@ class CastContentBrowserClient: public content::ContentBrowserClient {
int render_process_id,
int opener_id,
bool* no_javascript_access) OVERRIDE;
virtual content::DevToolsManagerDelegate*
GetDevToolsManagerDelegate() OVERRIDE;
virtual void GetAdditionalMappedFilesForChildProcess(
const base::CommandLine& command_line,
int child_process_id,
......
......@@ -92,6 +92,8 @@ Target::Target(scoped_refptr<content::DevToolsAgentHost> agent_host)
} // namespace
// CastDevToolsDelegate -----------------------------------------------------
CastDevToolsDelegate::CastDevToolsDelegate() {
}
......@@ -111,16 +113,38 @@ base::FilePath CastDevToolsDelegate::GetDebugFrontendDir() {
return base::FilePath();
}
std::string CastDevToolsDelegate::GetPageThumbnailData(const GURL& url) {
return "";
scoped_ptr<net::StreamListenSocket>
CastDevToolsDelegate::CreateSocketForTethering(
net::StreamListenSocket::Delegate* delegate,
std::string* name) {
return scoped_ptr<net::StreamListenSocket>();
}
// CastDevToolsManagerDelegate -----------------------------------------------
CastDevToolsManagerDelegate::CastDevToolsManagerDelegate() {
}
CastDevToolsManagerDelegate::~CastDevToolsManagerDelegate() {
}
scoped_ptr<content::DevToolsTarget> CastDevToolsDelegate::CreateNewTarget(
base::DictionaryValue* CastDevToolsManagerDelegate::HandleCommand(
content::DevToolsAgentHost* agent_host,
base::DictionaryValue* command) {
return NULL;
}
std::string CastDevToolsManagerDelegate::GetPageThumbnailData(
const GURL& url) {
return "";
}
scoped_ptr<content::DevToolsTarget>
CastDevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
return scoped_ptr<content::DevToolsTarget>();
}
void CastDevToolsDelegate::EnumerateTargets(TargetCallback callback) {
void CastDevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) {
TargetList targets;
content::DevToolsAgentHost::List agents =
content::DevToolsAgentHost::GetOrCreateAll();
......@@ -131,12 +155,5 @@ void CastDevToolsDelegate::EnumerateTargets(TargetCallback callback) {
callback.Run(targets);
}
scoped_ptr<net::StreamListenSocket>
CastDevToolsDelegate::CreateSocketForTethering(
net::StreamListenSocket::Delegate* delegate,
std::string* name) {
return scoped_ptr<net::StreamListenSocket>();
}
} // namespace shell
} // namespace chromecast
......@@ -6,12 +6,17 @@
#define CHROMECAST_SHELL_BROWSER_DEVTOOLS_CAST_DEV_TOOLS_DELEGATE_H_
#include "content/public/browser/devtools_http_handler_delegate.h"
#include "content/public/browser/devtools_manager_delegate.h"
#include "net/socket/stream_listen_socket.h"
namespace base {
class FilePath;
}
namespace content {
class BrowserContext;
}
namespace chromecast {
namespace shell {
......@@ -24,10 +29,6 @@ class CastDevToolsDelegate : public content::DevToolsHttpHandlerDelegate {
virtual std::string GetDiscoveryPageHTML() OVERRIDE;
virtual bool BundlesFrontendResources() OVERRIDE;
virtual base::FilePath GetDebugFrontendDir() OVERRIDE;
virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE;
virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget(
const GURL& url) OVERRIDE;
virtual void EnumerateTargets(TargetCallback callback) OVERRIDE;
virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
net::StreamListenSocket::Delegate* delegate,
std::string* name) OVERRIDE;
......@@ -36,6 +37,30 @@ class CastDevToolsDelegate : public content::DevToolsHttpHandlerDelegate {
DISALLOW_COPY_AND_ASSIGN(CastDevToolsDelegate);
};
class CastDevToolsManagerDelegate : public content::DevToolsManagerDelegate {
public:
CastDevToolsManagerDelegate();
virtual ~CastDevToolsManagerDelegate();
// DevToolsManagerDelegate implementation.
virtual void Inspect(
content::BrowserContext* browser_context,
content::DevToolsAgentHost* agent_host) OVERRIDE {}
virtual void DevToolsAgentStateChanged(
content::DevToolsAgentHost* agent_host,
bool attached) OVERRIDE {}
virtual base::DictionaryValue* HandleCommand(
content::DevToolsAgentHost* agent_host,
base::DictionaryValue* command) OVERRIDE;
virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget(
const GURL& url) OVERRIDE;
virtual void EnumerateTargets(TargetCallback callback) OVERRIDE;
virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(CastDevToolsManagerDelegate);
};
} // namespace shell
} // namespace chromecast
......
......@@ -18,6 +18,7 @@
#include "base/threading/thread.h"
#include "base/values.h"
#include "content/browser/devtools/devtools_browser_target.h"
#include "content/browser/devtools/devtools_manager.h"
#include "content/browser/devtools/devtools_protocol.h"
#include "content/browser/devtools/devtools_protocol_constants.h"
#include "content/browser/devtools/devtools_system_info_handler.h"
......@@ -522,9 +523,16 @@ void DevToolsHttpHandlerImpl::OnJsonRequestUI(
if (command == "list") {
std::string host = info.headers["host"];
AddRef(); // Balanced in OnTargetListReceived.
delegate_->EnumerateTargets(
base::Bind(&DevToolsHttpHandlerImpl::OnTargetListReceived,
this, connection_id, host));
DevToolsManagerDelegate* manager_delegate =
DevToolsManager::GetInstance()->delegate();
if (manager_delegate) {
manager_delegate->EnumerateTargets(
base::Bind(&DevToolsHttpHandlerImpl::OnTargetListReceived,
this, connection_id, host));
} else {
DevToolsManagerDelegate::TargetList empty_list;
OnTargetListReceived(connection_id, host, empty_list);
}
return;
}
......@@ -533,7 +541,11 @@ void DevToolsHttpHandlerImpl::OnJsonRequestUI(
query, net::UnescapeRule::URL_SPECIAL_CHARS));
if (!url.is_valid())
url = GURL(url::kAboutBlankURL);
scoped_ptr<DevToolsTarget> target(delegate_->CreateNewTarget(url));
scoped_ptr<DevToolsTarget> target;
DevToolsManagerDelegate* manager_delegate =
DevToolsManager::GetInstance()->delegate();
if (manager_delegate)
target = manager_delegate->CreateNewTarget(url);
if (!target) {
SendJson(connection_id,
net::HTTP_INTERNAL_SERVER_ERROR,
......@@ -594,13 +606,13 @@ void DevToolsHttpHandlerImpl::OnJsonRequestUI(
void DevToolsHttpHandlerImpl::OnTargetListReceived(
int connection_id,
const std::string& host,
const DevToolsHttpHandlerDelegate::TargetList& targets) {
DevToolsHttpHandlerDelegate::TargetList sorted_targets = targets;
const DevToolsManagerDelegate::TargetList& targets) {
DevToolsManagerDelegate::TargetList sorted_targets = targets;
std::sort(sorted_targets.begin(), sorted_targets.end(), TimeComparator);
STLDeleteValues(&target_map_);
base::ListValue list_value;
for (DevToolsHttpHandlerDelegate::TargetList::const_iterator it =
for (DevToolsManagerDelegate::TargetList::const_iterator it =
sorted_targets.begin(); it != sorted_targets.end(); ++it) {
DevToolsTarget* target = *it;
target_map_[target->GetId()] = target;
......@@ -619,7 +631,10 @@ DevToolsTarget* DevToolsHttpHandlerImpl::GetTarget(const std::string& id) {
void DevToolsHttpHandlerImpl::OnThumbnailRequestUI(
int connection_id, const GURL& page_url) {
std::string data = delegate_->GetPageThumbnailData(page_url);
DevToolsManagerDelegate* manager_delegate =
DevToolsManager::GetInstance()->delegate();
std::string data =
manager_delegate ? manager_delegate->GetPageThumbnailData(page_url) : "";
if (!data.empty())
Send200(connection_id, data, "image/png");
else
......@@ -864,7 +879,10 @@ base::DictionaryValue* DevToolsHttpHandlerImpl::SerializeTarget(
if (favicon_url.is_valid())
dictionary->SetString(kTargetFaviconUrlField, favicon_url.spec());
if (!delegate_->GetPageThumbnailData(url).empty()) {
DevToolsManagerDelegate* manager_delegate =
DevToolsManager::GetInstance()->delegate();
if (manager_delegate &&
!manager_delegate->GetPageThumbnailData(url).empty()) {
dictionary->SetString(kTargetThumbnailUrlField,
std::string(kThumbUrlPrefix) + id);
}
......
......@@ -16,6 +16,7 @@
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_http_handler.h"
#include "content/public/browser/devtools_http_handler_delegate.h"
#include "content/public/browser/devtools_manager_delegate.h"
#include "net/http/http_status_code.h"
#include "net/server/http_server.h"
......@@ -80,7 +81,7 @@ class DevToolsHttpHandlerImpl
void OnTargetListReceived(
int connection_id,
const std::string& host,
const DevToolsHttpHandlerDelegate::TargetList& targets);
const DevToolsManagerDelegate::TargetList& targets);
DevToolsTarget* GetTarget(const std::string& id);
......
......@@ -86,18 +86,6 @@ class DummyDelegate : public DevToolsHttpHandlerDelegate {
return base::FilePath();
}
virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE {
return std::string();
}
virtual scoped_ptr<DevToolsTarget> CreateNewTarget(const GURL& url) OVERRIDE {
return scoped_ptr<DevToolsTarget>();
}
virtual void EnumerateTargets(TargetCallback callback) OVERRIDE {
callback.Run(TargetList());
}
virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
net::StreamListenSocket::Delegate* delegate,
std::string* name) OVERRIDE {
......
......@@ -12,8 +12,6 @@
#include "base/memory/scoped_ptr.h"
#include "net/socket/stream_listen_socket.h"
class GURL;
namespace content {
class DevToolsTarget;
......@@ -32,20 +30,6 @@ class DevToolsHttpHandlerDelegate {
// Returns path to the front-end files on the local filesystem for debugging.
virtual base::FilePath GetDebugFrontendDir() = 0;
// Get a thumbnail for a given page. Returns non-empty string iff we have the
// thumbnail.
virtual std::string GetPageThumbnailData(const GURL& url) = 0;
// Creates new inspectable target.
virtual scoped_ptr<DevToolsTarget> CreateNewTarget(const GURL& url) = 0;
typedef std::vector<DevToolsTarget*> TargetList;
typedef base::Callback<void(const TargetList&)> TargetCallback;
// Requests the list of all inspectable targets.
// The caller gets the ownership of the returned targets.
virtual void EnumerateTargets(TargetCallback callback) = 0;
// Creates named socket for reversed tethering implementation (used with
// remote debugging, primarily for mobile).
virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
......
......@@ -5,14 +5,22 @@
#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_
#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_
#include <string>
#include <vector>
#include "base/callback.h"
namespace base {
class DictionaryValue;
}
class GURL;
namespace content {
class BrowserContext;
class DevToolsAgentHost;
class DevToolsTarget;
class DevToolsManagerDelegate {
public:
......@@ -29,6 +37,20 @@ class DevToolsManagerDelegate {
virtual base::DictionaryValue* HandleCommand(
DevToolsAgentHost* agent_host,
base::DictionaryValue* command) = 0;
// Creates new inspectable target.
virtual scoped_ptr<DevToolsTarget> CreateNewTarget(const GURL& url) = 0;
typedef std::vector<DevToolsTarget*> TargetList;
typedef base::Callback<void(const TargetList&)> TargetCallback;
// Requests the list of all inspectable targets.
// The caller gets the ownership of the returned targets.
virtual void EnumerateTargets(TargetCallback callback) = 0;
// Get a thumbnail for a given page. Returns non-empty string iff we have the
// thumbnail.
virtual std::string GetPageThumbnailData(const GURL& url) = 0;
};
} // namespace content
......
......@@ -348,6 +348,11 @@ bool ShellContentBrowserClient::ShouldSwapProcessesForRedirect(
return g_swap_processes_for_redirect;
}
DevToolsManagerDelegate*
ShellContentBrowserClient::GetDevToolsManagerDelegate() {
return new ShellDevToolsManagerDelegate(browser_context());
}
#if defined(OS_POSIX) && !defined(OS_MACOSX)
void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
const CommandLine& command_line,
......
......@@ -75,6 +75,7 @@ class ShellContentBrowserClient : public ContentBrowserClient {
virtual bool ShouldSwapProcessesForRedirect(ResourceContext* resource_context,
const GURL& current_url,
const GURL& new_url) OVERRIDE;
virtual DevToolsManagerDelegate* GetDevToolsManagerDelegate() OVERRIDE;
#if defined(OS_POSIX) && !defined(OS_MACOSX)
virtual void GetAdditionalMappedFilesForChildProcess(
......
......@@ -178,6 +178,8 @@ bool Target::Close() const {
namespace content {
// ShellDevToolsDelegate ----------------------------------------------------
ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context)
: browser_context_(browser_context) {
std::string frontend_url;
......@@ -218,12 +220,36 @@ base::FilePath ShellDevToolsDelegate::GetDebugFrontendDir() {
return base::FilePath();
}
std::string ShellDevToolsDelegate::GetPageThumbnailData(const GURL& url) {
scoped_ptr<net::StreamListenSocket>
ShellDevToolsDelegate::CreateSocketForTethering(
net::StreamListenSocket::Delegate* delegate,
std::string* name) {
return scoped_ptr<net::StreamListenSocket>();
}
// ShellDevToolsManagerDelegate ----------------------------------------------
ShellDevToolsManagerDelegate::ShellDevToolsManagerDelegate(
BrowserContext* browser_context)
: browser_context_(browser_context) {
}
ShellDevToolsManagerDelegate::~ShellDevToolsManagerDelegate() {
}
base::DictionaryValue* ShellDevToolsManagerDelegate::HandleCommand(
DevToolsAgentHost* agent_host,
base::DictionaryValue* command) {
return NULL;
}
std::string ShellDevToolsManagerDelegate::GetPageThumbnailData(
const GURL& url) {
return std::string();
}
scoped_ptr<DevToolsTarget>
ShellDevToolsDelegate::CreateNewTarget(const GURL& url) {
ShellDevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
Shell* shell = Shell::CreateNewWindow(browser_context_,
url,
NULL,
......@@ -233,7 +259,7 @@ ShellDevToolsDelegate::CreateNewTarget(const GURL& url) {
new Target(DevToolsAgentHost::GetOrCreateFor(shell->web_contents())));
}
void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) {
void ShellDevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) {
TargetList targets;
content::DevToolsAgentHost::List agents =
content::DevToolsAgentHost::GetOrCreateAll();
......@@ -244,11 +270,4 @@ void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) {
callback.Run(targets);
}
scoped_ptr<net::StreamListenSocket>
ShellDevToolsDelegate::CreateSocketForTethering(
net::StreamListenSocket::Delegate* delegate,
std::string* name) {
return scoped_ptr<net::StreamListenSocket>();
}
} // namespace content
......@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "content/public/browser/devtools_http_handler_delegate.h"
#include "content/public/browser/devtools_manager_delegate.h"
namespace content {
......@@ -22,13 +23,10 @@ class ShellDevToolsDelegate : public DevToolsHttpHandlerDelegate {
// Stops http server.
void Stop();
// DevToolsHttpProtocolHandler::Delegate overrides.
// DevToolsHttpHandlerDelegate implementation.
virtual std::string GetDiscoveryPageHTML() OVERRIDE;
virtual bool BundlesFrontendResources() OVERRIDE;
virtual base::FilePath GetDebugFrontendDir() OVERRIDE;
virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE;
virtual scoped_ptr<DevToolsTarget> CreateNewTarget(const GURL& url) OVERRIDE;
virtual void EnumerateTargets(TargetCallback callback) OVERRIDE;
virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(
net::StreamListenSocket::Delegate* delegate,
std::string* name) OVERRIDE;
......@@ -44,6 +42,29 @@ class ShellDevToolsDelegate : public DevToolsHttpHandlerDelegate {
DISALLOW_COPY_AND_ASSIGN(ShellDevToolsDelegate);
};
class ShellDevToolsManagerDelegate : public DevToolsManagerDelegate {
public:
explicit ShellDevToolsManagerDelegate(BrowserContext* browser_context);
virtual ~ShellDevToolsManagerDelegate();
// DevToolsManagerDelegate implementation.
virtual void Inspect(BrowserContext* browser_context,
DevToolsAgentHost* agent_host) OVERRIDE {}
virtual void DevToolsAgentStateChanged(DevToolsAgentHost* agent_host,
bool attached) OVERRIDE {}
virtual base::DictionaryValue* HandleCommand(
DevToolsAgentHost* agent_host,
base::DictionaryValue* command) OVERRIDE;
virtual scoped_ptr<DevToolsTarget> CreateNewTarget(const GURL& url) OVERRIDE;
virtual void EnumerateTargets(TargetCallback callback) OVERRIDE;
virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE;
private:
BrowserContext* browser_context_;
DISALLOW_COPY_AND_ASSIGN(ShellDevToolsManagerDelegate);
};
} // namespace content
#endif // CONTENT_SHELL_BROWSER_SHELL_DEVTOOLS_DELEGATE_H_
......@@ -11,6 +11,7 @@
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_devtools_delegate.h"
#include "extensions/browser/extension_message_filter.h"
#include "extensions/browser/extension_protocols.h"
#include "extensions/browser/extension_registry.h"
......@@ -244,4 +245,9 @@ const Extension* ShellContentBrowserClient::GetExtension(
site_instance->GetSiteURL());
}
content::DevToolsManagerDelegate*
ShellContentBrowserClient::GetDevToolsManagerDelegate() {
return new content::ShellDevToolsManagerDelegate(GetBrowserContext());
}
} // namespace extensions
......@@ -60,6 +60,8 @@ class ShellContentBrowserClient : public content::ContentBrowserClient {
int plugin_process_id) OVERRIDE;
virtual void GetAdditionalAllowedSchemesForFileSystem(
std::vector<std::string>* additional_schemes) OVERRIDE;
virtual content::DevToolsManagerDelegate*
GetDevToolsManagerDelegate() OVERRIDE;
private:
// Appends command line switches for a renderer process.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment