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

Side by Side Diff: headless/public/headless_browser.h

Issue 2024973002: headless: Allow protocol handler customization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 years, 6 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
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 #ifndef HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ 5 #ifndef HEADLESS_PUBLIC_HEADLESS_BROWSER_H_
6 #define HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ 6 #define HEADLESS_PUBLIC_HEADLESS_BROWSER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <unordered_map>
10 11
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "headless/public/headless_export.h" 15 #include "headless/public/headless_export.h"
15 #include "net/base/host_port_pair.h" 16 #include "net/base/host_port_pair.h"
16 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
18 #include "net/url_request/url_request_job_factory.h"
17 19
18 namespace base { 20 namespace base {
19 class MessagePump; 21 class MessagePump;
20 class SingleThreadTaskRunner; 22 class SingleThreadTaskRunner;
21 } 23 }
22 24
23 namespace gfx { 25 namespace gfx {
24 class Size; 26 class Size;
25 } 27 }
26 28
(...skipping 27 matching lines...) Expand all
54 virtual void Shutdown() = 0; 56 virtual void Shutdown() = 0;
55 57
56 protected: 58 protected:
57 HeadlessBrowser() {} 59 HeadlessBrowser() {}
58 virtual ~HeadlessBrowser() {} 60 virtual ~HeadlessBrowser() {}
59 61
60 private: 62 private:
61 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser); 63 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser);
62 }; 64 };
63 65
66 using ProtocolHandlerMap = std::unordered_map<
67 std::string,
68 std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler>>;
69
64 // Embedding API overrides for the headless browser. 70 // Embedding API overrides for the headless browser.
65 struct HeadlessBrowser::Options { 71 struct HeadlessBrowser::Options {
66 class Builder; 72 class Builder;
67 73
68 Options(Options&& options); 74 Options(Options&& options);
69 ~Options(); 75 ~Options();
70 76
71 Options& operator=(Options&& options); 77 Options& operator=(Options&& options);
72 78
73 // Command line options to be passed to browser. 79 // Command line options to be passed to browser.
(...skipping 16 matching lines...) Expand all
90 96
91 // Comma-separated list of rules that control how hostnames are mapped. See 97 // Comma-separated list of rules that control how hostnames are mapped. See
92 // chrome::switches::kHostRules for a description for the format. 98 // chrome::switches::kHostRules for a description for the format.
93 std::string host_resolver_rules; 99 std::string host_resolver_rules;
94 100
95 // Run the browser in single process mode instead of using separate renderer 101 // Run the browser in single process mode instead of using separate renderer
96 // processes as per default. Note that this also disables any sandboxing of 102 // processes as per default. Note that this also disables any sandboxing of
97 // web content, which can be a security risk. 103 // web content, which can be a security risk.
98 bool single_process_mode; 104 bool single_process_mode;
99 105
106 // Custom network protocol handlers. These can be used to override URL
107 // fetching for different network schemes.
108 ProtocolHandlerMap protocol_handlers;
109
100 private: 110 private:
101 Options(int argc, const char** argv); 111 Options(int argc, const char** argv);
102 112
103 DISALLOW_COPY_AND_ASSIGN(Options); 113 DISALLOW_COPY_AND_ASSIGN(Options);
104 }; 114 };
105 115
106 class HeadlessBrowser::Options::Builder { 116 class HeadlessBrowser::Options::Builder {
107 public: 117 public:
108 Builder(int argc, const char** argv); 118 Builder(int argc, const char** argv);
109 Builder(); 119 Builder();
110 ~Builder(); 120 ~Builder();
111 121
112 Builder& SetUserAgent(const std::string& user_agent); 122 Builder& SetUserAgent(const std::string& user_agent);
113 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint); 123 Builder& EnableDevToolsServer(const net::IPEndPoint& endpoint);
114 Builder& SetMessagePump(base::MessagePump* message_pump); 124 Builder& SetMessagePump(base::MessagePump* message_pump);
115 Builder& SetProxyServer(const net::HostPortPair& proxy_server); 125 Builder& SetProxyServer(const net::HostPortPair& proxy_server);
116 Builder& SetHostResolverRules(const std::string& host_resolver_rules); 126 Builder& SetHostResolverRules(const std::string& host_resolver_rules);
117 Builder& SetSingleProcessMode(bool single_process_mode); 127 Builder& SetSingleProcessMode(bool single_process_mode);
128 Builder& SetProtocolHandlers(ProtocolHandlerMap protocol_handlers);
118 129
119 Options Build(); 130 Options Build();
120 131
121 private: 132 private:
122 Options options_; 133 Options options_;
123 134
124 DISALLOW_COPY_AND_ASSIGN(Builder); 135 DISALLOW_COPY_AND_ASSIGN(Builder);
125 }; 136 };
126 137
127 // Main entry point for running the headless browser. This function constructs 138 // Main entry point for running the headless browser. This function constructs
128 // the headless browser instance, passing it to the given 139 // the headless browser instance, passing it to the given
129 // |on_browser_start_callback| callback. Note that since this function executes 140 // |on_browser_start_callback| callback. Note that since this function executes
130 // the main loop, it will only return after HeadlessBrowser::Shutdown() is 141 // the main loop, it will only return after HeadlessBrowser::Shutdown() is
131 // called, returning the exit code for the process. 142 // called, returning the exit code for the process.
132 int HeadlessBrowserMain( 143 int HeadlessBrowserMain(
133 HeadlessBrowser::Options options, 144 HeadlessBrowser::Options options,
134 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); 145 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback);
135 146
136 } // namespace headless 147 } // namespace headless
137 148
138 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ 149 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698