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
Родитель 2d46164ce0
Коммит 34e54b93a4
7 изменённых файлов: 39 добавлений и 23 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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