OLD | NEW |
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 description.SetBoolean("empty", screen_rect.size().IsEmpty()); | 150 description.SetBoolean("empty", screen_rect.size().IsEmpty()); |
151 if (!screen_rect.size().IsEmpty()) { | 151 if (!screen_rect.size().IsEmpty()) { |
152 description.SetInteger("width", screen_rect.width()); | 152 description.SetInteger("width", screen_rect.width()); |
153 description.SetInteger("height", screen_rect.height()); | 153 description.SetInteger("height", screen_rect.height()); |
154 } | 154 } |
155 std::string json; | 155 std::string json; |
156 base::JSONWriter::Write(&description, &json); | 156 base::JSONWriter::Write(&description, &json); |
157 return json; | 157 return json; |
158 } | 158 } |
159 | 159 |
| 160 // Factory for UnixDomainServerSocket. |
| 161 class UnixDomainServerSocketFactory |
| 162 : public content::DevToolsHttpHandler::ServerSocketFactory { |
| 163 public: |
| 164 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
| 165 : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {} |
| 166 |
| 167 private: |
| 168 // content::DevToolsHttpHandler::ServerSocketFactory. |
| 169 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { |
| 170 return scoped_ptr<net::ServerSocket>( |
| 171 new net::UnixDomainServerSocket( |
| 172 base::Bind(&content::CanUserConnectToDevTools), |
| 173 true)); |
| 174 } |
| 175 |
| 176 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); |
| 177 }; |
| 178 |
160 } // namespace | 179 } // namespace |
161 | 180 |
162 namespace android_webview { | 181 namespace android_webview { |
163 | 182 |
164 AwDevToolsServer::AwDevToolsServer() | 183 AwDevToolsServer::AwDevToolsServer() |
165 : protocol_handler_(NULL) { | 184 : protocol_handler_(NULL) { |
166 } | 185 } |
167 | 186 |
168 AwDevToolsServer::~AwDevToolsServer() { | 187 AwDevToolsServer::~AwDevToolsServer() { |
169 Stop(); | 188 Stop(); |
170 } | 189 } |
171 | 190 |
172 void AwDevToolsServer::Start() { | 191 void AwDevToolsServer::Start() { |
173 if (protocol_handler_) | 192 if (protocol_handler_) |
174 return; | 193 return; |
175 | 194 |
| 195 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> factory( |
| 196 new UnixDomainServerSocketFactory( |
| 197 base::StringPrintf(kSocketNameFormat, getpid()))); |
176 protocol_handler_ = content::DevToolsHttpHandler::Start( | 198 protocol_handler_ = content::DevToolsHttpHandler::Start( |
177 new net::deprecated::UnixDomainListenSocketWithAbstractNamespaceFactory( | 199 factory.Pass(), |
178 base::StringPrintf(kSocketNameFormat, getpid()), | |
179 "", | |
180 base::Bind(&content::CanUserConnectToDevTools)), | |
181 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), | 200 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), |
182 new AwDevToolsServerDelegate(), | 201 new AwDevToolsServerDelegate(), |
183 base::FilePath()); | 202 base::FilePath()); |
184 } | 203 } |
185 | 204 |
186 void AwDevToolsServer::Stop() { | 205 void AwDevToolsServer::Stop() { |
187 if (!protocol_handler_) | 206 if (!protocol_handler_) |
188 return; | 207 return; |
189 // Note that the call to Stop() below takes care of |protocol_handler_| | 208 // Note that the call to Stop() below takes care of |protocol_handler_| |
190 // deletion. | 209 // deletion. |
(...skipping 26 matching lines...) Expand all Loading... |
217 AwDevToolsServer* devtools_server = | 236 AwDevToolsServer* devtools_server = |
218 reinterpret_cast<AwDevToolsServer*>(server); | 237 reinterpret_cast<AwDevToolsServer*>(server); |
219 if (enabled) { | 238 if (enabled) { |
220 devtools_server->Start(); | 239 devtools_server->Start(); |
221 } else { | 240 } else { |
222 devtools_server->Stop(); | 241 devtools_server->Stop(); |
223 } | 242 } |
224 } | 243 } |
225 | 244 |
226 } // namespace android_webview | 245 } // namespace android_webview |
OLD | NEW |