Skip to content

Commit 46c4e0c

Browse files
committed
Bug 1877295 - Toolbar button option for returning to about:welcome r=pdahiya,fluent-reviewers,Gijs,desktop-theme-reviewers,omc-reviewers,bolsson
Differential Revision: https://phabricator.services.mozilla.com/D199934
1 parent d94ba2c commit 46c4e0c

File tree

15 files changed

+216
-3
lines changed

15 files changed

+216
-3
lines changed

browser/base/content/browser.xhtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
<link rel="localization" href="browser/shopping.ftl"/>
100100
<link rel="localization" href="preview/shopping.ftl"/>
101101
<link rel="localization" href="preview/profiles.ftl"/>
102+
<link rel="localization" href="preview/onboarding.ftl"/>
102103

103104
<title data-l10n-id="browser-main-window-title"></title>
104105

browser/components/BrowserGlue.sys.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const lazy = {};
99

1010
ChromeUtils.defineESModuleGetters(lazy, {
1111
AboutNewTab: "resource:///modules/AboutNewTab.sys.mjs",
12+
AWToolbarButton: "resource:///modules/aboutwelcome/AWToolbarUtils.sys.mjs",
1213
ASRouter: "resource:///modules/asrouter/ASRouter.sys.mjs",
1314
ASRouterDefaultConfig:
1415
"resource:///modules/asrouter/ASRouterDefaultConfig.sys.mjs",
@@ -2951,6 +2952,20 @@ BrowserGlue.prototype = {
29512952
},
29522953
},
29532954

2955+
// Add the setup button if this is the first startup
2956+
{
2957+
name: "AWToolbarButton.SetupButton",
2958+
task: async () => {
2959+
if (
2960+
lazy.AWToolbarButton.hasToolbarButtonEnabled &&
2961+
// Not in automation: the button changes CUI state, breaking tests
2962+
!Cu.isInAutomation
2963+
) {
2964+
await lazy.AWToolbarButton.maybeAddSetupButton();
2965+
}
2966+
},
2967+
},
2968+
29542969
{
29552970
name: "ASRouterNewTabHook.createInstance",
29562971
task: () => {

browser/components/aboutwelcome/actors/AboutWelcomeChild.sys.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ ChromeUtils.defineLazyGetter(lazy, "log", () => {
2020
return new Logger("AboutWelcomeChild");
2121
});
2222

23+
const DID_SEE_FINAL_SCREEN_PREF = "browser.aboutwelcome.didSeeFinalScreen";
24+
25+
XPCOMUtils.defineLazyPreferenceGetter(
26+
lazy,
27+
"toolbarEntrypoint",
28+
"browser.aboutwelcome.entrypoint",
29+
""
30+
);
31+
2332
export class AboutWelcomeChild extends JSWindowActorChild {
2433
// Can be used to avoid accesses to the document/contentWindow after it's
2534
// destroyed, which may throw unhandled exceptions.
@@ -233,6 +242,9 @@ export class AboutWelcomeChild extends JSWindowActorChild {
233242
* @param {object} eventData
234243
*/
235244
AWSendEventTelemetry(eventData) {
245+
if (lazy.toolbarEntrypoint) {
246+
eventData.event_context.entrypoint = lazy.toolbarEntrypoint;
247+
}
236248
this.AWSendToParent("TELEMETRY_EVENT", {
237249
...eventData,
238250
event_context: {
@@ -256,10 +268,24 @@ export class AboutWelcomeChild extends JSWindowActorChild {
256268
return this.wrapPromise(this.sendQuery("AWPage:WAIT_FOR_MIGRATION_CLOSE"));
257269
}
258270

271+
setDidSeeFinalScreen() {
272+
this.AWSendToParent("SPECIAL_ACTION", {
273+
type: "SET_PREF",
274+
data: {
275+
pref: {
276+
name: DID_SEE_FINAL_SCREEN_PREF,
277+
value: true,
278+
},
279+
},
280+
});
281+
}
282+
259283
AWFinish() {
260284
const shouldFocusNewtabUrlBar =
261285
lazy.NimbusFeatures.aboutwelcome.getVariable("newtabUrlBarFocus");
262286

287+
this.setDidSeeFinalScreen();
288+
263289
this.contentWindow.location.href = "about:home";
264290
if (shouldFocusNewtabUrlBar) {
265291
this.AWSendToParent("SPECIAL_ACTION", {

browser/components/aboutwelcome/actors/AboutWelcomeParent.sys.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class AboutWelcomeObserver {
8585

8686
stop() {
8787
lazy.log.debug(`Terminate reason is ${this.terminateReason}`);
88+
// Clear the entrypoint pref
89+
Services.prefs.clearUserPref("browser.aboutwelcome.entrypoint");
8890
Services.obs.removeObserver(this, "quit-application");
8991
if (!this.win) {
9092
return;

browser/components/aboutwelcome/content/onboarding.ftl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ amo-picker-subtitle = Extensions are like apps for your browser, and they let yo
1919
amo-picker-install-button-label = Add to { -brand-short-name }
2020
amo-picker-install-complete-label = Installed
2121
amo-picker-collection-link = Explore more add-ons
22+
23+
# Button label for the experimental return to about:welcome toolbar button
24+
browser-aboutwelcome-button =
25+
.label = Finish setup
26+
.tooltiptext = Finish setting up { -brand-short-name }.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
6+
7+
const lazy = {};
8+
9+
ChromeUtils.defineESModuleGetters(lazy, {
10+
CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs",
11+
});
12+
13+
export const AWToolbarButton = {
14+
async maybeAddSetupButton() {
15+
// First check if we've already completed onboarding, in which
16+
// case we should remove the button.
17+
if (AWToolbarButton.didSeeFinalScreen) {
18+
AWToolbarButton.removeSetupButtonIfOnboardingComplete();
19+
return;
20+
}
21+
// Otherwise, check if this is a new profile where we need to add it.
22+
if (AWToolbarButton.hasToolbarButtonEnabled) {
23+
lazy.CustomizableUI.createWidget({
24+
id: "aboutwelcome-button",
25+
l10nId: "browser-aboutwelcome-button",
26+
defaultArea: lazy.CustomizableUI.AREA_BOOKMARKS,
27+
type: "button",
28+
onCreated(aNode) {
29+
aNode.className = "bookmark-item chromeclass-toolbar-additional";
30+
},
31+
onClick(aEvent) {
32+
AWToolbarButton.openWelcome(aEvent.view);
33+
},
34+
});
35+
}
36+
},
37+
38+
removeSetupButtonIfOnboardingComplete() {
39+
//Look for completion of Onboarding (we're using an AWFinish()
40+
//call from about:welcome as a proxy here)
41+
if (
42+
AWToolbarButton.didSeeFinalScreen ||
43+
!AWToolbarButton.hasToolbarButtonEnabled
44+
) {
45+
lazy.CustomizableUI.destroyWidget("aboutwelcome-button");
46+
}
47+
},
48+
49+
openWelcome(win) {
50+
Services.prefs.setStringPref(
51+
"browser.aboutwelcome.entrypoint",
52+
"toolbarButton"
53+
);
54+
let viewURL = "about:welcome";
55+
win.gBrowser.addTrustedTab(viewURL, {
56+
inBackground: false,
57+
});
58+
},
59+
};
60+
61+
XPCOMUtils.defineLazyPreferenceGetter(
62+
AWToolbarButton,
63+
"didSeeFinalScreen",
64+
"browser.aboutwelcome.didSeeFinalScreen",
65+
false,
66+
() => {
67+
AWToolbarButton.removeSetupButtonIfOnboardingComplete();
68+
}
69+
);
70+
71+
XPCOMUtils.defineLazyPreferenceGetter(
72+
AWToolbarButton,
73+
"hasToolbarButtonEnabled",
74+
"browser.aboutwelcome.toolbarButtonEnabled",
75+
false,
76+
() => {
77+
AWToolbarButton.removeSetupButtonIfOnboardingComplete();
78+
}
79+
);

browser/components/aboutwelcome/moz.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ EXTRA_JS_MODULES.aboutwelcome += [
2222
"modules/AboutWelcomeDefaults.sys.mjs",
2323
"modules/AboutWelcomeTelemetry.sys.mjs",
2424
"modules/AWScreenUtils.sys.mjs",
25+
"modules/AWToolbarUtils.sys.mjs",
2526
]
2627

2728
XPCSHELL_TESTS_MANIFESTS += [

browser/components/aboutwelcome/tests/browser/browser.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ skip-if = ["os == 'linux' && bits == 64"] # Bug 1757875
3737
["browser_aboutwelcome_multistage_mr.js"]
3838
skip-if = ["os == 'linux' && bits == 64 && debug"] # Bug 1812050
3939

40+
["browser_aboutwelcome_multistage_transitions.js"]
41+
skip-if = ["debug"] # Bug 1875203
42+
4043
["browser_aboutwelcome_multistage_video.js"]
4144

4245
["browser_aboutwelcome_observer.js"]
@@ -50,11 +53,10 @@ skip-if = [
5053

5154
["browser_aboutwelcome_screen_targeting.js"]
5255

56+
["browser_aboutwelcome_toolbar_button.js"]
57+
5358
["browser_aboutwelcome_upgrade_multistage_mr.js"]
5459
skip-if = [
5560
"win11_2009 && debug",
5661
"os == 'linux' && debug", # Bug 1804804 - disabled on win && linux for extremely high failure rate
5762
]
58-
59-
["browser_aboutwelcome_multistage_transitions.js"]
60-
skip-if = ["debug"] # Bug 1875203
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"use strict";
2+
3+
const { AboutWelcomeTelemetry } = ChromeUtils.importESModule(
4+
"resource:///modules/aboutwelcome/AboutWelcomeTelemetry.sys.mjs"
5+
);
6+
const { AWToolbarButton } = ChromeUtils.importESModule(
7+
"resource:///modules/aboutwelcome/AWToolbarUtils.sys.mjs"
8+
);
9+
10+
const TOOLBAR_PREF = "browser.aboutwelcome.toolbarButtonEnabled";
11+
const DID_SEE_FINAL_SCREEN_PREF = "browser.aboutwelcome.didSeeFinalScreen";
12+
13+
async function openNewTab() {
14+
let tab = await BrowserTestUtils.openNewForegroundTab(
15+
gBrowser,
16+
"about:newtab",
17+
false
18+
);
19+
20+
registerCleanupFunction(async () => {
21+
BrowserTestUtils.removeTab(tab);
22+
await SpecialPowers.popPrefEnv();
23+
});
24+
25+
return tab.linkedBrowser;
26+
}
27+
28+
add_task(async function test_add_and_remove_toolbar_button() {
29+
// Clear the final screen pref, which may have been set by other tests
30+
await SpecialPowers.pushPrefEnv({
31+
set: [[DID_SEE_FINAL_SCREEN_PREF, false]],
32+
});
33+
// Open newtab
34+
let win = await BrowserTestUtils.openNewBrowserWindow();
35+
win.BrowserOpenTab();
36+
ok(win, "browser exists");
37+
// Try to add the button. It shouldn't add because the pref is false
38+
await AWToolbarButton.maybeAddSetupButton();
39+
ok(
40+
!win.document.getElementById("aboutwelcome-button"),
41+
"Button should not exist"
42+
);
43+
// Set the pref and try again
44+
await SpecialPowers.pushPrefEnv({
45+
set: [[TOOLBAR_PREF, true]],
46+
});
47+
await AWToolbarButton.maybeAddSetupButton();
48+
// The button should exist
49+
ok(
50+
win.document.getElementById("aboutwelcome-button"),
51+
"Button should be added."
52+
);
53+
// Switch the pref to false and check again
54+
await SpecialPowers.pushPrefEnv({
55+
set: [[TOOLBAR_PREF, false]],
56+
});
57+
ok(
58+
!win.document.getElementById("aboutwelcome-button"),
59+
"Button should be removed"
60+
);
61+
// Cleanup
62+
await SpecialPowers.popPrefEnv();
63+
await BrowserTestUtils.closeWindow(win);
64+
});
Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)