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&,
|
void ChromeUtils::ClearStyleSheetCacheByPrincipal(GlobalObject&,
|
||||||
nsIPrincipal* aForPrincipal) {
|
nsIPrincipal* aForPrincipal) {
|
||||||
SharedStyleSheetCache::Clear(Some(aForPrincipal));
|
SharedStyleSheetCache::Clear(Nothing(), Some(aForPrincipal));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChromeUtils::ClearStyleSheetCacheBySite(
|
void ChromeUtils::ClearStyleSheetCacheBySite(
|
||||||
GlobalObject&, const nsACString& aSchemelessSite,
|
GlobalObject&, const nsACString& aSchemelessSite,
|
||||||
const dom::OriginAttributesPatternDictionary& aPattern) {
|
const dom::OriginAttributesPatternDictionary& aPattern) {
|
||||||
SharedStyleSheetCache::Clear(Nothing(), Some(nsCString(aSchemelessSite)),
|
SharedStyleSheetCache::Clear(Nothing(), Nothing(),
|
||||||
|
Some(nsCString(aSchemelessSite)),
|
||||||
Some(OriginAttributesPattern(aPattern)));
|
Some(OriginAttributesPattern(aPattern)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChromeUtils::ClearStyleSheetCache(GlobalObject&) {
|
void ChromeUtils::ClearStyleSheetCache(GlobalObject&,
|
||||||
SharedStyleSheetCache::Clear();
|
const Optional<bool>& aChrome) {
|
||||||
|
SharedStyleSheetCache::Clear(aChrome.WasPassed() ? Some(aChrome.Value())
|
||||||
|
: Nothing());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChromeUtils::ClearMessagingLayerSecurityStateByPrincipal(
|
void ChromeUtils::ClearMessagingLayerSecurityStateByPrincipal(
|
||||||
@@ -1592,18 +1595,20 @@ void ChromeUtils::ClearMessagingLayerSecurityState(GlobalObject&,
|
|||||||
|
|
||||||
void ChromeUtils::ClearScriptCacheByPrincipal(GlobalObject&,
|
void ChromeUtils::ClearScriptCacheByPrincipal(GlobalObject&,
|
||||||
nsIPrincipal* aForPrincipal) {
|
nsIPrincipal* aForPrincipal) {
|
||||||
SharedScriptCache::Clear(Some(aForPrincipal));
|
SharedScriptCache::Clear(Nothing(), Some(aForPrincipal));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChromeUtils::ClearScriptCacheBySite(
|
void ChromeUtils::ClearScriptCacheBySite(
|
||||||
GlobalObject&, const nsACString& aSchemelessSite,
|
GlobalObject&, const nsACString& aSchemelessSite,
|
||||||
const dom::OriginAttributesPatternDictionary& aPattern) {
|
const dom::OriginAttributesPatternDictionary& aPattern) {
|
||||||
SharedScriptCache::Clear(Nothing(), Some(nsCString(aSchemelessSite)),
|
SharedScriptCache::Clear(Nothing(), Nothing(),
|
||||||
Some(aPattern));
|
Some(nsCString(aSchemelessSite)), Some(aPattern));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChromeUtils::ClearScriptCache(GlobalObject&) {
|
void ChromeUtils::ClearScriptCache(GlobalObject&,
|
||||||
SharedScriptCache::Clear();
|
const Optional<bool>& aChrome) {
|
||||||
|
SharedScriptCache::Clear(aChrome.WasPassed() ? Some(aChrome.Value())
|
||||||
|
: Nothing());
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PROCTYPE_TO_WEBIDL_CASE(_procType, _webidl) \
|
#define PROCTYPE_TO_WEBIDL_CASE(_procType, _webidl) \
|
||||||
|
|||||||
@@ -193,7 +193,8 @@ class ChromeUtils {
|
|||||||
GlobalObject&, const nsACString& aSchemelessSite,
|
GlobalObject&, const nsACString& aSchemelessSite,
|
||||||
const dom::OriginAttributesPatternDictionary& aPattern);
|
const dom::OriginAttributesPatternDictionary& aPattern);
|
||||||
|
|
||||||
static void ClearStyleSheetCache(GlobalObject& aGlobal);
|
static void ClearStyleSheetCache(GlobalObject& aGlobal,
|
||||||
|
const Optional<bool>& aChrome);
|
||||||
|
|
||||||
static void ClearMessagingLayerSecurityStateByPrincipal(
|
static void ClearMessagingLayerSecurityStateByPrincipal(
|
||||||
GlobalObject&, nsIPrincipal* aPrincipal, ErrorResult& aRv);
|
GlobalObject&, nsIPrincipal* aPrincipal, ErrorResult& aRv);
|
||||||
@@ -212,7 +213,8 @@ class ChromeUtils {
|
|||||||
GlobalObject& aGlobal, const nsACString& aSchemelessSite,
|
GlobalObject& aGlobal, const nsACString& aSchemelessSite,
|
||||||
const dom::OriginAttributesPatternDictionary& aPattern);
|
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);
|
static void SetPerfStatsCollectionMask(GlobalObject& aGlobal, uint64_t aMask);
|
||||||
|
|
||||||
|
|||||||
@@ -242,8 +242,12 @@ namespace ChromeUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the entire stylesheet cache.
|
* 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
|
* Clears the JavaScript cache by schemeless site. This includes associated
|
||||||
@@ -258,8 +262,12 @@ namespace ChromeUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the entire JavaScript cache.
|
* 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.
|
* Clears the Messaging Layer Security state by schemeless site.
|
||||||
|
|||||||
@@ -2090,18 +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>>& aPrincipal,
|
const Maybe<bool>& aChrome, const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||||
const Maybe<nsCString>& aSchemelessSite,
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
const Maybe<OriginAttributesPattern>& aPattern) {
|
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||||
SharedStyleSheetCache::Clear(aPrincipal, aSchemelessSite, aPattern);
|
SharedStyleSheetCache::Clear(aChrome, aPrincipal, aSchemelessSite, aPattern);
|
||||||
return IPC_OK();
|
return IPC_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
mozilla::ipc::IPCResult ContentChild::RecvClearScriptCache(
|
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<nsCString>& aSchemelessSite,
|
||||||
const Maybe<OriginAttributesPattern>& aPattern) {
|
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||||
SharedScriptCache::Clear(aPrincipal, aSchemelessSite, aPattern);
|
SharedScriptCache::Clear(aChrome, aPrincipal, aSchemelessSite, aPattern);
|
||||||
return IPC_OK();
|
return IPC_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -245,12 +245,12 @@ class ContentChild final : public PContentChild,
|
|||||||
const ChromeRegistryItem& item);
|
const ChromeRegistryItem& item);
|
||||||
|
|
||||||
mozilla::ipc::IPCResult RecvClearStyleSheetCache(
|
mozilla::ipc::IPCResult RecvClearStyleSheetCache(
|
||||||
const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
const Maybe<bool>& aChrome, const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||||
const Maybe<nsCString>& aSchemelessSite,
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
const Maybe<OriginAttributesPattern>& aPattern);
|
const Maybe<OriginAttributesPattern>& aPattern);
|
||||||
|
|
||||||
mozilla::ipc::IPCResult RecvClearScriptCache(
|
mozilla::ipc::IPCResult RecvClearScriptCache(
|
||||||
const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
const Maybe<bool>& aChrome, const Maybe<RefPtr<nsIPrincipal>>& aPrincipal,
|
||||||
const Maybe<nsCString>& aSchemelessSite,
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
const Maybe<OriginAttributesPattern>& aPattern);
|
const Maybe<OriginAttributesPattern>& aPattern);
|
||||||
|
|
||||||
|
|||||||
@@ -655,11 +655,13 @@ child:
|
|||||||
|
|
||||||
async ClearImageCache(bool privateLoader, bool? chrome);
|
async ClearImageCache(bool privateLoader, bool? chrome);
|
||||||
|
|
||||||
async ClearStyleSheetCache(nullable nsIPrincipal? aPrincipal,
|
async ClearStyleSheetCache(bool? aChrome,
|
||||||
|
nullable nsIPrincipal? aPrincipal,
|
||||||
nsCString? aSchemelessSite,
|
nsCString? aSchemelessSite,
|
||||||
OriginAttributesPattern? aPattern);
|
OriginAttributesPattern? aPattern);
|
||||||
|
|
||||||
async ClearScriptCache(nullable nsIPrincipal? aPrincipal,
|
async ClearScriptCache(bool? aChrome,
|
||||||
|
nullable nsIPrincipal? aPrincipal,
|
||||||
nsCString? aSchemelessSite,
|
nsCString? aSchemelessSite,
|
||||||
OriginAttributesPattern? aPattern);
|
OriginAttributesPattern? aPattern);
|
||||||
|
|
||||||
|
|||||||
@@ -139,19 +139,21 @@ SharedScriptCache::Observe(nsISupports* aSubject, const char* aTopic,
|
|||||||
return NS_OK;
|
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<nsCString>& aSchemelessSite,
|
||||||
const Maybe<OriginAttributesPattern>& aPattern) {
|
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||||
using ContentParent = dom::ContentParent;
|
using ContentParent = dom::ContentParent;
|
||||||
|
|
||||||
if (XRE_IsParentProcess()) {
|
if (XRE_IsParentProcess()) {
|
||||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||||
Unused << cp->SendClearScriptCache(aPrincipal, aSchemelessSite, aPattern);
|
Unused << cp->SendClearScriptCache(aChrome, aPrincipal, aSchemelessSite,
|
||||||
|
aPattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sSingleton) {
|
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* LoaderPrincipal() const { return mLoaderPrincipal; }
|
||||||
nsIPrincipal* PartitionPrincipal() const { return mPartitionPrincipal; }
|
nsIPrincipal* PartitionPrincipal() const { return mPartitionPrincipal; }
|
||||||
|
|
||||||
|
nsIURI* URI() const { return mURI; }
|
||||||
|
|
||||||
enum { ALLOW_MEMMOVE = true };
|
enum { ALLOW_MEMMOVE = true };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -196,7 +198,8 @@ 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(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<nsCString>& aSchemelessSite = Nothing(),
|
||||||
const Maybe<OriginAttributesPattern>& aPattern = Nothing());
|
const Maybe<OriginAttributesPattern>& aPattern = Nothing());
|
||||||
|
|
||||||
|
|||||||
@@ -205,20 +205,20 @@ SharedStyleSheetCache::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SharedStyleSheetCache::Clear(
|
void SharedStyleSheetCache::Clear(
|
||||||
const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
const Maybe<bool>& aChrome, const Maybe<nsCOMPtr<nsIPrincipal>>& aPrincipal,
|
||||||
const Maybe<nsCString>& aSchemelessSite,
|
const Maybe<nsCString>& aSchemelessSite,
|
||||||
const Maybe<OriginAttributesPattern>& aPattern) {
|
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||||
using ContentParent = dom::ContentParent;
|
using ContentParent = dom::ContentParent;
|
||||||
|
|
||||||
if (XRE_IsParentProcess()) {
|
if (XRE_IsParentProcess()) {
|
||||||
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
|
||||||
Unused << cp->SendClearStyleSheetCache(aPrincipal, aSchemelessSite,
|
Unused << cp->SendClearStyleSheetCache(aChrome, aPrincipal,
|
||||||
aPattern);
|
aSchemelessSite, aPattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sSingleton) {
|
if (sSingleton) {
|
||||||
sSingleton->ClearInProcess(aPrincipal, aSchemelessSite, aPattern);
|
sSingleton->ClearInProcess(aChrome, aPrincipal, aSchemelessSite, aPattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ 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(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<nsCString>& aSchemelessSite = Nothing(),
|
||||||
const Maybe<OriginAttributesPattern>& aPattern = 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.
|
// to be called when the document goes away, or when its principal changes.
|
||||||
void UnregisterLoader(Loader&);
|
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<nsCString>& aSchemelessSite,
|
||||||
const Maybe<OriginAttributesPattern>& aPattern);
|
const Maybe<OriginAttributesPattern>& aPattern);
|
||||||
|
|
||||||
@@ -269,19 +270,31 @@ class SharedSubResourceCache {
|
|||||||
|
|
||||||
template <typename Traits, typename Derived>
|
template <typename Traits, typename Derived>
|
||||||
void SharedSubResourceCache<Traits, Derived>::ClearInProcess(
|
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<nsCString>& aSchemelessSite,
|
||||||
const Maybe<OriginAttributesPattern>& aPattern) {
|
const Maybe<OriginAttributesPattern>& aPattern) {
|
||||||
MOZ_ASSERT(aSchemelessSite.isSome() == aPattern.isSome(),
|
MOZ_ASSERT(aSchemelessSite.isSome() == aPattern.isSome(),
|
||||||
"Must pass both site and OA pattern.");
|
"Must pass both site and OA pattern.");
|
||||||
|
|
||||||
if (!aPrincipal && !aSchemelessSite) {
|
if (!aChrome && !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 (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())) {
|
if (aPrincipal && iter.Key().Principal()->Equals(aPrincipal.ref())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user