diff options
author | dgozman <dgozman@chromium.org> | 2014-09-22 05:40:06 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-22 12:40:22 +0000 |
commit | 252e18d2c4116131af20cac7759141ea930dcd28 (patch) | |
tree | 067f8dd6bc0a2be7dbf7d715218b0d08e2128a2c /chrome/browser | |
parent | 9b46fe6874291e1e50c9230b720293932dea6231 (diff) | |
download | chromium_src-252e18d2c4116131af20cac7759141ea930dcd28.zip chromium_src-252e18d2c4116131af20cac7759141ea930dcd28.tar.gz chromium_src-252e18d2c4116131af20cac7759141ea930dcd28.tar.bz2 |
[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}
Diffstat (limited to 'chrome/browser')
9 files changed, 440 insertions, 350 deletions
diff --git a/chrome/browser/android/dev_tools_manager_delegate_android.cc b/chrome/browser/android/dev_tools_manager_delegate_android.cc new file mode 100644 index 0000000..2754946 --- /dev/null +++ b/chrome/browser/android/dev_tools_manager_delegate_android.cc @@ -0,0 +1,345 @@ +// 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 "chrome/browser/android/dev_tools_manager_delegate_android.h" + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/strings/string_number_conversions.h" +#include "base/strings/utf_string_conversions.h" +#include "chrome/browser/android/tab_android.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/history/top_sites.h" +#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/ui/android/tab_model/tab_model.h" +#include "chrome/browser/ui/android/tab_model/tab_model_list.h" +#include "content/public/browser/devtools_agent_host.h" +#include "content/public/browser/devtools_target.h" +#include "content/public/browser/favicon_status.h" +#include "content/public/browser/navigation_entry.h" +#include "content/public/browser/web_contents.h" + +using content::DevToolsAgentHost; +using content::WebContents; + +namespace { + +const char kTargetTypePage[] = "page"; +const char kTargetTypeServiceWorker[] = "service_worker"; +const char kTargetTypeOther[] = "other"; + +GURL GetFaviconURLForContents(WebContents* web_contents) { + content::NavigationController& controller = web_contents->GetController(); + content::NavigationEntry* entry = controller.GetActiveEntry(); + if (entry != NULL && entry->GetURL().is_valid()) + return entry->GetFavicon().url; + return GURL(); +} + +GURL GetFaviconURLForAgentHost( + scoped_refptr<DevToolsAgentHost> agent_host) { + if (WebContents* web_contents = agent_host->GetWebContents()) + return GetFaviconURLForContents(web_contents); + return GURL(); +} + +base::TimeTicks GetLastActiveTimeForAgentHost( + scoped_refptr<DevToolsAgentHost> agent_host) { + if (WebContents* web_contents = agent_host->GetWebContents()) + return web_contents->GetLastActiveTime(); + return base::TimeTicks(); +} + +class TargetBase : public content::DevToolsTarget { + public: + // content::DevToolsTarget implementation: + virtual std::string GetParentId() const OVERRIDE { return std::string(); } + + virtual std::string GetTitle() const OVERRIDE { return title_; } + + virtual std::string GetDescription() const OVERRIDE { return std::string(); } + + virtual GURL GetURL() const OVERRIDE { return url_; } + + virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } + + virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { + return last_activity_time_; + } + + protected: + explicit TargetBase(WebContents* web_contents) + : title_(base::UTF16ToUTF8(web_contents->GetTitle())), + url_(web_contents->GetURL()), + favicon_url_(GetFaviconURLForContents(web_contents)), + last_activity_time_(web_contents->GetLastActiveTime()) { + } + + explicit TargetBase(scoped_refptr<DevToolsAgentHost> agent_host) + : title_(agent_host->GetTitle()), + url_(agent_host->GetURL()), + favicon_url_(GetFaviconURLForAgentHost(agent_host)), + last_activity_time_(GetLastActiveTimeForAgentHost(agent_host)) { + } + + TargetBase(const std::string& title, const GURL& url) + : title_(title), + url_(url) { + } + + private: + const std::string title_; + const GURL url_; + const GURL favicon_url_; + const base::TimeTicks last_activity_time_; +}; + +class TabTarget : public TargetBase { + public: + static TabTarget* CreateForWebContents(int tab_id, + WebContents* web_contents) { + return new TabTarget(tab_id, web_contents); + } + + static TabTarget* CreateForUnloadedTab(int tab_id, + const base::string16& title, + const GURL& url) { + return new TabTarget(tab_id, title, url); + } + + // content::DevToolsTarget implementation: + virtual std::string GetId() const OVERRIDE { + return base::IntToString(tab_id_); + } + + virtual std::string GetType() const OVERRIDE { + return kTargetTypePage; + } + + virtual bool IsAttached() const OVERRIDE { + TabModel* model; + int index; + if (!FindTab(&model, &index)) + return false; + WebContents* web_contents = model->GetWebContentsAt(index); + if (!web_contents) + return false; + return DevToolsAgentHost::IsDebuggerAttached(web_contents); + } + + virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { + TabModel* model; + int index; + if (!FindTab(&model, &index)) + return NULL; + WebContents* web_contents = model->GetWebContentsAt(index); + if (!web_contents) { + // The tab has been pushed out of memory, pull it back. + TabAndroid* tab = model->GetTabAt(index); + if (!tab) + return NULL; + + tab->LoadIfNeeded(); + web_contents = model->GetWebContentsAt(index); + if (!web_contents) + return NULL; + } + return DevToolsAgentHost::GetOrCreateFor(web_contents); + } + + virtual bool Activate() const OVERRIDE { + TabModel* model; + int index; + if (!FindTab(&model, &index)) + return false; + model->SetActiveIndex(index); + return true; + } + + virtual bool Close() const OVERRIDE { + TabModel* model; + int index; + if (!FindTab(&model, &index)) + return false; + model->CloseTabAt(index); + return true; + } + + private: + TabTarget(int tab_id, WebContents* web_contents) + : TargetBase(web_contents), + tab_id_(tab_id) { + } + + TabTarget(int tab_id, const base::string16& title, const GURL& url) + : TargetBase(base::UTF16ToUTF8(title), url), + tab_id_(tab_id) { + } + + bool FindTab(TabModel** model_result, int* index_result) const { + for (TabModelList::const_iterator iter = TabModelList::begin(); + iter != TabModelList::end(); ++iter) { + TabModel* model = *iter; + for (int i = 0; i < model->GetTabCount(); ++i) { + TabAndroid* tab = model->GetTabAt(i); + if (tab && tab->GetAndroidId() == tab_id_) { + *model_result = model; + *index_result = i; + return true; + } + } + } + return false; + } + + const int tab_id_; +}; + +class NonTabTarget : public TargetBase { + public: + explicit NonTabTarget(scoped_refptr<DevToolsAgentHost> agent_host) + : TargetBase(agent_host), + agent_host_(agent_host) { + } + + // content::DevToolsTarget implementation: + virtual std::string GetId() const OVERRIDE { + return agent_host_->GetId(); + } + + virtual std::string GetType() const OVERRIDE { + switch (agent_host_->GetType()) { + case DevToolsAgentHost::TYPE_WEB_CONTENTS: + if (TabModelList::begin() == TabModelList::end()) { + // If there are no tab models we must be running in ChromeShell. + // Return the 'page' target type for backwards compatibility. + return kTargetTypePage; + } + break; + case DevToolsAgentHost::TYPE_SERVICE_WORKER: + return kTargetTypeServiceWorker; + default: + break; + } + return kTargetTypeOther; + } + + 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_; +}; + +} // namespace + +DevToolsManagerDelegateAndroid::DevToolsManagerDelegateAndroid() + : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { +} + +DevToolsManagerDelegateAndroid::~DevToolsManagerDelegateAndroid() { +} + +void DevToolsManagerDelegateAndroid::Inspect( + content::BrowserContext* browser_context, + content::DevToolsAgentHost* agent_host) { +} + +base::DictionaryValue* DevToolsManagerDelegateAndroid::HandleCommand( + content::DevToolsAgentHost* agent_host, + base::DictionaryValue* command_dict) { + return network_protocol_handler_->HandleCommand(agent_host, command_dict); +} + +void DevToolsManagerDelegateAndroid::DevToolsAgentStateChanged( + content::DevToolsAgentHost* agent_host, + bool attached) { + network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); +} + +scoped_ptr<content::DevToolsTarget> + DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) { + if (TabModelList::empty()) + return scoped_ptr<content::DevToolsTarget>(); + + TabModel* tab_model = TabModelList::get(0); + if (!tab_model) + return scoped_ptr<content::DevToolsTarget>(); + + WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); + if (!web_contents) + return scoped_ptr<content::DevToolsTarget>(); + + TabAndroid* tab = TabAndroid::FromWebContents(web_contents); + if (!tab) + return scoped_ptr<content::DevToolsTarget>(); + + return scoped_ptr<content::DevToolsTarget>( + TabTarget::CreateForWebContents(tab->GetAndroidId(), web_contents)); +} + +void DevToolsManagerDelegateAndroid::EnumerateTargets(TargetCallback callback) { + TargetList targets; + + // Enumerate existing tabs, including the ones with no WebContents. + std::set<WebContents*> tab_web_contents; + for (TabModelList::const_iterator iter = TabModelList::begin(); + iter != TabModelList::end(); ++iter) { + TabModel* model = *iter; + for (int i = 0; i < model->GetTabCount(); ++i) { + TabAndroid* tab = model->GetTabAt(i); + if (!tab) + continue; + + WebContents* web_contents = model->GetWebContentsAt(i); + if (web_contents) { + tab_web_contents.insert(web_contents); + targets.push_back(TabTarget::CreateForWebContents(tab->GetAndroidId(), + web_contents)); + } else { + targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), + tab->GetTitle(), + tab->GetURL())); + } + } + } + + // Add targets for WebContents not associated with any tabs. + DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); + for (DevToolsAgentHost::List::iterator it = agents.begin(); + it != agents.end(); ++it) { + if (WebContents* web_contents = (*it)->GetWebContents()) { + if (tab_web_contents.find(web_contents) != tab_web_contents.end()) + continue; + } + targets.push_back(new NonTabTarget(*it)); + } + + callback.Run(targets); +} + +std::string DevToolsManagerDelegateAndroid::GetPageThumbnailData( + const GURL& url) { + Profile* profile = ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); + history::TopSites* top_sites = profile->GetTopSites(); + if (top_sites) { + scoped_refptr<base::RefCountedMemory> data; + if (top_sites->GetPageThumbnail(url, false, &data)) + return std::string(data->front_as<char>(), data->size()); + } + return std::string(); +} diff --git a/chrome/browser/android/dev_tools_manager_delegate_android.h b/chrome/browser/android/dev_tools_manager_delegate_android.h new file mode 100644 index 0000000..78bcb18 --- /dev/null +++ b/chrome/browser/android/dev_tools_manager_delegate_android.h @@ -0,0 +1,38 @@ +// 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_ diff --git a/chrome/browser/android/dev_tools_server.cc b/chrome/browser/android/dev_tools_server.cc index e41b65f..d577eb9 100644 --- a/chrome/browser/android/dev_tools_server.cc +++ b/chrome/browser/android/dev_tools_server.cc @@ -67,32 +67,6 @@ const char kFrontEndURL[] = "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d"; -const char kTargetTypePage[] = "page"; -const char kTargetTypeServiceWorker[] = "service_worker"; -const char kTargetTypeOther[] = "other"; - -static GURL GetFaviconURLForContents(WebContents* web_contents) { - content::NavigationController& controller = web_contents->GetController(); - content::NavigationEntry* entry = controller.GetActiveEntry(); - if (entry != NULL && entry->GetURL().is_valid()) - return entry->GetFavicon().url; - return GURL(); -} - -static GURL GetFaviconURLForAgentHost( - scoped_refptr<DevToolsAgentHost> agent_host) { - if (WebContents* web_contents = agent_host->GetWebContents()) - return GetFaviconURLForContents(web_contents); - return GURL(); -} - -static base::TimeTicks GetLastActiveTimeForAgentHost( - scoped_refptr<DevToolsAgentHost> agent_host) { - if (WebContents* web_contents = agent_host->GetWebContents()) - return web_contents->GetLastActiveTime(); - return base::TimeTicks(); -} - bool AuthorizeSocketAccessWithDebugPermission( const net::UnixDomainServerSocket::Credentials& credentials) { JNIEnv* env = base::android::AttachCurrentThread(); @@ -102,200 +76,6 @@ bool AuthorizeSocketAccessWithDebugPermission( content::CanUserConnectToDevTools(credentials); } -class TargetBase : public content::DevToolsTarget { - public: - // content::DevToolsTarget implementation: - virtual std::string GetParentId() const OVERRIDE { return std::string(); } - - virtual std::string GetTitle() const OVERRIDE { return title_; } - - virtual std::string GetDescription() const OVERRIDE { return std::string(); } - - virtual GURL GetURL() const OVERRIDE { return url_; } - - virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } - - virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { - return last_activity_time_; - } - - protected: - explicit TargetBase(WebContents* web_contents) - : title_(base::UTF16ToUTF8(web_contents->GetTitle())), - url_(web_contents->GetURL()), - favicon_url_(GetFaviconURLForContents(web_contents)), - last_activity_time_(web_contents->GetLastActiveTime()) { - } - - explicit TargetBase(scoped_refptr<DevToolsAgentHost> agent_host) - : title_(agent_host->GetTitle()), - url_(agent_host->GetURL()), - favicon_url_(GetFaviconURLForAgentHost(agent_host)), - last_activity_time_(GetLastActiveTimeForAgentHost(agent_host)) { - } - - TargetBase(const std::string& title, const GURL& url) - : title_(title), - url_(url) { - } - - private: - const std::string title_; - const GURL url_; - const GURL favicon_url_; - const base::TimeTicks last_activity_time_; -}; - -class TabTarget : public TargetBase { - public: - static TabTarget* CreateForWebContents(int tab_id, - WebContents* web_contents) { - return new TabTarget(tab_id, web_contents); - } - - static TabTarget* CreateForUnloadedTab(int tab_id, - const base::string16& title, - const GURL& url) { - return new TabTarget(tab_id, title, url); - } - - // content::DevToolsTarget implementation: - virtual std::string GetId() const OVERRIDE { - return base::IntToString(tab_id_); - } - - virtual std::string GetType() const OVERRIDE { - return kTargetTypePage; - } - - virtual bool IsAttached() const OVERRIDE { - TabModel* model; - int index; - if (!FindTab(&model, &index)) - return false; - WebContents* web_contents = model->GetWebContentsAt(index); - if (!web_contents) - return false; - return DevToolsAgentHost::IsDebuggerAttached(web_contents); - } - - virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { - TabModel* model; - int index; - if (!FindTab(&model, &index)) - return NULL; - WebContents* web_contents = model->GetWebContentsAt(index); - if (!web_contents) { - // The tab has been pushed out of memory, pull it back. - TabAndroid* tab = model->GetTabAt(index); - if (!tab) - return NULL; - - tab->LoadIfNeeded(); - web_contents = model->GetWebContentsAt(index); - if (!web_contents) - return NULL; - } - return DevToolsAgentHost::GetOrCreateFor(web_contents); - } - - virtual bool Activate() const OVERRIDE { - TabModel* model; - int index; - if (!FindTab(&model, &index)) - return false; - model->SetActiveIndex(index); - return true; - } - - virtual bool Close() const OVERRIDE { - TabModel* model; - int index; - if (!FindTab(&model, &index)) - return false; - model->CloseTabAt(index); - return true; - } - - private: - TabTarget(int tab_id, WebContents* web_contents) - : TargetBase(web_contents), - tab_id_(tab_id) { - } - - TabTarget(int tab_id, const base::string16& title, const GURL& url) - : TargetBase(base::UTF16ToUTF8(title), url), - tab_id_(tab_id) { - } - - bool FindTab(TabModel** model_result, int* index_result) const { - for (TabModelList::const_iterator iter = TabModelList::begin(); - iter != TabModelList::end(); ++iter) { - TabModel* model = *iter; - for (int i = 0; i < model->GetTabCount(); ++i) { - TabAndroid* tab = model->GetTabAt(i); - if (tab && tab->GetAndroidId() == tab_id_) { - *model_result = model; - *index_result = i; - return true; - } - } - } - return false; - } - - const int tab_id_; -}; - -class NonTabTarget : public TargetBase { - public: - explicit NonTabTarget(scoped_refptr<DevToolsAgentHost> agent_host) - : TargetBase(agent_host), - agent_host_(agent_host) { - } - - // content::DevToolsTarget implementation: - virtual std::string GetId() const OVERRIDE { - return agent_host_->GetId(); - } - - virtual std::string GetType() const OVERRIDE { - switch (agent_host_->GetType()) { - case DevToolsAgentHost::TYPE_WEB_CONTENTS: - if (TabModelList::begin() == TabModelList::end()) { - // If there are no tab models we must be running in ChromeShell. - // Return the 'page' target type for backwards compatibility. - return kTargetTypePage; - } - break; - case DevToolsAgentHost::TYPE_SERVICE_WORKER: - return kTargetTypeServiceWorker; - default: - break; - } - return kTargetTypeOther; - } - - 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_; -}; - // Delegate implementation for the devtools http handler on android. A new // instance of this gets created each time devtools is enabled. class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { @@ -325,78 +105,6 @@ class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { return base::FilePath(); } - virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE { - Profile* profile = - ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); - history::TopSites* top_sites = profile->GetTopSites(); - if (top_sites) { - scoped_refptr<base::RefCountedMemory> data; - if (top_sites->GetPageThumbnail(url, false, &data)) - return std::string(data->front_as<char>(), data->size()); - } - return ""; - } - - virtual scoped_ptr<content::DevToolsTarget> CreateNewTarget( - const GURL& url) OVERRIDE { - if (TabModelList::empty()) - return scoped_ptr<content::DevToolsTarget>(); - TabModel* tab_model = TabModelList::get(0); - if (!tab_model) - return scoped_ptr<content::DevToolsTarget>(); - WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); - if (!web_contents) - return scoped_ptr<content::DevToolsTarget>(); - - TabAndroid* tab = TabAndroid::FromWebContents(web_contents); - if (!tab) - return scoped_ptr<content::DevToolsTarget>(); - - return scoped_ptr<content::DevToolsTarget>( - TabTarget::CreateForWebContents(tab->GetAndroidId(), web_contents)); - } - - virtual void EnumerateTargets(TargetCallback callback) OVERRIDE { - TargetList targets; - - // Enumerate existing tabs, including the ones with no WebContents. - std::set<WebContents*> tab_web_contents; - for (TabModelList::const_iterator iter = TabModelList::begin(); - iter != TabModelList::end(); ++iter) { - TabModel* model = *iter; - for (int i = 0; i < model->GetTabCount(); ++i) { - TabAndroid* tab = model->GetTabAt(i); - if (!tab) - continue; - - WebContents* web_contents = model->GetWebContentsAt(i); - if (web_contents) { - tab_web_contents.insert(web_contents); - targets.push_back(TabTarget::CreateForWebContents(tab->GetAndroidId(), - web_contents)); - } else { - targets.push_back(TabTarget::CreateForUnloadedTab(tab->GetAndroidId(), - tab->GetTitle(), - tab->GetURL())); - } - } - } - - // Add targets for WebContents not associated with any tabs. - DevToolsAgentHost::List agents = - DevToolsAgentHost::GetOrCreateAll(); - for (DevToolsAgentHost::List::iterator it = agents.begin(); - it != agents.end(); ++it) { - if (WebContents* web_contents = (*it)->GetWebContents()) { - if (tab_web_contents.find(web_contents) != tab_web_contents.end()) - continue; - } - targets.push_back(new NonTabTarget(*it)); - } - - callback.Run(targets); - } - virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( net::StreamListenSocket::Delegate* delegate, std::string* name) OVERRIDE { diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index e655615..e5c7911 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -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( diff --git a/chrome/browser/devtools/BUILD.gn b/chrome/browser/devtools/BUILD.gn index d1def53..9404d4b 100644 --- a/chrome/browser/devtools/BUILD.gn +++ b/chrome/browser/devtools/BUILD.gn @@ -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", diff --git a/chrome/browser/devtools/browser_list_tabcontents_provider.cc b/chrome/browser/devtools/browser_list_tabcontents_provider.cc index 4ddb06f..6110231 100644 --- a/chrome/browser/devtools/browser_list_tabcontents_provider.cc +++ b/chrome/browser/devtools/browser_list_tabcontents_provider.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(¶ms); - 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, diff --git a/chrome/browser/devtools/browser_list_tabcontents_provider.h b/chrome/browser/devtools/browser_list_tabcontents_provider.h index 3296385..db425d0b 100644 --- a/chrome/browser/devtools/browser_list_tabcontents_provider.h +++ b/chrome/browser/devtools/browser_list_tabcontents_provider.h @@ -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; diff --git a/chrome/browser/devtools/chrome_devtools_manager_delegate.cc b/chrome/browser/devtools/chrome_devtools_manager_delegate.cc index fd9cfed..1bd1a82 100644 --- a/chrome/browser/devtools/chrome_devtools_manager_delegate.cc +++ b/chrome/browser/devtools/chrome_devtools_manager_delegate.cc @@ -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(¶ms); + 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)); +} + diff --git a/chrome/browser/devtools/chrome_devtools_manager_delegate.h b/chrome/browser/devtools/chrome_devtools_manager_delegate.h index 3885e48..08b7e62 100644 --- a/chrome/browser/devtools/chrome_devtools_manager_delegate.h +++ b/chrome/browser/devtools/chrome_devtools_manager_delegate.h @@ -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_; |