OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "headless/lib/browser/headless_devtools.h" | 5 #include "headless/lib/browser/headless_devtools.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/ptr_util.h" |
8 #include "components/devtools_http_handler/devtools_http_handler.h" | 9 #include "components/devtools_http_handler/devtools_http_handler.h" |
9 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" | 10 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" |
10 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
11 #include "content/public/browser/devtools_frontend_host.h" | 12 #include "content/public/browser/devtools_frontend_host.h" |
12 #include "content/public/browser/navigation_entry.h" | 13 #include "content/public/browser/navigation_entry.h" |
13 #include "headless/grit/headless_lib_resources.h" | 14 #include "headless/grit/headless_lib_resources.h" |
14 #include "headless/lib/browser/headless_browser_context.h" | 15 #include "headless/lib/browser/headless_browser_context.h" |
15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
16 #include "net/socket/tcp_server_socket.h" | 17 #include "net/socket/tcp_server_socket.h" |
17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
18 | 19 |
19 using devtools_http_handler::DevToolsHttpHandler; | 20 using devtools_http_handler::DevToolsHttpHandler; |
20 | 21 |
21 namespace headless { | 22 namespace headless { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 const int kBackLog = 10; | 26 const int kBackLog = 10; |
26 | 27 |
27 class TCPServerSocketFactory : public DevToolsHttpHandler::ServerSocketFactory { | 28 class TCPServerSocketFactory : public DevToolsHttpHandler::ServerSocketFactory { |
28 public: | 29 public: |
29 TCPServerSocketFactory(const net::IPEndPoint& endpoint) | 30 TCPServerSocketFactory(const net::IPEndPoint& endpoint) |
30 : endpoint_(endpoint) { | 31 : endpoint_(endpoint) { |
31 DCHECK(endpoint_.address().IsValid()); | 32 DCHECK(endpoint_.address().IsValid()); |
32 } | 33 } |
33 | 34 |
34 private: | 35 private: |
35 // DevToolsHttpHandler::ServerSocketFactory implementation: | 36 // DevToolsHttpHandler::ServerSocketFactory implementation: |
36 scoped_ptr<net::ServerSocket> CreateForHttpServer() override { | 37 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { |
37 scoped_ptr<net::ServerSocket> socket( | 38 std::unique_ptr<net::ServerSocket> socket( |
38 new net::TCPServerSocket(nullptr, net::NetLog::Source())); | 39 new net::TCPServerSocket(nullptr, net::NetLog::Source())); |
39 if (socket->Listen(endpoint_, kBackLog) != net::OK) | 40 if (socket->Listen(endpoint_, kBackLog) != net::OK) |
40 return scoped_ptr<net::ServerSocket>(); | 41 return std::unique_ptr<net::ServerSocket>(); |
41 | 42 |
42 return socket; | 43 return socket; |
43 } | 44 } |
44 | 45 |
45 net::IPEndPoint endpoint_; | 46 net::IPEndPoint endpoint_; |
46 | 47 |
47 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); | 48 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); |
48 }; | 49 }; |
49 | 50 |
50 class HeadlessDevToolsDelegate | 51 class HeadlessDevToolsDelegate |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 return std::string(); | 83 return std::string(); |
83 } | 84 } |
84 | 85 |
85 content::DevToolsExternalAgentProxyDelegate* | 86 content::DevToolsExternalAgentProxyDelegate* |
86 HeadlessDevToolsDelegate::HandleWebSocketConnection(const std::string& path) { | 87 HeadlessDevToolsDelegate::HandleWebSocketConnection(const std::string& path) { |
87 return nullptr; | 88 return nullptr; |
88 } | 89 } |
89 | 90 |
90 } // namespace | 91 } // namespace |
91 | 92 |
92 scoped_ptr<DevToolsHttpHandler> CreateLocalDevToolsHttpHandler( | 93 std::unique_ptr<DevToolsHttpHandler> CreateLocalDevToolsHttpHandler( |
93 HeadlessBrowserContext* browser_context) { | 94 HeadlessBrowserContext* browser_context) { |
94 const net::IPEndPoint& endpoint = | 95 const net::IPEndPoint& endpoint = |
95 browser_context->options().devtools_endpoint; | 96 browser_context->options().devtools_endpoint; |
96 scoped_ptr<DevToolsHttpHandler::ServerSocketFactory> socket_factory( | 97 std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory> socket_factory( |
97 new TCPServerSocketFactory(endpoint)); | 98 new TCPServerSocketFactory(endpoint)); |
98 return make_scoped_ptr(new DevToolsHttpHandler( | 99 return base::WrapUnique(new DevToolsHttpHandler( |
99 std::move(socket_factory), std::string(), new HeadlessDevToolsDelegate(), | 100 std::move(socket_factory), std::string(), new HeadlessDevToolsDelegate(), |
100 browser_context->GetPath(), base::FilePath(), std::string(), | 101 browser_context->GetPath(), base::FilePath(), std::string(), |
101 browser_context->options().user_agent)); | 102 browser_context->options().user_agent)); |
102 } | 103 } |
103 | 104 |
104 } // namespace headless | 105 } // namespace headless |
OLD | NEW |