Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: headless/public/headless_web_contents.h

Issue 2049363003: Adds support for headless chrome embedder mojo services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactored the JS for clarity Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 any client asks for it. Note if JS bindings are used they are
91 // assumed to be in their default location gen/path_to/filenme.mojom.js
Sami 2016/06/20 16:58:17 This comment about the JS bindings file is no long
alex clarke (OOO till 29th) 2016/06/20 23:19:13 Done.
92 template <typename Interface>
93 Builder& AddMojoService(
94 const base::Callback<void(mojo::InterfaceRequest<Interface>)>&
95 service_factory) {
96 return AddMojoService(
97 Interface::Name_,
98 base::Bind(&Builder::ForwardToServiceFactory<Interface>,
99 service_factory));
100 }
101 Builder& AddMojoService(const std::string& service_name,
102 const base::Callback<void(
103 mojo::ScopedMessagePipeHandle)>& service_factory);
104
105 // Specify JS mojo module bindings to be installed, one per mojom file.
106 // Note a single mojom file could potentially define many interfaces.
107 Builder& AddJsMojoBindings(const std::string& mojom_name,
Sami 2016/06/20 16:58:16 Is |mojom_file| a file that is read off disk somew
alex clarke (OOO till 29th) 2016/06/20 23:19:14 No it's not.
108 const std::string& js_bindings);
Sami 2016/06/20 16:58:16 Could you document |js_bindings| and where to get
alex clarke (OOO till 29th) 2016/06/20 23:19:14 Done.
109
85 // The returned object is owned by HeadlessBrowser. Call 110 // The returned object is owned by HeadlessBrowser. Call
86 // HeadlessWebContents::Close() to dispose it. 111 // HeadlessWebContents::Close() to dispose it.
87 HeadlessWebContents* Build(); 112 HeadlessWebContents* Build();
88 113
89 private: 114 private:
90 friend class HeadlessBrowserImpl; 115 friend class HeadlessBrowserImpl;
91 friend class HeadlessWebContentsImpl; 116 friend class HeadlessWebContentsImpl;
92 117
118 template <typename Interface>
119 static void ForwardToServiceFactory(
120 const base::Callback<void(mojo::InterfaceRequest<Interface>)>&
121 service_factory,
122 mojo::ScopedMessagePipeHandle handle) {
123 service_factory.Run(mojo::MakeRequest<Interface>(std::move(handle)));
124 }
125
126 struct MojoService {
127 MojoService();
128 MojoService(const std::string& service_name,
129 const base::Callback<void(mojo::ScopedMessagePipeHandle)>&
130 service_factory);
131 ~MojoService();
132
133 std::string service_name;
134 base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory;
135
136 private:
137 DISALLOW_COPY_AND_ASSIGN(MojoService);
138 };
139
140 struct MojoBindings {
141 MojoBindings();
142 MojoBindings(const std::string& mojom_name, const std::string& js_bindings);
143 ~MojoBindings();
144
145 std::string mojom_name;
146 std::string js_bindings;
147
148 private:
149 DISALLOW_COPY_AND_ASSIGN(MojoBindings);
150 };
151
93 explicit Builder(HeadlessBrowserImpl* browser); 152 explicit Builder(HeadlessBrowserImpl* browser);
94 153
95 HeadlessBrowserImpl* browser_; 154 HeadlessBrowserImpl* browser_;
96 GURL initial_url_ = GURL("about:blank"); 155 GURL initial_url_ = GURL("about:blank");
97 gfx::Size window_size_ = gfx::Size(800, 600); 156 gfx::Size window_size_ = gfx::Size(800, 600);
98 HeadlessBrowserContext* browser_context_; 157 HeadlessBrowserContext* browser_context_;
158 std::list<MojoService> mojo_services_;
159 std::list<MojoBindings> mojo_bindings_;
99 160
100 DISALLOW_COPY_AND_ASSIGN(Builder); 161 DISALLOW_COPY_AND_ASSIGN(Builder);
101 }; 162 };
102 163
103 } // namespace headless 164 } // namespace headless
104 165
105 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_ 166 #endif // HEADLESS_PUBLIC_HEADLESS_WEB_CONTENTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698