mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 12:50:09 +00:00
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:
parent
ff2f7c0866
commit
47916c8c70
@ -21,6 +21,7 @@
|
||||
#include "mozilla/ProcInfo.h"
|
||||
#include "mozilla/RDDProcessManager.h"
|
||||
#include "mozilla/ResultExtensions.h"
|
||||
#include "mozilla/SharedStyleSheetCache.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozilla/dom/BrowsingContext.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
@ -731,6 +732,11 @@ void ChromeUtils::ClearRecentJSDevError(GlobalObject&) {
|
||||
}
|
||||
#endif // NIGHTLY_BUILD
|
||||
|
||||
void ChromeUtils::ClearStyleSheetCache(GlobalObject&,
|
||||
nsIPrincipal* aForPrincipal) {
|
||||
SharedStyleSheetCache::Clear(aForPrincipal);
|
||||
}
|
||||
|
||||
#define PROCTYPE_TO_WEBIDL_CASE(_procType, _webidl) \
|
||||
case mozilla::ProcType::_procType: \
|
||||
return WebIDLProcType::_webidl
|
||||
|
@ -149,6 +149,8 @@ class ChromeUtils {
|
||||
|
||||
static void ClearRecentJSDevError(GlobalObject& aGlobal);
|
||||
|
||||
static void ClearStyleSheetCache(GlobalObject&, nsIPrincipal* aForPrincipal);
|
||||
|
||||
static already_AddRefed<Promise> RequestPerformanceMetrics(
|
||||
GlobalObject& aGlobal, ErrorResult& aRv);
|
||||
|
||||
|
@ -999,7 +999,7 @@ nsDOMWindowUtils::SuppressAnimation(bool aSuppress) {
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::ClearSharedStyleSheetCache() {
|
||||
SharedStyleSheetCache::ClearForTest();
|
||||
SharedStyleSheetCache::Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
interface nsIDOMProcessChild;
|
||||
interface nsIDOMProcessParent;
|
||||
interface Principal;
|
||||
|
||||
/**
|
||||
* An optimized QueryInterface method, generated by generateQI.
|
||||
@ -160,6 +161,11 @@ namespace ChromeUtils {
|
||||
void clearRecentJSDevError();
|
||||
#endif // NIGHTLY_BUILD
|
||||
|
||||
/**
|
||||
* Clears the stylesheet cache.
|
||||
*/
|
||||
void clearStyleSheetCache(optional Principal? principal = null);
|
||||
|
||||
/**
|
||||
* If the profiler is currently running and recording the current thread,
|
||||
* add a marker for the current thread. No-op otherwise.
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "mozilla/StaticPrefs_dom.h"
|
||||
#include "mozilla/StaticPrefs_fission.h"
|
||||
#include "mozilla/StaticPrefs_media.h"
|
||||
#include "mozilla/SharedStyleSheetCache.h"
|
||||
#include "mozilla/TelemetryIPC.h"
|
||||
#include "mozilla/RemoteDecoderManagerChild.h"
|
||||
#include "mozilla/devtools/HeapSnapshotTempFileHelperChild.h"
|
||||
@ -2079,6 +2080,13 @@ mozilla::ipc::IPCResult ContentChild::RecvRegisterChromeItem(
|
||||
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(
|
||||
const bool& privateLoader, const bool& chrome) {
|
||||
imgLoader* loader = privateLoader ? imgLoader::PrivateBrowsingLoader()
|
||||
|
@ -290,6 +290,8 @@ class ContentChild final : public PContentChild,
|
||||
mozilla::ipc::IPCResult RecvRegisterChromeItem(
|
||||
const ChromeRegistryItem& item);
|
||||
|
||||
mozilla::ipc::IPCResult RecvClearStyleSheetCache(
|
||||
const Maybe<RefPtr<nsIPrincipal>>& aForPrincipal);
|
||||
mozilla::ipc::IPCResult RecvClearImageCache(const bool& privateLoader,
|
||||
const bool& chrome);
|
||||
|
||||
|
@ -554,6 +554,8 @@ child:
|
||||
|
||||
async ClearImageCache(bool privateLoader, bool chrome);
|
||||
|
||||
async ClearStyleSheetCache(nsIPrincipal? aForPrincipal);
|
||||
|
||||
async SetOffline(bool offline);
|
||||
async SetConnectivity(bool connectivity);
|
||||
async SetCaptivePortalState(int32_t aState);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/StyleSheet.h"
|
||||
#include "mozilla/css/SheetLoadData.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/ServoBindings.h"
|
||||
#include "nsXULPrototypeCache.h"
|
||||
|
||||
@ -25,9 +26,30 @@ using IsAlternate = css::Loader::IsAlternate;
|
||||
|
||||
SharedStyleSheetCache* SharedStyleSheetCache::sInstance;
|
||||
|
||||
void SharedStyleSheetCache::ClearForTest() {
|
||||
if (sInstance) {
|
||||
void SharedStyleSheetCache::Clear(nsIPrincipal* aForPrincipal) {
|
||||
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();
|
||||
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.
|
||||
void UnregisterLoader(css::Loader&);
|
||||
|
||||
static void ClearForTest();
|
||||
static void Clear(nsIPrincipal* aForPrincipal = nullptr);
|
||||
|
||||
private:
|
||||
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 = {
|
||||
deleteByHost(aHost, aOriginAttributes) {
|
||||
return new Promise(aResolve => {
|
||||
@ -1057,6 +1093,11 @@ const FLAGS_MAP = [
|
||||
cleaners: [ImageCacheCleaner],
|
||||
},
|
||||
|
||||
{
|
||||
flag: Ci.nsIClearDataService.CLEAR_CSS_CACHE,
|
||||
cleaners: [CSSCacheCleaner],
|
||||
},
|
||||
|
||||
{
|
||||
flag: Ci.nsIClearDataService.CLEAR_PLUGIN_DATA,
|
||||
cleaners: [PluginDataCleaner],
|
||||
|
@ -224,6 +224,11 @@ interface nsIClearDataService : nsISupports
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@ -237,7 +242,7 @@ interface nsIClearDataService : nsISupports
|
||||
/**
|
||||
* 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
|
||||
@ -249,7 +254,7 @@ interface nsIClearDataService : nsISupports
|
||||
* Helper flag for 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_PERMISSIONS | CLEAR_DOM_STORAGES | CLEAR_CONTENT_PREFERENCES |
|
||||
CLEAR_PREDICTOR_NETWORK_DATA | CLEAR_DOM_PUSH_NOTIFICATIONS |
|
||||
|
Loading…
x
Reference in New Issue
Block a user