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_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. | |
|
Sami
2016/06/10 10:27:39
Please document the arguments.
alex clarke (OOO till 29th)
2016/06/11 20:51:50
Done.
| |
| 89 template <typename Interface> | |
| 90 Builder& AddEmbedderMojoService( | |
| 91 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& | |
| 92 service_factory, | |
| 93 const std::string& js_binding) { | |
| 94 return AddEmbedderMojoService( | |
| 95 Interface::Name_, | |
| 96 base::Bind(&Builder::ForwardToServiceFactory<Interface>, | |
| 97 service_factory), | |
| 98 js_binding); | |
| 99 } | |
| 100 Builder& AddEmbedderMojoService( | |
| 101 const std::string& service_name, | |
| 102 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& | |
| 103 service_factory, | |
| 104 const std::string& js_binding); | |
| 105 | |
| 85 // The returned object is owned by HeadlessBrowser. Call | 106 // The returned object is owned by HeadlessBrowser. Call |
| 86 // HeadlessWebContents::Close() to dispose it. | 107 // HeadlessWebContents::Close() to dispose it. |
| 87 HeadlessWebContents* Build(); | 108 HeadlessWebContents* Build(); |
| 88 | 109 |
| 89 private: | 110 private: |
| 90 friend class HeadlessBrowserImpl; | 111 friend class HeadlessBrowserImpl; |
| 91 friend class HeadlessWebContentsImpl; | 112 friend class HeadlessWebContentsImpl; |
| 92 | 113 |
| 114 template <typename Interface> | |
| 115 static void ForwardToServiceFactory( | |
| 116 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& | |
| 117 service_factory, | |
| 118 mojo::ScopedMessagePipeHandle handle) { | |
| 119 service_factory.Run(mojo::MakeRequest<Interface>(std::move(handle))); | |
| 120 } | |
| 121 | |
| 122 struct EmbedderMojoService { | |
| 123 EmbedderMojoService(); | |
| 124 EmbedderMojoService(const std::string& service_name, | |
| 125 const base::Callback<void( | |
| 126 mojo::ScopedMessagePipeHandle)>& service_factory, | |
| 127 const std::string& js_binding); | |
| 128 ~EmbedderMojoService(); | |
| 129 | |
| 130 std::string service_name; | |
| 131 base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory; | |
| 132 std::string js_binding; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(EmbedderMojoService); | |
|
Sami
2016/06/10 10:27:39
private:
alex clarke (OOO till 29th)
2016/06/11 20:51:50
Done.
| |
| 135 }; | |
| 136 | |
| 93 explicit Builder(HeadlessBrowserImpl* browser); | 137 explicit Builder(HeadlessBrowserImpl* browser); |
| 94 | 138 |
| 95 HeadlessBrowserImpl* browser_; | 139 HeadlessBrowserImpl* browser_; |
| 96 GURL initial_url_ = GURL("about:blank"); | 140 GURL initial_url_ = GURL("about:blank"); |
| 97 gfx::Size window_size_ = gfx::Size(800, 600); | 141 gfx::Size window_size_ = gfx::Size(800, 600); |
| 98 HeadlessBrowserContext* browser_context_; | 142 HeadlessBrowserContext* browser_context_; |
| 143 std::list<EmbedderMojoService> embedder_mojo_services_; | |
| 99 | 144 |
| 100 DISALLOW_COPY_AND_ASSIGN(Builder); | 145 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 101 }; | 146 }; |
| 102 | 147 |
| 103 } // namespace headless | 148 } // namespace headless |
| 104 | 149 |
| 105 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ | 150 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ |
| OLD | NEW |