| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | // Copyright (c) 2015 GitHub, Inc.
 | 
					
						
							|  |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							|  |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef ATOM_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_
 | 
					
						
							|  |  |  | #define ATOM_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-30 16:48:40 +05:30
										 |  |  | #include "atom/browser/web_contents_zoom_controller.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | #include "content/public/browser/browser_plugin_guest_delegate.h"
 | 
					
						
							|  |  |  | #include "content/public/browser/web_contents_observer.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace atom { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace api { | 
					
						
							|  |  |  | class WebContents; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // A struct of parameters for SetSize(). The parameters are all declared as
 | 
					
						
							|  |  |  | // scoped pointers since they are all optional. Null pointers indicate that the
 | 
					
						
							|  |  |  | // parameter has not been provided, and the last used value should be used. Note
 | 
					
						
							|  |  |  | // that when |enable_auto_size| is true, providing |normal_size| is not
 | 
					
						
							|  |  |  | // meaningful. This is because the normal size of the guestview is overridden
 | 
					
						
							|  |  |  | // whenever autosizing occurs.
 | 
					
						
							|  |  |  | struct SetSizeParams { | 
					
						
							| 
									
										
										
										
											2018-04-17 16:37:22 -07:00
										 |  |  |   SetSizeParams(); | 
					
						
							|  |  |  |   ~SetSizeParams(); | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-23 10:59:39 +09:00
										 |  |  |   std::unique_ptr<bool> enable_auto_size; | 
					
						
							|  |  |  |   std::unique_ptr<gfx::Size> min_size; | 
					
						
							|  |  |  |   std::unique_ptr<gfx::Size> max_size; | 
					
						
							|  |  |  |   std::unique_ptr<gfx::Size> normal_size; | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate, | 
					
						
							| 
									
										
										
										
											2017-01-30 16:48:40 +05:30
										 |  |  |                              public content::WebContentsObserver, | 
					
						
							|  |  |  |                              public WebContentsZoomController::Observer { | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  |  public: | 
					
						
							|  |  |  |   WebViewGuestDelegate(); | 
					
						
							|  |  |  |   ~WebViewGuestDelegate() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void Initialize(api::WebContents* api_web_contents); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Called when the WebContents is going to be destroyed.
 | 
					
						
							|  |  |  |   void Destroy(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Used to toggle autosize mode for this GuestView, and set both the automatic
 | 
					
						
							|  |  |  |   // and normal sizes.
 | 
					
						
							|  |  |  |   void SetSize(const SetSizeParams& params); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-12 17:26:37 +05:30
										 |  |  |   // Invoked when the contents auto-resized and the container should match it.
 | 
					
						
							|  |  |  |   void ResizeDueToAutoResize(const gfx::Size& new_size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 15:17:27 +03:00
										 |  |  |   // Return true if attached.
 | 
					
						
							| 
									
										
										
										
											2017-07-17 16:52:02 +03:00
										 |  |  |   bool IsAttached() const { return attached_; } | 
					
						
							| 
									
										
										
										
											2017-06-21 15:17:27 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  |  protected: | 
					
						
							|  |  |  |   // content::WebContentsObserver:
 | 
					
						
							| 
									
										
										
										
											2016-07-14 05:49:28 +05:30
										 |  |  |   void DidFinishNavigation( | 
					
						
							|  |  |  |       content::NavigationHandle* navigation_handle) override; | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // content::BrowserPluginGuestDelegate:
 | 
					
						
							|  |  |  |   void DidAttach(int guest_proxy_routing_id) final; | 
					
						
							| 
									
										
										
										
											2017-06-21 15:17:27 +03:00
										 |  |  |   void DidDetach() final; | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  |   content::WebContents* GetOwnerWebContents() const final; | 
					
						
							|  |  |  |   void SetGuestHost(content::GuestHost* guest_host) final; | 
					
						
							|  |  |  |   void WillAttach(content::WebContents* embedder_web_contents, | 
					
						
							|  |  |  |                   int element_instance_id, | 
					
						
							| 
									
										
										
										
											2015-08-04 16:46:11 +08:00
										 |  |  |                   bool is_full_page_plugin, | 
					
						
							|  |  |  |                   const base::Closure& completion_callback) final; | 
					
						
							| 
									
										
										
										
											2017-01-25 10:44:58 +09:00
										 |  |  |   bool CanBeEmbeddedInsideCrossProcessFrames() override; | 
					
						
							|  |  |  |   content::RenderWidgetHost* GetOwnerRenderWidgetHost() override; | 
					
						
							|  |  |  |   content::SiteInstance* GetOwnerSiteInstance() override; | 
					
						
							| 
									
										
										
										
											2017-05-23 13:26:19 -07:00
										 |  |  |   content::WebContents* CreateNewGuestWindow( | 
					
						
							| 
									
										
										
										
											2018-04-17 21:44:10 -04:00
										 |  |  |       const content::WebContents::CreateParams& create_params) override; | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-30 16:48:40 +05:30
										 |  |  |   // WebContentsZoomController::Observer:
 | 
					
						
							|  |  |  |   void OnZoomLevelChanged(content::WebContents* web_contents, | 
					
						
							| 
									
										
										
										
											2017-01-30 22:36:50 +05:30
										 |  |  |                           double level, | 
					
						
							|  |  |  |                           bool is_temporary) override; | 
					
						
							| 
									
										
										
										
											2017-01-30 16:48:40 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  |  private: | 
					
						
							|  |  |  |   // This method is invoked when the contents auto-resized to give the container
 | 
					
						
							|  |  |  |   // an opportunity to match it if it wishes.
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // This gives the derived class an opportunity to inform its container element
 | 
					
						
							|  |  |  |   // or perform other actions.
 | 
					
						
							| 
									
										
										
										
											2018-04-12 17:26:37 +05:30
										 |  |  |   void UpdateGuestSize(const gfx::Size& new_size, bool due_to_auto_resize); | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Returns the default size of the guestview.
 | 
					
						
							|  |  |  |   gfx::Size GetDefaultSize() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-30 16:09:05 +01:00
										 |  |  |   void ResetZoomController(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  |   // The WebContents that attaches this guest view.
 | 
					
						
							| 
									
										
										
										
											2017-10-11 08:14:03 +00:00
										 |  |  |   content::WebContents* embedder_web_contents_ = nullptr; | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-30 16:48:40 +05:30
										 |  |  |   // The zoom controller of the embedder that is used
 | 
					
						
							|  |  |  |   // to subscribe for zoom changes.
 | 
					
						
							| 
									
										
										
										
											2018-05-22 00:18:38 +02:00
										 |  |  |   WebContentsZoomController* embedder_zoom_controller_ = nullptr; | 
					
						
							| 
									
										
										
										
											2017-01-30 16:48:40 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  |   // The size of the container element.
 | 
					
						
							|  |  |  |   gfx::Size element_size_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // The size of the guest content. Note: In autosize mode, the container
 | 
					
						
							|  |  |  |   // element may not match the size of the guest.
 | 
					
						
							|  |  |  |   gfx::Size guest_size_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // A pointer to the guest_host.
 | 
					
						
							| 
									
										
										
										
											2018-05-22 00:18:38 +02:00
										 |  |  |   content::GuestHost* guest_host_ = nullptr; | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Indicates whether autosize mode is enabled or not.
 | 
					
						
							| 
									
										
										
										
											2018-05-22 00:18:38 +02:00
										 |  |  |   bool auto_size_enabled_ = false; | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // The maximum size constraints of the container element in autosize mode.
 | 
					
						
							|  |  |  |   gfx::Size max_auto_size_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // The minimum size constraints of the container element in autosize mode.
 | 
					
						
							|  |  |  |   gfx::Size min_auto_size_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // The size that will be used when autosize mode is disabled.
 | 
					
						
							|  |  |  |   gfx::Size normal_size_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Whether the guest view is inside a plugin document.
 | 
					
						
							| 
									
										
										
										
											2018-05-22 00:18:38 +02:00
										 |  |  |   bool is_full_page_plugin_ = false; | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 15:17:27 +03:00
										 |  |  |   // Whether attached.
 | 
					
						
							| 
									
										
										
										
											2018-05-22 00:18:38 +02:00
										 |  |  |   bool attached_ = false; | 
					
						
							| 
									
										
										
										
											2017-06-21 15:17:27 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 00:18:38 +02:00
										 |  |  |   api::WebContents* api_web_contents_ = nullptr; | 
					
						
							| 
									
										
										
										
											2015-06-25 14:28:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   DISALLOW_COPY_AND_ASSIGN(WebViewGuestDelegate); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace atom
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif  // ATOM_BROWSER_WEB_VIEW_GUEST_DELEGATE_H_
 |