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 "base/callback.h" | 8 #include <list> |
| 9 |
| 10 #include "base/bind.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "headless/public/headless_export.h" | 12 #include "headless/public/headless_export.h" |
| 13 #include "mojo/public/cpp/bindings/interface_request.h" |
11 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
12 #include "url/gurl.h" | 15 #include "url/gurl.h" |
13 | 16 |
14 namespace headless { | 17 namespace headless { |
15 class HeadlessBrowserContext; | 18 class HeadlessBrowserContext; |
16 class HeadlessBrowserImpl; | 19 class HeadlessBrowserImpl; |
17 class HeadlessDevToolsTarget; | 20 class HeadlessDevToolsTarget; |
18 | 21 |
19 // Class representing contents of a browser tab. Should be accessed from browser | 22 // Class representing contents of a browser tab. Should be accessed from browser |
20 // main thread. | 23 // main thread. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 78 |
76 // Specify the initial window size (default is 800x600). | 79 // Specify the initial window size (default is 800x600). |
77 Builder& SetWindowSize(const gfx::Size& size); | 80 Builder& SetWindowSize(const gfx::Size& size); |
78 | 81 |
79 // Set a browser context for storing session data (e.g., cookies, cache, local | 82 // Set a browser context for storing session data (e.g., cookies, cache, local |
80 // storage) for the tab. Several tabs can share the same browser context. If | 83 // storage) for the tab. Several tabs can share the same browser context. If |
81 // unset, the default browser context will be used. The browser context must | 84 // unset, the default browser context will be used. The browser context must |
82 // outlive this HeadlessWebContents. | 85 // outlive this HeadlessWebContents. |
83 Builder& SetBrowserContext(HeadlessBrowserContext* browser_context); | 86 Builder& SetBrowserContext(HeadlessBrowserContext* browser_context); |
84 | 87 |
| 88 // Specify an embedder provided Mojo service to be installed. The |
| 89 // |service_factory| callback is called on demand by Mojo to instantiate the |
| 90 // service if a client asks for it. |
| 91 template <typename Interface> |
| 92 Builder& AddMojoService( |
| 93 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& |
| 94 service_factory) { |
| 95 return AddMojoService( |
| 96 Interface::Name_, |
| 97 base::Bind(&Builder::ForwardToServiceFactory<Interface>, |
| 98 service_factory)); |
| 99 } |
| 100 Builder& AddMojoService(const std::string& service_name, |
| 101 const base::Callback<void( |
| 102 mojo::ScopedMessagePipeHandle)>& service_factory); |
| 103 |
| 104 // Specify JS mojo module bindings to be installed, one per mojom file. |
| 105 // Note a single mojom file could potentially define many interfaces. |
| 106 // |mojom_name| the name including path of the .mojom file. |
| 107 // |js_bindings| compiletime generated javascript bindings. Typically loaded |
| 108 // from gen/path/name.mojom.js. |
| 109 Builder& AddJsMojoBindings(const std::string& mojom_name, |
| 110 const std::string& js_bindings); |
| 111 |
85 // The returned object is owned by HeadlessBrowser. Call | 112 // The returned object is owned by HeadlessBrowser. Call |
86 // HeadlessWebContents::Close() to dispose it. | 113 // HeadlessWebContents::Close() to dispose it. |
87 HeadlessWebContents* Build(); | 114 HeadlessWebContents* Build(); |
88 | 115 |
89 private: | 116 private: |
90 friend class HeadlessBrowserImpl; | 117 friend class HeadlessBrowserImpl; |
91 friend class HeadlessWebContentsImpl; | 118 friend class HeadlessWebContentsImpl; |
92 | 119 |
| 120 template <typename Interface> |
| 121 static void ForwardToServiceFactory( |
| 122 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& |
| 123 service_factory, |
| 124 mojo::ScopedMessagePipeHandle handle) { |
| 125 service_factory.Run(mojo::MakeRequest<Interface>(std::move(handle))); |
| 126 } |
| 127 |
| 128 struct MojoService { |
| 129 MojoService(); |
| 130 MojoService(const std::string& service_name, |
| 131 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& |
| 132 service_factory); |
| 133 ~MojoService(); |
| 134 |
| 135 std::string service_name; |
| 136 base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory; |
| 137 |
| 138 private: |
| 139 DISALLOW_COPY_AND_ASSIGN(MojoService); |
| 140 }; |
| 141 |
| 142 struct MojoBindings { |
| 143 MojoBindings(); |
| 144 MojoBindings(const std::string& mojom_name, const std::string& js_bindings); |
| 145 ~MojoBindings(); |
| 146 |
| 147 std::string mojom_name; |
| 148 std::string js_bindings; |
| 149 |
| 150 private: |
| 151 DISALLOW_COPY_AND_ASSIGN(MojoBindings); |
| 152 }; |
| 153 |
93 explicit Builder(HeadlessBrowserImpl* browser); | 154 explicit Builder(HeadlessBrowserImpl* browser); |
94 | 155 |
95 HeadlessBrowserImpl* browser_; | 156 HeadlessBrowserImpl* browser_; |
96 GURL initial_url_ = GURL("about:blank"); | 157 GURL initial_url_ = GURL("about:blank"); |
97 gfx::Size window_size_ = gfx::Size(800, 600); | 158 gfx::Size window_size_ = gfx::Size(800, 600); |
98 HeadlessBrowserContext* browser_context_; | 159 HeadlessBrowserContext* browser_context_; |
| 160 std::list<MojoService> mojo_services_; |
| 161 std::list<MojoBindings> mojo_bindings_; |
99 | 162 |
100 DISALLOW_COPY_AND_ASSIGN(Builder); | 163 DISALLOW_COPY_AND_ASSIGN(Builder); |
101 }; | 164 }; |
102 | 165 |
103 } // namespace headless | 166 } // namespace headless |
104 | 167 |
105 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ | 168 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
OLD | NEW |