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..87014f8dc075e02f3ca40303f06b6cf2924bec00 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,29 @@ |
#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.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 +54,71 @@ const char kFrontEndURL[] = |
const char kDefaultSocketNamePrefix[] = "chrome"; |
const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d"; |
+const char kTargetTypePage[] = "page"; |
+ |
+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 kTargetTypePage; } |
+ 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 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(); |
+ 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 +159,30 @@ class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
return ""; |
} |
- virtual content::RenderViewHost* CreateNewTarget() OVERRIDE { |
+ virtual scoped_ptr<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 = |
+ return scoped_ptr<content::DevToolsTarget>(); |
+ 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 scoped_ptr<content::DevToolsTarget>(); |
+ return scoped_ptr<content::DevToolsTarget>(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( |