Chromium Code Reviews| Index: headless/public/headless_browser.h |
| diff --git a/headless/public/headless_browser.h b/headless/public/headless_browser.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..224d729ee12ec2701ef5029c52b052de6f38e7d1 |
| --- /dev/null |
| +++ b/headless/public/headless_browser.h |
| @@ -0,0 +1,114 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ |
| +#define HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "headless/public/headless_export.h" |
| + |
| +namespace base { |
| +class SingleThreadTaskRunner; |
| + |
| +namespace trace_event { |
| +class TraceConfig; |
| +} |
| +} |
| + |
| +namespace gfx { |
| +class Size; |
| +} |
| + |
| +namespace net { |
| +class URLRequestContextGetter; |
| +} |
| + |
| +namespace headless { |
| +class WebContents; |
| + |
| +class HEADLESS_EXPORT HeadlessBrowser { |
| + public: |
| + static HeadlessBrowser* Get(); |
| + |
| + struct Options; |
| + |
| + // Main routine for running browser. |
| + // Takes command line args and callback to run as soon as browser starts. |
| + static int Run( |
| + const Options& options, |
| + const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); |
| + |
| + // Create a new browser tab. |
| + virtual scoped_ptr<WebContents> CreateWebContents(const gfx::Size& size) = 0; |
| + |
| + virtual scoped_refptr<base::SingleThreadTaskRunner> BrowserMainThread() = 0; |
| + virtual scoped_refptr<base::SingleThreadTaskRunner> RendererMainThread() = 0; |
| + |
| + // Requests browser to stop as soon as possible. |
| + // |Run| will return as soon as browser stops. |
| + virtual void Stop() = 0; |
| + |
| + virtual void StartTracing(const base::trace_event::TraceConfig& trace_config, |
| + const base::Closure& on_tracing_started) = 0; |
| + virtual void StopTracing(const std::string& log_file_name, |
| + const base::Closure& on_tracing_stopped) = 0; |
| + |
| + protected: |
| + virtual ~HeadlessBrowser() {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser); |
| +}; |
| + |
| +struct HeadlessBrowser::Options { |
| + Options(Options&&); |
|
alex clarke (OOO till 29th)
2015/12/01 20:07:30
Do we actually need an explicit move and assignmen
altimin
2015/12/02 12:44:07
Thanks for the remark.
The reason behind explicit
|
| + Options& operator=(Options&&) = default; |
| + ~Options(); |
| + |
| + class Builder; |
| + |
| + // Command line options to be passed to browser. |
| + int argc; |
| + const char** argv; |
| + |
| + std::string user_agent; |
| + |
| + static const int kInvalidPort = -1; |
| + // If not null, create start devtools for remote debugging |
| + // on specified port. |
| + int devtools_http_port; |
| + |
| + // Optional URLRequestContextGetter for customizing network stack. |
| + scoped_refptr<net::URLRequestContextGetter> url_request_context_getter; |
| + |
| + private: |
| + Options(int argc, const char** argv); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Options); |
|
alex clarke (OOO till 29th)
2015/12/01 20:07:30
It feels a bit odd to use this macro and also defi
altimin
2015/12/02 12:44:07
Done.
|
| +}; |
| + |
| +class HeadlessBrowser::Options::Builder { |
| + public: |
| + Builder(int argc, const char** argv); |
| + ~Builder(); |
| + |
| + Builder& SetUserAgent(const std::string& user_agent); |
| + Builder& EnableDevToolsServer(int port); |
| + Builder& SetURLRequestContextGetter( |
| + scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); |
| + |
| + Options Build(); |
| + |
| + private: |
| + Options options_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Builder); |
|
Sami
2015/12/02 13:37:14
Is there a reason we couldn't keep this?
altimin
2015/12/02 13:43:41
My bad, I wanted to remove this from Options.
|
| +}; |
| + |
| +} // namespace headless |
| + |
| +#endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ |