| 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/browser/aw_dev_tools_manager_delegate.h" | |
| 8 #include "android_webview/common/aw_content_client.h" | 7 #include "android_webview/common/aw_content_client.h" |
| 9 #include "android_webview/native/aw_contents.h" | 8 #include "android_webview/native/aw_contents.h" |
| 10 #include "base/bind.h" | 9 #include "base/bind.h" |
| 11 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 12 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 13 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/values.h" | 14 #include "base/values.h" |
| 16 #include "components/devtools_http_handler/devtools_http_handler.h" | 15 #include "components/devtools_http_handler/devtools_http_handler.h" |
| 17 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" | 16 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" |
| 18 #include "content/public/browser/android/devtools_auth.h" | 17 #include "content/public/browser/android/devtools_auth.h" |
| 19 #include "content/public/browser/devtools_agent_host.h" | 18 #include "content/public/browser/devtools_agent_host.h" |
| 20 #include "content/public/browser/devtools_target.h" | |
| 21 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/user_agent.h" | 20 #include "content/public/common/user_agent.h" |
| 23 #include "jni/AwDevToolsServer_jni.h" | 21 #include "jni/AwDevToolsServer_jni.h" |
| 24 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 25 #include "net/socket/unix_domain_server_socket_posix.h" | 23 #include "net/socket/unix_domain_server_socket_posix.h" |
| 26 | 24 |
| 27 using content::DevToolsAgentHost; | 25 using content::DevToolsAgentHost; |
| 28 using content::RenderViewHost; | 26 using content::RenderViewHost; |
| 29 using content::WebContents; | 27 using content::WebContents; |
| 30 using devtools_http_handler::DevToolsHttpHandler; | 28 using devtools_http_handler::DevToolsHttpHandler; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 public devtools_http_handler::DevToolsHttpHandlerDelegate { | 42 public devtools_http_handler::DevToolsHttpHandlerDelegate { |
| 45 public: | 43 public: |
| 46 AwDevToolsServerDelegate() { | 44 AwDevToolsServerDelegate() { |
| 47 } | 45 } |
| 48 | 46 |
| 49 ~AwDevToolsServerDelegate() override {} | 47 ~AwDevToolsServerDelegate() override {} |
| 50 | 48 |
| 51 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation. | 49 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation. |
| 52 std::string GetDiscoveryPageHTML() override; | 50 std::string GetDiscoveryPageHTML() override; |
| 53 std::string GetFrontendResource(const std::string& path) override; | 51 std::string GetFrontendResource(const std::string& path) override; |
| 52 std::string GetPageThumbnailData(const GURL&) override; |
| 54 | 53 |
| 55 private: | 54 private: |
| 56 | 55 |
| 57 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); | 56 DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 | 59 |
| 61 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { | 60 std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { |
| 62 const char html[] = | 61 const char html[] = |
| 63 "<html>" | 62 "<html>" |
| 64 "<head><title>WebView remote debugging</title></head>" | 63 "<head><title>WebView remote debugging</title></head>" |
| 65 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" | 64 "<body>Please use <a href=\'chrome://inspect\'>chrome://inspect</a>" |
| 66 "</body>" | 65 "</body>" |
| 67 "</html>"; | 66 "</html>"; |
| 68 return html; | 67 return html; |
| 69 } | 68 } |
| 70 | 69 |
| 71 std::string AwDevToolsServerDelegate::GetFrontendResource( | 70 std::string AwDevToolsServerDelegate::GetFrontendResource( |
| 72 const std::string& path) { | 71 const std::string& path) { |
| 73 return std::string(); | 72 return std::string(); |
| 74 } | 73 } |
| 75 | 74 |
| 75 std::string AwDevToolsServerDelegate::GetPageThumbnailData(const GURL&) { |
| 76 return std::string(); |
| 77 } |
| 78 |
| 76 // Factory for UnixDomainServerSocket. | 79 // Factory for UnixDomainServerSocket. |
| 77 class UnixDomainServerSocketFactory | 80 class UnixDomainServerSocketFactory |
| 78 : public DevToolsHttpHandler::ServerSocketFactory { | 81 : public DevToolsHttpHandler::ServerSocketFactory { |
| 79 public: | 82 public: |
| 80 explicit UnixDomainServerSocketFactory(const std::string& socket_name) | 83 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
| 81 : socket_name_(socket_name), | 84 : socket_name_(socket_name), |
| 82 last_tethering_socket_(0) { | 85 last_tethering_socket_(0) { |
| 83 } | 86 } |
| 84 | 87 |
| 85 private: | 88 private: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 Stop(); | 127 Stop(); |
| 125 } | 128 } |
| 126 | 129 |
| 127 void AwDevToolsServer::Start() { | 130 void AwDevToolsServer::Start() { |
| 128 if (devtools_http_handler_) | 131 if (devtools_http_handler_) |
| 129 return; | 132 return; |
| 130 | 133 |
| 131 scoped_ptr<DevToolsHttpHandler::ServerSocketFactory> factory( | 134 scoped_ptr<DevToolsHttpHandler::ServerSocketFactory> factory( |
| 132 new UnixDomainServerSocketFactory( | 135 new UnixDomainServerSocketFactory( |
| 133 base::StringPrintf(kSocketNameFormat, getpid()))); | 136 base::StringPrintf(kSocketNameFormat, getpid()))); |
| 134 manager_delegate_.reset(new AwDevToolsManagerDelegate()); | |
| 135 devtools_http_handler_.reset(new DevToolsHttpHandler( | 137 devtools_http_handler_.reset(new DevToolsHttpHandler( |
| 136 factory.Pass(), | 138 factory.Pass(), |
| 137 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), | 139 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), |
| 138 new AwDevToolsServerDelegate(), | 140 new AwDevToolsServerDelegate(), |
| 139 manager_delegate_.get(), | |
| 140 base::FilePath(), | 141 base::FilePath(), |
| 141 base::FilePath(), | 142 base::FilePath(), |
| 142 GetProduct(), | 143 GetProduct(), |
| 143 GetUserAgent())); | 144 GetUserAgent())); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void AwDevToolsServer::Stop() { | 147 void AwDevToolsServer::Stop() { |
| 147 devtools_http_handler_.reset(); | 148 devtools_http_handler_.reset(); |
| 148 manager_delegate_.reset(); | |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool AwDevToolsServer::IsStarted() const { | 151 bool AwDevToolsServer::IsStarted() const { |
| 152 return devtools_http_handler_; | 152 return devtools_http_handler_; |
| 153 } | 153 } |
| 154 | 154 |
| 155 bool RegisterAwDevToolsServer(JNIEnv* env) { | 155 bool RegisterAwDevToolsServer(JNIEnv* env) { |
| 156 return RegisterNativesImpl(env); | 156 return RegisterNativesImpl(env); |
| 157 } | 157 } |
| 158 | 158 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 173 AwDevToolsServer* devtools_server = | 173 AwDevToolsServer* devtools_server = |
| 174 reinterpret_cast<AwDevToolsServer*>(server); | 174 reinterpret_cast<AwDevToolsServer*>(server); |
| 175 if (enabled) { | 175 if (enabled) { |
| 176 devtools_server->Start(); | 176 devtools_server->Start(); |
| 177 } else { | 177 } else { |
| 178 devtools_server->Stop(); | 178 devtools_server->Stop(); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 } // namespace android_webview | 182 } // namespace android_webview |
| OLD | NEW |