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_WEB_CONTENTS_IMPL_H_ | 5 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_ |
6 #define HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_ | 6 #define HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <unordered_map> | 11 #include <unordered_map> |
12 | 12 |
13 #include "content/public/browser/render_process_host_observer.h" | 13 #include "content/public/browser/render_process_host_observer.h" |
14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
15 #include "headless/public/headless_devtools_target.h" | 15 #include "headless/public/headless_devtools_target.h" |
16 #include "headless/public/headless_web_contents.h" | 16 #include "headless/public/headless_web_contents.h" |
17 | 17 |
18 namespace aura { | |
19 class Window; | |
20 } | |
21 | |
22 namespace content { | 18 namespace content { |
23 class DevToolsAgentHost; | 19 class DevToolsAgentHost; |
24 class WebContents; | 20 class WebContents; |
25 } | 21 } |
26 | 22 |
27 namespace gfx { | 23 namespace gfx { |
28 class Size; | 24 class Size; |
29 } | 25 } |
30 | 26 |
31 namespace headless { | 27 namespace headless { |
32 class HeadlessBrowserImpl; | 28 class HeadlessBrowserImpl; |
33 class WebContentsObserverAdapter; | 29 class WebContentsObserverAdapter; |
34 | 30 |
35 class HeadlessWebContentsImpl : public HeadlessWebContents, | 31 class HeadlessWebContentsImpl : public HeadlessWebContents, |
36 public HeadlessDevToolsTarget, | 32 public HeadlessDevToolsTarget, |
37 public content::RenderProcessHostObserver, | 33 public content::RenderProcessHostObserver, |
38 public content::WebContentsObserver { | 34 public content::WebContentsObserver { |
39 public: | 35 public: |
40 ~HeadlessWebContentsImpl() override; | 36 ~HeadlessWebContentsImpl() override; |
41 | 37 |
42 static HeadlessWebContentsImpl* From(HeadlessWebContents* web_contents); | 38 static HeadlessWebContentsImpl* From(HeadlessWebContents* web_contents); |
43 | 39 |
44 static std::unique_ptr<HeadlessWebContentsImpl> Create( | 40 static std::unique_ptr<HeadlessWebContentsImpl> Create( |
45 HeadlessWebContents::Builder* builder, | 41 HeadlessWebContents::Builder* builder); |
46 aura::Window* parent_window); | |
47 | 42 |
48 // Takes ownership of |web_contents|. | 43 // Takes ownership of |web_contents|. |
49 static std::unique_ptr<HeadlessWebContentsImpl> CreateFromWebContents( | 44 static std::unique_ptr<HeadlessWebContentsImpl> CreateFromWebContents( |
50 content::WebContents* web_contents, | 45 content::WebContents* web_contents, |
51 HeadlessBrowserContextImpl* browser_context); | 46 HeadlessBrowserContextImpl* browser_context); |
52 | 47 |
53 // HeadlessWebContents implementation: | 48 // HeadlessWebContents implementation: |
54 void AddObserver(Observer* observer) override; | 49 void AddObserver(Observer* observer) override; |
55 void RemoveObserver(Observer* observer) override; | 50 void RemoveObserver(Observer* observer) override; |
56 HeadlessDevToolsTarget* GetDevToolsTarget() override; | 51 HeadlessDevToolsTarget* GetDevToolsTarget() override; |
(...skipping 21 matching lines...) Expand all Loading... |
78 std::string GetDevToolsAgentHostId(); | 73 std::string GetDevToolsAgentHostId(); |
79 | 74 |
80 HeadlessBrowserImpl* browser() const; | 75 HeadlessBrowserImpl* browser() const; |
81 HeadlessBrowserContextImpl* browser_context() const; | 76 HeadlessBrowserContextImpl* browser_context() const; |
82 | 77 |
83 private: | 78 private: |
84 // Takes ownership of |web_contents|. | 79 // Takes ownership of |web_contents|. |
85 HeadlessWebContentsImpl(content::WebContents* web_contents, | 80 HeadlessWebContentsImpl(content::WebContents* web_contents, |
86 HeadlessBrowserContextImpl* browser_context); | 81 HeadlessBrowserContextImpl* browser_context); |
87 | 82 |
88 void InitializeScreen(aura::Window* parent_window, | 83 void InitializeScreen(const gfx::Size& initial_size); |
89 const gfx::Size& initial_size); | |
90 | 84 |
91 using MojoService = HeadlessWebContents::Builder::MojoService; | 85 using MojoService = HeadlessWebContents::Builder::MojoService; |
92 | 86 |
93 class Delegate; | 87 class Delegate; |
94 std::unique_ptr<Delegate> web_contents_delegate_; | 88 std::unique_ptr<Delegate> web_contents_delegate_; |
95 std::unique_ptr<content::WebContents> web_contents_; | 89 std::unique_ptr<content::WebContents> web_contents_; |
96 scoped_refptr<content::DevToolsAgentHost> agent_host_; | 90 scoped_refptr<content::DevToolsAgentHost> agent_host_; |
97 std::list<MojoService> mojo_services_; | 91 std::list<MojoService> mojo_services_; |
98 | 92 |
99 HeadlessBrowserContextImpl* browser_context_; // Not owned. | 93 HeadlessBrowserContextImpl* browser_context_; // Not owned. |
100 content::RenderProcessHost* render_process_host_; // Not owned. | 94 content::RenderProcessHost* render_process_host_; // Not owned. |
101 | 95 |
102 using ObserverMap = | 96 using ObserverMap = |
103 std::unordered_map<HeadlessWebContents::Observer*, | 97 std::unordered_map<HeadlessWebContents::Observer*, |
104 std::unique_ptr<WebContentsObserverAdapter>>; | 98 std::unique_ptr<WebContentsObserverAdapter>>; |
105 ObserverMap observer_map_; | 99 ObserverMap observer_map_; |
106 | 100 |
107 DISALLOW_COPY_AND_ASSIGN(HeadlessWebContentsImpl); | 101 DISALLOW_COPY_AND_ASSIGN(HeadlessWebContentsImpl); |
108 }; | 102 }; |
109 | 103 |
110 } // namespace headless | 104 } // namespace headless |
111 | 105 |
112 #endif // HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_ | 106 #endif // HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_ |
OLD | NEW |