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

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: Added Android implementations 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 "content/public/browser/devtools_agent_host.h"
12 #include "content/public/browser/devtools_http_handler.h" 13 #include "content/public/browser/devtools_http_handler.h"
14 #include "content/public/browser/devtools_target_descriptor.h"
15 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
15 #include "content/public/common/url_constants.h" 18 #include "content/public/common/url_constants.h"
16 #include "content/shell/browser/shell.h" 19 #include "content/shell/browser/shell.h"
17 #include "grit/shell_resources.h" 20 #include "grit/shell_resources.h"
18 #include "net/socket/tcp_listen_socket.h" 21 #include "net/socket/tcp_listen_socket.h"
19 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
20 23
21 #if defined(OS_ANDROID) 24 #if defined(OS_ANDROID)
22 #include "content/public/browser/android/devtools_auth.h" 25 #include "content/public/browser/android/devtools_auth.h"
23 #include "net/socket/unix_domain_socket_posix.h" 26 #include "net/socket/unix_domain_socket_posix.h"
24 #endif 27 #endif
25 28
29 using content::DevToolsAgentHost;
30 using content::RenderViewHost;
31 using content::WebContents;
32
26 namespace { 33 namespace {
27 34
28 net::StreamListenSocketFactory* CreateSocketFactory() { 35 net::StreamListenSocketFactory* CreateSocketFactory() {
29 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 36 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
30 #if defined(OS_ANDROID) 37 #if defined(OS_ANDROID)
31 std::string socket_name = "content_shell_devtools_remote"; 38 std::string socket_name = "content_shell_devtools_remote";
32 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { 39 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) {
33 socket_name = command_line.GetSwitchValueASCII( 40 socket_name = command_line.GetSwitchValueASCII(
34 switches::kRemoteDebuggingSocketName); 41 switches::kRemoteDebuggingSocketName);
35 } 42 }
(...skipping 10 matching lines...) Expand all
46 if (base::StringToInt(port_str, &temp_port) && 53 if (base::StringToInt(port_str, &temp_port) &&
47 temp_port > 0 && temp_port < 65535) { 54 temp_port > 0 && temp_port < 65535) {
48 port = temp_port; 55 port = temp_port;
49 } else { 56 } else {
50 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; 57 DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
51 } 58 }
52 } 59 }
53 return new net::TCPListenSocketFactory("127.0.0.1", port); 60 return new net::TCPListenSocketFactory("127.0.0.1", port);
54 #endif 61 #endif
55 } 62 }
63
64 RenderViewHost* GetRenderViewHost(const std::string& id) {
65 DevToolsAgentHost* agent_host = DevToolsAgentHost::GetForId(id);
66 return agent_host ? agent_host->GetRenderViewHost() : NULL;
67 }
68
69 WebContents* GetWebContents(const std::string& id) {
70 RenderViewHost* rvh = GetRenderViewHost(id);
71 return rvh ? WebContents::FromRenderViewHost(rvh) : NULL;
72 }
73
56 } // namespace 74 } // namespace
57 75
58 namespace content { 76 namespace content {
59 77
60 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context) 78 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context)
61 : browser_context_(browser_context) { 79 : browser_context_(browser_context) {
62 // Note that Content Shell always used bundled DevTools frontend, 80 // Note that Content Shell always used bundled DevTools frontend,
63 // even on Android, because the shell is used for running layout tests. 81 // even on Android, because the shell is used for running layout tests.
64 devtools_http_handler_ = 82 devtools_http_handler_ =
65 DevToolsHttpHandler::Start(CreateSocketFactory(), std::string(), this); 83 DevToolsHttpHandler::Start(CreateSocketFactory(), std::string(), this);
(...skipping 13 matching lines...) Expand all
79 } 97 }
80 98
81 bool ShellDevToolsDelegate::BundlesFrontendResources() { 99 bool ShellDevToolsDelegate::BundlesFrontendResources() {
82 return true; 100 return true;
83 } 101 }
84 102
85 base::FilePath ShellDevToolsDelegate::GetDebugFrontendDir() { 103 base::FilePath ShellDevToolsDelegate::GetDebugFrontendDir() {
86 return base::FilePath(); 104 return base::FilePath();
87 } 105 }
88 106
89 std::string ShellDevToolsDelegate::GetPageThumbnailData(const GURL& url) { 107 bool ShellDevToolsDelegate::SupportsPageThumbnails() {
108 return false;
109 }
110
111 std::string ShellDevToolsDelegate::GetPageThumbnailData(const std::string& id) {
90 return std::string(); 112 return std::string();
91 } 113 }
92 114
93 RenderViewHost* ShellDevToolsDelegate::CreateNewTarget() { 115 DevToolsHttpHandlerDelegate::Target*
116 ShellDevToolsDelegate::CreateNewTarget() {
94 Shell* shell = Shell::CreateNewWindow(browser_context_, 117 Shell* shell = Shell::CreateNewWindow(browser_context_,
95 GURL(kAboutBlankURL), 118 GURL(kAboutBlankURL),
96 NULL, 119 NULL,
97 MSG_ROUTING_NONE, 120 MSG_ROUTING_NONE,
98 gfx::Size()); 121 gfx::Size());
99 return shell->web_contents()->GetRenderViewHost(); 122 return Target::FromWebContents(shell->web_contents());
100 } 123 }
101 124
102 DevToolsHttpHandlerDelegate::TargetType 125 bool ShellDevToolsDelegate::ActivateTarget(const std::string& id) {
103 ShellDevToolsDelegate::GetTargetType(RenderViewHost*) { 126 WebContents* web_contents = GetWebContents(id);
104 return kTargetTypeTab; 127 if (!web_contents)
128 return false;
129 web_contents->GetDelegate()->ActivateContents(web_contents);
130 return true;
105 } 131 }
106 132
107 std::string ShellDevToolsDelegate::GetViewDescription( 133 bool ShellDevToolsDelegate::CloseTarget(const std::string& id) {
108 content::RenderViewHost*) { 134 RenderViewHost* rvh = GetRenderViewHost(id);
109 return std::string(); 135 if (!rvh)
136 return false;
137 rvh->ClosePage();
138 return true;
139 }
140
141 scoped_refptr<content::DevToolsAgentHost>
142 ShellDevToolsDelegate::GetAgentHost(const std::string& id) {
143 return content::DevToolsAgentHost::GetForId(id);
144 }
145
146 void ShellDevToolsDelegate::RequestTargets(TargetCallback callback) {
147 TargetList targets;
148 std::vector<RenderViewHost*> rvh_list =
149 content::DevToolsAgentHost::GetValidRenderViewHosts();
150 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin();
151 it != rvh_list.end(); ++it) {
152 WebContents* web_contents = WebContents::FromRenderViewHost(*it);
153 if (web_contents)
154 targets.push_back(Target::FromWebContents(web_contents));
155 }
156 callback.Run(targets);
110 } 157 }
111 158
112 scoped_ptr<net::StreamListenSocket> 159 scoped_ptr<net::StreamListenSocket>
113 ShellDevToolsDelegate::CreateSocketForTethering( 160 ShellDevToolsDelegate::CreateSocketForTethering(
114 net::StreamListenSocket::Delegate* delegate, 161 net::StreamListenSocket::Delegate* delegate,
115 std::string* name) { 162 std::string* name) {
116 return scoped_ptr<net::StreamListenSocket>(); 163 return scoped_ptr<net::StreamListenSocket>();
117 } 164 }
118 165
119 } // namespace content 166 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698