Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3457)

Unified Diff: chrome/browser/android/dev_tools_server.cc

Issue 24995003: DevTools: Extract target discovery and manipulation from DevToolsHttpHandlerImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added Android implementations Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/dev_tools_server.cc
diff --git a/chrome/browser/android/dev_tools_server.cc b/chrome/browser/android/dev_tools_server.cc
index 771aa1e7dc9d8b7eab23750708257015cc60582e..aed5269a9e0f4c9032a3b243ed75ac3b017bb6ff 100644
--- a/chrome/browser/android/dev_tools_server.cc
+++ b/chrome/browser/android/dev_tools_server.cc
@@ -23,9 +23,13 @@
#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
#include "content/public/browser/android/devtools_auth.h"
#include "content/public/browser/browser_thread.h"
+#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_target_descriptor.h"
+#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "grit/devtools_discovery_page_resources.h"
@@ -35,6 +39,10 @@
#include "ui/base/resource/resource_bundle.h"
#include "webkit/common/user_agent/user_agent_util.h"
+using content::DevToolsAgentHost;
+using content::RenderViewHost;
+using content::WebContents;
+
namespace {
const char kFrontEndURL[] =
@@ -42,6 +50,16 @@ const char kFrontEndURL[] =
const char kDefaultSocketNamePrefix[] = "chrome";
const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d";
+RenderViewHost* GetRenderViewHost(const std::string& id) {
+ DevToolsAgentHost* agent_host = DevToolsAgentHost::GetForId(id);
+ return agent_host ? agent_host->GetRenderViewHost() : NULL;
+}
+
+WebContents* GetWebContents(const std::string& id) {
+ RenderViewHost* rvh = GetRenderViewHost(id);
+ return rvh ? WebContents::FromRenderViewHost(rvh) : NULL;
+}
+
// 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 {
@@ -69,7 +87,16 @@ class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
return base::FilePath();
}
- virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE {
+ virtual bool SupportsPageThumbnails() OVERRIDE {
+ return true;
+ }
+
+ virtual std::string GetPageThumbnailData(const std::string& id) OVERRIDE {
+ WebContents* web_contents = GetWebContents(id);
+ if (!web_contents)
+ return "";
+
+ GURL url = web_contents->GetURL();
Profile* profile =
ProfileManager::GetLastUsedProfile()->GetOriginalProfile();
history::TopSites* top_sites = profile->GetTopSites();
@@ -82,25 +109,51 @@ class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
return "";
}
- virtual content::RenderViewHost* CreateNewTarget() OVERRIDE {
+ virtual Target* CreateNewTarget() OVERRIDE {
Profile* profile =
g_browser_process->profile_manager()->GetDefaultProfile();
TabModel* tab_model = TabModelList::GetTabModelWithProfile(profile);
if (!tab_model)
return NULL;
- content::WebContents* web_contents =
+ WebContents* web_contents =
tab_model->CreateTabForTesting(GURL(content::kAboutBlankURL));
if (!web_contents)
return NULL;
- return web_contents->GetRenderViewHost();
+ return Target::FromWebContents(web_contents);
}
- virtual TargetType GetTargetType(content::RenderViewHost*) OVERRIDE {
- return kTargetTypeTab;
+ virtual bool ActivateTarget(const std::string& id) OVERRIDE {
+ WebContents* web_contents = GetWebContents(id);
+ if (!web_contents)
+ return false;
+ web_contents->GetDelegate()->ActivateContents(web_contents);
+ return true;
}
- virtual std::string GetViewDescription(content::RenderViewHost*) OVERRIDE {
- return "";
+ virtual bool CloseTarget(const std::string& id) OVERRIDE {
+ RenderViewHost* rvh = GetRenderViewHost(id);
+ if (!rvh)
+ return false;
+ rvh->ClosePage();
+ return true;
+ }
+
+ virtual scoped_refptr<DevToolsAgentHost> GetAgentHost(
+ const std::string& id) OVERRIDE {
+ return DevToolsAgentHost::GetForId(id);
+ }
+
+ virtual void RequestTargets(TargetCallback callback) OVERRIDE {
+ TargetList targets;
+ std::vector<RenderViewHost*> rvh_list =
+ DevToolsAgentHost::GetValidRenderViewHosts();
+ for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin();
+ it != rvh_list.end(); ++it) {
+ WebContents* web_contents = WebContents::FromRenderViewHost(*it);
+ if (web_contents)
+ targets.push_back(Target::FromWebContents(web_contents));
+ }
+ callback.Run(targets);
}
virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(

Powered by Google App Engine
This is Rietveld 408576698