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"
|
||||
// and "midi-sysex" (and yes, this is confusing).
|
||||
"midi"_ns,
|
||||
"storage-access"_ns
|
||||
"storage-access"_ns,
|
||||
"screen-wake-lock"_ns
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ CreatePermissionStatus(JSContext* aCx, JS::Handle<JSObject*> aPermission,
|
|||
case PermissionName::Notifications:
|
||||
case PermissionName::Push:
|
||||
case PermissionName::Persistent_storage:
|
||||
case PermissionName::Screen_wake_lock:
|
||||
return PermissionStatus::Create(aWindow, permission.mName);
|
||||
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "ErrorList.h"
|
||||
#include "mozilla/AlreadyAddRefed.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "mozilla/dom/Event.h"
|
||||
|
|
@ -18,6 +19,9 @@
|
|||
#include "nsIGlobalObject.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsContentPermissionHelper.h"
|
||||
#include "nscore.h"
|
||||
#include "WakeLock.h"
|
||||
#include "WakeLockJS.h"
|
||||
#include "WakeLockSentinel.h"
|
||||
|
||||
|
|
@ -35,6 +39,8 @@ nsLiteralCString WakeLockJS::GetRequestErrorMessage(RequestError aRv) {
|
|||
return "The pref dom.screenwakelock.enabled is disabled."_ns;
|
||||
case RequestError::InternalFailure:
|
||||
return "A browser-internal error occured."_ns;
|
||||
case RequestError::PermissionDenied:
|
||||
return "Permission to request screen-wake-lock was denied."_ns;
|
||||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("Unknown error reason");
|
||||
return "Unknown error"_ns;
|
||||
|
|
@ -126,7 +132,7 @@ WakeLockJS::Obtain(WakeLockType aType) {
|
|||
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);
|
||||
|
||||
return lock.forget();
|
||||
|
|
@ -148,16 +154,19 @@ already_AddRefed<Promise> WakeLockJS::Request(WakeLockType aType,
|
|||
return promise.forget();
|
||||
}
|
||||
|
||||
// Step 7.1. Requesting permission to use screen-wake-lock
|
||||
// Note: implemented in a future part, for now always try to obtain
|
||||
auto lockOrErr = Obtain(aType);
|
||||
if (lockOrErr.isOk()) {
|
||||
RefPtr<WakeLockSentinel> lock = lockOrErr.unwrap();
|
||||
promise->MaybeResolve(lock);
|
||||
} else {
|
||||
promise->MaybeRejectWithNotAllowedError(
|
||||
GetRequestErrorMessage(lockOrErr.unwrapErr()));
|
||||
}
|
||||
// For now, we don't check the permission as we always grant the lock
|
||||
// Step 7.3. Queue a task
|
||||
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||
"ObtainWakeLock", [aType, promise, self = RefPtr<WakeLockJS>(this)]() {
|
||||
auto lockOrErr = self->Obtain(aType);
|
||||
if (lockOrErr.isOk()) {
|
||||
RefPtr<WakeLockSentinel> lock = lockOrErr.unwrap();
|
||||
promise->MaybeResolve(lock);
|
||||
} else {
|
||||
promise->MaybeRejectWithNotAllowedError(
|
||||
GetRequestErrorMessage(lockOrErr.unwrapErr()));
|
||||
}
|
||||
}));
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ class WakeLockJS final : public nsIDOMEventListener,
|
|||
DocHidden,
|
||||
PolicyDisallowed,
|
||||
PrefDisabled,
|
||||
InternalFailure
|
||||
InternalFailure,
|
||||
PermissionDenied
|
||||
};
|
||||
|
||||
static nsLiteralCString GetRequestErrorMessage(RequestError aRv);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ enum PermissionName {
|
|||
"push",
|
||||
"persistent-storage",
|
||||
"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]
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ static const DelegateInfo sPermissionsMap[] = {
|
|||
{"microphone", u"microphone", DelegatePolicy::eDelegateUseFeaturePolicy},
|
||||
{"screen", u"display-capture", DelegatePolicy::eDelegateUseFeaturePolicy},
|
||||
{"xr", u"xr-spatial-tracking", DelegatePolicy::eDelegateUseFeaturePolicy},
|
||||
};
|
||||
{"screen-wake-lock", u"screen-wake-lock",
|
||||
DelegatePolicy::eDelegateUseFeaturePolicy}};
|
||||
|
||||
static_assert(PermissionDelegateHandler::DELEGATED_PERMISSION_COUNT ==
|
||||
(sizeof(sPermissionsMap) / sizeof(DelegateInfo)),
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class PermissionDelegateHandler final : public nsIPermissionDelegateHandler {
|
|||
explicit PermissionDelegateHandler() = default;
|
||||
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 {
|
||||
Array<uint32_t, DELEGATED_PERMISSION_COUNT> mPermissions;
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ bool HasDefaultPref(const nsACString& aType) {
|
|||
// A list of permissions that can have a fallback default permission
|
||||
// set under the permissions.default.* pref.
|
||||
static const nsLiteralCString kPermissionsWithDefaults[] = {
|
||||
"camera"_ns, "microphone"_ns, "geo"_ns, "desktop-notification"_ns,
|
||||
"shortcuts"_ns};
|
||||
"camera"_ns, "microphone"_ns, "geo"_ns, "desktop-notification"_ns,
|
||||
"shortcuts"_ns, "screen-wake-lock"_ns};
|
||||
|
||||
if (!aType.IsEmpty()) {
|
||||
for (const auto& perm : kPermissionsWithDefaults) {
|
||||
|
|
|
|||
|
|
@ -12819,6 +12819,11 @@
|
|||
value: 1
|
||||
mirror: always
|
||||
|
||||
- name: permissions.default.screen-wake-lock
|
||||
type: RelaxedAtomicUint32
|
||||
value: 1
|
||||
mirror: always
|
||||
|
||||
- name: permissions.isolateBy.userContext
|
||||
type: RelaxedAtomicBool
|
||||
value: false
|
||||
|
|
|
|||
Loading…
Reference in a new issue