Bug 1914102 - Use OffscreenCanvas in TabBase.capture instead of creating a canvas...
[gecko.git] / dom / locks / Lock.h
blobced0fc3785962928f7936ec3defd4e0f4df342c7
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/. */
7 #ifndef mozilla_dom_Lock_h
8 #define mozilla_dom_Lock_h
10 #include "js/TypeDecls.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/ErrorResult.h"
13 #include "mozilla/WeakPtr.h"
14 #include "mozilla/dom/BindingDeclarations.h"
15 #include "mozilla/dom/LockManagerBinding.h"
16 #include "mozilla/dom/PromiseNativeHandler.h"
17 #include "nsCycleCollectionParticipant.h"
18 #include "nsWrapperCache.h"
20 namespace mozilla::dom {
22 class LockManager;
23 namespace locks {
24 class LockRequestChild;
27 class Lock final : public PromiseNativeHandler, public nsWrapperCache {
28 friend class LockManager;
30 public:
31 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
32 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Lock)
34 Lock(nsIGlobalObject* aGlobal,
35 const WeakPtr<locks::LockRequestChild>& aLockRequestChild,
36 const nsString& aName, LockMode aMode,
37 const RefPtr<Promise>& aReleasedPromise, ErrorResult& aRv);
39 protected:
40 ~Lock() = default;
42 public:
43 nsIGlobalObject* GetParentObject() const { return mOwner; };
45 JSObject* WrapObject(JSContext* aCx,
46 JS::Handle<JSObject*> aGivenProto) override;
48 void GetName(nsString& aRetVal) const;
50 LockMode Mode() const;
52 Promise& GetWaitingPromise();
54 // PromiseNativeHandler
55 virtual void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
56 ErrorResult& aRv) override;
57 virtual void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
58 ErrorResult& aRv) override;
60 private:
61 nsCOMPtr<nsIGlobalObject> mOwner;
62 WeakPtr<locks::LockRequestChild> mLockRequestChild;
64 nsString mName;
65 LockMode mMode;
66 RefPtr<Promise> mWaitingPromise;
67 RefPtr<Promise> mReleasedPromise;
70 } // namespace mozilla::dom
72 #endif // mozilla_dom_Lock_h