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> |
| 9 |
8 #include "base/callback.h" | 10 #include "base/callback.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 |
85 // The returned object is owned by HeadlessBrowser. Call | 104 // The returned object is owned by HeadlessBrowser. Call |
86 // HeadlessWebContents::Close() to dispose it. | 105 // HeadlessWebContents::Close() to dispose it. |
87 HeadlessWebContents* Build(); | 106 HeadlessWebContents* Build(); |
88 | 107 |
89 private: | 108 private: |
90 friend class HeadlessBrowserImpl; | 109 friend class HeadlessBrowserImpl; |
91 friend class HeadlessWebContentsImpl; | 110 friend class HeadlessWebContentsImpl; |
92 | 111 |
| 112 template <typename Interface> |
| 113 static void ForwardToServiceFactory( |
| 114 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& |
| 115 service_factory, |
| 116 mojo::ScopedMessagePipeHandle handle) { |
| 117 service_factory.Run(mojo::MakeRequest<Interface>(std::move(handle))); |
| 118 } |
| 119 |
| 120 struct MojoService { |
| 121 MojoService(); |
| 122 MojoService(const std::string& service_name, |
| 123 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& |
| 124 service_factory); |
| 125 ~MojoService(); |
| 126 |
| 127 std::string service_name; |
| 128 base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory; |
| 129 |
| 130 private: |
| 131 DISALLOW_COPY_AND_ASSIGN(MojoService); |
| 132 }; |
| 133 |
93 explicit Builder(HeadlessBrowserImpl* browser); | 134 explicit Builder(HeadlessBrowserImpl* browser); |
94 | 135 |
95 HeadlessBrowserImpl* browser_; | 136 HeadlessBrowserImpl* browser_; |
96 GURL initial_url_ = GURL("about:blank"); | 137 GURL initial_url_ = GURL("about:blank"); |
97 gfx::Size window_size_ = gfx::Size(800, 600); | 138 gfx::Size window_size_ = gfx::Size(800, 600); |
98 HeadlessBrowserContext* browser_context_; | 139 HeadlessBrowserContext* browser_context_; |
| 140 std::list<MojoService> mojo_services_; |
99 | 141 |
100 DISALLOW_COPY_AND_ASSIGN(Builder); | 142 DISALLOW_COPY_AND_ASSIGN(Builder); |
101 }; | 143 }; |
102 | 144 |
103 } // namespace headless | 145 } // namespace headless |
104 | 146 |
105 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ | 147 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
OLD | NEW |