зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1744524: part 5) Add pref for enabling `clipboard.readText()` gated by a "Paste" button. r=edgar
The web platform test (WPT) framework doesn't support such user agent specific buttons. The corresponding WPTs continue to use the pref "dom.events.testing.asyncClipboard", which skips showing the button. Differential Revision: https://phabricator.services.mozilla.com/D145058
This commit is contained in:
Родитель
eeb75692f4
Коммит
574daa1ebf
|
@ -116,6 +116,31 @@ already_AddRefed<nsIRunnable> Clipboard::ReadTextRequest::Answer() {
|
|||
});
|
||||
}
|
||||
|
||||
static bool IsReadTextExposedToContent() {
|
||||
return StaticPrefs::dom_events_asyncClipboard_readText_DoNotUseDirectly();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIRunnable>
|
||||
Clipboard::CheckReadTextPermissionAndHandleRequest(
|
||||
Promise& aPromise, nsIPrincipal& aSubjectPrincipal) {
|
||||
if (IsTestingPrefEnabledOrHasReadPermission(aSubjectPrincipal)) {
|
||||
MOZ_LOG(GetClipboardLog(), LogLevel::Debug,
|
||||
("%s: testing pref enabled or has read permission", __FUNCTION__));
|
||||
return ReadTextRequest{aPromise, aSubjectPrincipal}.Answer();
|
||||
}
|
||||
|
||||
if (aSubjectPrincipal.GetIsAddonOrExpandedAddonPrincipal()) {
|
||||
// TODO: enable showing the "Paste" button in this case; see bug 1773681.
|
||||
MOZ_LOG(GetClipboardLog(), LogLevel::Debug,
|
||||
("%s: Addon without read permssion.", __FUNCTION__));
|
||||
aPromise.MaybeRejectWithUndefined();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return HandleReadTextRequestWhichRequiresPasteButton(aPromise,
|
||||
aSubjectPrincipal);
|
||||
}
|
||||
|
||||
already_AddRefed<nsIRunnable>
|
||||
Clipboard::HandleReadTextRequestWhichRequiresPasteButton(
|
||||
Promise& aPromise, nsIPrincipal& aSubjectPrincipal) {
|
||||
|
@ -188,18 +213,10 @@ already_AddRefed<Promise> Clipboard::ReadHelper(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// We want to disable security check for automated tests that have the pref
|
||||
// dom.events.testing.asyncClipboard set to true
|
||||
const bool isTestingPrefEnabledOrHasReadPermission =
|
||||
IsTestingPrefEnabledOrHasReadPermission(aSubjectPrincipal);
|
||||
|
||||
switch (aClipboardReadType) {
|
||||
case eReadText: {
|
||||
RefPtr<nsIRunnable> runnable =
|
||||
isTestingPrefEnabledOrHasReadPermission
|
||||
? ReadTextRequest{*p, aSubjectPrincipal}.Answer()
|
||||
: HandleReadTextRequestWhichRequiresPasteButton(
|
||||
*p, aSubjectPrincipal);
|
||||
CheckReadTextPermissionAndHandleRequest(*p, aSubjectPrincipal);
|
||||
|
||||
if (runnable) {
|
||||
GetParentObject()->Dispatch(TaskCategory::Other, runnable.forget());
|
||||
|
@ -208,6 +225,12 @@ already_AddRefed<Promise> Clipboard::ReadHelper(
|
|||
break;
|
||||
}
|
||||
case eRead: {
|
||||
// We want to disable security check for automated tests that have the
|
||||
// pref
|
||||
// dom.events.testing.asyncClipboard set to true
|
||||
const bool isTestingPrefEnabledOrHasReadPermission =
|
||||
IsTestingPrefEnabledOrHasReadPermission(aSubjectPrincipal);
|
||||
|
||||
if (!isTestingPrefEnabledOrHasReadPermission) {
|
||||
MOZ_LOG(GetClipboardLog(), LogLevel::Debug,
|
||||
("Clipboard, ReadHelper, "
|
||||
|
@ -765,7 +788,8 @@ LogModule* Clipboard::GetClipboardLog() { return gClipboardLog; }
|
|||
/* static */
|
||||
bool Clipboard::ReadTextEnabled(JSContext* aCx, JSObject* aGlobal) {
|
||||
nsIPrincipal* prin = nsContentUtils::SubjectPrincipal(aCx);
|
||||
return IsTestingPrefEnabled() || prin->GetIsAddonOrExpandedAddonPrincipal() ||
|
||||
return IsReadTextExposedToContent() ||
|
||||
prin->GetIsAddonOrExpandedAddonPrincipal() ||
|
||||
prin->IsSystemPrincipal();
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,10 @@ class Clipboard : public DOMEventTargetHelper {
|
|||
static bool IsTestingPrefEnabledOrHasReadPermission(
|
||||
nsIPrincipal& aSubjectPrincipal);
|
||||
|
||||
// @return the remaining work to fill aPromise.
|
||||
already_AddRefed<nsIRunnable> CheckReadTextPermissionAndHandleRequest(
|
||||
Promise& aPromise, nsIPrincipal& aSubjectPrincipal);
|
||||
|
||||
// @return the remaining work to fill aPromise.
|
||||
already_AddRefed<nsIRunnable> HandleReadTextRequestWhichRequiresPasteButton(
|
||||
Promise& aPromise, nsIPrincipal& aSubjectPrincipal);
|
||||
|
|
|
@ -2247,6 +2247,7 @@
|
|||
value: false
|
||||
mirror: always
|
||||
|
||||
# Skips checking permission and user activation when accessing the clipboard.
|
||||
# Should only be enabled in tests.
|
||||
# Access with Clipboard::IsTestingPrefEnabled().
|
||||
- name: dom.events.testing.asyncClipboard
|
||||
|
@ -2255,6 +2256,13 @@
|
|||
mirror: always
|
||||
do_not_use_directly: true
|
||||
|
||||
# Control whether `navigator.clipboard.readText()` is exposed to content.
|
||||
- name: dom.events.asyncClipboard.readText
|
||||
type: bool
|
||||
value: false
|
||||
mirror: always
|
||||
do_not_use_directly: true
|
||||
|
||||
# This pref controls whether or not the `protected` dataTransfer state is
|
||||
# enabled. If the `protected` dataTransfer stae is disabled, then the
|
||||
# DataTransfer will be read-only whenever it should be protected, and will not
|
||||
|
|
|
@ -1 +1 @@
|
|||
prefs: [dom.events.asyncClipboard.clipboardItem: true, dom.events.testing.asyncClipboard:true, marionette.setpermission.enabled:true]
|
||||
prefs: [dom.events.asyncClipboard.clipboardItem: true, dom.events.asyncClipboard.readText: true, dom.events.testing.asyncClipboard:true, marionette.setpermission.enabled:true]
|
||||
|
|
Загрузка…
Ссылка в новой задаче