| 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_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 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 const WebContentsCreatedCallback& callback) = 0; | 191 const WebContentsCreatedCallback& callback) = 0; |
| 192 | 192 |
| 193 // This creates a WebContents and initializes |this| GuestViewBase to use the | 193 // This creates a WebContents and initializes |this| GuestViewBase to use the |
| 194 // newly created WebContents. | 194 // newly created WebContents. |
| 195 void Init(const base::DictionaryValue& create_params, | 195 void Init(const base::DictionaryValue& create_params, |
| 196 const WebContentsCreatedCallback& callback); | 196 const WebContentsCreatedCallback& callback); |
| 197 | 197 |
| 198 void InitWithWebContents(const base::DictionaryValue& create_params, | 198 void InitWithWebContents(const base::DictionaryValue& create_params, |
| 199 content::WebContents* guest_web_contents); | 199 content::WebContents* guest_web_contents); |
| 200 | 200 |
| 201 void LoadURLWithParams( |
| 202 const content::NavigationController::LoadURLParams& load_params); |
| 203 |
| 201 bool IsViewType(const char* const view_type) const { | 204 bool IsViewType(const char* const view_type) const { |
| 202 return !strcmp(GetViewType(), view_type); | 205 return !strcmp(GetViewType(), view_type); |
| 203 } | 206 } |
| 204 | 207 |
| 205 // Used to toggle autosize mode for this GuestView, and set both the automatic | 208 // Used to toggle autosize mode for this GuestView, and set both the automatic |
| 206 // and normal sizes. | 209 // and normal sizes. |
| 207 void SetSize(const SetSizeParams& params); | 210 void SetSize(const SetSizeParams& params); |
| 208 | 211 |
| 209 bool initialized() const { return initialized_; } | 212 bool initialized() const { return initialized_; } |
| 210 | 213 |
| 211 content::WebContents* embedder_web_contents() const { | 214 content::WebContents* embedder_web_contents() const { |
| 212 return attached() ? owner_web_contents_ : nullptr; | 215 return attached() ? owner_web_contents_ : nullptr; |
| 213 } | 216 } |
| 214 | 217 |
| 215 content::WebContents* owner_web_contents() const { | 218 content::WebContents* owner_web_contents() const { |
| 216 return owner_web_contents_; | 219 return owner_web_contents_; |
| 217 } | 220 } |
| 218 | 221 |
| 222 content::GuestHost* host() const { |
| 223 return guest_host_; |
| 224 } |
| 225 |
| 219 // Returns the parameters associated with the element hosting this GuestView | 226 // Returns the parameters associated with the element hosting this GuestView |
| 220 // passed in from JavaScript. | 227 // passed in from JavaScript. |
| 221 base::DictionaryValue* attach_params() const { return attach_params_.get(); } | 228 base::DictionaryValue* attach_params() const { return attach_params_.get(); } |
| 222 | 229 |
| 223 // Returns whether this guest has an associated embedder. | 230 // Returns whether this guest has an associated embedder. |
| 224 bool attached() const { | 231 bool attached() const { |
| 225 return element_instance_id_ != guestview::kInstanceIDNone; | 232 return element_instance_id_ != guestview::kInstanceIDNone; |
| 226 } | 233 } |
| 227 | 234 |
| 228 // Returns the instance ID of the <*view> element. | 235 // Returns the instance ID of the <*view> element. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 250 GuestViewBase* GetOpener() const { | 257 GuestViewBase* GetOpener() const { |
| 251 return opener_.get(); | 258 return opener_.get(); |
| 252 } | 259 } |
| 253 | 260 |
| 254 // Returns the URL of the owner WebContents. | 261 // Returns the URL of the owner WebContents. |
| 255 const GURL& GetOwnerSiteURL() const; | 262 const GURL& GetOwnerSiteURL() const; |
| 256 | 263 |
| 257 // Whether the guest view is inside a plugin document. | 264 // Whether the guest view is inside a plugin document. |
| 258 bool is_full_page_plugin() { return is_full_page_plugin_; } | 265 bool is_full_page_plugin() { return is_full_page_plugin_; } |
| 259 | 266 |
| 267 // Returns the routing ID of the guest proxy in the owner's renderer process. |
| 268 // This value is only valid after attachment or first navigation. |
| 269 int proxy_routing_id() const { return guest_proxy_routing_id_; } |
| 270 |
| 260 // Destroy this guest. | 271 // Destroy this guest. |
| 261 void Destroy(); | 272 void Destroy(); |
| 262 | 273 |
| 263 // Saves the attach state of the custom element hosting this GuestView. | 274 // Saves the attach state of the custom element hosting this GuestView. |
| 264 void SetAttachParams(const base::DictionaryValue& params); | 275 void SetAttachParams(const base::DictionaryValue& params); |
| 265 void SetOpener(GuestViewBase* opener); | 276 void SetOpener(GuestViewBase* opener); |
| 266 | 277 |
| 267 // BrowserPluginGuestDelegate implementation. | 278 // BrowserPluginGuestDelegate implementation. |
| 268 content::WebContents* CreateNewGuestWindow( | 279 content::WebContents* CreateNewGuestWindow( |
| 269 const content::WebContents::CreateParams& create_params) final; | 280 const content::WebContents::CreateParams& create_params) final; |
| 270 void DidAttach(int guest_proxy_routing_id) final; | 281 void DidAttach(int guest_proxy_routing_id) final; |
| 271 void DidDetach() final; | 282 void DidDetach() final; |
| 272 content::WebContents* GetOwnerWebContents() const final; | 283 content::WebContents* GetOwnerWebContents() const final; |
| 273 void GuestSizeChanged(const gfx::Size& new_size) final; | 284 void GuestSizeChanged(const gfx::Size& new_size) final; |
| 274 void RegisterDestructionCallback(const DestructionCallback& callback) final; | 285 void SetGuestHost(content::GuestHost* guest_host) final; |
| 275 void SetGuestSizer(content::GuestSizer* guest_sizer) final; | |
| 276 void WillAttach(content::WebContents* embedder_web_contents, | 286 void WillAttach(content::WebContents* embedder_web_contents, |
| 277 int browser_plugin_instance_id, | 287 int browser_plugin_instance_id, |
| 278 bool is_full_page_plugin) final; | 288 bool is_full_page_plugin) final; |
| 279 | 289 |
| 280 // ui_zoom::ZoomObserver implementation. | 290 // ui_zoom::ZoomObserver implementation. |
| 281 void OnZoomChanged( | 291 void OnZoomChanged( |
| 282 const ui_zoom::ZoomController::ZoomChangedEventData& data) override; | 292 const ui_zoom::ZoomController::ZoomChangedEventData& data) override; |
| 283 | 293 |
| 284 // Dispatches an event to the guest proxy. | 294 // Dispatches an event to the guest proxy. |
| 285 void DispatchEventToGuestProxy(Event* event); | 295 void DispatchEventToGuestProxy(Event* event); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // Indicates that this guest is in the process of being destroyed. | 399 // Indicates that this guest is in the process of being destroyed. |
| 390 bool is_being_destroyed_; | 400 bool is_being_destroyed_; |
| 391 | 401 |
| 392 // This is a queue of Events that are destined to be sent to the embedder once | 402 // This is a queue of Events that are destined to be sent to the embedder once |
| 393 // the guest is attached to a particular embedder. | 403 // the guest is attached to a particular embedder. |
| 394 std::deque<linked_ptr<Event> > pending_events_; | 404 std::deque<linked_ptr<Event> > pending_events_; |
| 395 | 405 |
| 396 // The opener guest view. | 406 // The opener guest view. |
| 397 base::WeakPtr<GuestViewBase> opener_; | 407 base::WeakPtr<GuestViewBase> opener_; |
| 398 | 408 |
| 399 DestructionCallback destruction_callback_; | |
| 400 | |
| 401 // The parameters associated with the element hosting this GuestView that | 409 // The parameters associated with the element hosting this GuestView that |
| 402 // are passed in from JavaScript. This will typically be the view instance ID, | 410 // are passed in from JavaScript. This will typically be the view instance ID, |
| 403 // and element-specific parameters. These parameters are passed along to new | 411 // and element-specific parameters. These parameters are passed along to new |
| 404 // guests that are created from this guest. | 412 // guests that are created from this guest. |
| 405 scoped_ptr<base::DictionaryValue> attach_params_; | 413 scoped_ptr<base::DictionaryValue> attach_params_; |
| 406 | 414 |
| 407 // This observer ensures that this guest self-destructs if the embedder goes | 415 // This observer ensures that this guest self-destructs if the embedder goes |
| 408 // away. | 416 // away. |
| 409 scoped_ptr<OwnerLifetimeObserver> owner_lifetime_observer_; | 417 scoped_ptr<OwnerLifetimeObserver> owner_lifetime_observer_; |
| 410 | 418 |
| 411 // This observer ensures that if the guest is unattached and its opener goes | 419 // This observer ensures that if the guest is unattached and its opener goes |
| 412 // away then this guest also self-destructs. | 420 // away then this guest also self-destructs. |
| 413 scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_; | 421 scoped_ptr<OpenerLifetimeObserver> opener_lifetime_observer_; |
| 414 | 422 |
| 415 // The size of the guest content. Note: In autosize mode, the container | 423 // The size of the guest content. Note: In autosize mode, the container |
| 416 // element may not match the size of the guest. | 424 // element may not match the size of the guest. |
| 417 gfx::Size guest_size_; | 425 gfx::Size guest_size_; |
| 418 | 426 |
| 419 // A pointer to the guest_sizer. | 427 // A pointer to the guest_host. |
| 420 content::GuestSizer* guest_sizer_; | 428 content::GuestHost* guest_host_; |
| 421 | 429 |
| 422 // Indicates whether autosize mode is enabled or not. | 430 // Indicates whether autosize mode is enabled or not. |
| 423 bool auto_size_enabled_; | 431 bool auto_size_enabled_; |
| 424 | 432 |
| 425 // The maximum size constraints of the container element in autosize mode. | 433 // The maximum size constraints of the container element in autosize mode. |
| 426 gfx::Size max_auto_size_; | 434 gfx::Size max_auto_size_; |
| 427 | 435 |
| 428 // The minimum size constraints of the container element in autosize mode. | 436 // The minimum size constraints of the container element in autosize mode. |
| 429 gfx::Size min_auto_size_; | 437 gfx::Size min_auto_size_; |
| 430 | 438 |
| 431 // The size that will be used when autosize mode is disabled. | 439 // The size that will be used when autosize mode is disabled. |
| 432 gfx::Size normal_size_; | 440 gfx::Size normal_size_; |
| 433 | 441 |
| 434 // Whether the guest view is inside a plugin document. | 442 // Whether the guest view is inside a plugin document. |
| 435 bool is_full_page_plugin_; | 443 bool is_full_page_plugin_; |
| 436 | 444 |
| 445 // The routing ID of the proxy to the guest in the owner's renderer process. |
| 446 int guest_proxy_routing_id_; |
| 447 |
| 437 // This is used to ensure pending tasks will not fire after this object is | 448 // This is used to ensure pending tasks will not fire after this object is |
| 438 // destroyed. | 449 // destroyed. |
| 439 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; | 450 base::WeakPtrFactory<GuestViewBase> weak_ptr_factory_; |
| 440 | 451 |
| 441 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); | 452 DISALLOW_COPY_AND_ASSIGN(GuestViewBase); |
| 442 }; | 453 }; |
| 443 | 454 |
| 444 } // namespace extensions | 455 } // namespace extensions |
| 445 | 456 |
| 446 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ | 457 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_BASE_H_ |
| OLD | NEW |