Bug 1943650 - Command-line --help output misformatted after --dbus-service. r=emilio
[gecko.git] / toolkit / components / credentialmanagement / CredentialChosenCallback.h
blob4a927d31b7569caf20f8fb9702e5df38869a9415
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_CREDENTIALCHOSENCALLBACK_H_
8 #define MOZILLA_CREDENTIALCHOSENCALLBACK_H_
10 #include "nsICredentialChosenCallback.h"
11 #include "nsINamed.h"
12 #include "nsStringFwd.h"
13 #include "nsTArray.h"
15 #include "mozilla/dom/IdentityCredentialSerializationHelpers.h"
16 #include "mozilla/dom/Promise.h"
18 namespace mozilla {
20 using dom::IPCIdentityCredential;
21 using dom::Promise;
23 class CredentialChosenCallback final : public nsICredentialChosenCallback,
24 public nsINamed {
25 public:
26 explicit CredentialChosenCallback(
27 CopyableTArray<IPCIdentityCredential>&& aOptions,
28 const RefPtr<MozPromise<IPCIdentityCredential, nsresult, true>::Private>&
29 aResult)
30 : mOptions(aOptions), mResult(aResult) {}
32 NS_IMETHOD
33 Notify(const nsACString& aCredential) override;
35 NS_IMETHOD
36 GetName(nsACString& aName) override;
38 NS_DECL_ISUPPORTS
40 private:
41 ~CredentialChosenCallback() {
42 if (mResult) {
43 mResult->Reject(NS_ERROR_FAILURE, __func__);
47 // mOptions is the list of credentials presented to the user in the credential
48 // chooser. We maintain this list so we can resolve with the user's choice of
49 // credential.
50 CopyableTArray<IPCIdentityCredential> mOptions;
52 // mResult is a promise that will fulfill once the user has made a choice.
53 // Dismissal is represented as a reject(NS_OK), and selection resolves with
54 // an entry of mOptions.
55 RefPtr<MozPromise<IPCIdentityCredential, nsresult, true>::Private> mResult;
58 } // namespace mozilla
60 #endif /* MOZILLA_CREDENTIALCHOSENCALLBACK_H_ */