Backed out 5 changesets (bug 1782087, bug 1782094, bug 1782093, bug 1782091) for causing bc failures in toolkit/components/cleardata/tests/browser/browser_quota.js CLOSED TREE

Backed out changeset e810f2f0580f (bug 1782093)
Backed out changeset 955c8cad8112 (bug 1782087)
Backed out changeset 372252b98cd7 (bug 1782087)
Backed out changeset 32e4f376e64f (bug 1782094)
Backed out changeset 1475247d538f (bug 1782091)
This commit is contained in:
Sandor Molnar 2022-12-03 00:53:52 +02:00
Родитель 91267bb248
Коммит b2e8991495
23 изменённых файлов: 27 добавлений и 1532 удалений

Просмотреть файл

@ -306,7 +306,7 @@
<image id="webauthn-notification-icon" class="notification-anchor-icon" role="button"
data-l10n-id="urlbar-web-authn-anchor"/>
<image id="identity-credential-notification-icon" class="notification-anchor-icon" role="button"
data-l10n-id="identity-credential-urlbar-anchor"/>
data-l10n-id="urlbar-identity-credential-anchor"/>
<image id="storage-access-notification-icon" class="notification-anchor-icon storage-access-icon" role="button"
data-l10n-id="urlbar-storage-access-anchor"/>
</box>

Просмотреть файл

@ -172,18 +172,13 @@
<popupnotificationcontent id="identity-credential-provider" orient="vertical">
<html:div id="identity-credential-provider-selector-container">
</html:div>
<description class="popup-notification-description" id="credential-provider-explanation" data-l10n-id="identity-credential-description-provider-explanation"/>
<description class="popup-notification-description" id="credential-provider-explanation" data-l10n-id="credential-description-provider-explanation"/>
<html:template id="template-credential-provider-list-item">
<toolbarbutton class="credential-provider-list-item subviewbutton-nav subviewbutton" align="center" wrap="true">
<label flex="1" class="credential-provider-list-item-label"></label>
</toolbarbutton>
</html:template>
</popupnotificationcontent>
<popupnotificationcontent id="identity-credential-policy" orient="vertical">
<description id="identity-credential-policy-explanation"/>
<label class="text-link" is="text-link" data-l10n-id="identity-credential-privacy-policy" id="identity-credential-privacy-policy"></label>
<label class="text-link" is="text-link" data-l10n-id="identity-credential-terms-of-service" id="identity-credential-terms-of-service"></label>
</popupnotificationcontent>
<popupnotificationcontent id="identity-credential-account" orient="vertical" hidden="true">
<html:div id="identity-credential-account-selector-container">
</html:div>

Просмотреть файл

@ -4,22 +4,13 @@
## Credential panel
## $host (String): the hostname of the site that is being displayed.
## $provider (String): the hostname of another website you are using to log in to the site being displayed
identity-credential-header-providers = Sign in to { $host }
identity-credential-header-accounts = Pick a { $host } account
credential-header-providers = Sign in to { $host }.
credential-header-accounts = Pick a { $host } account.
# Identity providers are websites you use to log into another website, for example: Google when you Log in with Google.
identity-credential-description-provider-explanation = These are the identity providers that would like to help you log in.
identity-credential-description-account-explanation = Picking an account here shares that identity with { $host }.
identity-credential-urlbar-anchor =
credential-description-provider-explanation = These are the identity providers that would like to help you log in.
credential-description-account-explanation = Picking an account here shares that identity with { $host }.
urlbar-identity-credential-anchor =
.tooltiptext = Open federated login panel
identity-credential-cancel-button =
.label = Cancel
.accesskey = C
identity-credential-accept-button =
.label = Okay
.accesskey = O
identity-credential-policy-title = Legal information
identity-credential-policy-description = Logging into { $host } with an account from { $provider } is controlled by these legal policies. This is optional and you can cancel this and try to log in again using another method.
identity-credential-privacy-policy = Privacy Policy
identity-credential-terms-of-service = Terms of Service
credential-cancel-label = Cancel
credential-cancel-accesskey = C

Просмотреть файл

@ -523,8 +523,7 @@ export var Sanitizer = {
Ci.nsIClearDataService.CLEAR_CONTENT_PREFERENCES |
Ci.nsIClearDataService.CLEAR_DOM_PUSH_NOTIFICATIONS |
Ci.nsIClearDataService.CLEAR_CLIENT_AUTH_REMEMBER_SERVICE |
Ci.nsIClearDataService.CLEAR_CERT_EXCEPTIONS |
Ci.nsIClearDataService.CLEAR_CREDENTIAL_MANAGER_STATE
Ci.nsIClearDataService.CLEAR_CERT_EXCEPTIONS
);
TelemetryStopwatch.finish("FX_SANITIZE_SITESETTINGS", refObj);
},

Просмотреть файл

