diff options
Diffstat (limited to 'browser/components/newtab/lib/OnboardingMessageProvider.jsm')
-rw-r--r-- | browser/components/newtab/lib/OnboardingMessageProvider.jsm | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/browser/components/newtab/lib/OnboardingMessageProvider.jsm b/browser/components/newtab/lib/OnboardingMessageProvider.jsm new file mode 100644 index 0000000000..d2219647c7 --- /dev/null +++ b/browser/components/newtab/lib/OnboardingMessageProvider.jsm @@ -0,0 +1,92 @@ +/* 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/. */ +"use strict"; +/* globals Localization */ +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); + +const L10N = new Localization([ + "branding/brand.ftl", + "browser/branding/brandings.ftl", + "browser/branding/sync-brand.ftl", + "browser/newtab/onboarding.ftl", +]); + +const ONBOARDING_MESSAGES = () => [ + { + id: "FXA_ACCOUNTS_BADGE", + template: "toolbar_badge", + content: { + delay: 10000, // delay for 10 seconds + target: "fxa-toolbar-menu-button", + }, + // Never accessed the FxA panel && doesn't use Firefox sync & has FxA enabled + targeting: `!hasAccessedFxAPanel && !usesFirefoxSync && isFxAEnabled == true`, + trigger: { id: "toolbarBadgeUpdate" }, + }, + { + id: "PROTECTIONS_PANEL_1", + template: "protections_panel", + content: { + title: { string_id: "cfr-protections-panel-header" }, + body: { string_id: "cfr-protections-panel-body" }, + link_text: { string_id: "cfr-protections-panel-link-text" }, + cta_url: `${Services.urlFormatter.formatURLPref( + "app.support.baseURL" + )}etp-promotions?as=u&utm_source=inproduct`, + cta_type: "OPEN_URL", + }, + trigger: { id: "protectionsPanelOpen" }, + }, +]; + +const OnboardingMessageProvider = { + async getExtraAttributes() { + const [header, button_label] = await L10N.formatMessages([ + { id: "onboarding-welcome-header" }, + { id: "onboarding-start-browsing-button-label" }, + ]); + return { header: header.value, button_label: button_label.value }; + }, + async getMessages() { + const messages = await this.translateMessages(await ONBOARDING_MESSAGES()); + return messages; + }, + async getUntranslatedMessages() { + // This is helpful for jsonSchema testing - since we are localizing in the provider + const messages = await ONBOARDING_MESSAGES(); + return messages; + }, + async translateMessages(messages) { + let translatedMessages = []; + for (const msg of messages) { + let translatedMessage = { ...msg }; + + // If the message has no content, do not attempt to translate it + if (!translatedMessage.content) { + translatedMessages.push(translatedMessage); + continue; + } + + // Translate any secondary buttons separately + if (msg.content.secondary_button) { + const [secondary_button_string] = await L10N.formatMessages([ + { id: msg.content.secondary_button.label.string_id }, + ]); + translatedMessage.content.secondary_button.label = + secondary_button_string.value; + } + if (msg.content.header) { + const [header_string] = await L10N.formatMessages([ + { id: msg.content.header.string_id }, + ]); + translatedMessage.content.header = header_string.value; + } + translatedMessages.push(translatedMessage); + } + return translatedMessages; + }, +}; +this.OnboardingMessageProvider = OnboardingMessageProvider; + +const EXPORTED_SYMBOLS = ["OnboardingMessageProvider"]; |