Remove WebContentsUserData::kLocatorKey

https://chromium-review.googlesource.com/c/chromium/src/+/1093015
This commit is contained in:
Jeremy Apthorp 2018-10-02 15:14:43 -07:00
parent 2d46164ce0
commit 34e54b93a4
7 changed files with 39 additions and 23 deletions

View file

@ -462,7 +462,7 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
auto* relay = auto* relay =
NativeWindowRelay::FromWebContents(embedder_->web_contents()); NativeWindowRelay::FromWebContents(embedder_->web_contents());
if (relay) if (relay)
owner_window = relay->window.get(); owner_window = relay->GetNativeWindow();
} }
if (owner_window) if (owner_window)
SetOwnerWindow(owner_window); SetOwnerWindow(owner_window);
@ -985,7 +985,8 @@ 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 = devtools->GetUserData(NativeWindowRelay::UserDataKey()); bool has_window =
devtools->GetUserData(NativeWindowRelay::kNativeWindowRelayUserDataKey);
if (owner_window() && !has_window) if (owner_window() && !has_window)
handle->SetOwnerWindow(devtools, owner_window()); handle->SetOwnerWindow(devtools, owner_window());
@ -1820,7 +1821,8 @@ gfx::Size WebContents::GetSizeForNewRenderView(content::WebContents* wc) const {
if (IsOffScreen() && wc == web_contents()) { if (IsOffScreen() && wc == web_contents()) {
auto* relay = NativeWindowRelay::FromWebContents(web_contents()); auto* relay = NativeWindowRelay::FromWebContents(web_contents());
if (relay) { if (relay) {
return relay->window->GetSize(); auto* owner_window = relay->GetNativeWindow();
return owner_window ? owner_window->GetSize() : gfx::Size();
} }
} }
@ -1913,7 +1915,7 @@ void WebContents::SetEmbedder(const WebContents* embedder) {
NativeWindow* owner_window = nullptr; NativeWindow* owner_window = nullptr;
auto* relay = NativeWindowRelay::FromWebContents(embedder->web_contents()); auto* relay = NativeWindowRelay::FromWebContents(embedder->web_contents());
if (relay) { if (relay) {
owner_window = relay->window.get(); owner_window = relay->GetNativeWindow();
} }
if (owner_window) if (owner_window)
SetOwnerWindow(owner_window); SetOwnerWindow(owner_window);

View file

@ -86,7 +86,7 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
auto* relay = auto* relay =
web_contents ? NativeWindowRelay::FromWebContents(web_contents) : nullptr; web_contents ? NativeWindowRelay::FromWebContents(web_contents) : nullptr;
if (relay) if (relay)
window = relay->window.get(); window = relay->GetNativeWindow();
auto* web_preferences = WebContentsPreferences::From(web_contents); auto* web_preferences = WebContentsPreferences::From(web_contents);
bool offscreen = bool offscreen =

View file

@ -72,7 +72,7 @@ void AtomJavaScriptDialogManager::RunJavaScriptDialog(
if (web_preferences && !web_preferences->IsEnabled(options::kOffscreen)) { if (web_preferences && !web_preferences->IsEnabled(options::kOffscreen)) {
auto* relay = NativeWindowRelay::FromWebContents(web_contents); auto* relay = NativeWindowRelay::FromWebContents(web_contents);
if (relay) if (relay)
window = relay->window.get(); window = relay->GetNativeWindow();
} }
atom::ShowMessageBox( atom::ShowMessageBox(

View file

@ -189,17 +189,17 @@ void CommonWebContentsDelegate::SetOwnerWindow(NativeWindow* owner_window) {
void CommonWebContentsDelegate::SetOwnerWindow( void CommonWebContentsDelegate::SetOwnerWindow(
content::WebContents* web_contents, content::WebContents* web_contents,
NativeWindow* owner_window) { NativeWindow* owner_window) {
owner_window_ = owner_window ? owner_window->GetWeakPtr() : nullptr;
auto relay = std::make_unique<NativeWindowRelay>(owner_window_);
auto* relay_key = relay->key;
if (owner_window) { if (owner_window) {
owner_window_ = owner_window->GetWeakPtr();
#if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX) #if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX)
autofill_popup_.reset(new AutofillPopup()); autofill_popup_.reset(new AutofillPopup());
#endif #endif
web_contents->SetUserData(relay_key, std::move(relay)); NativeWindowRelay::CreateForWebContents(web_contents,
owner_window->GetWeakPtr());
} else { } else {
web_contents->RemoveUserData(relay_key); owner_window_ = nullptr;
relay.reset(); web_contents->RemoveUserData(
NativeWindowRelay::kNativeWindowRelayUserDataKey);
} }
} }

View file

@ -21,8 +21,6 @@
#include "ui/display/win/screen_win.h" #include "ui/display/win/screen_win.h"
#endif #endif
DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::NativeWindowRelay);
namespace atom { namespace atom {
namespace { namespace {
@ -577,8 +575,22 @@ const views::Widget* NativeWindow::GetWidget() const {
return widget(); 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)));
}
NativeWindowRelay::NativeWindowRelay(base::WeakPtr<NativeWindow> window) NativeWindowRelay::NativeWindowRelay(base::WeakPtr<NativeWindow> window)
: key(UserDataKey()), window(window) {} : native_window_(window) {}
NativeWindowRelay::~NativeWindowRelay() = default; NativeWindowRelay::~NativeWindowRelay() = default;

View file

@ -346,18 +346,20 @@ class NativeWindow : public base::SupportsUserData,
class NativeWindowRelay class NativeWindowRelay
: public content::WebContentsUserData<NativeWindowRelay> { : public content::WebContentsUserData<NativeWindowRelay> {
public: public:
explicit NativeWindowRelay(base::WeakPtr<NativeWindow> window); static const void* const kNativeWindowRelayUserDataKey;
static void CreateForWebContents(content::WebContents*,
base::WeakPtr<NativeWindow>);
~NativeWindowRelay() override; ~NativeWindowRelay() override;
static void* UserDataKey() { NativeWindow* GetNativeWindow() const { return native_window_.get(); }
return content::WebContentsUserData<NativeWindowRelay>::UserDataKey();
}
void* key;
base::WeakPtr<NativeWindow> window;
private: private:
friend class content::WebContentsUserData<NativeWindow>; friend class content::WebContentsUserData<NativeWindow>;
explicit NativeWindowRelay(base::WeakPtr<NativeWindow> window);
base::WeakPtr<NativeWindow> native_window_;
}; };
} // namespace atom } // namespace atom

View file

@ -329,7 +329,7 @@ void WebContentsPreferences::AppendCommandLineSwitches(
if (embedder) { if (embedder) {
auto* relay = NativeWindowRelay::FromWebContents(embedder); auto* relay = NativeWindowRelay::FromWebContents(embedder);
if (relay) { if (relay) {
auto* window = relay->window.get(); auto* window = relay->GetNativeWindow();
if (window) { if (window) {
const bool visible = window->IsVisible() && !window->IsMinimized(); const bool visible = window->IsVisible() && !window->IsMinimized();
if (!visible) { if (!visible) {