Browse Source

fix: HTML5 fullscreen APIs not working in <webview> (#20432)

Milan Burda 5 years ago
parent
commit
c344eca32c

+ 1 - 2
atom/browser/api/atom_api_web_contents.cc

@@ -983,8 +983,7 @@ void WebContents::DevToolsOpened() {
 
   // Inherit owner window in devtools when it doesn't have one.
   auto* devtools = managed_web_contents()->GetDevToolsWebContents();
-  bool has_window =
-      devtools->GetUserData(NativeWindowRelay::kNativeWindowRelayUserDataKey);
+  bool has_window = devtools->GetUserData(NativeWindowRelay::UserDataKey());
   if (owner_window() && !has_window)
     handle->SetOwnerWindow(devtools, owner_window());
 

+ 1 - 2
atom/browser/common_web_contents_delegate.cc

@@ -211,8 +211,7 @@ void CommonWebContentsDelegate::SetOwnerWindow(
                                             owner_window->GetWeakPtr());
   } else {
     owner_window_ = nullptr;
-    web_contents->RemoveUserData(
-        NativeWindowRelay::kNativeWindowRelayUserDataKey);
+    web_contents->RemoveUserData(NativeWindowRelay::UserDataKey());
   }
 #if BUILDFLAG(ENABLE_OSR)
   auto* osr_wcv = GetOffScreenWebContentsView();

+ 4 - 7
atom/browser/native_window.cc

@@ -575,18 +575,15 @@ const views::Widget* NativeWindow::GetWidget() const {
   return widget();
 }
 
-// static
-const void* const NativeWindowRelay::kNativeWindowRelayUserDataKey =
-    &NativeWindowRelay::kNativeWindowRelayUserDataKey;
-
 // static
 void NativeWindowRelay::CreateForWebContents(
     content::WebContents* web_contents,
     base::WeakPtr<NativeWindow> window) {
   DCHECK(web_contents);
-  DCHECK(!web_contents->GetUserData(kNativeWindowRelayUserDataKey));
-  web_contents->SetUserData(kNativeWindowRelayUserDataKey,
-                            base::WrapUnique(new NativeWindowRelay(window)));
+  if (!web_contents->GetUserData(UserDataKey())) {
+    web_contents->SetUserData(UserDataKey(),
+                              base::WrapUnique(new NativeWindowRelay(window)));
+  }
 }
 
 NativeWindowRelay::NativeWindowRelay(base::WeakPtr<NativeWindow> window)

+ 5 - 2
atom/browser/native_window.h

@@ -354,8 +354,6 @@ class NativeWindow : public base::SupportsUserData,
 class NativeWindowRelay
     : public content::WebContentsUserData<NativeWindowRelay> {
  public:
-  static const void* const kNativeWindowRelayUserDataKey;
-
   static void CreateForWebContents(content::WebContents*,
                                    base::WeakPtr<NativeWindow>);
 
@@ -363,6 +361,11 @@ class NativeWindowRelay
 
   NativeWindow* GetNativeWindow() const { return native_window_.get(); }
 
+  // UserDataKey() is protected in content::WebContentsUserData<T>
+  static inline const void* UserDataKey() {
+    return content::WebContentsUserData<NativeWindowRelay>::UserDataKey();
+  }
+
  private:
   friend class content::WebContentsUserData<NativeWindow>;
   explicit NativeWindowRelay(base::WeakPtr<NativeWindow> window);