From 612caa865ce31293ce7d7ead8168df57a3fd2f26 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Tue, 29 May 2018 17:35:28 +0200 Subject: [PATCH] Bug 1462662 - Wipe the container for privacy.usercontext.about_newtab_segregation.enabled on shutdown, r=johannh --- browser/modules/Sanitizer.jsm | 42 +++++++++++++++++++ .../test/unit/test_Sanitizer_interrupted.js | 4 ++ 2 files changed, 46 insertions(+) diff --git a/browser/modules/Sanitizer.jsm b/browser/modules/Sanitizer.jsm index 303a5e1ca513..6fd30f708835 100644 --- a/browser/modules/Sanitizer.jsm +++ b/browser/modules/Sanitizer.jsm @@ -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 != -1) { + 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. diff --git a/browser/modules/test/unit/test_Sanitizer_interrupted.js b/browser/modules/test/unit/test_Sanitizer_interrupted.js index 707b8b6431d6..575f113921be 100644 --- a/browser/modules/test/unit/test_Sanitizer_interrupted.js +++ b/browser/modules/test/unit/test_Sanitizer_interrupted.js @@ -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);