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_server_socket_posix.h" | 22 #include "net/socket/unix_domain_listen_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 /* use_abstract_namespace */)); | |
174 } | |
175 | |
176 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); | |
177 }; | |
178 | |
179 } // namespace | 160 } // namespace |
180 | 161 |
181 namespace android_webview { | 162 namespace android_webview { |
182 | 163 |
183 AwDevToolsServer::AwDevToolsServer() | 164 AwDevToolsServer::AwDevToolsServer() |
184 : protocol_handler_(NULL) { | 165 : protocol_handler_(NULL) { |
185 } | 166 } |
186 | 167 |
187 AwDevToolsServer::~AwDevToolsServer() { | 168 AwDevToolsServer::~AwDevToolsServer() { |
188 Stop(); | 169 Stop(); |
189 } | 170 } |
190 | 171 |
191 void AwDevToolsServer::Start() { | 172 void AwDevToolsServer::Start() { |
192 if (protocol_handler_) | 173 if (protocol_handler_) |
193 return; | 174 return; |
194 | 175 |
195 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> factory( | |
196 new UnixDomainServerSocketFactory( | |
197 base::StringPrintf(kSocketNameFormat, getpid()))); | |
198 protocol_handler_ = content::DevToolsHttpHandler::Start( | 176 protocol_handler_ = content::DevToolsHttpHandler::Start( |
199 factory.Pass(), | 177 new net::deprecated::UnixDomainListenSocketWithAbstractNamespaceFactory( |
| 178 base::StringPrintf(kSocketNameFormat, getpid()), |
| 179 "", |
| 180 base::Bind(&content::CanUserConnectToDevTools)), |
200 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), | 181 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), |
201 new AwDevToolsServerDelegate(), | 182 new AwDevToolsServerDelegate(), |
202 base::FilePath()); | 183 base::FilePath()); |
203 } | 184 } |
204 | 185 |
205 void AwDevToolsServer::Stop() { | 186 void AwDevToolsServer::Stop() { |
206 if (!protocol_handler_) | 187 if (!protocol_handler_) |
207 return; | 188 return; |
208 // Note that the call to Stop() below takes care of |protocol_handler_| | 189 // Note that the call to Stop() below takes care of |protocol_handler_| |
209 // deletion. | 190 // deletion. |
(...skipping 26 matching lines...) Expand all Loading... |
236 AwDevToolsServer* devtools_server = | 217 AwDevToolsServer* devtools_server = |
237 reinterpret_cast<AwDevToolsServer*>(server); | 218 reinterpret_cast<AwDevToolsServer*>(server); |
238 if (enabled) { | 219 if (enabled) { |
239 devtools_server->Start(); | 220 devtools_server->Start(); |
240 } else { | 221 } else { |
241 devtools_server->Stop(); | 222 devtools_server->Stop(); |
242 } | 223 } |
243 } | 224 } |
244 | 225 |
245 } // namespace android_webview | 226 } // namespace android_webview |
OLD | NEW |