Bug 1662987 - ClearDataService should know how to clear the stylesheet cache. r=baku

Much like it does for images.

Differential Revision: https://phabricator.services.mozilla.com/D89242
This commit is contained in:
Emilio Cobos Álvarez 2020-09-08 19:38:43 +00:00
Родитель ff2f7c0866
Коммит 47916c8c70
11 изменённых файлов: 100 добавлений и 6 удалений

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

@ -21,6 +21,7 @@
#include "mozilla/ProcInfo.h" #include "mozilla/ProcInfo.h"
#include "mozilla/RDDProcessManager.h" #include "mozilla/RDDProcessManager.h"
#include "mozilla/ResultExtensions.h" #include "mozilla/ResultExtensions.h"
#include "mozilla/SharedStyleSheetCache.h"
#include "mozilla/TimeStamp.h" #include "mozilla/TimeStamp.h"
#include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentChild.h"
@ -731,6 +732,11 @@ void ChromeUtils::ClearRecentJSDevError(GlobalObject&) {
} }
#endif // NIGHTLY_BUILD #endif // NIGHTLY_BUILD
void ChromeUtils::ClearStyleSheetCache(GlobalObject&,
nsIPrincipal* aForPrincipal) {
SharedStyleSheetCache::Clear(aForPrincipal);
}
#define PROCTYPE_TO_WEBIDL_CASE(_procType, _webidl) \ #define PROCTYPE_TO_WEBIDL_CASE(_procType, _webidl) \
case mozilla::ProcType::_procType: \ case mozilla::ProcType::_procType: \
return WebIDLProcType::_webidl return WebIDLProcType::_webidl

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