@ -15,9 +15,7 @@
#include "mozilla/ExpandedPrincipal.h"
#include "mozilla/NullPrincipal.h"
#include "nsEffectiveTLDService.h"
#include "nsIGlobalObject.h"
#include "nsIIdentityCredentialPromptService.h"
#include "nsIIdentityCredentialStorageService.h"
#include "nsITimer.h"
#include "nsIXPConnect.h"
#include "nsNetUtil.h"
@ -229,22 +227,6 @@ IdentityCredential::CreateCredential(nsIPrincipal* aPrincipal,
return IdentityCredential::GetAccountPromise::CreateAndReject(
error, __func__);
})
->Then(
GetCurrentSerialEventTarget(), __func__,
[argumentPrincipal, browsingContext,
aProvider](const Tuple<IdentityInternalManifest, IdentityAccount>&
promiseResult) {
IdentityInternalManifest currentManifest;
IdentityAccount account;
Tie(currentManifest, account) = promiseResult;
return IdentityCredential::PromptUserWithPolicy(
browsingContext, argumentPrincipal, account, currentManifest,
aProvider);
},
[](nsresult error) {
return IdentityCredential::GetAccountPromise::CreateAndReject(
error, __func__);
})
->Then(
GetCurrentSerialEventTarget(), __func__,
[argumentPrincipal,
@ -328,7 +310,7 @@ IdentityCredential::CheckRootManifest(nsIPrincipal* aPrincipal,
}
// Create a new request
constexpr auto fragment = ""_ns;
nsCString fragment = ""_ns;
auto internalRequest =
MakeSafeRefPtr<InternalRequest>(manifestURIString, fragment);
internalRequest->SetCredentialsMode(RequestCredentials::Omit);
@ -393,7 +375,7 @@ IdentityCredential::FetchInternalManifest(nsIPrincipal* aPrincipal,
}
// Create a new request
constexpr auto fragment = ""_ns;
nsCString fragment = ""_ns;
auto internalRequest =
MakeSafeRefPtr<InternalRequest>(configLocation, fragment);
internalRequest->SetRedirectMode(RequestRedirect::Error);
@ -460,7 +442,7 @@ IdentityCredential::FetchAccountList(
}
// Create a new request
constexpr auto fragment = ""_ns;
nsCString fragment = ""_ns;
auto internalRequest =
MakeSafeRefPtr<InternalRequest>(configLocation, fragment);
internalRequest->SetRedirectMode(RequestRedirect::Error);
@ -515,7 +497,7 @@ RefPtr<IdentityCredential::GetTokenPromise> IdentityCredential::FetchToken(
}
// Create a new request
constexpr auto fragment = ""_ns;
nsCString fragment = ""_ns;
auto internalRequest =
MakeSafeRefPtr<InternalRequest>(tokenLocation, fragment);
internalRequest->SetMethod("POST"_ns);
@ -568,53 +550,6 @@ RefPtr<IdentityCredential::GetTokenPromise> IdentityCredential::FetchToken(
});
}
// static
RefPtr<IdentityCredential::GetMetadataPromise>
IdentityCredential::FetchMetadata(nsIPrincipal* aPrincipal,
const IdentityInternalManifest& aManifest) {
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(aPrincipal);
// Build the URL
nsCString configLocation =
NS_ConvertUTF16toUTF8(aManifest.mClient_metadata_endpoint);
// Create the global
nsIXPConnect* xpc = nsContentUtils::XPConnect();
MOZ_ASSERT(xpc, "This should never be null!");
nsCOMPtr<nsIGlobalObject> global;
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> sandbox(cx);
nsresult rv = xpc->CreateSandbox(cx, aPrincipal, sandbox.address());
if (NS_WARN_IF(NS_FAILED(rv))) {
return IdentityCredential::GetMetadataPromise::CreateAndReject(rv,
__func__);
}
MOZ_ASSERT(JS_IsGlobalObject(sandbox));
global = xpc::NativeGlobal(sandbox);
if (NS_WARN_IF(!global)) {
return IdentityCredential::GetMetadataPromise::CreateAndReject(
NS_ERROR_FAILURE, __func__);
}
// Create a new request
constexpr auto fragment = ""_ns;
auto internalRequest =
MakeSafeRefPtr<InternalRequest>(configLocation, fragment);
internalRequest->SetRedirectMode(RequestRedirect::Error);
internalRequest->SetCredentialsMode(RequestCredentials::Omit);
internalRequest->SetReferrerPolicy(ReferrerPolicy::No_referrer);
internalRequest->SetMode(RequestMode::Cors);
internalRequest->SetCacheMode(RequestCache::No_cache);
internalRequest->SetHeaders(new InternalHeaders(HeadersGuardEnum::Request));
internalRequest->OverrideContentPolicyType(
nsContentPolicyType::TYPE_WEB_IDENTITY);
RefPtr<Request> request =
new Request(global, std::move(internalRequest), nullptr);
return FetchJSONStructure<IdentityClientMetadata>(request);
}
// static
RefPtr<IdentityCredential::GetIdentityProviderPromise>
IdentityCredential::PromptUserToSelectProvider(
@ -728,136 +663,6 @@ IdentityCredential::PromptUserToSelectAccount(
return resultPromise;
}
// static
RefPtr<IdentityCredential::GetAccountPromise>
IdentityCredential::PromptUserWithPolicy(
BrowsingContext* aBrowsingContext, nsIPrincipal* aPrincipal,
const IdentityAccount& aAccount, const IdentityInternalManifest& aManifest,
const IdentityProvider& aProvider) {
MOZ_ASSERT(aBrowsingContext);
MOZ_ASSERT(aPrincipal);
nsresult error;
nsCOMPtr<nsIIdentityCredentialStorageService> icStorageService =
mozilla::components::IdentityCredentialStorageService::Service(&error);
if (NS_WARN_IF(!icStorageService)) {
return IdentityCredential::GetAccountPromise::CreateAndReject(error,
__func__);
}
// Check the storage bit
nsCString configLocation =
NS_ConvertUTF16toUTF8(aManifest.mAccounts_endpoint);
nsCOMPtr<nsIURI> idpURI;
error = NS_NewURI(getter_AddRefs(idpURI), configLocation);
if (NS_WARN_IF(NS_FAILED(error))) {
return IdentityCredential::GetAccountPromise::CreateAndReject(error,
__func__);
}
bool registered = false;
bool allowLogout = false;
nsCOMPtr<nsIPrincipal> idpPrincipal = BasePrincipal::CreateContentPrincipal(
idpURI, aPrincipal->OriginAttributesRef());
error = icStorageService->GetState(aPrincipal, idpPrincipal,
NS_ConvertUTF16toUTF8(aAccount.mId),
&registered, &allowLogout);
if (NS_WARN_IF(NS_FAILED(error))) {
return IdentityCredential::GetAccountPromise::CreateAndReject(error,
__func__);
}
// if registered, mark as logged in and return
if (registered) {
icStorageService->SetState(aPrincipal, idpPrincipal,
NS_ConvertUTF16toUTF8(aAccount.mId), true, true);
return IdentityCredential::GetAccountPromise::CreateAndResolve(
MakeTuple(aManifest, aAccount), __func__);
}
// otherwise, fetch ->Then display ->Then return ->Catch reject
RefPtr<BrowsingContext> browsingContext(aBrowsingContext);
nsCOMPtr<nsIPrincipal> argumentPrincipal(aPrincipal);
return FetchMetadata(aPrincipal, aManifest)
->Then(
GetCurrentSerialEventTarget(), __func__,
[aAccount, aProvider, argumentPrincipal, browsingContext,
icStorageService,
idpPrincipal](const IdentityClientMetadata& metadata)
-> RefPtr<GenericPromise> {
nsresult error;
nsCOMPtr<nsIIdentityCredentialPromptService> icPromptService =
mozilla::components::IdentityCredentialPromptService::Service(
&error);
if (NS_WARN_IF(!icPromptService)) {
return GenericPromise::CreateAndReject(error, __func__);
}
nsCOMPtr<nsIXPConnectWrappedJS> wrapped =
do_QueryInterface(icPromptService);
AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.Init(wrapped->GetJSObjectGlobal()))) {
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE,
__func__);
}
JS::Rooted<JS::Value> providerJS(jsapi.cx());
bool success = ToJSValue(jsapi.cx(), aProvider, &providerJS);
if (NS_WARN_IF(!success)) {
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE,
__func__);
}
JS::Rooted<JS::Value> metadataJS(jsapi.cx());
success = ToJSValue(jsapi.cx(), metadata, &metadataJS);
if (NS_WARN_IF(!success)) {
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE,
__func__);
}
RefPtr<Promise> showPromptPromise;
icPromptService->ShowPolicyPrompt(
browsingContext, providerJS, metadataJS,
getter_AddRefs(showPromptPromise));
RefPtr<GenericPromise::Private> resultPromise =
new GenericPromise::Private(__func__);
RefPtr<DomPromiseListener> listener = new DomPromiseListener(
[aAccount, argumentPrincipal, idpPrincipal, resultPromise,
icStorageService](JSContext* aCx,
JS::Handle<JS::Value> aValue) {
bool isBool = aValue.isBoolean();
if (!isBool) {
resultPromise->Reject(NS_ERROR_FAILURE, __func__);
return;
}
icStorageService->SetState(
argumentPrincipal, idpPrincipal,
NS_ConvertUTF16toUTF8(aAccount.mId), true, true);
resultPromise->Resolve(aValue.toBoolean(), __func__);
},
[resultPromise](nsresult aRv) {
resultPromise->Reject(aRv, __func__);
});
showPromptPromise->AppendNativeHandler(listener);
return resultPromise;
},
[](nsresult error) {
return GenericPromise::CreateAndReject(error, __func__);
})
->Then(
GetCurrentSerialEventTarget(), __func__,
[aManifest, aAccount](bool success) {
if (success) {
return IdentityCredential::GetAccountPromise::CreateAndResolve(
MakeTuple(aManifest, aAccount), __func__);
}
return IdentityCredential::GetAccountPromise::CreateAndReject(
NS_ERROR_FAILURE, __func__);
},
[](nsresult error) {
return IdentityCredential::GetAccountPromise::CreateAndReject(
error, __func__);
});
}
// static
void IdentityCredential::CloseUserInterface(BrowsingContext* aBrowsingContext) {
nsresult error;
@ -869,67 +674,4 @@ void IdentityCredential::CloseUserInterface(BrowsingContext* aBrowsingContext) {
icPromptService->Close(aBrowsingContext);
}
// static
already_AddRefed<Promise> IdentityCredential::LogoutRPs(
GlobalObject& aGlobal,
const Sequence<IdentityCredentialLogoutRPsRequest>& aLogoutRequests,
ErrorResult& aRv) {
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
RefPtr<Promise> promise = Promise::CreateResolvedWithUndefined(global, aRv);
NS_ENSURE_FALSE(aRv.Failed(), nullptr);
nsresult rv;
nsCOMPtr<nsIIdentityCredentialStorageService> icStorageService =
components::IdentityCredentialStorageService::Service(&rv);
if (NS_WARN_IF(!icStorageService)) {
aRv.Throw(rv);
return nullptr;
}
RefPtr<nsIPrincipal> rpPrincipal = global->PrincipalOrNull();
for (const auto& request : aLogoutRequests) {
// Get the current state
nsCOMPtr<nsIURI> idpURI;
rv = NS_NewURI(getter_AddRefs(idpURI), request.mUrl);
if (NS_FAILED(rv)) {
aRv.ThrowTypeError<MSG_INVALID_URL>(request.mUrl);
return nullptr;
}
nsCOMPtr<nsIPrincipal> idpPrincipal = BasePrincipal::CreateContentPrincipal(
idpURI, rpPrincipal->OriginAttributesRef());
bool registered, allowLogout;
icStorageService->GetState(rpPrincipal, idpPrincipal, request.mAccountId,
&registered, &allowLogout);
// Ignore this request if it isn't permitted
if (!(registered && allowLogout)) {
continue;
}
// Issue the logout request
constexpr auto fragment = ""_ns;
auto internalRequest =
MakeSafeRefPtr<InternalRequest>(request.mUrl, fragment);
internalRequest->SetRedirectMode(RequestRedirect::Error);
internalRequest->SetCredentialsMode(RequestCredentials::Include);
internalRequest->SetReferrerPolicy(ReferrerPolicy::Strict_origin);
internalRequest->SetMode(RequestMode::Cors);
internalRequest->SetCacheMode(RequestCache::No_cache);
internalRequest->OverrideContentPolicyType(
nsContentPolicyType::TYPE_WEB_IDENTITY);
RefPtr<Request> domRequest =
new Request(global, std::move(internalRequest), nullptr);
RequestOrUSVString fetchInput;
fetchInput.SetAsRequest() = domRequest;
RootedDictionary<RequestInit> requestInit(RootingCx());
IgnoredErrorResult error;
RefPtr<Promise> fetchPromise = FetchRequest(global, fetchInput, requestInit,
CallerType::System, error);
// Change state to disallow more logout requests
icStorageService->SetState(rpPrincipal, idpPrincipal, request.mAccountId,
true, false);
}
return promise.forget();
}
} // namespace mozilla::dom

