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

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

Issue 2043603004: headless: Introduce a browser context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits 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
« no previous file with comments | « headless/lib/headless_web_contents_browsertest.cc ('k') | headless/public/headless_browser.cc » ('j') | 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 #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 #include <unordered_map>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "headless/public/headless_browser_context.h"
16 #include "headless/public/headless_export.h" 17 #include "headless/public/headless_export.h"
18 #include "headless/public/headless_web_contents.h"
17 #include "net/base/host_port_pair.h" 19 #include "net/base/host_port_pair.h"
18 #include "net/base/ip_endpoint.h" 20 #include "net/base/ip_endpoint.h"
19 #include "net/url_request/url_request_job_factory.h" 21 #include "net/url_request/url_request_job_factory.h"
20 22
21 namespace base { 23 namespace base {
22 class MessagePump; 24 class MessagePump;
23 class SingleThreadTaskRunner; 25 class SingleThreadTaskRunner;
24 } 26 }
25 27
26 namespace gfx { 28 namespace gfx {
27 class Size; 29 class Size;
28 } 30 }
29 31
30 namespace headless { 32 namespace headless {
31 class HeadlessWebContents;
32 33
33 // This class represents the global headless browser instance. To get a pointer 34 // This class represents the global headless browser instance. To get a pointer
34 // to one, call |HeadlessBrowserMain| to initiate the browser main loop. An 35 // to one, call |HeadlessBrowserMain| to initiate the browser main loop. An
35 // instance of |HeadlessBrowser| will be passed to the callback given to that 36 // instance of |HeadlessBrowser| will be passed to the callback given to that
36 // function. 37 // function.
37 class HEADLESS_EXPORT HeadlessBrowser { 38 class HEADLESS_EXPORT HeadlessBrowser {
38 public: 39 public:
39 struct Options; 40 struct Options;
40 41
41 // Create a new browser tab which navigates to |initial_url|. |size| is in 42 // Open a new tab. Returns a builder object which can be used to set
42 // physical pixels. 43 // properties for the new tab.
43 // We require the user to pass an initial URL to ensure that the renderer 44 virtual HeadlessWebContents::Builder CreateWebContentsBuilder() = 0;
44 // gets initialized and eventually becomes ready to be inspected. See 45
45 // HeadlessWebContents::Observer::DevToolsTargetReady. 46 // Deprecated. Use CreateWebContentsBuilder() instead.
46 virtual HeadlessWebContents* CreateWebContents(const GURL& initial_url, 47 virtual HeadlessWebContents* CreateWebContents(const GURL& initial_url,
47 const gfx::Size& size) = 0; 48 const gfx::Size& size) = 0;
48 49
49 virtual std::vector<HeadlessWebContents*> GetAllWebContents() = 0; 50 virtual std::vector<HeadlessWebContents*> GetAllWebContents() = 0;
50 51
51 // Returns a task runner for submitting work to the browser main thread. 52 // Returns a task runner for submitting work to the browser main thread.
52 virtual scoped_refptr<base::SingleThreadTaskRunner> BrowserMainThread() 53 virtual scoped_refptr<base::SingleThreadTaskRunner> BrowserMainThread()
53 const = 0; 54 const = 0;
54 55
55 // Returns a task runner for submitting work to the browser file thread. 56 // Returns a task runner for submitting work to the browser file thread.
56 virtual scoped_refptr<base::SingleThreadTaskRunner> BrowserFileThread() 57 virtual scoped_refptr<base::SingleThreadTaskRunner> BrowserFileThread()
57 const = 0; 58 const = 0;
58 59
59 // Requests browser to stop as soon as possible. |Run| will return as soon as 60 // Requests browser to stop as soon as possible. |Run| will return as soon as
60 // browser stops. 61 // browser stops.
61 virtual void Shutdown() = 0; 62 virtual void Shutdown() = 0;
62 63
64 // Create a new browser context, which can be used to isolate
65 // HeadlessWebContents from one another.
66 virtual HeadlessBrowserContext::Builder CreateBrowserContextBuilder() = 0;
67
63 protected: 68 protected:
64 HeadlessBrowser() {} 69 HeadlessBrowser() {}
65 virtual ~HeadlessBrowser() {} 70 virtual ~HeadlessBrowser() {}
66 71
67 private: 72 private:
68 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser); 73 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowser);
69 }; 74 };
70 75
71 using ProtocolHandlerMap = std::unordered_map< 76 using ProtocolHandlerMap = std::unordered_map<
72 std::string, 77 std::string,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // |on_browser_start_callback| callback. Note that since this function executes 150 // |on_browser_start_callback| callback. Note that since this function executes
146 // the main loop, it will only return after HeadlessBrowser::Shutdown() is 151 // the main loop, it will only return after HeadlessBrowser::Shutdown() is
147 // called, returning the exit code for the process. 152 // called, returning the exit code for the process.
148 int HeadlessBrowserMain( 153 int HeadlessBrowserMain(
149 HeadlessBrowser::Options options, 154 HeadlessBrowser::Options options,
150 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback); 155 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback);
151 156
152 } // namespace headless 157 } // namespace headless
153 158
154 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_ 159 #endif // HEADLESS_PUBLIC_HEADLESS_BROWSER_H_
OLDNEW
« no previous file with comments | « headless/lib/headless_web_contents_browsertest.cc ('k') | headless/public/headless_browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698