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

Side by Side Diff: content/shell/browser/shell_devtools_manager_delegate.cc

Issue 2295623002: DevTools: simplify http handler delegate as it is moving into content. (Closed)
Patch Set: lcean Created 4 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 unified diff | Download patch
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_manager_delegate.h" 5 #include "content/shell/browser/shell_devtools_manager_delegate.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "components/devtools_http_handler/devtools_http_handler.h" 20 #include "components/devtools_http_handler/devtools_http_handler.h"
21 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/devtools_agent_host.h" 22 #include "content/public/browser/devtools_agent_host.h"
23 #include "content/public/browser/devtools_frontend_host.h" 23 #include "content/public/browser/devtools_frontend_host.h"
24 #include "content/public/browser/devtools_socket_factory.h"
24 #include "content/public/browser/favicon_status.h" 25 #include "content/public/browser/favicon_status.h"
25 #include "content/public/browser/navigation_entry.h" 26 #include "content/public/browser/navigation_entry.h"
26 #include "content/public/browser/render_view_host.h" 27 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
28 #include "content/public/common/content_switches.h" 29 #include "content/public/common/content_switches.h"
29 #include "content/public/common/url_constants.h" 30 #include "content/public/common/url_constants.h"
30 #include "content/public/common/user_agent.h" 31 #include "content/public/common/user_agent.h"
31 #include "content/shell/browser/shell.h" 32 #include "content/shell/browser/shell.h"
32 #include "content/shell/common/shell_content_client.h" 33 #include "content/shell/common/shell_content_client.h"
33 #include "grit/shell_resources.h" 34 #include "grit/shell_resources.h"
(...skipping 13 matching lines...) Expand all
47 namespace { 48 namespace {
48 49
49 #if defined(OS_ANDROID) 50 #if defined(OS_ANDROID)
50 const char kFrontEndURL[] = 51 const char kFrontEndURL[] =
51 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html"; 52 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html";
52 #endif 53 #endif
53 54
54 const int kBackLog = 10; 55 const int kBackLog = 10;
55 56
56 #if defined(OS_ANDROID) 57 #if defined(OS_ANDROID)
57 class UnixDomainServerSocketFactory 58 class UnixDomainServerSocketFactory : public content::DevToolsSocketFactory {
58 : public DevToolsHttpHandler::ServerSocketFactory {
59 public: 59 public:
60 explicit UnixDomainServerSocketFactory(const std::string& socket_name) 60 explicit UnixDomainServerSocketFactory(const std::string& socket_name)
61 : socket_name_(socket_name) {} 61 : socket_name_(socket_name) {}
62 62
63 private: 63 private:
64 // DevToolsHttpHandler::ServerSocketFactory. 64 // content::DevToolsSocketFactory.
65 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { 65 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
66 std::unique_ptr<net::UnixDomainServerSocket> socket( 66 std::unique_ptr<net::UnixDomainServerSocket> socket(
67 new net::UnixDomainServerSocket(base::Bind(&CanUserConnectToDevTools), 67 new net::UnixDomainServerSocket(base::Bind(&CanUserConnectToDevTools),
68 true /* use_abstract_namespace */)); 68 true /* use_abstract_namespace */));
69 if (socket->BindAndListen(socket_name_, kBackLog) != net::OK) 69 if (socket->BindAndListen(socket_name_, kBackLog) != net::OK)
70 return std::unique_ptr<net::ServerSocket>(); 70 return std::unique_ptr<net::ServerSocket>();
71 71
72 return std::move(socket); 72 return std::move(socket);
73 } 73 }
74 74
75 std::unique_ptr<net::ServerSocket> CreateForTethering(
76 std::string* out_name) override {
77 return nullptr;
78 }
79
75 std::string socket_name_; 80 std::string socket_name_;
76 81
77 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); 82 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory);
78 }; 83 };
79 #else 84 #else
80 class TCPServerSocketFactory 85 class TCPServerSocketFactory : public content::DevToolsSocketFactory {
81 : public DevToolsHttpHandler::ServerSocketFactory {
82 public: 86 public:
83 TCPServerSocketFactory(const std::string& address, uint16_t port) 87 TCPServerSocketFactory(const std::string& address, uint16_t port)
84 : address_(address), port_(port) {} 88 : address_(address), port_(port) {}
85 89
86 private: 90 private:
87 // DevToolsHttpHandler::ServerSocketFactory. 91 // content::DevToolsSocketFactory.
88 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { 92 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
89 std::unique_ptr<net::ServerSocket> socket( 93 std::unique_ptr<net::ServerSocket> socket(
90 new net::TCPServerSocket(nullptr, net::NetLog::Source())); 94 new net::TCPServerSocket(nullptr, net::NetLog::Source()));
91 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK) 95 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK)
92 return std::unique_ptr<net::ServerSocket>(); 96 return std::unique_ptr<net::ServerSocket>();
93 97
94 return socket; 98 return socket;
95 } 99 }
96 100
101 std::unique_ptr<net::ServerSocket> CreateForTethering(
102 std::string* out_name) override {
103 return nullptr;
104 }
105
97 std::string address_; 106 std::string address_;
98 uint16_t port_; 107 uint16_t port_;
99 108
100 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); 109 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory);
101 }; 110 };
102 #endif 111 #endif
103 112
104 std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory> 113 std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
105 CreateSocketFactory() {
106 const base::CommandLine& command_line = 114 const base::CommandLine& command_line =
107 *base::CommandLine::ForCurrentProcess(); 115 *base::CommandLine::ForCurrentProcess();
108 #if defined(OS_ANDROID) 116 #if defined(OS_ANDROID)
109 std::string socket_name = "content_shell_devtools_remote"; 117 std::string socket_name = "content_shell_devtools_remote";
110 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { 118 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) {
111 socket_name = command_line.GetSwitchValueASCII( 119 socket_name = command_line.GetSwitchValueASCII(
112 switches::kRemoteDebuggingSocketName); 120 switches::kRemoteDebuggingSocketName);
113 } 121 }
114 return std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory>( 122 return std::unique_ptr<content::DevToolsSocketFactory>(
115 new UnixDomainServerSocketFactory(socket_name)); 123 new UnixDomainServerSocketFactory(socket_name));
116 #else 124 #else
117 // See if the user specified a port on the command line (useful for 125 // See if the user specified a port on the command line (useful for
118 // automation). If not, use an ephemeral port by specifying 0. 126 // automation). If not, use an ephemeral port by specifying 0.
119 uint16_t port = 0; 127 uint16_t port = 0;
120 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { 128 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
121 int temp_port; 129 int temp_port;
122 std::string port_str = 130 std::string port_str =
123 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); 131 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
124 if (base::StringToInt(port_str, &temp_port) && 132 if (base::StringToInt(port_str, &temp_port) &&
125 temp_port >= 0 && temp_port < 65535) { 133 temp_port >= 0 && temp_port < 65535) {
126 port = static_cast<uint16_t>(temp_port); 134 port = static_cast<uint16_t>(temp_port);
127 } else { 135 } else {
128 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; 136 DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
129 } 137 }
130 } 138 }
131 return std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory>( 139 return std::unique_ptr<content::DevToolsSocketFactory>(
132 new TCPServerSocketFactory("127.0.0.1", port)); 140 new TCPServerSocketFactory("127.0.0.1", port));
133 #endif 141 #endif
134 } 142 }
135 143
136 // ShellDevToolsDelegate ---------------------------------------------------- 144 // ShellDevToolsDelegate ----------------------------------------------------
137 145
138 class ShellDevToolsDelegate : 146 class ShellDevToolsDelegate :
139 public devtools_http_handler::DevToolsHttpHandlerDelegate { 147 public devtools_http_handler::DevToolsHttpHandlerDelegate {
140 public: 148 public:
141 explicit ShellDevToolsDelegate(); 149 explicit ShellDevToolsDelegate();
142 ~ShellDevToolsDelegate() override; 150 ~ShellDevToolsDelegate() override;
143 151
144 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation. 152 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation.
145 std::string GetDiscoveryPageHTML() override; 153 std::string GetDiscoveryPageHTML() override;
146 std::string GetFrontendResource(const std::string& path) override; 154 std::string GetFrontendResource(const std::string& path) override;
147 std::string GetPageThumbnailData(const GURL& url) override;
148 DevToolsExternalAgentProxyDelegate*
149 HandleWebSocketConnection(const std::string& path) override;
150 155
151 private: 156 private:
152 DISALLOW_COPY_AND_ASSIGN(ShellDevToolsDelegate); 157 DISALLOW_COPY_AND_ASSIGN(ShellDevToolsDelegate);
153 }; 158 };
154 159
155 ShellDevToolsDelegate::ShellDevToolsDelegate() { 160 ShellDevToolsDelegate::ShellDevToolsDelegate() {
156 } 161 }
157 162
158 ShellDevToolsDelegate::~ShellDevToolsDelegate() { 163 ShellDevToolsDelegate::~ShellDevToolsDelegate() {
159 } 164 }
160 165
161 std::string ShellDevToolsDelegate::GetDiscoveryPageHTML() { 166 std::string ShellDevToolsDelegate::GetDiscoveryPageHTML() {
162 #if defined(OS_ANDROID) 167 #if defined(OS_ANDROID)
163 return std::string(); 168 return std::string();
164 #else 169 #else
165 return ResourceBundle::GetSharedInstance().GetRawDataResource( 170 return ResourceBundle::GetSharedInstance().GetRawDataResource(
166 IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); 171 IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string();
167 #endif 172 #endif
168 } 173 }
169 174
170 std::string ShellDevToolsDelegate::GetFrontendResource( 175 std::string ShellDevToolsDelegate::GetFrontendResource(
171 const std::string& path) { 176 const std::string& path) {
172 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); 177 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string();
173 } 178 }
174 179
175 std::string ShellDevToolsDelegate::GetPageThumbnailData(const GURL& url) {
176 return std::string();
177 }
178
179 DevToolsExternalAgentProxyDelegate*
180 ShellDevToolsDelegate::HandleWebSocketConnection(const std::string& path) {
181 return nullptr;
182 }
183
184 } // namespace 180 } // namespace
185 181
186 // ShellDevToolsManagerDelegate ---------------------------------------------- 182 // ShellDevToolsManagerDelegate ----------------------------------------------
187 183
188 // static 184 // static
189 DevToolsHttpHandler* 185 DevToolsHttpHandler*
190 ShellDevToolsManagerDelegate::CreateHttpHandler( 186 ShellDevToolsManagerDelegate::CreateHttpHandler(
191 BrowserContext* browser_context) { 187 BrowserContext* browser_context) {
192 std::string frontend_url; 188 std::string frontend_url;
193 #if defined(OS_ANDROID) 189 #if defined(OS_ANDROID)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 scoped_refptr<DevToolsAgentHost> 226 scoped_refptr<DevToolsAgentHost>
231 ShellDevToolsManagerDelegate::CreateNewTarget(const GURL& url) { 227 ShellDevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
232 Shell* shell = Shell::CreateNewWindow(browser_context_, 228 Shell* shell = Shell::CreateNewWindow(browser_context_,
233 url, 229 url,
234 nullptr, 230 nullptr,
235 gfx::Size()); 231 gfx::Size());
236 return DevToolsAgentHost::GetOrCreateFor(shell->web_contents()); 232 return DevToolsAgentHost::GetOrCreateFor(shell->web_contents());
237 } 233 }
238 234
239 } // namespace content 235 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/browser/shell_devtools_frontend.cc ('k') | headless/lib/browser/headless_devtools.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698