Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: headless/lib/browser/headless_devtools.cc

Issue 2295623002: DevTools: simplify http handler delegate as it is moving into content. (Closed)
Patch Set: lcean Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/shell/browser/shell_devtools_manager_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "components/devtools_http_handler/devtools_http_handler.h" 12 #include "components/devtools_http_handler/devtools_http_handler.h"
13 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" 13 #include "components/devtools_http_handler/devtools_http_handler_delegate.h"
14 #include "content/public/browser/devtools_frontend_host.h" 14 #include "content/public/browser/devtools_frontend_host.h"
15 #include "content/public/browser/devtools_socket_factory.h"
15 #include "content/public/browser/navigation_entry.h" 16 #include "content/public/browser/navigation_entry.h"
16 #include "headless/grit/headless_lib_resources.h" 17 #include "headless/grit/headless_lib_resources.h"
17 #include "headless/public/headless_browser.h" 18 #include "headless/public/headless_browser.h"
18 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
19 #include "net/socket/tcp_server_socket.h" 20 #include "net/socket/tcp_server_socket.h"
20 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
21 22
22 using devtools_http_handler::DevToolsHttpHandler; 23 using devtools_http_handler::DevToolsHttpHandler;
23 24
24 namespace headless { 25 namespace headless {
25 26
26 namespace { 27 namespace {
27 28
28 const int kBackLog = 10; 29 const int kBackLog = 10;
29 30
30 class TCPServerSocketFactory : public DevToolsHttpHandler::ServerSocketFactory { 31 class TCPServerSocketFactory : public content::DevToolsSocketFactory {
31 public: 32 public:
32 explicit TCPServerSocketFactory(const net::IPEndPoint& endpoint) 33 explicit TCPServerSocketFactory(const net::IPEndPoint& endpoint)
33 : endpoint_(endpoint) { 34 : endpoint_(endpoint) {
34 DCHECK(endpoint_.address().IsValid()); 35 DCHECK(endpoint_.address().IsValid());
35 } 36 }
36 37
37 private: 38 private:
38 // DevToolsHttpHandler::ServerSocketFactory implementation: 39 // content::DevToolsSocketFactory implementation:
39 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { 40 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
40 std::unique_ptr<net::ServerSocket> socket( 41 std::unique_ptr<net::ServerSocket> socket(
41 new net::TCPServerSocket(nullptr, net::NetLog::Source())); 42 new net::TCPServerSocket(nullptr, net::NetLog::Source()));
42 if (socket->Listen(endpoint_, kBackLog) != net::OK) 43 if (socket->Listen(endpoint_, kBackLog) != net::OK)
43 return std::unique_ptr<net::ServerSocket>(); 44 return std::unique_ptr<net::ServerSocket>();
44 45
45 return socket; 46 return socket;
46 } 47 }
47 48
49 std::unique_ptr<net::ServerSocket> CreateForTethering(
50 std::string* out_name) override {
51 return nullptr;
52 }
53
48 net::IPEndPoint endpoint_; 54 net::IPEndPoint endpoint_;
49 55
50 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); 56 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory);
51 }; 57 };
52 58
53 class HeadlessDevToolsDelegate 59 class HeadlessDevToolsDelegate
54 : public devtools_http_handler::DevToolsHttpHandlerDelegate { 60 : public devtools_http_handler::DevToolsHttpHandlerDelegate {
55 public: 61 public:
56 HeadlessDevToolsDelegate(); 62 HeadlessDevToolsDelegate();
57 ~HeadlessDevToolsDelegate() override; 63 ~HeadlessDevToolsDelegate() override;
58 64
59 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation: 65 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation:
60 std::string GetDiscoveryPageHTML() override; 66 std::string GetDiscoveryPageHTML() override;
61 std::string GetFrontendResource(const std::string& path) override; 67 std::string GetFrontendResource(const std::string& path) override;
62 std::string GetPageThumbnailData(const GURL& url) override;
63 content::DevToolsExternalAgentProxyDelegate* HandleWebSocketConnection(
64 const std::string& path) override;
65 68
66 private: 69 private:
67 DISALLOW_COPY_AND_ASSIGN(HeadlessDevToolsDelegate); 70 DISALLOW_COPY_AND_ASSIGN(HeadlessDevToolsDelegate);
68 }; 71 };
69 72
70 HeadlessDevToolsDelegate::HeadlessDevToolsDelegate() {} 73 HeadlessDevToolsDelegate::HeadlessDevToolsDelegate() {}
71 74
72 HeadlessDevToolsDelegate::~HeadlessDevToolsDelegate() {} 75 HeadlessDevToolsDelegate::~HeadlessDevToolsDelegate() {}
73 76
74 std::string HeadlessDevToolsDelegate::GetDiscoveryPageHTML() { 77 std::string HeadlessDevToolsDelegate::GetDiscoveryPageHTML() {
75 return ResourceBundle::GetSharedInstance().GetRawDataResource( 78 return ResourceBundle::GetSharedInstance().GetRawDataResource(
76 IDR_HEADLESS_LIB_DEVTOOLS_DISCOVERY_PAGE).as_string(); 79 IDR_HEADLESS_LIB_DEVTOOLS_DISCOVERY_PAGE).as_string();
77 } 80 }
78 81
79 std::string HeadlessDevToolsDelegate::GetFrontendResource( 82 std::string HeadlessDevToolsDelegate::GetFrontendResource(
80 const std::string& path) { 83 const std::string& path) {
81 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); 84 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string();
82 } 85 }
83 86
84 std::string HeadlessDevToolsDelegate::GetPageThumbnailData(const GURL& url) {
85 return std::string();
86 }
87
88 content::DevToolsExternalAgentProxyDelegate*
89 HeadlessDevToolsDelegate::HandleWebSocketConnection(const std::string& path) {
90 return nullptr;
91 }
92
93 } // namespace 87 } // namespace
94 88
95 std::unique_ptr<DevToolsHttpHandler> CreateLocalDevToolsHttpHandler( 89 std::unique_ptr<DevToolsHttpHandler> CreateLocalDevToolsHttpHandler(
96 HeadlessBrowser::Options* options) { 90 HeadlessBrowser::Options* options) {
97 const net::IPEndPoint& endpoint = options->devtools_endpoint; 91 const net::IPEndPoint& endpoint = options->devtools_endpoint;
98 std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory> socket_factory( 92 std::unique_ptr<content::DevToolsSocketFactory> socket_factory(
99 new TCPServerSocketFactory(endpoint)); 93 new TCPServerSocketFactory(endpoint));
100 return base::MakeUnique<DevToolsHttpHandler>( 94 return base::MakeUnique<DevToolsHttpHandler>(
101 std::move(socket_factory), std::string(), new HeadlessDevToolsDelegate(), 95 std::move(socket_factory), std::string(), new HeadlessDevToolsDelegate(),
102 options->user_data_dir, // TODO(altimin): Figure a proper value for this. 96 options->user_data_dir, // TODO(altimin): Figure a proper value for this.
103 base::FilePath(), std::string(), options->user_agent); 97 base::FilePath(), std::string(), options->user_agent);
104 } 98 }
105 99
106 } // namespace headless 100 } // namespace headless
OLDNEW
« no previous file with comments | « content/shell/browser/shell_devtools_manager_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698