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 <string> | 11 #include <string> |
12 #include <unordered_map> | 12 #include <unordered_map> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
| 15 #include "base/files/file_util.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/optional.h" |
16 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
18 #include "headless/lib/browser/headless_devtools_manager_delegate.h" | 20 #include "headless/lib/browser/headless_devtools_manager_delegate.h" |
| 21 #include "headless/lib/browser/headless_download_manager_delegate.h" |
19 #include "headless/lib/browser/headless_web_contents_impl.h" | 22 #include "headless/lib/browser/headless_web_contents_impl.h" |
20 #include "headless/public/headless_export.h" | 23 #include "headless/public/headless_export.h" |
21 | 24 |
22 namespace headless { | 25 namespace headless { |
23 | 26 |
24 class HeadlessBrowserContextImpl; | 27 class HeadlessBrowserContextImpl; |
25 class HeadlessBrowserMainParts; | 28 class HeadlessBrowserMainParts; |
26 | 29 |
27 // Exported for tests. | 30 // Exported for tests. |
28 class HEADLESS_EXPORT HeadlessBrowserImpl : public HeadlessBrowser, | 31 class HEADLESS_EXPORT HeadlessBrowserImpl : public HeadlessBrowser, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 HeadlessBrowserContext* CreateBrowserContext( | 72 HeadlessBrowserContext* CreateBrowserContext( |
70 HeadlessBrowserContext::Builder* builder); | 73 HeadlessBrowserContext::Builder* builder); |
71 // Close given |browser_context| and delete it | 74 // Close given |browser_context| and delete it |
72 // (all web contents associated with it go away too). | 75 // (all web contents associated with it go away too). |
73 void DestroyBrowserContext(HeadlessBrowserContextImpl* browser_context); | 76 void DestroyBrowserContext(HeadlessBrowserContextImpl* browser_context); |
74 | 77 |
75 HeadlessWebContentsImpl* GetWebContentsForWindowId(const int window_id); | 78 HeadlessWebContentsImpl* GetWebContentsForWindowId(const int window_id); |
76 | 79 |
77 base::WeakPtr<HeadlessBrowserImpl> GetWeakPtr(); | 80 base::WeakPtr<HeadlessBrowserImpl> GetWeakPtr(); |
78 | 81 |
| 82 // Set the download behaviour of the HeadlessDownloadManagerDelegate for all |
| 83 // current and future browser contexts. |
| 84 void SetDownloadBehavior( |
| 85 HeadlessDownloadManagerDelegate::DownloadBehavior behavior); |
| 86 |
| 87 // Set the download directory of the HeadlessDownloadManagerDelegate for all |
| 88 // current and future browser contexts. |
| 89 void SetDownloadDirectory(const base::FilePath& path); |
| 90 |
79 // All the methods that begin with Platform need to be implemented by the | 91 // All the methods that begin with Platform need to be implemented by the |
80 // platform specific headless implementation. | 92 // platform specific headless implementation. |
81 // Helper for one time initialization of application | 93 // Helper for one time initialization of application |
82 void PlatformInitialize(); | 94 void PlatformInitialize(); |
83 void PlatformCreateWindow(); | 95 void PlatformCreateWindow(); |
84 void PlatformInitializeWebContents(const gfx::Size& initial_size, | 96 void PlatformInitializeWebContents(const gfx::Size& initial_size, |
85 HeadlessWebContentsImpl* web_contents); | 97 HeadlessWebContentsImpl* web_contents); |
86 | 98 |
87 protected: | 99 protected: |
88 base::Callback<void(HeadlessBrowser*)> on_start_callback_; | 100 base::Callback<void(HeadlessBrowser*)> on_start_callback_; |
89 HeadlessBrowser::Options options_; | 101 HeadlessBrowser::Options options_; |
90 HeadlessBrowserMainParts* browser_main_parts_; // Not owned. | 102 HeadlessBrowserMainParts* browser_main_parts_; // Not owned. |
91 | 103 |
92 std::unordered_map<std::string, std::unique_ptr<HeadlessBrowserContextImpl>> | 104 std::unordered_map<std::string, std::unique_ptr<HeadlessBrowserContextImpl>> |
93 browser_contexts_; | 105 browser_contexts_; |
94 HeadlessBrowserContext* default_browser_context_; // Not owned. | 106 HeadlessBrowserContext* default_browser_context_; // Not owned. |
95 | 107 |
| 108 base::Optional<HeadlessDownloadManagerDelegate::DownloadBehavior> |
| 109 download_behavior_; |
| 110 base::Optional<base::FilePath> download_path_; |
| 111 |
96 scoped_refptr<content::DevToolsAgentHost> agent_host_; | 112 scoped_refptr<content::DevToolsAgentHost> agent_host_; |
97 | 113 |
98 base::WeakPtrFactory<HeadlessBrowserImpl> weak_ptr_factory_; | 114 base::WeakPtrFactory<HeadlessBrowserImpl> weak_ptr_factory_; |
99 | 115 |
100 private: | 116 private: |
101 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserImpl); | 117 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserImpl); |
102 }; | 118 }; |
103 | 119 |
104 } // namespace headless | 120 } // namespace headless |
105 | 121 |
106 #endif // HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_ | 122 #endif // HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_ |
OLD | NEW |