|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +const lazy = {}; |
| 6 | +const { topChromeWindow } = window.browsingContext; |
| 7 | +const { XPCOMUtils } = ChromeUtils.importESModule( |
| 8 | + "resource://gre/modules/XPCOMUtils.sys.mjs" |
| 9 | +); |
| 10 | + |
| 11 | +ChromeUtils.defineESModuleGetters(lazy, { |
| 12 | + AboutWelcomeParent: "resource:///actors/AboutWelcomeParent.sys.mjs", |
| 13 | +}); |
| 14 | + |
| 15 | +XPCOMUtils.defineLazyPreferenceGetter( |
| 16 | + lazy, |
| 17 | + "onboardingConfig", |
| 18 | + "browser.smartwindow.onboarding.config", |
| 19 | + JSON.stringify({ |
| 20 | + id: "smart-window-welcome", |
| 21 | + template: "spotlight", |
| 22 | + modal: "tab", |
| 23 | + transitions: true, |
| 24 | + backdrop: "linear-gradient(0deg, #D9C7F8 0%, #F6EEFC 102.21%)", |
| 25 | + screens: [ |
| 26 | + { |
| 27 | + id: "welcome_screen", |
| 28 | + auto_advance: "additional_button", |
| 29 | + content: { |
| 30 | + fullscreen: true, |
| 31 | + hide_secondary_section: "responsive", |
| 32 | + narrow: true, |
| 33 | + position: "split", |
| 34 | + title: { |
| 35 | + fontWeight: 600, |
| 36 | + fontSize: "55px", |
| 37 | + width: "800px", |
| 38 | + textAlign: "center", |
| 39 | + raw: "Welcome to Smart Window", |
| 40 | + }, |
| 41 | + title_style: "fancy shine", |
| 42 | + text_color: "dark", |
| 43 | + primary_button: { |
| 44 | + label: "Next", |
| 45 | + action: { |
| 46 | + navigate: true |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + { |
| 52 | + id: "CHOOSE_MODEL", |
| 53 | + content: { |
| 54 | + position: "center", |
| 55 | + screen_style: { |
| 56 | + width: "650px", |
| 57 | + height: "500px", |
| 58 | + }, |
| 59 | + title: { |
| 60 | + raw: "Pick a model to start", |
| 61 | + }, |
| 62 | + subtitle: { |
| 63 | + raw: "You can switch anytime - and trying a few helps you find the best fit.", |
| 64 | + }, |
| 65 | + tiles: { |
| 66 | + type: "single-select", |
| 67 | + autoTrigger: false, |
| 68 | + action: { |
| 69 | + picker: "<event>", |
| 70 | + }, |
| 71 | + data: [ |
| 72 | + { |
| 73 | + id: "model_1", |
| 74 | + label: { |
| 75 | + raw: "Fast & Clear", |
| 76 | + fontSize: 17, |
| 77 | + fontWeight: 600, |
| 78 | + }, |
| 79 | + body: { |
| 80 | + raw: "Quick answer to everyday questions", |
| 81 | + color: "var(--text-color-deemphasized)", |
| 82 | + }, |
| 83 | + }, |
| 84 | + { |
| 85 | + id: "model_2", |
| 86 | + label: { |
| 87 | + raw: "Fast & Clear", |
| 88 | + fontSize: 17, |
| 89 | + fontWeight: 600, |
| 90 | + }, |
| 91 | + body: { |
| 92 | + raw: "Quick answer to everyday questions", |
| 93 | + color: "var(--text-color-deemphasized)", |
| 94 | + }, |
| 95 | + }, |
| 96 | + { |
| 97 | + id: "model_3", |
| 98 | + label: { |
| 99 | + raw: "Fast & Clear", |
| 100 | + fontSize: 17, |
| 101 | + fontWeight: 600, |
| 102 | + }, |
| 103 | + body: { |
| 104 | + raw: "Quick answer to everyday questions", |
| 105 | + color: "var(--text-color-deemphasized)", |
| 106 | + }, |
| 107 | + } |
| 108 | + ] |
| 109 | + }, |
| 110 | + primary_button: { |
| 111 | + label: { |
| 112 | + raw: "Next" |
| 113 | + }, |
| 114 | + action: { |
| 115 | + navigate: true |
| 116 | + } |
| 117 | + }, |
| 118 | + } |
| 119 | + }, |
| 120 | + { |
| 121 | + id: "APPLY_INSIGHTS", |
| 122 | + content: { |
| 123 | + position: "center", |
| 124 | + screen_style: { |
| 125 | + width: "650px", |
| 126 | + height: "500px", |
| 127 | + }, |
| 128 | + title: { |
| 129 | + raw: "Smarter browsing starts now", |
| 130 | + }, |
| 131 | + subtitle: { |
| 132 | + raw: "Get personalized answers fast. Compare info across tabs. Find what you need in your history in your words, not keywords.", |
| 133 | + }, |
| 134 | + above_button_content: [ |
| 135 | + { |
| 136 | + type: "image", |
| 137 | + url: "chrome://browser/content/smartwindow/insights.png", |
| 138 | + width: "500px", |
| 139 | + height: "200px" |
| 140 | + } |
| 141 | + ], |
| 142 | + primary_button: { |
| 143 | + label: { |
| 144 | + raw: "Back" |
| 145 | + }, |
| 146 | + action: { |
| 147 | + navigate: true, |
| 148 | + goBack: true |
| 149 | + } |
| 150 | + }, |
| 151 | + additional_button: { |
| 152 | + label: "Let's Go", |
| 153 | + style: "primary", |
| 154 | + flow: "row", |
| 155 | + action: { |
| 156 | + navigate: true |
| 157 | + } |
| 158 | + }, |
| 159 | + } |
| 160 | + } |
| 161 | + ], |
| 162 | + }) |
| 163 | +); |
| 164 | + |
| 165 | +function addStylesheet(href) { |
| 166 | + const link = document.head.appendChild(document.createElement("link")); |
| 167 | + link.rel = "stylesheet"; |
| 168 | + link.href = href; |
| 169 | +} |
| 170 | + |
| 171 | +function renderMultistage(ready) { |
| 172 | + const AWParent = new lazy.AboutWelcomeParent(); |
| 173 | + const receive = name => data => |
| 174 | + AWParent.onContentMessage( |
| 175 | + `AWPage:${name}`, |
| 176 | + data, |
| 177 | + topChromeWindow.gBrowser.selectedBrowser |
| 178 | + ); |
| 179 | + |
| 180 | + // Expose top level functions expected by the bundle. |
| 181 | + window.AWGetFeatureConfig = () => JSON.parse(lazy.onboardingConfig); |
| 182 | + window.AWGetSelectedTheme = receive("GET_SELECTED_THEME"); |
| 183 | + window.AWGetInstalledAddons = receive("GET_INSTALLED_ADDONS"); |
| 184 | + window.AWSelectTheme = data => receive("SELECT_THEME")(data?.toUpperCase()); |
| 185 | + window.AWSendEventTelemetry = receive("TELEMETRY_EVENT"); |
| 186 | + |
| 187 | + window.AWSendToDeviceEmailsSupported = receive( |
| 188 | + "SEND_TO_DEVICE_EMAILS_SUPPORTED" |
| 189 | + ); |
| 190 | + window.AWAddScreenImpression = receive("ADD_SCREEN_IMPRESSION"); |
| 191 | + window.AWSendToParent = (name, data) => receive(name)(data); |
| 192 | + window.AWFinish = () => { |
| 193 | + window.close(); |
| 194 | + }; |
| 195 | + window.AWWaitForMigrationClose = receive("WAIT_FOR_MIGRATION_CLOSE"); |
| 196 | + window.AWEvaluateScreenTargeting = receive("EVALUATE_SCREEN_TARGETING"); |
| 197 | + window.AWEvaluateAttributeTargeting = receive("EVALUATE_ATTRIBUTE_TARGETING"); |
| 198 | + |
| 199 | + // Update styling to be compatible with about:welcome. |
| 200 | + addStylesheet("chrome://browser/content/aboutwelcome/aboutwelcome.css"); |
| 201 | + |
| 202 | + document.body.classList.add("onboardingContainer"); |
| 203 | + document.body.id = "multi-stage-message-root"; |
| 204 | + // This value is reported as the "page" in telemetry |
| 205 | + document.body.dataset.page = "smart-window-welcome"; |
| 206 | + const bundleScript = document.head.appendChild( |
| 207 | + document.createElement("script") |
| 208 | + ); |
| 209 | + bundleScript.src = |
| 210 | + "chrome://browser/content/aboutwelcome/aboutwelcome.bundle.js"; |
| 211 | + |
| 212 | + ready(); |
| 213 | +} |
| 214 | + |
| 215 | +// Initialize when DOM is ready |
| 216 | +if (document.readyState === "loading") { |
| 217 | + document.addEventListener( |
| 218 | + "DOMContentLoaded", |
| 219 | + () => renderMultistage(() => { }), |
| 220 | + { once: true } |
| 221 | + ); |
| 222 | +} else { |
| 223 | + renderMultistage(() => { }); |
| 224 | +} |
0 commit comments