Bug 1704628 Part 4: Avoid use of ESC to close context menu in browser_toolbox_content...
[gecko.git] / dom / power / WakeLock.h
blob0ccf5c81fd80c688bd11624d9e801213de262c47
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_power_WakeLock_h
8 #define mozilla_dom_power_WakeLock_h
10 #include "nsCOMPtr.h"
11 #include "nsIDOMEventListener.h"
12 #include "nsIObserver.h"
13 #include "nsIWakeLock.h"
14 #include "nsString.h"
15 #include "nsWeakReference.h"
16 #include "nsWrapperCache.h"
18 class nsPIDOMWindowInner;
20 namespace mozilla {
21 class ErrorResult;
23 namespace dom {
24 class Document;
26 class WakeLock final : public nsIDOMEventListener,
27 public nsIObserver,
28 public nsSupportsWeakReference,
29 public nsIWakeLock {
30 public:
31 NS_DECL_NSIDOMEVENTLISTENER
32 NS_DECL_NSIOBSERVER
33 NS_DECL_NSIWAKELOCK
35 NS_DECL_ISUPPORTS
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, nsPIDOMWindowInner* aWindow);
49 // WebIDL methods
51 nsPIDOMWindowInner* GetParentObject() const;
53 void GetTopic(nsAString& aTopic);
55 void Unlock(ErrorResult& aRv);
57 private:
58 virtual ~WakeLock();
60 void DoUnlock();
61 void DoLock();
62 void AttachEventListener();
63 void DetachEventListener();
65 // Return true if all parts of the given document are regarded as invisible.
66 bool IsDocumentInvisible(const Document& aDocument) const;
68 bool mLocked;
69 bool mHidden;
71 // The ID of the ContentParent on behalf of whom we acquired this lock, or
72 // CONTENT_PROCESS_UNKNOWN_ID if this lock was acquired on behalf of the
73 // current process.
74 uint64_t mContentParentID;
75 nsString mTopic;
77 // window that this was created for. Weak reference.
78 nsWeakPtr mWindow;
81 } // namespace dom
82 } // namespace mozilla
84 #endif // mozilla_dom_power_WakeLock_h