| 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 | 9 |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "chrome/browser/android/dev_tools_manager_delegate_android.h" | |
| 22 #include "chrome/browser/android/tab_android.h" | 21 #include "chrome/browser/android/tab_android.h" |
| 23 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/history/top_sites_factory.h" | 23 #include "chrome/browser/history/top_sites_factory.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 25 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
| 27 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 26 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
| 28 #include "chrome/common/chrome_content_client.h" | 27 #include "chrome/common/chrome_content_client.h" |
| 29 #include "chrome/common/chrome_version_info.h" | 28 #include "chrome/common/chrome_version_info.h" |
| 30 #include "components/devtools_http_handler/devtools_http_handler.h" | 29 #include "components/devtools_http_handler/devtools_http_handler.h" |
| 31 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" | 30 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" |
| 32 #include "components/history/core/browser/top_sites.h" | 31 #include "components/history/core/browser/top_sites.h" |
| 33 #include "content/public/browser/android/devtools_auth.h" | 32 #include "content/public/browser/android/devtools_auth.h" |
| 34 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/devtools_agent_host.h" | 34 #include "content/public/browser/devtools_agent_host.h" |
| 36 #include "content/public/browser/devtools_target.h" | |
| 37 #include "content/public/browser/favicon_status.h" | 35 #include "content/public/browser/favicon_status.h" |
| 38 #include "content/public/browser/navigation_entry.h" | 36 #include "content/public/browser/navigation_entry.h" |
| 39 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
| 40 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/browser/web_contents_delegate.h" | 39 #include "content/public/browser/web_contents_delegate.h" |
| 42 #include "content/public/common/content_switches.h" | 40 #include "content/public/common/content_switches.h" |
| 43 #include "content/public/common/url_constants.h" | 41 #include "content/public/common/url_constants.h" |
| 44 #include "content/public/common/user_agent.h" | 42 #include "content/public/common/user_agent.h" |
| 45 #include "grit/browser_resources.h" | 43 #include "grit/browser_resources.h" |
| 46 #include "jni/DevToolsServer_jni.h" | 44 #include "jni/DevToolsServer_jni.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 FROM_HERE, | 97 FROM_HERE, |
| 100 base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails)); | 98 base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails)); |
| 101 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 99 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 102 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); | 100 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); |
| 103 } | 101 } |
| 104 | 102 |
| 105 std::string GetFrontendResource(const std::string& path) override { | 103 std::string GetFrontendResource(const std::string& path) override { |
| 106 return std::string(); | 104 return std::string(); |
| 107 } | 105 } |
| 108 | 106 |
| 107 std::string GetPageThumbnailData(const GURL& url) override { |
| 108 Profile* profile = |
| 109 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
| 110 scoped_refptr<history::TopSites> top_sites = |
| 111 TopSitesFactory::GetForProfile(profile); |
| 112 if (top_sites) { |
| 113 scoped_refptr<base::RefCountedMemory> data; |
| 114 if (top_sites->GetPageThumbnail(url, false, &data)) |
| 115 return std::string(data->front_as<char>(), data->size()); |
| 116 } |
| 117 return std::string(); |
| 118 } |
| 119 |
| 109 private: | 120 private: |
| 110 static void PopulatePageThumbnails() { | 121 static void PopulatePageThumbnails() { |
| 111 Profile* profile = | 122 Profile* profile = |
| 112 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); | 123 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
| 113 scoped_refptr<history::TopSites> top_sites = | 124 scoped_refptr<history::TopSites> top_sites = |
| 114 TopSitesFactory::GetForProfile(profile); | 125 TopSitesFactory::GetForProfile(profile); |
| 115 if (top_sites) | 126 if (top_sites) |
| 116 top_sites->SyncWithHistory(); | 127 top_sites->SyncWithHistory(); |
| 117 } | 128 } |
| 118 | 129 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 199 } |
| 189 | 200 |
| 190 void DevToolsServer::Start(bool allow_debug_permission) { | 201 void DevToolsServer::Start(bool allow_debug_permission) { |
| 191 if (devtools_http_handler_) | 202 if (devtools_http_handler_) |
| 192 return; | 203 return; |
| 193 | 204 |
| 194 net::UnixDomainServerSocket::AuthCallback auth_callback = | 205 net::UnixDomainServerSocket::AuthCallback auth_callback = |
| 195 allow_debug_permission ? | 206 allow_debug_permission ? |
| 196 base::Bind(&AuthorizeSocketAccessWithDebugPermission) : | 207 base::Bind(&AuthorizeSocketAccessWithDebugPermission) : |
| 197 base::Bind(&content::CanUserConnectToDevTools); | 208 base::Bind(&content::CanUserConnectToDevTools); |
| 198 manager_delegate_.reset(new DevToolsManagerDelegateAndroid()); | |
| 199 chrome::VersionInfo version_info; | 209 chrome::VersionInfo version_info; |
| 200 | 210 |
| 201 scoped_ptr<DevToolsHttpHandler::ServerSocketFactory> factory( | 211 scoped_ptr<DevToolsHttpHandler::ServerSocketFactory> factory( |
| 202 new UnixDomainServerSocketFactory(socket_name_, auth_callback)); | 212 new UnixDomainServerSocketFactory(socket_name_, auth_callback)); |
| 203 devtools_http_handler_.reset(new DevToolsHttpHandler( | 213 devtools_http_handler_.reset(new DevToolsHttpHandler( |
| 204 factory.Pass(), | 214 factory.Pass(), |
| 205 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), | 215 base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), |
| 206 new DevToolsServerDelegate(), | 216 new DevToolsServerDelegate(), |
| 207 manager_delegate_.get(), | |
| 208 base::FilePath(), | 217 base::FilePath(), |
| 209 base::FilePath(), | 218 base::FilePath(), |
| 210 version_info.ProductNameAndVersionForUserAgent(), | 219 version_info.ProductNameAndVersionForUserAgent(), |
| 211 ::GetUserAgent())); | 220 ::GetUserAgent())); |
| 212 } | 221 } |
| 213 | 222 |
| 214 void DevToolsServer::Stop() { | 223 void DevToolsServer::Stop() { |
| 215 devtools_http_handler_.reset(); | 224 devtools_http_handler_.reset(); |
| 216 manager_delegate_.reset(); | |
| 217 } | 225 } |
| 218 | 226 |
| 219 bool DevToolsServer::IsStarted() const { | 227 bool DevToolsServer::IsStarted() const { |
| 220 return devtools_http_handler_; | 228 return devtools_http_handler_; |
| 221 } | 229 } |
| 222 | 230 |
| 223 bool RegisterDevToolsServer(JNIEnv* env) { | 231 bool RegisterDevToolsServer(JNIEnv* env) { |
| 224 return RegisterNativesImpl(env); | 232 return RegisterNativesImpl(env); |
| 225 } | 233 } |
| 226 | 234 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 247 jlong server, | 255 jlong server, |
| 248 jboolean enabled, | 256 jboolean enabled, |
| 249 jboolean allow_debug_permission) { | 257 jboolean allow_debug_permission) { |
| 250 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); | 258 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); |
| 251 if (enabled) { | 259 if (enabled) { |
| 252 devtools_server->Start(allow_debug_permission); | 260 devtools_server->Start(allow_debug_permission); |
| 253 } else { | 261 } else { |
| 254 devtools_server->Stop(); | 262 devtools_server->Stop(); |
| 255 } | 263 } |
| 256 } | 264 } |
| OLD | NEW |