@@ -12,8 +12,13 @@ const lazy = {};
12
12
13
13
XPCOMUtils . defineLazyModuleGetters ( lazy , {
14
14
AboutWelcomeParent : "resource:///actors/AboutWelcomeParent.jsm" ,
15
+ ASRouter : "resource://activity-stream/lib/ASRouter.jsm" ,
15
16
} ) ;
16
17
18
+ // When expanding the use of Feature Callout
19
+ // to new about: pages, make `progressPref` a
20
+ // configurable field on callout messages and
21
+ // use it to determine which pref to observe
17
22
XPCOMUtils . defineLazyPreferenceGetter (
18
23
lazy ,
19
24
"featureTourProgress" ,
@@ -36,7 +41,7 @@ async function _handlePrefChange() {
36
41
container ?. classList . add ( "hidden" ) ;
37
42
// wait for fade out transition
38
43
setTimeout ( async ( ) => {
39
- _loadConfig ( lazy . featureTourProgress . message ) ;
44
+ await _loadConfig ( ) ;
40
45
container ?. remove ( ) ;
41
46
await _renderCallout ( ) ;
42
47
} , TRANSITION_MS ) ;
@@ -78,170 +83,6 @@ let READY = false;
78
83
79
84
const TRANSITION_MS = 500 ;
80
85
const CONTAINER_ID = "root" ;
81
- const MESSAGES = [
82
- {
83
- id : "FIREFOX_VIEW_FEATURE_TOUR" ,
84
- template : "multistage" ,
85
- backdrop : "transparent" ,
86
- transitions : false ,
87
- disableHistoryUpdates : true ,
88
- screens : [
89
- {
90
- id : "FEATURE_CALLOUT_1" ,
91
- parent_selector : "#tabpickup-steps" ,
92
- content : {
93
- position : "callout" ,
94
- arrow_position : "top" ,
95
- title : {
96
- string_id : "callout-firefox-view-tab-pickup-title" ,
97
- } ,
98
- subtitle : {
99
- string_id : "callout-firefox-view-tab-pickup-subtitle" ,
100
- } ,
101
- logo : {
102
- imageURL : "chrome://browser/content/callout-tab-pickup.svg" ,
103
- darkModeImageURL :
104
- "chrome://browser/content/callout-tab-pickup-dark.svg" ,
105
- height : "128px" ,
106
- } ,
107
- primary_button : {
108
- label : {
109
- string_id : "callout-primary-advance-button-label" ,
110
- } ,
111
- action : {
112
- type : "SET_PREF" ,
113
- data : {
114
- pref : {
115
- name : "browser.firefox-view.feature-tour" ,
116
- value : JSON . stringify ( {
117
- message : "FIREFOX_VIEW_FEATURE_TOUR" ,
118
- screen : "FEATURE_CALLOUT_2" ,
119
- complete : false ,
120
- } ) ,
121
- } ,
122
- } ,
123
- } ,
124
- } ,
125
- dismiss_button : {
126
- action : {
127
- type : "SET_PREF" ,
128
- data : {
129
- pref : {
130
- name : "browser.firefox-view.feature-tour" ,
131
- value : JSON . stringify ( {
132
- message : "FIREFOX_VIEW_FEATURE_TOUR" ,
133
- screen : "FEATURE_CALLOUT_1" ,
134
- complete : true ,
135
- } ) ,
136
- } ,
137
- } ,
138
- } ,
139
- } ,
140
- } ,
141
- } ,
142
- {
143
- id : "FEATURE_CALLOUT_2" ,
144
- parent_selector : "#recently-closed-tabs-container" ,
145
- content : {
146
- position : "callout" ,
147
- arrow_position : "bottom" ,
148
- title : {
149
- string_id : "callout-firefox-view-recently-closed-title" ,
150
- } ,
151
- subtitle : {
152
- string_id : "callout-firefox-view-recently-closed-subtitle" ,
153
- } ,
154
- primary_button : {
155
- label : {
156
- string_id : "callout-primary-advance-button-label" ,
157
- } ,
158
- action : {
159
- type : "SET_PREF" ,
160
- data : {
161
- pref : {
162
- name : "browser.firefox-view.feature-tour" ,
163
- value : JSON . stringify ( {
164
- message : "FIREFOX_VIEW_FEATURE_TOUR" ,
165
- screen : "FEATURE_CALLOUT_3" ,
166
- complete : false ,
167
- } ) ,
168
- } ,
169
- } ,
170
- } ,
171
- } ,
172
- dismiss_button : {
173
- action : {
174
- type : "SET_PREF" ,
175
- data : {
176
- pref : {
177
- name : "browser.firefox-view.feature-tour" ,
178
- value : JSON . stringify ( {
179
- message : "FIREFOX_VIEW_FEATURE_TOUR" ,
180
- screen : "FEATURE_CALLOUT_2" ,
181
- complete : true ,
182
- } ) ,
183
- } ,
184
- } ,
185
- } ,
186
- } ,
187
- } ,
188
- } ,
189
- {
190
- id : "FEATURE_CALLOUT_3" ,
191
- parent_selector : "#colorways.content-container" ,
192
- content : {
193
- position : "callout" ,
194
- arrow_position : "end" ,
195
- title : {
196
- string_id : "callout-firefox-view-colorways-title" ,
197
- } ,
198
- subtitle : {
199
- string_id : "callout-firefox-view-colorways-subtitle" ,
200
- } ,
201
- logo : {
202
- imageURL : "chrome://browser/content/callout-colorways.svg" ,
203
- darkModeImageURL :
204
- "chrome://browser/content/callout-colorways-dark.svg" ,
205
- height : "128px" ,
206
- } ,
207
- primary_button : {
208
- label : {
209
- string_id : "callout-primary-complete-button-label" ,
210
- } ,
211
- action : {
212
- type : "SET_PREF" ,
213
- data : {
214
- pref : {
215
- name : "browser.firefox-view.feature-tour" ,
216
- value : JSON . stringify ( {
217
- message : "FIREFOX_VIEW_FEATURE_TOUR" ,
218
- screen : "" ,
219
- complete : true ,
220
- } ) ,
221
- } ,
222
- } ,
223
- } ,
224
- } ,
225
- dismiss_button : {
226
- action : {
227
- type : "SET_PREF" ,
228
- data : {
229
- pref : {
230
- name : "browser.firefox-view.feature-tour" ,
231
- value : JSON . stringify ( {
232
- message : "FIREFOX_VIEW_FEATURE_TOUR" ,
233
- screen : "FEATURE_CALLOUT_3" ,
234
- complete : true ,
235
- } ) ,
236
- } ,
237
- } ,
238
- } ,
239
- } ,
240
- } ,
241
- } ,
242
- ] ,
243
- } ,
244
- ] ;
245
86
246
87
function _createContainer ( ) {
247
88
let container = document . createElement ( "div" ) ;
@@ -253,6 +94,10 @@ function _createContainer() {
253
94
) ;
254
95
container . id = CONTAINER_ID ;
255
96
let parent = document . querySelector ( CURRENT_SCREEN ?. parent_selector ) ;
97
+ if ( ! parent ) {
98
+ container . remove ( ) ;
99
+ return false ;
100
+ }
256
101
container . setAttribute ( "aria-describedby" , `#${ CONTAINER_ID } .welcome-text` ) ;
257
102
container . tabIndex = 0 ;
258
103
parent . insertAdjacentElement ( "afterend" , container ) ;
@@ -504,38 +349,24 @@ function _observeRender(container) {
504
349
RENDER_OBSERVER ?. observe ( container , { childList : true } ) ;
505
350
}
506
351
507
- function _loadConfig ( messageId ) {
508
- // If the parent element a screen describes doesn't exist, remove screen
509
- // and ensure last screen displays the final primary CTA
510
- // (for example, when there are no active colorways in about:firefoxview)
511
- function _getRelevantScreens ( screens ) {
512
- const finalCTA = screens [ screens . length - 1 ] . content . primary_button ;
513
- screens = screens . filter ( ( s , i ) => {
514
- return document . querySelector ( s . parent_selector ) ;
515
- } ) ;
516
- if ( screens . length ) {
517
- screens [ screens . length - 1 ] . content . primary_button = finalCTA ;
518
- }
519
- return screens ;
520
- }
521
-
522
- let content = MESSAGES . find ( m => m . id === messageId ) ;
523
- const screenId = lazy . featureTourProgress . screen ;
524
- let screenIndex ;
525
- if ( content ?. screens ?. length && screenId ) {
526
- content . screens = _getRelevantScreens ( content . screens ) ;
527
- screenIndex = content . screens . findIndex ( s => s . id === screenId ) ;
528
- content . startScreen = screenIndex ;
529
- }
530
- CURRENT_SCREEN = content ?. screens ?. [ screenIndex || 0 ] ;
531
- CONFIG = content ;
352
+ async function _loadConfig ( ) {
353
+ await lazy . ASRouter . waitForInitialized ;
354
+ let result = await lazy . ASRouter . sendTriggerMessage ( {
355
+ // triggerId and triggerContext
356
+ id : "featureCalloutCheck" ,
357
+ context : { source : document . location . pathname . toLowerCase ( ) } ,
358
+ } ) ;
359
+ CONFIG = result . message . content ;
360
+ CURRENT_SCREEN = CONFIG ?. screens ?. [ CONFIG ?. startScreen || 0 ] ;
532
361
}
533
362
534
363
async function _renderCallout ( ) {
535
364
let container = _createContainer ( ) ;
536
- // This results in rendering the Feature Callout
537
- await _addScriptsAndRender ( container ) ;
538
- _observeRender ( container ) ;
365
+ if ( container ) {
366
+ // This results in rendering the Feature Callout
367
+ await _addScriptsAndRender ( container ) ;
368
+ _observeRender ( container ) ;
369
+ }
539
370
}
540
371
/**
541
372
* Render content based on about:welcome multistage template.
@@ -546,9 +377,9 @@ async function showFeatureCallout(messageId) {
546
377
return ;
547
378
}
548
379
549
- _loadConfig ( messageId ) ;
380
+ await _loadConfig ( ) ;
550
381
551
- if ( ! CONFIG ) {
382
+ if ( ! CONFIG ?. screens ?. length ) {
552
383
return ;
553
384
}
554
385
0 commit comments