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

Unified Diff: content/shell/browser/shell_devtools_delegate.cc

Issue 24995003: DevTools: Extract target discovery and manipulation from DevToolsHttpHandlerImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed clang compile and a minor bug 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: content/shell/browser/shell_devtools_delegate.cc
diff --git a/content/shell/browser/shell_devtools_delegate.cc b/content/shell/browser/shell_devtools_delegate.cc
index c8d256f61256127e8668ef7e235ffff04d03eb6a..8e47884953916559632960e652a6cd10da1e302c 100644
--- a/content/shell/browser/shell_devtools_delegate.cc
+++ b/content/shell/browser/shell_devtools_delegate.cc
@@ -9,12 +9,18 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_http_handler.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/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/shell/browser/shell.h"
#include "grit/shell_resources.h"
+#include "net/base/escape.h"
#include "net/socket/tcp_listen_socket.h"
#include "ui/base/resource/resource_bundle.h"
@@ -23,8 +29,14 @@
#include "net/socket/unix_domain_socket_posix.h"
#endif
+using content::DevToolsAgentHost;
+using content::RenderViewHost;
+using content::WebContents;
+
namespace {
+const char kTargetTypePage[] = "page";
+
net::StreamListenSocketFactory* CreateSocketFactory() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
#if defined(OS_ANDROID)
@@ -53,6 +65,72 @@ net::StreamListenSocketFactory* CreateSocketFactory() {
return new net::TCPListenSocketFactory("127.0.0.1", port);
#endif
}
+
+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:
+ virtual ~Target() {}
+
+ 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;
+}
+
} // namespace
namespace content {
@@ -90,23 +168,26 @@ std::string ShellDevToolsDelegate::GetPageThumbnailData(const GURL& url) {
return std::string();
}
-RenderViewHost* ShellDevToolsDelegate::CreateNewTarget() {
+scoped_refptr<DevToolsTarget> ShellDevToolsDelegate::CreateNewTarget() {
Shell* shell = Shell::CreateNewWindow(browser_context_,
GURL(kAboutBlankURL),
NULL,
MSG_ROUTING_NONE,
gfx::Size());
- return shell->web_contents()->GetRenderViewHost();
+ return new Target(shell->web_contents());
}
-DevToolsHttpHandlerDelegate::TargetType
-ShellDevToolsDelegate::GetTargetType(RenderViewHost*) {
- return kTargetTypeTab;
-}
-
-std::string ShellDevToolsDelegate::GetViewDescription(
- content::RenderViewHost*) {
- return std::string();
+void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) {
+ TargetList targets;
+ std::vector<RenderViewHost*> rvh_list =
+ content::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);
}
scoped_ptr<net::StreamListenSocket>

Powered by Google App Engine
This is Rietveld 408576698