Bug 1835710 - Cancel off-thread JIT compilation before changing nursery allocation...
[gecko.git] / dom / base / StorageAccessPermissionRequest.h
blobdec3054d659a74769960ad2629810f697205d7f3
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 StorageAccessPermissionRequest_h_
8 #define StorageAccessPermissionRequest_h_
10 #include "nsContentPermissionHelper.h"
11 #include "mozilla/Maybe.h"
12 #include "mozilla/MozPromise.h"
14 #include <functional>
16 class nsPIDOMWindowInner;
18 namespace mozilla::dom {
20 class StorageAccessPermissionRequest final
21 : public ContentPermissionRequestBase {
22 public:
23 NS_DECL_ISUPPORTS_INHERITED
24 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(StorageAccessPermissionRequest,
25 ContentPermissionRequestBase)
27 // nsIContentPermissionRequest
28 NS_IMETHOD Cancel(void) override;
29 NS_IMETHOD Allow(JS::Handle<JS::Value> choices) override;
30 NS_IMETHOD GetTypes(nsIArray** aTypes) override;
32 using AllowCallback = std::function<void()>;
33 using CancelCallback = std::function<void()>;
35 static already_AddRefed<StorageAccessPermissionRequest> Create(
36 nsPIDOMWindowInner* aWindow, AllowCallback&& aAllowCallback,
37 CancelCallback&& aCancelCallback);
39 static already_AddRefed<StorageAccessPermissionRequest> Create(
40 nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal,
41 AllowCallback&& aAllowCallback, CancelCallback&& aCancelCallback);
43 // The argument aTopLevelBaseDomain is used here to optionally indicate what
44 // the top-level site of the permission requested will be. This is used in
45 // the requestStorageAccessUnderSite call because that call is not made from
46 // an embedded context. If aTopLevelBaseDomain is Nothing() the base domain
47 // of aPrincipal's Top browsing context is used.
48 static already_AddRefed<StorageAccessPermissionRequest> Create(
49 nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal,
50 const Maybe<nsCString>& aTopLevelBaseDomain,
51 AllowCallback&& aAllowCallback, CancelCallback&& aCancelCallback);
53 using AutoGrantDelayPromise = MozPromise<bool, bool, true>;
54 RefPtr<AutoGrantDelayPromise> MaybeDelayAutomaticGrants();
56 private:
57 StorageAccessPermissionRequest(nsPIDOMWindowInner* aWindow,
58 nsIPrincipal* aNodePrincipal,
59 const Maybe<nsCString>& aTopLevelBaseDomain,
60 AllowCallback&& aAllowCallback,
61 CancelCallback&& aCancelCallback);
62 ~StorageAccessPermissionRequest() {
63 // Invoke Cancel() to ensure we call a callback even if the request has
64 // been destroyed before the request is completed.
65 Cancel();
68 unsigned CalculateSimulatedDelay();
70 AllowCallback mAllowCallback;
71 CancelCallback mCancelCallback;
72 nsTArray<nsString> mOptions;
73 nsTArray<PermissionRequest> mPermissionRequests;
74 bool mCallbackCalled;
77 } // namespace mozilla::dom
79 #endif // StorageAccessPermissionRequest_h_