From 3ad0639b2eb5a2764e36551a9155f61b1d0fdac3 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 12 Apr 2018 17:26:37 +0530 Subject: [PATCH] Surface synchronization: Implement auto-resize for OOPIF/BrowserPlugin https://chromium-review.googlesource.com/c/chromium/src/+/753801 --- atom/browser/api/atom_api_web_contents.cc | 8 +++++++ atom/browser/api/atom_api_web_contents.h | 2 ++ atom/browser/web_view_guest_delegate.cc | 28 +++++++++++------------ atom/browser/web_view_guest_delegate.h | 7 +++--- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index ca72a3e6959c..1e4e23c79d71 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -785,6 +785,14 @@ content::JavaScriptDialogManager* WebContents::GetJavaScriptDialogManager( return dialog_manager_.get(); } +void WebContents::ResizeDueToAutoResize( + content::WebContents* web_contents, + const gfx::Size& new_size) { + if (IsGuest()) { + guest_delegate_->ResizeDueToAutoResize(new_size); + } +} + void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) { // Do nothing, we override this method just to avoid compilation error since // there are two virtual functions named BeforeUnloadFired. diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index e6ef1bb192c2..31e04ee3e1ec 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -337,6 +337,8 @@ class WebContents : public mate::TrackableObject, const content::BluetoothChooser::EventHandler& handler) override; content::JavaScriptDialogManager* GetJavaScriptDialogManager( content::WebContents* source) override; + void ResizeDueToAutoResize(content::WebContents* web_contents, + const gfx::Size& new_size) override; // content::WebContentsObserver: void BeforeUnloadFired(const base::TimeTicks& proceed_time) override; diff --git a/atom/browser/web_view_guest_delegate.cc b/atom/browser/web_view_guest_delegate.cc index f1d144bc5a0b..ed8e2d87c760 100644 --- a/atom/browser/web_view_guest_delegate.cc +++ b/atom/browser/web_view_guest_delegate.cc @@ -80,21 +80,26 @@ void WebViewGuestDelegate::SetSize(const SetSizeParams& params) { new_size = GetDefaultSize(); } + bool changed_due_to_auto_resize = false; if (auto_size_enabled_) { // Autosize was previously enabled. rvh->DisableAutoResize(new_size); - GuestSizeChangedDueToAutoSize(guest_size_, new_size); + changed_due_to_auto_resize = true; } else { // Autosize was already disabled. guest_host_->SizeContents(new_size); } - guest_size_ = new_size; + UpdateGuestSize(new_size, changed_due_to_auto_resize); } auto_size_enabled_ = enable_auto_size; } +void WebViewGuestDelegate::ResizeDueToAutoResize(const gfx::Size& new_size) { + UpdateGuestSize(new_size, auto_size_enabled_); +} + void WebViewGuestDelegate::DidFinishNavigation( content::NavigationHandle* navigation_handle) { if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) { @@ -126,13 +131,6 @@ content::WebContents* WebViewGuestDelegate::GetOwnerWebContents() const { return embedder_web_contents_; } -void WebViewGuestDelegate::GuestSizeChanged(const gfx::Size& new_size) { - if (!auto_size_enabled_) - return; - GuestSizeChangedDueToAutoSize(guest_size_, new_size); - guest_size_ = new_size; -} - void WebViewGuestDelegate::SetGuestHost(content::GuestHost* guest_host) { guest_host_ = guest_host; } @@ -163,11 +161,13 @@ void WebViewGuestDelegate::OnZoomLevelChanged( } } -void WebViewGuestDelegate::GuestSizeChangedDueToAutoSize( - const gfx::Size& old_size, - const gfx::Size& new_size) { - api_web_contents_->Emit("size-changed", old_size.width(), old_size.height(), - new_size.width(), new_size.height()); +void WebViewGuestDelegate::UpdateGuestSize(const gfx::Size& new_size, + bool due_to_auto_resize) { + if (due_to_auto_resize) + api_web_contents_->Emit("size-changed", guest_size_.width(), + guest_size_.height(), new_size.width(), + new_size.height()); + guest_size_ = new_size; } gfx::Size WebViewGuestDelegate::GetDefaultSize() const { diff --git a/atom/browser/web_view_guest_delegate.h b/atom/browser/web_view_guest_delegate.h index 2384b0e6dd45..784ca99275dd 100644 --- a/atom/browser/web_view_guest_delegate.h +++ b/atom/browser/web_view_guest_delegate.h @@ -47,6 +47,9 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate, // and normal sizes. void SetSize(const SetSizeParams& params); + // Invoked when the contents auto-resized and the container should match it. + void ResizeDueToAutoResize(const gfx::Size& new_size); + // Return true if attached. bool IsAttached() const { return attached_; } @@ -59,7 +62,6 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate, void DidAttach(int guest_proxy_routing_id) final; void DidDetach() final; content::WebContents* GetOwnerWebContents() const final; - void GuestSizeChanged(const gfx::Size& new_size) final; void SetGuestHost(content::GuestHost* guest_host) final; void WillAttach(content::WebContents* embedder_web_contents, int element_instance_id, @@ -82,8 +84,7 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate, // // This gives the derived class an opportunity to inform its container element // or perform other actions. - void GuestSizeChangedDueToAutoSize(const gfx::Size& old_size, - const gfx::Size& new_size); + void UpdateGuestSize(const gfx::Size& new_size, bool due_to_auto_resize); // Returns the default size of the guestview. gfx::Size GetDefaultSize() const;