Bumping manifests a=b2g-bump
[gecko.git] / dom / power / WakeLock.h
blob8a187a9eb50bc6a1f7537651638c8c22237e7812
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
9 #include "nsCOMPtr.h"
10 #include "nsIDOMEventListener.h"
11 #include "nsIObserver.h"
12 #include "nsString.h"
13 #include "nsWeakReference.h"
14 #include "nsWrapperCache.h"
15 #include "mozilla/ErrorResult.h"
17 class nsIDOMWindow;
19 namespace mozilla {
20 namespace dom {
22 class ContentParent;
24 class WakeLock MOZ_FINAL
25 : public nsIDOMEventListener
26 , public nsWrapperCache
27 , public nsIObserver
28 , public nsSupportsWeakReference
30 public:
31 NS_DECL_NSIDOMEVENTLISTENER
32 NS_DECL_NSIOBSERVER
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.
42 WakeLock();
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
46 // invisible.
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);
54 // WebIDL methods
56 nsISupports* GetParentObject() const;
58 virtual JSObject*
59 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
61 void GetTopic(nsAString& aTopic);
63 void Unlock(ErrorResult& aRv);
65 private:
66 virtual ~WakeLock();
68 void DoUnlock();
69 void DoLock();
70 void AttachEventListener();
71 void DetachEventListener();
73 bool mLocked;
74 bool mHidden;
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
78 // current process.
79 uint64_t mContentParentID;
80 nsString mTopic;
82 // window that this was created for. Weak reference.
83 nsWeakPtr mWindow;
86 } // namespace dom
87 } // namespace mozilla
89 #endif // mozilla_dom_power_WakeLock_h