Skip to content

Commit

Permalink
Bug 1931859 - Newtab ensure if Unified ads API is turned on and off, …
Browse files Browse the repository at this point in the history
…we keep the state and experience consistent. a=dmeehan

Original Revision: https://phabricator.services.mozilla.com/D229341

Differential Revision: https://phabricator.services.mozilla.com/D229351
  • Loading branch information
ScottDowne committed Nov 18, 2024
1 parent ad5c22c commit e5a84b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions browser/components/newtab/lib/TelemetryFeed.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const TELEMETRY_PREF = "telemetry";
export const EVENTS_TELEMETRY_PREF = "telemetry.ut.events";
export const PREF_UNIFIED_ADS_SPOCS_ENABLED = "unifiedAds.spocs.enabled";
export const PREF_UNIFIED_ADS_TILES_ENABLED = "unifiedAds.tiles.enabled";
const PREF_ENDPOINTS = "discoverystream.endpoints";
const PREF_SHOW_SPONSORED_STORIES = "showSponsored";
const PREF_SHOW_SPONSORED_TOPSITES = "showSponsoredTopSites";

Expand Down Expand Up @@ -978,6 +979,14 @@ export class TelemetryFeed {
);
}

// Make sure the callback endpoint is allowed
const allowed = this._prefs.get(PREF_ENDPOINTS).split(",");
if (!allowed.some(prefix => data.url.startsWith(prefix))) {
throw new Error(
`[Unified ads callback] Not one of allowed prefixes (${allowed})`
);
}

const url = new URL(data.url);
url.searchParams.append("position", data.position);

Expand Down
1 change: 1 addition & 0 deletions browser/components/newtab/lib/TopSitesFeed.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,7 @@ export class TopSitesFeed {
this.refresh({ broadcast: true });
break;
case SHOW_SPONSORED_PREF:
case PREF_UNIFIED_ADS_TILES_ENABLED:
if (
lazy.NimbusFeatures.newtab.getVariable(
NIMBUS_VARIABLE_CONTILE_ENABLED
Expand Down

0 comments on commit e5a84b3

Please sign in to comment.