@ -149,6 +149,8 @@ class ChromeUtils {
static void ClearRecentJSDevError(GlobalObject& aGlobal); static void ClearRecentJSDevError(GlobalObject& aGlobal);
static void ClearStyleSheetCache(GlobalObject&, nsIPrincipal* aForPrincipal);
static already_AddRefed<Promise> RequestPerformanceMetrics( static already_AddRefed<Promise> RequestPerformanceMetrics(
GlobalObject& aGlobal, ErrorResult& aRv); GlobalObject& aGlobal, ErrorResult& aRv);

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

@ -999,7 +999,7 @@ nsDOMWindowUtils::SuppressAnimation(bool aSuppress) {
NS_IMETHODIMP NS_IMETHODIMP
nsDOMWindowUtils::ClearSharedStyleSheetCache() { nsDOMWindowUtils::ClearSharedStyleSheetCache() {
SharedStyleSheetCache::ClearForTest(); SharedStyleSheetCache::Clear();
return NS_OK; return NS_OK;
} }

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

@ -6,6 +6,7 @@
interface nsIDOMProcessChild; interface nsIDOMProcessChild;
interface nsIDOMProcessParent; interface nsIDOMProcessParent;
interface Principal;
/** /**
* An optimized QueryInterface method, generated by generateQI. * An optimized QueryInterface method, generated by generateQI.
@ -160,6 +161,11 @@ namespace ChromeUtils {
void clearRecentJSDevError(); void clearRecentJSDevError();
#endif // NIGHTLY_BUILD #endif // NIGHTLY_BUILD
/**
* Clears the stylesheet cache.
*/
void clearStyleSheetCache(optional Principal? principal = null);
/** /**
* If the profiler is currently running and recording the current thread, * If the profiler is currently running and recording the current thread,
* add a marker for the current thread. No-op otherwise. * add a marker for the current thread. No-op otherwise.

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

@ -34,6 +34,7 @@
#include "mozilla/StaticPrefs_dom.h" #include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_fission.h" #include "mozilla/StaticPrefs_fission.h"
#include "mozilla/StaticPrefs_media.h" #include "mozilla/StaticPrefs_media.h"
#include "mozilla/SharedStyleSheetCache.h"
#include "mozilla/TelemetryIPC.h" #include "mozilla/TelemetryIPC.h"
#include "mozilla/RemoteDecoderManagerChild.h" #include "mozilla/RemoteDecoderManagerChild.h"
#include "mozilla/devtools/HeapSnapshotTempFileHelperChild.h" #include "mozilla/devtools/HeapSnapshotTempFileHelperChild.h"
@ -2079,6 +2080,13 @@ mozilla::ipc::IPCResult ContentChild::RecvRegisterChromeItem(
return IPC_OK(); return IPC_OK();
} }
mozilla::ipc::IPCResult ContentChild::RecvClearStyleSheetCache(
const Maybe<RefPtr<nsIPrincipal>>& aForPrincipal) {
nsIPrincipal* prin = aForPrincipal ? aForPrincipal.value().get() : nullptr;
SharedStyleSheetCache::Clear(prin);
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvClearImageCache( mozilla::ipc::IPCResult ContentChild::RecvClearImageCache(
const bool& privateLoader, const bool& chrome) { const bool& privateLoader, const bool& chrome) {
imgLoader* loader = privateLoader ? imgLoader::PrivateBrowsingLoader() imgLoader* loader = privateLoader ? imgLoader::PrivateBrowsingLoader()

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

@ -290,6 +290,8 @@ class ContentChild final : public PContentChild,
mozilla::ipc::IPCResult RecvRegisterChromeItem( mozilla::ipc::IPCResult RecvRegisterChromeItem(
const ChromeRegistryItem& item); const ChromeRegistryItem& item);
mozilla::ipc::IPCResult RecvClearStyleSheetCache(
const Maybe<RefPtr<nsIPrincipal>>& aForPrincipal);
mozilla::ipc::IPCResult RecvClearImageCache(const bool& privateLoader, mozilla::ipc::IPCResult RecvClearImageCache(const bool& privateLoader,
const bool& chrome); const bool& chrome);

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

@ -554,6 +554,8 @@ child:
async ClearImageCache(bool privateLoader, bool chrome); async ClearImageCache(bool privateLoader, bool chrome);
async ClearStyleSheetCache(nsIPrincipal? aForPrincipal);
async SetOffline(bool offline); async SetOffline(bool offline);
async SetConnectivity(bool connectivity); async SetConnectivity(bool connectivity);
async SetCaptivePortalState(int32_t aState); async SetCaptivePortalState(int32_t aState);

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

@ -9,6 +9,7 @@
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "mozilla/StyleSheet.h" #include "mozilla/StyleSheet.h"
#include "mozilla/css/SheetLoadData.h" #include "mozilla/css/SheetLoadData.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/ServoBindings.h" #include "mozilla/ServoBindings.h"
#include "nsXULPrototypeCache.h" #include "nsXULPrototypeCache.h"
@ -25,9 +26,30 @@ using IsAlternate = css::Loader::IsAlternate;
SharedStyleSheetCache* SharedStyleSheetCache::sInstance; SharedStyleSheetCache* SharedStyleSheetCache::sInstance;
void SharedStyleSheetCache::ClearForTest() { void SharedStyleSheetCache::Clear(nsIPrincipal* aForPrincipal) {
if (sInstance) { using ContentParent = dom::ContentParent;
if (XRE_IsParentProcess()) {
auto forPrincipal = aForPrincipal ? Some(RefPtr(aForPrincipal)) : Nothing();
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
Unused << cp->SendClearStyleSheetCache(forPrincipal);
}
}
if (!sInstance) {
return;
}
if (!aForPrincipal) {
sInstance->mCompleteSheets.Clear(); sInstance->mCompleteSheets.Clear();
return;
}
for (auto iter = sInstance->mCompleteSheets.Iter(); !iter.Done();
iter.Next()) {
if (iter.Key().Principal()->Equals(aForPrincipal)) {
iter.Remove();
}
} }
} }

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

@ -98,7 +98,7 @@ class SharedStyleSheetCache final : public nsIMemoryReporter {
// be called when the document goes away, or when its principal changes. // be called when the document goes away, or when its principal changes.
void UnregisterLoader(css::Loader&); void UnregisterLoader(css::Loader&);
static void ClearForTest(); static void Clear(nsIPrincipal* aForPrincipal = nullptr);
private: private:
static already_AddRefed<SharedStyleSheetCache> Create(); static already_AddRefed<SharedStyleSheetCache> Create();

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

@ -166,6 +166,42 @@ const NetworkCacheCleaner = {
}, },
}; };
const CSSCacheCleaner = {
deleteByHost(aHost, aOriginAttributes) {
return new Promise(aResolve => {
// 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
);
ChromeUtils.clearStyleSheetCache(httpPrincipal);
ChromeUtils.clearStyleSheetCache(httpsPrincipal);
aResolve();
});
},
deleteByPrincipal(aPrincipal) {
return new Promise(aResolve => {
ChromeUtils.clearStyleSheetCache(aPrincipal);
aResolve();
});
},
deleteAll() {
return new Promise(aResolve => {
ChromeUtils.clearStyleSheetCache();
aResolve();
});
},
};
const ImageCacheCleaner = { const ImageCacheCleaner = {
deleteByHost(aHost, aOriginAttributes) { deleteByHost(aHost, aOriginAttributes) {
return new Promise(aResolve => { return new Promise(aResolve => {
@ -1057,6 +1093,11 @@ const FLAGS_MAP = [
cleaners: [ImageCacheCleaner], cleaners: [ImageCacheCleaner],
}, },
{
flag: Ci.nsIClearDataService.CLEAR_CSS_CACHE,
cleaners: [CSSCacheCleaner],
},
{ {
flag: Ci.nsIClearDataService.CLEAR_PLUGIN_DATA, flag: Ci.nsIClearDataService.CLEAR_PLUGIN_DATA,
cleaners: [PluginDataCleaner], cleaners: [PluginDataCleaner],

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

@ -224,6 +224,11 @@ interface nsIClearDataService : nsISupports
*/ */
const uint32_t CLEAR_CONTENT_BLOCKING_RECORDS = 1 << 22; const uint32_t CLEAR_CONTENT_BLOCKING_RECORDS = 1 << 22;
/**
* Clear the in-memory CSS cache.
*/
const uint32_t CLEAR_CSS_CACHE = 1 << 23;
/** /**
* Use this value to delete all the data. * Use this value to delete all the data.
*/ */
@ -237,7 +242,7 @@ interface nsIClearDataService : nsISupports
/** /**
* Delete all the possible caches. * Delete all the possible caches.
*/ */
const uint32_t CLEAR_ALL_CACHES = CLEAR_NETWORK_CACHE | CLEAR_IMAGE_CACHE; const uint32_t CLEAR_ALL_CACHES = CLEAR_NETWORK_CACHE | CLEAR_IMAGE_CACHE | CLEAR_CSS_CACHE;
/** /**
* Delete all DOM storages * Delete all DOM storages
@ -249,7 +254,7 @@ interface nsIClearDataService : nsISupports
* Helper flag for forget about site * Helper flag for forget about site
*/ */
const uint32_t CLEAR_FORGET_ABOUT_SITE = const uint32_t CLEAR_FORGET_ABOUT_SITE =
CLEAR_HISTORY | CLEAR_SESSION_HISTORY | CLEAR_NETWORK_CACHE | CLEAR_IMAGE_CACHE | CLEAR_HISTORY | CLEAR_SESSION_HISTORY | CLEAR_ALL_CACHES |
CLEAR_COOKIES | CLEAR_EME | CLEAR_PLUGIN_DATA | CLEAR_DOWNLOADS | CLEAR_PASSWORDS | CLEAR_COOKIES | CLEAR_EME | CLEAR_PLUGIN_DATA | CLEAR_DOWNLOADS | CLEAR_PASSWORDS |
CLEAR_PERMISSIONS | CLEAR_DOM_STORAGES | CLEAR_CONTENT_PREFERENCES | CLEAR_PERMISSIONS | CLEAR_DOM_STORAGES | CLEAR_CONTENT_PREFERENCES |
CLEAR_PREDICTOR_NETWORK_DATA | CLEAR_DOM_PUSH_NOTIFICATIONS | CLEAR_PREDICTOR_NETWORK_DATA | CLEAR_DOM_PUSH_NOTIFICATIONS |