Chromium Code Reviews| 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/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "headless/lib/browser/headless_devtools_manager_delegate.h" | 18 #include "headless/lib/browser/headless_devtools_manager_delegate.h" |
| 19 #include "headless/lib/browser/headless_web_contents_impl.h" | 19 #include "headless/lib/browser/headless_web_contents_impl.h" |
| 20 #include "headless/public/headless_export.h" | 20 #include "headless/public/headless_export.h" |
| 21 | 21 |
| 22 namespace headless { | 22 namespace headless { |
| 23 | 23 |
| 24 class HeadlessBrowserContextImpl; | 24 class HeadlessBrowserContextImpl; |
| 25 class HeadlessBrowserMainParts; | 25 class HeadlessBrowserMainParts; |
| 26 | 26 |
| 27 class HeadlessBrowserWindow { | |
| 28 public: | |
| 29 explicit HeadlessBrowserWindow(gfx::Size size); | |
| 30 gfx::Rect bounds() const { return bounds_; } | |
| 31 std::string state() const { return state_; } | |
|
Sami
2017/05/22 16:30:57
nit: const ref
| |
| 32 void set_bounds(gfx::Rect bounds) { bounds_ = bounds; } | |
| 33 void set_state(std::string state); | |
|
Sami
2017/05/22 16:30:57
nit: const ref
| |
| 34 | |
| 35 private: | |
| 36 gfx::Rect bounds_; | |
| 37 std::string state_; | |
| 38 | |
| 39 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserWindow); | |
| 40 }; | |
| 41 | |
| 27 // Exported for tests. | 42 // Exported for tests. |
| 28 class HEADLESS_EXPORT HeadlessBrowserImpl : public HeadlessBrowser, | 43 class HEADLESS_EXPORT HeadlessBrowserImpl : public HeadlessBrowser, |
| 29 public HeadlessDevToolsTarget { | 44 public HeadlessDevToolsTarget { |
| 30 public: | 45 public: |
| 31 HeadlessBrowserImpl( | 46 HeadlessBrowserImpl( |
| 32 const base::Callback<void(HeadlessBrowser*)>& on_start_callback, | 47 const base::Callback<void(HeadlessBrowser*)>& on_start_callback, |
| 33 HeadlessBrowser::Options options); | 48 HeadlessBrowser::Options options); |
| 34 ~HeadlessBrowserImpl() override; | 49 ~HeadlessBrowserImpl() override; |
| 35 | 50 |
| 36 // HeadlessBrowser implementation: | 51 // HeadlessBrowser implementation: |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 58 void ForceAttachClient(HeadlessDevToolsClient* client) override; | 73 void ForceAttachClient(HeadlessDevToolsClient* client) override; |
| 59 void DetachClient(HeadlessDevToolsClient* client) override; | 74 void DetachClient(HeadlessDevToolsClient* client) override; |
| 60 bool IsAttached() override; | 75 bool IsAttached() override; |
| 61 | 76 |
| 62 void set_browser_main_parts(HeadlessBrowserMainParts* browser_main_parts); | 77 void set_browser_main_parts(HeadlessBrowserMainParts* browser_main_parts); |
| 63 HeadlessBrowserMainParts* browser_main_parts() const; | 78 HeadlessBrowserMainParts* browser_main_parts() const; |
| 64 | 79 |
| 65 void RunOnStartCallback(); | 80 void RunOnStartCallback(); |
| 66 | 81 |
| 67 HeadlessBrowser::Options* options() { return &options_; } | 82 HeadlessBrowser::Options* options() { return &options_; } |
| 83 HeadlessBrowserWindow* window() { return &window_; } | |
| 68 | 84 |
| 69 HeadlessBrowserContext* CreateBrowserContext( | 85 HeadlessBrowserContext* CreateBrowserContext( |
| 70 HeadlessBrowserContext::Builder* builder); | 86 HeadlessBrowserContext::Builder* builder); |
| 71 // Close given |browser_context| and delete it | 87 // Close given |browser_context| and delete it |
| 72 // (all web contents associated with it go away too). | 88 // (all web contents associated with it go away too). |
| 73 void DestroyBrowserContext(HeadlessBrowserContextImpl* browser_context); | 89 void DestroyBrowserContext(HeadlessBrowserContextImpl* browser_context); |
| 74 | 90 |
| 75 base::WeakPtr<HeadlessBrowserImpl> GetWeakPtr(); | 91 base::WeakPtr<HeadlessBrowserImpl> GetWeakPtr(); |
| 76 | 92 |
| 77 // All the methods that begin with Platform need to be implemented by the | 93 // All the methods that begin with Platform need to be implemented by the |
| 78 // platform specific headless implementation. | 94 // platform specific headless implementation. |
| 79 // Helper for one time initialization of application | 95 // Helper for one time initialization of application |
| 80 void PlatformInitialize(); | 96 void PlatformInitialize(); |
| 81 void PlatformCreateWindow(); | 97 void PlatformCreateWindow(); |
| 82 void PlatformInitializeWebContents(const gfx::Size& initial_size, | 98 void PlatformInitializeWebContents(const gfx::Size& initial_window_size, |
| 99 const gfx::Size& screen_size, | |
| 83 HeadlessWebContentsImpl* web_contents); | 100 HeadlessWebContentsImpl* web_contents); |
| 84 | 101 |
| 85 protected: | 102 protected: |
| 86 base::Callback<void(HeadlessBrowser*)> on_start_callback_; | 103 base::Callback<void(HeadlessBrowser*)> on_start_callback_; |
| 87 HeadlessBrowser::Options options_; | 104 HeadlessBrowser::Options options_; |
| 105 HeadlessBrowserWindow window_; | |
| 106 | |
| 88 HeadlessBrowserMainParts* browser_main_parts_; // Not owned. | 107 HeadlessBrowserMainParts* browser_main_parts_; // Not owned. |
| 89 | 108 |
| 90 std::unordered_map<std::string, std::unique_ptr<HeadlessBrowserContextImpl>> | 109 std::unordered_map<std::string, std::unique_ptr<HeadlessBrowserContextImpl>> |
| 91 browser_contexts_; | 110 browser_contexts_; |
| 92 HeadlessBrowserContext* default_browser_context_; // Not owned. | 111 HeadlessBrowserContext* default_browser_context_; // Not owned. |
| 93 | 112 |
| 94 scoped_refptr<content::DevToolsAgentHost> agent_host_; | 113 scoped_refptr<content::DevToolsAgentHost> agent_host_; |
| 95 | 114 |
| 96 base::WeakPtrFactory<HeadlessBrowserImpl> weak_ptr_factory_; | 115 base::WeakPtrFactory<HeadlessBrowserImpl> weak_ptr_factory_; |
| 97 | 116 |
| 98 private: | 117 private: |
| 99 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserImpl); | 118 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserImpl); |
| 100 }; | 119 }; |
| 101 | 120 |
| 102 } // namespace headless | 121 } // namespace headless |
| 103 | 122 |
| 104 #endif // HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_ | 123 #endif // HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_ |
| OLD | NEW |