| 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 "content/shell/browser/shell_devtools_manager_delegate.h" | 5 #include "content/shell/browser/shell_devtools_manager_delegate.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "components/devtools_discovery/devtools_discovery_manager.h" | |
| 21 #include "components/devtools_http_handler/devtools_http_handler.h" | 20 #include "components/devtools_http_handler/devtools_http_handler.h" |
| 22 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/devtools_agent_host.h" | 22 #include "content/public/browser/devtools_agent_host.h" |
| 24 #include "content/public/browser/devtools_frontend_host.h" | 23 #include "content/public/browser/devtools_frontend_host.h" |
| 25 #include "content/public/browser/favicon_status.h" | 24 #include "content/public/browser/favicon_status.h" |
| 26 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
| 27 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
| 28 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
| 30 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 port = static_cast<uint16_t>(temp_port); | 126 port = static_cast<uint16_t>(temp_port); |
| 128 } else { | 127 } else { |
| 129 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; | 128 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; |
| 130 } | 129 } |
| 131 } | 130 } |
| 132 return std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory>( | 131 return std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory>( |
| 133 new TCPServerSocketFactory("127.0.0.1", port)); | 132 new TCPServerSocketFactory("127.0.0.1", port)); |
| 134 #endif | 133 #endif |
| 135 } | 134 } |
| 136 | 135 |
| 137 scoped_refptr<content::DevToolsAgentHost> | |
| 138 CreateNewShellTarget(BrowserContext* browser_context, const GURL& url) { | |
| 139 Shell* shell = Shell::CreateNewWindow(browser_context, | |
| 140 url, | |
| 141 nullptr, | |
| 142 gfx::Size()); | |
| 143 return DevToolsAgentHost::GetOrCreateFor(shell->web_contents()); | |
| 144 } | |
| 145 | |
| 146 // ShellDevToolsDelegate ---------------------------------------------------- | 136 // ShellDevToolsDelegate ---------------------------------------------------- |
| 147 | 137 |
| 148 class ShellDevToolsDelegate : | 138 class ShellDevToolsDelegate : |
| 149 public devtools_http_handler::DevToolsHttpHandlerDelegate { | 139 public devtools_http_handler::DevToolsHttpHandlerDelegate { |
| 150 public: | 140 public: |
| 151 explicit ShellDevToolsDelegate(BrowserContext* browser_context); | 141 explicit ShellDevToolsDelegate(); |
| 152 ~ShellDevToolsDelegate() override; | 142 ~ShellDevToolsDelegate() override; |
| 153 | 143 |
| 154 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation. | 144 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation. |
| 155 std::string GetDiscoveryPageHTML() override; | 145 std::string GetDiscoveryPageHTML() override; |
| 156 std::string GetFrontendResource(const std::string& path) override; | 146 std::string GetFrontendResource(const std::string& path) override; |
| 157 std::string GetPageThumbnailData(const GURL& url) override; | 147 std::string GetPageThumbnailData(const GURL& url) override; |
| 158 DevToolsExternalAgentProxyDelegate* | 148 DevToolsExternalAgentProxyDelegate* |
| 159 HandleWebSocketConnection(const std::string& path) override; | 149 HandleWebSocketConnection(const std::string& path) override; |
| 160 | 150 |
| 161 private: | 151 private: |
| 162 DISALLOW_COPY_AND_ASSIGN(ShellDevToolsDelegate); | 152 DISALLOW_COPY_AND_ASSIGN(ShellDevToolsDelegate); |
| 163 }; | 153 }; |
| 164 | 154 |
| 165 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context) { | 155 ShellDevToolsDelegate::ShellDevToolsDelegate() { |
| 166 devtools_discovery::DevToolsDiscoveryManager::GetInstance()-> | |
| 167 SetCreateCallback(base::Bind(&CreateNewShellTarget, | |
| 168 base::Unretained(browser_context))); | |
| 169 } | 156 } |
| 170 | 157 |
| 171 ShellDevToolsDelegate::~ShellDevToolsDelegate() { | 158 ShellDevToolsDelegate::~ShellDevToolsDelegate() { |
| 172 devtools_discovery::DevToolsDiscoveryManager::GetInstance()-> | |
| 173 SetCreateCallback( | |
| 174 devtools_discovery::DevToolsDiscoveryManager::CreateCallback()); | |
| 175 } | 159 } |
| 176 | 160 |
| 177 std::string ShellDevToolsDelegate::GetDiscoveryPageHTML() { | 161 std::string ShellDevToolsDelegate::GetDiscoveryPageHTML() { |
| 178 #if defined(OS_ANDROID) | 162 #if defined(OS_ANDROID) |
| 179 return std::string(); | 163 return std::string(); |
| 180 #else | 164 #else |
| 181 return ResourceBundle::GetSharedInstance().GetRawDataResource( | 165 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 182 IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); | 166 IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); |
| 183 #endif | 167 #endif |
| 184 } | 168 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 205 DevToolsHttpHandler* | 189 DevToolsHttpHandler* |
| 206 ShellDevToolsManagerDelegate::CreateHttpHandler( | 190 ShellDevToolsManagerDelegate::CreateHttpHandler( |
| 207 BrowserContext* browser_context) { | 191 BrowserContext* browser_context) { |
| 208 std::string frontend_url; | 192 std::string frontend_url; |
| 209 #if defined(OS_ANDROID) | 193 #if defined(OS_ANDROID) |
| 210 frontend_url = base::StringPrintf(kFrontEndURL, GetWebKitRevision().c_str()); | 194 frontend_url = base::StringPrintf(kFrontEndURL, GetWebKitRevision().c_str()); |
| 211 #endif | 195 #endif |
| 212 return new DevToolsHttpHandler( | 196 return new DevToolsHttpHandler( |
| 213 CreateSocketFactory(), | 197 CreateSocketFactory(), |
| 214 frontend_url, | 198 frontend_url, |
| 215 new ShellDevToolsDelegate(browser_context), | 199 new ShellDevToolsDelegate(), |
| 216 browser_context->GetPath(), | 200 browser_context->GetPath(), |
| 217 base::FilePath(), | 201 base::FilePath(), |
| 218 std::string(), | 202 std::string(), |
| 219 GetShellUserAgent()); | 203 GetShellUserAgent()); |
| 220 } | 204 } |
| 221 | 205 |
| 222 ShellDevToolsManagerDelegate::ShellDevToolsManagerDelegate() { | 206 ShellDevToolsManagerDelegate::ShellDevToolsManagerDelegate( |
| 207 BrowserContext* browser_context) |
| 208 : browser_context_(browser_context) { |
| 223 } | 209 } |
| 224 | 210 |
| 225 ShellDevToolsManagerDelegate::~ShellDevToolsManagerDelegate() { | 211 ShellDevToolsManagerDelegate::~ShellDevToolsManagerDelegate() { |
| 226 } | 212 } |
| 227 | 213 |
| 228 base::DictionaryValue* ShellDevToolsManagerDelegate::HandleCommand( | 214 base::DictionaryValue* ShellDevToolsManagerDelegate::HandleCommand( |
| 229 DevToolsAgentHost* agent_host, | 215 DevToolsAgentHost* agent_host, |
| 230 base::DictionaryValue* command_dict) { | 216 base::DictionaryValue* command_dict) { |
| 231 std::unique_ptr<base::DictionaryValue> result = | 217 return HandleCreateTargetCommand(command_dict).release(); |
| 232 devtools_discovery::DevToolsDiscoveryManager::GetInstance() | |
| 233 ->HandleCreateTargetCommand(command_dict); | |
| 234 return result.release(); // Caller takes ownership. | |
| 235 } | 218 } |
| 236 | 219 |
| 237 std::string ShellDevToolsManagerDelegate::GetTargetType(RenderFrameHost* host) { | 220 std::string ShellDevToolsManagerDelegate::GetTargetType(RenderFrameHost* host) { |
| 238 return DevToolsAgentHost::kTypePage; | 221 return DevToolsAgentHost::kTypePage; |
| 239 } | 222 } |
| 240 | 223 |
| 241 std::string ShellDevToolsManagerDelegate::GetTargetTitle( | 224 std::string ShellDevToolsManagerDelegate::GetTargetTitle( |
| 242 RenderFrameHost* host) { | 225 RenderFrameHost* host) { |
| 243 return ""; | 226 return ""; |
| 244 } | 227 } |
| 245 | 228 |
| 229 |
| 230 scoped_refptr<DevToolsAgentHost> |
| 231 ShellDevToolsManagerDelegate::CreateNewTarget(const GURL& url) { |
| 232 Shell* shell = Shell::CreateNewWindow(browser_context_, |
| 233 url, |
| 234 nullptr, |
| 235 gfx::Size()); |
| 236 return DevToolsAgentHost::GetOrCreateFor(shell->web_contents()); |
| 237 } |
| 238 |
| 239 std::unique_ptr<base::DictionaryValue> |
| 240 ShellDevToolsManagerDelegate::HandleCreateTargetCommand( |
| 241 base::DictionaryValue* command_dict) { |
| 242 int id; |
| 243 std::string method; |
| 244 std::string url; |
| 245 const base::DictionaryValue* params_dict = nullptr; |
| 246 if (command_dict->GetInteger("id", &id) && |
| 247 command_dict->GetString("method", &method) && |
| 248 method == "Browser.createTarget" && |
| 249 command_dict->GetDictionary("params", ¶ms_dict) && |
| 250 params_dict->GetString("url", &url)) { |
| 251 scoped_refptr<content::DevToolsAgentHost> agent_host = |
| 252 CreateNewTarget(GURL(url)); |
| 253 if (!agent_host) |
| 254 return nullptr; |
| 255 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 256 result->SetInteger("id", id); |
| 257 std::unique_ptr<base::DictionaryValue> cmd_result( |
| 258 new base::DictionaryValue()); |
| 259 cmd_result->SetString("targetId", agent_host->GetId()); |
| 260 result->Set("result", std::move(cmd_result)); |
| 261 return result; |
| 262 } |
| 263 return nullptr; |
| 264 } |
| 265 |
| 246 } // namespace content | 266 } // namespace content |
| OLD | NEW |