2014-06-25 09:12:07 +04:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2009-10-07 13:09:11 +04:00
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2009-10-07 13:09:11 +04:00
|
|
|
|
2010-10-14 12:46:38 +04:00
|
|
|
// Stop updating jumplists after some idle time.
|
|
|
|
const IDLE_TIMEOUT_SECONDS = 5 * 60;
|
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
// Prefs
|
|
|
|
const PREF_TASKBAR_BRANCH = "browser.taskbar.lists.";
|
|
|
|
const PREF_TASKBAR_ENABLED = "enabled";
|
|
|
|
const PREF_TASKBAR_ITEMCOUNT = "maxListItemCount";
|
|
|
|
const PREF_TASKBAR_FREQUENT = "frequent.enabled";
|
|
|
|
const PREF_TASKBAR_RECENT = "recent.enabled";
|
|
|
|
const PREF_TASKBAR_TASKS = "tasks.enabled";
|
2010-05-27 20:03:10 +04:00
|
|
|
const PREF_TASKBAR_REFRESH = "refreshInSeconds";
|
2009-10-07 13:09:11 +04:00
|
|
|
|
2010-10-14 12:46:38 +04:00
|
|
|
// Hash keys for pendingStatements.
|
|
|
|
const LIST_TYPE = {
|
2017-06-15 20:24:17 +03:00
|
|
|
FREQUENT: 0,
|
2018-08-31 08:59:17 +03:00
|
|
|
RECENT: 1,
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|
2010-10-14 12:46:38 +04:00
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
/**
|
|
|
|
* Exports
|
|
|
|
*/
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = [
|
2009-10-07 13:09:11 +04:00
|
|
|
"WinTaskbarJumpList",
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Smart getters
|
|
|
|
*/
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "_prefs", function() {
|
2012-01-17 05:34:51 +04:00
|
|
|
return Services.prefs.getBranch(PREF_TASKBAR_BRANCH);
|
2009-10-07 13:09:11 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "_stringBundle", function() {
|
2010-10-14 12:46:36 +04:00
|
|
|
return Services.strings
|
|
|
|
.createBundle("chrome://browser/locale/taskbar.properties");
|
|
|
|
});
|
|
|
|
|
2010-10-14 12:46:38 +04:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "_idle",
|
|
|
|
"@mozilla.org/widget/idleservice;1",
|
|
|
|
"nsIIdleService");
|
2009-10-07 13:09:11 +04:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "_taskbarService",
|
|
|
|
"@mozilla.org/windows-taskbar;1",
|
|
|
|
"nsIWinTaskbar");
|
2010-05-15 04:24:50 +04:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "PlacesUtils",
|
2017-06-07 10:21:18 +03:00
|
|
|
"resource://gre/modules/PlacesUtils.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
|
2012-10-25 00:21:33 +04:00
|
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
|
2014-11-18 22:21:44 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "gHistoryObserver", function() {
|
|
|
|
return Object.freeze({
|
|
|
|
onClearHistory() {
|
|
|
|
WinTaskbarJumpList.update();
|
|
|
|
},
|
2018-05-09 22:36:56 +03:00
|
|
|
onBeginUpdateBatch() {},
|
|
|
|
onEndUpdateBatch() {},
|
|
|
|
onVisits() {},
|
|
|
|
onTitleChanged() {},
|
|
|
|
onFrecencyChanged() {},
|
|
|
|
onManyFrecenciesChanged() {},
|
|
|
|
onDeleteURI() {},
|
|
|
|
onPageChanged() {},
|
|
|
|
onDeleteVisits() {},
|
2018-05-08 11:39:03 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI([Ci.nsINavHistoryObserver]),
|
2014-11-18 22:21:44 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
/**
|
|
|
|
* Global functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
function _getString(name) {
|
|
|
|
return _stringBundle.GetStringFromName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Task list configuration data object.
|
|
|
|
|
|
|
|
var tasksCfg = [
|
|
|
|
/**
|
|
|
|
* Task configuration options: title, description, args, iconIndex, open, close.
|
|
|
|
*
|
|
|
|
* title - Task title displayed in the list. (strings in the table are temp fillers.)
|
|
|
|
* description - Tooltip description on the list item.
|
|
|
|
* args - Command line args to invoke the task.
|
|
|
|
* iconIndex - Optional win icon index into the main application for the
|
|
|
|
* list item.
|
|
|
|
* open - Boolean indicates if the command should be visible after the browser opens.
|
|
|
|
* close - Boolean indicates if the command should be visible after the browser closes.
|
|
|
|
*/
|
2012-11-21 05:31:35 +04:00
|
|
|
// Open new tab
|
2009-10-07 13:09:11 +04:00
|
|
|
{
|
2016-12-31 05:47:25 +03:00
|
|
|
get title() { return _getString("taskbar.tasks.newTab.label"); },
|
2015-09-23 11:58:10 +03:00
|
|
|
get description() { return _getString("taskbar.tasks.newTab.description"); },
|
2009-10-07 13:09:11 +04:00
|
|
|
args: "-new-tab about:blank",
|
2012-04-28 19:22:06 +04:00
|
|
|
iconIndex: 3, // New window icon
|
2009-10-07 13:09:11 +04:00
|
|
|
open: true,
|
2010-10-14 12:46:38 +04:00
|
|
|
close: true, // The jump list already has an app launch icon, but
|
|
|
|
// we don't always update the list on shutdown.
|
|
|
|
// Thus true for consistency.
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
2012-11-21 05:31:35 +04:00
|
|
|
// Open new window
|
2009-10-07 13:09:11 +04:00
|
|
|
{
|
2016-12-31 05:47:25 +03:00
|
|
|
get title() { return _getString("taskbar.tasks.newWindow.label"); },
|
2015-09-23 11:58:10 +03:00
|
|
|
get description() { return _getString("taskbar.tasks.newWindow.description"); },
|
2009-10-07 13:09:11 +04:00
|
|
|
args: "-browser",
|
2012-04-28 19:22:06 +04:00
|
|
|
iconIndex: 2, // New tab icon
|
2009-10-07 13:09:11 +04:00
|
|
|
open: true,
|
2010-10-14 12:46:38 +04:00
|
|
|
close: true, // No point, but we don't always update the list on
|
2012-11-21 05:31:35 +04:00
|
|
|
// shutdown. Thus true for consistency.
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-03-01 19:20:38 +03:00
|
|
|
// Open new private window
|
|
|
|
let privateWindowTask = {
|
|
|
|
get title() { return _getString("taskbar.tasks.newPrivateWindow.label"); },
|
|
|
|
get description() { return _getString("taskbar.tasks.newPrivateWindow.description"); },
|
|
|
|
args: "-private-window",
|
|
|
|
iconIndex: 4, // Private browsing mode icon
|
|
|
|
open: true,
|
|
|
|
close: true, // No point, but we don't always update the list on
|
|
|
|
// shutdown. Thus true for consistency.
|
|
|
|
};
|
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
// Implementation
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var WinTaskbarJumpList =
|
2009-10-07 13:09:11 +04:00
|
|
|
{
|
|
|
|
_builder: null,
|
|
|
|
_tasks: null,
|
|
|
|
_shuttingDown: false,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Startup, shutdown, and update
|
2016-02-04 01:22:33 +03:00
|
|
|
*/
|
2009-10-07 13:09:11 +04:00
|
|
|
|
|
|
|
startup: function WTBJL_startup() {
|
|
|
|
// exit if this isn't win7 or higher.
|
|
|
|
if (!this._initTaskbar())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Store our task list config data
|
|
|
|
this._tasks = tasksCfg;
|
|
|
|
|
2018-03-01 19:20:38 +03:00
|
|
|
if (PrivateBrowsingUtils.enabled) {
|
|
|
|
tasksCfg.push(privateWindowTask);
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
// retrieve taskbar related prefs.
|
|
|
|
this._refreshPrefs();
|
2010-10-14 12:46:36 +04:00
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
// observer for private browsing and our prefs branch
|
|
|
|
this._initObs();
|
|
|
|
|
|
|
|
// jump list refresh timer
|
2010-10-14 12:46:38 +04:00
|
|
|
this._updateTimer();
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
update: function WTBJL_update() {
|
|
|
|
// are we disabled via prefs? don't do anything!
|
|
|
|
if (!this._enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// do what we came here to do, update the taskbar jumplist
|
|
|
|
this._buildList();
|
|
|
|
},
|
|
|
|
|
|
|
|
_shutdown: function WTBJL__shutdown() {
|
|
|
|
this._shuttingDown = true;
|
|
|
|
this._free();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List building
|
2010-10-14 12:46:38 +04:00
|
|
|
*
|
|
|
|
* @note Async builders must add their mozIStoragePendingStatement to
|
|
|
|
* _pendingStatements object, using a different LIST_TYPE entry for
|
|
|
|
* each statement. Once finished they must remove it and call
|
|
|
|
* commitBuild(). When there will be no more _pendingStatements,
|
|
|
|
* commitBuild() will commit for real.
|
|
|
|
*/
|
|
|
|
|
|
|
|
_pendingStatements: {},
|
|
|
|
_hasPendingStatements: function WTBJL__hasPendingStatements() {
|
2010-11-08 17:03:51 +03:00
|
|
|
return Object.keys(this._pendingStatements).length > 0;
|
2010-10-14 12:46:38 +04:00
|
|
|
},
|
2009-10-07 13:09:11 +04:00
|
|
|
|
2018-07-11 01:34:28 +03:00
|
|
|
async _buildList() {
|
2010-10-14 12:46:38 +04:00
|
|
|
if (this._hasPendingStatements()) {
|
|
|
|
// We were requested to update the list while another update was in
|
|
|
|
// progress, this could happen at shutdown, idle or privatebrowsing.
|
|
|
|
// Abort the current list building.
|
|
|
|
for (let listType in this._pendingStatements) {
|
|
|
|
this._pendingStatements[listType].cancel();
|
|
|
|
delete this._pendingStatements[listType];
|
|
|
|
}
|
|
|
|
this._builder.abortListBuild();
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
// anything to build?
|
|
|
|
if (!this._showFrequent && !this._showRecent && !this._showTasks) {
|
|
|
|
// don't leave the last list hanging on the taskbar.
|
|
|
|
this._deleteActiveJumpList();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-20 19:56:01 +03:00
|
|
|
await this._startBuild();
|
2009-10-07 13:09:11 +04:00
|
|
|
|
2010-06-01 20:09:41 +04:00
|
|
|
if (this._showTasks)
|
|
|
|
this._buildTasks();
|
2009-10-07 13:09:11 +04:00
|
|
|
|
|
|
|
// Space for frequent items takes priority over recent.
|
2010-06-01 20:09:41 +04:00
|
|
|
if (this._showFrequent)
|
|
|
|
this._buildFrequent();
|
2009-10-07 13:09:11 +04:00
|
|
|
|
2010-06-01 20:09:41 +04:00
|
|
|
if (this._showRecent)
|
|
|
|
this._buildRecent();
|
2009-10-07 13:09:11 +04:00
|
|
|
|
|
|
|
this._commitBuild();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Taskbar api wrappers
|
2016-02-04 01:22:33 +03:00
|
|
|
*/
|
2009-10-07 13:09:11 +04:00
|
|
|
|
2018-07-11 01:34:28 +03:00
|
|
|
async _startBuild() {
|
2009-10-07 13:09:11 +04:00
|
|
|
this._builder.abortListBuild();
|
2018-07-11 01:34:28 +03:00
|
|
|
let URIsToRemove = await this._builder.initListBuild();
|
|
|
|
if (URIsToRemove.length > 0) {
|
2009-10-07 13:09:11 +04:00
|
|
|
// Prior to building, delete removed items from history.
|
2018-07-11 01:34:28 +03:00
|
|
|
this._clearHistory(URIsToRemove);
|
2009-10-07 13:09:11 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_commitBuild: function WTBJL__commitBuild() {
|
2017-05-24 11:38:57 +03:00
|
|
|
if (this._hasPendingStatements()) {
|
|
|
|
return;
|
2010-10-14 12:46:38 +04:00
|
|
|
}
|
2017-05-24 11:38:57 +03:00
|
|
|
|
|
|
|
this._builder.commitListBuild(succeed => {
|
|
|
|
if (!succeed) {
|
|
|
|
this._builder.abortListBuild();
|
|
|
|
}
|
|
|
|
});
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildTasks: function WTBJL__buildTasks() {
|
|
|
|
var items = Cc["@mozilla.org/array;1"].
|
|
|
|
createInstance(Ci.nsIMutableArray);
|
2016-11-11 19:10:51 +03:00
|
|
|
this._tasks.forEach(function(task) {
|
2009-10-07 13:09:11 +04:00
|
|
|
if ((this._shuttingDown && !task.close) || (!this._shuttingDown && !task.open))
|
|
|
|
return;
|
|
|
|
var item = this._getHandlerAppItem(task.title, task.description,
|
2011-09-06 23:11:29 +04:00
|
|
|
task.args, task.iconIndex, null);
|
2017-04-14 22:51:39 +03:00
|
|
|
items.appendElement(item);
|
2009-10-07 13:09:11 +04:00
|
|
|
}, this);
|
2016-02-04 01:22:33 +03:00
|
|
|
|
2010-06-01 20:09:41 +04:00
|
|
|
if (items.length > 0)
|
|
|
|
this._builder.addListToBuild(this._builder.JUMPLIST_CATEGORY_TASKS, items);
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildCustom: function WTBJL__buildCustom(title, items) {
|
2010-06-01 20:09:41 +04:00
|
|
|
if (items.length > 0)
|
|
|
|
this._builder.addListToBuild(this._builder.JUMPLIST_CATEGORY_CUSTOMLIST, items, title);
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildFrequent: function WTBJL__buildFrequent() {
|
|
|
|
// Windows supports default frequent and recent lists,
|
|
|
|
// but those depend on internal windows visit tracking
|
|
|
|
// which we don't populate. So we build our own custom
|
|
|
|
// frequent and recent lists using our nav history data.
|
|
|
|
|
|
|
|
var items = Cc["@mozilla.org/array;1"].
|
|
|
|
createInstance(Ci.nsIMutableArray);
|
|
|
|
// track frequent items so that we don't add them to
|
|
|
|
// the recent list.
|
|
|
|
this._frequentHashList = [];
|
2009-10-07 15:35:37 +04:00
|
|
|
|
2010-10-14 12:46:38 +04:00
|
|
|
this._pendingStatements[LIST_TYPE.FREQUENT] = this._getHistoryResults(
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING,
|
|
|
|
this._maxItemCount,
|
2016-11-11 19:10:51 +03:00
|
|
|
function(aResult) {
|
2010-10-14 12:46:38 +04:00
|
|
|
if (!aResult) {
|
|
|
|
delete this._pendingStatements[LIST_TYPE.FREQUENT];
|
|
|
|
// The are no more results, build the list.
|
|
|
|
this._buildCustom(_getString("taskbar.frequent.label"), items);
|
|
|
|
this._commitBuild();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let title = aResult.title || aResult.uri;
|
2017-01-09 22:27:25 +03:00
|
|
|
let faviconPageUri = Services.io.newURI(aResult.uri);
|
2016-02-04 01:22:33 +03:00
|
|
|
let shortcut = this._getHandlerAppItem(title, title, aResult.uri, 1,
|
2011-09-06 23:11:29 +04:00
|
|
|
faviconPageUri);
|
2017-04-14 22:51:39 +03:00
|
|
|
items.appendElement(shortcut);
|
2010-10-14 12:46:38 +04:00
|
|
|
this._frequentHashList.push(aResult.uri);
|
|
|
|
},
|
|
|
|
this
|
|
|
|
);
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildRecent: function WTBJL__buildRecent() {
|
|
|
|
var items = Cc["@mozilla.org/array;1"].
|
|
|
|
createInstance(Ci.nsIMutableArray);
|
2010-10-14 12:46:38 +04:00
|
|
|
// Frequent items will be skipped, so we select a double amount of
|
|
|
|
// entries and stop fetching results at _maxItemCount.
|
|
|
|
var count = 0;
|
|
|
|
|
|
|
|
this._pendingStatements[LIST_TYPE.RECENT] = this._getHistoryResults(
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING,
|
|
|
|
this._maxItemCount * 2,
|
2016-11-11 19:10:51 +03:00
|
|
|
function(aResult) {
|
2010-10-14 12:46:38 +04:00
|
|
|
if (!aResult) {
|
|
|
|
// The are no more results, build the list.
|
|
|
|
this._buildCustom(_getString("taskbar.recent.label"), items);
|
|
|
|
delete this._pendingStatements[LIST_TYPE.RECENT];
|
|
|
|
this._commitBuild();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count >= this._maxItemCount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not add items to recent that have already been added to frequent.
|
|
|
|
if (this._frequentHashList &&
|
2018-02-01 22:45:22 +03:00
|
|
|
this._frequentHashList.includes(aResult.uri)) {
|
2010-10-14 12:46:38 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let title = aResult.title || aResult.uri;
|
2017-01-09 22:27:25 +03:00
|
|
|
let faviconPageUri = Services.io.newURI(aResult.uri);
|
2011-09-06 23:11:29 +04:00
|
|
|
let shortcut = this._getHandlerAppItem(title, title, aResult.uri, 1,
|
|
|
|
faviconPageUri);
|
2017-04-14 22:51:39 +03:00
|
|
|
items.appendElement(shortcut);
|
2010-10-14 12:46:38 +04:00
|
|
|
count++;
|
|
|
|
},
|
|
|
|
this
|
|
|
|
);
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_deleteActiveJumpList: function WTBJL__deleteAJL() {
|
2010-06-01 20:09:41 +04:00
|
|
|
this._builder.deleteActiveList();
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Jump list item creation helpers
|
|
|
|
*/
|
|
|
|
|
2016-02-04 01:22:33 +03:00
|
|
|
_getHandlerAppItem: function WTBJL__getHandlerAppItem(name, description,
|
|
|
|
args, iconIndex,
|
2011-09-06 23:11:29 +04:00
|
|
|
faviconPageUri) {
|
2017-08-04 11:49:22 +03:00
|
|
|
var file = Services.dirsvc.get("XREExeF", Ci.nsIFile);
|
2009-10-07 13:09:11 +04:00
|
|
|
|
|
|
|
var handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"].
|
|
|
|
createInstance(Ci.nsILocalHandlerApp);
|
|
|
|
handlerApp.executable = file;
|
|
|
|
// handlers default to the leaf name if a name is not specified
|
2009-12-15 23:33:51 +03:00
|
|
|
if (name && name.length != 0)
|
2009-10-07 13:09:11 +04:00
|
|
|
handlerApp.name = name;
|
|
|
|
handlerApp.detailedDescription = description;
|
|
|
|
handlerApp.appendParameter(args);
|
|
|
|
|
|
|
|
var item = Cc["@mozilla.org/windows-jumplistshortcut;1"].
|
|
|
|
createInstance(Ci.nsIJumpListShortcut);
|
|
|
|
item.app = handlerApp;
|
2011-09-06 23:11:29 +04:00
|
|
|
item.iconIndex = iconIndex;
|
|
|
|
item.faviconPageUri = faviconPageUri;
|
2009-10-07 13:09:11 +04:00
|
|
|
return item;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getSeparatorItem: function WTBJL__getSeparatorItem() {
|
|
|
|
var item = Cc["@mozilla.org/windows-jumplistseparator;1"].
|
|
|
|
createInstance(Ci.nsIJumpListSeparator);
|
|
|
|
return item;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Nav history helpers
|
2010-10-14 12:46:38 +04:00
|
|
|
*/
|
2009-10-07 13:09:11 +04:00
|
|
|
|
2010-10-14 12:46:38 +04:00
|
|
|
_getHistoryResults:
|
|
|
|
function WTBLJL__getHistoryResults(aSortingMode, aLimit, aCallback, aScope) {
|
2010-10-14 12:46:36 +04:00
|
|
|
var options = PlacesUtils.history.getNewQueryOptions();
|
2010-10-14 12:46:38 +04:00
|
|
|
options.maxResults = aLimit;
|
|
|
|
options.sortingMode = aSortingMode;
|
2010-10-14 12:46:36 +04:00
|
|
|
var query = PlacesUtils.history.getNewQuery();
|
2009-10-07 13:09:11 +04:00
|
|
|
|
2010-10-14 12:46:38 +04:00
|
|
|
// Return the pending statement to the caller, to allow cancelation.
|
2018-05-10 11:39:12 +03:00
|
|
|
return PlacesUtils.history.asyncExecuteLegacyQuery(query, options, {
|
2016-12-30 02:34:54 +03:00
|
|
|
handleResult(aResultSet) {
|
2010-10-14 12:46:38 +04:00
|
|
|
for (let row; (row = aResultSet.getNextRow());) {
|
|
|
|
try {
|
|
|
|
aCallback.call(aScope,
|
2017-06-15 20:24:17 +03:00
|
|
|
{ uri: row.getResultByIndex(1),
|
2018-08-31 08:59:17 +03:00
|
|
|
title: row.getResultByIndex(2),
|
2010-10-14 12:46:38 +04:00
|
|
|
});
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
},
|
2016-12-30 02:34:54 +03:00
|
|
|
handleError(aError) {
|
2017-06-07 10:21:18 +03:00
|
|
|
Cu.reportError(
|
2010-10-14 12:46:38 +04:00
|
|
|
"Async execution error (" + aError.result + "): " + aError.message);
|
|
|
|
},
|
2016-12-30 02:34:54 +03:00
|
|
|
handleCompletion(aReason) {
|
2010-10-14 12:46:38 +04:00
|
|
|
aCallback.call(WinTaskbarJumpList, null);
|
|
|
|
},
|
|
|
|
});
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
2010-10-14 12:46:36 +04:00
|
|
|
|
2018-07-11 01:34:28 +03:00
|
|
|
_clearHistory: function WTBJL__clearHistory(uriSpecsToRemove) {
|
|
|
|
let URIsToRemove = uriSpecsToRemove.map(spec => {
|
|
|
|
try { // in case we get a bad uri
|
|
|
|
return Services.io.newURI(spec);
|
|
|
|
} catch (e) {
|
|
|
|
return null;
|
2009-10-07 13:09:11 +04:00
|
|
|
}
|
2018-07-11 01:34:28 +03:00
|
|
|
}).filter(uri => !!uri);
|
|
|
|
|
2010-10-14 12:46:38 +04:00
|
|
|
if (URIsToRemove.length > 0) {
|
2017-06-07 10:21:18 +03:00
|
|
|
PlacesUtils.history.remove(URIsToRemove).catch(Cu.reportError);
|
2010-10-14 12:46:38 +04:00
|
|
|
}
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prefs utilities
|
2016-02-04 01:22:33 +03:00
|
|
|
*/
|
2009-10-07 13:09:11 +04:00
|
|
|
|
|
|
|
_refreshPrefs: function WTBJL__refreshPrefs() {
|
|
|
|
this._enabled = _prefs.getBoolPref(PREF_TASKBAR_ENABLED);
|
|
|
|
this._showFrequent = _prefs.getBoolPref(PREF_TASKBAR_FREQUENT);
|
|
|
|
this._showRecent = _prefs.getBoolPref(PREF_TASKBAR_RECENT);
|
|
|
|
this._showTasks = _prefs.getBoolPref(PREF_TASKBAR_TASKS);
|
|
|
|
this._maxItemCount = _prefs.getIntPref(PREF_TASKBAR_ITEMCOUNT);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init and shutdown utilities
|
2016-02-04 01:22:33 +03:00
|
|
|
*/
|
2009-10-07 13:09:11 +04:00
|
|
|
|
|
|
|
_initTaskbar: function WTBJL__initTaskbar() {
|
|
|
|
this._builder = _taskbarService.createJumpListBuilder();
|
|
|
|
if (!this._builder || !this._builder.available)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_initObs: function WTBJL__initObs() {
|
2010-10-14 12:46:38 +04:00
|
|
|
// If the browser is closed while in private browsing mode, the "exit"
|
|
|
|
// notification is fired on quit-application-granted.
|
|
|
|
// History cleanup can happen at profile-change-teardown.
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.obs.addObserver(this, "profile-before-change");
|
|
|
|
Services.obs.addObserver(this, "browser:purge-session-history");
|
|
|
|
_prefs.addObserver("", this);
|
2014-11-18 22:21:44 +03:00
|
|
|
PlacesUtils.history.addObserver(gHistoryObserver, false);
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
2016-02-04 01:22:33 +03:00
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
_freeObs: function WTBJL__freeObs() {
|
2010-10-14 12:46:38 +04:00
|
|
|
Services.obs.removeObserver(this, "profile-before-change");
|
2010-10-14 12:46:36 +04:00
|
|
|
Services.obs.removeObserver(this, "browser:purge-session-history");
|
2009-10-07 13:09:11 +04:00
|
|
|
_prefs.removeObserver("", this);
|
2014-11-18 22:21:44 +03:00
|
|
|
PlacesUtils.history.removeObserver(gHistoryObserver);
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
2010-10-14 12:46:38 +04:00
|
|
|
_updateTimer: function WTBJL__updateTimer() {
|
|
|
|
if (this._enabled && !this._shuttingDown && !this._timer) {
|
|
|
|
this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
this._timer.initWithCallback(this,
|
2016-11-11 01:48:04 +03:00
|
|
|
_prefs.getIntPref(PREF_TASKBAR_REFRESH) * 1000,
|
2010-10-14 12:46:38 +04:00
|
|
|
this._timer.TYPE_REPEATING_SLACK);
|
2016-12-31 05:47:25 +03:00
|
|
|
} else if ((!this._enabled || this._shuttingDown) && this._timer) {
|
2010-10-14 12:46:38 +04:00
|
|
|
this._timer.cancel();
|
|
|
|
delete this._timer;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_hasIdleObserver: false,
|
|
|
|
_updateIdleObserver: function WTBJL__updateIdleObserver() {
|
|
|
|
if (this._enabled && !this._shuttingDown && !this._hasIdleObserver) {
|
|
|
|
_idle.addIdleObserver(this, IDLE_TIMEOUT_SECONDS);
|
|
|
|
this._hasIdleObserver = true;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else if ((!this._enabled || this._shuttingDown) && this._hasIdleObserver) {
|
2010-10-14 12:46:38 +04:00
|
|
|
_idle.removeIdleObserver(this, IDLE_TIMEOUT_SECONDS);
|
|
|
|
this._hasIdleObserver = false;
|
|
|
|
}
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_free: function WTBJL__free() {
|
|
|
|
this._freeObs();
|
2010-10-14 12:46:38 +04:00
|
|
|
this._updateTimer();
|
|
|
|
this._updateIdleObserver();
|
2009-10-07 13:09:11 +04:00
|
|
|
delete this._builder;
|
|
|
|
},
|
2010-06-01 20:09:41 +04:00
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
/**
|
|
|
|
* Notification handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
notify: function WTBJL_notify(aTimer) {
|
2010-10-14 12:46:38 +04:00
|
|
|
// Add idle observer on the first notification so it doesn't hit startup.
|
|
|
|
this._updateIdleObserver();
|
2017-09-07 07:15:13 +03:00
|
|
|
Services.tm.idleDispatchToMainThread(() => { this.update(); });
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
observe: function WTBJL_observe(aSubject, aTopic, aData) {
|
|
|
|
switch (aTopic) {
|
|
|
|
case "nsPref:changed":
|
2018-02-08 21:15:26 +03:00
|
|
|
if (this._enabled && !_prefs.getBoolPref(PREF_TASKBAR_ENABLED))
|
2010-06-01 20:09:41 +04:00
|
|
|
this._deleteActiveJumpList();
|
2009-10-07 13:09:11 +04:00
|
|
|
this._refreshPrefs();
|
2010-10-14 12:46:38 +04:00
|
|
|
this._updateTimer();
|
|
|
|
this._updateIdleObserver();
|
2017-09-07 07:15:13 +03:00
|
|
|
Services.tm.idleDispatchToMainThread(() => { this.update(); });
|
2009-10-07 13:09:11 +04:00
|
|
|
break;
|
|
|
|
|
2010-10-14 12:46:38 +04:00
|
|
|
case "profile-before-change":
|
2009-10-07 13:09:11 +04:00
|
|
|
this._shutdown();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "browser:purge-session-history":
|
|
|
|
this.update();
|
|
|
|
break;
|
2010-10-14 12:46:38 +04:00
|
|
|
case "idle":
|
|
|
|
if (this._timer) {
|
|
|
|
this._timer.cancel();
|
|
|
|
delete this._timer;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-01-08 21:43:01 +04:00
|
|
|
case "active":
|
2010-10-14 12:46:38 +04:00
|
|
|
this._updateTimer();
|
|
|
|
break;
|
2009-10-07 13:09:11 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|