| 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/base/net_errors.h" |
| 22 #include "net/socket/unix_domain_server_socket_posix.h" | 23 #include "net/socket/unix_domain_server_socket_posix.h" |
| 23 | 24 |
| 24 using content::DevToolsAgentHost; | 25 using content::DevToolsAgentHost; |
| 25 using content::RenderViewHost; | 26 using content::RenderViewHost; |
| 26 using content::WebContents; | 27 using content::WebContents; |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 const char kFrontEndURL[] = | 31 const char kFrontEndURL[] = |
| 31 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; | 32 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; |
| 32 const char kSocketNameFormat[] = "webview_devtools_remote_%d"; | 33 const char kSocketNameFormat[] = "webview_devtools_remote_%d"; |
| 34 const char kTetheringSocketName[] = "webview_devtools_tethering_%d_%d"; |
| 35 |
| 36 const int kBackLog = 10; |
| 33 | 37 |
| 34 // Delegate implementation for the devtools http handler for WebView. A new | 38 // Delegate implementation for the devtools http handler for WebView. A new |
| 35 // instance of this gets created each time web debugging is enabled. | 39 // instance of this gets created each time web debugging is enabled. |
| 36 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { | 40 class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
| 37 public: | 41 public: |
| 38 AwDevToolsServerDelegate() {} | 42 AwDevToolsServerDelegate() : last_tethering_socket_(0) { |
| 43 } |
| 44 |
| 39 virtual ~AwDevToolsServerDelegate() {} | 45 virtual ~AwDevToolsServerDelegate() {} |
| 40 | 46 |
| 41 // DevToolsHttpProtocolHandler::Delegate overrides. | 47 // DevToolsHttpProtocolHandler::Delegate overrides. |
| 42 std::string GetDiscoveryPageHTML() override; | 48 std::string GetDiscoveryPageHTML() override; |
| 43 | 49 |
| 44 bool BundlesFrontendResources() override { | 50 bool BundlesFrontendResources() override { |
| 45 return false; | 51 return false; |
| 46 } | 52 } |
| 47 | 53 |
| 48 base::FilePath GetDebugFrontendDir() override { | 54 base::FilePath GetDebugFrontendDir() override { |
| 49 return base::FilePath(); | 55 return base::FilePath(); |
| 50 } | 56 } |
| 51 | 57 |
| 52 scoped_ptr<net::ServerSocket> | 58 scoped_ptr<net::ServerSocket> |
| 53 CreateSocketForTethering(std::string* name) override { | 59 CreateSocketForTethering(std::string* name) override { |
| 54 return scoped_ptr<net::ServerSocket>(); | 60 *name = base::StringPrintf( |
| 61 kTetheringSocketName, getpid(), ++last_tethering_socket_); |
| 62 scoped_ptr<net::UnixDomainServerSocket> socket( |
| 63 new net::UnixDomainServerSocket( |
| 64 base::Bind(&content::CanUserConnectToDevTools), true)); |
| 65 if (socket->ListenWithAddressAndPort(*name, 0, kBackLog) != net::OK) |
| 66 return scoped_ptr<net::ServerSocket>(); |
| 67 |
| 68 return socket.Pass(); |
| 55 } | 69 } |
| 56 | 70 |
| 57 private: | 71 private: |
| 72 int last_tethering_socket_; |
| 73 |
| 58 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); | 74 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); |
| 59 }; | 75 }; |
| 60 | 76 |
| 61 | 77 |
| 62 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { | 78 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { |
| 63 const char html[] = | 79 const char html[] = |
| 64 "<html>" | 80 "<html>" |
| 65 "<head><title>WebView remote debugging</title></head>" | 81 "<head><title>WebView remote debugging</title></head>" |
| 66 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" | 82 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" |
| 67 "</body>" | 83 "</body>" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 AwDevToolsServer* devtools_server = | 164 AwDevToolsServer* devtools_server = |
| 149 reinterpret_cast<AwDevToolsServer*>(server); | 165 reinterpret_cast<AwDevToolsServer*>(server); |
| 150 if (enabled) { | 166 if (enabled) { |
| 151 devtools_server->Start(); | 167 devtools_server->Start(); |
| 152 } else { | 168 } else { |
| 153 devtools_server->Stop(); | 169 devtools_server->Stop(); |
| 154 } | 170 } |
| 155 } | 171 } |
| 156 | 172 |
| 157 } // namespace android_webview | 173 } // namespace android_webview |
| OLD | NEW |