Просмотреть файл

@ -34,7 +34,6 @@ class IdentityCredential final : public Credential {
typedef MozPromise<Tuple<IdentityInternalManifest, IdentityAccount>, nsresult,
true>
GetAccountPromise;
typedef MozPromise<IdentityClientMetadata, nsresult, true> GetMetadataPromise;
explicit IdentityCredential(nsPIDOMWindowInner* aParent);
@ -52,11 +51,6 @@ class IdentityCredential final : public Credential {
void GetToken(nsAString& aToken) const;
void SetToken(const nsAString& aToken);
static already_AddRefed<Promise> LogoutRPs(
GlobalObject& aGlobal,
const Sequence<IdentityCredentialLogoutRPsRequest>& aLogoutRequests,
ErrorResult& aRv);
static RefPtr<GetIdentityCredentialPromise> DiscoverFromExternalSource(
nsPIDOMWindowInner* aParent, const CredentialRequestOptions& aOptions,
bool aSameOriginWithAncestors);
@ -160,9 +154,6 @@ class IdentityCredential final : public Credential {
const IdentityInternalManifest& aManifest,
const IdentityAccount& aAccount);
static RefPtr<GetMetadataPromise> FetchMetadata(
nsIPrincipal* aPrincipal, const IdentityInternalManifest& aManifest);
static RefPtr<GetIdentityProviderPromise> PromptUserToSelectProvider(
BrowsingContext* aBrowsingContext,
const Sequence<IdentityProvider>& aProviders);
@ -171,12 +162,6 @@ class IdentityCredential final : public Credential {
BrowsingContext* aBrowsingContext, const IdentityAccountList& aAccounts,
const IdentityInternalManifest& aManifest);
static RefPtr<GetAccountPromise> PromptUserWithPolicy(
BrowsingContext* aBrowsingContext, nsIPrincipal* aPrincipal,
const IdentityAccount& aAccount,
const IdentityInternalManifest& aManifest,
const IdentityProvider& aProvider);
static void CloseUserInterface(BrowsingContext* aBrowsingContext);
private:

Просмотреть файл

@ -15,8 +15,6 @@ support-files =
/.well-known/web-identity^headers^
server_manifest.sjs
server_manifest_wrong_provider_in_manifest.sjs
server_metadata.json
server_metadata.json^headers^
server_simple_accounts.sjs
server_simple_idtoken.sjs
server_no_accounts_accounts.sjs

Просмотреть файл

@ -35,7 +35,7 @@ function handleRequest(request, response) {
accounts_endpoint:
"https://example.net/tests/dom/credentialmanagement/identity/tests/mochitest/server_TESTNAME_accounts.sjs",
client_metadata_endpoint:
"https://example.net/tests/dom/credentialmanagement/identity/tests/mochitest/server_metadata.json",
"https://example.net/tests/dom/credentialmanagement/identity/tests/mochitest/server_TESTNAME_metadata.sjs",
id_token_endpoint:
"https://example.net/tests/dom/credentialmanagement/identity/tests/mochitest/server_TESTNAME_idtoken.sjs",
};

Просмотреть файл

@ -1,4 +0,0 @@
{
"privacy_policy_url" : "https://example.net/tests/dom/credentialmanagement/identity/tests/mochitest/null.txt",
"terms_of_service_url" : "https://example.net/tests/dom/credentialmanagement/identity/tests/mochitest/null.txt"
}

Просмотреть файл

@ -1,2 +0,0 @@
Content-Type: application/json
Access-Control-Allow-Origin: *

Просмотреть файл

@ -12,8 +12,6 @@
Pref="dom.security.credentialmanagement.identity.enabled"]
interface IdentityCredential : Credential {
readonly attribute USVString? token;
[Throws]
static Promise<undefined> logoutRPs(sequence<IdentityCredentialLogoutRPsRequest> logoutRequests);
};
dictionary IdentityCredentialRequestOptions {
@ -72,7 +70,6 @@ dictionary IdentityAccountList {
};
// https://fedidcg.github.io/FedCM/#idp-api-client-id-metadata-endpoint
[GenerateInit, GenerateConversionToJS]
dictionary IdentityClientMetadata {
USVString privacy_policy_url;
USVString terms_of_service_url;
@ -83,9 +80,3 @@ dictionary IdentityClientMetadata {
dictionary IdentityToken {
required USVString token;
};
// https://fedidcg.github.io/FedCM/#browser-api-idp-sign-out
dictionary IdentityCredentialLogoutRPsRequest {
required UTF8String url;
required UTF8String accountId;
};

Просмотреть файл

@ -25,12 +25,6 @@ XPCOMUtils.defineLazyServiceGetter(
"@mozilla.org/tracking-db-service;1",
"nsITrackingDBService"
);
XPCOMUtils.defineLazyServiceGetter(
lazy,
"IdentityCredentialStorageService",
"@mozilla.org/browser/identity-credential-storage-service;1",
"nsIIdentityCredentialStorageService"
);
/**
* Test if host, OriginAttributes or principal belong to a baseDomain. Also
@ -1384,49 +1378,6 @@ const PreflightCacheCleaner = {
},
};
const IdentityCredentialStorageCleaner = {
async deleteAll() {
lazy.IdentityCredentialStorageService.clear();
},
async deleteByPrincipal(aPrincipal, aIsUserRequest) {
lazy.IdentityCredentialStorageService.deleteFromPrincipal(aPrincipal);
},
async deleteByBaseDomain(aBaseDomain, aIsUserRequest) {
if (!aIsUserRequest) {
return;
}
lazy.IdentityCredentialStorageService.deleteFromBaseDomain(aBaseDomain);
},
async deleteByRange(aFrom, aTo) {
lazy.IdentityCredentialStorageService.deleteFromRange(aFrom, aTo);
},
async deleteByHost(aHost, aOriginAttributes) {
// Delete data from both HTTP and HTTPS sites.
let httpURI = Services.io.newURI("http://" + aHost);
let httpsURI = Services.io.newURI("https://" + aHost);
let httpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
httpURI,
aOriginAttributes
);
let httpsPrincipal = Services.scriptSecurityManager.createContentPrincipal(
httpsURI,
aOriginAttributes
);
lazy.IdentityCredentialStorageService.deleteFromPrincipal(httpPrincipal);
lazy.IdentityCredentialStorageService.deleteFromPrincipal(httpsPrincipal);
},
async deleteByOriginAttributes(aOriginAttributesString) {
lazy.IdentityCredentialStorageService.deleteDataFromOriginAttributesPattern(
aOriginAttributesString
);
},
};
// Here the map of Flags-Cleaners.
const FLAGS_MAP = [
{
@ -1536,11 +1487,6 @@ const FLAGS_MAP = [
flag: Ci.nsIClearDataService.CLEAR_PREFLIGHT_CACHE,
cleaners: [PreflightCacheCleaner],
},
{
flag: Ci.nsIClearDataService.CLEAR_CREDENTIAL_MANAGER_STATE,
cleaners: [IdentityCredentialStorageCleaner],
},
];
export function ClearDataService() {

Просмотреть файл

@ -275,11 +275,6 @@ interface nsIClearDataService : nsISupports
*/
const uint32_t CLEAR_CLIENT_AUTH_REMEMBER_SERVICE = 1 << 24;
/**
* Clear state associated with FedCM
*/
const uint32_t CLEAR_CREDENTIAL_MANAGER_STATE = 1 << 24;
/**
* Use this value to delete all the data.
*/
@ -309,8 +304,7 @@ interface nsIClearDataService : nsISupports
CLEAR_COOKIES | CLEAR_EME | CLEAR_DOWNLOADS | CLEAR_PASSWORDS |
CLEAR_PERMISSIONS | CLEAR_DOM_STORAGES | CLEAR_CONTENT_PREFERENCES |
CLEAR_PREDICTOR_NETWORK_DATA | CLEAR_DOM_PUSH_NOTIFICATIONS |
CLEAR_CLIENT_AUTH_REMEMBER_SERVICE | CLEAR_REPORTS | CLEAR_CERT_EXCEPTIONS |
CLEAR_CREDENTIAL_MANAGER_STATE;
CLEAR_CLIENT_AUTH_REMEMBER_SERVICE | CLEAR_REPORTS | CLEAR_CERT_EXCEPTIONS;
};
/**

Просмотреть файл

@ -63,17 +63,15 @@ export class IdentityCredentialPromptService {
true
);
let headerMessage = localization.formatValueSync(
"identity-credential-header-providers",
"credential-header-providers",
{
host: "<>",
}
);
let [cancel] = localization.formatMessagesSync([
{ id: "identity-credential-cancel-button" },
]);
let cancelLabel = cancel.attributes.find(x => x.name == "label").value;
let cancelKey = cancel.attributes.find(x => x.name == "accesskey").value;
let cancelLabel = localization.formatValueSync("credential-cancel-label");
let cancelKey = localization.formatValueSync(
"credential-cancel-accesskey"
);
// Build the choices into the panel
let listBox = browser.ownerDocument.getElementById(
@ -125,9 +123,6 @@ export class IdentityCredentialPromptService {
browser.ownerDocument.getElementById(
"identity-credential-provider"
).hidden = false;
browser.ownerDocument.getElementById(
"identity-credential-policy"
).hidden = true;
browser.ownerDocument.getElementById(
"identity-credential-account"
).hidden = true;
@ -143,131 +138,6 @@ export class IdentityCredentialPromptService {
});
}
/**
* Ask the user, using a PopupNotification, to approve or disapprove of the policies of the Identity Provider.
* @param {BrowsingContext} browsingContext - The BrowsingContext of the document requesting an identity credential via navigator.credentials.get()
* @param {IdentityProvider} identityProvider - The Identity Provider that the user has selected to use
* @param {IdentityCredentialMetadata} identityCredentialMetadata - The metadata displayed to the user
* @returns {Promise<bool>} A boolean representing the user's acceptance of the metadata.
*/
showPolicyPrompt(
browsingContext,
identityProvider,
identityCredentialMetadata
) {
// For testing only.
if (lazy.SELECT_FIRST_IN_UI_LISTS) {
return Promise.resolve(true);
}
if (
!identityCredentialMetadata ||
(!identityCredentialMetadata.privacy_policy_url &&
!identityCredentialMetadata.terms_of_service_url)
) {
return Promise.resolve(true);
}
return new Promise(function(resolve, reject) {
let browser = browsingContext.top.embedderElement;
if (!browser) {
reject();
return;
}
let providerURI = new URL(identityProvider.configURL);
let providerDisplayDomain = lazy.IDNService.convertToDisplayIDN(
providerURI.host,
{}
);
let currentBaseDomain =
browsingContext.currentWindowContext.documentPrincipal.baseDomain;
// Localize the description
// Bug 1797154 - Convert localization calls to use the async formatValues.
let localization = new Localization(
["preview/identityCredentialNotification.ftl"],
true
);
let descriptionMessage = localization.formatValueSync(
"identity-credential-policy-description",
{
host: currentBaseDomain,
provider: providerDisplayDomain,
}
);
let [accept, cancel] = localization.formatMessagesSync([
{ id: "identity-credential-accept-button" },
{ id: "identity-credential-cancel-button" },
]);
let cancelLabel = cancel.attributes.find(x => x.name == "label").value;
let cancelKey = cancel.attributes.find(x => x.name == "accesskey").value;
let acceptLabel = accept.attributes.find(x => x.name == "label").value;
let acceptKey = accept.attributes.find(x => x.name == "accesskey").value;
let title = localization.formatValueSync(
"identity-credential-policy-title"
);
// Populate the content of the policy panel
let description = browser.ownerDocument.getElementById(
"identity-credential-policy-explanation"
);
description.textContent = descriptionMessage;
let privacyPolicyAnchor = browser.ownerDocument.getElementById(
"identity-credential-privacy-policy"
);
privacyPolicyAnchor.hidden = true;
if (identityCredentialMetadata.privacy_policy_url) {
privacyPolicyAnchor.href =
identityCredentialMetadata.privacy_policy_url;
privacyPolicyAnchor.hidden = false;
}
let termsOfServiceAnchor = browser.ownerDocument.getElementById(
"identity-credential-terms-of-service"
);
termsOfServiceAnchor.hidden = true;
if (identityCredentialMetadata.terms_of_service_url) {
termsOfServiceAnchor.href =
identityCredentialMetadata.terms_of_service_url;
termsOfServiceAnchor.hidden = false;
}
// Construct the necessary arguments for notification behavior
let options = {};
let mainAction = {
label: acceptLabel,
accessKey: acceptKey,
callback(event) {
resolve(true);
},
};
let secondaryActions = [
{
label: cancelLabel,
accessKey: cancelKey,
callback(event) {
resolve(false);
},
},
];
// Show the popup
let ownerDocument = browser.ownerDocument;
ownerDocument.getElementById(
"identity-credential-provider"
).hidden = true;
ownerDocument.getElementById("identity-credential-policy").hidden = false;
ownerDocument.getElementById("identity-credential-account").hidden = true;
browser.ownerGlobal.PopupNotifications.show(
browser,
"identity-credential",
title,
"identity-credential-notification-icon",
mainAction,
secondaryActions,
options
);
});
}
/**
* Ask the user, using a PopupNotification, to select an account from a provided list.
* @param {BrowsingContext} browsingContext - The BrowsingContext of the document requesting an identity credential via navigator.credentials.get()
@ -295,23 +165,21 @@ export class IdentityCredentialPromptService {
true
);
let headerMessage = localization.formatValueSync(
"identity-credential-header-accounts",
"credential-header-accounts",
{
host: "<>",
}
);
let descriptionMessage = localization.formatValueSync(
"identity-credential-description-account-explanation",
"credential-description-account-explanation",
{
host: currentOrigin,
}
);
let [cancel] = localization.formatMessagesSync([
{ id: "identity-credential-cancel-button" },
]);
let cancelLabel = cancel.attributes.find(x => x.name == "label").value;
let cancelKey = cancel.attributes.find(x => x.name == "accesskey").value;
let cancelLabel = localization.formatValueSync("credential-cancel-label");
let cancelKey = localization.formatValueSync(
"credential-cancel-accesskey"
);
// Add the description text
browser.ownerDocument.getElementById(
@ -360,9 +228,6 @@ export class IdentityCredentialPromptService {
browser.ownerDocument.getElementById(
"identity-credential-provider"
).hidden = true;
browser.ownerDocument.getElementById(
"identity-credential-policy"
).hidden = true;
browser.ownerDocument.getElementById(
"identity-credential-account"
).hidden = false;

Просмотреть файл

@ -1,582 +0,0 @@
/* -*- 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 "IdentityCredentialStorageService.h"
#include "ErrorList.h"
#include "MainThreadUtils.h"
#include "mozIStorageService.h"
#include "mozIStorageConnection.h"
#include "mozIStorageStatement.h"
#include "mozStorageCID.h"
#include "mozilla/Base64.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/OriginAttributes.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsCRT.h"
#include "nsDebug.h"
#include "nsDirectoryServiceUtils.h"
#include "nsIObserverService.h"
#include "nsServiceManagerUtils.h"
#include "prtime.h"
#define ACCOUNT_STATE_FILENAME "credentialstate.sqlite"_ns
#define SCHEMA_VERSION 1
#define MODIFIED_NOW PR_Now()
namespace mozilla {
StaticRefPtr<IdentityCredentialStorageService>
gIdentityCredentialStorageService;
NS_IMPL_ISUPPORTS(IdentityCredentialStorageService,
nsIIdentityCredentialStorageService, nsIObserver)
IdentityCredentialStorageService::~IdentityCredentialStorageService() {
AssertIsOnMainThread();
}
already_AddRefed<IdentityCredentialStorageService>
IdentityCredentialStorageService::GetSingleton() {
AssertIsOnMainThread();
if (!gIdentityCredentialStorageService) {
gIdentityCredentialStorageService = new IdentityCredentialStorageService();
ClearOnShutdown(&gIdentityCredentialStorageService);
nsresult rv = gIdentityCredentialStorageService->Init();
NS_ENSURE_SUCCESS(rv, nullptr);
}
RefPtr<IdentityCredentialStorageService> service =
gIdentityCredentialStorageService;
return service.forget();
}
nsresult createTable(mozIStorageConnection* aDatabase) {
// Currently there is only one schema version, so we just need to create the
// table. The definition uses no explicit rowid column, instead primary keying
// on the tuple defined in the spec. We store two bits and some additional
// data to make integration with the ClearDataService easier/possible.
NS_ENSURE_ARG_POINTER(aDatabase);
nsresult rv = aDatabase->SetSchemaVersion(SCHEMA_VERSION);
NS_ENSURE_SUCCESS(rv, rv);
rv = aDatabase->ExecuteSimpleSQL(
nsLiteralCString("CREATE TABLE identity ("
"rpOrigin TEXT NOT NULL"
",idpOrigin TEXT NOT NULL"
",credentialId TEXT NOT NULL"
",registered INTEGER"
",allowLogout INTEGER"
",modificationTime INTEGER"
",rpBaseDomain TEXT"
",PRIMARY KEY (rpOrigin, idpOrigin, credentialId)"
")"));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
nsresult getMemoryDatabaseConnection(mozIStorageConnection** aDatabase) {
nsCOMPtr<mozIStorageService> storage =
do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(storage, NS_ERROR_UNEXPECTED);
nsresult rv = storage->OpenSpecialDatabase(
kMozStorageMemoryStorageKey, "icsprivatedb"_ns,
mozIStorageService::CONNECTION_DEFAULT, aDatabase);
NS_ENSURE_SUCCESS(rv, rv);
bool ready = false;
(*aDatabase)->GetConnectionReady(&ready);
NS_ENSURE_TRUE(ready, NS_ERROR_UNEXPECTED);
bool tableExists = false;
(*aDatabase)->TableExists("identity"_ns, &tableExists);
if (!tableExists) {
rv = createTable(*aDatabase);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
nsresult getDiskDatabaseConnection(mozIStorageConnection** aDatabase) {
// Create the file we store the database in.
nsCOMPtr<nsIFile> profileDir;
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(profileDir));
NS_ENSURE_SUCCESS(rv, rv);
rv = profileDir->AppendNative(nsLiteralCString(ACCOUNT_STATE_FILENAME));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<mozIStorageService> storage =
do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(storage, NS_ERROR_UNEXPECTED);
rv = storage->OpenDatabase(profileDir, mozIStorageService::CONNECTION_DEFAULT,
aDatabase);
if (rv == NS_ERROR_FILE_CORRUPTED) {
rv = profileDir->Remove(false);
NS_ENSURE_SUCCESS(rv, rv);
rv = storage->OpenDatabase(
profileDir, mozIStorageService::CONNECTION_DEFAULT, aDatabase);
}
NS_ENSURE_SUCCESS(rv, rv);
bool ready = false;
(*aDatabase)->GetConnectionReady(&ready);
NS_ENSURE_TRUE(ready, NS_ERROR_UNEXPECTED);
return NS_OK;
}
nsresult IdentityCredentialStorageService::Init() {
AssertIsOnMainThread();
nsresult rv;
RefPtr<mozIStorageConnection> database;
rv = getDiskDatabaseConnection(getter_AddRefs(database));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> privateBrowsingDatabase;
rv = getMemoryDatabaseConnection(getter_AddRefs(privateBrowsingDatabase));
NS_ENSURE_SUCCESS(rv, rv);
// Create the database table for memory and disk if it doesn't already exist
bool tableExists = false;
database->TableExists("identity"_ns, &tableExists);
if (!tableExists) {
rv = createTable(database);
NS_ENSURE_SUCCESS(rv, rv);
}
// Register the PBMode cleaner (IdentityCredentialStorageService::Observe) as
// an observer.
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
NS_ENSURE_TRUE(observerService, NS_ERROR_FAILURE);
observerService->AddObserver(this, "last-pb-context-exited", false);
mInitialized.Flip();
return NS_OK;
}
NS_IMETHODIMP IdentityCredentialStorageService::SetState(
nsIPrincipal* aRPPrincipal, nsIPrincipal* aIDPPrincipal,
nsACString const& aCredentialID, bool aRegistered, bool aAllowLogout) {
AssertIsOnMainThread();
MOZ_ASSERT(XRE_IsParentProcess());
NS_ENSURE_ARG_POINTER(aRPPrincipal);
NS_ENSURE_ARG_POINTER(aIDPPrincipal);
nsresult rv;
rv = IdentityCredentialStorageService::ValidatePrincipal(aRPPrincipal);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> database;
rv = getDiskDatabaseConnection(getter_AddRefs(database));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> privateBrowsingDatabase;
rv = getMemoryDatabaseConnection(getter_AddRefs(privateBrowsingDatabase));
NS_ENSURE_SUCCESS(rv, rv);
// Build the statement on one of our databases. This is in memory if the RP
// principal is private, disk otherwise. The queries are the same, using the
// SQLite3 UPSERT syntax.
nsCOMPtr<mozIStorageStatement> stmt;
nsCString rpOrigin;
rv = aRPPrincipal->GetOrigin(rpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
constexpr auto upsert_query = nsLiteralCString(
"INSERT INTO identity(rpOrigin, idpOrigin, credentialId, "
"registered, allowLogout, modificationTime, rpBaseDomain)"
"VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)"
"ON CONFLICT(rpOrigin, idpOrigin, credentialId)"
"DO UPDATE SET registered=excluded.registered, "
"allowLogout=excluded.allowLogout, "
"modificationTime=excluded.modificationTime");
if (OriginAttributes::IsPrivateBrowsing(rpOrigin)) {
rv = privateBrowsingDatabase->CreateStatement(upsert_query,
getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
} else {
rv = database->CreateStatement(upsert_query, getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
}
// Bind the arguments to the query and execute it.
nsCString idpOrigin;
rv = aIDPPrincipal->GetOrigin(idpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
nsCString rpBaseDomain;
rv = aRPPrincipal->GetBaseDomain(rpBaseDomain);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByIndex(0, rpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByIndex(1, idpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByIndex(2, aCredentialID);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindInt32ByIndex(3, aRegistered ? 1 : 0);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindInt32ByIndex(4, aAllowLogout ? 1 : 0);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindInt64ByIndex(5, MODIFIED_NOW);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByIndex(6, rpBaseDomain);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP IdentityCredentialStorageService::GetState(
nsIPrincipal* aRPPrincipal, nsIPrincipal* aIDPPrincipal,
nsACString const& aCredentialID, bool* aRegistered, bool* aAllowLogout) {
AssertIsOnMainThread();
nsresult rv;
rv = IdentityCredentialStorageService::ValidatePrincipal(aRPPrincipal);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> database;
rv = getDiskDatabaseConnection(getter_AddRefs(database));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> privateBrowsingDatabase;
rv = getMemoryDatabaseConnection(getter_AddRefs(privateBrowsingDatabase));
NS_ENSURE_SUCCESS(rv, rv);
auto constexpr selectQuery = nsLiteralCString(
"SELECT registered, allowLogout FROM identity WHERE rpOrigin=?1 AND "
"idpOrigin=?2 AND credentialId=?3");
nsCString rpOrigin;
nsCString idpOrigin;
rv = aRPPrincipal->GetOrigin(rpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
rv = aIDPPrincipal->GetOrigin(idpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
// If the RP principal is private, query the provided tuple in memory
nsCOMPtr<mozIStorageStatement> stmt;
if (OriginAttributes::IsPrivateBrowsing(rpOrigin)) {
rv = privateBrowsingDatabase->CreateStatement(selectQuery,
getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
} else {
rv = database->CreateStatement(selectQuery, getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
}
rv = stmt->BindUTF8StringByIndex(0, rpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByIndex(1, idpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByIndex(2, aCredentialID);
NS_ENSURE_SUCCESS(rv, rv);
bool hasResult;
// If we find a result, return it
if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
int64_t registeredInt, allowLogoutInt;
rv = stmt->GetInt64(0, &registeredInt);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->GetInt64(1, &allowLogoutInt);
NS_ENSURE_SUCCESS(rv, rv);
*aRegistered = registeredInt != 0;
*aAllowLogout = allowLogoutInt != 0;
return NS_OK;
}
// The tuple was not found on disk or in memory, use the defaults.
*aRegistered = false;
*aAllowLogout = false;
return NS_OK;
}
NS_IMETHODIMP IdentityCredentialStorageService::Delete(
nsIPrincipal* aRPPrincipal, nsIPrincipal* aIDPPrincipal,
nsACString const& aCredentialID) {
AssertIsOnMainThread();
nsresult rv;
rv = IdentityCredentialStorageService::ValidatePrincipal(aRPPrincipal);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> database;
rv = getDiskDatabaseConnection(getter_AddRefs(database));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> privateBrowsingDatabase;
rv = getMemoryDatabaseConnection(getter_AddRefs(privateBrowsingDatabase));
NS_ENSURE_SUCCESS(rv, rv);
auto constexpr deleteQuery = nsLiteralCString(
"DELETE FROM identity WHERE rpOrigin=?1 AND idpOrigin=?2 AND "
"credentialId=?3");
// Delete all entries matching this tuple.
// We only have to execute one statement because we don't want to delete
// entries on disk from PB mode
nsCOMPtr<mozIStorageStatement> stmt;
nsCString rpOrigin;
rv = aRPPrincipal->GetOrigin(rpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
if (OriginAttributes::IsPrivateBrowsing(rpOrigin)) {
rv = privateBrowsingDatabase->CreateStatement(deleteQuery,
getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
} else {
rv = database->CreateStatement(deleteQuery, getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
}
nsCString idpOrigin;
rv = aIDPPrincipal->GetOrigin(idpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByIndex(0, rpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByIndex(1, idpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByIndex(2, aCredentialID);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP IdentityCredentialStorageService::Clear() {
AssertIsOnMainThread();
RefPtr<mozIStorageConnection> database;
nsresult rv = getDiskDatabaseConnection(getter_AddRefs(database));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> privateBrowsingDatabase;
rv = getMemoryDatabaseConnection(getter_AddRefs(privateBrowsingDatabase));
NS_ENSURE_SUCCESS(rv, rv);
// We just clear all rows from both databases.
rv = privateBrowsingDatabase->ExecuteSimpleSQL(
nsLiteralCString("DELETE FROM identity;"));
NS_ENSURE_SUCCESS(rv, rv);
rv = database->ExecuteSimpleSQL(nsLiteralCString("DELETE FROM identity;"));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP
IdentityCredentialStorageService::DeleteFromOriginAttributesPattern(
nsAString const& aOriginAttributesPattern) {
nsresult rv;
NS_ENSURE_FALSE(aOriginAttributesPattern.IsEmpty(), NS_ERROR_FAILURE);
// parse the JSON origin attribute argument
OriginAttributesPattern oaPattern;
if (!oaPattern.Init(aOriginAttributesPattern)) {
NS_ERROR("Could not parse the argument for OriginAttributes");
return NS_ERROR_FAILURE;
}
RefPtr<mozIStorageConnection> database;
rv = getDiskDatabaseConnection(getter_AddRefs(database));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> privateBrowsingDatabase;
rv = getMemoryDatabaseConnection(getter_AddRefs(privateBrowsingDatabase));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> chosenDatabase;
if (!oaPattern.mPrivateBrowsingId.WasPassed() ||
oaPattern.mPrivateBrowsingId.Value() ==
nsIScriptSecurityManager::DEFAULT_PRIVATE_BROWSING_ID) {
chosenDatabase = database;
} else {
chosenDatabase = privateBrowsingDatabase;
}
chosenDatabase->BeginTransaction();
Vector<int64_t> rowIdsToDelete;
nsCOMPtr<mozIStorageStatement> stmt;
rv = chosenDatabase->CreateStatement(
nsLiteralCString("SELECT rowid, rpOrigin FROM identity;"),
getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
bool hasResult;
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
int64_t rowId;
nsCString rpOrigin;
nsCString rpOriginNoSuffix;
rv = stmt->GetInt64(0, &rowId);
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
rv = stmt->GetUTF8String(1, rpOrigin);
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
OriginAttributes oa;
bool parsedSuccessfully = oa.PopulateFromOrigin(rpOrigin, rpOriginNoSuffix);
NS_ENSURE_TRUE(parsedSuccessfully, NS_ERROR_FAILURE);
if (oaPattern.Matches(oa)) {
bool appendedSuccessfully = rowIdsToDelete.append(rowId);
NS_ENSURE_TRUE(appendedSuccessfully, NS_ERROR_FAILURE);
}
}
for (auto rowId : rowIdsToDelete) {
rv = chosenDatabase->CreateStatement(
nsLiteralCString("DELETE FROM identity WHERE rowid = ?1"),
getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindInt64ByIndex(0, rowId);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
}
rv = chosenDatabase->CommitTransaction();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP IdentityCredentialStorageService::DeleteFromTimeRange(
int64_t aStart, int64_t aEnd) {
nsresult rv;
RefPtr<mozIStorageConnection> database;
rv = getDiskDatabaseConnection(getter_AddRefs(database));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> privateBrowsingDatabase;
rv = getMemoryDatabaseConnection(getter_AddRefs(privateBrowsingDatabase));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<mozIStorageStatement> stmt;
auto constexpr deleteTimeQuery = nsLiteralCString(
"DELETE FROM identity WHERE modificationTime > ?1 and modificationTime < "
"?2");
// We just clear all matching rows from both databases.
rv = privateBrowsingDatabase->CreateStatement(deleteTimeQuery,
getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindInt64ByIndex(0, aStart);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindInt64ByIndex(1, aEnd);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
rv = database->CreateStatement(deleteTimeQuery, getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindInt64ByIndex(0, aStart);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindInt64ByIndex(1, aEnd);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP IdentityCredentialStorageService::
IdentityCredentialStorageService::DeleteFromPrincipal(
nsIPrincipal* aRPPrincipal) {
nsresult rv =
IdentityCredentialStorageService::ValidatePrincipal(aRPPrincipal);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> database;
rv = getDiskDatabaseConnection(getter_AddRefs(database));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> privateBrowsingDatabase;
rv = getMemoryDatabaseConnection(getter_AddRefs(privateBrowsingDatabase));
NS_ENSURE_SUCCESS(rv, rv);
auto constexpr deletePrincipalQuery =
nsLiteralCString("DELETE FROM identity WHERE rpOrigin=?1");
// create the (identical) statement on the database we need to clear from.
// Like delete, a given argument is either private or not, so there is only
// one argument to execute.
nsCOMPtr<mozIStorageStatement> stmt;
nsCString rpOrigin;
rv = aRPPrincipal->GetOrigin(rpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
if (OriginAttributes::IsPrivateBrowsing(rpOrigin)) {
rv = privateBrowsingDatabase->CreateStatement(deletePrincipalQuery,
getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
} else {
rv = database->CreateStatement(deletePrincipalQuery, getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
}
rv = stmt->BindUTF8StringByIndex(0, rpOrigin);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP IdentityCredentialStorageService::DeleteFromBaseDomain(
nsACString const& aBaseDomain) {
nsresult rv;
RefPtr<mozIStorageConnection> database;
rv = getDiskDatabaseConnection(getter_AddRefs(database));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<mozIStorageConnection> privateBrowsingDatabase;
rv = getMemoryDatabaseConnection(getter_AddRefs(privateBrowsingDatabase));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<mozIStorageStatement> stmt;
auto constexpr deleteBaseDomainQuery =
nsLiteralCString("DELETE FROM identity WHERE rpBaseDomain=?1");
// We just clear all matching rows from both databases.
// This is very easy because we store the relevant base domain.
rv = database->CreateStatement(deleteBaseDomainQuery, getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByIndex(0, aBaseDomain);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
rv = privateBrowsingDatabase->CreateStatement(deleteBaseDomainQuery,
getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->BindUTF8StringByIndex(0, aBaseDomain);
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->Execute();
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP
IdentityCredentialStorageService::Observe(nsISupports* aSubject,
const char* aTopic,
const char16_t* aData) {
AssertIsOnMainThread();
// Double check that we have the right topic.
if (!nsCRT::strcmp(aTopic, "last-pb-context-exited")) {
RefPtr<mozIStorageConnection> privateBrowsingDatabase;
nsresult rv =
getMemoryDatabaseConnection(getter_AddRefs(privateBrowsingDatabase));
NS_ENSURE_SUCCESS(rv, rv);
// Delete exactly all of the private browsing data
rv = privateBrowsingDatabase->ExecuteSimpleSQL(
nsLiteralCString("DELETE FROM identity;"));
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
// static
nsresult IdentityCredentialStorageService::ValidatePrincipal(
nsIPrincipal* aPrincipal) {
// We add some constraints on the RP principal where it is provided to reduce
// edge cases in implementation. These are reasonable constraints with the
// semantics of the store: it must be a http or https content principal.
NS_ENSURE_ARG_POINTER(aPrincipal);
NS_ENSURE_TRUE(aPrincipal->GetIsContentPrincipal(), NS_ERROR_FAILURE);
nsCString scheme;
nsresult rv = aPrincipal->GetScheme(scheme);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(scheme.Equals("http"_ns) || scheme.Equals("https"_ns),
NS_ERROR_FAILURE);
return NS_OK;
}
} // namespace mozilla

Просмотреть файл

@ -1,47 +0,0 @@
/* -*- 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/. */
#ifndef MOZILLA_IDENTITYCREDENTIALSTORAGESERVICE_H_
#define MOZILLA_IDENTITYCREDENTIALSTORAGESERVICE_H_
#include "ErrorList.h"
#include "mozIStorageConnection.h"
#include "mozilla/AlreadyAddRefed.h"
#include "nsIIdentityCredentialStorageService.h"
#include "mozilla/dom/FlippedOnce.h"
#include "nsIObserver.h"
#include "nsISupports.h"
namespace mozilla {
class IdentityCredentialStorageService final
: public nsIIdentityCredentialStorageService,
public nsIObserver {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIIDENTITYCREDENTIALSTORAGESERVICE
NS_DECL_NSIOBSERVER
// Returns the singleton instance which is addreffed.
static already_AddRefed<IdentityCredentialStorageService> GetSingleton();
IdentityCredentialStorageService(const IdentityCredentialStorageService&) =
delete;
IdentityCredentialStorageService& operator=(
const IdentityCredentialStorageService&) = delete;
private:
IdentityCredentialStorageService() = default;
~IdentityCredentialStorageService();
nsresult Init();
static nsresult ValidatePrincipal(nsIPrincipal* aPrincipal);
FlippedOnce<false> mInitialized;
};
} // namespace mozilla
#endif /* MOZILLA_IDENTITYCREDENTIALSTORAGESERVICE_H_ */

Просмотреть файл

@ -13,15 +13,4 @@ Classes = [
'constructor': 'IdentityCredentialPromptService',
'name': 'IdentityCredentialPromptService',
},
{
'cid': '{029823d0-0448-46c5-af1f-25cd4501d0d7}',
'contract_ids': ['@mozilla.org/browser/identity-credential-storage-service;1'],
'processes': ProcessSelector.MAIN_PROCESS_ONLY,
'singleton' : True,
'type': 'mozilla::IdentityCredentialStorageService',
'headers': ['mozilla/IdentityCredentialStorageService.h'],
'interfaces': ['nsIIdentityCredentialStorageService'],
'name': 'IdentityCredentialStorageService',
'constructor': 'mozilla::IdentityCredentialStorageService::GetSingleton',
},
]

Просмотреть файл

@ -7,17 +7,8 @@
with Files("**"):
BUG_COMPONENT = ("Core", "DOM: Credential Management")
EXPORTS.mozilla += [
"IdentityCredentialStorageService.h",
]
UNIFIED_SOURCES += ["IdentityCredentialStorageService.cpp"]
FINAL_LIBRARY = "xul"
XPIDL_SOURCES += [
"nsIIdentityCredentialPromptService.idl",
"nsIIdentityCredentialStorageService.idl",
]
XPIDL_MODULE = "dom_identitycredential"
@ -26,8 +17,6 @@ EXTRA_JS_MODULES += [
"IdentityCredentialPromptService.sys.mjs",
]
XPCSHELL_TESTS_MANIFESTS += ["tests/xpcshell/xpcshell.ini"]
XPCOM_MANIFESTS += [
"components.conf",
]

Просмотреть файл

@ -11,9 +11,6 @@ interface nsIIdentityCredentialPromptService : nsISupports {
// Display to the user an interface to choose from among the identity providers listed
// Resolves with one of the elements of the list.
Promise showProviderPrompt(in BrowsingContext browsingContext, in jsval identityProviders);
// Display to the user an interface to approve (or disapprove) of the terms of service for
// the identity provider when used on the current site.
Promise showPolicyPrompt(in BrowsingContext browsingContext, in jsval identityProvider, in jsval identityClientMetadata);
// Display to the user an interface to choose from among the accounts listed.
// Resolves with one of the elements of the list.
Promise showAccountListPrompt(in BrowsingContext browsingContext, in jsval accountList);

Просмотреть файл

@ -1,38 +0,0 @@
/* 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 "nsISupports.idl"
#include "nsIPrincipal.idl"
webidl IdentityCredential;
[scriptable, builtinclass, uuid(029823d0-0448-46c5-af1f-25cd4501d0d7)]
interface nsIIdentityCredentialStorageService : nsISupports {
// Store the registered and allowLogout bit for the tuple (rpPrincipal, idpPrincipal, credentialID).
// This goes straight to disk if rpPrincipal is not in Private Browsing mode and stays in memory otherwise.
// Additionally, if rpPrincipal is private, it will be cleared when the user closes the last private browsing window.
void setState(in nsIPrincipal rpPrincipal, in nsIPrincipal idpPrincipal, in ACString credentialID, in boolean registered, in boolean allowLogout);
// Retrieve the registered and allowLogout bits for the tuple (rpPrincipal, idpPrincipal, credentialID).
// This will always return defaults, even if there was never a value stored or it was deleted.
void getState(in nsIPrincipal rpPrincipal, in nsIPrincipal idpPrincipal, in ACString credentialID, out boolean registered, out boolean allowLogout);
// Delete the entry for the tuple (rpPrincipal, idpPrincipal, credentialID).
void delete(in nsIPrincipal rpPrincipal, in nsIPrincipal idpPrincipal, in ACString credentialID);
// Delete all data in this service.
void clear();
// Delete all data stored under a tuple with rpPrincipal that has the given base domain
void deleteFromBaseDomain(in ACString baseDomain);
// Delete all data stored under a tuple with a given rpPrincipal
void deleteFromPrincipal(in nsIPrincipal rpPrincipal);
// Delete all data stored in the given time range (microseconds since epoch)
void deleteFromTimeRange(in PRTime aFrom, in PRTime aTo);
// Delete all data matching the given Origin Attributes pattern
void deleteFromOriginAttributesPattern(in AString aPattern);
};

Просмотреть файл

@ -1,9 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const { TestUtils } = ChromeUtils.import(
"resource://testing-common/TestUtils.jsm"
);

Просмотреть файл

@ -1,300 +0,0 @@
/* 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/. */
XPCOMUtils.defineLazyServiceGetter(
this,
"IdentityCredentialStorageService",
"@mozilla.org/browser/identity-credential-storage-service;1",
"nsIIdentityCredentialStorageService"
);
do_get_profile();
add_task(async function test_insert_and_delete() {
let rpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://rp.com/"),
{}
);
let idpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://idp.com/"),
{}
);
const credentialID = "ID";
// Test initial value
let registered = {};
let allowLogout = {};
IdentityCredentialStorageService.getState(
rpPrincipal,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(!registered.value, "Should not be registered initially.");
Assert.ok(!allowLogout.value, "Should not allow logout initially.");
// Set and read a value
IdentityCredentialStorageService.setState(
rpPrincipal,
idpPrincipal,
credentialID,
true,
true
);
IdentityCredentialStorageService.getState(
rpPrincipal,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(registered.value, "Should be registered by set.");
Assert.ok(allowLogout.value, "Should now allow logout by set.");
IdentityCredentialStorageService.delete(
rpPrincipal,
idpPrincipal,
credentialID
);
IdentityCredentialStorageService.getState(
rpPrincipal,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(!registered.value, "Should not be registered after deletion.");
Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
IdentityCredentialStorageService.clear();
});
add_task(async function test_basedomain_delete() {
let rpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://rp.com/"),
{}
);
let rpPrincipal2 = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://www.rp.com/"),
{}
);
let rpPrincipal3 = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://www.other.com/"),
{}
);
let idpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://idp.com/"),
{}
);
const credentialID = "ID";
let registered = {};
let allowLogout = {};
// Set values
IdentityCredentialStorageService.setState(
rpPrincipal,
idpPrincipal,
credentialID,
true,
true
);
IdentityCredentialStorageService.setState(
rpPrincipal2,
idpPrincipal,
credentialID,
true,
true
);
IdentityCredentialStorageService.setState(
rpPrincipal3,
idpPrincipal,
credentialID,
true,
true
);
IdentityCredentialStorageService.deleteFromBaseDomain(
rpPrincipal2.baseDomain
);
IdentityCredentialStorageService.getState(
rpPrincipal,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(!registered.value, "Should not be registered after deletion.");
Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
IdentityCredentialStorageService.getState(
rpPrincipal2,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(!registered.value, "Should not be registered after deletion.");
Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
IdentityCredentialStorageService.getState(
rpPrincipal3,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(registered.value, "Should be registered by set.");
Assert.ok(allowLogout.value, "Should now allow logout by set.");
IdentityCredentialStorageService.clear();
});
add_task(async function test_principal_delete() {
let rpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://rp.com/"),
{}
);
let rpPrincipal2 = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://www.rp.com/"),
{}
);
let rpPrincipal3 = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://www.other.com/"),
{}
);
let idpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://idp.com/"),
{}
);
const credentialID = "ID";
let registered = {};
let allowLogout = {};
// Set values
IdentityCredentialStorageService.setState(
rpPrincipal,
idpPrincipal,
credentialID,
true,
true
);
IdentityCredentialStorageService.setState(
rpPrincipal2,
idpPrincipal,
credentialID,
true,
true
);
IdentityCredentialStorageService.setState(
rpPrincipal3,
idpPrincipal,
credentialID,
true,
true
);
IdentityCredentialStorageService.deleteFromPrincipal(rpPrincipal2);
IdentityCredentialStorageService.getState(
rpPrincipal,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(registered.value, "Should be registered by set.");
Assert.ok(allowLogout.value, "Should now allow logout by set.");
IdentityCredentialStorageService.getState(
rpPrincipal2,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(!registered.value, "Should not be registered after deletion.");
Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
IdentityCredentialStorageService.getState(
rpPrincipal3,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(registered.value, "Should be registered by set.");
Assert.ok(allowLogout.value, "Should now allow logout by set.");
IdentityCredentialStorageService.clear();
});
add_task(async function test_principal_delete() {
let rpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://rp.com/"),
{}
);
let rpPrincipal2 = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://rp.com/"),
{ privateBrowsingId: 1 }
);
let rpPrincipal3 = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://www.other.com/"),
{ privateBrowsingId: 1 }
);
let idpPrincipal = Services.scriptSecurityManager.createContentPrincipal(
Services.io.newURI("https://idp.com/"),
{}
);
const credentialID = "ID";
let registered = {};
let allowLogout = {};
// Set values
IdentityCredentialStorageService.setState(
rpPrincipal,
idpPrincipal,
credentialID,
true,
true
);
IdentityCredentialStorageService.setState(
rpPrincipal2,
idpPrincipal,
credentialID,
true,
true
);
IdentityCredentialStorageService.setState(
rpPrincipal3,
idpPrincipal,
credentialID,
true,
true
);
IdentityCredentialStorageService.deleteFromOriginAttributesPattern(
'{ "privateBrowsingId": 1 }'
);
IdentityCredentialStorageService.getState(
rpPrincipal,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(registered.value, "Should be registered by set.");
Assert.ok(allowLogout.value, "Should now allow logout by set.");
IdentityCredentialStorageService.getState(
rpPrincipal2,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(!registered.value, "Should not be registered after deletion.");
Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
IdentityCredentialStorageService.getState(
rpPrincipal3,
idpPrincipal,
credentialID,
registered,
allowLogout
);
Assert.ok(!registered.value, "Should not be registered after deletion.");
Assert.ok(!allowLogout.value, "Should not allow logout after deletion.");
IdentityCredentialStorageService.clear();
});

Просмотреть файл

@ -1,4 +0,0 @@
[DEFAULT]
head = head.js
[test_identity_credential_storage_service.js]