content: Fix WebContentsUserData for usage across components.

1354402
This commit is contained in:
deepak1556 2019-01-21 22:26:54 +05:30
parent a864167d46
commit 9439ac108d
16 changed files with 48 additions and 15 deletions

View file

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

View file

@ -31,9 +31,13 @@ class WebContentsViewRelay
atom::api::WebContentsView* view_ = nullptr; atom::api::WebContentsView* view_ = nullptr;
WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(WebContentsViewRelay); DISALLOW_COPY_AND_ASSIGN(WebContentsViewRelay);
}; };
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsViewRelay)
} // namespace } // namespace
namespace atom { namespace atom {

View file

@ -0,0 +1,14 @@
// Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/child_web_contents_tracker.h"
namespace atom {
ChildWebContentsTracker::ChildWebContentsTracker(
content::WebContents* web_contents) {}
WEB_CONTENTS_USER_DATA_KEY_IMPL(ChildWebContentsTracker)
} // namespace atom

View file

@ -18,11 +18,12 @@ struct ChildWebContentsTracker
GURL url; GURL url;
std::string frame_name; std::string frame_name;
explicit ChildWebContentsTracker(content::WebContents* web_contents) {}
private: private:
explicit ChildWebContentsTracker(content::WebContents* web_contents);
friend class content::WebContentsUserData<ChildWebContentsTracker>; friend class content::WebContentsUserData<ChildWebContentsTracker>;
WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(ChildWebContentsTracker); DISALLOW_COPY_AND_ASSIGN(ChildWebContentsTracker);
}; };

View file

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

View file

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

View file

@ -360,8 +360,6 @@ class NativeWindow : public base::SupportsUserData,
class NativeWindowRelay class NativeWindowRelay
: public content::WebContentsUserData<NativeWindowRelay> { : public content::WebContentsUserData<NativeWindowRelay> {
public: public:
static const void* const kNativeWindowRelayUserDataKey;
static void CreateForWebContents(content::WebContents*, static void CreateForWebContents(content::WebContents*,
base::WeakPtr<NativeWindow>); base::WeakPtr<NativeWindow>);
@ -369,6 +367,8 @@ class NativeWindowRelay
NativeWindow* GetNativeWindow() const { return native_window_.get(); } NativeWindow* GetNativeWindow() const { return native_window_.get(); }
WEB_CONTENTS_USER_DATA_KEY_DECL();
private: private:
friend class content::WebContentsUserData<NativeWindow>; friend class content::WebContentsUserData<NativeWindow>;
explicit NativeWindowRelay(base::WeakPtr<NativeWindow> window); explicit NativeWindowRelay(base::WeakPtr<NativeWindow> window);

View file

@ -195,4 +195,6 @@ void PrintPreviewMessageHandler::RejectPromise(int request_id) {
promise->RejectWithErrorMessage("Failed to generate PDF"); promise->RejectWithErrorMessage("Failed to generate PDF");
} }
WEB_CONTENTS_USER_DATA_KEY_IMPL(PrintPreviewMessageHandler)
} // namespace atom } // namespace atom

View file

@ -67,6 +67,8 @@ class PrintPreviewMessageHandler
base::WeakPtrFactory<PrintPreviewMessageHandler> weak_ptr_factory_; base::WeakPtrFactory<PrintPreviewMessageHandler> weak_ptr_factory_;
WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(PrintPreviewMessageHandler); DISALLOW_COPY_AND_ASSIGN(PrintPreviewMessageHandler);
}; };

View file

@ -154,4 +154,6 @@ bool WebContentsPermissionHelper::CheckMediaAccessPermission(
return CheckPermission(content::PermissionType::AUDIO_CAPTURE, &details); return CheckPermission(content::PermissionType::AUDIO_CAPTURE, &details);
} }
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsPermissionHelper)
} // namespace atom } // namespace atom

View file

@ -53,6 +53,8 @@ class WebContentsPermissionHelper
content::WebContents* web_contents_; content::WebContents* web_contents_;
WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(WebContentsPermissionHelper); DISALLOW_COPY_AND_ASSIGN(WebContentsPermissionHelper);
}; };

View file

@ -436,4 +436,6 @@ void WebContentsPreferences::OverrideWebkitPrefs(
prefs->default_encoding = encoding; prefs->default_encoding = encoding;
} }
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsPreferences)
} // namespace atom } // namespace atom

View file

@ -82,6 +82,8 @@ class WebContentsPreferences
base::Value preference_ = base::Value(base::Value::Type::DICTIONARY); base::Value preference_ = base::Value(base::Value::Type::DICTIONARY);
base::Value last_preference_ = base::Value(base::Value::Type::DICTIONARY); base::Value last_preference_ = base::Value(base::Value::Type::DICTIONARY);
WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences); DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences);
}; };

View file

@ -278,4 +278,6 @@ void WebContentsZoomController::SetZoomFactorOnNavigationIfNeeded(
SetZoomLevel(zoom_level); SetZoomLevel(zoom_level);
} }
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsZoomController)
} // namespace atom } // namespace atom

View file

@ -112,6 +112,8 @@ class WebContentsZoomController
content::HostZoomMap* host_zoom_map_; content::HostZoomMap* host_zoom_map_;
WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(WebContentsZoomController); DISALLOW_COPY_AND_ASSIGN(WebContentsZoomController);
}; };

View file

@ -251,6 +251,7 @@ filenames = {
"atom/browser/browser_observer.h", "atom/browser/browser_observer.h",
"atom/browser/browser_process_impl.cc", "atom/browser/browser_process_impl.cc",
"atom/browser/browser_process_impl.h", "atom/browser/browser_process_impl.h",
"atom/browser/child_web_contents_tracker.cc",
"atom/browser/child_web_contents_tracker.h", "atom/browser/child_web_contents_tracker.h",
"atom/browser/common_web_contents_delegate_mac.mm", "atom/browser/common_web_contents_delegate_mac.mm",
"atom/browser/common_web_contents_delegate_views.cc", "atom/browser/common_web_contents_delegate_views.cc",