Bug 1745495 - Don't initialize activity stream when new tab is disabled. r=daleharvey

This will also load activity stream if the pref is enabled again.

Differential Revision: https://phabricator.services.mozilla.com/D133541
This commit is contained in:
Brendan Dahl 2021-12-22 09:10:05 +00:00
Родитель 2c4082a199
Коммит efbcfe5c99
2 изменённых файлов: 43 добавлений и 1 удалений

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

@ -34,11 +34,13 @@ const SEPARATE_PRIVILEGED_CONTENT_PROCESS_PREF =
"browser.tabs.remote.separatePrivilegedContentProcess"; "browser.tabs.remote.separatePrivilegedContentProcess";
const ACTIVITY_STREAM_DEBUG_PREF = "browser.newtabpage.activity-stream.debug"; const ACTIVITY_STREAM_DEBUG_PREF = "browser.newtabpage.activity-stream.debug";
const SIMPLIFIED_WELCOME_ENABLED_PREF = "browser.aboutwelcome.enabled"; const SIMPLIFIED_WELCOME_ENABLED_PREF = "browser.aboutwelcome.enabled";
const NEWTAB_PREF = "browser.newtabpage.enabled";
function cleanup() { function cleanup() {
Services.prefs.clearUserPref(SEPARATE_PRIVILEGED_CONTENT_PROCESS_PREF); Services.prefs.clearUserPref(SEPARATE_PRIVILEGED_CONTENT_PROCESS_PREF);
Services.prefs.clearUserPref(ACTIVITY_STREAM_DEBUG_PREF); Services.prefs.clearUserPref(ACTIVITY_STREAM_DEBUG_PREF);
Services.prefs.clearUserPref(SIMPLIFIED_WELCOME_ENABLED_PREF); Services.prefs.clearUserPref(SIMPLIFIED_WELCOME_ENABLED_PREF);
Services.prefs.clearUserPref(NEWTAB_PREF);
AboutNewTab.resetNewTabURL(); AboutNewTab.resetNewTabURL();
} }
@ -357,3 +359,20 @@ addTestsWithPrivilegedContentProcessPref(async function test_updates() {
cleanup(); cleanup();
}); });
add_task(async function test_disabling_newtab() {
// Check disabling new tab also disables activity stream.
Services.prefs.setBoolPref(NEWTAB_PREF, false);
Assert.ok(
!AboutNewTab.activityStreamEnabled,
".activityStreamEnabled should be disabled"
);
// Check enabling new tab also enables activity stream.
Services.prefs.setBoolPref(NEWTAB_PREF, true);
Assert.ok(
AboutNewTab.activityStreamEnabled,
".activityStreamEnabled should be enabled."
);
cleanup();
});

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

@ -40,6 +40,7 @@ const AboutNewTab = {
_activityStreamEnabled: false, _activityStreamEnabled: false,
activityStream: null, activityStream: null,
activityStreamDebug: false, activityStreamDebug: false,
browserReady: false,
_newTabURL: ABOUT_URL, _newTabURL: ABOUT_URL,
_newTabURLOverridden: false, _newTabURLOverridden: false,
@ -77,8 +78,21 @@ const AboutNewTab = {
} }
); );
XPCOMUtils.defineLazyPreferenceGetter(
this,
"newTabPageEnabled",
"browser.newtabpage.enabled",
false,
(preference, previousValue, newValue) => {
if (newValue && this.browserReady) {
this.initializeActivityStream();
}
this.toggleActivityStream(newValue);
}
);
// More initialization happens here // More initialization happens here
this.toggleActivityStream(true); this.toggleActivityStream(this.newTabPageEnabled);
this.initialized = true; this.initialized = true;
if (this.isPageListenerOverridden) { if (this.isPageListenerOverridden) {
@ -169,6 +183,15 @@ const AboutNewTab = {
* onBrowserReady - Continues the initialization of Activity Stream after browser is ready. * onBrowserReady - Continues the initialization of Activity Stream after browser is ready.
*/ */
onBrowserReady() { onBrowserReady() {
this.browserReady = true;
if (!this.newTabPageEnabled) {
// Don't bother initializing activity stream if new tab page is disabled.
return;
}
this.initializeActivityStream();
},
initializeActivityStream() {
if (this.activityStream && this.activityStream.initialized) { if (this.activityStream && this.activityStream.initialized) {
return; return;
} }