Browse Source

fix: HTML fullscreen request for sub frames (#18736) (#18781)

Don't re-enter fullscreen if there is a pending operation,
for subframe fullscreen request `EnterFullScreenModeForTab`
will be called for both the frame in question as well as
the outer webContents hosting it.
Shelley Vohr 5 years ago
parent
commit
bf9b001989

+ 4 - 0
atom/browser/api/atom_api_web_contents.cc

@@ -837,6 +837,10 @@ void WebContents::DidChangeThemeColor(SkColor theme_color) {
   }
 }
 
+void WebContents::DidAcquireFullscreen(content::RenderFrameHost* rfh) {
+  set_fullscreen_frame(rfh);
+}
+
 void WebContents::DocumentLoadedInFrame(
     content::RenderFrameHost* render_frame_host) {
   if (!render_frame_host->GetParent())

+ 1 - 0
atom/browser/api/atom_api_web_contents.h

@@ -448,6 +448,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
       const MediaPlayerId& id,
       content::WebContentsObserver::MediaStoppedReason reason) override;
   void DidChangeThemeColor(SkColor theme_color) override;
+  void DidAcquireFullscreen(content::RenderFrameHost* rfh) override;
 
   // InspectableWebContentsDelegate:
   void DevToolsReloadPage() override;

+ 4 - 2
atom/browser/common_web_contents_delegate.cc

@@ -322,9 +322,12 @@ void CommonWebContentsDelegate::EnterFullscreenModeForTab(
     const blink::WebFullscreenOptions& options) {
   if (!owner_window_)
     return;
+  if (IsFullscreenForTabOrPending(source)) {
+    DCHECK_EQ(fullscreen_frame_, source->GetFocusedFrame());
+    return;
+  }
   SetHtmlApiFullscreen(true);
   owner_window_->NotifyWindowEnterHtmlFullScreen();
-  source->GetRenderViewHost()->GetWidget()->SynchronizeVisualProperties();
 }
 
 void CommonWebContentsDelegate::ExitFullscreenModeForTab(
@@ -333,7 +336,6 @@ void CommonWebContentsDelegate::ExitFullscreenModeForTab(
     return;
   SetHtmlApiFullscreen(false);
   owner_window_->NotifyWindowLeaveHtmlFullScreen();
-  source->GetRenderViewHost()->GetWidget()->SynchronizeVisualProperties();
 }
 
 bool CommonWebContentsDelegate::IsFullscreenForTabOrPending(

+ 7 - 0
atom/browser/common_web_contents_delegate.h

@@ -68,6 +68,10 @@ class CommonWebContentsDelegate : public content::WebContentsDelegate,
 
   bool is_html_fullscreen() const { return html_fullscreen_; }
 
+  void set_fullscreen_frame(content::RenderFrameHost* rfh) {
+    fullscreen_frame_ = rfh;
+  }
+
  protected:
 #if BUILDFLAG(ENABLE_OSR)
   virtual OffScreenWebContentsView* GetOffScreenWebContentsView() const;
@@ -203,6 +207,9 @@ class CommonWebContentsDelegate : public content::WebContentsDelegate,
 
   scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
 
+  // Stores the frame thats currently in fullscreen, nullptr if there is none.
+  content::RenderFrameHost* fullscreen_frame_ = nullptr;
+
   base::WeakPtrFactory<CommonWebContentsDelegate> weak_factory_;
 
   DISALLOW_COPY_AND_ASSIGN(CommonWebContentsDelegate);