Bug 1915419 - CSSCacheCleaner, JSCacheCleaner support for OriginAttributesPattern. r=emilio,anti-tracking-reviewers,timhuang
Differential Revision: https://phabricator.services.mozilla.com/D220713
This commit is contained in:
@@ -1361,12 +1361,14 @@ void ChromeUtils::ClearRecentJSDevError(GlobalObject&) {
|
|||||||
|
|
||||||
void ChromeUtils::ClearStyleSheetCacheByPrincipal(GlobalObject&,
|
void ChromeUtils::ClearStyleSheetCacheByPrincipal(GlobalObject&,
|
||||||
nsIPrincipal* aForPrincipal) {
|
nsIPrincipal* aForPrincipal) {
|
||||||
SharedStyleSheetCache::Clear(aForPrincipal);
|
SharedStyleSheetCache::Clear(Some(aForPrincipal));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChromeUtils::ClearStyleSheetCacheByBaseDomain(
|
void ChromeUtils::ClearStyleSheetCacheBySite(
|
||||||
GlobalObject&, const nsACString& aBaseDomain) {
|
GlobalObject&, const nsACString& aSchemelessSite,
|
||||||
SharedStyleSheetCache::Clear(nullptr, &aBaseDomain);
|
const dom::OriginAttributesPatternDictionary& aPattern) {
|
||||||
|
SharedStyleSheetCache::Clear(Nothing(), Some(nsCString(aSchemelessSite)),
|
||||||
|
Some(OriginAttributesPattern(aPattern)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChromeUtils::ClearStyleSheetCache(GlobalObject&) {
|
void ChromeUtils::ClearStyleSheetCache(GlobalObject&) {
|
||||||
@@ -1375,12 +1377,14 @@ void ChromeUtils::ClearStyleSheetCache(GlobalObject&) {
|
|||||||
|
|
||||||
void ChromeUtils::ClearScriptCacheByPrincipal(GlobalObject&,
|
void ChromeUtils::ClearScriptCacheByPrincipal(GlobalObject&,
|
||||||
nsIPrincipal* aForPrincipal) {
|
nsIPrincipal* aForPrincipal) {
|
||||||
SharedScriptCache::Clear(aForPrincipal);
|
SharedScriptCache::Clear(Some(aForPrincipal));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChromeUtils::ClearScriptCacheByBaseDomain(GlobalObject&,
|
void ChromeUtils::ClearScriptCacheBySite(
|
||||||
const nsACString& aBaseDomain) {
|
GlobalObject&, const nsACString& aSchemelessSite,
|
||||||
SharedScriptCache::Clear(nullptr, &aBaseDomain);
|
const dom::OriginAttributesPatternDictionary& aPattern) {
|
||||||
|
SharedScriptCache::Clear(Nothing(), Some(nsCString(aSchemelessSite)),
|
||||||
|
Some(aPattern));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChromeUtils::ClearScriptCache(GlobalObject&) {
|
void ChromeUtils::ClearScriptCache(GlobalObject&) {
|
||||||
|
|||||||
@@ -185,16 +185,18 @@ class ChromeUtils {
|
|||||||
static void ClearStyleSheetCacheByPrincipal(GlobalObject&,
|
static void ClearStyleSheetCacheByPrincipal(GlobalObject&,
|
||||||
nsIPrincipal* aForPrincipal);
|
nsIPrincipal* aForPrincipal);
|
||||||
|
|
||||||
static void ClearStyleSheetCacheByBaseDomain(GlobalObject& aGlobal,
|
static void ClearStyleSheetCacheBySite(
|
||||||
const nsACString& aBaseDomain);
|
GlobalObject&, const nsACString& aSchemelessSite,
|
||||||
|
const dom::OriginAttributesPatternDictionary& aPattern);
|
||||||
|
|
||||||
static void ClearStyleSheetCache(GlobalObject& aGlobal);
|
static void ClearStyleSheetCache(GlobalObject& aGlobal);
|
||||||
|
|
||||||
static void ClearScriptCacheByPrincipal(GlobalObject&,
|
static void ClearScriptCacheByPrincipal(GlobalObject&,
|
||||||
nsIPrincipal* aForPrincipal);
|
nsIPrincipal* aForPrincipal);
|
||||||
|
|
||||||
static void ClearScriptCacheByBaseDomain(GlobalObject& aGlobal,
|
static void ClearScriptCacheBySite(
|
||||||
const nsACString& aBaseDomain);
|
GlobalObject& aGlobal, const nsACString& aSchemelessSite,
|
||||||
|
const dom::OriginAttributesPatternDictionary& aPattern);
|
||||||
|
|
||||||
static void ClearScriptCache(GlobalObject& aGlobal);
|
static void ClearScriptCache(GlobalObject& aGlobal);
|
||||||
|
|
||||||
|
|||||||
@@ -228,10 +228,10 @@ namespace ChromeUtils {
|
|||||||
#endif // NIGHTLY_BUILD
|
#endif // NIGHTLY_BUILD
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the stylesheet cache by baseDomain. This includes associated
|
* Clears the stylesheet cache by site. This includes associated
|
||||||
* state-partitioned cache.
|
* state-partitioned cache.
|
||||||
*/
|
*/
|
||||||
undefined clearStyleSheetCacheByBaseDomain(UTF8String baseDomain);
|
undefined clearStyleSheetCacheBySite(UTF8String schemelessSite, optional OriginAttributesPatternDictionary pattern = {});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the stylesheet cache by principal.
|
* Clears the stylesheet cache by principal.
|
||||||
@@ -244,10 +244,10 @@ namespace ChromeUtils {
|
|||||||
undefined clearStyleSheetCache();
|
undefined clearStyleSheetCache();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the JavaScript cache by baseDomain. This includes associated
|
* Clears the JavaScript cache by schemeless site. This includes associated
|
||||||
* state-partitioned cache.
|
* state-partitioned cache.
|
||||||
*/
|
*/
|
||||||
undefined clearScriptCacheByBaseDomain(UTF8String baseDomain);
|
undefined clearScriptCacheBySite(UTF8String schemelessSite, optional OriginAttributesPatternDictionary pattern = {});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the JavaScript cache by principal.
|
* Clears the JavaScript cache by principal.
|
||||||
|
|||||||
@@ -2090,22 +2090,18 @@ mozilla::ipc::IPCResult ContentChild::RecvRegisterChromeItem(
|
|||||||
return IPC_OK();
|
return IPC_OK();
|
||||||
}
|
}
|
||||||
mozilla::ipc::IPCResult ContentChild::RecvClearStyleSheetCache(
|
mozilla::ipc::IPCResult ContentChild::RecvClearStyleSheetCache(
|
||||||
const Maybe<RefPtr<nsIPrincipal>>& aForPrincipal,
|
const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||||
const Maybe<nsCString>& aBaseDomain) {
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
nsIPrincipal* principal =
|
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||||
aForPrincipal ? aForPrincipal.value().get() : nullptr;
|
SharedStyleSheetCache::Clear(aPrincipal, aSchemelessSite, aPattern);
|
||||||
const nsCString* baseDomain = aBaseDomain ? aBaseDomain.ptr() : nullptr;
|
|
||||||
SharedStyleSheetCache::Clear(principal, baseDomain);
|
|
||||||
return IPC_OK();
|
return IPC_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
mozilla::ipc::IPCResult ContentChild::RecvClearScriptCache(
|
mozilla::ipc::IPCResult ContentChild::RecvClearScriptCache(
|
||||||
const Maybe<RefPtr<nsIPrincipal>>& aForPrincipal,
|
const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||||
const Maybe<nsCString>& aBaseDomain) {
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
nsIPrincipal* principal =
|
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||||
aForPrincipal ? aForPrincipal.value().get() : nullptr;
|
SharedScriptCache::Clear(aPrincipal, aSchemelessSite, aPattern);
|
||||||
const nsCString* baseDomain = aBaseDomain ? aBaseDomain.ptr() : nullptr;
|
|
||||||
SharedScriptCache::Clear(principal, baseDomain);
|
|
||||||
return IPC_OK();
|
return IPC_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -246,12 +246,14 @@ class ContentChild final : public PContentChild,
|
|||||||
const ChromeRegistryItem& item);
|
const ChromeRegistryItem& item);
|
||||||
|
|
||||||
mozilla::ipc::IPCResult RecvClearStyleSheetCache(
|
mozilla::ipc::IPCResult RecvClearStyleSheetCache(
|
||||||
const Maybe<RefPtr<nsIPrincipal>>& aForPrincipal,
|
const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||||
const Maybe<nsCString>& aBaseDomain);
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
|
const Maybe<OriginAttributesPattern>& aPattern);
|
||||||
|
|
||||||
mozilla::ipc::IPCResult RecvClearScriptCache(
|
mozilla::ipc::IPCResult RecvClearScriptCache(
|
||||||
const Maybe<RefPtr<nsIPrincipal>>& aForPrincipal,
|
const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||||
const Maybe<nsCString>& aBaseDomain);
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
|
const Maybe<OriginAttributesPattern>& aPattern);
|
||||||
|
|
||||||
mozilla::ipc::IPCResult RecvClearImageCacheFromPrincipal(
|
mozilla::ipc::IPCResult RecvClearImageCacheFromPrincipal(
|
||||||
nsIPrincipal* aPrincipal);
|
nsIPrincipal* aPrincipal);
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ using mozilla::widget::ThemeChangeKind from "mozilla/widget/WidgetMessageUtils.h
|
|||||||
using class mozilla::dom::MessagePort from "mozilla/dom/MessagePort.h";
|
using class mozilla::dom::MessagePort from "mozilla/dom/MessagePort.h";
|
||||||
[MoveOnly=data] using class mozilla::dom::ipc::StructuredCloneData from "mozilla/dom/ipc/StructuredCloneData.h";
|
[MoveOnly=data] using class mozilla::dom::ipc::StructuredCloneData from "mozilla/dom/ipc/StructuredCloneData.h";
|
||||||
using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";
|
using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";
|
||||||
|
using mozilla::OriginAttributesPattern from "mozilla/dom/quota/SerializationHelpers.h";
|
||||||
using struct mozilla::layers::TextureFactoryIdentifier from "mozilla/layers/CompositorTypes.h";
|
using struct mozilla::layers::TextureFactoryIdentifier from "mozilla/layers/CompositorTypes.h";
|
||||||
using mozilla::layers::CompositorOptions from "mozilla/layers/CompositorOptions.h";
|
using mozilla::layers::CompositorOptions from "mozilla/layers/CompositorOptions.h";
|
||||||
using mozilla::layers::LayersId from "mozilla/layers/LayersTypes.h";
|
using mozilla::layers::LayersId from "mozilla/layers/LayersTypes.h";
|
||||||
@@ -667,11 +668,13 @@ child:
|
|||||||
|
|
||||||
async ClearImageCache(bool privateLoader, bool chrome);
|
async ClearImageCache(bool privateLoader, bool chrome);
|
||||||
|
|
||||||
async ClearStyleSheetCache(nullable nsIPrincipal? aForPrincipal,
|
async ClearStyleSheetCache(nullable nsIPrincipal? aPrincipal,
|
||||||
nsCString? aBaseDomain);
|
nsCString? aSchemelessSite,
|
||||||
|
OriginAttributesPattern? aPattern);
|
||||||
|
|
||||||
async ClearScriptCache(nullable nsIPrincipal? aForPrincipal,
|
async ClearScriptCache(nullable nsIPrincipal? aPrincipal,
|
||||||
nsCString? aBaseDomain);
|
nsCString? aSchemelessSite,
|
||||||
|
OriginAttributesPattern? aPattern);
|
||||||
|
|
||||||
async SetOffline(bool offline);
|
async SetOffline(bool offline);
|
||||||
async SetConnectivity(bool connectivity);
|
async SetConnectivity(bool connectivity);
|
||||||
|
|||||||
@@ -84,13 +84,36 @@ struct ParamTraits<mozilla::OriginAttributesPattern> {
|
|||||||
WriteParam(aWriter, aParam.mPrivateBrowsingId);
|
WriteParam(aWriter, aParam.mPrivateBrowsingId);
|
||||||
WriteParam(aWriter, aParam.mUserContextId);
|
WriteParam(aWriter, aParam.mUserContextId);
|
||||||
WriteParam(aWriter, aParam.mGeckoViewSessionContextId);
|
WriteParam(aWriter, aParam.mGeckoViewSessionContextId);
|
||||||
|
WriteParam(aWriter, aParam.mPartitionKey);
|
||||||
|
WriteParam(aWriter, aParam.mPartitionKeyPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool Read(MessageReader* aReader, paramType* aResult) {
|
static bool Read(MessageReader* aReader, paramType* aResult) {
|
||||||
return ReadParam(aReader, &aResult->mFirstPartyDomain) &&
|
return ReadParam(aReader, &aResult->mFirstPartyDomain) &&
|
||||||
ReadParam(aReader, &aResult->mPrivateBrowsingId) &&
|
ReadParam(aReader, &aResult->mPrivateBrowsingId) &&
|
||||||
ReadParam(aReader, &aResult->mUserContextId) &&
|
ReadParam(aReader, &aResult->mUserContextId) &&
|
||||||
ReadParam(aReader, &aResult->mGeckoViewSessionContextId);
|
ReadParam(aReader, &aResult->mGeckoViewSessionContextId) &&
|
||||||
|
ReadParam(aReader, &aResult->mPartitionKey) &&
|
||||||
|
ReadParam(aReader, &aResult->mPartitionKeyPattern);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct ParamTraits<mozilla::dom::PartitionKeyPatternDictionary> {
|
||||||
|
typedef mozilla::dom::PartitionKeyPatternDictionary paramType;
|
||||||
|
|
||||||
|
static void Write(MessageWriter* aWriter, const paramType& aParam) {
|
||||||
|
WriteParam(aWriter, aParam.mScheme);
|
||||||
|
WriteParam(aWriter, aParam.mBaseDomain);
|
||||||
|
WriteParam(aWriter, aParam.mPort);
|
||||||
|
WriteParam(aWriter, aParam.mForeignByAncestorContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool Read(MessageReader* aReader, paramType* aResult) {
|
||||||
|
return ReadParam(aReader, &aResult->mScheme) &&
|
||||||
|
ReadParam(aReader, &aResult->mBaseDomain) &&
|
||||||
|
ReadParam(aReader, &aResult->mPort) &&
|
||||||
|
ReadParam(aReader, &aResult->mForeignByAncestorContext);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -138,21 +138,19 @@ SharedScriptCache::Observe(nsISupports* aSubject, const char* aTopic,
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SharedScriptCache::Clear(nsIPrincipal* aForPrincipal,
|
void SharedScriptCache::Clear(const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||||
const nsACString* aBaseDomain) {
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
|
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||||
using ContentParent = dom::ContentParent;
|
using ContentParent = dom::ContentParent;
|
||||||
|
|
||||||
if (XRE_IsParentProcess()) {
|
if (XRE_IsParentProcess()) {
|
||||||
auto forPrincipal = aForPrincipal ? Some(RefPtr(aForPrincipal)) : Nothing();
|
|
||||||
auto baseDomain = aBaseDomain ? Some(nsCString(*aBaseDomain)) : Nothing();
|
|
||||||
|
|
||||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||||
Unused << cp->SendClearScriptCache(forPrincipal, baseDomain);
|
Unused << cp->SendClearScriptCache(aPrincipal, aSchemelessSite, aPattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sSingleton) {
|
if (sSingleton) {
|
||||||
sSingleton->ClearInProcess(aForPrincipal, aBaseDomain);
|
sSingleton->ClearInProcess(aPrincipal, aSchemelessSite, aPattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -189,8 +189,9 @@ class SharedScriptCache final
|
|||||||
// a sheet cache (loaders that are not owned by a document).
|
// a sheet cache (loaders that are not owned by a document).
|
||||||
static void LoadCompleted(SharedScriptCache*, ScriptLoadData&);
|
static void LoadCompleted(SharedScriptCache*, ScriptLoadData&);
|
||||||
using Base::LoadCompleted;
|
using Base::LoadCompleted;
|
||||||
static void Clear(nsIPrincipal* aForPrincipal = nullptr,
|
static void Clear(const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal = Nothing(),
|
||||||
const nsACString* aBaseDomain = nullptr);
|
const Maybe<nsCString>& aSchemelessSite = Nothing(),
|
||||||
|
const Maybe<OriginAttributesPattern>& aPattern = Nothing());
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~SharedScriptCache();
|
~SharedScriptCache();
|
||||||
|
|||||||
@@ -199,21 +199,21 @@ SharedStyleSheetCache::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SharedStyleSheetCache::Clear(nsIPrincipal* aForPrincipal,
|
void SharedStyleSheetCache::Clear(
|
||||||
const nsACString* aBaseDomain) {
|
const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||||
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
|
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||||
using ContentParent = dom::ContentParent;
|
using ContentParent = dom::ContentParent;
|
||||||
|
|
||||||
if (XRE_IsParentProcess()) {
|
if (XRE_IsParentProcess()) {
|
||||||
auto forPrincipal = aForPrincipal ? Some(RefPtr(aForPrincipal)) : Nothing();
|
|
||||||
auto baseDomain = aBaseDomain ? Some(nsCString(*aBaseDomain)) : Nothing();
|
|
||||||
|
|
||||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||||
Unused << cp->SendClearStyleSheetCache(forPrincipal, baseDomain);
|
Unused << cp->SendClearStyleSheetCache(aPrincipal, aSchemelessSite,
|
||||||
|
aPattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sSingleton) {
|
if (sSingleton) {
|
||||||
sSingleton->ClearInProcess(aForPrincipal, aBaseDomain);
|
sSingleton->ClearInProcess(aPrincipal, aSchemelessSite, aPattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,8 +66,9 @@ class SharedStyleSheetCache final
|
|||||||
using Base::LoadCompleted;
|
using Base::LoadCompleted;
|
||||||
static void LoadCompletedInternal(SharedStyleSheetCache*, css::SheetLoadData&,
|
static void LoadCompletedInternal(SharedStyleSheetCache*, css::SheetLoadData&,
|
||||||
nsTArray<RefPtr<css::SheetLoadData>>&);
|
nsTArray<RefPtr<css::SheetLoadData>>&);
|
||||||
static void Clear(nsIPrincipal* aForPrincipal = nullptr,
|
static void Clear(const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal = Nothing(),
|
||||||
const nsACString* aBaseDomain = nullptr);
|
const Maybe<nsCString>& aSchemelessSite = Nothing(),
|
||||||
|
const Maybe<OriginAttributesPattern>& aPattern = Nothing());
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void InsertIfNeeded(css::SheetLoadData&);
|
void InsertIfNeeded(css::SheetLoadData&);
|
||||||
|
|||||||
@@ -156,8 +156,9 @@ class SharedSubResourceCache {
|
|||||||
// to be called when the document goes away, or when its principal changes.
|
// to be called when the document goes away, or when its principal changes.
|
||||||
void UnregisterLoader(Loader&);
|
void UnregisterLoader(Loader&);
|
||||||
|
|
||||||
void ClearInProcess(nsIPrincipal* aForPrincipal = nullptr,
|
void ClearInProcess(const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||||
const nsACString* aBaseDomain = nullptr);
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
|
const Maybe<OriginAttributesPattern>& aPattern);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void CancelPendingLoadsForLoader(Loader&);
|
void CancelPendingLoadsForLoader(Loader&);
|
||||||
@@ -193,36 +194,52 @@ class SharedSubResourceCache {
|
|||||||
|
|
||||||
template <typename Traits, typename Derived>
|
template <typename Traits, typename Derived>
|
||||||
void SharedSubResourceCache<Traits, Derived>::ClearInProcess(
|
void SharedSubResourceCache<Traits, Derived>::ClearInProcess(
|
||||||
nsIPrincipal* aForPrincipal, const nsACString* aBaseDomain) {
|
const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||||
if (!aForPrincipal && !aBaseDomain) {
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
|
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||||
|
MOZ_ASSERT(aSchemelessSite.isSome() == aPattern.isSome(),
|
||||||
|
"Must pass both site and OA pattern.");
|
||||||
|
|
||||||
|
if (!aPrincipal && !aSchemelessSite) {
|
||||||
mComplete.Clear();
|
mComplete.Clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto iter = mComplete.Iter(); !iter.Done(); iter.Next()) {
|
for (auto iter = mComplete.Iter(); !iter.Done(); iter.Next()) {
|
||||||
const bool shouldRemove = [&] {
|
const bool shouldRemove = [&] {
|
||||||
if (aForPrincipal && iter.Key().Principal()->Equals(aForPrincipal)) {
|
if (aPrincipal && iter.Key().Principal()->Equals(aPrincipal.ref())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!aBaseDomain) {
|
if (!aSchemelessSite) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Clear by baseDomain.
|
// Clear by site.
|
||||||
nsIPrincipal* partitionPrincipal = iter.Key().PartitionPrincipal();
|
nsIPrincipal* partitionPrincipal = iter.Key().PartitionPrincipal();
|
||||||
|
|
||||||
// Clear entries with matching base domain. This includes entries
|
// Clear entries with site. This includes entries which are partitioned
|
||||||
// which are partitioned under other top level sites (= have a
|
// under other top level sites (= have a partitionKey set).
|
||||||
// partitionKey set).
|
|
||||||
nsAutoCString principalBaseDomain;
|
nsAutoCString principalBaseDomain;
|
||||||
nsresult rv = partitionPrincipal->GetBaseDomain(principalBaseDomain);
|
nsresult rv = partitionPrincipal->GetBaseDomain(principalBaseDomain);
|
||||||
if (NS_SUCCEEDED(rv) && principalBaseDomain.Equals(*aBaseDomain)) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (principalBaseDomain.Equals(aSchemelessSite.ref()) &&
|
||||||
|
aPattern.ref().Matches(partitionPrincipal->OriginAttributesRef())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear entries partitioned under aBaseDomain.
|
// Clear entries partitioned under aSchemelessSite. We need to add the
|
||||||
return StoragePrincipalHelper::PartitionKeyHasBaseDomain(
|
// partition key filter to aPattern so that we include any OA filtering
|
||||||
partitionPrincipal->OriginAttributesRef().mPartitionKey,
|
// specified by the caller. For example the caller may pass aPattern = {
|
||||||
*aBaseDomain);
|
// privateBrowsingId: 1 } which means we may only clear partitioned
|
||||||
|
// private browsing data.
|
||||||
|
OriginAttributesPattern patternWithPartitionKey(aPattern.ref());
|
||||||
|
patternWithPartitionKey.mPartitionKeyPattern.Construct();
|
||||||
|
patternWithPartitionKey.mPartitionKeyPattern.Value()
|
||||||
|
.mBaseDomain.Construct(NS_ConvertUTF8toUTF16(aSchemelessSite.ref()));
|
||||||
|
|
||||||
|
return patternWithPartitionKey.Matches(
|
||||||
|
partitionPrincipal->OriginAttributesRef());
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if (shouldRemove) {
|
if (shouldRemove) {
|
||||||
|
|||||||
@@ -528,9 +528,11 @@ const CSSCacheCleaner = {
|
|||||||
ChromeUtils.clearStyleSheetCacheByPrincipal(aPrincipal);
|
ChromeUtils.clearStyleSheetCacheByPrincipal(aPrincipal);
|
||||||
},
|
},
|
||||||
|
|
||||||
async deleteBySite(aSchemelessSite, _aOriginAttributesPattern) {
|
async deleteBySite(aSchemelessSite, aOriginAttributesPattern) {
|
||||||
// TODO: aOriginAttributesPattern
|
ChromeUtils.clearStyleSheetCacheBySite(
|
||||||
ChromeUtils.clearStyleSheetCacheByBaseDomain(aSchemelessSite);
|
aSchemelessSite,
|
||||||
|
aOriginAttributesPattern
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
async deleteAll() {
|
async deleteAll() {
|
||||||
@@ -560,9 +562,11 @@ const JSCacheCleaner = {
|
|||||||
ChromeUtils.clearScriptCacheByPrincipal(aPrincipal);
|
ChromeUtils.clearScriptCacheByPrincipal(aPrincipal);
|
||||||
},
|
},
|
||||||
|
|
||||||
async deleteBySite(aSchemelessSite, _aOriginAttributesPattern) {
|
async deleteBySite(aSchemelessSite, aOriginAttributesPattern) {
|
||||||
// TODO: aOriginAttributesPattern
|
ChromeUtils.clearScriptCacheBySite(
|
||||||
ChromeUtils.clearScriptCacheByBaseDomain(aSchemelessSite);
|
aSchemelessSite,
|
||||||
|
aOriginAttributesPattern
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
async deleteAll() {
|
async deleteAll() {
|
||||||
|
|||||||
@@ -8,6 +8,17 @@ const ORIGIN_A = `https://${BASE_DOMAIN_A}`;
|
|||||||
const ORIGIN_A_HTTP = `http://${BASE_DOMAIN_A}`;
|
const ORIGIN_A_HTTP = `http://${BASE_DOMAIN_A}`;
|
||||||
const ORIGIN_A_SUB = `https://test1.${BASE_DOMAIN_A}`;
|
const ORIGIN_A_SUB = `https://test1.${BASE_DOMAIN_A}`;
|
||||||
|
|
||||||
|
const CONTAINER_PRINCIPAL_A =
|
||||||
|
Services.scriptSecurityManager.createContentPrincipal(
|
||||||
|
Services.io.newURI(ORIGIN_A),
|
||||||
|
{ userContextId: 2 }
|
||||||
|
);
|
||||||
|
const CONTAINER_PRINCIPAL_A_SUB =
|
||||||
|
Services.scriptSecurityManager.createContentPrincipal(
|
||||||
|
Services.io.newURI(ORIGIN_A_SUB),
|
||||||
|
{ userContextId: 2 }
|
||||||
|
);
|
||||||
|
|
||||||
const BASE_DOMAIN_B = "example.org";
|
const BASE_DOMAIN_B = "example.org";
|
||||||
const ORIGIN_B = `https://${BASE_DOMAIN_B}`;
|
const ORIGIN_B = `https://${BASE_DOMAIN_B}`;
|
||||||
const ORIGIN_B_HTTP = `http://${BASE_DOMAIN_B}`;
|
const ORIGIN_B_HTTP = `http://${BASE_DOMAIN_B}`;
|
||||||
@@ -27,17 +38,23 @@ function getTestURLForOrigin(origin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function testCached(origin, isCached) {
|
async function testCached(origin, isCached) {
|
||||||
let url = getTestURLForOrigin(origin);
|
let principal =
|
||||||
|
Services.scriptSecurityManager.createContentPrincipalFromOrigin(origin);
|
||||||
|
let url = getTestURLForOrigin(principal.originNoSuffix);
|
||||||
|
|
||||||
let numParsed;
|
let numParsed;
|
||||||
|
|
||||||
let tab = tabs[origin];
|
let tab = tabs[principal.origin];
|
||||||
let loadedPromise;
|
let loadedPromise;
|
||||||
if (!tab) {
|
if (!tab) {
|
||||||
info("Creating new tab for " + url);
|
info("Creating new tab for " + url);
|
||||||
tab = BrowserTestUtils.addTab(gBrowser, url);
|
tab = gBrowser.addTab(url, {
|
||||||
|
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
|
||||||
|
userContextId: principal.originAttributes.userContextId,
|
||||||
|
});
|
||||||
|
gBrowser.selectedTab = tab;
|
||||||
loadedPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
loadedPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||||
tabs[origin] = tab;
|
tabs[principal.origin] = tab;
|
||||||
} else {
|
} else {
|
||||||
loadedPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
loadedPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||||
tab.linkedBrowser.reload();
|
tab.linkedBrowser.reload();
|
||||||
@@ -59,6 +76,11 @@ async function addTestTabs() {
|
|||||||
await testCached(ORIGIN_B, false);
|
await testCached(ORIGIN_B, false);
|
||||||
await testCached(ORIGIN_B_SUB, false);
|
await testCached(ORIGIN_B_SUB, false);
|
||||||
await testCached(ORIGIN_B_HTTP, false);
|
await testCached(ORIGIN_B_HTTP, false);
|
||||||
|
// Add more entries for ORIGIN_A but set a different user context.
|
||||||
|
await testCached(CONTAINER_PRINCIPAL_A.origin, false);
|
||||||
|
// Add another entry for ORIGIN_A but set a different user context.
|
||||||
|
await testCached(CONTAINER_PRINCIPAL_A_SUB.origin, false);
|
||||||
|
|
||||||
// Test that the cache has been populated.
|
// Test that the cache has been populated.
|
||||||
await testCached(ORIGIN_A, true);
|
await testCached(ORIGIN_A, true);
|
||||||
await testCached(ORIGIN_A_SUB, true);
|
await testCached(ORIGIN_A_SUB, true);
|
||||||
@@ -66,6 +88,8 @@ async function addTestTabs() {
|
|||||||
await testCached(ORIGIN_B, true);
|
await testCached(ORIGIN_B, true);
|
||||||
await testCached(ORIGIN_B_SUB, true);
|
await testCached(ORIGIN_B_SUB, true);
|
||||||
await testCached(ORIGIN_B_HTTP, true);
|
await testCached(ORIGIN_B_HTTP, true);
|
||||||
|
await testCached(CONTAINER_PRINCIPAL_A.origin, true);
|
||||||
|
await testCached(CONTAINER_PRINCIPAL_A_SUB.origin, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cleanupTestTabs() {
|
async function cleanupTestTabs() {
|
||||||
@@ -95,17 +119,20 @@ add_task(async function test_deleteByPrincipal() {
|
|||||||
await testCached(ORIGIN_B, true);
|
await testCached(ORIGIN_B, true);
|
||||||
await testCached(ORIGIN_B_SUB, true);
|
await testCached(ORIGIN_B_SUB, true);
|
||||||
await testCached(ORIGIN_B_HTTP, true);
|
await testCached(ORIGIN_B_HTTP, true);
|
||||||
|
// User context 2 not cleared because we clear by exact principal.
|
||||||
|
await testCached(CONTAINER_PRINCIPAL_A.origin, true);
|
||||||
|
await testCached(CONTAINER_PRINCIPAL_A_SUB.origin, true);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
cleanupTestTabs();
|
cleanupTestTabs();
|
||||||
ChromeUtils.clearStyleSheetCache();
|
ChromeUtils.clearStyleSheetCache();
|
||||||
});
|
});
|
||||||
|
|
||||||
add_task(async function test_deleteByBaseDomain() {
|
add_task(async function test_deleteBySite() {
|
||||||
await addTestTabs();
|
await addTestTabs();
|
||||||
|
|
||||||
// Clear data for base domain of A.
|
// Clear data for base domain of A.
|
||||||
info("Clearing cache for base domain " + BASE_DOMAIN_A);
|
info("Clearing cache for (schemeless) site " + BASE_DOMAIN_A);
|
||||||
await new Promise(resolve => {
|
await new Promise(resolve => {
|
||||||
Services.clearData.deleteDataFromSite(
|
Services.clearData.deleteDataFromSite(
|
||||||
BASE_DOMAIN_A,
|
BASE_DOMAIN_A,
|
||||||
@@ -120,6 +147,10 @@ add_task(async function test_deleteByBaseDomain() {
|
|||||||
await testCached(ORIGIN_A, false);
|
await testCached(ORIGIN_A, false);
|
||||||
await testCached(ORIGIN_A_SUB, false);
|
await testCached(ORIGIN_A_SUB, false);
|
||||||
await testCached(ORIGIN_A_HTTP, false);
|
await testCached(ORIGIN_A_HTTP, false);
|
||||||
|
// User context 2 also cleared because we passed the wildcard
|
||||||
|
// OriginAttributesPattern {} above.
|
||||||
|
await testCached(CONTAINER_PRINCIPAL_A.origin, false);
|
||||||
|
await testCached(CONTAINER_PRINCIPAL_A_SUB.origin, false);
|
||||||
// Entries for B should still exist.
|
// Entries for B should still exist.
|
||||||
await testCached(ORIGIN_B, true);
|
await testCached(ORIGIN_B, true);
|
||||||
await testCached(ORIGIN_B_SUB, true);
|
await testCached(ORIGIN_B_SUB, true);
|
||||||
@@ -129,3 +160,37 @@ add_task(async function test_deleteByBaseDomain() {
|
|||||||
cleanupTestTabs();
|
cleanupTestTabs();
|
||||||
ChromeUtils.clearStyleSheetCache();
|
ChromeUtils.clearStyleSheetCache();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
add_task(async function test_deleteBySite_oa_pattern() {
|
||||||
|
await addTestTabs();
|
||||||
|
|
||||||
|
// Clear data for site A.
|
||||||
|
info("Clearing cache for (schemeless) site+pattern " + BASE_DOMAIN_A);
|
||||||
|
await new Promise(resolve => {
|
||||||
|
Services.clearData.deleteDataFromSite(
|
||||||
|
BASE_DOMAIN_A,
|
||||||
|
{ userContextId: CONTAINER_PRINCIPAL_A.originAttributes.userContextId },
|
||||||
|
false,
|
||||||
|
Ci.nsIClearDataService.CLEAR_CSS_CACHE,
|
||||||
|
resolve
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Normal entries should not have been cleared.
|
||||||
|
await testCached(ORIGIN_A, true);
|
||||||
|
await testCached(ORIGIN_A_SUB, true);
|
||||||
|
await testCached(ORIGIN_A_HTTP, true);
|
||||||
|
|
||||||
|
// Container entries should have been cleared because we have targeted them with the pattern.
|
||||||
|
await testCached(CONTAINER_PRINCIPAL_A.origin, false);
|
||||||
|
await testCached(CONTAINER_PRINCIPAL_A_SUB.origin, false);
|
||||||
|
|
||||||
|
// Entries for unrelated site B should still exist.
|
||||||
|
await testCached(ORIGIN_B, true);
|
||||||
|
await testCached(ORIGIN_B_SUB, true);
|
||||||
|
await testCached(ORIGIN_B_HTTP, true);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
cleanupTestTabs();
|
||||||
|
ChromeUtils.clearStyleSheetCache();
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user