Bug 1278037 - Part 3: Modify the nsIQuotaManagerService.clearStoragesForPrincipal() for clearing all storages under the given origin. r=janv

--HG--
extra : rebase_source : a7fdc05823bf274258588cd682bc2698d39b452d
extra : histedit_source : 4222585575bb96126cd8bca7e2c342d121535752
This commit is contained in:
Tim Huang 2016-08-17 14:46:16 +08:00
parent c0c2d18169
commit 5277f5e7aa
4 changed files with 30 additions and 3 deletions

View File

@ -6251,8 +6251,11 @@ OriginClearOp::DoInitOnMainThread()
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mOriginScope.SetFromOrigin(origin);
if (params.clearAll()) {
mOriginScope.SetFromPrefix(origin);
} else {
mOriginScope.SetFromOrigin(origin);
}
}
return NS_OK;
@ -6289,6 +6292,10 @@ OriginClearOp::DeleteFiles(QuotaManager* aQuotaManager,
nsCString originSanitized(originScope.GetOrigin());
SanitizeOriginString(originSanitized);
originScope.SetOrigin(originSanitized);
} else if (originScope.IsPrefix()) {
nsCString prefixSanitized(originScope.GetPrefix());
SanitizeOriginString(prefixSanitized);
originScope.SetPrefix(prefixSanitized);
}
bool hasMore;

View File

@ -33,6 +33,7 @@ struct ClearOriginParams
PrincipalInfo principalInfo;
PersistenceType persistenceType;
bool persistenceTypeIsExplicit;
bool clearAll;
};
struct ClearOriginsParams

View File

@ -561,12 +561,22 @@ QuotaManagerService::Clear(nsIQuotaRequest** _retval)
NS_IMETHODIMP
QuotaManagerService::ClearStoragesForPrincipal(nsIPrincipal* aPrincipal,
const nsACString& aPersistenceType,
bool aClearAll,
nsIQuotaRequest** _retval)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aPrincipal);
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
nsCString suffix;
BasePrincipal::Cast(aPrincipal)->OriginAttributesRef().CreateSuffix(suffix);
if (NS_WARN_IF(aClearAll && !suffix.IsEmpty())) {
// The originAttributes should be default originAttributes when the
// aClearAll flag is set.
return NS_ERROR_INVALID_ARG;
}
RefPtr<Request> request = new Request(aPrincipal);
ClearOriginParams params;
@ -596,6 +606,8 @@ QuotaManagerService::ClearStoragesForPrincipal(nsIPrincipal* aPrincipal,
params.persistenceTypeIsExplicit() = true;
}
params.clearAll() = aClearAll;
nsAutoPtr<PendingRequestInfo> info(new RequestInfo(request, params));
rv = InitiateRequest(info);

View File

@ -50,10 +50,17 @@ interface nsIQuotaManagerService : nsISupports
*
* @param aPrincipal
* A principal for the origin whose storages are to be cleared.
* @param aPersistenceType
* An optional string that tells what persistence type of storages
* will be cleared.
* @param aClearAll
* An optional boolean to indicate clearing all storages under the
* given origin.
*/
[must_use] nsIQuotaRequest
clearStoragesForPrincipal(in nsIPrincipal aPrincipal,
[optional] in ACString aPersistenceType);
[optional] in ACString aPersistenceType,
[optional] in boolean aClearAll);
/**
* Resets quota and storage management. This can be used to force