зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1653932 - Add pref for top site defaults from remote settings. r=mikedeboer
Differential Revision: https://phabricator.services.mozilla.com/D84532
This commit is contained in:
Родитель
2dcd19dfc0
Коммит
ab5f6e6216
|
@ -1291,6 +1291,8 @@ pref("prompts.tab_modal.enabled", true);
|
||||||
// This is a fallback value for when prompt callers do not specify a modalType.
|
// This is a fallback value for when prompt callers do not specify a modalType.
|
||||||
pref("prompts.defaultModalType", 3);
|
pref("prompts.defaultModalType", 3);
|
||||||
|
|
||||||
|
pref("browser.topsites.useRemoteSetting", false);
|
||||||
|
|
||||||
// Activates preloading of the new tab url.
|
// Activates preloading of the new tab url.
|
||||||
pref("browser.newtab.preload", true);
|
pref("browser.newtab.preload", true);
|
||||||
|
|
||||||
|
|
|
@ -121,9 +121,17 @@ this.Screenshots = {
|
||||||
if (!this._shouldGetScreenshots()) {
|
if (!this._shouldGetScreenshots()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// __sharedCache may not exist yet for links from default top sites that
|
||||||
|
// don't have a default tippy top icon.
|
||||||
|
// eslint-disable-next-line no-unsanitized/property
|
||||||
|
link.__sharedCache ??= {
|
||||||
|
updateLink(prop, val) {
|
||||||
|
link[prop] = val;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const cache = link.__sharedCache;
|
||||||
// Nothing to do if we already have a pending screenshot or
|
// Nothing to do if we already have a pending screenshot or
|
||||||
// if a previous request failed and returned null.
|
// if a previous request failed and returned null.
|
||||||
const cache = link.__sharedCache;
|
|
||||||
if (cache.fetchingScreenshot || link[property] !== undefined) {
|
if (cache.fetchingScreenshot || link[property] !== undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,9 @@ for (let searchProvider of ["amazon", "google"]) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const REMOTE_SETTING_DEFAULTS_PREF = "browser.topsites.useRemoteSetting";
|
||||||
|
const REMOTE_SETTING_OVERRIDE_PREF = "browser.topsites.default";
|
||||||
|
|
||||||
function getShortURLForCurrentSearch() {
|
function getShortURLForCurrentSearch() {
|
||||||
const url = shortURL({ url: Services.search.defaultEngine.searchForm });
|
const url = shortURL({ url: Services.search.defaultEngine.searchForm });
|
||||||
return url;
|
return url;
|
||||||
|
@ -125,15 +128,15 @@ this.TopSitesFeed = class TopSitesFeed {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
// If the feed was previously disabled PREFS_INITIAL_VALUES was never received
|
// If the feed was previously disabled PREFS_INITIAL_VALUES was never received
|
||||||
this.refreshDefaults(
|
this._readDefaults();
|
||||||
this.store.getState().Prefs.values[DEFAULT_SITES_PREF]
|
|
||||||
);
|
|
||||||
this._storage = this.store.dbStorage.getDbTable("sectionPrefs");
|
this._storage = this.store.dbStorage.getDbTable("sectionPrefs");
|
||||||
this.refresh({ broadcast: true, isStartup: true });
|
this.refresh({ broadcast: true, isStartup: true });
|
||||||
Services.obs.addObserver(this, "browser-search-engine-modified");
|
Services.obs.addObserver(this, "browser-search-engine-modified");
|
||||||
for (let [pref] of SEARCH_TILE_OVERRIDE_PREFS) {
|
for (let [pref] of SEARCH_TILE_OVERRIDE_PREFS) {
|
||||||
Services.prefs.addObserver(pref, this);
|
Services.prefs.addObserver(pref, this);
|
||||||
}
|
}
|
||||||
|
Services.prefs.addObserver(REMOTE_SETTING_DEFAULTS_PREF, this);
|
||||||
|
Services.prefs.addObserver(REMOTE_SETTING_OVERRIDE_PREF, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
uninit() {
|
uninit() {
|
||||||
|
@ -142,24 +145,35 @@ this.TopSitesFeed = class TopSitesFeed {
|
||||||
for (let [pref] of SEARCH_TILE_OVERRIDE_PREFS) {
|
for (let [pref] of SEARCH_TILE_OVERRIDE_PREFS) {
|
||||||
Services.prefs.removeObserver(pref, this);
|
Services.prefs.removeObserver(pref, this);
|
||||||
}
|
}
|
||||||
|
Services.prefs.removeObserver(REMOTE_SETTING_DEFAULTS_PREF, this);
|
||||||
|
Services.prefs.removeObserver(REMOTE_SETTING_OVERRIDE_PREF, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
observe(subj, topic, data) {
|
observe(subj, topic, data) {
|
||||||
// We should update the current top sites if the search engine has been changed since
|
switch (topic) {
|
||||||
// the search engine that gets filtered out of top sites has changed.
|
case "browser-search-engine-modified":
|
||||||
if (
|
// We should update the current top sites if the search engine has been changed since
|
||||||
topic === "browser-search-engine-modified" &&
|
// the search engine that gets filtered out of top sites has changed.
|
||||||
data === "engine-default" &&
|
if (
|
||||||
this.store.getState().Prefs.values[FILTER_DEFAULT_SEARCH_PREF]
|
data === "engine-default" &&
|
||||||
) {
|
this.store.getState().Prefs.values[FILTER_DEFAULT_SEARCH_PREF]
|
||||||
delete this._currentSearchHostname;
|
) {
|
||||||
this._currentSearchHostname = getShortURLForCurrentSearch();
|
delete this._currentSearchHostname;
|
||||||
this.refresh({ broadcast: true });
|
this._currentSearchHostname = getShortURLForCurrentSearch();
|
||||||
} else if (
|
this.refresh({ broadcast: true });
|
||||||
topic === "nsPref:changed" &&
|
}
|
||||||
SEARCH_TILE_OVERRIDE_PREFS.has(data)
|
break;
|
||||||
) {
|
case "nsPref:changed":
|
||||||
this.refresh({ broadcast: true });
|
if (
|
||||||
|
data === REMOTE_SETTING_DEFAULTS_PREF ||
|
||||||
|
data === REMOTE_SETTING_OVERRIDE_PREF
|
||||||
|
) {
|
||||||
|
this._readDefaults();
|
||||||
|
this.refresh({ broadcast: true });
|
||||||
|
} else if (SEARCH_TILE_OVERRIDE_PREFS.has(data)) {
|
||||||
|
this.refresh({ broadcast: true });
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +181,30 @@ this.TopSitesFeed = class TopSitesFeed {
|
||||||
return site && site.hostname;
|
return site && site.hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _readDefaults - sets DEFAULT_TOP_SITES
|
||||||
|
*/
|
||||||
|
_readDefaults() {
|
||||||
|
this._useRemoteSetting = Services.prefs.getBoolPref(
|
||||||
|
REMOTE_SETTING_DEFAULTS_PREF
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!this._useRemoteSetting) {
|
||||||
|
this.refreshDefaults(
|
||||||
|
this.store.getState().Prefs.values[DEFAULT_SITES_PREF]
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let sites;
|
||||||
|
try {
|
||||||
|
sites = Services.prefs.getStringPref(REMOTE_SETTING_OVERRIDE_PREF);
|
||||||
|
} catch (e) {}
|
||||||
|
// Placeholder for the actual remote setting (bug 1653937).
|
||||||
|
sites ??= "https://mozilla.org,https://firefox.com";
|
||||||
|
this.refreshDefaults(sites);
|
||||||
|
}
|
||||||
|
|
||||||
refreshDefaults(sites) {
|
refreshDefaults(sites) {
|
||||||
// Clear out the array of any previous defaults
|
// Clear out the array of any previous defaults
|
||||||
DEFAULT_TOP_SITES.length = 0;
|
DEFAULT_TOP_SITES.length = 0;
|
||||||
|
@ -884,7 +922,9 @@ this.TopSitesFeed = class TopSitesFeed {
|
||||||
case at.PREF_CHANGED:
|
case at.PREF_CHANGED:
|
||||||
switch (action.data.name) {
|
switch (action.data.name) {
|
||||||
case DEFAULT_SITES_PREF:
|
case DEFAULT_SITES_PREF:
|
||||||
this.refreshDefaults(action.data.value);
|
if (!this._useRemoteSetting) {
|
||||||
|
this.refreshDefaults(action.data.value);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ROWS_PREF:
|
case ROWS_PREF:
|
||||||
case FILTER_DEFAULT_SEARCH_PREF:
|
case FILTER_DEFAULT_SEARCH_PREF:
|
||||||
|
@ -906,7 +946,9 @@ this.TopSitesFeed = class TopSitesFeed {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case at.PREFS_INITIAL_VALUES:
|
case at.PREFS_INITIAL_VALUES:
|
||||||
this.refreshDefaults(action.data[DEFAULT_SITES_PREF]);
|
if (!this._useRemoteSetting) {
|
||||||
|
this.refreshDefaults(action.data[DEFAULT_SITES_PREF]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case at.TOP_SITES_PIN:
|
case at.TOP_SITES_PIN:
|
||||||
this.pin(action);
|
this.pin(action);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче