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 net::IPEndPoint& endpoint) |
| 29 : endpoint_(endpoint) { |
| 30 DCHECK(endpoint_.address().IsValid()); |
| 31 } |
| 32 |
| 33 private: |
| 34 // DevToolsHttpHandler::ServerSocketFactory implementation: |
| 35 scoped_ptr<net::ServerSocket> CreateForHttpServer() override { |
| 36 scoped_ptr<net::ServerSocket> socket( |
| 37 new net::TCPServerSocket(nullptr, net::NetLog::Source())); |
| 38 if (socket->Listen(endpoint_, kBackLog) != net::OK) |
| 39 return scoped_ptr<net::ServerSocket>(); |
| 40 |
| 41 return socket; |
| 42 } |
| 43 |
| 44 net::IPEndPoint endpoint_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); |
| 47 }; |
| 48 |
| 49 class HeadlessDevToolsDelegate |
| 50 : public devtools_http_handler::DevToolsHttpHandlerDelegate { |
| 51 public: |
| 52 HeadlessDevToolsDelegate(); |
| 53 ~HeadlessDevToolsDelegate() override; |
| 54 |
| 55 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation: |
| 56 std::string GetDiscoveryPageHTML() override; |
| 57 std::string GetFrontendResource(const std::string& path) override; |
| 58 std::string GetPageThumbnailData(const GURL& url) override; |
| 59 content::DevToolsExternalAgentProxyDelegate* HandleWebSocketConnection( |
| 60 const std::string& path) override; |
| 61 |
| 62 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(HeadlessDevToolsDelegate); |
| 64 }; |
| 65 |
| 66 HeadlessDevToolsDelegate::HeadlessDevToolsDelegate() {} |
| 67 |
| 68 HeadlessDevToolsDelegate::~HeadlessDevToolsDelegate() {} |
| 69 |
| 70 std::string HeadlessDevToolsDelegate::GetDiscoveryPageHTML() { |
| 71 return std::string(); |
| 72 } |
| 73 |
| 74 std::string HeadlessDevToolsDelegate::GetFrontendResource( |
| 75 const std::string& path) { |
| 76 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); |
| 77 } |
| 78 |
| 79 std::string HeadlessDevToolsDelegate::GetPageThumbnailData(const GURL& url) { |
| 80 return std::string(); |
| 81 } |
| 82 |
| 83 content::DevToolsExternalAgentProxyDelegate* |
| 84 HeadlessDevToolsDelegate::HandleWebSocketConnection(const std::string& path) { |
| 85 return nullptr; |
| 86 } |
| 87 |
| 88 } // namespace |
| 89 |
| 90 scoped_ptr<DevToolsHttpHandler> CreateLocalDevToolsHttpHandler( |
| 91 HeadlessBrowserContext* browser_context) { |
| 92 const net::IPEndPoint& endpoint = |
| 93 browser_context->options().devtools_endpoint; |
| 94 scoped_ptr<DevToolsHttpHandler::ServerSocketFactory> socket_factory( |
| 95 new TCPServerSocketFactory(endpoint)); |
| 96 return make_scoped_ptr(new DevToolsHttpHandler( |
| 97 std::move(socket_factory), std::string(), new HeadlessDevToolsDelegate(), |
| 98 browser_context->GetPath(), base::FilePath(), std::string(), |
| 99 browser_context->options().user_agent)); |
| 100 } |
| 101 |
| 102 } // namespace headless |
OLD | NEW |