1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
/* import-globals-from preferences.js */
var gMoreFromMozillaPane = {
initialized: false,
/**
* "default" is whatever template is the default, as defined by the code
* in this file (currently in `getTemplateName`). Setting option to an
* invalid value will leave it unchanged.
*/
_option: "default",
set option(value) {
if (!value) {
this._option = "default";
return;
}
if (value === "default" || value === "simple") {
this._option = value;
}
},
get option() {
return this._option;
},
getTemplateName() {
if (!this._option || this._option == "default") {
return "simple";
}
return this._option;
},
getURL(url, region, option, hasEmail) {
const URL_PARAMS = {
utm_source: "about-prefs",
utm_campaign: "morefrommozilla",
utm_medium: "firefox-desktop",
};
// UTM content param used in analytics to record
// UI template used to open URL
const utm_content = {
default: "default",
simple: "fxvt-113-a",
};
const experiment_params = {
entrypoint_experiment: "morefrommozilla-experiment-1846",
};
let pageUrl = new URL(url);
for (let [key, val] of Object.entries(URL_PARAMS)) {
pageUrl.searchParams.append(key, val);
}
// Append region by product to utm_content and also
// append '-email' when URL is opened
// from send email link in QRCode box
if (option) {
pageUrl.searchParams.set(
"utm_content",
`${utm_content[option]}-${region}${hasEmail ? "-email" : ""}`
);
}
// Add experiments params when user is shown an experimental UI
// with template value as 'simple' set via Nimbus
if (option !== "default") {
pageUrl.searchParams.set(
"entrypoint_experiment",
experiment_params.entrypoint_experiment
);
pageUrl.searchParams.set("entrypoint_variation", `treatment-${option}`);
}
return pageUrl.toString();
},
renderProducts() {
const isRegionUS = Region.home.toLowerCase() === "us";
let products = [
{
id: "firefox-mobile",
title_string_id: "more-from-moz-firefox-mobile-title",
description_string_id: "more-from-moz-firefox-mobile-description",
region: "global",
button: {
id: "fxMobile",
type: "link",
label_string_id: "more-from-moz-learn-more-link",
actionURL: BrowserUtils.isChinaRepack()
? "https://www.firefox.com.cn/browsers/mobile/"
: "https://www.mozilla.org/firefox/browsers/mobile/",
},
qrcode: {
title: {
string_id: "more-from-moz-qr-code-box-firefox-mobile-title",
},
image_src_prefix:
"chrome://browser/content/preferences/more-from-mozilla-qr-code",
button: {
id: "qr-code-send-email",
label: {
string_id: "more-from-moz-qr-code-box-firefox-mobile-button",
},
actionURL: BrowserUtils.isChinaRepack()
? "https://www.firefox.com.cn/mobile/get-app/"
: "https://www.mozilla.org/firefox/mobile/get-app/?v=mfm",
},
},
},
{
id: "mozilla-monitor",
title_string_id: "more-from-moz-mozilla-monitor-title",
description_string_id: isRegionUS
? "more-from-moz-mozilla-monitor-us-description"
: "more-from-moz-mozilla-monitor-global-description",
region: isRegionUS ? "us" : "global",
button: {
id: "mozillaMonitor",
label_string_id: "more-from-moz-mozilla-monitor-button",
actionURL: "https://monitor.mozilla.org/",
},
},
];
if (BrowserUtils.shouldShowVPNPromo()) {
const vpn = {
id: "mozilla-vpn",
title_string_id: "more-from-moz-mozilla-vpn-title",
description_string_id: "more-from-moz-mozilla-vpn-description",
region: "global",
button: {
id: "mozillaVPN",
label_string_id: "more-from-moz-button-mozilla-vpn-2",
actionURL: "https://www.mozilla.org/products/vpn/",
},
};
products.push(vpn);
}
if (BrowserUtils.shouldShowPromo(BrowserUtils.PromoType.RELAY)) {
const relay = {
id: "firefox-relay",
title_string_id: "more-from-moz-firefox-relay-title",
description_string_id: "more-from-moz-firefox-relay-description",
region: "global",
button: {
id: "firefoxRelay",
label_string_id: "more-from-moz-firefox-relay-button",
actionURL: "https://relay.firefox.com/",
},
};
products.push(relay);
}
products.push({
id: "solo-ai",
title_string_id: "more-from-moz-solo-title",
description_string_id: "more-from-moz-solo-description",
region: "global",
button: {
id: "soloAI",
label_string_id: "more-from-moz-solo-button",
actionURL: "https://soloist.ai/?utm_type=more_from_mozilla",
},
});
this._productsContainer = document.getElementById(
"moreFromMozillaCategory"
);
let frag = document.createDocumentFragment();
this._template = document.getElementById(this.getTemplateName());
// Exit when internal data is incomplete
if (!this._template) {
return;
}
for (let product of products) {
let template = this._template.content.cloneNode(true);
let title = template.querySelector(".product-title");
let desc = template.querySelector(".description");
document.l10n.setAttributes(title, product.title_string_id);
title.id = product.id;
document.l10n.setAttributes(desc, product.description_string_id);
let isLink = product.button.type === "link";
let actionElement = template.querySelector(
isLink ? ".text-link" : ".small-button"
);
if (actionElement) {
actionElement.hidden = false;
actionElement.id = `${this.option}-${product.button.id}`;
document.l10n.setAttributes(
actionElement,
product.button.label_string_id
);
if (isLink) {
actionElement.setAttribute(
"href",
this.getURL(product.button.actionURL, product.region, this.option)
);
} else {
actionElement.addEventListener("click", function () {
let mainWindow = window.windowRoot.ownerGlobal;
mainWindow.openTrustedLinkIn(
gMoreFromMozillaPane.getURL(
product.button.actionURL,
product.region,
gMoreFromMozillaPane.option
),
"tab"
);
});
}
}
if (product.qrcode) {
let qrcode = template.querySelector(".qr-code-box");
qrcode.setAttribute("hidden", "false");
let qrcode_title = template.querySelector(".qr-code-box-title");
document.l10n.setAttributes(
qrcode_title,
product.qrcode.title.string_id
);
let img = template.querySelector(".qr-code-box-image");
// Append QRCode image source by template. For CN region
// simple template, we want a CN specific QRCode
img.src =
product.qrcode.image_src_prefix +
"-" +
this.getTemplateName() +
`${
BrowserUtils.isChinaRepack() &&
this.getTemplateName().includes("simple")
? "-cn"
: ""
}` +
".svg";
// Add image a11y attributes
document.l10n.setAttributes(
img,
"more-from-moz-qr-code-firefox-mobile-img"
);
let qrc_link = template.querySelector(".qr-code-link");
// So the telemetry includes info about which option is being used
qrc_link.id = `${this.option}-${product.qrcode.button.id}`;
// For supported locales, this link allows users to send themselves a
// download link by email. It should be hidden for unsupported locales.
if (BrowserUtils.sendToDeviceEmailsSupported()) {
document.l10n.setAttributes(
qrc_link,
product.qrcode.button.label.string_id
);
qrc_link.href = this.getURL(
product.qrcode.button.actionURL,
product.region,
this.option,
true
);
qrc_link.hidden = false;
}
}
frag.appendChild(template);
}
this._productsContainer.appendChild(frag);
},
async init() {
if (this.initialized) {
return;
}
this.initialized = true;
document
.getElementById("moreFromMozillaCategory")
.removeAttribute("data-hidden-from-search");
document
.getElementById("moreFromMozillaCategory-header")
.removeAttribute("data-hidden-from-search");
this.renderProducts();
},
};
|