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_PUBLIC_HEADLESS_WEB_CONTENTS_H_ | 5 #ifndef HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
6 #define HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ | 6 #define HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/process/kill.h" | 14 #include "base/process/kill.h" |
15 #include "headless/public/headless_export.h" | 15 #include "headless/public/headless_export.h" |
16 #include "mojo/public/cpp/bindings/interface_request.h" | 16 #include "mojo/public/cpp/bindings/interface_request.h" |
17 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 | 19 |
20 namespace headless { | 20 namespace headless { |
21 class HeadlessBrowserContextImpl; | 21 class HeadlessBrowserContextImpl; |
22 class HeadlessBrowserImpl; | 22 class HeadlessBrowserImpl; |
23 class HeadlessDevToolsTarget; | 23 class HeadlessDevToolsTarget; |
| 24 class HeadlessTabSocket; |
24 | 25 |
25 // Class representing contents of a browser tab. Should be accessed from browser | 26 // Class representing contents of a browser tab. Should be accessed from browser |
26 // main thread. | 27 // main thread. |
27 class HEADLESS_EXPORT HeadlessWebContents { | 28 class HEADLESS_EXPORT HeadlessWebContents { |
28 public: | 29 public: |
29 class HEADLESS_EXPORT Builder; | 30 class HEADLESS_EXPORT Builder; |
30 | 31 |
31 virtual ~HeadlessWebContents() {} | 32 virtual ~HeadlessWebContents() {} |
32 | 33 |
33 class HEADLESS_EXPORT Observer { | 34 class HEADLESS_EXPORT Observer { |
(...skipping 30 matching lines...) Expand all Loading... |
64 virtual void RemoveObserver(Observer* observer) = 0; | 65 virtual void RemoveObserver(Observer* observer) = 0; |
65 | 66 |
66 // Return a DevTools target corresponding to this tab. Note that this method | 67 // Return a DevTools target corresponding to this tab. Note that this method |
67 // won't return a valid value until Observer::DevToolsTargetReady has been | 68 // won't return a valid value until Observer::DevToolsTargetReady has been |
68 // signaled. | 69 // signaled. |
69 virtual HeadlessDevToolsTarget* GetDevToolsTarget() = 0; | 70 virtual HeadlessDevToolsTarget* GetDevToolsTarget() = 0; |
70 | 71 |
71 // Close this page. |HeadlessWebContents| object will be destroyed. | 72 // Close this page. |HeadlessWebContents| object will be destroyed. |
72 virtual void Close() = 0; | 73 virtual void Close() = 0; |
73 | 74 |
| 75 // Returns the headless tab socket for JS -> C++ if one was created. |
| 76 virtual HeadlessTabSocket* GetHeadlessTabSocket() const = 0; |
| 77 |
74 private: | 78 private: |
75 friend class HeadlessWebContentsImpl; | 79 friend class HeadlessWebContentsImpl; |
76 HeadlessWebContents() {} | 80 HeadlessWebContents() {} |
77 | 81 |
78 DISALLOW_COPY_AND_ASSIGN(HeadlessWebContents); | 82 DISALLOW_COPY_AND_ASSIGN(HeadlessWebContents); |
79 }; | 83 }; |
80 | 84 |
81 class HEADLESS_EXPORT HeadlessWebContents::Builder { | 85 class HEADLESS_EXPORT HeadlessWebContents::Builder { |
82 public: | 86 public: |
83 ~Builder(); | 87 ~Builder(); |
84 Builder(Builder&&); | 88 Builder(Builder&&); |
85 | 89 |
86 // Set an initial URL to ensure that the renderer gets initialized and | 90 // Set an initial URL to ensure that the renderer gets initialized and |
87 // eventually becomes ready to be inspected. See | 91 // eventually becomes ready to be inspected. See |
88 // HeadlessWebContents::Observer::DevToolsTargetReady. The default URL is | 92 // HeadlessWebContents::Observer::DevToolsTargetReady. The default URL is |
89 // about:blank. | 93 // about:blank. |
90 Builder& SetInitialURL(const GURL& initial_url); | 94 Builder& SetInitialURL(const GURL& initial_url); |
91 | 95 |
92 // Specify the initial window size (default is configured in browser options). | 96 // Specify the initial window size (default is configured in browser options). |
93 Builder& SetWindowSize(const gfx::Size& size); | 97 Builder& SetWindowSize(const gfx::Size& size); |
94 | 98 |
95 // Specify an embedder provided Mojo service to be installed. The | 99 // DEPRECATED. Specify an embedder provided Mojo service to be installed. The |
96 // |service_factory| callback is called on demand by Mojo to instantiate the | 100 // |service_factory| callback is called on demand by Mojo to instantiate the |
97 // service if a client asks for it. | 101 // service if a client asks for it. |
| 102 // TODO(alexclarke): Remove AddMojoService. |
98 template <typename Interface> | 103 template <typename Interface> |
99 Builder& AddMojoService( | 104 Builder& AddMojoService( |
100 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& | 105 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& |
101 service_factory) { | 106 service_factory) { |
102 return AddMojoService( | 107 return AddMojoService( |
103 Interface::Name_, | 108 Interface::Name_, |
104 base::Bind(&Builder::ForwardToServiceFactory<Interface>, | 109 base::Bind(&Builder::ForwardToServiceFactory<Interface>, |
105 service_factory)); | 110 service_factory)); |
106 } | 111 } |
107 Builder& AddMojoService(const std::string& service_name, | 112 Builder& AddMojoService(const std::string& service_name, |
108 const base::Callback<void( | 113 const base::Callback<void( |
109 mojo::ScopedMessagePipeHandle)>& service_factory); | 114 mojo::ScopedMessagePipeHandle)>& service_factory); |
110 | 115 |
| 116 // Whether or not a headless tab socket should be created, to allow JS -> C++ |
| 117 // embedder communications. |
| 118 Builder& CreateTabSocket(bool create_tab_socket); |
| 119 |
111 // The returned object is owned by HeadlessBrowser. Call | 120 // The returned object is owned by HeadlessBrowser. Call |
112 // HeadlessWebContents::Close() to dispose it. | 121 // HeadlessWebContents::Close() to dispose it. |
113 HeadlessWebContents* Build(); | 122 HeadlessWebContents* Build(); |
114 | 123 |
115 private: | 124 private: |
116 friend class HeadlessBrowserImpl; | 125 friend class HeadlessBrowserImpl; |
117 friend class HeadlessBrowserContextImpl; | 126 friend class HeadlessBrowserContextImpl; |
118 friend class HeadlessWebContentsImpl; | 127 friend class HeadlessWebContentsImpl; |
119 | 128 |
120 explicit Builder(HeadlessBrowserContextImpl* browser_context); | 129 explicit Builder(HeadlessBrowserContextImpl* browser_context); |
(...skipping 18 matching lines...) Expand all Loading... |
139 | 148 |
140 private: | 149 private: |
141 DISALLOW_COPY_AND_ASSIGN(MojoService); | 150 DISALLOW_COPY_AND_ASSIGN(MojoService); |
142 }; | 151 }; |
143 | 152 |
144 HeadlessBrowserContextImpl* browser_context_; | 153 HeadlessBrowserContextImpl* browser_context_; |
145 | 154 |
146 GURL initial_url_ = GURL("about:blank"); | 155 GURL initial_url_ = GURL("about:blank"); |
147 gfx::Size window_size_; | 156 gfx::Size window_size_; |
148 std::list<MojoService> mojo_services_; | 157 std::list<MojoService> mojo_services_; |
| 158 bool create_tab_socket_ = false; |
149 | 159 |
150 DISALLOW_COPY_AND_ASSIGN(Builder); | 160 DISALLOW_COPY_AND_ASSIGN(Builder); |
151 }; | 161 }; |
152 | 162 |
153 } // namespace headless | 163 } // namespace headless |
154 | 164 |
155 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ | 165 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
OLD | NEW |