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

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

Issue 1674263002: headless: Initial headless embedder API implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added navigation test. Created 4 years, 10 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 <string>
9
8 #include "base/callback.h" 10 #include "base/callback.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
12 #include "headless/public/headless_export.h" 14 #include "headless/public/headless_export.h"
15 #include "net/url_request/url_request_context_getter.h"
13 16
14 namespace base { 17 namespace base {
18 class MessagePump;
15 class SingleThreadTaskRunner; 19 class SingleThreadTaskRunner;
16 20
17 namespace trace_event { 21 namespace trace_event {
18 class TraceConfig; 22 class TraceConfig;
19 } 23 }
20 } 24 }
21 25
22 namespace gfx { 26 namespace gfx {
23 class Size; 27 class Size;
24 } 28 }
25 29
26 namespace net { 30 namespace net {
27 class URLRequestContextGetter; 31 class URLRequestContextGetter;
28 } 32 }
29 33
30 namespace headless { 34 namespace headless {
31 class WebContents; 35 class HeadlessWebContents;
32 36
33 class HEADLESS_EXPORT HeadlessBrowser { 37 class HEADLESS_EXPORT HeadlessBrowser {
34 public: 38 public:
35 static HeadlessBrowser* Get();
36
37 struct Options; 39 struct Options;
38 40
39 // Main routine for running browser. 41 // Main routine for running browser.
40 // Takes command line args and callback to run as soon as browser starts. 42 // Takes command line args and callback to run as soon as browser starts.
41 static int Run( 43 using StartCallback = base::Callback<void(HeadlessBrowser*)>;
42 const Options& options, 44 static int Run(const Options& options,
43 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); 45 const StartCallback& on_browser_start_callback);
44 46
45 // Create a new browser tab. 47 // Create a new browser tab. |size| is in physical pixels.
46 virtual scoped_ptr<WebContents> CreateWebContents(const gfx::Size& size) = 0; 48 virtual scoped_ptr<HeadlessWebContents> CreateWebContents(
49 const gfx::Size& size) = 0;
47 50
48 virtual scoped_refptr<base::SingleThreadTaskRunner> BrowserMainThread() = 0; 51 virtual scoped_refptr<base::SingleThreadTaskRunner> BrowserMainThread() = 0;
49 virtual scoped_refptr<base::SingleThreadTaskRunner> RendererMainThread() = 0; 52 virtual scoped_refptr<base::SingleThreadTaskRunner> RendererMainThread() = 0;
50 53
51 // Requests browser to stop as soon as possible. 54 // Requests browser to stop as soon as possible.
52 // |Run| will return as soon as browser stops. 55 // |Run| will return as soon as browser stops.
53 virtual void Stop() = 0; 56 virtual void Stop() = 0;
54 57
55 virtual void StartTracing(const base::trace_event::TraceConfig& trace_config, 58 virtual void StartTracing(const base::trace_event::TraceConfig& trace_config,
56 const base::Closure& on_tracing_started) = 0; 59 const base::Closure& on_tracing_started) = 0;
57 virtual void StopTracing(const std::string& log_file_name, 60 virtual void StopTracing(const std::string& log_file_name,
58 const base::Closure& on_tracing_stopped) = 0; 61 const base::Closure& on_tracing_stopped) = 0;
59 62
60 protected: 63 protected:
64 HeadlessBrowser() {}
61 virtual ~HeadlessBrowser() {} 65 virtual ~HeadlessBrowser() {}
62 66
63 private: 67 private:
64 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser); 68 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser);
65 }; 69 };
66 70
71 // Embedding API overrides for the headless browser.
67 struct HeadlessBrowser::Options { 72 struct HeadlessBrowser::Options {
68 ~Options(); 73 ~Options();
69 74
70 class Builder; 75 class Builder;
71 76
72 // Command line options to be passed to browser. 77 // Command line options to be passed to browser.
73 int argc; 78 int argc;
74 const char** argv; 79 const char** argv;
75 80
76 std::string user_agent; 81 std::string user_agent;
77 std::string navigator_platform; 82 std::string navigator_platform;
78 83
79 static const int kInvalidPort = -1; 84 static const int kInvalidPort = -1;
80 // If not null, create start devtools for remote debugging
81 // on specified port.
82 int devtools_http_port; 85 int devtools_http_port;
83 86
84 // Optional URLRequestContextGetter for customizing network stack. 87 // Optional URLRequestContextGetter for customizing network stack. Allows
85 // Allows overriding: 88 // overriding, e.g.:
86 // - Cookie storage 89 // - Cookie storage
87 // - HTTP cache 90 // - HTTP cache
88 // - SSL config 91 // - SSL config
89 // - Proxy service 92 // - Proxy service
93 //
94 // See HeadlessNetwork for more details.
90 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter; 95 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter;
91 96
92 scoped_ptr<base::MessagePump> message_pump; 97 // Optional message pump that overrides the default. Must outlive the browser.
98 base::MessagePump* message_pump;
93 99
94 private: 100 private:
95 Options(int argc, const char** argv); 101 Options(int argc, const char** argv);
96 }; 102 };
97 103
98 class HeadlessBrowser::Options::Builder { 104 class HeadlessBrowser::Options::Builder {
99 public: 105 public:
100 Builder(int argc, const char** argv); 106 Builder(int argc, const char** argv);
101 ~Builder(); 107 ~Builder();
102 108
103 Builder& SetUserAgent(const std::string& user_agent); 109 Builder& SetUserAgent(const std::string& user_agent);
104 Builder& EnableDevToolsServer(int port); 110 Builder& EnableDevToolsServer(int port);
105 Builder& SetURLRequestContextGetter( 111 Builder& SetURLRequestContextGetter(
106 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); 112 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
113 Builder& SetMessagePump(base::MessagePump* message_pump);
107 114
108 Options Build(); 115 Options Build();
109 116
110 private: 117 private:
111 Options options_; 118 Options options_;
112 119
113 DISALLOW_COPY_AND_ASSIGN(Builder); 120 DISALLOW_COPY_AND_ASSIGN(Builder);
114 }; 121 };
115 122
116 } // namespace headless 123 } // namespace headless
117 124
118 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ 125 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698