| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 void Init(const base::DictionaryValue& create_params, | 199 void Init(const base::DictionaryValue& create_params, |
| 184 const WebContentsCreatedCallback& callback); | 200 const WebContentsCreatedCallback& callback); |
| 185 | 201 |
| 186 void InitWithWebContents(const base::DictionaryValue& create_params, | 202 void InitWithWebContents(const base::DictionaryValue& create_params, |
| 187 content::WebContents* guest_web_contents); | 203 content::WebContents* guest_web_contents); |
| 188 | 204 |
| 189 bool IsViewType(const char* const view_type) const { | 205 bool IsViewType(const char* const view_type) const { |
| 190 return !strcmp(GetViewType(), view_type); | 206 return !strcmp(GetViewType(), view_type); |
| 191 } | 207 } |
| 192 | 208 |
| 193 // Toggles autosize mode for this GuestView. | 209 // Used to toggle autosize mode for this GuestView, and set both the automatic |
| 194 void SetAutoSize(bool enabled, | 210 // and normal sizes. |
| 195 const gfx::Size& min_size, | 211 void SetSize(const SetSizeParams& params); |
| 196 const gfx::Size& max_size); | |
| 197 | 212 |
| 198 bool initialized() const { return initialized_; } | 213 bool initialized() const { return initialized_; } |
| 199 | 214 |
| 200 content::WebContents* embedder_web_contents() const { | 215 content::WebContents* embedder_web_contents() const { |
| 201 return attached() ? owner_web_contents_ : NULL; | 216 return attached() ? owner_web_contents_ : NULL; |
| 202 } | 217 } |
| 203 | 218 |
| 204 content::WebContents* owner_web_contents() const { | 219 content::WebContents* owner_web_contents() const { |
| 205 return owner_web_contents_; | 220 return owner_web_contents_; |
| 206 } | 221 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 class OwnerLifetimeObserver; | 299 class OwnerLifetimeObserver; |
| 285 | 300 |
| 286 class OpenerLifetimeObserver; | 301 class OpenerLifetimeObserver; |
| 287 | 302 |
| 288 void SendQueuedEvents(); | 303 void SendQueuedEvents(); |
| 289 | 304 |
| 290 void CompleteInit(scoped_ptr<base::DictionaryValue> create_params, | 305 void CompleteInit(scoped_ptr<base::DictionaryValue> create_params, |
| 291 const WebContentsCreatedCallback& callback, | 306 const WebContentsCreatedCallback& callback, |
| 292 content::WebContents* guest_web_contents); | 307 content::WebContents* guest_web_contents); |
| 293 | 308 |
| 294 void SetUpAutoSize(const base::DictionaryValue& params); | 309 void SetUpSizing(const base::DictionaryValue& params); |
| 295 | 310 |
| 296 void StartTrackingEmbedderZoomLevel(); | 311 void StartTrackingEmbedderZoomLevel(); |
| 297 void StopTrackingEmbedderZoomLevel(); | 312 void StopTrackingEmbedderZoomLevel(); |
| 298 | 313 |
| 299 static void RegisterGuestViewTypes(); | 314 static void RegisterGuestViewTypes(); |
| 300 | 315 |
| 301 // WebContentsObserver implementation. | 316 // WebContentsObserver implementation. |
| 302 void DidStopLoading(content::RenderViewHost* render_view_host) final; | 317 void DidStopLoading(content::RenderViewHost* render_view_host) final; |
| 303 void RenderViewReady() final; | 318 void RenderViewReady() final; |
| 304 void WebContentsDestroyed() final; | 319 void WebContentsDestroyed() final; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 scoped_ptr<base::DictionaryValue> attach_params_; | 371 scoped_ptr<base::DictionaryValue> attach_params_; |
| 357 | 372 |
| 358 // This observer ensures that this guest self-destructs if the embedder goes | 373 // This observer ensures that this guest self-destructs if the embedder goes |
| 359 // away. | 374 // away. |
| 360 scoped_ptr<OwnerLifetimeObserver> owner_lifetime_observer_; | 375 scoped_ptr<OwnerLifetimeObserver> owner_lifetime_observer_; |
| 361 | 376 |
| 362 // This observer ensures that if the guest is unattached and its opener goes | 377 // This observer ensures that if the guest is unattached and its opener goes |
| 363 // away then this guest also self-destructs. | 378 // away then this guest also self-destructs. |
| 364 scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_; | 379 scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_; |
| 365 | 380 |
| 366 // The size of the container element. | |
| 367 gfx::Size element_size_; | |
| 368 | |
| 369 // The size of the guest content. Note: In autosize mode, the container | 381 // The size of the guest content. Note: In autosize mode, the container |
| 370 // element may not match the size of the guest. | 382 // element may not match the size of the guest. |
| 371 gfx::Size guest_size_; | 383 gfx::Size guest_size_; |
| 372 | 384 |
| 373 // A pointer to the guest_sizer. | 385 // A pointer to the guest_sizer. |
| 374 content::GuestSizer* guest_sizer_; | 386 content::GuestSizer* guest_sizer_; |
| 375 | 387 |
| 376 // Indicates whether autosize mode is enabled or not. | 388 // Indicates whether autosize mode is enabled or not. |
| 377 bool auto_size_enabled_; | 389 bool auto_size_enabled_; |
| 378 | 390 |
| 379 // The maximum size constraints of the container element in autosize mode. | 391 // The maximum size constraints of the container element in autosize mode. |
| 380 gfx::Size max_auto_size_; | 392 gfx::Size max_auto_size_; |
| 381 | 393 |
| 382 // The minimum size constraints of the container element in autosize mode. | 394 // The minimum size constraints of the container element in autosize mode. |
| 383 gfx::Size min_auto_size_; | 395 gfx::Size min_auto_size_; |
| 384 | 396 |
| 397 // The size that will be used when autosize mode is disabled. |
| 398 gfx::Size normal_size_; |
| 399 |
| 385 // Whether the guest view is inside a plugin document. | 400 // Whether the guest view is inside a plugin document. |
| 386 bool is_full_page_plugin_; | 401 bool is_full_page_plugin_; |
| 387 | 402 |
| 388 // This is used to ensure pending tasks will not fire after this object is | 403 // This is used to ensure pending tasks will not fire after this object is |
| 389 // destroyed. | 404 // destroyed. |
| 390 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 405 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
| 391 | 406 |
| 392 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 407 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
| 393 }; | 408 }; |
| 394 | 409 |
| 395 } // namespace extensions | 410 } // namespace extensions |
| 396 | 411 |
| 397 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 412 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
| OLD | NEW |