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