1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef DOM_WAKELOCKSENTINEL_H_
8 #define DOM_WAKELOCKSENTINEL_H_
10 #include "js/TypeDecls.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/DOMEventTargetHelper.h"
13 #include "mozilla/TimeStamp.h"
14 #include "mozilla/dom/WakeLockBinding.h"
16 namespace mozilla::dom
{
20 } // namespace mozilla::dom
22 namespace mozilla::dom
{
24 class WakeLockSentinel final
: public DOMEventTargetHelper
{
26 WakeLockSentinel(nsIGlobalObject
* aOwnerWindow
, WakeLockType aType
)
27 : DOMEventTargetHelper(aOwnerWindow
),
29 mCreationTime(TimeStamp::Now()) {}
33 MOZ_DIAGNOSTIC_ASSERT(mReleased
);
34 MOZ_DIAGNOSTIC_ASSERT(!mHoldsActualLock
);
38 JSObject
* WrapObject(JSContext
* aCx
,
39 JS::Handle
<JSObject
*> aGivenProto
) override
;
41 bool Released() const;
43 WakeLockType
Type() const { return mType
; }
46 already_AddRefed
<Promise
> ReleaseLock(ErrorResult
& aRv
);
49 void NotifyLockReleased();
51 IMPL_EVENT_HANDLER(release
);
53 // Acquire underlying system wake lock by modifying the HAL wake lock counter
54 void AcquireActualLock();
59 bool mReleased
= false;
62 * To avoid user fingerprinting, WakeLockJS::Request will provide a
63 * WakeLockSentinel even if the lock type is not applicable or cannot be
65 * But when releasing this sentinel, we have to know whether
66 * AcquireActualLock was called.
68 * https://w3c.github.io/screen-wake-lock/#dfn-applicable-wake-lock
69 * https://w3c.github.io/screen-wake-lock/#the-request-method
71 bool mHoldsActualLock
= false;
73 // Time when this object was created
74 TimeStamp mCreationTime
;
77 } // namespace mozilla::dom
79 #endif // DOM_WAKELOCKSENTINEL_H_