Bug 1462662 - Wipe the container for privacy.usercontext.about_newtab_segregation.enabled on shutdown, r=johannh

This commit is contained in:
Andrea Marchesini 2018-05-29 17:35:28 +02:00
parent def556b4a1
commit c0f1056898
2 changed files with 46 additions and 0 deletions

View File

@ -17,6 +17,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
setTimeout: "resource://gre/modules/Timer.jsm",
ServiceWorkerCleanUp: "resource://gre/modules/ServiceWorkerCleanUp.jsm",
OfflineAppCacheHelper: "resource://gre/modules/offlineAppCache.jsm",
ContextualIdentityService: "resource://gre/modules/ContextualIdentityService.jsm",
});
XPCOMUtils.defineLazyServiceGetter(this, "sas",
@ -71,6 +72,12 @@ var Sanitizer = {
*/
PREF_TIMESPAN: "privacy.sanitize.timeSpan",
/**
* Pref to newTab segregation. If true, on shutdown, the private container
* used in about:newtab is cleaned up. Exposed because used in tests.
*/
PREF_NEWTAB_SEGREGATION: "privacy.usercontext.about_newtab_segregation.enabled",
/**
* Time span constants corresponding to values of the privacy.sanitize.timeSpan
* pref. Used to determine how much history to clear, for various items
@ -91,6 +98,11 @@ var Sanitizer = {
*/
shouldSanitizeOnShutdown: false,
/**
* Whether we should sanitize the private container for about:newtab.
*/
shouldSanitizeNewTabContainer: false,
/**
* Shows a sanitization dialog to the user.
*
@ -145,6 +157,17 @@ var Sanitizer = {
{fetchState: () => ({ progress })}
);
this.shouldSanitizeNewTabContainer = Services.prefs.getBoolPref(this.PREF_NEWTAB_SEGREGATION, false);
if (this.shouldSanitizeNewTabContainer) {
addPendingSanitization("newtab-container", [], {});
}
let i = pendingSanitizations.findIndex(s => s.id == "newtab-container");
if (i) {
pendingSanitizations.splice(i, 1);
sanitizeNewTabSegregation();
}
// Finally, run the sanitizations that were left pending, because we crashed
// before completing them.
for (let {itemsToClear, options} of pendingSanitizations) {
@ -272,6 +295,12 @@ var Sanitizer = {
let itemsToClear = getItemsToClearFromPrefBranch(Sanitizer.PREF_SHUTDOWN_BRANCH);
addPendingSanitization("shutdown", itemsToClear, {});
}
} else if (data == this.PREF_NEWTAB_SEGREGATION) {
this.shouldSanitizeNewTabContainer = Services.prefs.getBoolPref(this.PREF_NEWTAB_SEGREGATION, false);
removePendingSanitization("newtab-container");
if (this.shouldSanitizeNewTabContainer) {
addPendingSanitization("newtab-container", [], {});
}
}
}
},
@ -990,6 +1019,11 @@ async function sanitizeOnShutdown(progress) {
}
}
if (Sanitizer.shouldSanitizeNewTabContainer) {
sanitizeNewTabSegregation();
removePendingSanitization("newtab-container");
}
if (Sanitizer.shouldSanitizeOnShutdown) {
// We didn't crash during shutdown sanitization, so annotate it to avoid
// sanitizing again on startup.
@ -1061,6 +1095,14 @@ async function sanitizeSessionPrincipal(principal) {
]);
}
function sanitizeNewTabSegregation() {
let identity = ContextualIdentityService.getPrivateIdentity("userContextIdInternal.thumbnail");
if (identity) {
Services.obs.notifyObservers(null, "clear-origin-attributes-data",
JSON.stringify({ userContextId: identity.userContextId }));
}
}
/**
* Gets an array of items to clear from the given pref branch.
* @param branch The pref branch to fetch.

View File

@ -11,9 +11,13 @@ do_get_profile();
add_task(async function() {
ChromeUtils.import("resource:///modules/Sanitizer.jsm");
Services.prefs.setBoolPref(Sanitizer.PREF_NEWTAB_SEGREGATION, false);
registerCleanupFunction(() => {
Services.prefs.clearUserPref(Sanitizer.PREF_SANITIZE_ON_SHUTDOWN);
Services.prefs.clearUserPref(Sanitizer.PREF_SHUTDOWN_BRANCH + "formdata");
Services.prefs.clearUserPref(Sanitizer.PREF_NEWTAB_SEGREGATION);
});
Services.prefs.setBoolPref(Sanitizer.PREF_SANITIZE_ON_SHUTDOWN, true);
Services.prefs.setBoolPref(Sanitizer.PREF_SHUTDOWN_BRANCH + "formdata", true);