tor-browser

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

Lock.h (2071B)


      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/. */
      6 
      7 #ifndef mozilla_dom_Lock_h
      8 #define mozilla_dom_Lock_h
      9 
     10 #include "js/TypeDecls.h"
     11 #include "mozilla/ErrorResult.h"
     12 #include "mozilla/WeakPtr.h"
     13 #include "mozilla/dom/BindingDeclarations.h"
     14 #include "mozilla/dom/LockManagerBinding.h"
     15 #include "mozilla/dom/PromiseNativeHandler.h"
     16 #include "nsCycleCollectionParticipant.h"
     17 #include "nsWrapperCache.h"
     18 
     19 namespace mozilla::dom {
     20 
     21 class LockManager;
     22 namespace locks {
     23 class LockRequestChild;
     24 }
     25 
     26 class Lock final : public PromiseNativeHandler, public nsWrapperCache {
     27  friend class LockManager;
     28 
     29 public:
     30  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     31  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Lock)
     32 
     33  Lock(nsIGlobalObject* aGlobal,
     34       const WeakPtr<locks::LockRequestChild>& aLockRequestChild,
     35       const nsString& aName, LockMode aMode,
     36       const RefPtr<Promise>& aReleasedPromise, ErrorResult& aRv);
     37 
     38 protected:
     39  ~Lock() = default;
     40 
     41 public:
     42  nsIGlobalObject* GetParentObject() const { return mOwner; };
     43 
     44  JSObject* WrapObject(JSContext* aCx,
     45                       JS::Handle<JSObject*> aGivenProto) override;
     46 
     47  void GetName(nsString& aRetVal) const;
     48 
     49  LockMode Mode() const;
     50 
     51  Promise& GetWaitingPromise();
     52 
     53  // PromiseNativeHandler
     54  virtual void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
     55                                ErrorResult& aRv) override;
     56  virtual void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
     57                                ErrorResult& aRv) override;
     58 
     59 private:
     60  nsCOMPtr<nsIGlobalObject> mOwner;
     61  WeakPtr<locks::LockRequestChild> mLockRequestChild;
     62 
     63  nsString mName;
     64  LockMode mMode;
     65  RefPtr<Promise> mWaitingPromise;
     66  RefPtr<Promise> mReleasedPromise;
     67 };
     68 
     69 }  // namespace mozilla::dom
     70 
     71 #endif  // mozilla_dom_Lock_h