| 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/devtools/remote_debugging_server.h" | 5 #include "chrome/browser/devtools/remote_debugging_server.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" | |
| 11 #include "chrome/browser/history/top_sites_factory.h" | 10 #include "chrome/browser/history/top_sites_factory.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_iterator.h" | 13 #include "chrome/browser/ui/browser_iterator.h" |
| 15 #include "chrome/common/chrome_content_client.h" | 14 #include "chrome/common/chrome_content_client.h" |
| 16 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/chrome_version_info.h" | 16 #include "chrome/common/chrome_version_info.h" |
| 18 #include "components/devtools_http_handler/devtools_http_handler.h" | 17 #include "components/devtools_http_handler/devtools_http_handler.h" |
| 19 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" | 18 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" |
| 20 #include "components/history/core/browser/top_sites.h" | 19 #include "components/history/core/browser/top_sites.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 77 |
| 79 class ChromeDevToolsHttpHandlerDelegate | 78 class ChromeDevToolsHttpHandlerDelegate |
| 80 : public devtools_http_handler::DevToolsHttpHandlerDelegate { | 79 : public devtools_http_handler::DevToolsHttpHandlerDelegate { |
| 81 public: | 80 public: |
| 82 ChromeDevToolsHttpHandlerDelegate(); | 81 ChromeDevToolsHttpHandlerDelegate(); |
| 83 ~ChromeDevToolsHttpHandlerDelegate() override; | 82 ~ChromeDevToolsHttpHandlerDelegate() override; |
| 84 | 83 |
| 85 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation. | 84 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation. |
| 86 std::string GetDiscoveryPageHTML() override; | 85 std::string GetDiscoveryPageHTML() override; |
| 87 std::string GetFrontendResource(const std::string& path) override; | 86 std::string GetFrontendResource(const std::string& path) override; |
| 87 std::string GetPageThumbnailData(const GURL& url) override; |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 DISALLOW_COPY_AND_ASSIGN(ChromeDevToolsHttpHandlerDelegate); | 90 DISALLOW_COPY_AND_ASSIGN(ChromeDevToolsHttpHandlerDelegate); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 ChromeDevToolsHttpHandlerDelegate::ChromeDevToolsHttpHandlerDelegate() { | 93 ChromeDevToolsHttpHandlerDelegate::ChromeDevToolsHttpHandlerDelegate() { |
| 94 } | 94 } |
| 95 | 95 |
| 96 ChromeDevToolsHttpHandlerDelegate::~ChromeDevToolsHttpHandlerDelegate() { | 96 ChromeDevToolsHttpHandlerDelegate::~ChromeDevToolsHttpHandlerDelegate() { |
| 97 } | 97 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 112 } | 112 } |
| 113 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 113 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 114 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); | 114 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 std::string ChromeDevToolsHttpHandlerDelegate::GetFrontendResource( | 117 std::string ChromeDevToolsHttpHandlerDelegate::GetFrontendResource( |
| 118 const std::string& path) { | 118 const std::string& path) { |
| 119 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); | 119 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 std::string ChromeDevToolsHttpHandlerDelegate::GetPageThumbnailData( |
| 123 const GURL& url) { |
| 124 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 125 Profile* profile = (*it)->profile(); |
| 126 scoped_refptr<history::TopSites> top_sites = |
| 127 TopSitesFactory::GetForProfile(profile); |
| 128 if (!top_sites) |
| 129 continue; |
| 130 scoped_refptr<base::RefCountedMemory> data; |
| 131 if (top_sites->GetPageThumbnail(url, false, &data)) |
| 132 return std::string(data->front_as<char>(), data->size()); |
| 133 } |
| 134 return std::string(); |
| 135 } |
| 136 |
| 122 } // namespace | 137 } // namespace |
| 123 | 138 |
| 124 // static | 139 // static |
| 125 void RemoteDebuggingServer::EnableTetheringForDebug() { | 140 void RemoteDebuggingServer::EnableTetheringForDebug() { |
| 126 g_tethering_enabled.Get() = true; | 141 g_tethering_enabled.Get() = true; |
| 127 } | 142 } |
| 128 | 143 |
| 129 RemoteDebuggingServer::RemoteDebuggingServer( | 144 RemoteDebuggingServer::RemoteDebuggingServer( |
| 130 chrome::HostDesktopType host_desktop_type, | 145 chrome::HostDesktopType host_desktop_type, |
| 131 const std::string& ip, | 146 const std::string& ip, |
| 132 uint16 port) { | 147 uint16 port) { |
| 133 base::FilePath output_dir; | 148 base::FilePath output_dir; |
| 134 if (!port) { | 149 if (!port) { |
| 135 // The client requested an ephemeral port. Must write the selected | 150 // The client requested an ephemeral port. Must write the selected |
| 136 // port to a well-known location in the profile directory to | 151 // port to a well-known location in the profile directory to |
| 137 // bootstrap the connection process. | 152 // bootstrap the connection process. |
| 138 bool result = PathService::Get(chrome::DIR_USER_DATA, &output_dir); | 153 bool result = PathService::Get(chrome::DIR_USER_DATA, &output_dir); |
| 139 DCHECK(result); | 154 DCHECK(result); |
| 140 } | 155 } |
| 141 | 156 |
| 142 manager_delegate_.reset(new ChromeDevToolsManagerDelegate()); | |
| 143 | |
| 144 base::FilePath debug_frontend_dir; | 157 base::FilePath debug_frontend_dir; |
| 145 #if defined(DEBUG_DEVTOOLS) | 158 #if defined(DEBUG_DEVTOOLS) |
| 146 PathService::Get(chrome::DIR_INSPECTOR, &debug_frontend_dir); | 159 PathService::Get(chrome::DIR_INSPECTOR, &debug_frontend_dir); |
| 147 #endif | 160 #endif |
| 148 | 161 |
| 149 chrome::VersionInfo version_info; | 162 chrome::VersionInfo version_info; |
| 150 | 163 |
| 151 devtools_http_handler_.reset(new devtools_http_handler::DevToolsHttpHandler( | 164 devtools_http_handler_.reset(new devtools_http_handler::DevToolsHttpHandler( |
| 152 make_scoped_ptr(new TCPServerSocketFactory(ip, port)), | 165 make_scoped_ptr(new TCPServerSocketFactory(ip, port)), |
| 153 std::string(), | 166 std::string(), |
| 154 new ChromeDevToolsHttpHandlerDelegate(), | 167 new ChromeDevToolsHttpHandlerDelegate(), |
| 155 manager_delegate_.get(), | |
| 156 output_dir, | 168 output_dir, |
| 157 debug_frontend_dir, | 169 debug_frontend_dir, |
| 158 version_info.ProductNameAndVersionForUserAgent(), | 170 version_info.ProductNameAndVersionForUserAgent(), |
| 159 ::GetUserAgent())); | 171 ::GetUserAgent())); |
| 160 } | 172 } |
| 161 | 173 |
| 162 RemoteDebuggingServer::~RemoteDebuggingServer() { | 174 RemoteDebuggingServer::~RemoteDebuggingServer() { |
| 163 } | 175 } |
| OLD | NEW |