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
|
|
|
|
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-10-14 12:46:36 +04:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
2009-10-07 13:09:11 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
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 = {
|
|
|
|
FREQUENT: 0
|
|
|
|
, RECENT: 1
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
/**
|
|
|
|
* Exports
|
|
|
|
*/
|
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.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");
|
|
|
|
});
|
|
|
|
|
2014-12-10 18:02:17 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "PlacesUtils", function() {
|
|
|
|
Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
|
|
|
|
return PlacesUtils;
|
|
|
|
});
|
2010-10-14 12:46:36 +04:00
|
|
|
|
2014-12-10 18:02:17 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "NetUtil", function() {
|
|
|
|
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
|
|
|
return NetUtil;
|
|
|
|
});
|
2009-10-07 13:09:11 +04:00
|
|
|
|
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
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "_winShellService",
|
|
|
|
"@mozilla.org/browser/shell-service;1",
|
|
|
|
"nsIWindowsShellService");
|
|
|
|
|
2012-10-25 00:21:33 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
|
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
|
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
|
|
|
{
|
|
|
|
get title() _getString("taskbar.tasks.newTab.label"),
|
|
|
|
get description() _getString("taskbar.tasks.newTab.description"),
|
|
|
|
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
|
|
|
{
|
|
|
|
get title() _getString("taskbar.tasks.newWindow.label"),
|
|
|
|
get description() _getString("taskbar.tasks.newWindow.description"),
|
|
|
|
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
|
|
|
},
|
2010-05-27 20:01:26 +04:00
|
|
|
|
2012-11-21 05:31:35 +04:00
|
|
|
// Open new private window
|
|
|
|
{
|
|
|
|
get title() _getString("taskbar.tasks.newPrivateWindow.label"),
|
|
|
|
get description() _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
|
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.WinTaskbarJumpList =
|
2009-10-07 13:09:11 +04:00
|
|
|
{
|
|
|
|
_builder: null,
|
|
|
|
_tasks: null,
|
|
|
|
_shuttingDown: false,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Startup, shutdown, and update
|
2014-12-10 18:02:17 +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;
|
|
|
|
|
2010-05-15 04:24:50 +04:00
|
|
|
// Win shell shortcut maintenance. If we've gone through an update,
|
|
|
|
// this will update any pinned taskbar shortcuts. Not specific to
|
2014-12-10 18:02:17 +03:00
|
|
|
// jump lists, but this was a convienent place to call it.
|
2011-01-28 00:10:37 +03:00
|
|
|
try {
|
|
|
|
// dev builds may not have helper.exe, ignore failures.
|
|
|
|
this._shortcutMaintenance();
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
2010-05-15 04:24:50 +04:00
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
// Store our task list config data
|
|
|
|
this._tasks = tasksCfg;
|
|
|
|
|
|
|
|
// 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;
|
2014-12-10 18:02:17 +03:00
|
|
|
|
|
|
|
// Correctly handle a clear history on shutdown. If there are no
|
|
|
|
// entries be sure to empty all history lists. Luckily Places caches
|
|
|
|
// this value, so it's a pretty fast call.
|
|
|
|
if (!PlacesUtils.history.hasHistoryEntries) {
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
this._free();
|
|
|
|
},
|
|
|
|
|
2010-05-15 04:24:50 +04:00
|
|
|
_shortcutMaintenance: function WTBJL__maintenace() {
|
|
|
|
_winShellService.shortcutMaintenance();
|
|
|
|
},
|
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
|
|
|
_buildList: function WTBJL__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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._startBuild())
|
|
|
|
return;
|
|
|
|
|
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
|
2014-12-10 18:02:17 +03:00
|
|
|
*/
|
2009-10-07 13:09:11 +04:00
|
|
|
|
|
|
|
_startBuild: function WTBJL__startBuild() {
|
|
|
|
var removedItems = Cc["@mozilla.org/array;1"].
|
|
|
|
createInstance(Ci.nsIMutableArray);
|
|
|
|
this._builder.abortListBuild();
|
2014-12-10 18:02:17 +03:00
|
|
|
if (this._builder.initListBuild(removedItems)) {
|
2009-10-07 13:09:11 +04:00
|
|
|
// Prior to building, delete removed items from history.
|
|
|
|
this._clearHistory(removedItems);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_commitBuild: function WTBJL__commitBuild() {
|
2010-10-14 12:46:38 +04:00
|
|
|
if (!this._hasPendingStatements() && !this._builder.commitListBuild()) {
|
2009-10-07 13:09:11 +04:00
|
|
|
this._builder.abortListBuild();
|
2010-10-14 12:46:38 +04:00
|
|
|
}
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildTasks: function WTBJL__buildTasks() {
|
|
|
|
var items = Cc["@mozilla.org/array;1"].
|
|
|
|
createInstance(Ci.nsIMutableArray);
|
|
|
|
this._tasks.forEach(function (task) {
|
|
|
|
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);
|
2009-10-07 13:09:11 +04:00
|
|
|
items.appendElement(item, false);
|
|
|
|
}, this);
|
2014-12-10 18:02:17 +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() {
|
2014-12-10 18:02:17 +03:00
|
|
|
// If history is empty, just bail out.
|
|
|
|
if (!PlacesUtils.history.hasHistoryEntries) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
// 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,
|
|
|
|
function (aResult) {
|
|
|
|
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;
|
2011-09-06 23:11:29 +04:00
|
|
|
let faviconPageUri = Services.io.newURI(aResult.uri, null, null);
|
2014-12-10 18:02:17 +03:00
|
|
|
let shortcut = this._getHandlerAppItem(title, title, aResult.uri, 1,
|
2011-09-06 23:11:29 +04:00
|
|
|
faviconPageUri);
|
2010-10-14 12:46:38 +04:00
|
|
|
items.appendElement(shortcut, false);
|
|
|
|
this._frequentHashList.push(aResult.uri);
|
|
|
|
},
|
|
|
|
this
|
|
|
|
);
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildRecent: function WTBJL__buildRecent() {
|
2014-12-10 18:02:17 +03:00
|
|
|
// If history is empty, just bail out.
|
|
|
|
if (!PlacesUtils.history.hasHistoryEntries) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
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,
|
|
|
|
function (aResult) {
|
|
|
|
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 &&
|
|
|
|
this._frequentHashList.indexOf(aResult.uri) != -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let title = aResult.title || aResult.uri;
|
2011-09-06 23:11:29 +04:00
|
|
|
let faviconPageUri = Services.io.newURI(aResult.uri, null, null);
|
|
|
|
let shortcut = this._getHandlerAppItem(title, title, aResult.uri, 1,
|
|
|
|
faviconPageUri);
|
2010-10-14 12:46:38 +04:00
|
|
|
items.appendElement(shortcut, false);
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2014-12-10 18:02:17 +03:00
|
|
|
_getHandlerAppItem: function WTBJL__getHandlerAppItem(name, description,
|
|
|
|
args, iconIndex,
|
2011-09-06 23:11:29 +04:00
|
|
|
faviconPageUri) {
|
2012-12-14 21:40:20 +04:00
|
|
|
var file = Services.dirsvc.get("XREExeF", Ci.nsILocalFile);
|
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.
|
|
|
|
return PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
|
|
|
|
.asyncExecuteLegacyQueries([query], 1, options, {
|
|
|
|
handleResult: function (aResultSet) {
|
|
|
|
for (let row; (row = aResultSet.getNextRow());) {
|
|
|
|
try {
|
|
|
|
aCallback.call(aScope,
|
|
|
|
{ uri: row.getResultByIndex(1)
|
|
|
|
, title: row.getResultByIndex(2)
|
|
|
|
});
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleError: function (aError) {
|
|
|
|
Components.utils.reportError(
|
|
|
|
"Async execution error (" + aError.result + "): " + aError.message);
|
|
|
|
},
|
|
|
|
handleCompletion: function (aReason) {
|
|
|
|
aCallback.call(WinTaskbarJumpList, null);
|
|
|
|
},
|
|
|
|
});
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
2010-10-14 12:46:36 +04:00
|
|
|
|
2009-10-07 13:09:11 +04:00
|
|
|
_clearHistory: function WTBJL__clearHistory(items) {
|
|
|
|
if (!items)
|
|
|
|
return;
|
2010-10-14 12:46:38 +04:00
|
|
|
var URIsToRemove = [];
|
2011-01-28 00:10:37 +03:00
|
|
|
var e = items.enumerate();
|
|
|
|
while (e.hasMoreElements()) {
|
|
|
|
let oldItem = e.getNext().QueryInterface(Ci.nsIJumpListShortcut);
|
2009-10-07 13:09:11 +04:00
|
|
|
if (oldItem) {
|
|
|
|
try { // in case we get a bad uri
|
|
|
|
let uriSpec = oldItem.app.getParameter(0);
|
2010-10-14 12:46:38 +04:00
|
|
|
URIsToRemove.push(NetUtil.newURI(uriSpec));
|
2009-10-07 13:09:11 +04:00
|
|
|
} catch (err) { }
|
|
|
|
}
|
|
|
|
}
|
2010-10-14 12:46:38 +04:00
|
|
|
if (URIsToRemove.length > 0) {
|
|
|
|
PlacesUtils.bhistory.removePages(URIsToRemove, URIsToRemove.length, true);
|
|
|
|
}
|
2009-10-07 13:09:11 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prefs utilities
|
2014-12-10 18:02:17 +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
|
2014-12-10 18:02:17 +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.
|
|
|
|
Services.obs.addObserver(this, "profile-before-change", false);
|
2010-10-14 12:46:36 +04:00
|
|
|
Services.obs.addObserver(this, "browser:purge-session-history", false);
|
2009-10-07 13:09:11 +04:00
|
|
|
_prefs.addObserver("", this, false);
|
|
|
|
},
|
2014-12-10 18:02:17 +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);
|
|
|
|
},
|
|
|
|
|
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,
|
|
|
|
_prefs.getIntPref(PREF_TASKBAR_REFRESH)*1000,
|
|
|
|
this._timer.TYPE_REPEATING_SLACK);
|
|
|
|
}
|
|
|
|
else if ((!this._enabled || this._shuttingDown) && this._timer) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else if ((!this._enabled || this._shuttingDown) && this._hasIdleObserver) {
|
|
|
|
_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();
|
2009-10-07 13:09:11 +04:00
|
|
|
this.update();
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function WTBJL_observe(aSubject, aTopic, aData) {
|
|
|
|
switch (aTopic) {
|
|
|
|
case "nsPref:changed":
|
2010-06-01 20:09:41 +04:00
|
|
|
if (this._enabled == true && !_prefs.getBoolPref(PREF_TASKBAR_ENABLED))
|
|
|
|
this._deleteActiveJumpList();
|
2009-10-07 13:09:11 +04:00
|
|
|
this._refreshPrefs();
|
2010-10-14 12:46:38 +04:00
|
|
|
this._updateTimer();
|
|
|
|
this._updateIdleObserver();
|
2009-10-07 13:09:11 +04:00
|
|
|
this.update();
|
|
|
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|