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

Side by Side Diff: android_webview/native/aw_dev_tools_server.cc

Issue 487013003: Revert "Revert of Replace StreamListenSocket with StreamSocket in HttpServer. (patchset #29 of http… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 6 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/android/dev_tools_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "android_webview/native/aw_dev_tools_server.h" 5 #include "android_webview/native/aw_dev_tools_server.h"
6 6
7 #include "android_webview/native/aw_contents.h" 7 #include "android_webview/native/aw_contents.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "content/public/browser/android/devtools_auth.h" 14 #include "content/public/browser/android/devtools_auth.h"
15 #include "content/public/browser/devtools_agent_host.h" 15 #include "content/public/browser/devtools_agent_host.h"
16 #include "content/public/browser/devtools_http_handler.h" 16 #include "content/public/browser/devtools_http_handler.h"
17 #include "content/public/browser/devtools_http_handler_delegate.h" 17 #include "content/public/browser/devtools_http_handler_delegate.h"
18 #include "content/public/browser/devtools_target.h" 18 #include "content/public/browser/devtools_target.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/user_agent.h" 20 #include "content/public/common/user_agent.h"
21 #include "jni/AwDevToolsServer_jni.h" 21 #include "jni/AwDevToolsServer_jni.h"
22 #include "net/socket/unix_domain_listen_socket_posix.h" 22 #include "net/socket/unix_domain_server_socket_posix.h"
23 23
24 using content::DevToolsAgentHost; 24 using content::DevToolsAgentHost;
25 using content::RenderViewHost; 25 using content::RenderViewHost;
26 using content::WebContents; 26 using content::WebContents;
27 27
28 namespace { 28 namespace {
29 29
30 const char kFrontEndURL[] = 30 const char kFrontEndURL[] =
31 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; 31 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html";
32 const char kSocketNameFormat[] = "webview_devtools_remote_%d"; 32 const char kSocketNameFormat[] = "webview_devtools_remote_%d";
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 description.SetBoolean("empty", screen_rect.size().IsEmpty()); 158 description.SetBoolean("empty", screen_rect.size().IsEmpty());
159 if (!screen_rect.size().IsEmpty()) { 159 if (!screen_rect.size().IsEmpty()) {
160 description.SetInteger("width", screen_rect.width()); 160 description.SetInteger("width", screen_rect.width());
161 description.SetInteger("height", screen_rect.height()); 161 description.SetInteger("height", screen_rect.height());
162 } 162 }
163 std::string json; 163 std::string json;
164 base::JSONWriter::Write(&description, &json); 164 base::JSONWriter::Write(&description, &json);
165 return json; 165 return json;
166 } 166 }
167 167
168 // Factory for UnixDomainServerSocket.
169 class UnixDomainServerSocketFactory
170 : public content::DevToolsHttpHandler::ServerSocketFactory {
171 public:
172 explicit UnixDomainServerSocketFactory(const std::string& socket_name)
173 : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {}
174
175 private:
176 // content::DevToolsHttpHandler::ServerSocketFactory.
177 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE {
178 return scoped_ptr<net::ServerSocket>(
179 new net::UnixDomainServerSocket(
180 base::Bind(&content::CanUserConnectToDevTools),
181 true /* use_abstract_namespace */));
182 }
183
184 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory);
185 };
186
168 } // namespace 187 } // namespace
169 188
170 namespace android_webview { 189 namespace android_webview {
171 190
172 AwDevToolsServer::AwDevToolsServer() 191 AwDevToolsServer::AwDevToolsServer()
173 : protocol_handler_(NULL) { 192 : protocol_handler_(NULL) {
174 } 193 }
175 194
176 AwDevToolsServer::~AwDevToolsServer() { 195 AwDevToolsServer::~AwDevToolsServer() {
177 Stop(); 196 Stop();
178 } 197 }
179 198
180 void AwDevToolsServer::Start() { 199 void AwDevToolsServer::Start() {
181 if (protocol_handler_) 200 if (protocol_handler_)
182 return; 201 return;
183 202
203 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> factory(
204 new UnixDomainServerSocketFactory(
205 base::StringPrintf(kSocketNameFormat, getpid())));
184 protocol_handler_ = content::DevToolsHttpHandler::Start( 206 protocol_handler_ = content::DevToolsHttpHandler::Start(
185 new net::deprecated::UnixDomainListenSocketWithAbstractNamespaceFactory( 207 factory.Pass(),
186 base::StringPrintf(kSocketNameFormat, getpid()),
187 "",
188 base::Bind(&content::CanUserConnectToDevTools)),
189 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), 208 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()),
190 new AwDevToolsServerDelegate(), 209 new AwDevToolsServerDelegate(),
191 base::FilePath()); 210 base::FilePath());
192 } 211 }
193 212
194 void AwDevToolsServer::Stop() { 213 void AwDevToolsServer::Stop() {
195 if (!protocol_handler_) 214 if (!protocol_handler_)
196 return; 215 return;
197 // Note that the call to Stop() below takes care of |protocol_handler_| 216 // Note that the call to Stop() below takes care of |protocol_handler_|
198 // deletion. 217 // deletion.
(...skipping 26 matching lines...) Expand all
225 AwDevToolsServer* devtools_server = 244 AwDevToolsServer* devtools_server =
226 reinterpret_cast<AwDevToolsServer*>(server); 245 reinterpret_cast<AwDevToolsServer*>(server);
227 if (enabled) { 246 if (enabled) {
228 devtools_server->Start(); 247 devtools_server->Start();
229 } else { 248 } else {
230 devtools_server->Stop(); 249 devtools_server->Stop();
231 } 250 }
232 } 251 }
233 252
234 } // namespace android_webview 253 } // namespace android_webview
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/dev_tools_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698