OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 5 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 6 #define EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "content/public/browser/browser_plugin_guest_delegate.h" | 12 #include "content/public/browser/browser_plugin_guest_delegate.h" |
13 #include "content/public/browser/render_process_host_observer.h" | 13 #include "content/public/browser/render_process_host_observer.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/browser/web_contents_delegate.h" | 15 #include "content/public/browser/web_contents_delegate.h" |
16 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
17 | 17 |
18 struct RendererContentSettingRules; | 18 struct RendererContentSettingRules; |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 | 21 |
22 // A GuestViewBase is the base class browser-side API implementation for a | 22 // A GuestViewBase is the base class browser-side API implementation for a |
23 // <*view> tag. GuestViewBase maintains an association between a guest | 23 // <*view> tag. GuestViewBase maintains an association between a guest |
24 // WebContents and an embedder WebContents. It receives events issued from | 24 // WebContents and an embedder WebContents. It receives events issued from |
25 // the guest and relays them to the embedder. GuestViewBase tracks the lifetime | 25 // the guest and relays them to the embedder. GuestViewBase tracks the lifetime |
26 // of its embedder render process until it is attached to a particular embedder | 26 // of its embedder render process until it is attached to a particular embedder |
27 // WebContents. At that point, its lifetime is restricted in scope to the | 27 // WebContents. At that point, its lifetime is restricted in scope to the |
28 // lifetime of its embedder WebContents. | 28 // lifetime of its embedder WebContents. |
29 class GuestViewBase : public content::BrowserPluginGuestDelegate, | 29 class GuestViewBase : public content::BrowserPluginGuestDelegate, |
| 30 public content::RenderProcessHostObserver, |
30 public content::WebContentsDelegate, | 31 public content::WebContentsDelegate, |
31 public content::WebContentsObserver { | 32 public content::WebContentsObserver { |
32 public: | 33 public: |
33 class Event { | 34 class Event { |
34 public: | 35 public: |
35 Event(const std::string& name, scoped_ptr<base::DictionaryValue> args); | 36 Event(const std::string& name, scoped_ptr<base::DictionaryValue> args); |
36 ~Event(); | 37 ~Event(); |
37 | 38 |
38 const std::string& name() const { return name_; } | 39 const std::string& name() const { return name_; } |
39 | 40 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 const base::DictionaryValue& create_params, | 164 const base::DictionaryValue& create_params, |
164 const WebContentsCreatedCallback& callback) = 0; | 165 const WebContentsCreatedCallback& callback) = 0; |
165 | 166 |
166 // This creates a WebContents and initializes |this| GuestViewBase to use the | 167 // This creates a WebContents and initializes |this| GuestViewBase to use the |
167 // newly created WebContents. | 168 // newly created WebContents. |
168 void Init(const std::string& embedder_extension_id, | 169 void Init(const std::string& embedder_extension_id, |
169 content::WebContents* embedder_web_contents, | 170 content::WebContents* embedder_web_contents, |
170 const base::DictionaryValue& create_params, | 171 const base::DictionaryValue& create_params, |
171 const WebContentsCreatedCallback& callback); | 172 const WebContentsCreatedCallback& callback); |
172 | 173 |
173 void InitWithWebContents(const std::string& embedder_extension_id, | 174 void InitWithWebContents( |
174 content::WebContents* embedder_web_contents, | 175 const std::string& embedder_extension_id, |
175 content::WebContents* guest_web_contents); | 176 int embedder_render_process_id, |
| 177 content::WebContents* guest_web_contents); |
176 | 178 |
177 bool IsViewType(const char* const view_type) const { | 179 bool IsViewType(const char* const view_type) const { |
178 return !strcmp(GetViewType(), view_type); | 180 return !strcmp(GetViewType(), view_type); |
179 } | 181 } |
180 | 182 |
181 // Toggles autosize mode for this GuestView. | 183 // Toggles autosize mode for this GuestView. |
182 void SetAutoSize(bool enabled, | 184 void SetAutoSize(bool enabled, |
183 const gfx::Size& min_size, | 185 const gfx::Size& min_size, |
184 const gfx::Size& max_size); | 186 const gfx::Size& max_size); |
185 | 187 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 return opener_.get(); | 222 return opener_.get(); |
221 } | 223 } |
222 | 224 |
223 // Destroy this guest. | 225 // Destroy this guest. |
224 void Destroy(); | 226 void Destroy(); |
225 | 227 |
226 // Saves the attach state of the custom element hosting this GuestView. | 228 // Saves the attach state of the custom element hosting this GuestView. |
227 void SetAttachParams(const base::DictionaryValue& params); | 229 void SetAttachParams(const base::DictionaryValue& params); |
228 void SetOpener(GuestViewBase* opener); | 230 void SetOpener(GuestViewBase* opener); |
229 | 231 |
| 232 // RenderProcessHostObserver implementation |
| 233 virtual void RenderProcessExited(content::RenderProcessHost* host, |
| 234 base::ProcessHandle handle, |
| 235 base::TerminationStatus status, |
| 236 int exit_code) override; |
| 237 |
230 // BrowserPluginGuestDelegate implementation. | 238 // BrowserPluginGuestDelegate implementation. |
231 virtual void DidAttach(int guest_proxy_routing_id) override final; | 239 virtual void DidAttach(int guest_proxy_routing_id) override final; |
232 virtual void ElementSizeChanged(const gfx::Size& old_size, | 240 virtual void ElementSizeChanged(const gfx::Size& old_size, |
233 const gfx::Size& new_size) override final; | 241 const gfx::Size& new_size) override final; |
234 virtual void GuestSizeChanged(const gfx::Size& old_size, | 242 virtual void GuestSizeChanged(const gfx::Size& old_size, |
235 const gfx::Size& new_size) override final; | 243 const gfx::Size& new_size) override final; |
236 virtual void RegisterDestructionCallback( | 244 virtual void RegisterDestructionCallback( |
237 const DestructionCallback& callback) override final; | 245 const DestructionCallback& callback) override final; |
238 virtual void WillAttach( | 246 virtual void WillAttach( |
239 content::WebContents* embedder_web_contents, | 247 content::WebContents* embedder_web_contents, |
240 int browser_plugin_instance_id) override final; | 248 int browser_plugin_instance_id) override final; |
241 | 249 |
242 // Dispatches an event |event_name| to the embedder with the |event| fields. | 250 // Dispatches an event |event_name| to the embedder with the |event| fields. |
243 void DispatchEventToEmbedder(Event* event); | 251 void DispatchEventToEmbedder(Event* event); |
244 | 252 |
245 protected: | 253 protected: |
246 GuestViewBase(content::BrowserContext* browser_context, | 254 GuestViewBase(content::BrowserContext* browser_context, |
247 int guest_instance_id); | 255 int guest_instance_id); |
248 | 256 |
249 virtual ~GuestViewBase(); | 257 virtual ~GuestViewBase(); |
250 | 258 |
251 private: | 259 private: |
252 class EmbedderLifetimeObserver; | 260 class EmbedderWebContentsObserver; |
253 | 261 |
254 void SendQueuedEvents(); | 262 void SendQueuedEvents(); |
255 | 263 |
256 void CompleteInit(const std::string& embedder_extension_id, | 264 void CompleteInit(const std::string& embedder_extension_id, |
257 content::WebContents* embedder_web_contents, | 265 int embedder_render_process_id, |
258 const WebContentsCreatedCallback& callback, | 266 const WebContentsCreatedCallback& callback, |
259 content::WebContents* guest_web_contents); | 267 content::WebContents* guest_web_contents); |
260 | 268 |
261 static void RegisterGuestViewTypes(); | 269 static void RegisterGuestViewTypes(); |
262 | 270 |
263 // WebContentsObserver implementation. | 271 // WebContentsObserver implementation. |
264 virtual void DidStopLoading( | 272 virtual void DidStopLoading( |
265 content::RenderViewHost* render_view_host) override final; | 273 content::RenderViewHost* render_view_host) override final; |
266 virtual void RenderViewReady() override final; | 274 virtual void RenderViewReady() override final; |
267 virtual void WebContentsDestroyed() override final; | 275 virtual void WebContentsDestroyed() override final; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 base::WeakPtr<GuestViewBase> opener_; | 313 base::WeakPtr<GuestViewBase> opener_; |
306 | 314 |
307 DestructionCallback destruction_callback_; | 315 DestructionCallback destruction_callback_; |
308 | 316 |
309 // The parameters associated with the element hosting this GuestView that | 317 // The parameters associated with the element hosting this GuestView that |
310 // are passed in from JavaScript. This will typically be the view instance ID, | 318 // are passed in from JavaScript. This will typically be the view instance ID, |
311 // and element-specific parameters. These parameters are passed along to new | 319 // and element-specific parameters. These parameters are passed along to new |
312 // guests that are created from this guest. | 320 // guests that are created from this guest. |
313 scoped_ptr<base::DictionaryValue> attach_params_; | 321 scoped_ptr<base::DictionaryValue> attach_params_; |
314 | 322 |
315 scoped_ptr<EmbedderLifetimeObserver> embedder_web_contents_observer_; | 323 scoped_ptr<EmbedderWebContentsObserver> embedder_web_contents_observer_; |
316 | 324 |
317 // The size of the container element. | 325 // The size of the container element. |
318 gfx::Size element_size_; | 326 gfx::Size element_size_; |
319 | 327 |
320 // The size of the guest content. Note: In autosize mode, the container | 328 // The size of the guest content. Note: In autosize mode, the container |
321 // element may not match the size of the guest. | 329 // element may not match the size of the guest. |
322 gfx::Size guest_size_; | 330 gfx::Size guest_size_; |
323 | 331 |
324 // Indicates whether autosize mode is enabled or not. | 332 // Indicates whether autosize mode is enabled or not. |
325 bool auto_size_enabled_; | 333 bool auto_size_enabled_; |
326 | 334 |
327 // The maximum size constraints of the container element in autosize mode. | 335 // The maximum size constraints of the container element in autosize mode. |
328 gfx::Size max_auto_size_; | 336 gfx::Size max_auto_size_; |
329 | 337 |
330 // The minimum size constraints of the container element in autosize mode. | 338 // The minimum size constraints of the container element in autosize mode. |
331 gfx::Size min_auto_size_; | 339 gfx::Size min_auto_size_; |
332 | 340 |
333 // This is used to ensure pending tasks will not fire after this object is | 341 // This is used to ensure pending tasks will not fire after this object is |
334 // destroyed. | 342 // destroyed. |
335 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 343 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
336 | 344 |
337 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 345 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
338 }; | 346 }; |
339 | 347 |
340 } // namespace extensions | 348 } // namespace extensions |
341 | 349 |
342 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 350 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
OLD | NEW |