tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WakeLock.h (1897B)


      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/. */
      6 
      7 #ifndef mozilla_dom_power_WakeLock_h
      8 #define mozilla_dom_power_WakeLock_h
      9 
     10 #include "nsCOMPtr.h"
     11 #include "nsIDOMEventListener.h"
     12 #include "nsIWakeLock.h"
     13 #include "nsString.h"
     14 #include "nsWeakReference.h"
     15 #include "nsWrapperCache.h"
     16 
     17 class nsPIDOMWindowInner;
     18 
     19 namespace mozilla {
     20 class ErrorResult;
     21 
     22 namespace dom {
     23 class Document;
     24 
     25 class WakeLock final : public nsIDOMEventListener,
     26                       public nsSupportsWeakReference,
     27                       public nsIWakeLock {
     28 public:
     29  NS_DECL_NSIDOMEVENTLISTENER
     30  NS_DECL_NSIWAKELOCK
     31 
     32  NS_DECL_ISUPPORTS
     33 
     34  // Note: WakeLock lives for the lifetime of the document in order to avoid
     35  // exposing GC behavior to pages. This means that
     36  // |var foo = navigator.requestWakeLock('cpu'); foo = null;|
     37  // doesn't unlock the 'cpu' resource.
     38 
     39  WakeLock() = default;
     40 
     41  // Initialize this wake lock on behalf of the given window.  Null windows are
     42  // allowed; a lock without an associated window is always considered
     43  // invisible.
     44  nsresult Init(const nsAString& aTopic, nsPIDOMWindowInner* aWindow);
     45 
     46  // WebIDL methods
     47 
     48  nsPIDOMWindowInner* GetParentObject() const;
     49 
     50  void GetTopic(nsAString& aTopic);
     51 
     52  void Unlock(ErrorResult& aRv);
     53 
     54 private:
     55  virtual ~WakeLock();
     56 
     57  void DoUnlock();
     58  void DoLock();
     59  void AttachEventListener();
     60  void DetachEventListener();
     61 
     62  bool mLocked = false;
     63  bool mHidden = true;
     64 
     65  nsString mTopic;
     66 
     67  // window that this was created for.  Weak reference.
     68  nsWeakPtr mWindow;
     69 };
     70 
     71 }  // namespace dom
     72 }  // namespace mozilla
     73 
     74 #endif  // mozilla_dom_power_WakeLock_h