content: Fix WebContentsUserData for usage across components.

https://chromium-review.googlesource.com/c/chromium/src/+/1354402
This commit is contained in:
deepak1556
2019-01-21 22:26:54 +05:30
committed by Samuel Attard
parent eabc5166ac
commit d5c37c301a
16 changed files with 48 additions and 15 deletions

View File

@@ -1012,8 +1012,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());

View File

@@ -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 {

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;
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);
};

View File

@@ -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();

View File

@@ -574,18 +574,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)
@@ -593,4 +590,6 @@ NativeWindowRelay::NativeWindowRelay(base::WeakPtr<NativeWindow> window)
NativeWindowRelay::~NativeWindowRelay() = default;
WEB_CONTENTS_USER_DATA_KEY_IMPL(NativeWindowRelay)
} // namespace atom

View File

@@ -362,8 +362,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>);
@@ -371,6 +369,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);

View File

@@ -180,4 +180,6 @@ void PrintPreviewMessageHandler::RunPrintToPDFCallback(
print_to_pdf_callback_map_.erase(request_id);
}
WEB_CONTENTS_USER_DATA_KEY_IMPL(PrintPreviewMessageHandler)
} // namespace atom

View File

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

View File

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

View File

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

View File

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

View File

@@ -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);
};

View File

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

View File

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

View File

@@ -242,6 +242,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",