Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "headless/lib/browser/headless_devtools.h" | |
| 6 | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "components/devtools_http_handler/devtools_http_handler.h" | |
| 9 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" | |
| 10 #include "content/public/browser/browser_context.h" | |
| 11 #include "content/public/browser/devtools_frontend_host.h" | |
| 12 #include "content/public/browser/navigation_entry.h" | |
| 13 #include "headless/lib/browser/headless_browser_context.h" | |
| 14 #include "net/base/net_errors.h" | |
| 15 #include "net/socket/tcp_server_socket.h" | |
| 16 #include "ui/base/resource/resource_bundle.h" | |
| 17 | |
| 18 using devtools_http_handler::DevToolsHttpHandler; | |
| 19 | |
| 20 namespace headless { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 const int kBackLog = 10; | |
| 25 | |
| 26 class TCPServerSocketFactory : public DevToolsHttpHandler::ServerSocketFactory { | |
| 27 public: | |
| 28 TCPServerSocketFactory(const std::string& address, uint16_t port) | |
| 29 : address_(address), port_(port) {} | |
| 30 | |
| 31 private: | |
| 32 // DevToolsHttpHandler::ServerSocketFactory implementation: | |
| 33 scoped_ptr<net::ServerSocket> CreateForHttpServer() override { | |
| 34 scoped_ptr<net::ServerSocket> socket( | |
| 35 new net::TCPServerSocket(nullptr, net::NetLog::Source())); | |
| 36 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK) | |
| 37 return scoped_ptr<net::ServerSocket>(); | |
| 38 | |
| 39 return socket; | |
| 40 } | |
| 41 | |
| 42 std::string address_; | |
| 43 uint16_t port_; | |
| 44 | |
| 45 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); | |
| 46 }; | |
| 47 | |
| 48 class HeadlessDevToolsDelegate | |
| 49 : public devtools_http_handler::DevToolsHttpHandlerDelegate { | |
| 50 public: | |
| 51 HeadlessDevToolsDelegate(); | |
| 52 ~HeadlessDevToolsDelegate() override; | |
| 53 | |
| 54 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation: | |
| 55 std::string GetDiscoveryPageHTML() override; | |
| 56 std::string GetFrontendResource(const std::string& path) override; | |
| 57 std::string GetPageThumbnailData(const GURL& url) override; | |
| 58 content::DevToolsExternalAgentProxyDelegate* HandleWebSocketConnection( | |
| 59 const std::string& path) override; | |
| 60 | |
| 61 private: | |
| 62 DISALLOW_COPY_AND_ASSIGN(HeadlessDevToolsDelegate); | |
| 63 }; | |
| 64 | |
| 65 HeadlessDevToolsDelegate::HeadlessDevToolsDelegate() {} | |
| 66 | |
| 67 HeadlessDevToolsDelegate::~HeadlessDevToolsDelegate() {} | |
| 68 | |
| 69 std::string HeadlessDevToolsDelegate::GetDiscoveryPageHTML() { | |
| 70 return std::string(); | |
| 71 } | |
| 72 | |
| 73 std::string HeadlessDevToolsDelegate::GetFrontendResource( | |
| 74 const std::string& path) { | |
| 75 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); | |
| 76 } | |
| 77 | |
| 78 std::string HeadlessDevToolsDelegate::GetPageThumbnailData(const GURL& url) { | |
| 79 return std::string(); | |
| 80 } | |
| 81 | |
| 82 content::DevToolsExternalAgentProxyDelegate* | |
| 83 HeadlessDevToolsDelegate::HandleWebSocketConnection(const std::string& path) { | |
| 84 return nullptr; | |
| 85 } | |
| 86 | |
| 87 } // namespace | |
| 88 | |
| 89 scoped_ptr<DevToolsHttpHandler> CreateLocalDevToolsHttpHandler( | |
| 90 HeadlessBrowserContext* browser_context) { | |
| 91 int port = browser_context->options().devtools_http_port; | |
| 92 DCHECK_GE(port, 0); | |
| 93 scoped_ptr<DevToolsHttpHandler::ServerSocketFactory> socket_factory( | |
| 94 new TCPServerSocketFactory("127.0.0.1", port)); | |
|
Ryan Sleevi
2016/02/22 21:11:13
Is this correct? Are you sure it should always be
Sami
2016/02/23 20:19:08
Agreed, I think it would be better for this to be
| |
| 95 return make_scoped_ptr(new DevToolsHttpHandler( | |
| 96 std::move(socket_factory), std::string(), new HeadlessDevToolsDelegate(), | |
| 97 browser_context->GetPath(), base::FilePath(), std::string(), | |
| 98 browser_context->options().user_agent)); | |
| 99 } | |
| 100 | |
| 101 } // namespace headless | |
| OLD | NEW |