gecko-dev/toolkit/components/credentialmanagement/CredentialChosenCallback.cpp
Benjamin VanderSloot 2d39580faa Bug 1892021, part 3 - Credential chosen callback update to match new semantic - r=anti-tracking-reviewers,pbz
Down the stack I need to change the argument to `notify` in the nsICredentialChosenCallback so it
can run in Javascript for testing. I make the change here that allows consumers of this class to
still get the `IPCIdentityCredential` in the resolve callback of the argument promise.

Differential Revision: https://phabricator.services.mozilla.com/D215007
2024-07-26 16:53:20 +00:00

49 lines
1.3 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/CredentialChosenCallback.h"
#include "mozilla/dom/Credential.h"
namespace mozilla {
using dom::Credential;
using dom::Promise;
nsresult CredentialChosenCallback::Notify(const nsACString& aCredentialId) {
MOZ_ASSERT(NS_IsMainThread());
if (!mResult) {
return NS_OK;
}
if (aCredentialId.IsVoid()) {
mResult->Reject(NS_OK, __func__);
mResult = nullptr;
return NS_OK;
}
for (auto option : mOptions) {
if (option.id().Equals(NS_ConvertUTF8toUTF16(aCredentialId))) {
mResult->Resolve(option, __func__);
mResult = nullptr;
return NS_OK;
}
}
mResult->Reject(nsresult::NS_ERROR_NO_CONTENT, __func__);
mResult = nullptr;
return NS_OK;
}
nsresult CredentialChosenCallback::GetName(nsACString& aName) {
aName.AssignLiteral("CredentialChosenCallback");
return NS_OK;
}
NS_IMPL_ISUPPORTS(CredentialChosenCallback, nsICredentialChosenCallback,
nsINamed)
} // namespace mozilla