mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 00:32:11 +00:00
Bug 1660966 - Implement basic region filtering for remote top site defaults. r=mikedeboer
Differential Revision: https://phabricator.services.mozilla.com/D88120
This commit is contained in:
parent
b85693acc5
commit
cade61bc40
@ -89,8 +89,8 @@ module.exports = function(config) {
|
||||
"lib/TopSitesFeed.jsm": {
|
||||
statements: 80,
|
||||
lines: 80,
|
||||
functions: 96,
|
||||
branches: 80,
|
||||
functions: 90,
|
||||
branches: 70,
|
||||
},
|
||||
"lib/Screenshots.jsm": {
|
||||
statements: 94,
|
||||
|
@ -66,6 +66,11 @@ ChromeUtils.defineModuleGetter(
|
||||
"RemoteSettings",
|
||||
"resource://services-settings/remote-settings.js"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"Region",
|
||||
"resource://gre/modules/Region.jsm"
|
||||
);
|
||||
|
||||
const DEFAULT_SITES_PREF = "default.sites";
|
||||
const SHOWN_ON_NEWTAB_PREF = "feeds.topsites";
|
||||
@ -271,7 +276,7 @@ this.TopSitesFeed = class TopSitesFeed {
|
||||
failed = true;
|
||||
}
|
||||
if (!result.length) {
|
||||
Cu.reportError("Received empty search configuration!");
|
||||
Cu.reportError("Received empty top sites configuration!");
|
||||
failed = true;
|
||||
}
|
||||
// If we failed, or the result is empty, try loading from the local dump.
|
||||
@ -280,8 +285,27 @@ this.TopSitesFeed = class TopSitesFeed {
|
||||
// Now call this again.
|
||||
return this._getRemoteConfig(false);
|
||||
}
|
||||
|
||||
// Sort sites based on the "order" attribute.
|
||||
result.sort((a, b) => a.order - b.order);
|
||||
|
||||
// Filter by region.
|
||||
result = result.filter(topsite => {
|
||||
if (
|
||||
topsite.exclude_regions &&
|
||||
topsite.exclude_regions.includes(Region.home)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
topsite.include_regions &&
|
||||
!topsite.include_regions.includes(Region.home)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
{"data":[{"url":"https://www.amazon.com/","order":4,"title":"Amazon","schema":1598289482863,"send_attribution_request":true,"id":"08f43769-116f-4450-b57d-5108042b5fe5","last_modified":1598289691049},{"url":"https://www.facebook.com/","order":1,"title":"Facebook","schema":1598289454075,"send_attribution_request":false,"id":"b64b8279-6996-4e35-9176-c5ae5964c422","last_modified":1598289691047},{"url":"https://www.youtube.com/","order":3,"title":"Youtube","schema":1598289470275,"send_attribution_request":false,"id":"fc5d5d35-5637-4268-bb5f-f262818fa7e9","last_modified":1598289691044},{"url":"https://www.wikipedia.org/","order":5,"title":"Wikipedia","schema":1598289491094,"send_attribution_request":false,"id":"7105fa42-4066-41df-9af3-885a7b2e9682","last_modified":1598289691041},{"url":"https://twitter.com/","order":2,"title":"Twitter","schema":1598289462557,"send_attribution_request":false,"id":"6bb2647b-31d6-4185-9052-6d680bf2d777","last_modified":1598289691039},{"url":"https://google.com/","order":0,"schema":1598289436719,"search_shortcut":true,"send_attribution_request":false,"id":"cb6417cc-21d1-4a4d-9103-5094a5277342","last_modified":1598289691036}]}
|
||||
{"data":[{"url":"https://www.wikipedia.org/","order":5,"title":"Wikipedia","schema":1598345694864,"exclude_regions":["DE"],"send_attribution_request":false,"id":"7105fa42-4066-41df-9af3-885a7b2e9682","last_modified":1598345800680},{"url":"https://de.wikipedia.org/wiki/","order":5,"title":"Wikipedia (DE)","schema":1598345679108,"include_regions":["DE"],"id":"f5419213-0611-40f5-aa12-ddc79d096657","last_modified":1598345800678},{"url":"https://google.com/","order":0,"title":"Google","schema":1598343701162,"keyword":"@google","search_shortcut":true,"send_attribution_request":false,"id":"cb6417cc-21d1-4a4d-9103-5094a5277342","last_modified":1598344419277},{"url":"https://www.facebook.com/","order":1,"title":"Facebook","schema":1598289454075,"send_attribution_request":false,"id":"b64b8279-6996-4e35-9176-c5ae5964c422","last_modified":1598290394840},{"url":"https://www.youtube.com/","order":3,"title":"Youtube","schema":1598289470275,"send_attribution_request":false,"id":"fc5d5d35-5637-4268-bb5f-f262818fa7e9","last_modified":1598290394838},{"url":"https://twitter.com/","order":2,"title":"Twitter","schema":1598289462557,"send_attribution_request":false,"id":"6bb2647b-31d6-4185-9052-6d680bf2d777","last_modified":1598290394833},{"url":"https://www.amazon.com/","order":4,"title":"Amazon","schema":1598289482863,"send_attribution_request":true,"id":"08f43769-116f-4450-b57d-5108042b5fe5","last_modified":1598290394831}]}
|
||||
|
Loading…
Reference in New Issue
Block a user