forked from mirrors/gecko-dev
Bug 1589554 - Part 3: Screen Wake Lock permission integration. r=webidl,dom-core,smaug,pbz,edgar
Depends on D189509 Differential Revision: https://phabricator.services.mozilla.com/D189510
This commit is contained in:
parent
248841bc9c
commit
f0dc3526ed
9 changed files with 37 additions and 18 deletions
|
|
@ -19,7 +19,8 @@ static const nsLiteralCString kPermissionTypes[] = {
|
||||||
// "midi" is the only public permission but internally we have both "midi"
|
// "midi" is the only public permission but internally we have both "midi"
|
||||||
// and "midi-sysex" (and yes, this is confusing).
|
// and "midi-sysex" (and yes, this is confusing).
|
||||||
"midi"_ns,
|
"midi"_ns,
|
||||||
"storage-access"_ns
|
"storage-access"_ns,
|
||||||
|
"screen-wake-lock"_ns
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ CreatePermissionStatus(JSContext* aCx, JS::Handle<JSObject*> aPermission,
|
||||||
case PermissionName::Notifications:
|
case PermissionName::Notifications:
|
||||||
case PermissionName::Push:
|
case PermissionName::Push:
|
||||||
case PermissionName::Persistent_storage:
|
case PermissionName::Persistent_storage:
|
||||||
|
case PermissionName::Screen_wake_lock:
|
||||||
return PermissionStatus::Create(aWindow, permission.mName);
|
return PermissionStatus::Create(aWindow, permission.mName);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "ErrorList.h"
|
#include "ErrorList.h"
|
||||||
|
#include "mozilla/AlreadyAddRefed.h"
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
#include "mozilla/dom/Document.h"
|
#include "mozilla/dom/Document.h"
|
||||||
#include "mozilla/dom/Event.h"
|
#include "mozilla/dom/Event.h"
|
||||||
|
|
@ -18,6 +19,9 @@
|
||||||
#include "nsIGlobalObject.h"
|
#include "nsIGlobalObject.h"
|
||||||
#include "nsISupports.h"
|
#include "nsISupports.h"
|
||||||
#include "nsPIDOMWindow.h"
|
#include "nsPIDOMWindow.h"
|
||||||
|
#include "nsContentPermissionHelper.h"
|
||||||
|
#include "nscore.h"
|
||||||
|
#include "WakeLock.h"
|
||||||
#include "WakeLockJS.h"
|
#include "WakeLockJS.h"
|
||||||
#include "WakeLockSentinel.h"
|
#include "WakeLockSentinel.h"
|
||||||
|
|
||||||
|
|
@ -35,6 +39,8 @@ nsLiteralCString WakeLockJS::GetRequestErrorMessage(RequestError aRv) {
|
||||||
return "The pref dom.screenwakelock.enabled is disabled."_ns;
|
return "The pref dom.screenwakelock.enabled is disabled."_ns;
|
||||||
case RequestError::InternalFailure:
|
case RequestError::InternalFailure:
|
||||||
return "A browser-internal error occured."_ns;
|
return "A browser-internal error occured."_ns;
|
||||||
|
case RequestError::PermissionDenied:
|
||||||
|
return "Permission to request screen-wake-lock was denied."_ns;
|
||||||
default:
|
default:
|
||||||
MOZ_ASSERT_UNREACHABLE("Unknown error reason");
|
MOZ_ASSERT_UNREACHABLE("Unknown error reason");
|
||||||
return "Unknown error"_ns;
|
return "Unknown error"_ns;
|
||||||
|
|
@ -126,7 +132,7 @@ WakeLockJS::Obtain(WakeLockType aType) {
|
||||||
lock->AcquireActualLock();
|
lock->AcquireActualLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Steps 7.3.4., 7.3.5. Append lock to locks and resolve promise with lock
|
// Steps 7.3.4. append lock to locks
|
||||||
doc->ActiveWakeLocks(aType).Insert(lock);
|
doc->ActiveWakeLocks(aType).Insert(lock);
|
||||||
|
|
||||||
return lock.forget();
|
return lock.forget();
|
||||||
|
|
@ -148,9 +154,11 @@ already_AddRefed<Promise> WakeLockJS::Request(WakeLockType aType,
|
||||||
return promise.forget();
|
return promise.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 7.1. Requesting permission to use screen-wake-lock
|
// For now, we don't check the permission as we always grant the lock
|
||||||
// Note: implemented in a future part, for now always try to obtain
|
// Step 7.3. Queue a task
|
||||||
auto lockOrErr = Obtain(aType);
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||||
|
"ObtainWakeLock", [aType, promise, self = RefPtr<WakeLockJS>(this)]() {
|
||||||
|
auto lockOrErr = self->Obtain(aType);
|
||||||
if (lockOrErr.isOk()) {
|
if (lockOrErr.isOk()) {
|
||||||
RefPtr<WakeLockSentinel> lock = lockOrErr.unwrap();
|
RefPtr<WakeLockSentinel> lock = lockOrErr.unwrap();
|
||||||
promise->MaybeResolve(lock);
|
promise->MaybeResolve(lock);
|
||||||
|
|
@ -158,6 +166,7 @@ already_AddRefed<Promise> WakeLockJS::Request(WakeLockType aType,
|
||||||
promise->MaybeRejectWithNotAllowedError(
|
promise->MaybeRejectWithNotAllowedError(
|
||||||
GetRequestErrorMessage(lockOrErr.unwrapErr()));
|
GetRequestErrorMessage(lockOrErr.unwrapErr()));
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
return promise.forget();
|
return promise.forget();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,8 @@ class WakeLockJS final : public nsIDOMEventListener,
|
||||||
DocHidden,
|
DocHidden,
|
||||||
PolicyDisallowed,
|
PolicyDisallowed,
|
||||||
PrefDisabled,
|
PrefDisabled,
|
||||||
InternalFailure
|
InternalFailure,
|
||||||
|
PermissionDenied
|
||||||
};
|
};
|
||||||
|
|
||||||
static nsLiteralCString GetRequestErrorMessage(RequestError aRv);
|
static nsLiteralCString GetRequestErrorMessage(RequestError aRv);
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ enum PermissionName {
|
||||||
"push",
|
"push",
|
||||||
"persistent-storage",
|
"persistent-storage",
|
||||||
"midi",
|
"midi",
|
||||||
"storage-access" // Defined in https://privacycg.github.io/storage-access/#permissions-integration
|
"storage-access", // Defined in https://privacycg.github.io/storage-access/#permissions-integration
|
||||||
|
"screen-wake-lock" // Defined in https://w3c.github.io/screen-wake-lock/
|
||||||
};
|
};
|
||||||
|
|
||||||
[GenerateInit]
|
[GenerateInit]
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,8 @@ static const DelegateInfo sPermissionsMap[] = {
|
||||||
{"microphone", u"microphone", DelegatePolicy::eDelegateUseFeaturePolicy},
|
{"microphone", u"microphone", DelegatePolicy::eDelegateUseFeaturePolicy},
|
||||||
{"screen", u"display-capture", DelegatePolicy::eDelegateUseFeaturePolicy},
|
{"screen", u"display-capture", DelegatePolicy::eDelegateUseFeaturePolicy},
|
||||||
{"xr", u"xr-spatial-tracking", DelegatePolicy::eDelegateUseFeaturePolicy},
|
{"xr", u"xr-spatial-tracking", DelegatePolicy::eDelegateUseFeaturePolicy},
|
||||||
};
|
{"screen-wake-lock", u"screen-wake-lock",
|
||||||
|
DelegatePolicy::eDelegateUseFeaturePolicy}};
|
||||||
|
|
||||||
static_assert(PermissionDelegateHandler::DELEGATED_PERMISSION_COUNT ==
|
static_assert(PermissionDelegateHandler::DELEGATED_PERMISSION_COUNT ==
|
||||||
(sizeof(sPermissionsMap) / sizeof(DelegateInfo)),
|
(sizeof(sPermissionsMap) / sizeof(DelegateInfo)),
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class PermissionDelegateHandler final : public nsIPermissionDelegateHandler {
|
||||||
explicit PermissionDelegateHandler() = default;
|
explicit PermissionDelegateHandler() = default;
|
||||||
explicit PermissionDelegateHandler(mozilla::dom::Document* aDocument);
|
explicit PermissionDelegateHandler(mozilla::dom::Document* aDocument);
|
||||||
|
|
||||||
static constexpr size_t DELEGATED_PERMISSION_COUNT = 12;
|
static constexpr size_t DELEGATED_PERMISSION_COUNT = 13;
|
||||||
|
|
||||||
typedef struct DelegatedPermissionList {
|
typedef struct DelegatedPermissionList {
|
||||||
Array<uint32_t, DELEGATED_PERMISSION_COUNT> mPermissions;
|
Array<uint32_t, DELEGATED_PERMISSION_COUNT> mPermissions;
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ bool HasDefaultPref(const nsACString& aType) {
|
||||||
// set under the permissions.default.* pref.
|
// set under the permissions.default.* pref.
|
||||||
static const nsLiteralCString kPermissionsWithDefaults[] = {
|
static const nsLiteralCString kPermissionsWithDefaults[] = {
|
||||||
"camera"_ns, "microphone"_ns, "geo"_ns, "desktop-notification"_ns,
|
"camera"_ns, "microphone"_ns, "geo"_ns, "desktop-notification"_ns,
|
||||||
"shortcuts"_ns};
|
"shortcuts"_ns, "screen-wake-lock"_ns};
|
||||||
|
|
||||||
if (!aType.IsEmpty()) {
|
if (!aType.IsEmpty()) {
|
||||||
for (const auto& perm : kPermissionsWithDefaults) {
|
for (const auto& perm : kPermissionsWithDefaults) {
|
||||||
|
|
|
||||||
|
|
@ -12819,6 +12819,11 @@
|
||||||
value: 1
|
value: 1
|
||||||
mirror: always
|
mirror: always
|
||||||
|
|
||||||
|
- name: permissions.default.screen-wake-lock
|
||||||
|
type: RelaxedAtomicUint32
|
||||||
|
value: 1
|
||||||
|
mirror: always
|
||||||
|
|
||||||
- name: permissions.isolateBy.userContext
|
- name: permissions.isolateBy.userContext
|
||||||
type: RelaxedAtomicBool
|
type: RelaxedAtomicBool
|
||||||
value: false
|
value: false
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue