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