OLD | NEW |
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_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_ | 5 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_ |
6 #define HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_ | 6 #define HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_ |
7 | 7 |
8 #include "headless/public/headless_browser.h" | 8 #include "headless/public/headless_browser.h" |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
| 11 #include <unordered_map> |
11 | 12 |
12 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
13 #include "headless/lib/browser/headless_web_contents_impl.h" | 14 #include "headless/lib/browser/headless_web_contents_impl.h" |
14 | 15 |
15 namespace aura { | 16 namespace aura { |
16 class WindowTreeHost; | 17 class WindowTreeHost; |
| 18 |
| 19 namespace client { |
| 20 class WindowTreeClient; |
| 21 } |
17 } | 22 } |
18 | 23 |
19 namespace headless { | 24 namespace headless { |
20 | 25 |
21 class HeadlessBrowserContext; | 26 class HeadlessBrowserContext; |
22 class HeadlessBrowserMainParts; | 27 class HeadlessBrowserMainParts; |
23 | 28 |
24 class HeadlessBrowserImpl : public HeadlessBrowser { | 29 class HeadlessBrowserImpl : public HeadlessBrowser { |
25 public: | 30 public: |
26 HeadlessBrowserImpl( | 31 HeadlessBrowserImpl( |
27 const base::Callback<void(HeadlessBrowser*)>& on_start_callback, | 32 const base::Callback<void(HeadlessBrowser*)>& on_start_callback, |
28 const HeadlessBrowser::Options& options); | 33 const HeadlessBrowser::Options& options); |
29 ~HeadlessBrowserImpl() override; | 34 ~HeadlessBrowserImpl() override; |
30 | 35 |
31 // HeadlessBrowser implementation: | 36 // HeadlessBrowser implementation: |
32 std::unique_ptr<HeadlessWebContents> CreateWebContents( | 37 HeadlessWebContents* CreateWebContents(const GURL& initial_url, |
33 const GURL& initial_url, | 38 const gfx::Size& size) override; |
34 const gfx::Size& size) override; | |
35 scoped_refptr<base::SingleThreadTaskRunner> BrowserMainThread() | 39 scoped_refptr<base::SingleThreadTaskRunner> BrowserMainThread() |
36 const override; | 40 const override; |
37 | 41 |
38 void Shutdown() override; | 42 void Shutdown() override; |
39 | 43 |
| 44 std::vector<HeadlessWebContents*> GetAllWebContents() override; |
| 45 |
40 void set_browser_main_parts(HeadlessBrowserMainParts* browser_main_parts); | 46 void set_browser_main_parts(HeadlessBrowserMainParts* browser_main_parts); |
41 HeadlessBrowserMainParts* browser_main_parts() const; | 47 HeadlessBrowserMainParts* browser_main_parts() const; |
42 | 48 |
43 HeadlessBrowserContext* browser_context() const; | 49 HeadlessBrowserContext* browser_context() const; |
44 | 50 |
45 void RunOnStartCallback(); | 51 void RunOnStartCallback(); |
46 | 52 |
47 const HeadlessBrowser::Options& options() const { return options_; } | 53 const HeadlessBrowser::Options& options() const { return options_; } |
48 | 54 |
| 55 HeadlessWebContentsImpl* RegisterWebContents( |
| 56 std::unique_ptr<HeadlessWebContentsImpl> web_contents); |
| 57 |
| 58 // Close given |web_contents| and delete it. |
| 59 void DestroyWebContents(HeadlessWebContentsImpl* web_contents); |
| 60 |
49 // Customize the options used by this headless browser instance. Note that | 61 // Customize the options used by this headless browser instance. Note that |
50 // options which take effect before the message loop has been started (e.g., | 62 // options which take effect before the message loop has been started (e.g., |
51 // custom message pumps) cannot be set via this method. | 63 // custom message pumps) cannot be set via this method. |
52 void SetOptionsForTesting(const HeadlessBrowser::Options& options); | 64 void SetOptionsForTesting(const HeadlessBrowser::Options& options); |
53 | 65 |
54 protected: | 66 protected: |
55 base::Callback<void(HeadlessBrowser*)> on_start_callback_; | 67 base::Callback<void(HeadlessBrowser*)> on_start_callback_; |
56 HeadlessBrowser::Options options_; | 68 HeadlessBrowser::Options options_; |
57 HeadlessBrowserMainParts* browser_main_parts_; // Not owned. | 69 HeadlessBrowserMainParts* browser_main_parts_; // Not owned. |
58 std::unique_ptr<aura::WindowTreeHost> window_tree_host_; | 70 std::unique_ptr<aura::WindowTreeHost> window_tree_host_; |
| 71 std::unique_ptr<aura::client::WindowTreeClient> window_tree_client_; |
| 72 |
| 73 std::unordered_map<HeadlessWebContents*, std::unique_ptr<HeadlessWebContents>> |
| 74 web_contents_; |
59 | 75 |
60 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserImpl); | 76 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserImpl); |
61 }; | 77 }; |
62 | 78 |
63 } // namespace headless | 79 } // namespace headless |
64 | 80 |
65 #endif // HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_ | 81 #endif // HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_ |
OLD | NEW |