1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_power_WakeLock_h
7 #define mozilla_dom_power_WakeLock_h
10 #include "nsIDOMEventListener.h"
11 #include "nsIObserver.h"
13 #include "nsWeakReference.h"
14 #include "nsWrapperCache.h"
15 #include "mozilla/ErrorResult.h"
24 class WakeLock MOZ_FINAL
25 : public nsIDOMEventListener
26 , public nsWrapperCache
28 , public nsSupportsWeakReference
31 NS_DECL_NSIDOMEVENTLISTENER
34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
35 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(WakeLock
, nsIDOMEventListener
)
37 // Note: WakeLock lives for the lifetime of the document in order to avoid
38 // exposing GC behavior to pages. This means that
39 // |var foo = navigator.requestWakeLock('cpu'); foo = null;|
40 // doesn't unlock the 'cpu' resource.
44 // Initialize this wake lock on behalf of the given window. Null windows are
45 // allowed; a lock without an associated window is always considered
47 nsresult
Init(const nsAString
&aTopic
, nsIDOMWindow
* aWindow
);
49 // Initialize this wake lock on behalf of the given process. If the process
50 // dies, the lock is released. A wake lock initialized via this method is
51 // always considered visible.
52 nsresult
Init(const nsAString
&aTopic
, ContentParent
* aContentParent
);
56 nsISupports
* GetParentObject() const;
59 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
61 void GetTopic(nsAString
& aTopic
);
63 void Unlock(ErrorResult
& aRv
);
70 void AttachEventListener();
71 void DetachEventListener();
76 // The ID of the ContentParent on behalf of whom we acquired this lock, or
77 // CONTENT_PROCESS_UNKNOWN_ID if this lock was acquired on behalf of the
79 uint64_t mContentParentID
;
82 // window that this was created for. Weak reference.
87 } // namespace mozilla
89 #endif // mozilla_dom_power_WakeLock_h