| 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_host.h" | 14 #include "content/public/browser/guest_host.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 class GuestViewEvent; |
| 26 |
| 25 // A struct of parameters for SetSize(). The parameters are all declared as | 27 // 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 | 28 // 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 | 29 // 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 | 30 // 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 | 31 // meaningful. This is because the normal size of the guestview is overridden |
| 30 // whenever autosizing occurs. | 32 // whenever autosizing occurs. |
| 31 struct SetSizeParams { | 33 struct SetSizeParams { |
| 32 SetSizeParams(); | 34 SetSizeParams(); |
| 33 ~SetSizeParams(); | 35 ~SetSizeParams(); |
| 34 | 36 |
| 35 scoped_ptr<bool> enable_auto_size; | 37 scoped_ptr<bool> enable_auto_size; |
| 36 scoped_ptr<gfx::Size> min_size; | 38 scoped_ptr<gfx::Size> min_size; |
| 37 scoped_ptr<gfx::Size> max_size; | 39 scoped_ptr<gfx::Size> max_size; |
| 38 scoped_ptr<gfx::Size> normal_size; | 40 scoped_ptr<gfx::Size> normal_size; |
| 39 }; | 41 }; |
| 40 | 42 |
| 41 // A GuestViewBase is the base class browser-side API implementation for a | 43 // A GuestViewBase is the base class browser-side API implementation for a |
| 42 // <*view> tag. GuestViewBase maintains an association between a guest | 44 // <*view> tag. GuestViewBase maintains an association between a guest |
| 43 // WebContents and an owner WebContents. It receives events issued from | 45 // WebContents and an owner WebContents. It receives events issued from |
| 44 // the guest and relays them to the owner. GuestViewBase tracks the lifetime | 46 // the guest and relays them to the owner. GuestViewBase tracks the lifetime |
| 45 // of its owner. A GuestViewBase's owner is referred to as an embedder if | 47 // of its owner. A GuestViewBase's owner is referred to as an embedder if |
| 46 // it is attached to a container within the owner's WebContents. | 48 // it is attached to a container within the owner's WebContents. |
| 47 class GuestViewBase : public content::BrowserPluginGuestDelegate, | 49 class GuestViewBase : public content::BrowserPluginGuestDelegate, |
| 48 public content::WebContentsDelegate, | 50 public content::WebContentsDelegate, |
| 49 public content::WebContentsObserver, | 51 public content::WebContentsObserver, |
| 50 public ui_zoom::ZoomObserver { | 52 public ui_zoom::ZoomObserver { |
| 51 public: | 53 public: |
| 52 class Event { | |
| 53 public: | |
| 54 Event(const std::string& name, scoped_ptr<base::DictionaryValue> args); | |
| 55 ~Event(); | |
| 56 | |
| 57 const std::string& name() const { return name_; } | |
| 58 | |
| 59 scoped_ptr<base::DictionaryValue> GetArguments(); | |
| 60 | |
| 61 private: | |
| 62 const std::string name_; | |
| 63 scoped_ptr<base::DictionaryValue> args_; | |
| 64 }; | |
| 65 | |
| 66 // Returns a *ViewGuest if this GuestView is of the given view type. | 54 // Returns a *ViewGuest if this GuestView is of the given view type. |
| 67 template <typename T> | 55 template <typename T> |
| 68 T* As() { | 56 T* As() { |
| 69 if (IsViewType(T::Type)) | 57 if (IsViewType(T::Type)) |
| 70 return static_cast<T*>(this); | 58 return static_cast<T*>(this); |
| 71 | 59 |
| 72 return nullptr; | 60 return nullptr; |
| 73 } | 61 } |
| 74 | 62 |
| 75 using GuestCreationCallback = | 63 using GuestCreationCallback = |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 void SetGuestHost(content::GuestHost* guest_host) final; | 287 void SetGuestHost(content::GuestHost* guest_host) final; |
| 300 void WillAttach(content::WebContents* embedder_web_contents, | 288 void WillAttach(content::WebContents* embedder_web_contents, |
| 301 int browser_plugin_instance_id, | 289 int browser_plugin_instance_id, |
| 302 bool is_full_page_plugin) final; | 290 bool is_full_page_plugin) final; |
| 303 | 291 |
| 304 // ui_zoom::ZoomObserver implementation. | 292 // ui_zoom::ZoomObserver implementation. |
| 305 void OnZoomChanged( | 293 void OnZoomChanged( |
| 306 const ui_zoom::ZoomController::ZoomChangedEventData& data) final; | 294 const ui_zoom::ZoomController::ZoomChangedEventData& data) final; |
| 307 | 295 |
| 308 // Dispatches an event to the guest proxy. | 296 // Dispatches an event to the guest proxy. |
| 309 void DispatchEventToGuestProxy(Event* event); | 297 void DispatchEventToGuestProxy(GuestViewEvent* event); |
| 310 | 298 |
| 311 // Dispatches an event to the view. | 299 // Dispatches an event to the view. |
| 312 void DispatchEventToView(Event* event); | 300 void DispatchEventToView(GuestViewEvent* event); |
| 313 | 301 |
| 314 protected: | 302 protected: |
| 315 explicit GuestViewBase(content::WebContents* owner_web_contents); | 303 explicit GuestViewBase(content::WebContents* owner_web_contents); |
| 316 | 304 |
| 317 ~GuestViewBase() override; | 305 ~GuestViewBase() override; |
| 318 | 306 |
| 319 // Convert sizes in pixels from logical to physical numbers of pixels. | 307 // Convert sizes in pixels from logical to physical numbers of pixels. |
| 320 // Note that a size can consist of a fractional number of logical pixels | 308 // Note that a size can consist of a fractional number of logical pixels |
| 321 // (hence |logical_pixels| is represented as a double), but will always | 309 // (hence |logical_pixels| is represented as a double), but will always |
| 322 // consist of an integral number of physical pixels (hence the return value | 310 // consist of an integral number of physical pixels (hence the return value |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 const gfx::Size& pref_size) final; | 351 const gfx::Size& pref_size) final; |
| 364 void UpdateTargetURL(content::WebContents* source, const GURL& url) override; | 352 void UpdateTargetURL(content::WebContents* source, const GURL& url) override; |
| 365 | 353 |
| 366 void SetGuestZoomLevelToMatchEmbedder(); | 354 void SetGuestZoomLevelToMatchEmbedder(); |
| 367 | 355 |
| 368 private: | 356 private: |
| 369 class OwnerContentsObserver; | 357 class OwnerContentsObserver; |
| 370 | 358 |
| 371 class OpenerLifetimeObserver; | 359 class OpenerLifetimeObserver; |
| 372 | 360 |
| 373 void DispatchEvent(Event* event, int instance_id); | |
| 374 | |
| 375 void SendQueuedEvents(); | 361 void SendQueuedEvents(); |
| 376 | 362 |
| 377 void CompleteInit(scoped_ptr<base::DictionaryValue> create_params, | 363 void CompleteInit(scoped_ptr<base::DictionaryValue> create_params, |
| 378 const WebContentsCreatedCallback& callback, | 364 const WebContentsCreatedCallback& callback, |
| 379 content::WebContents* guest_web_contents); | 365 content::WebContents* guest_web_contents); |
| 380 | 366 |
| 381 // Dispatches the onResize event to the embedder. | 367 // Dispatches the onResize event to the embedder. |
| 382 void DispatchOnResizeEvent(const gfx::Size& old_size, | 368 void DispatchOnResizeEvent(const gfx::Size& old_size, |
| 383 const gfx::Size& new_size); | 369 const gfx::Size& new_size); |
| 384 | 370 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 402 |
| 417 // |initialized_| indicates whether GuestViewBase::Init has been called for | 403 // |initialized_| indicates whether GuestViewBase::Init has been called for |
| 418 // this object. | 404 // this object. |
| 419 bool initialized_; | 405 bool initialized_; |
| 420 | 406 |
| 421 // Indicates that this guest is in the process of being destroyed. | 407 // Indicates that this guest is in the process of being destroyed. |
| 422 bool is_being_destroyed_; | 408 bool is_being_destroyed_; |
| 423 | 409 |
| 424 // This is a queue of Events that are destined to be sent to the embedder once | 410 // This is a queue of Events that are destined to be sent to the embedder once |
| 425 // the guest is attached to a particular embedder. | 411 // the guest is attached to a particular embedder. |
| 426 std::deque<linked_ptr<Event> > pending_events_; | 412 std::deque<linked_ptr<GuestViewEvent> > pending_events_; |
| 427 | 413 |
| 428 // The opener guest view. | 414 // The opener guest view. |
| 429 base::WeakPtr<GuestViewBase> opener_; | 415 base::WeakPtr<GuestViewBase> opener_; |
| 430 | 416 |
| 431 // The parameters associated with the element hosting this GuestView that | 417 // The parameters associated with the element hosting this GuestView that |
| 432 // are passed in from JavaScript. This will typically be the view instance ID, | 418 // are passed in from JavaScript. This will typically be the view instance ID, |
| 433 // and element-specific parameters. These parameters are passed along to new | 419 // and element-specific parameters. These parameters are passed along to new |
| 434 // guests that are created from this guest. | 420 // guests that are created from this guest. |
| 435 scoped_ptr<base::DictionaryValue> attach_params_; | 421 scoped_ptr<base::DictionaryValue> attach_params_; |
| 436 | 422 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 // This is used to ensure pending tasks will not fire after this object is | 456 // This is used to ensure pending tasks will not fire after this object is |
| 471 // destroyed. | 457 // destroyed. |
| 472 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 458 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
| 473 | 459 |
| 474 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 460 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
| 475 }; | 461 }; |
| 476 | 462 |
| 477 } // namespace extensions | 463 } // namespace extensions |
| 478 | 464 |
| 479 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 465 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
| OLD | NEW |