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"
16 class nsPIDOMWindowInner
;
18 namespace mozilla::dom
{
20 class StorageAccessPermissionRequest final
21 : public ContentPermissionRequestBase
{
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
, bool aFrameOnly
,
51 AllowCallback
&& aAllowCallback
, CancelCallback
&& aCancelCallback
);
53 using AutoGrantDelayPromise
= MozPromise
<bool, bool, true>;
54 RefPtr
<AutoGrantDelayPromise
> MaybeDelayAutomaticGrants();
57 StorageAccessPermissionRequest(nsPIDOMWindowInner
* aWindow
,
58 nsIPrincipal
* aNodePrincipal
,
59 const Maybe
<nsCString
>& aTopLevelBaseDomain
,
61 AllowCallback
&& aAllowCallback
,
62 CancelCallback
&& aCancelCallback
);
63 ~StorageAccessPermissionRequest() {
64 // Invoke Cancel() to ensure we call a callback even if the request has
65 // been destroyed before the request is completed.
69 unsigned CalculateSimulatedDelay();
71 AllowCallback mAllowCallback
;
72 CancelCallback mCancelCallback
;
73 nsTArray
<nsString
> mOptions
;
74 nsTArray
<PermissionRequest
> mPermissionRequests
;
78 } // namespace mozilla::dom
80 #endif // StorageAccessPermissionRequest_h_