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

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: Extracted DevToolsTarget class 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..4d94521087c97fb06f0f56162f48da613a785517 100644
--- a/chrome/browser/android/dev_tools_server.cc
+++ b/chrome/browser/android/dev_tools_server.cc
@@ -15,6 +15,7 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
+#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/devtools_adb_bridge.h"
#include "chrome/browser/history/top_sites.h"
@@ -23,18 +24,28 @@
#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/favicon_status.h"
+#include "content/public/browser/navigation_entry.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"
#include "jni/DevToolsServer_jni.h"
+#include "net/base/escape.h"
#include "net/socket/unix_domain_socket_posix.h"
#include "net/url_request/url_request_context_getter.h"
#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 +53,71 @@ const char kFrontEndURL[] =
const char kDefaultSocketNamePrefix[] = "chrome";
const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d";
+class Target : public content::DevToolsTarget {
+ public:
+ explicit Target(WebContents* web_contents);
+
+ virtual std::string GetId() const OVERRIDE { return id_; }
+ virtual std::string GetType() const OVERRIDE { return type_; }
+ 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_;
+ }
+ virtual bool IsAttached() const OVERRIDE {
+ return agent_host_->IsAttached();
+ }
+ virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
+ return agent_host_;
+ }
+ virtual bool Activate() const OVERRIDE;
+ virtual bool Close() const OVERRIDE;
+
+ private:
+ scoped_refptr<DevToolsAgentHost> agent_host_;
+ std::string id_;
+ std::string type_;
+ std::string title_;
+ GURL url_;
+ GURL favicon_url_;
+ base::TimeTicks last_activity_time_;
+};
+
+Target::Target(WebContents* web_contents) {
+ agent_host_ =
+ DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost());
+ id_ = agent_host_->GetId();
+ type_ = "page";
+ title_ = UTF16ToUTF8(net::EscapeForHTML(web_contents->GetTitle()));
+ url_ = web_contents->GetURL();
+ content::NavigationController& controller = web_contents->GetController();
+ content::NavigationEntry* entry = controller.GetActiveEntry();
+ if (entry != NULL && entry->GetURL().is_valid())
+ favicon_url_ = entry->GetFavicon().url;
+ last_activity_time_ = web_contents->GetLastSelectedTime();
+}
+
+bool Target::Activate() const {
+ RenderViewHost* rvh = agent_host_->GetRenderViewHost();
+ if (!rvh)
+ return false;
+ WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
+ if (!web_contents)
+ return false;
+ web_contents->GetDelegate()->ActivateContents(web_contents);
+ return true;
+}
+
+bool Target::Close() const {
+ RenderViewHost* rvh = agent_host_->GetRenderViewHost();
+ if (!rvh)
+ return false;
+ rvh->ClosePage();
+ return true;
+}
+
// 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 {
@@ -82,25 +158,30 @@ class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
return "";
}
- virtual content::RenderViewHost* CreateNewTarget() OVERRIDE {
+ virtual scoped_refptr<content::DevToolsTarget> 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();
- }
-
- virtual TargetType GetTargetType(content::RenderViewHost*) OVERRIDE {
- return kTargetTypeTab;
+ return new Target(web_contents);
}
- virtual std::string GetViewDescription(content::RenderViewHost*) OVERRIDE {
- return "";
+ virtual void EnumerateTargets(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(new Target(web_contents));
+ }
+ callback.Run(targets);
}
virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering(

Powered by Google App Engine
This is Rietveld 408576698