Bug 1923868 - Support setting Firefox as default based on installer attribution campaign r=firefox-desktop-core-reviewers ,nalexander,omc-reviewers,pdahiya
This patch adds an startup idle task that sets the browser as default if an attribution campaign id of "set_default_browser" is present on first run. This works supports an upcoming experiment where users will have the option to "download as default" via [[ https://www.mozilla.org/en-US/firefox/new/ | the stub installer marketing page ]]. Differential Revision: https://phabricator.services.mozilla.com/D225212
This commit is contained in:
@@ -176,6 +176,12 @@ XPCOMUtils.defineLazyPreferenceGetter(
|
||||
"toolkit.profiles.storeID",
|
||||
null
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
lazy,
|
||||
"didHandleCampaignAction",
|
||||
"trailhead.firstrun.didHandleCampaignAction",
|
||||
false
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetters(lazy, {
|
||||
AUS: ["@mozilla.org/updates/update-service;1", "nsIApplicationUpdateService"],
|
||||
@@ -258,6 +264,39 @@ function CacheListAttachedOAuthClients() {
|
||||
};
|
||||
}
|
||||
|
||||
function CacheUnhandledCampaignAction() {
|
||||
return {
|
||||
_lastUpdated: 0,
|
||||
_value: null,
|
||||
expire() {
|
||||
this._lastUpdated = 0;
|
||||
this._value = null;
|
||||
},
|
||||
get() {
|
||||
const now = Date.now();
|
||||
// Don't get cached value until the action has been handled to ensure
|
||||
// proper screen targeting in about:welcome
|
||||
if (
|
||||
now - this._lastUpdated >= FRECENT_SITES_UPDATE_INTERVAL ||
|
||||
!lazy.didHandleCampaignAction
|
||||
) {
|
||||
this._value = null;
|
||||
if (!lazy.didHandleCampaignAction) {
|
||||
const attributionData =
|
||||
lazy.AttributionCode.getCachedAttributionData();
|
||||
const ALLOWED_CAMPAIGN_ACTIONS = ["SET_DEFAULT_BROWSER"];
|
||||
const campaign = attributionData?.campaign?.toUpperCase();
|
||||
if (campaign && ALLOWED_CAMPAIGN_ACTIONS.includes(campaign)) {
|
||||
this._value = campaign;
|
||||
}
|
||||
}
|
||||
this._lastUpdated = now;
|
||||
}
|
||||
return this._value;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function CheckBrowserNeedsUpdate(
|
||||
updateInterval = FRECENT_SITES_UPDATE_INTERVAL
|
||||
) {
|
||||
@@ -326,6 +365,7 @@ export const QueryCache = {
|
||||
RecentBookmarks: new CachedTargetingGetter("getRecentBookmarks"),
|
||||
ListAttachedOAuthClients: new CacheListAttachedOAuthClients(),
|
||||
UserMonthlyActivity: new CachedTargetingGetter("getUserMonthlyActivity"),
|
||||
UnhandledCampaignAction: new CacheUnhandledCampaignAction(),
|
||||
},
|
||||
getters: {
|
||||
doesAppNeedPin: new CachedTargetingGetter(
|
||||
@@ -1066,6 +1106,17 @@ const TargetingGetters = {
|
||||
return attributionData?.campaign === "migration";
|
||||
},
|
||||
|
||||
/**
|
||||
* Whether the user opted into a special message action represented by an
|
||||
* installer attribution campaign and this choice still needs to be honored.
|
||||
* @return {string} A special message action to be executed on first-run. For
|
||||
* example, `"SET_DEFAULT_BROWSER"` when the user selected to set as default
|
||||
* via the install marketing page and set default has not yet been
|
||||
* automatically triggered, 'null' otherwise.
|
||||
*/
|
||||
get unhandledCampaignAction() {
|
||||
return QueryCache.queries.UnhandledCampaignAction.get();
|
||||
},
|
||||
/**
|
||||
* The values of the height and width available to the browser to display
|
||||
* web content. The available height and width are each calculated taking
|
||||
|
||||
Reference in New Issue
Block a user