Skip to content

Commit 6649a57

Browse files
committed
Bug 1751010: Create a separate jumplist for the Private Browsing taskbar icon. r=mhowell
Because the Private Browsing Jump List only contains Tasks it is static we can get away with only building it once. Differential Revision: https://phabricator.services.mozilla.com/D138600
1 parent 119452b commit 6649a57

File tree

6 files changed

+162
-111
lines changed

6 files changed

+162
-111
lines changed

browser/modules/WindowsJumpLists.jsm

Lines changed: 133 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -141,52 +141,34 @@ let privateWindowTask = {
141141

142142
// Implementation
143143

144-
var WinTaskbarJumpList = {
145-
_builder: null,
146-
_tasks: null,
147-
_shuttingDown: false,
148-
149-
/**
150-
* Startup, shutdown, and update
151-
*/
152-
153-
startup: function WTBJL_startup() {
154-
// exit if this isn't win7 or higher.
155-
if (!this._initTaskbar()) {
156-
return;
157-
}
158-
159-
// Store our task list config data
160-
this._tasks = tasksCfg;
161-
162-
if (PrivateBrowsingUtils.enabled) {
163-
tasksCfg.push(privateWindowTask);
164-
}
165-
166-
// retrieve taskbar related prefs.
167-
this._refreshPrefs();
168-
169-
// observer for private browsing and our prefs branch
170-
this._initObs();
171-
172-
// jump list refresh timer
173-
this._updateTimer();
174-
},
175-
176-
update: function WTBJL_update() {
177-
// are we disabled via prefs? don't do anything!
178-
if (!this._enabled) {
179-
return;
180-
}
181-
182-
// do what we came here to do, update the taskbar jumplist
183-
this._buildList();
184-
},
185-
186-
_shutdown: function WTBJL__shutdown() {
187-
this._shuttingDown = true;
188-
this._free();
189-
},
144+
var Builder = class {
145+
constructor(builder) {
146+
this._builder = builder;
147+
this._tasks = null;
148+
this._pendingStatements = {};
149+
this._shuttingDown = false;
150+
// These are ultimately controlled by prefs, so we disable
151+
// everything until is read from there
152+
this._showTasks = false;
153+
this._showFrequent = false;
154+
this._showRecent = false;
155+
this._maxItemCount = 0;
156+
}
157+
158+
refreshPrefs(showTasks, showFrequent, showRecent, maxItemCount) {
159+
this._showTasks = showTasks;
160+
this._showFrequent = showFrequent;
161+
this._showRecent = showRecent;
162+
this._maxItemCount = maxItemCount;
163+
}
164+
165+
updateShutdownState(shuttingDown) {
166+
this._shuttingDown = shuttingDown;
167+
}
168+
169+
delete() {
170+
delete this._builder;
171+
}
190172

191173
/**
192174
* List building
@@ -198,13 +180,15 @@ var WinTaskbarJumpList = {
198180
* commitBuild() will commit for real.
199181
*/
200182

201-
_pendingStatements: {},
202-
_hasPendingStatements: function WTBJL__hasPendingStatements() {
183+
_hasPendingStatements() {
203184
return !!Object.keys(this._pendingStatements).length;
204-
},
185+
}
205186

206-
async _buildList() {
207-
if (this._hasPendingStatements()) {
187+
async buildList() {
188+
if (
189+
(this._showFrequent || this._showRecent) &&
190+
this._hasPendingStatements()
191+
) {
208192
// We were requested to update the list while another update was in
209193
// progress, this could happen at shutdown, idle or privatebrowsing.
210194
// Abort the current list building.
@@ -238,7 +222,7 @@ var WinTaskbarJumpList = {
238222
}
239223

240224
this._commitBuild();
241-
},
225+
}
242226

243227
/**
244228
* Taskbar api wrappers
@@ -251,10 +235,13 @@ var WinTaskbarJumpList = {
251235
// Prior to building, delete removed items from history.
252236
this._clearHistory(URIsToRemove);
253237
}
254-
},
238+
}
255239

256-
_commitBuild: function WTBJL__commitBuild() {
257-
if (this._hasPendingStatements()) {
240+
_commitBuild() {
241+
if (
242+
(this._showFrequent || this._showRecent) &&
243+
this._hasPendingStatements()
244+
) {
258245
return;
259246
}
260247

@@ -263,9 +250,9 @@ var WinTaskbarJumpList = {
263250
this._builder.abortListBuild();
264251
}
265252
});
266-
},
253+
}
267254

268-
_buildTasks: function WTBJL__buildTasks() {
255+
_buildTasks() {
269256
var items = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
270257
this._tasks.forEach(function(task) {
271258
if (
@@ -290,19 +277,19 @@ var WinTaskbarJumpList = {
290277
items
291278
);
292279
}
293-
},
280+
}
294281

295-
_buildCustom: function WTBJL__buildCustom(title, items) {
282+
_buildCustom(title, items) {
296283
if (items.length) {
297284
this._builder.addListToBuild(
298285
this._builder.JUMPLIST_CATEGORY_CUSTOMLIST,
299286
items,
300287
title
301288
);
302289
}
303-
},
290+
}
304291

305-
_buildFrequent: function WTBJL__buildFrequent() {
292+
_buildFrequent() {
306293
// Windows supports default frequent and recent lists,
307294
// but those depend on internal windows visit tracking
308295
// which we don't populate. So we build our own custom
@@ -339,9 +326,9 @@ var WinTaskbarJumpList = {
339326
},
340327
this
341328
);
342-
},
329+
}
343330

344-
_buildRecent: function WTBJL__buildRecent() {
331+
_buildRecent() {
345332
var items = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
346333
// Frequent items will be skipped, so we select a double amount of
347334
// entries and stop fetching results at _maxItemCount.
@@ -385,23 +372,17 @@ var WinTaskbarJumpList = {
385372
},
386373
this
387374
);
388-
},
375+
}
389376

390-
_deleteActiveJumpList: function WTBJL__deleteAJL() {
377+
_deleteActiveJumpList() {
391378
this._builder.deleteActiveList();
392-
},
379+
}
393380

394381
/**
395382
* Jump list item creation helpers
396383
*/
397384

398-
_getHandlerAppItem: function WTBJL__getHandlerAppItem(
399-
name,
400-
description,
401-
args,
402-
iconIndex,
403-
faviconPageUri
404-
) {
385+
_getHandlerAppItem(name, description, args, iconIndex, faviconPageUri) {
405386
var file = Services.dirsvc.get("XREExeF", Ci.nsIFile);
406387

407388
var handlerApp = Cc[
@@ -422,25 +403,13 @@ var WinTaskbarJumpList = {
422403
item.iconIndex = iconIndex;
423404
item.faviconPageUri = faviconPageUri;
424405
return item;
425-
},
426-
427-
_getSeparatorItem: function WTBJL__getSeparatorItem() {
428-
var item = Cc["@mozilla.org/windows-jumplistseparator;1"].createInstance(
429-
Ci.nsIJumpListSeparator
430-
);
431-
return item;
432-
},
406+
}
433407

434408
/**
435409
* Nav history helpers
436410
*/
437411

438-
_getHistoryResults: function WTBLJL__getHistoryResults(
439-
aSortingMode,
440-
aLimit,
441-
aCallback,
442-
aScope
443-
) {
412+
_getHistoryResults(aSortingMode, aLimit, aCallback, aScope) {
444413
var options = PlacesUtils.history.getNewQueryOptions();
445414
options.maxResults = aLimit;
446415
options.sortingMode = aSortingMode;
@@ -464,12 +433,12 @@ var WinTaskbarJumpList = {
464433
);
465434
},
466435
handleCompletion(aReason) {
467-
aCallback.call(WinTaskbarJumpList, null);
436+
aCallback.call(aScope, null);
468437
},
469438
});
470-
},
439+
}
471440

472-
_clearHistory: function WTBJL__clearHistory(uriSpecsToRemove) {
441+
_clearHistory(uriSpecsToRemove) {
473442
let URIsToRemove = uriSpecsToRemove
474443
.map(spec => {
475444
try {
@@ -484,6 +453,61 @@ var WinTaskbarJumpList = {
484453
if (URIsToRemove.length) {
485454
PlacesUtils.history.remove(URIsToRemove).catch(Cu.reportError);
486455
}
456+
}
457+
};
458+
459+
var WinTaskbarJumpList = {
460+
// We build two separate jump lists -- one for the regular Firefox icon
461+
// and one for the Private Browsing icon
462+
_builder: null,
463+
_pbBuilder: null,
464+
_shuttingDown: false,
465+
466+
/**
467+
* Startup, shutdown, and update
468+
*/
469+
470+
startup: function WTBJL_startup() {
471+
// exit if this isn't win7 or higher.
472+
if (!this._initTaskbar()) {
473+
return;
474+
}
475+
476+
if (PrivateBrowsingUtils.enabled) {
477+
tasksCfg.push(privateWindowTask);
478+
}
479+
// Store our task list config data
480+
this._builder._tasks = tasksCfg;
481+
this._pbBuilder._tasks = tasksCfg;
482+
483+
// retrieve taskbar related prefs.
484+
this._refreshPrefs();
485+
486+
// observer for private browsing and our prefs branch
487+
this._initObs();
488+
489+
// jump list refresh timer
490+
this._updateTimer();
491+
492+
// We only build the Private Browsing Jump List once
493+
this._pbBuilder.buildList();
494+
},
495+
496+
update: function WTBJL_update() {
497+
// are we disabled via prefs? don't do anything!
498+
if (!this._enabled) {
499+
return;
500+
}
501+
502+
// do what we came here to do, update the taskbar jumplist
503+
this._builder.buildList();
504+
},
505+
506+
_shutdown: function WTBJL__shutdown() {
507+
this._builder.updateShutdownState(true);
508+
this._pbBuilder.updateShutdownState(true);
509+
this._shuttingDown = true;
510+
this._free();
487511
},
488512

489513
/**
@@ -492,22 +516,33 @@ var WinTaskbarJumpList = {
492516

493517
_refreshPrefs: function WTBJL__refreshPrefs() {
494518
this._enabled = _prefs.getBoolPref(PREF_TASKBAR_ENABLED);
495-
this._showFrequent = _prefs.getBoolPref(PREF_TASKBAR_FREQUENT);
496-
this._showRecent = _prefs.getBoolPref(PREF_TASKBAR_RECENT);
497-
this._showTasks = _prefs.getBoolPref(PREF_TASKBAR_TASKS);
498-
this._maxItemCount = _prefs.getIntPref(PREF_TASKBAR_ITEMCOUNT);
519+
var showTasks = _prefs.getBoolPref(PREF_TASKBAR_TASKS);
520+
this._builder.refreshPrefs(
521+
showTasks,
522+
_prefs.getBoolPref(PREF_TASKBAR_FREQUENT),
523+
_prefs.getBoolPref(PREF_TASKBAR_RECENT),
524+
_prefs.getIntPref(PREF_TASKBAR_ITEMCOUNT)
525+
);
526+
// showTasks is the only relevant pref for the Private Browsing Jump List
527+
// the others are are related to frequent/recent entries, which are
528+
// explicitly disabled for it
529+
this._pbBuilder.refreshPrefs(showTasks, false, false, 0);
499530
},
500531

501532
/**
502533
* Init and shutdown utilities
503534
*/
504535

505536
_initTaskbar: function WTBJL__initTaskbar() {
506-
this._builder = _taskbarService.createJumpListBuilder();
507-
if (!this._builder || !this._builder.available) {
537+
var builder = _taskbarService.createJumpListBuilder(false);
538+
var pbBuilder = _taskbarService.createJumpListBuilder(true);
539+
if (!builder || !builder.available || !pbBuilder || !pbBuilder.available) {
508540
return false;
509541
}
510542

543+
this._builder = new Builder(builder, true, true, true);
544+
this._pbBuilder = new Builder(pbBuilder, true, false, false);
545+
511546
return true;
512547
},
513548

@@ -571,7 +606,8 @@ var WinTaskbarJumpList = {
571606
this._freeObs();
572607
this._updateTimer();
573608
this._updateIdleObserver();
574-
delete this._builder;
609+
this._builder.delete();
610+
this._pbBuilder.delete();
575611
},
576612

577613
notify: function WTBJL_notify(aTimer) {

widget/nsIJumpListBuilder.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,6 @@ interface nsIJumpListBuilder : nsISupports
156156
* @throw NS_ERROR_UNEXPECTED on internal errors.
157157
*/
158158
boolean deleteActiveList();
159+
160+
void setAppUserModelID(in AString aAppUserModelId);
159161
};

widget/nsIWinTaskbar.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ interface nsIWinTaskbar : nsISupports
129129
* @throw NS_ERROR_ALREADY_INITIALIZED if an nsIJumpListBuilder instance is
130130
* currently building a list.
131131
*/
132-
nsIJumpListBuilder createJumpListBuilder();
132+
nsIJumpListBuilder createJumpListBuilder(in boolean aPrivateBrowsing);
133133

134134
/**
135135
* Application window taskbar group settings

0 commit comments

Comments
 (0)