| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/android/dev_tools_server.h" | 5 #include "chrome/browser/android/dev_tools_server.h" |
| 6 | 6 |
| 7 #include <pwd.h> | 7 #include <pwd.h> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/android/context_utils.h" | 11 #include "base/android/context_utils.h" |
| 12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "chrome/browser/android/tab_android.h" | 23 #include "chrome/browser/android/tab_android.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/history/top_sites_factory.h" | |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 26 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 28 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 27 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 29 #include "chrome/common/chrome_content_client.h" | 28 #include "chrome/common/chrome_content_client.h" |
| 30 #include "chrome/grit/browser_resources.h" | 29 #include "chrome/grit/browser_resources.h" |
| 31 #include "components/devtools_http_handler/devtools_http_handler.h" | 30 #include "components/devtools_http_handler/devtools_http_handler.h" |
| 32 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" | 31 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" |
| 33 #include "components/history/core/browser/top_sites.h" | |
| 34 #include "components/version_info/version_info.h" | 32 #include "components/version_info/version_info.h" |
| 35 #include "content/public/browser/android/devtools_auth.h" | 33 #include "content/public/browser/android/devtools_auth.h" |
| 36 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/devtools_agent_host.h" | 35 #include "content/public/browser/devtools_agent_host.h" |
| 36 #include "content/public/browser/devtools_socket_factory.h" |
| 38 #include "content/public/browser/favicon_status.h" | 37 #include "content/public/browser/favicon_status.h" |
| 39 #include "content/public/browser/navigation_entry.h" | 38 #include "content/public/browser/navigation_entry.h" |
| 40 #include "content/public/browser/render_view_host.h" | 39 #include "content/public/browser/render_view_host.h" |
| 41 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 42 #include "content/public/browser/web_contents_delegate.h" | 41 #include "content/public/browser/web_contents_delegate.h" |
| 43 #include "content/public/common/content_switches.h" | 42 #include "content/public/common/content_switches.h" |
| 44 #include "content/public/common/url_constants.h" | 43 #include "content/public/common/url_constants.h" |
| 45 #include "content/public/common/user_agent.h" | 44 #include "content/public/common/user_agent.h" |
| 46 #include "jni/DevToolsServer_jni.h" | 45 #include "jni/DevToolsServer_jni.h" |
| 47 #include "net/base/net_errors.h" | 46 #include "net/base/net_errors.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 84 |
| 86 // Delegate implementation for the devtools http handler on android. A new | 85 // Delegate implementation for the devtools http handler on android. A new |
| 87 // instance of this gets created each time devtools is enabled. | 86 // instance of this gets created each time devtools is enabled. |
| 88 class DevToolsServerDelegate : | 87 class DevToolsServerDelegate : |
| 89 public devtools_http_handler::DevToolsHttpHandlerDelegate { | 88 public devtools_http_handler::DevToolsHttpHandlerDelegate { |
| 90 public: | 89 public: |
| 91 DevToolsServerDelegate() { | 90 DevToolsServerDelegate() { |
| 92 } | 91 } |
| 93 | 92 |
| 94 std::string GetDiscoveryPageHTML() override { | 93 std::string GetDiscoveryPageHTML() override { |
| 95 // TopSites updates itself after a delay. Ask TopSites to update itself | |
| 96 // when we're about to show the remote debugging landing page. | |
| 97 content::BrowserThread::PostTask( | |
| 98 content::BrowserThread::UI, | |
| 99 FROM_HERE, | |
| 100 base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails)); | |
| 101 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 94 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 102 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); | 95 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); |
| 103 } | 96 } |
| 104 | 97 |
| 105 std::string GetFrontendResource(const std::string& path) override { | 98 std::string GetFrontendResource(const std::string& path) override { |
| 106 return std::string(); | 99 return std::string(); |
| 107 } | 100 } |
| 108 | 101 |
| 109 std::string GetPageThumbnailData(const GURL& url) override { | |
| 110 Profile* profile = | |
| 111 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); | |
| 112 scoped_refptr<history::TopSites> top_sites = | |
| 113 TopSitesFactory::GetForProfile(profile); | |
| 114 if (top_sites) { | |
| 115 scoped_refptr<base::RefCountedMemory> data; | |
| 116 if (top_sites->GetPageThumbnail(url, false, &data)) | |
| 117 return std::string(data->front_as<char>(), data->size()); | |
| 118 } | |
| 119 return std::string(); | |
| 120 } | |
| 121 | |
| 122 content::DevToolsExternalAgentProxyDelegate* | |
| 123 HandleWebSocketConnection(const std::string& path) override { | |
| 124 return nullptr; | |
| 125 } | |
| 126 | |
| 127 private: | 102 private: |
| 128 static void PopulatePageThumbnails() { | |
| 129 Profile* profile = | |
| 130 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); | |
| 131 scoped_refptr<history::TopSites> top_sites = | |
| 132 TopSitesFactory::GetForProfile(profile); | |
| 133 if (top_sites) | |
| 134 top_sites->SyncWithHistory(); | |
| 135 } | |
| 136 | 103 |
| 137 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate); | 104 DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate); |
| 138 }; | 105 }; |
| 139 | 106 |
| 140 // Factory for UnixDomainServerSocket. It tries a fallback socket when | 107 // Factory for UnixDomainServerSocket. It tries a fallback socket when |
| 141 // original socket doesn't work. | 108 // original socket doesn't work. |
| 142 class UnixDomainServerSocketFactory | 109 class UnixDomainServerSocketFactory : public content::DevToolsSocketFactory { |
| 143 : public DevToolsHttpHandler::ServerSocketFactory { | |
| 144 public: | 110 public: |
| 145 UnixDomainServerSocketFactory( | 111 UnixDomainServerSocketFactory( |
| 146 const std::string& socket_name, | 112 const std::string& socket_name, |
| 147 const net::UnixDomainServerSocket::AuthCallback& auth_callback) | 113 const net::UnixDomainServerSocket::AuthCallback& auth_callback) |
| 148 : socket_name_(socket_name), | 114 : socket_name_(socket_name), |
| 149 last_tethering_socket_(0), | 115 last_tethering_socket_(0), |
| 150 auth_callback_(auth_callback) { | 116 auth_callback_(auth_callback) { |
| 151 } | 117 } |
| 152 | 118 |
| 153 private: | 119 private: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 172 } |
| 207 | 173 |
| 208 void DevToolsServer::Start(bool allow_debug_permission) { | 174 void DevToolsServer::Start(bool allow_debug_permission) { |
| 209 if (devtools_http_handler_) | 175 if (devtools_http_handler_) |
| 210 return; | 176 return; |
| 211 | 177 |
| 212 net::UnixDomainServerSocket::AuthCallback auth_callback = | 178 net::UnixDomainServerSocket::AuthCallback auth_callback = |
| 213 allow_debug_permission ? | 179 allow_debug_permission ? |
| 214 base::Bind(&AuthorizeSocketAccessWithDebugPermission) : | 180 base::Bind(&AuthorizeSocketAccessWithDebugPermission) : |
| 215 base::Bind(&content::CanUserConnectToDevTools); | 181 base::Bind(&content::CanUserConnectToDevTools); |
| 216 std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory> factory( | 182 std::unique_ptr<content::DevToolsSocketFactory> factory( |
| 217 new UnixDomainServerSocketFactory(socket_name_, auth_callback)); | 183 new UnixDomainServerSocketFactory(socket_name_, auth_callback)); |
| 218 devtools_http_handler_.reset(new DevToolsHttpHandler( | 184 devtools_http_handler_.reset(new DevToolsHttpHandler( |
| 219 std::move(factory), | 185 std::move(factory), |
| 220 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), | 186 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), |
| 221 new DevToolsServerDelegate(), base::FilePath(), base::FilePath(), | 187 new DevToolsServerDelegate(), base::FilePath(), base::FilePath(), |
| 222 version_info::GetProductNameAndVersionForUserAgent(), ::GetUserAgent())); | 188 version_info::GetProductNameAndVersionForUserAgent(), ::GetUserAgent())); |
| 223 } | 189 } |
| 224 | 190 |
| 225 void DevToolsServer::Stop() { | 191 void DevToolsServer::Stop() { |
| 226 devtools_http_handler_.reset(); | 192 devtools_http_handler_.reset(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 jlong server, | 226 jlong server, |
| 261 jboolean enabled, | 227 jboolean enabled, |
| 262 jboolean allow_debug_permission) { | 228 jboolean allow_debug_permission) { |
| 263 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); | 229 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); |
| 264 if (enabled) { | 230 if (enabled) { |
| 265 devtools_server->Start(allow_debug_permission); | 231 devtools_server->Start(allow_debug_permission); |
| 266 } else { | 232 } else { |
| 267 devtools_server->Stop(); | 233 devtools_server->Stop(); |
| 268 } | 234 } |
| 269 } | 235 } |
| OLD | NEW |