content: Fix WebContentsUserData for usage across components.
https://chromium-review.googlesource.com/c/chromium/src/+/1354402
This commit is contained in:
parent
a864167d46
commit
9439ac108d
16 changed files with 48 additions and 15 deletions
|
@ -999,8 +999,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());
|
||||
|
||||
|
|
|
@ -31,9 +31,13 @@ class WebContentsViewRelay
|
|||
|
||||
atom::api::WebContentsView* view_ = nullptr;
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebContentsViewRelay);
|
||||
};
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsViewRelay)
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace atom {
|
||||
|
|
14
atom/browser/child_web_contents_tracker.cc
Normal file
14
atom/browser/child_web_contents_tracker.cc
Normal 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
|
|
@ -18,11 +18,12 @@ struct ChildWebContentsTracker
|
|||
GURL url;
|
||||
std::string frame_name;
|
||||
|
||||
explicit ChildWebContentsTracker(content::WebContents* web_contents) {}
|
||||
|
||||
private:
|
||||
explicit ChildWebContentsTracker(content::WebContents* web_contents);
|
||||
friend class content::WebContentsUserData<ChildWebContentsTracker>;
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ChildWebContentsTracker);
|
||||
};
|
||||
|
||||
|
|
|
@ -213,8 +213,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();
|
||||
|
|
|
@ -577,18 +577,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)
|
||||
|
@ -596,4 +593,6 @@ NativeWindowRelay::NativeWindowRelay(base::WeakPtr<NativeWindow> window)
|
|||
|
||||
NativeWindowRelay::~NativeWindowRelay() = default;
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_IMPL(NativeWindowRelay)
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -360,8 +360,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>);
|
||||
|
||||
|
@ -369,6 +367,8 @@ class NativeWindowRelay
|
|||
|
||||
NativeWindow* GetNativeWindow() const { return native_window_.get(); }
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
||||
|
||||
private:
|
||||
friend class content::WebContentsUserData<NativeWindow>;
|
||||
explicit NativeWindowRelay(base::WeakPtr<NativeWindow> window);
|
||||
|
|
|
@ -195,4 +195,6 @@ void PrintPreviewMessageHandler::RejectPromise(int request_id) {
|
|||
promise->RejectWithErrorMessage("Failed to generate PDF");
|
||||
}
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_IMPL(PrintPreviewMessageHandler)
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -67,6 +67,8 @@ class PrintPreviewMessageHandler
|
|||
|
||||
base::WeakPtrFactory<PrintPreviewMessageHandler> weak_ptr_factory_;
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PrintPreviewMessageHandler);
|
||||
};
|
||||
|
||||
|
|
|
@ -154,4 +154,6 @@ bool WebContentsPermissionHelper::CheckMediaAccessPermission(
|
|||
return CheckPermission(content::PermissionType::AUDIO_CAPTURE, &details);
|
||||
}
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsPermissionHelper)
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -53,6 +53,8 @@ class WebContentsPermissionHelper
|
|||
|
||||
content::WebContents* web_contents_;
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebContentsPermissionHelper);
|
||||
};
|
||||
|
||||
|
|
|
@ -436,4 +436,6 @@ void WebContentsPreferences::OverrideWebkitPrefs(
|
|||
prefs->default_encoding = encoding;
|
||||
}
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsPreferences)
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -82,6 +82,8 @@ class WebContentsPreferences
|
|||
base::Value 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);
|
||||
};
|
||||
|
||||
|
|
|
@ -278,4 +278,6 @@ void WebContentsZoomController::SetZoomFactorOnNavigationIfNeeded(
|
|||
SetZoomLevel(zoom_level);
|
||||
}
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_IMPL(WebContentsZoomController)
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -112,6 +112,8 @@ class WebContentsZoomController
|
|||
|
||||
content::HostZoomMap* host_zoom_map_;
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebContentsZoomController);
|
||||
};
|
||||
|
||||
|
|
|
@ -251,6 +251,7 @@ filenames = {
|
|||
"atom/browser/browser_observer.h",
|
||||
"atom/browser/browser_process_impl.cc",
|
||||
"atom/browser/browser_process_impl.h",
|
||||
"atom/browser/child_web_contents_tracker.cc",
|
||||
"atom/browser/child_web_contents_tracker.h",
|
||||
"atom/browser/common_web_contents_delegate_mac.mm",
|
||||
"atom/browser/common_web_contents_delegate_views.cc",
|
||||
|
|
Loading…
Reference in a new issue