Bug 1948808 - Part 2: Add chrome optional parameter to control the target of clear in-memory cache. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D238581
This commit is contained in:
@@ -1282,18 +1282,21 @@ void ChromeUtils::ClearRecentJSDevError(GlobalObject&) {
|
||||
|
||||
void ChromeUtils::ClearStyleSheetCacheByPrincipal(GlobalObject&,
|
||||
nsIPrincipal* aForPrincipal) {
|
||||
SharedStyleSheetCache::Clear(Some(aForPrincipal));
|
||||
SharedStyleSheetCache::Clear(Nothing(), Some(aForPrincipal));
|
||||
}
|
||||
|
||||
void ChromeUtils::ClearStyleSheetCacheBySite(
|
||||
GlobalObject&, const nsACString& aSchemelessSite,
|
||||
const dom::OriginAttributesPatternDictionary& aPattern) {
|
||||
SharedStyleSheetCache::Clear(Nothing(), Some(nsCString(aSchemelessSite)),
|
||||
SharedStyleSheetCache::Clear(Nothing(), Nothing(),
|
||||
Some(nsCString(aSchemelessSite)),
|
||||
Some(OriginAttributesPattern(aPattern)));
|
||||
}
|
||||
|
||||
void ChromeUtils::ClearStyleSheetCache(GlobalObject&) {
|
||||
SharedStyleSheetCache::Clear();
|
||||
void ChromeUtils::ClearStyleSheetCache(GlobalObject&,
|
||||
const Optional<bool>& aChrome) {
|
||||
SharedStyleSheetCache::Clear(aChrome.WasPassed() ? Some(aChrome.Value())
|
||||
: Nothing());
|
||||
}
|
||||
|
||||
void ChromeUtils::ClearMessagingLayerSecurityStateByPrincipal(
|
||||
@@ -1592,18 +1595,20 @@ void ChromeUtils::ClearMessagingLayerSecurityState(GlobalObject&,
|
||||
|
||||
void ChromeUtils::ClearScriptCacheByPrincipal(GlobalObject&,
|
||||
nsIPrincipal* aForPrincipal) {
|
||||
SharedScriptCache::Clear(Some(aForPrincipal));
|
||||
SharedScriptCache::Clear(Nothing(), Some(aForPrincipal));
|
||||
}
|
||||
|
||||
void ChromeUtils::ClearScriptCacheBySite(
|
||||
GlobalObject&, const nsACString& aSchemelessSite,
|
||||
const dom::OriginAttributesPatternDictionary& aPattern) {
|
||||
SharedScriptCache::Clear(Nothing(), Some(nsCString(aSchemelessSite)),
|
||||
Some(aPattern));
|
||||
SharedScriptCache::Clear(Nothing(), Nothing(),
|
||||
Some(nsCString(aSchemelessSite)), Some(aPattern));
|
||||
}
|
||||
|
||||
void ChromeUtils::ClearScriptCache(GlobalObject&) {
|
||||
SharedScriptCache::Clear();
|
||||
void ChromeUtils::ClearScriptCache(GlobalObject&,
|
||||
const Optional<bool>& aChrome) {
|
||||
SharedScriptCache::Clear(aChrome.WasPassed() ? Some(aChrome.Value())
|
||||
: Nothing());
|
||||
}
|
||||
|
||||
#define PROCTYPE_TO_WEBIDL_CASE(_procType, _webidl) \
|
||||
|
||||
@@ -193,7 +193,8 @@ class ChromeUtils {
|
||||
GlobalObject&, const nsACString& aSchemelessSite,
|
||||
const dom::OriginAttributesPatternDictionary& aPattern);
|
||||
|
||||
static void ClearStyleSheetCache(GlobalObject& aGlobal);
|
||||
static void ClearStyleSheetCache(GlobalObject& aGlobal,
|
||||
const Optional<bool>& aChrome);
|
||||
|
||||
static void ClearMessagingLayerSecurityStateByPrincipal(
|
||||
GlobalObject&, nsIPrincipal* aPrincipal, ErrorResult& aRv);
|
||||
@@ -212,7 +213,8 @@ class ChromeUtils {
|
||||
GlobalObject& aGlobal, const nsACString& aSchemelessSite,
|
||||
const dom::OriginAttributesPatternDictionary& aPattern);
|
||||
|
||||
static void ClearScriptCache(GlobalObject& aGlobal);
|
||||
static void ClearScriptCache(GlobalObject& aGlobal,
|
||||
const Optional<bool>& aChrome);
|
||||
|
||||
static void SetPerfStatsCollectionMask(GlobalObject& aGlobal, uint64_t aMask);
|
||||
|
||||
|
||||
@@ -242,8 +242,12 @@ namespace ChromeUtils {
|
||||
|
||||
/**
|
||||
* Clears the entire stylesheet cache.
|
||||
*
|
||||
* If chrome parameter is passed and true, this clears chrome cache.
|
||||
* If chrome parameter is passed and false, this clears content cache.
|
||||
* If chrome parameter is not passed, this clears all cache.
|
||||
*/
|
||||
undefined clearStyleSheetCache();
|
||||
undefined clearStyleSheetCache(optional boolean chrome);
|
||||
|
||||
/**
|
||||
* Clears the JavaScript cache by schemeless site. This includes associated
|
||||
@@ -258,8 +262,12 @@ namespace ChromeUtils {
|
||||
|
||||
/**
|
||||
* Clears the entire JavaScript cache.
|
||||
*
|
||||
* If chrome parameter is passed and true, this clears chrome cache.
|
||||
* If chrome parameter is passed and false, this clears content cache.
|
||||
* If chrome parameter is not passed, this clears all cache.
|
||||
*/
|
||||
undefined clearScriptCache();
|
||||
undefined clearScriptCache(optional boolean chrome);
|
||||
|
||||
/**
|
||||
* Clears the Messaging Layer Security state by schemeless site.
|
||||
|
||||
@@ -2090,18 +2090,18 @@ mozilla::ipc::IPCResult ContentChild::RecvRegisterChromeItem(
|
||||
return IPC_OK();
|
||||
}
|
||||
mozilla::ipc::IPCResult ContentChild::RecvClearStyleSheetCache(
|
||||
const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<bool>& aChrome, const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<nsCString>& aSchemelessSite,
|
||||
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||
SharedStyleSheetCache::Clear(aPrincipal, aSchemelessSite, aPattern);
|
||||
SharedStyleSheetCache::Clear(aChrome, aPrincipal, aSchemelessSite, aPattern);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult ContentChild::RecvClearScriptCache(
|
||||
const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<bool>& aChrome, const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<nsCString>& aSchemelessSite,
|
||||
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||
SharedScriptCache::Clear(aPrincipal, aSchemelessSite, aPattern);
|
||||
SharedScriptCache::Clear(aChrome, aPrincipal, aSchemelessSite, aPattern);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
|
||||
@@ -245,12 +245,12 @@ class ContentChild final : public PContentChild,
|
||||
const ChromeRegistryItem& item);
|
||||
|
||||
mozilla::ipc::IPCResult RecvClearStyleSheetCache(
|
||||
const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<bool>& aChrome, const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<nsCString>& aSchemelessSite,
|
||||
const Maybe<OriginAttributesPattern>& aPattern);
|
||||
|
||||
mozilla::ipc::IPCResult RecvClearScriptCache(
|
||||
const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<bool>& aChrome, const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<nsCString>& aSchemelessSite,
|
||||
const Maybe<OriginAttributesPattern>& aPattern);
|
||||
|
||||
|
||||
@@ -655,11 +655,13 @@ child:
|
||||
|
||||
async ClearImageCache(bool privateLoader, bool? chrome);
|
||||
|
||||
async ClearStyleSheetCache(nullable nsIPrincipal? aPrincipal,
|
||||
async ClearStyleSheetCache(bool? aChrome,
|
||||
nullable nsIPrincipal? aPrincipal,
|
||||
nsCString? aSchemelessSite,
|
||||
OriginAttributesPattern? aPattern);
|
||||
|
||||
async ClearScriptCache(nullable nsIPrincipal? aPrincipal,
|
||||
async ClearScriptCache(bool? aChrome,
|
||||
nullable nsIPrincipal? aPrincipal,
|
||||
nsCString? aSchemelessSite,
|
||||
OriginAttributesPattern? aPattern);
|
||||
|
||||
|
||||
@@ -139,19 +139,21 @@ SharedScriptCache::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void SharedScriptCache::Clear(const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||
void SharedScriptCache::Clear(const Maybe<bool>& aChrome,
|
||||
const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<nsCString>& aSchemelessSite,
|
||||
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||
using ContentParent = dom::ContentParent;
|
||||
|
||||
if (XRE_IsParentProcess()) {
|
||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||
Unused << cp->SendClearScriptCache(aPrincipal, aSchemelessSite, aPattern);
|
||||
Unused << cp->SendClearScriptCache(aChrome, aPrincipal, aSchemelessSite,
|
||||
aPattern);
|
||||
}
|
||||
}
|
||||
|
||||
if (sSingleton) {
|
||||
sSingleton->ClearInProcess(aPrincipal, aSchemelessSite, aPattern);
|
||||
sSingleton->ClearInProcess(aChrome, aPrincipal, aSchemelessSite, aPattern);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,8 @@ class ScriptHashKey : public PLDHashEntryHdr {
|
||||
nsIPrincipal* LoaderPrincipal() const { return mLoaderPrincipal; }
|
||||
nsIPrincipal* PartitionPrincipal() const { return mPartitionPrincipal; }
|
||||
|
||||
nsIURI* URI() const { return mURI; }
|
||||
|
||||
enum { ALLOW_MEMMOVE = true };
|
||||
|
||||
protected:
|
||||
@@ -196,7 +198,8 @@ class SharedScriptCache final
|
||||
// a sheet cache (loaders that are not owned by a document).
|
||||
static void LoadCompleted(SharedScriptCache*, ScriptLoadData&);
|
||||
using Base::LoadCompleted;
|
||||
static void Clear(const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal = Nothing(),
|
||||
static void Clear(const Maybe<bool>& aChrome = Nothing(),
|
||||
const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal = Nothing(),
|
||||
const Maybe<nsCString>& aSchemelessSite = Nothing(),
|
||||
const Maybe<OriginAttributesPattern>& aPattern = Nothing());
|
||||
|
||||
|
||||
@@ -205,20 +205,20 @@ SharedStyleSheetCache::CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
}
|
||||
|
||||
void SharedStyleSheetCache::Clear(
|
||||
const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<bool>& aChrome, const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<nsCString>& aSchemelessSite,
|
||||
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||
using ContentParent = dom::ContentParent;
|
||||
|
||||
if (XRE_IsParentProcess()) {
|
||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||
Unused << cp->SendClearStyleSheetCache(aPrincipal, aSchemelessSite,
|
||||
aPattern);
|
||||
Unused << cp->SendClearStyleSheetCache(aChrome, aPrincipal,
|
||||
aSchemelessSite, aPattern);
|
||||
}
|
||||
}
|
||||
|
||||
if (sSingleton) {
|
||||
sSingleton->ClearInProcess(aPrincipal, aSchemelessSite, aPattern);
|
||||
sSingleton->ClearInProcess(aChrome, aPrincipal, aSchemelessSite, aPattern);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,8 @@ class SharedStyleSheetCache final
|
||||
using Base::LoadCompleted;
|
||||
static void LoadCompletedInternal(SharedStyleSheetCache*, css::SheetLoadData&,
|
||||
nsTArray<RefPtr<css::SheetLoadData>>&);
|
||||
static void Clear(const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal = Nothing(),
|
||||
static void Clear(const Maybe<bool>& aChrome = Nothing(),
|
||||
const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal = Nothing(),
|
||||
const Maybe<nsCString>& aSchemelessSite = Nothing(),
|
||||
const Maybe<OriginAttributesPattern>& aPattern = Nothing());
|
||||
|
||||
|
||||
@@ -239,7 +239,8 @@ class SharedSubResourceCache {
|
||||
// to be called when the document goes away, or when its principal changes.
|
||||
void UnregisterLoader(Loader&);
|
||||
|
||||
void ClearInProcess(const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||
void ClearInProcess(const Maybe<bool>& aChrome,
|
||||
const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<nsCString>& aSchemelessSite,
|
||||
const Maybe<OriginAttributesPattern>& aPattern);
|
||||
|
||||
@@ -269,19 +270,31 @@ class SharedSubResourceCache {
|
||||
|
||||
template <typename Traits, typename Derived>
|
||||
void SharedSubResourceCache<Traits, Derived>::ClearInProcess(
|
||||
const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<bool>& aChrome, const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||
const Maybe<nsCString>& aSchemelessSite,
|
||||
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||
MOZ_ASSERT(aSchemelessSite.isSome() == aPattern.isSome(),
|
||||
"Must pass both site and OA pattern.");
|
||||
|
||||
if (!aPrincipal && !aSchemelessSite) {
|
||||
if (!aChrome && !aPrincipal && !aSchemelessSite) {
|
||||
mComplete.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto iter = mComplete.Iter(); !iter.Done(); iter.Next()) {
|
||||
const bool shouldRemove = [&] {
|
||||
if (aChrome.isSome()) {
|
||||
nsIURI* uri = iter.Key().URI();
|
||||
bool isChrome = uri->SchemeIs("chrome") || uri->SchemeIs("resource");
|
||||
if (*aChrome != isChrome) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!aPrincipal && !aSchemelessSite) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (aPrincipal && iter.Key().Principal()->Equals(aPrincipal.ref())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user