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 "components/ui/zoom/zoom_observer.h" | 12 #include "components/ui/zoom/zoom_observer.h" |
13 #include "content/public/browser/browser_plugin_guest_delegate.h" | 13 #include "content/public/browser/browser_plugin_guest_delegate.h" |
14 #include "content/public/browser/guest_sizer.h" | 14 #include "content/public/browser/guest_sizer.h" |
15 #include "content/public/browser/render_process_host_observer.h" | 15 #include "content/public/browser/render_process_host_observer.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
18 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" |
19 #include "extensions/common/guest_view/guest_view_constants.h" | 19 #include "extensions/common/guest_view/guest_view_constants.h" |
20 | 20 |
21 struct RendererContentSettingRules; | 21 struct RendererContentSettingRules; |
22 | 22 |
23 namespace extensions { | 23 namespace extensions { |
24 | 24 |
| 25 // A struct of parameters for SetSize(). The parameters are all declared as |
| 26 // scoped pointers since they are all optional. Null pointers indicate that the |
| 27 // parameter has not been provided, and the last used value should be used. Note |
| 28 // that when |enable_auto_size| is true, providing |normal_size| is not |
| 29 // meaningful. This is because the normal size of the guestview is overridden |
| 30 // whenever autosizing occurs. |
| 31 struct SetSizeParams { |
| 32 SetSizeParams(); |
| 33 ~SetSizeParams(); |
| 34 |
| 35 scoped_ptr<bool> enable_auto_size; |
| 36 scoped_ptr<gfx::Size> min_size; |
| 37 scoped_ptr<gfx::Size> max_size; |
| 38 scoped_ptr<gfx::Size> normal_size; |
| 39 }; |
| 40 |
25 // A GuestViewBase is the base class browser-side API implementation for a | 41 // A GuestViewBase is the base class browser-side API implementation for a |
26 // <*view> tag. GuestViewBase maintains an association between a guest | 42 // <*view> tag. GuestViewBase maintains an association between a guest |
27 // WebContents and an owner WebContents. It receives events issued from | 43 // WebContents and an owner WebContents. It receives events issued from |
28 // the guest and relays them to the owner. GuestViewBase tracks the lifetime | 44 // the guest and relays them to the owner. GuestViewBase tracks the lifetime |
29 // of its owner. A GuestViewBase's owner is referred to as an embedder if | 45 // of its owner. A GuestViewBase's owner is referred to as an embedder if |
30 // it is attached to a container within the owner's WebContents. | 46 // it is attached to a container within the owner's WebContents. |
31 class GuestViewBase : public content::BrowserPluginGuestDelegate, | 47 class GuestViewBase : public content::BrowserPluginGuestDelegate, |
32 public content::WebContentsDelegate, | 48 public content::WebContentsDelegate, |
33 public content::WebContentsObserver, | 49 public content::WebContentsObserver, |
34 public ui_zoom::ZoomObserver { | 50 public ui_zoom::ZoomObserver { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 void Init(const base::DictionaryValue& create_params, | 196 void Init(const base::DictionaryValue& create_params, |
181 const WebContentsCreatedCallback& callback); | 197 const WebContentsCreatedCallback& callback); |
182 | 198 |
183 void InitWithWebContents(const base::DictionaryValue& create_params, | 199 void InitWithWebContents(const base::DictionaryValue& create_params, |
184 content::WebContents* guest_web_contents); | 200 content::WebContents* guest_web_contents); |
185 | 201 |
186 bool IsViewType(const char* const view_type) const { | 202 bool IsViewType(const char* const view_type) const { |
187 return !strcmp(GetViewType(), view_type); | 203 return !strcmp(GetViewType(), view_type); |
188 } | 204 } |
189 | 205 |
190 // Toggles autosize mode for this GuestView. | 206 // Used to toggle autosize mode for this GuestView, and set both the automatic |
191 void SetAutoSize(bool enabled, | 207 // and normal sizes. |
192 const gfx::Size& min_size, | 208 void SetSize(const SetSizeParams& params); |
193 const gfx::Size& max_size); | |
194 | 209 |
195 bool initialized() const { return initialized_; } | 210 bool initialized() const { return initialized_; } |
196 | 211 |
197 content::WebContents* embedder_web_contents() const { | 212 content::WebContents* embedder_web_contents() const { |
198 return attached() ? owner_web_contents_ : NULL; | 213 return attached() ? owner_web_contents_ : NULL; |
199 } | 214 } |
200 | 215 |
201 content::WebContents* owner_web_contents() const { | 216 content::WebContents* owner_web_contents() const { |
202 return owner_web_contents_; | 217 return owner_web_contents_; |
203 } | 218 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 void SendQueuedEvents(); | 306 void SendQueuedEvents(); |
292 | 307 |
293 void CompleteInit(scoped_ptr<base::DictionaryValue> create_params, | 308 void CompleteInit(scoped_ptr<base::DictionaryValue> create_params, |
294 const WebContentsCreatedCallback& callback, | 309 const WebContentsCreatedCallback& callback, |
295 content::WebContents* guest_web_contents); | 310 content::WebContents* guest_web_contents); |
296 | 311 |
297 // Dispatches the onResize event to the embedder. | 312 // Dispatches the onResize event to the embedder. |
298 void DispatchOnResizeEvent(const gfx::Size& old_size, | 313 void DispatchOnResizeEvent(const gfx::Size& old_size, |
299 const gfx::Size& new_size); | 314 const gfx::Size& new_size); |
300 | 315 |
301 void SetUpAutoSize(const base::DictionaryValue& params); | 316 void SetUpSizing(const base::DictionaryValue& params); |
302 | 317 |
303 void StartTrackingEmbedderZoomLevel(); | 318 void StartTrackingEmbedderZoomLevel(); |
304 void StopTrackingEmbedderZoomLevel(); | 319 void StopTrackingEmbedderZoomLevel(); |
305 | 320 |
306 static void RegisterGuestViewTypes(); | 321 static void RegisterGuestViewTypes(); |
307 | 322 |
308 // WebContentsObserver implementation. | 323 // WebContentsObserver implementation. |
309 void DidStopLoading(content::RenderViewHost* render_view_host) final; | 324 void DidStopLoading(content::RenderViewHost* render_view_host) final; |
310 void RenderViewReady() final; | 325 void RenderViewReady() final; |
311 void WebContentsDestroyed() final; | 326 void WebContentsDestroyed() final; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 scoped_ptr<base::DictionaryValue> attach_params_; | 382 scoped_ptr<base::DictionaryValue> attach_params_; |
368 | 383 |
369 // This observer ensures that this guest self-destructs if the embedder goes | 384 // This observer ensures that this guest self-destructs if the embedder goes |
370 // away. | 385 // away. |
371 scoped_ptr<OwnerLifetimeObserver> owner_lifetime_observer_; | 386 scoped_ptr<OwnerLifetimeObserver> owner_lifetime_observer_; |
372 | 387 |
373 // This observer ensures that if the guest is unattached and its opener goes | 388 // This observer ensures that if the guest is unattached and its opener goes |
374 // away then this guest also self-destructs. | 389 // away then this guest also self-destructs. |
375 scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_; | 390 scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_; |
376 | 391 |
377 // The size of the container element. | |
378 gfx::Size element_size_; | |
379 | |
380 // The size of the guest content. Note: In autosize mode, the container | 392 // The size of the guest content. Note: In autosize mode, the container |
381 // element may not match the size of the guest. | 393 // element may not match the size of the guest. |
382 gfx::Size guest_size_; | 394 gfx::Size guest_size_; |
383 | 395 |
384 // A pointer to the guest_sizer. | 396 // A pointer to the guest_sizer. |
385 content::GuestSizer* guest_sizer_; | 397 content::GuestSizer* guest_sizer_; |
386 | 398 |
387 // Indicates whether autosize mode is enabled or not. | 399 // Indicates whether autosize mode is enabled or not. |
388 bool auto_size_enabled_; | 400 bool auto_size_enabled_; |
389 | 401 |
390 // The maximum size constraints of the container element in autosize mode. | 402 // The maximum size constraints of the container element in autosize mode. |
391 gfx::Size max_auto_size_; | 403 gfx::Size max_auto_size_; |
392 | 404 |
393 // The minimum size constraints of the container element in autosize mode. | 405 // The minimum size constraints of the container element in autosize mode. |
394 gfx::Size min_auto_size_; | 406 gfx::Size min_auto_size_; |
395 | 407 |
| 408 // The size that will be used when autosize mode is disabled. |
| 409 gfx::Size normal_size_; |
| 410 |
396 // Whether the guest view is inside a plugin document. | 411 // Whether the guest view is inside a plugin document. |
397 bool is_full_page_plugin_; | 412 bool is_full_page_plugin_; |
398 | 413 |
399 // This is used to ensure pending tasks will not fire after this object is | 414 // This is used to ensure pending tasks will not fire after this object is |
400 // destroyed. | 415 // destroyed. |
401 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 416 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
402 | 417 |
403 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 418 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
404 }; | 419 }; |
405 | 420 |
406 } // namespace extensions | 421 } // namespace extensions |
407 | 422 |
408 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 423 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
OLD | NEW |