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

Side by Side 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: Extracted DevToolsTarget class Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/shell/browser/shell_devtools_delegate.h" 5 #include "content/shell/browser/shell_devtools_delegate.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "content/public/browser/devtools_agent_host.h"
12 #include "content/public/browser/devtools_http_handler.h" 14 #include "content/public/browser/devtools_http_handler.h"
15 #include "content/public/browser/favicon_status.h"
16 #include "content/public/browser/navigation_entry.h"
17 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
15 #include "content/public/common/url_constants.h" 20 #include "content/public/common/url_constants.h"
16 #include "content/shell/browser/shell.h" 21 #include "content/shell/browser/shell.h"
17 #include "grit/shell_resources.h" 22 #include "grit/shell_resources.h"
23 #include "net/base/escape.h"
18 #include "net/socket/tcp_listen_socket.h" 24 #include "net/socket/tcp_listen_socket.h"
19 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
20 26
21 #if defined(OS_ANDROID) 27 #if defined(OS_ANDROID)
22 #include "content/public/browser/android/devtools_auth.h" 28 #include "content/public/browser/android/devtools_auth.h"
23 #include "net/socket/unix_domain_socket_posix.h" 29 #include "net/socket/unix_domain_socket_posix.h"
24 #endif 30 #endif
25 31
32 using content::DevToolsAgentHost;
33 using content::RenderViewHost;
34 using content::WebContents;
35
26 namespace { 36 namespace {
27 37
28 net::StreamListenSocketFactory* CreateSocketFactory() { 38 net::StreamListenSocketFactory* CreateSocketFactory() {
29 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 39 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
30 #if defined(OS_ANDROID) 40 #if defined(OS_ANDROID)
31 std::string socket_name = "content_shell_devtools_remote"; 41 std::string socket_name = "content_shell_devtools_remote";
32 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { 42 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) {
33 socket_name = command_line.GetSwitchValueASCII( 43 socket_name = command_line.GetSwitchValueASCII(
34 switches::kRemoteDebuggingSocketName); 44 switches::kRemoteDebuggingSocketName);
35 } 45 }
(...skipping 10 matching lines...) Expand all
46 if (base::StringToInt(port_str, &temp_port) && 56 if (base::StringToInt(port_str, &temp_port) &&
47 temp_port > 0 && temp_port < 65535) { 57 temp_port > 0 && temp_port < 65535) {
48 port = temp_port; 58 port = temp_port;
49 } else { 59 } else {
50 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; 60 DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
51 } 61 }
52 } 62 }
53 return new net::TCPListenSocketFactory("127.0.0.1", port); 63 return new net::TCPListenSocketFactory("127.0.0.1", port);
54 #endif 64 #endif
55 } 65 }
66
67 class Target : public content::DevToolsTarget {
68 public:
69 explicit Target(WebContents* web_contents);
70
71 virtual std::string GetId() const OVERRIDE { return id_; }
72 virtual std::string GetType() const OVERRIDE { return type_; }
73 virtual std::string GetTitle() const OVERRIDE { return title_; }
74 virtual std::string GetDescription() const OVERRIDE { return std::string(); }
75 virtual GURL GetUrl() const OVERRIDE { return url_; }
76 virtual GURL GetFaviconUrl() const OVERRIDE { return favicon_url_; }
77 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
78 return last_activity_time_;
79 }
80 virtual bool IsAttached() const OVERRIDE {
81 return agent_host_->IsAttached();
82 }
83 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
84 return agent_host_;
85 }
86 virtual bool Activate() const OVERRIDE;
87 virtual bool Close() const OVERRIDE;
88
89 private:
90 scoped_refptr<DevToolsAgentHost> agent_host_;
91 std::string id_;
92 std::string type_;
93 std::string title_;
94 GURL url_;
95 GURL favicon_url_;
96 base::TimeTicks last_activity_time_;
97 };
98
99 Target::Target(WebContents* web_contents) {
100 agent_host_ =
101 DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost());
102 id_ = agent_host_->GetId();
103 type_ = "page";
104 title_ = UTF16ToUTF8(net::EscapeForHTML(web_contents->GetTitle()));
105 url_ = web_contents->GetURL();
106 content::NavigationController& controller = web_contents->GetController();
107 content::NavigationEntry* entry = controller.GetActiveEntry();
108 if (entry != NULL && entry->GetURL().is_valid())
109 favicon_url_ = entry->GetFavicon().url;
110 last_activity_time_ = web_contents->GetLastSelectedTime();
111 }
112
113 bool Target::Activate() const {
114 RenderViewHost* rvh = agent_host_->GetRenderViewHost();
115 if (!rvh)
116 return false;
117 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
118 if (!web_contents)
119 return false;
120 web_contents->GetDelegate()->ActivateContents(web_contents);
121 return true;
122 }
123
124 bool Target::Close() const {
125 RenderViewHost* rvh = agent_host_->GetRenderViewHost();
126 if (!rvh)
127 return false;
128 rvh->ClosePage();
129 return true;
130 }
131
56 } // namespace 132 } // namespace
57 133
58 namespace content { 134 namespace content {
59 135
60 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context) 136 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context)
61 : browser_context_(browser_context) { 137 : browser_context_(browser_context) {
62 // Note that Content Shell always used bundled DevTools frontend, 138 // Note that Content Shell always used bundled DevTools frontend,
63 // even on Android, because the shell is used for running layout tests. 139 // even on Android, because the shell is used for running layout tests.
64 devtools_http_handler_ = 140 devtools_http_handler_ =
65 DevToolsHttpHandler::Start(CreateSocketFactory(), std::string(), this); 141 DevToolsHttpHandler::Start(CreateSocketFactory(), std::string(), this);
(...skipping 17 matching lines...) Expand all
83 } 159 }
84 160
85 base::FilePath ShellDevToolsDelegate::GetDebugFrontendDir() { 161 base::FilePath ShellDevToolsDelegate::GetDebugFrontendDir() {
86 return base::FilePath(); 162 return base::FilePath();
87 } 163 }
88 164
89 std::string ShellDevToolsDelegate::GetPageThumbnailData(const GURL& url) { 165 std::string ShellDevToolsDelegate::GetPageThumbnailData(const GURL& url) {
90 return std::string(); 166 return std::string();
91 } 167 }
92 168
93 RenderViewHost* ShellDevToolsDelegate::CreateNewTarget() { 169 scoped_refptr<DevToolsTarget> ShellDevToolsDelegate::CreateNewTarget() {
94 Shell* shell = Shell::CreateNewWindow(browser_context_, 170 Shell* shell = Shell::CreateNewWindow(browser_context_,
95 GURL(kAboutBlankURL), 171 GURL(kAboutBlankURL),
96 NULL, 172 NULL,
97 MSG_ROUTING_NONE, 173 MSG_ROUTING_NONE,
98 gfx::Size()); 174 gfx::Size());
99 return shell->web_contents()->GetRenderViewHost(); 175 return new Target(shell->web_contents());
100 } 176 }
101 177
102 DevToolsHttpHandlerDelegate::TargetType 178 void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) {
103 ShellDevToolsDelegate::GetTargetType(RenderViewHost*) { 179 TargetList targets;
104 return kTargetTypeTab; 180 std::vector<RenderViewHost*> rvh_list =
105 } 181 content::DevToolsAgentHost::GetValidRenderViewHosts();
106 182 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin();
107 std::string ShellDevToolsDelegate::GetViewDescription( 183 it != rvh_list.end(); ++it) {
108 content::RenderViewHost*) { 184 WebContents* web_contents = WebContents::FromRenderViewHost(*it);
109 return std::string(); 185 if (web_contents)
186 targets.push_back(new Target(web_contents));
187 }
188 callback.Run(targets);
110 } 189 }
111 190
112 scoped_ptr<net::StreamListenSocket> 191 scoped_ptr<net::StreamListenSocket>
113 ShellDevToolsDelegate::CreateSocketForTethering( 192 ShellDevToolsDelegate::CreateSocketForTethering(
114 net::StreamListenSocket::Delegate* delegate, 193 net::StreamListenSocket::Delegate* delegate,
115 std::string* name) { 194 std::string* name) {
116 return scoped_ptr<net::StreamListenSocket>(); 195 return scoped_ptr<net::StreamListenSocket>();
117 } 196 }
118 197
119 } // namespace content 198 } // namespace content
OLDNEW
« content/public/browser/devtools_target.h ('K') | « content/shell/browser/shell_devtools_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698