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/. */
7 #ifndef MOZILLA_IDENTITYCREDENTIALREQUESTMANAGER_H_
8 #define MOZILLA_IDENTITYCREDENTIALREQUESTMANAGER_H_
10 #include "mozilla/ClearOnShutdown.h"
11 #include "mozilla/PrincipalHashKey.h"
12 #include "mozilla/dom/IdentityCredential.h"
13 #include "mozilla/dom/IdentityCredentialBinding.h"
14 #include "mozilla/dom/IPCIdentityCredential.h"
15 #include "nsIPrincipal.h"
16 #include "nsTHashMap.h"
20 class IdentityCredentialRequestManager final
: nsISupports
{
24 static IdentityCredentialRequestManager
* GetInstance();
26 // Store an active cross origin identity credential request happening from the
27 // given principal and inner window ID. These accumulate forever, but if the
28 // window goes away, we will be unable to notify of a store.
29 nsresult
StorePendingRequest(
30 const nsCOMPtr
<nsIPrincipal
>& aRPPrincipal
,
31 const dom::IdentityCredentialRequestOptions
& aRequest
,
33 dom::IdentityCredential::GetIPCIdentityCredentialPromise::Private
>&
35 const RefPtr
<dom::CanonicalBrowsingContext
>& aBrowsingContext
);
37 // If the given credential stored by the given principal would be effective
38 // for a previously stored request, notify the window that stored that request
39 // with the credential so it can resolve a promise with that credential data.
40 void NotifyOfStoredCredential(const nsCOMPtr
<nsIPrincipal
>& aIDPPrincipal
,
41 const dom::IPCIdentityCredential
& aCredential
);
43 IdentityCredentialRequestManager(IdentityCredentialRequestManager
& other
) =
45 void operator=(const IdentityCredentialRequestManager
&) = delete;
48 static StaticRefPtr
<IdentityCredentialRequestManager
> sSingleton
;
49 IdentityCredentialRequestManager() {};
50 ~IdentityCredentialRequestManager() = default;
52 struct PendingRequestEntry
{
53 nsCOMPtr
<nsIPrincipal
> mRPPrincipal
;
54 dom::IdentityCredentialRequestOptions mRequestOptions
;
55 RefPtr
<dom::IdentityCredential::GetIPCIdentityCredentialPromise::Private
>
57 RefPtr
<dom::CanonicalBrowsingContext
> mBrowsingContext
;
60 nsIPrincipal
* aRPPrincipal
,
61 const dom::IdentityCredentialRequestOptions
& aRequestOptions
,
63 dom::IdentityCredential::GetIPCIdentityCredentialPromise::Private
>&
65 const RefPtr
<dom::CanonicalBrowsingContext
>& aBrowsingContext
)
66 : mRPPrincipal(aRPPrincipal
),
67 mRequestOptions(aRequestOptions
),
69 mBrowsingContext(aBrowsingContext
) {}
71 nsTHashMap
<PrincipalHashKey
, nsTArray
<PendingRequestEntry
>> mPendingRequests
;
74 } // namespace mozilla
76 #endif /* MOZILLA_IDENTITYCREDENTIALSTORAGESERVICE_H_ */