2010-05-06 11:12:59 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Extension Manager UI.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* the Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Blair McBride <bmcbride@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/PluralForm.jsm");
|
|
|
|
Cu.import("resource://gre/modules/DownloadUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/AddonManager.jsm");
|
2010-07-19 16:01:23 -07:00
|
|
|
Cu.import("resource://gre/modules/AddonRepository.jsm");
|
2010-05-06 11:12:59 -07:00
|
|
|
|
|
|
|
|
|
|
|
const PREF_DISCOVERURL = "extensions.webservice.discoverURL";
|
2010-07-19 16:01:23 -07:00
|
|
|
const PREF_MAXRESULTS = "extensions.getAddons.maxResults";
|
2010-06-02 02:13:03 -07:00
|
|
|
const PREF_BACKGROUND_UPDATE = "extensions.update.enabled";
|
2010-09-01 16:40:20 -07:00
|
|
|
const PREF_CHECK_COMPATIBILITY = "extensions.checkCompatibility";
|
|
|
|
const PREF_CHECK_UPDATE_SECURITY = "extensions.checkUpdateSecurity";
|
2010-09-13 23:56:54 -07:00
|
|
|
const PREF_AUTOUPDATE_DEFAULT = "extensions.update.autoUpdateDefault";
|
2010-09-01 16:40:20 -07:00
|
|
|
|
|
|
|
const BRANCH_REGEXP = /^([^\.]+\.[0-9]+[a-z]*).*/gi;
|
2010-05-06 11:12:59 -07:00
|
|
|
|
|
|
|
const LOADING_MSG_DELAY = 100;
|
|
|
|
|
|
|
|
const SEARCH_SCORE_MULTIPLIER_NAME = 2;
|
|
|
|
const SEARCH_SCORE_MULTIPLIER_DESCRIPTION = 2;
|
|
|
|
|
2010-07-19 16:01:23 -07:00
|
|
|
// Use integers so search scores are sortable by nsIXULSortService
|
|
|
|
const SEARCH_SCORE_MATCH_WHOLEWORD = 10;
|
|
|
|
const SEARCH_SCORE_MATCH_WORDBOUNDRY = 6;
|
|
|
|
const SEARCH_SCORE_MATCH_SUBSTRING = 3;
|
2010-05-06 11:12:59 -07:00
|
|
|
|
2010-06-02 02:13:03 -07:00
|
|
|
const UPDATES_RECENT_TIMESPAN = 2 * 24 * 3600000; // 2 days (in milliseconds)
|
|
|
|
const UPDATES_RELEASENOTES_TRANSFORMFILE = "chrome://mozapps/content/extensions/updateinfo.xsl";
|
|
|
|
|
|
|
|
const XMLURI_PARSE_ERROR = "http://www.mozilla.org/newlayout/xml/parsererror.xml"
|
|
|
|
|
2010-11-30 14:19:10 -08:00
|
|
|
const VIEW_DEFAULT = "addons://discover/";
|
2010-12-02 17:52:34 -08:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var gStrings = {};
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(gStrings, "bundleSvc",
|
|
|
|
"@mozilla.org/intl/stringbundle;1",
|
|
|
|
"nsIStringBundleService");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(gStrings, "brand", function() {
|
|
|
|
return this.bundleSvc.createBundle("chrome://branding/locale/brand.properties");
|
|
|
|
});
|
|
|
|
XPCOMUtils.defineLazyGetter(gStrings, "ext", function() {
|
|
|
|
return this.bundleSvc.createBundle("chrome://mozapps/locale/extensions/extensions.properties");
|
|
|
|
});
|
|
|
|
XPCOMUtils.defineLazyGetter(gStrings, "dl", function() {
|
|
|
|
return this.bundleSvc.createBundle("chrome://mozapps/locale/downloads/downloads.properties");
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(gStrings, "brandShortName", function() {
|
|
|
|
return this.brand.GetStringFromName("brandShortName");
|
|
|
|
});
|
|
|
|
XPCOMUtils.defineLazyGetter(gStrings, "appVersion", function() {
|
|
|
|
return Services.appinfo.version;
|
|
|
|
});
|
|
|
|
|
2010-09-28 13:24:27 -07:00
|
|
|
document.addEventListener("load", initialize, true);
|
|
|
|
window.addEventListener("unload", shutdown, false);
|
2010-05-06 11:12:59 -07:00
|
|
|
|
2010-06-24 12:50:04 -07:00
|
|
|
var gPendingInitializations = 1;
|
|
|
|
__defineGetter__("gIsInitializing", function() gPendingInitializations > 0);
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
function initialize() {
|
2010-09-28 13:24:27 -07:00
|
|
|
document.removeEventListener("load", initialize, true);
|
2010-05-06 11:12:59 -07:00
|
|
|
gCategories.initialize();
|
|
|
|
gHeader.initialize();
|
|
|
|
gViewController.initialize();
|
|
|
|
gEventManager.initialize();
|
2010-06-24 12:50:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function notifyInitialized() {
|
|
|
|
if (!gIsInitializing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gPendingInitializations--;
|
|
|
|
if (!gIsInitializing) {
|
|
|
|
var event = document.createEvent("Events");
|
|
|
|
event.initEvent("Initialized", true, true);
|
|
|
|
document.dispatchEvent(event);
|
|
|
|
}
|
2010-05-01 11:04:44 -07:00
|
|
|
}
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
function shutdown() {
|
2010-08-11 09:55:12 -07:00
|
|
|
gCategories.shutdown();
|
2010-07-19 16:01:23 -07:00
|
|
|
gSearchView.shutdown();
|
2010-05-06 11:12:59 -07:00
|
|
|
gEventManager.shutdown();
|
2010-06-16 20:13:20 -07:00
|
|
|
gViewController.shutdown();
|
2010-05-01 11:04:44 -07:00
|
|
|
}
|
|
|
|
|
2010-06-15 11:40:05 -07:00
|
|
|
// Used by external callers to load a specific view into the manager
|
2010-08-27 15:23:53 -07:00
|
|
|
function loadView(aViewId) {
|
|
|
|
if (!gViewController.initialViewSelected) {
|
|
|
|
// The caller opened the window and immediately loaded the view so it
|
|
|
|
// should be the initial history entry
|
|
|
|
gViewController.loadInitialView(aViewId);
|
|
|
|
} else {
|
|
|
|
gViewController.loadView(aViewId);
|
|
|
|
}
|
2010-06-15 11:40:05 -07:00
|
|
|
}
|
|
|
|
|
2010-09-28 13:24:27 -07:00
|
|
|
/**
|
2010-10-26 10:45:15 -07:00
|
|
|
* A wrapper around the HTML5 session history service that allows the browser
|
|
|
|
* back/forward controls to work within the manager
|
2010-09-28 13:24:27 -07:00
|
|
|
*/
|
2010-10-26 10:45:15 -07:00
|
|
|
var HTML5History = {
|
|
|
|
get canGoBack() {
|
|
|
|
return window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.canGoBack;
|
|
|
|
},
|
|
|
|
|
|
|
|
get canGoForward() {
|
|
|
|
return window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.canGoForward;
|
|
|
|
},
|
|
|
|
|
|
|
|
back: function() {
|
|
|
|
window.history.back();
|
|
|
|
gViewController.updateCommand("cmd_back");
|
|
|
|
gViewController.updateCommand("cmd_forward");
|
|
|
|
},
|
|
|
|
|
|
|
|
forward: function() {
|
|
|
|
window.history.forward();
|
|
|
|
gViewController.updateCommand("cmd_back");
|
|
|
|
gViewController.updateCommand("cmd_forward");
|
|
|
|
},
|
2010-09-28 13:24:27 -07:00
|
|
|
|
|
|
|
pushState: function(aState) {
|
2010-10-26 10:45:15 -07:00
|
|
|
window.history.pushState(aState, document.title);
|
2010-09-28 13:24:27 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
replaceState: function(aState) {
|
2010-10-26 10:45:15 -07:00
|
|
|
window.history.replaceState(aState, document.title);
|
2010-09-28 13:24:27 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
popState: function() {
|
2010-10-26 10:45:15 -07:00
|
|
|
window.addEventListener("popstate", function(event) {
|
|
|
|
window.removeEventListener("popstate", arguments.callee, true);
|
|
|
|
// TODO To ensure we can't go forward again we put an additional entry
|
|
|
|
// for the current state into the history. Ideally we would just strip
|
|
|
|
// the history but there doesn't seem to be a way to do that. Bug 590661
|
|
|
|
window.history.pushState(event.state, document.title);
|
|
|
|
}, true);
|
|
|
|
window.history.back();
|
|
|
|
gViewController.updateCommand("cmd_back");
|
|
|
|
gViewController.updateCommand("cmd_forward");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A wrapper around a fake history service
|
|
|
|
*/
|
|
|
|
var FakeHistory = {
|
|
|
|
pos: 0,
|
|
|
|
states: [null],
|
|
|
|
|
|
|
|
get canGoBack() {
|
|
|
|
return this.pos > 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
get canGoForward() {
|
|
|
|
return (this.pos + 1) < this.states.length;
|
|
|
|
},
|
|
|
|
|
|
|
|
back: function() {
|
|
|
|
if (this.pos == 0)
|
|
|
|
throw new Error("Cannot go back from this point");
|
|
|
|
|
|
|
|
this.pos--;
|
|
|
|
gViewController.statePopped({ state: this.states[this.pos] });
|
|
|
|
gViewController.updateCommand("cmd_back");
|
|
|
|
gViewController.updateCommand("cmd_forward");
|
2010-09-28 13:24:27 -07:00
|
|
|
},
|
2010-10-26 10:45:15 -07:00
|
|
|
|
|
|
|
forward: function() {
|
|
|
|
if ((this.pos + 1) >= this.states.length)
|
|
|
|
throw new Error("Cannot go forward from this point");
|
|
|
|
|
|
|
|
this.pos++;
|
|
|
|
gViewController.statePopped({ state: this.states[this.pos] });
|
|
|
|
gViewController.updateCommand("cmd_back");
|
|
|
|
gViewController.updateCommand("cmd_forward");
|
|
|
|
},
|
|
|
|
|
|
|
|
pushState: function(aState) {
|
|
|
|
this.pos++;
|
|
|
|
this.states.splice(this.pos);
|
|
|
|
this.states.push(aState);
|
|
|
|
},
|
|
|
|
|
|
|
|
replaceState: function(aState) {
|
|
|
|
this.states[this.pos] = aState;
|
|
|
|
},
|
|
|
|
|
|
|
|
popState: function() {
|
|
|
|
if (this.pos == 0)
|
|
|
|
throw new Error("Cannot popState from this view");
|
|
|
|
|
|
|
|
this.states.splice(this.pos);
|
|
|
|
this.pos--;
|
|
|
|
|
|
|
|
gViewController.statePopped({ state: this.states[this.pos] });
|
|
|
|
gViewController.updateCommand("cmd_back");
|
|
|
|
gViewController.updateCommand("cmd_forward");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// If the window has a session history then use the HTML5 History wrapper
|
|
|
|
// otherwise use our fake history implementation
|
|
|
|
if (window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.sessionHistory) {
|
|
|
|
var gHistory = HTML5History;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gHistory = FakeHistory;
|
2010-09-28 13:24:27 -07:00
|
|
|
}
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var gEventManager = {
|
|
|
|
_listeners: {},
|
|
|
|
_installListeners: [],
|
2010-09-01 16:40:20 -07:00
|
|
|
checkCompatibilityPref: "",
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
initialize: function() {
|
|
|
|
var self = this;
|
|
|
|
["onEnabling", "onEnabled", "onDisabling", "onDisabled", "onUninstalling",
|
|
|
|
"onUninstalled", "onInstalled", "onOperationCancelled",
|
2010-06-02 02:13:03 -07:00
|
|
|
"onUpdateAvailable", "onUpdateFinished", "onCompatibilityUpdateAvailable",
|
|
|
|
"onPropertyChanged"].forEach(function(aEvent) {
|
2010-05-06 11:12:59 -07:00
|
|
|
self[aEvent] = function() {
|
|
|
|
self.delegateAddonEvent(aEvent, Array.splice(arguments, 0));
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
["onNewInstall", "onDownloadStarted", "onDownloadEnded", "onDownloadFailed",
|
|
|
|
"onDownloadProgress", "onDownloadCancelled", "onInstallStarted",
|
|
|
|
"onInstallEnded", "onInstallFailed", "onInstallCancelled",
|
|
|
|
"onExternalInstall"].forEach(function(aEvent) {
|
|
|
|
self[aEvent] = function() {
|
|
|
|
self.delegateInstallEvent(aEvent, Array.splice(arguments, 0));
|
|
|
|
};
|
|
|
|
});
|
|
|
|
AddonManager.addInstallListener(this);
|
|
|
|
AddonManager.addAddonListener(this);
|
2010-09-01 16:40:20 -07:00
|
|
|
|
|
|
|
var version = Services.appinfo.version.replace(BRANCH_REGEXP, "$1");
|
|
|
|
this.checkCompatibilityPref = PREF_CHECK_COMPATIBILITY + "." + version;
|
|
|
|
|
|
|
|
Services.prefs.addObserver(this.checkCompatibilityPref, this, false);
|
|
|
|
Services.prefs.addObserver(PREF_CHECK_UPDATE_SECURITY, this, false);
|
2010-09-13 23:56:54 -07:00
|
|
|
Services.prefs.addObserver(PREF_AUTOUPDATE_DEFAULT, this, false);
|
2010-09-01 16:40:20 -07:00
|
|
|
|
|
|
|
this.refreshGlobalWarning();
|
2010-09-13 23:56:54 -07:00
|
|
|
this.refreshAutoUpdateDefault();
|
2010-09-02 21:41:06 -07:00
|
|
|
|
|
|
|
var contextMenu = document.getElementById("addonitem-popup");
|
|
|
|
contextMenu.addEventListener("popupshowing", function() {
|
|
|
|
var addon = gViewController.currentViewObj.getSelectedAddon();
|
|
|
|
contextMenu.setAttribute("addontype", addon.type);
|
2010-10-07 10:30:10 -07:00
|
|
|
|
|
|
|
var menuSep = document.getElementById("addonitem-menuseparator");
|
|
|
|
var countEnabledMenuCmds = 0;
|
|
|
|
for (var i = 0; i < contextMenu.children.length; i++) {
|
|
|
|
if (contextMenu.children[i].nodeName == "menuitem" &&
|
|
|
|
gViewController.isCommandEnabled(contextMenu.children[i].command)) {
|
|
|
|
countEnabledMenuCmds++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// with only one menu item, we hide the menu separator
|
|
|
|
menuSep.hidden = (countEnabledMenuCmds <= 1);
|
|
|
|
|
2010-09-02 21:41:06 -07:00
|
|
|
}, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
shutdown: function() {
|
2010-09-01 16:40:20 -07:00
|
|
|
Services.prefs.removeObserver(this.checkCompatibilityPref, this);
|
|
|
|
Services.prefs.removeObserver(PREF_CHECK_UPDATE_SECURITY, this);
|
2010-09-13 23:56:54 -07:00
|
|
|
Services.prefs.removeObserver(PREF_AUTOUPDATE_DEFAULT, this, false);
|
2010-09-01 16:40:20 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
AddonManager.removeInstallListener(this);
|
|
|
|
AddonManager.removeAddonListener(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
registerAddonListener: function(aListener, aAddonId) {
|
|
|
|
if (!(aAddonId in this._listeners))
|
|
|
|
this._listeners[aAddonId] = [];
|
|
|
|
else if (this._listeners[aAddonId].indexOf(aListener) != -1)
|
|
|
|
return;
|
|
|
|
this._listeners[aAddonId].push(aListener);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
unregisterAddonListener: function(aListener, aAddonId) {
|
|
|
|
if (!(aAddonId in this._listeners))
|
|
|
|
return;
|
|
|
|
var index = this._listeners[aAddonId].indexOf(aListener);
|
|
|
|
if (index == -1)
|
|
|
|
return;
|
|
|
|
this._listeners[aAddonId].splice(index, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
registerInstallListener: function(aListener) {
|
|
|
|
if (this._installListeners.indexOf(aListener) != -1)
|
|
|
|
return;
|
|
|
|
this._installListeners.push(aListener);
|
2010-04-29 10:37:34 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
unregisterInstallListener: function(aListener) {
|
|
|
|
var i = this._installListeners.indexOf(aListener);
|
|
|
|
if (i == -1)
|
|
|
|
return;
|
|
|
|
this._installListeners.splice(i, 1);
|
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
delegateAddonEvent: function(aEvent, aParams) {
|
|
|
|
var addon = aParams.shift();
|
|
|
|
if (!(addon.id in this._listeners))
|
|
|
|
return;
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var listeners = this._listeners[addon.id];
|
|
|
|
for (let i = 0; i < listeners.length; i++) {
|
|
|
|
let listener = listeners[i];
|
|
|
|
if (!(aEvent in listener))
|
|
|
|
continue;
|
|
|
|
try {
|
|
|
|
listener[aEvent].apply(listener, aParams);
|
|
|
|
} catch(e) {
|
|
|
|
// this shouldn't be fatal
|
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
delegateInstallEvent: function(aEvent, aParams) {
|
2010-10-18 11:11:05 -07:00
|
|
|
var existingAddon = aEvent == "onExternalInstall" ? aParams[1] : aParams[0].existingAddon;
|
|
|
|
// If the install is an update then send the event to all listeners
|
|
|
|
// registered for the existing add-on
|
|
|
|
if (existingAddon)
|
|
|
|
this.delegateAddonEvent(aEvent, [existingAddon].concat(aParams));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
for (let i = 0; i < this._installListeners.length; i++) {
|
|
|
|
let listener = this._installListeners[i];
|
|
|
|
if (!(aEvent in listener))
|
|
|
|
continue;
|
|
|
|
try {
|
|
|
|
listener[aEvent].apply(listener, aParams);
|
|
|
|
} catch(e) {
|
|
|
|
// this shouldn't be fatal
|
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-09-01 16:40:20 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
refreshGlobalWarning: function() {
|
|
|
|
var page = document.getElementById("addons-page");
|
|
|
|
|
|
|
|
if (Services.appinfo.inSafeMode) {
|
|
|
|
page.setAttribute("warning", "safemode");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var checkUpdateSecurity = true;
|
|
|
|
var checkUpdateSecurityDefault = true;
|
|
|
|
try {
|
|
|
|
checkUpdateSecurity = Services.prefs.getBoolPref(PREF_CHECK_UPDATE_SECURITY);
|
|
|
|
} catch(e) { }
|
|
|
|
try {
|
|
|
|
var defaultBranch = Services.prefs.getDefaultBranch("");
|
|
|
|
checkUpdateSecurityDefault = defaultBranch.getBoolPref(PREF_CHECK_UPDATE_SECURITY);
|
|
|
|
} catch(e) { }
|
|
|
|
if (checkUpdateSecurityDefault && !checkUpdateSecurity) {
|
|
|
|
page.setAttribute("warning", "updatesecurity");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var checkCompatibility = true;
|
|
|
|
try {
|
|
|
|
checkCompatibility = Services.prefs.getBoolPref(this.checkCompatibilityPref);
|
|
|
|
} catch(e) { }
|
|
|
|
if (!checkCompatibility) {
|
|
|
|
page.setAttribute("warning", "checkcompatibility");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
page.removeAttribute("warning");
|
|
|
|
},
|
|
|
|
|
2010-09-13 23:56:54 -07:00
|
|
|
refreshAutoUpdateDefault: function() {
|
|
|
|
var defaultEnable = true;
|
|
|
|
try {
|
|
|
|
defaultEnable = Services.prefs.getBoolPref(PREF_AUTOUPDATE_DEFAULT);
|
|
|
|
} catch(e) { }
|
|
|
|
document.getElementById("utils-autoUpdateDefault").setAttribute("checked",
|
|
|
|
defaultEnable);
|
|
|
|
document.getElementById("utils-resetAddonUpdatesToAutomatic").hidden = !defaultEnable;
|
|
|
|
document.getElementById("utils-resetAddonUpdatesToManual").hidden = defaultEnable;
|
|
|
|
},
|
|
|
|
|
2010-09-01 16:40:20 -07:00
|
|
|
observe: function(aSubject, aTopic, aData) {
|
|
|
|
switch (aData) {
|
|
|
|
case this.checkCompatibilityPref:
|
|
|
|
case PREF_CHECK_UPDATE_SECURITY:
|
|
|
|
this.refreshGlobalWarning();
|
|
|
|
break;
|
2010-09-13 23:56:54 -07:00
|
|
|
case PREF_AUTOUPDATE_DEFAULT:
|
|
|
|
this.refreshAutoUpdateDefault();
|
|
|
|
break;
|
2010-09-01 16:40:20 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-28 12:13:14 -08:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var gViewController = {
|
|
|
|
viewPort: null,
|
|
|
|
currentViewId: "",
|
|
|
|
currentViewObj: null,
|
2010-06-16 20:13:20 -07:00
|
|
|
currentViewRequest: 0,
|
2010-05-06 11:12:59 -07:00
|
|
|
viewObjects: {},
|
2010-07-26 12:42:06 -07:00
|
|
|
viewChangeCallback: null,
|
2010-08-27 15:23:53 -07:00
|
|
|
initialViewSelected: false,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
initialize: function() {
|
|
|
|
this.viewPort = document.getElementById("view-port");
|
2008-01-28 09:11:48 -08:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
this.viewObjects["search"] = gSearchView;
|
|
|
|
this.viewObjects["discover"] = gDiscoverView;
|
|
|
|
this.viewObjects["list"] = gListView;
|
|
|
|
this.viewObjects["detail"] = gDetailView;
|
2010-06-02 02:13:03 -07:00
|
|
|
this.viewObjects["updates"] = gUpdatesView;
|
2008-01-28 09:11:48 -08:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
for each (let view in this.viewObjects)
|
|
|
|
view.initialize();
|
2008-01-28 09:11:48 -08:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
window.controllers.appendController(this);
|
2010-09-28 13:24:27 -07:00
|
|
|
|
|
|
|
window.addEventListener("popstate",
|
|
|
|
gViewController.statePopped.bind(gViewController),
|
|
|
|
false);
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2008-01-28 09:11:48 -08:00
|
|
|
|
2010-06-16 20:13:20 -07:00
|
|
|
shutdown: function() {
|
2010-07-26 12:42:06 -07:00
|
|
|
if (this.currentViewObj)
|
|
|
|
this.currentViewObj.hide();
|
2010-06-16 20:13:20 -07:00
|
|
|
this.currentViewRequest = 0;
|
2010-06-02 02:13:03 -07:00
|
|
|
|
|
|
|
for each(let view in this.viewObjects) {
|
|
|
|
if ("shutdown" in view) {
|
|
|
|
try {
|
|
|
|
view.shutdown();
|
|
|
|
} catch(e) {
|
|
|
|
// this shouldn't be fatal
|
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-16 20:13:20 -07:00
|
|
|
},
|
|
|
|
|
2010-08-27 15:23:53 -07:00
|
|
|
statePopped: function(e) {
|
|
|
|
// If this is a navigation to a previous state then load that state
|
|
|
|
if (e.state) {
|
|
|
|
this.loadViewInternal(e.state.view, e.state.previousView);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the initial view has already been selected (by a call to loadView) then
|
|
|
|
// bail out now
|
|
|
|
if (this.initialViewSelected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Otherwise load the default view
|
|
|
|
var view = VIEW_DEFAULT;
|
|
|
|
if (gCategories.node.selectedItem &&
|
|
|
|
gCategories.node.selectedItem.id != "category-search")
|
|
|
|
view = gCategories.node.selectedItem.value;
|
|
|
|
|
|
|
|
if ("arguments" in window && window.arguments.length > 0) {
|
|
|
|
if ("view" in window.arguments[0])
|
|
|
|
view = window.arguments[0].view;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loadInitialView(view);
|
|
|
|
},
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
parseViewId: function(aViewId) {
|
|
|
|
var matchRegex = /^addons:\/\/([^\/]+)\/(.*)$/;
|
|
|
|
var [,viewType, viewParam] = aViewId.match(matchRegex) || [];
|
|
|
|
return {type: viewType, param: decodeURIComponent(viewParam)};
|
|
|
|
},
|
2008-01-28 09:11:48 -08:00
|
|
|
|
2010-06-24 12:50:04 -07:00
|
|
|
get isLoading() {
|
2010-08-27 15:23:53 -07:00
|
|
|
return !this.currentViewObj || this.currentViewObj.node.hasAttribute("loading");
|
2010-06-24 12:50:04 -07:00
|
|
|
},
|
|
|
|
|
2010-08-27 15:23:53 -07:00
|
|
|
loadView: function(aViewId) {
|
2010-05-06 11:12:59 -07:00
|
|
|
if (aViewId == this.currentViewId)
|
|
|
|
return;
|
2008-01-28 09:11:48 -08:00
|
|
|
|
2010-09-28 13:24:27 -07:00
|
|
|
gHistory.pushState({
|
2010-08-27 15:23:53 -07:00
|
|
|
view: aViewId,
|
|
|
|
previousView: this.currentViewId
|
|
|
|
}, document.title);
|
|
|
|
this.loadViewInternal(aViewId, this.currentViewId);
|
|
|
|
},
|
|
|
|
|
|
|
|
loadInitialView: function(aViewId) {
|
2010-09-28 13:24:27 -07:00
|
|
|
gHistory.replaceState({
|
2010-08-27 15:23:53 -07:00
|
|
|
view: aViewId,
|
|
|
|
previousView: null
|
|
|
|
}, document.title);
|
|
|
|
|
|
|
|
this.loadViewInternal(aViewId, null);
|
|
|
|
this.initialViewSelected = true;
|
|
|
|
notifyInitialized();
|
|
|
|
},
|
|
|
|
|
|
|
|
loadViewInternal: function(aViewId, aPreviousView) {
|
2010-05-06 11:12:59 -07:00
|
|
|
var view = this.parseViewId(aViewId);
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
if (!view.type || !(view.type in this.viewObjects))
|
|
|
|
throw new Error("Invalid view: " + view.type);
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var viewObj = this.viewObjects[view.type];
|
|
|
|
if (!viewObj.node)
|
|
|
|
throw new Error("Root node doesn't exist for '" + view.type + "' view");
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
if (this.currentViewObj) {
|
|
|
|
try {
|
|
|
|
let canHide = this.currentViewObj.hide();
|
|
|
|
if (canHide === false)
|
|
|
|
return;
|
2010-06-16 20:13:20 -07:00
|
|
|
this.viewPort.selectedPanel.removeAttribute("loading");
|
2010-05-06 11:12:59 -07:00
|
|
|
} catch (e) {
|
|
|
|
// this shouldn't be fatal
|
|
|
|
Cu.reportError(e);
|
2008-01-28 09:11:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-27 15:23:53 -07:00
|
|
|
gCategories.select(aViewId, aPreviousView);
|
2008-01-28 09:11:48 -08:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
this.currentViewId = aViewId;
|
|
|
|
this.currentViewObj = viewObj;
|
2007-08-09 19:47:48 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
this.viewPort.selectedPanel = this.currentViewObj.node;
|
2010-06-16 20:13:20 -07:00
|
|
|
this.viewPort.selectedPanel.setAttribute("loading", "true");
|
|
|
|
this.currentViewObj.show(view.param, ++this.currentViewRequest);
|
|
|
|
},
|
|
|
|
|
2010-08-27 15:23:53 -07:00
|
|
|
// Moves back in the document history and removes the current history entry
|
|
|
|
popState: function(aCallback) {
|
2010-09-28 13:24:27 -07:00
|
|
|
this.viewChangeCallback = aCallback;
|
|
|
|
gHistory.popState();
|
2010-08-27 15:23:53 -07:00
|
|
|
},
|
|
|
|
|
2010-06-16 20:13:20 -07:00
|
|
|
notifyViewChanged: function() {
|
|
|
|
this.viewPort.selectedPanel.removeAttribute("loading");
|
2010-07-26 12:42:06 -07:00
|
|
|
|
2010-08-27 15:23:53 -07:00
|
|
|
if (this.viewChangeCallback) {
|
2010-07-26 12:42:06 -07:00
|
|
|
this.viewChangeCallback();
|
2010-08-27 15:23:53 -07:00
|
|
|
this.viewChangeCallback = null;
|
|
|
|
}
|
2010-07-26 12:42:06 -07:00
|
|
|
|
2010-06-16 20:13:20 -07:00
|
|
|
var event = document.createEvent("Events");
|
|
|
|
event.initEvent("ViewChanged", true, true);
|
|
|
|
this.currentViewObj.node.dispatchEvent(event);
|
2010-05-01 11:04:44 -07:00
|
|
|
},
|
2007-08-09 19:47:48 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
commands: {
|
2010-10-07 15:11:35 -07:00
|
|
|
cmd_back: {
|
|
|
|
isEnabled: function() {
|
2010-10-26 10:45:15 -07:00
|
|
|
return gHistory.canGoBack;
|
2010-10-07 15:11:35 -07:00
|
|
|
},
|
|
|
|
doCommand: function() {
|
2010-10-26 10:45:15 -07:00
|
|
|
gHistory.back();
|
2010-10-07 15:11:35 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cmd_forward: {
|
|
|
|
isEnabled: function() {
|
2010-10-26 10:45:15 -07:00
|
|
|
return gHistory.canGoForward;
|
2010-10-07 15:11:35 -07:00
|
|
|
},
|
|
|
|
doCommand: function() {
|
2010-10-26 10:45:15 -07:00
|
|
|
gHistory.forward();
|
2010-10-07 15:11:35 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
cmd_restartApp: {
|
|
|
|
isEnabled: function() true,
|
|
|
|
doCommand: function() {
|
2010-09-13 10:48:24 -07:00
|
|
|
let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].
|
|
|
|
createInstance(Ci.nsISupportsPRBool);
|
|
|
|
Services.obs.notifyObservers(cancelQuit, "quit-application-requested",
|
|
|
|
"restart");
|
|
|
|
if (cancelQuit.data)
|
|
|
|
return; // somebody canceled our quit request
|
|
|
|
|
|
|
|
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].
|
|
|
|
getService(Ci.nsIAppStartup);
|
|
|
|
appStartup.quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart);
|
2010-05-06 11:12:59 -07:00
|
|
|
}
|
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-09-01 16:40:20 -07:00
|
|
|
cmd_enableCheckCompatibility: {
|
|
|
|
isEnabled: function() true,
|
|
|
|
doCommand: function() {
|
|
|
|
Services.prefs.clearUserPref(gEventManager.checkCompatibilityPref);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cmd_enableUpdateSecurity: {
|
|
|
|
isEnabled: function() true,
|
|
|
|
doCommand: function() {
|
|
|
|
Services.prefs.clearUserPref(PREF_CHECK_UPDATE_SECURITY);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-09-13 23:56:54 -07:00
|
|
|
cmd_toggleAutoUpdateDefault: {
|
|
|
|
isEnabled: function() true,
|
|
|
|
doCommand: function() {
|
|
|
|
var oldValue = true;
|
|
|
|
try {
|
|
|
|
oldValue = Services.prefs.getBoolPref(PREF_AUTOUPDATE_DEFAULT);
|
|
|
|
} catch(e) { }
|
|
|
|
Services.prefs.setBoolPref(PREF_AUTOUPDATE_DEFAULT, !oldValue);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cmd_resetAddonAutoUpdate: {
|
|
|
|
isEnabled: function() true,
|
|
|
|
doCommand: function() {
|
|
|
|
AddonManager.getAllAddons(function(aAddonList) {
|
|
|
|
aAddonList.forEach(function(aAddon) {
|
|
|
|
if ("applyBackgroundUpdates" in aAddon)
|
|
|
|
aAddon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DEFAULT;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
cmd_goToDiscoverPane: {
|
|
|
|
isEnabled: function() {
|
|
|
|
return gDiscoverView.enabled;
|
|
|
|
},
|
|
|
|
doCommand: function() {
|
|
|
|
gViewController.loadView("addons://discover/");
|
|
|
|
}
|
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-06-02 02:13:03 -07:00
|
|
|
cmd_goToRecentUpdates: {
|
|
|
|
isEnabled: function() true,
|
|
|
|
doCommand: function() {
|
|
|
|
gViewController.loadView("addons://updates/recent");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cmd_goToAvailableUpdates: {
|
|
|
|
isEnabled: function() true,
|
|
|
|
doCommand: function() {
|
|
|
|
gViewController.loadView("addons://updates/available");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
cmd_showItemDetails: {
|
|
|
|
isEnabled: function(aAddon) {
|
2010-10-07 10:29:17 -07:00
|
|
|
return !!aAddon && (gViewController.currentViewObj != gDetailView);
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
|
|
|
doCommand: function(aAddon) {
|
|
|
|
gViewController.loadView("addons://detail/" +
|
|
|
|
encodeURIComponent(aAddon.id));
|
|
|
|
}
|
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
cmd_findAllUpdates: {
|
2010-06-02 02:13:03 -07:00
|
|
|
inProgress: false,
|
|
|
|
isEnabled: function() !this.inProgress,
|
2010-05-06 11:12:59 -07:00
|
|
|
doCommand: function() {
|
2010-06-02 02:13:03 -07:00
|
|
|
this.inProgress = true;
|
|
|
|
gViewController.updateCommand("cmd_findAllUpdates");
|
2010-05-06 11:12:59 -07:00
|
|
|
document.getElementById("updates-noneFound").hidden = true;
|
|
|
|
document.getElementById("updates-progress").hidden = false;
|
2010-10-15 10:00:03 -07:00
|
|
|
document.getElementById("updates-manualUpdatesFound-btn").hidden = true;
|
2010-05-06 11:12:59 -07:00
|
|
|
|
|
|
|
var pendingChecks = 0;
|
|
|
|
var numUpdated = 0;
|
2010-06-02 02:13:03 -07:00
|
|
|
var numManualUpdates = 0;
|
2010-05-06 11:12:59 -07:00
|
|
|
var restartNeeded = false;
|
2010-09-13 23:56:54 -07:00
|
|
|
var autoUpdateDefault = AddonManager.autoUpdateDefault;
|
2010-06-02 02:13:03 -07:00
|
|
|
var self = this;
|
2010-05-06 11:12:59 -07:00
|
|
|
|
|
|
|
function updateStatus() {
|
|
|
|
if (pendingChecks > 0)
|
|
|
|
return;
|
2010-06-02 02:13:03 -07:00
|
|
|
|
|
|
|
self.inProgress = false;
|
|
|
|
gViewController.updateCommand("cmd_findAllUpdates");
|
2010-05-06 11:12:59 -07:00
|
|
|
document.getElementById("updates-progress").hidden = true;
|
2010-06-02 02:13:03 -07:00
|
|
|
gUpdatesView.maybeRefresh();
|
|
|
|
|
|
|
|
if (numManualUpdates > 0 && numUpdated == 0) {
|
2010-10-15 10:00:03 -07:00
|
|
|
document.getElementById("updates-manualUpdatesFound-btn").hidden = false;
|
2010-06-02 02:13:03 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
|
|
|
|
if (numUpdated == 0) {
|
2010-05-06 11:21:23 -07:00
|
|
|
document.getElementById("updates-noneFound").hidden = false;
|
2010-05-06 11:12:59 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
if (restartNeeded) {
|
|
|
|
document.getElementById("updates-downloaded").hidden = false;
|
2010-10-15 10:00:03 -07:00
|
|
|
document.getElementById("updates-restart-btn").hidden = false;
|
2010-05-06 11:12:59 -07:00
|
|
|
} else {
|
|
|
|
document.getElementById("updates-installed").hidden = false;
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var updateInstallListener = {
|
|
|
|
onDownloadFailed: function() {
|
|
|
|
pendingChecks--;
|
|
|
|
updateStatus();
|
|
|
|
},
|
|
|
|
onInstallFailed: function() {
|
|
|
|
pendingChecks--;
|
|
|
|
updateStatus();
|
|
|
|
},
|
|
|
|
onInstallEnded: function(aInstall, aAddon) {
|
|
|
|
pendingChecks--;
|
|
|
|
numUpdated++;
|
|
|
|
if (isPending(aInstall.existingAddon, "upgrade"))
|
|
|
|
restartNeeded = true;
|
|
|
|
updateStatus();
|
|
|
|
}
|
|
|
|
};
|
2010-04-29 10:37:34 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var updateCheckListener = {
|
|
|
|
onUpdateAvailable: function(aAddon, aInstall) {
|
|
|
|
gEventManager.delegateAddonEvent("onUpdateAvailable",
|
|
|
|
[aAddon, aInstall]);
|
2010-09-13 23:56:54 -07:00
|
|
|
if (shouldAutoUpdate(aAddon, autoUpdateDefault)) {
|
2010-06-02 02:13:03 -07:00
|
|
|
aInstall.addListener(updateInstallListener);
|
|
|
|
aInstall.install();
|
|
|
|
} else {
|
|
|
|
pendingChecks--;
|
|
|
|
numManualUpdates++;
|
|
|
|
updateStatus();
|
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
|
|
|
onNoUpdateAvailable: function(aAddon) {
|
|
|
|
pendingChecks--;
|
|
|
|
updateStatus();
|
|
|
|
},
|
|
|
|
onUpdateFinished: function(aAddon, aError) {
|
|
|
|
gEventManager.delegateAddonEvent("onUpdateFinished",
|
|
|
|
[aAddon, aError]);
|
|
|
|
}
|
|
|
|
};
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
AddonManager.getAddonsByTypes(null, function(aAddonList) {
|
|
|
|
aAddonList.forEach(function(aAddon) {
|
|
|
|
if (aAddon.permissions & AddonManager.PERM_CAN_UPGRADE) {
|
|
|
|
pendingChecks++;
|
|
|
|
aAddon.findUpdates(updateCheckListener,
|
|
|
|
AddonManager.UPDATE_WHEN_USER_REQUESTED);
|
|
|
|
}
|
|
|
|
});
|
2010-05-24 13:16:29 -07:00
|
|
|
|
|
|
|
if (pendingChecks == 0)
|
|
|
|
updateStatus();
|
2010-05-06 11:12:59 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
cmd_findItemUpdates: {
|
|
|
|
isEnabled: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return false;
|
|
|
|
return hasPermission(aAddon, "upgrade");
|
|
|
|
},
|
|
|
|
doCommand: function(aAddon) {
|
|
|
|
var listener = {
|
|
|
|
onUpdateAvailable: function(aAddon, aInstall) {
|
|
|
|
gEventManager.delegateAddonEvent("onUpdateAvailable",
|
|
|
|
[aAddon, aInstall]);
|
2010-09-13 23:56:54 -07:00
|
|
|
if (shouldAutoUpdate(aAddon))
|
2010-06-02 02:13:03 -07:00
|
|
|
aInstall.install();
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
|
|
|
onNoUpdateAvailable: function(aAddon) {
|
|
|
|
gEventManager.delegateAddonEvent("onNoUpdateAvailable",
|
|
|
|
[aAddon]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
gEventManager.delegateAddonEvent("onCheckingUpdate", [aAddon]);
|
|
|
|
aAddon.findUpdates(listener, AddonManager.UPDATE_WHEN_USER_REQUESTED);
|
2010-05-01 11:04:44 -07:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
cmd_showItemPreferences: {
|
|
|
|
isEnabled: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return false;
|
|
|
|
return aAddon.isActive && !!aAddon.optionsURL;
|
|
|
|
},
|
|
|
|
doCommand: function(aAddon) {
|
|
|
|
var optionsURL = aAddon.optionsURL;
|
|
|
|
var windows = Services.wm.getEnumerator(null);
|
|
|
|
while (windows.hasMoreElements()) {
|
|
|
|
var win = windows.getNext();
|
|
|
|
if (win.document.documentURI == optionsURL) {
|
|
|
|
win.focus();
|
|
|
|
return;
|
2008-03-07 16:16:38 -08:00
|
|
|
}
|
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
var features = "chrome,titlebar,toolbar,centerscreen";
|
|
|
|
try {
|
|
|
|
var instantApply = Services.prefs.getBoolPref("browser.preferences.instantApply");
|
|
|
|
features += instantApply ? ",dialog=no" : ",modal";
|
|
|
|
} catch (e) {
|
|
|
|
features += ",modal";
|
|
|
|
}
|
|
|
|
openDialog(optionsURL, "", features);
|
2008-03-07 16:16:38 -08:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
cmd_showItemAbout: {
|
|
|
|
isEnabled: function(aAddon) {
|
|
|
|
// XXXunf This may be applicable to install items too. See bug 561260
|
|
|
|
return !!aAddon;
|
|
|
|
},
|
|
|
|
doCommand: function(aAddon) {
|
|
|
|
var aboutURL = aAddon.aboutURL;
|
|
|
|
if (aboutURL)
|
|
|
|
openDialog(aboutURL, "", "chrome,centerscreen,modal");
|
|
|
|
else
|
|
|
|
openDialog("chrome://mozapps/content/extensions/about.xul",
|
|
|
|
"", "chrome,centerscreen,modal", aAddon);
|
2008-03-07 16:16:38 -08:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2008-03-07 16:16:38 -08:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
cmd_enableItem: {
|
|
|
|
isEnabled: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return false;
|
|
|
|
return hasPermission(aAddon, "enable");
|
|
|
|
},
|
|
|
|
doCommand: function(aAddon) {
|
|
|
|
aAddon.userDisabled = false;
|
2010-07-29 10:35:34 -07:00
|
|
|
},
|
|
|
|
getTooltip: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return "";
|
|
|
|
if (aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_ENABLE)
|
|
|
|
return gStrings.ext.GetStringFromName("enableAddonRestartRequiredTooltip");
|
|
|
|
return gStrings.ext.GetStringFromName("enableAddonTooltip");
|
2008-03-07 16:16:38 -08:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2007-08-07 23:58:22 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
cmd_disableItem: {
|
|
|
|
isEnabled: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return false;
|
|
|
|
return hasPermission(aAddon, "disable");
|
|
|
|
},
|
|
|
|
doCommand: function(aAddon) {
|
|
|
|
aAddon.userDisabled = true;
|
2010-07-29 10:35:34 -07:00
|
|
|
},
|
|
|
|
getTooltip: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return "";
|
|
|
|
if (aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_DISABLE)
|
|
|
|
return gStrings.ext.GetStringFromName("disableAddonRestartRequiredTooltip");
|
|
|
|
return gStrings.ext.GetStringFromName("disableAddonTooltip");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2007-08-07 23:58:22 -07:00
|
|
|
|
2010-09-01 09:57:48 -07:00
|
|
|
cmd_installItem: {
|
|
|
|
isEnabled: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return false;
|
|
|
|
return aAddon.install && aAddon.install.state == AddonManager.STATE_AVAILABLE;
|
|
|
|
},
|
|
|
|
doCommand: function(aAddon) {
|
2010-09-02 21:41:06 -07:00
|
|
|
function doInstall() {
|
2010-09-01 09:57:48 -07:00
|
|
|
gViewController.currentViewObj.getListItemForID(aAddon.id)._installStatus.installRemote();
|
2010-09-02 21:41:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gViewController.currentViewObj == gDetailView)
|
|
|
|
gViewController.popState(doInstall);
|
|
|
|
else
|
|
|
|
doInstall();
|
2010-09-01 09:57:48 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
cmd_uninstallItem: {
|
|
|
|
isEnabled: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return false;
|
|
|
|
return hasPermission(aAddon, "uninstall");
|
|
|
|
},
|
|
|
|
doCommand: function(aAddon) {
|
2010-07-26 12:42:06 -07:00
|
|
|
if (gViewController.currentViewObj != gDetailView) {
|
|
|
|
aAddon.uninstall();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-27 15:23:53 -07:00
|
|
|
gViewController.popState(function() {
|
2010-07-26 12:42:06 -07:00
|
|
|
gViewController.currentViewObj.getListItemForID(aAddon.id).uninstall();
|
|
|
|
});
|
2010-07-29 10:35:34 -07:00
|
|
|
},
|
|
|
|
getTooltip: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return "";
|
|
|
|
if (aAddon.operationsRequiringRestart & AddonManager.OP_NEEDS_RESTART_UNINSTALL)
|
|
|
|
return gStrings.ext.GetStringFromName("uninstallAddonRestartRequiredTooltip");
|
|
|
|
return gStrings.ext.GetStringFromName("uninstallAddonTooltip");
|
2010-05-01 11:04:44 -07:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2008-03-14 16:34:32 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
cmd_cancelUninstallItem: {
|
|
|
|
isEnabled: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return false;
|
|
|
|
return isPending(aAddon, "uninstall");
|
|
|
|
},
|
|
|
|
doCommand: function(aAddon) {
|
|
|
|
aAddon.cancelUninstall();
|
2008-10-15 06:56:25 -07:00
|
|
|
}
|
2010-06-01 18:41:41 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
cmd_installFromFile: {
|
|
|
|
isEnabled: function() true,
|
|
|
|
doCommand: function() {
|
|
|
|
const nsIFilePicker = Ci.nsIFilePicker;
|
|
|
|
var fp = Cc["@mozilla.org/filepicker;1"]
|
|
|
|
.createInstance(nsIFilePicker);
|
|
|
|
fp.init(window,
|
|
|
|
gStrings.ext.GetStringFromName("installFromFile.dialogTitle"),
|
|
|
|
nsIFilePicker.modeOpenMultiple);
|
|
|
|
try {
|
|
|
|
fp.appendFilter(gStrings.ext.GetStringFromName("installFromFile.filterName"),
|
|
|
|
"*.xpi;*.jar");
|
|
|
|
fp.appendFilters(nsIFilePicker.filterAll);
|
|
|
|
} catch (e) { }
|
|
|
|
|
|
|
|
if (fp.show() != nsIFilePicker.returnOK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var files = fp.files;
|
|
|
|
var installs = [];
|
|
|
|
|
|
|
|
function buildNextInstall() {
|
|
|
|
if (!files.hasMoreElements()) {
|
|
|
|
if (installs.length > 0) {
|
|
|
|
// Display the normal install confirmation for the installs
|
|
|
|
AddonManager.installAddonsFromWebpage("application/x-xpinstall",
|
|
|
|
this, null, installs);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var file = files.getNext();
|
|
|
|
AddonManager.getInstallForFile(file, function(aInstall) {
|
|
|
|
installs.push(aInstall);
|
|
|
|
buildNextInstall();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
buildNextInstall();
|
|
|
|
}
|
2010-09-01 09:57:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
cmd_cancelOperation: {
|
|
|
|
isEnabled: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return false;
|
|
|
|
return aAddon.pendingOperations != AddonManager.PENDING_NONE;
|
|
|
|
},
|
|
|
|
doCommand: function(aAddon) {
|
|
|
|
if (isPending(aAddon, "install")) {
|
|
|
|
aAddon.install.cancel();
|
|
|
|
} else if (isPending(aAddon, "upgrade")) {
|
2010-10-06 10:14:46 -07:00
|
|
|
aAddon.pendingUpgrade.install.cancel();
|
2010-09-01 09:57:48 -07:00
|
|
|
} else if (isPending(aAddon, "uninstall")) {
|
|
|
|
aAddon.cancelUninstall();
|
|
|
|
} else if (isPending(aAddon, "enable")) {
|
|
|
|
aAddon.userDisabled = true;
|
|
|
|
} else if (isPending(aAddon, "disable")) {
|
|
|
|
aAddon.userDisabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cmd_contribute: {
|
|
|
|
isEnabled: function(aAddon) {
|
|
|
|
if (!aAddon)
|
|
|
|
return false;
|
2010-09-09 19:17:08 -07:00
|
|
|
return ("contributionURL" in aAddon && aAddon.contributionURL);
|
2010-09-01 09:57:48 -07:00
|
|
|
},
|
|
|
|
doCommand: function(aAddon) {
|
2010-09-09 19:17:08 -07:00
|
|
|
openURL(aAddon.contributionURL);
|
2010-09-01 09:57:48 -07:00
|
|
|
}
|
2008-03-14 16:34:32 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-07 23:58:22 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
supportsCommand: function(aCommand) {
|
|
|
|
return (aCommand in this.commands);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-07 23:58:22 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
isCommandEnabled: function(aCommand) {
|
|
|
|
if (!this.supportsCommand(aCommand))
|
|
|
|
return false;
|
|
|
|
var addon = this.currentViewObj.getSelectedAddon();
|
|
|
|
return this.commands[aCommand].isEnabled(addon);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
updateCommands: function() {
|
|
|
|
// wait until the view is initialized
|
|
|
|
if (!this.currentViewObj)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2010-05-06 11:12:59 -07:00
|
|
|
var addon = this.currentViewObj.getSelectedAddon();
|
2010-06-02 02:13:03 -07:00
|
|
|
for (let commandId in this.commands)
|
|
|
|
this.updateCommand(commandId, addon);
|
|
|
|
},
|
|
|
|
|
|
|
|
updateCommand: function(aCommandId, aAddon) {
|
|
|
|
if (typeof aAddon == "undefined")
|
|
|
|
aAddon = this.currentViewObj.getSelectedAddon();
|
|
|
|
var cmd = this.commands[aCommandId];
|
|
|
|
var cmdElt = document.getElementById(aCommandId);
|
|
|
|
cmdElt.setAttribute("disabled", !cmd.isEnabled(aAddon));
|
|
|
|
if ("getTooltip" in cmd) {
|
2010-08-02 17:59:51 -07:00
|
|
|
let tooltip = cmd.getTooltip(aAddon);
|
2010-06-02 02:13:03 -07:00
|
|
|
if (tooltip)
|
|
|
|
cmdElt.setAttribute("tooltiptext", tooltip);
|
|
|
|
else
|
|
|
|
cmdElt.removeAttribute("tooltiptext");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2010-06-23 16:35:21 -07:00
|
|
|
doCommand: function(aCommand, aAddon) {
|
2010-05-06 11:12:59 -07:00
|
|
|
if (!this.supportsCommand(aCommand))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2010-05-06 11:12:59 -07:00
|
|
|
var cmd = this.commands[aCommand];
|
2010-06-23 16:35:21 -07:00
|
|
|
if (!aAddon)
|
|
|
|
aAddon = this.currentViewObj.getSelectedAddon();
|
|
|
|
if (!cmd.isEnabled(aAddon))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2010-06-23 16:35:21 -07:00
|
|
|
cmd.doCommand(aAddon);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onEvent: function() {}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
function formatDate(aDate) {
|
|
|
|
return Cc["@mozilla.org/intl/scriptabledateformat;1"]
|
|
|
|
.getService(Ci.nsIScriptableDateFormat)
|
|
|
|
.FormatDate("",
|
|
|
|
Ci.nsIScriptableDateFormat.dateFormatLong,
|
|
|
|
aDate.getFullYear(),
|
|
|
|
aDate.getMonth() + 1,
|
|
|
|
aDate.getDate()
|
|
|
|
);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-09-05 18:20:11 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
function hasPermission(aAddon, aPerm) {
|
|
|
|
var perm = AddonManager["PERM_CAN_" + aPerm.toUpperCase()];
|
|
|
|
return !!(aAddon.permissions & perm);
|
2009-09-17 02:03:33 -07:00
|
|
|
}
|
|
|
|
|
2007-09-05 18:20:11 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
function isPending(aAddon, aAction) {
|
|
|
|
var action = AddonManager["PENDING_" + aAction.toUpperCase()];
|
|
|
|
return !!(aAddon.pendingOperations & action);
|
|
|
|
}
|
2007-09-05 18:20:11 -07:00
|
|
|
|
2010-06-02 02:13:03 -07:00
|
|
|
function isInState(aInstall, aState) {
|
|
|
|
var state = AddonManager["STATE_" + aState.toUpperCase()];
|
|
|
|
return aInstall.state == state;
|
|
|
|
}
|
|
|
|
|
2007-09-05 18:20:11 -07:00
|
|
|
|
2010-09-13 23:56:54 -07:00
|
|
|
function shouldAutoUpdate(aAddon, aDefault) {
|
|
|
|
if (!("applyBackgroundUpdates" in aAddon))
|
|
|
|
return false;
|
|
|
|
if (aAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_ENABLE)
|
|
|
|
return true;
|
|
|
|
if (aAddon.applyBackgroundUpdates == AddonManager.AUTOUPDATE_DISABLE)
|
|
|
|
return false;
|
|
|
|
return aDefault !== undefined ? aDefault : AddonManager.autoUpdateDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-23 10:46:05 -07:00
|
|
|
function createItem(aObj, aIsInstall, aIsRemote) {
|
2010-05-06 11:12:59 -07:00
|
|
|
let item = document.createElement("richlistitem");
|
2007-09-05 18:20:11 -07:00
|
|
|
|
2010-09-01 09:57:48 -07:00
|
|
|
item.setAttribute("class", "addon addon-view");
|
2010-05-06 11:12:59 -07:00
|
|
|
item.setAttribute("name", aObj.name);
|
|
|
|
item.setAttribute("type", aObj.type);
|
2010-07-19 16:01:23 -07:00
|
|
|
item.setAttribute("remote", !!aIsRemote);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
if (aIsInstall) {
|
|
|
|
item.mInstall = aObj;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-23 10:46:05 -07:00
|
|
|
if (aObj.state != AddonManager.STATE_INSTALLED) {
|
|
|
|
item.setAttribute("status", "installing");
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
aObj = aObj.addon;
|
|
|
|
}
|
2008-09-04 03:11:52 -07:00
|
|
|
|
2010-08-23 10:46:05 -07:00
|
|
|
item.mAddon = aObj;
|
2008-09-04 03:11:52 -07:00
|
|
|
|
2010-08-23 10:46:05 -07:00
|
|
|
item.setAttribute("status", "installed");
|
|
|
|
|
|
|
|
// set only attributes needed for sorting and XBL binding,
|
|
|
|
// the binding handles the rest
|
|
|
|
item.setAttribute("value", aObj.id);
|
|
|
|
|
2010-12-02 17:52:34 -08:00
|
|
|
return item;
|
2010-11-30 14:18:00 -08:00
|
|
|
}
|
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
function sortElements(aElements, aSortBy, aAscending) {
|
|
|
|
const DATE_FIELDS = ["updateDate"];
|
|
|
|
const INTEGER_FIELDS = ["size", "relevancescore"];
|
|
|
|
|
|
|
|
function dateCompare(a, b) {
|
|
|
|
var aTime = a.getTime();
|
|
|
|
var bTime = b.getTime();
|
|
|
|
if (aTime < bTime)
|
|
|
|
return -1;
|
|
|
|
if (aTime > bTime)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function intCompare(a, b) {
|
|
|
|
return a - b;
|
|
|
|
}
|
|
|
|
|
|
|
|
function stringCompare(a, b) {
|
|
|
|
return a.localeCompare(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getValue(aObj) {
|
|
|
|
if (!aObj)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if (aObj.hasAttribute(aSortBy))
|
|
|
|
return aObj.getAttribute(aSortBy);
|
|
|
|
|
|
|
|
addon = aObj.mAddon || aObj.mInstall;
|
|
|
|
if (!addon)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return addon[aSortBy];
|
|
|
|
}
|
|
|
|
|
|
|
|
var sortFunc = stringCompare;
|
|
|
|
if (DATE_FIELDS.indexOf(aSortBy) != -1)
|
|
|
|
sortFunc = dateCompare;
|
|
|
|
else if (INTEGER_FIELDS.indexOf(aSortBy) != -1)
|
|
|
|
sortFunc = intCompare;
|
|
|
|
|
|
|
|
aElements.sort(function(a, b) {
|
|
|
|
if (!aAscending)
|
|
|
|
[a, b] = [b, a];
|
|
|
|
|
|
|
|
var aValue = getValue(a);
|
|
|
|
var bValue = getValue(b);
|
|
|
|
|
|
|
|
if (!aValue && !bValue)
|
|
|
|
return 0;
|
|
|
|
if (!aValue)
|
|
|
|
return -1;
|
|
|
|
if (!bValue)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return sortFunc(aValue, bValue);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function sortList(aList, aSortBy, aAscending) {
|
|
|
|
var elements = Array.slice(aList.childNodes, 0);
|
|
|
|
sortElements(elements, aSortBy, aAscending);
|
|
|
|
|
|
|
|
while (aList.listChild)
|
|
|
|
aList.removeChild(aList.lastChild);
|
|
|
|
|
|
|
|
elements.forEach(function(aElement) {
|
|
|
|
aList.appendChild(aElement);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-06-24 12:50:04 -07:00
|
|
|
function getAddonsAndInstalls(aType, aCallback) {
|
2010-12-10 13:01:08 -08:00
|
|
|
let addons = null, installs = null;
|
|
|
|
let types = (aType != null) ? [aType] : null;
|
2010-06-24 12:50:04 -07:00
|
|
|
|
2010-12-10 13:01:08 -08:00
|
|
|
AddonManager.getAddonsByTypes(types, function(aAddonsList) {
|
2010-06-24 12:50:04 -07:00
|
|
|
addons = aAddonsList;
|
|
|
|
if (installs != null)
|
|
|
|
aCallback(addons, installs);
|
|
|
|
});
|
|
|
|
|
2010-12-10 13:01:08 -08:00
|
|
|
AddonManager.getInstallsByTypes(types, function(aInstallsList) {
|
2010-06-24 12:50:04 -07:00
|
|
|
// skip over upgrade installs and non-active installs
|
|
|
|
installs = aInstallsList.filter(function(aInstall) {
|
|
|
|
return !(aInstall.existingAddon ||
|
|
|
|
aInstall.state == AddonManager.STATE_AVAILABLE);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (addons != null)
|
|
|
|
aCallback(addons, installs)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-12-10 18:32:10 -08:00
|
|
|
function doPendingUninstalls(aListBox) {
|
|
|
|
// Uninstalling add-ons can mutate the list so find the add-ons first then
|
|
|
|
// uninstall them
|
|
|
|
var items = [];
|
|
|
|
var listitem = aListBox.firstChild;
|
|
|
|
while (listitem) {
|
|
|
|
if (listitem.getAttribute("pending") == "uninstall" &&
|
|
|
|
!listitem.isPending("uninstall"))
|
|
|
|
items.push(listitem.mAddon);
|
|
|
|
listitem = listitem.nextSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
items.forEach(function(aAddon) { aAddon.uninstall(); });
|
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var gCategories = {
|
|
|
|
node: null,
|
|
|
|
_search: null,
|
2010-08-11 09:55:12 -07:00
|
|
|
_maybeHidden: null,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
initialize: function() {
|
|
|
|
this.node = document.getElementById("categories");
|
|
|
|
this._search = this.get("addons://search/");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
this.maybeHideSearch();
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var self = this;
|
|
|
|
this.node.addEventListener("select", function() {
|
|
|
|
self.maybeHideSearch();
|
|
|
|
gViewController.loadView(self.node.selectedItem.value);
|
|
|
|
}, false);
|
2010-05-20 10:55:44 -07:00
|
|
|
|
|
|
|
this.node.addEventListener("click", function(aEvent) {
|
|
|
|
var selectedItem = self.node.selectedItem;
|
|
|
|
if (aEvent.target.localName == "richlistitem" &&
|
|
|
|
aEvent.target == selectedItem) {
|
|
|
|
var viewId = selectedItem.value;
|
|
|
|
|
|
|
|
if (gViewController.parseViewId(viewId).type == "search") {
|
|
|
|
viewId += encodeURIComponent(gHeader.searchQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
gViewController.loadView(viewId);
|
|
|
|
}
|
|
|
|
}, false);
|
2010-05-26 15:00:00 -07:00
|
|
|
|
2010-08-11 09:55:12 -07:00
|
|
|
this._maybeHidden = ["addons://list/locale", "addons://list/searchengine"];
|
|
|
|
gPendingInitializations += this._maybeHidden.length;
|
|
|
|
this._maybeHidden.forEach(function(aId) {
|
2010-05-26 15:00:00 -07:00
|
|
|
var type = gViewController.parseViewId(aId).param;
|
2010-06-24 12:50:04 -07:00
|
|
|
getAddonsAndInstalls(type, function(aAddonsList, aInstallsList) {
|
2010-08-11 09:55:12 -07:00
|
|
|
var hidden = (aAddonsList.length == 0 && aInstallsList.length == 0);
|
|
|
|
var item = self.get(aId);
|
|
|
|
|
|
|
|
// Don't load view that is becoming hidden
|
|
|
|
if (hidden && aId == gViewController.currentViewId)
|
|
|
|
gViewController.loadView(VIEW_DEFAULT);
|
|
|
|
|
|
|
|
item.hidden = hidden;
|
|
|
|
|
2010-06-24 12:50:04 -07:00
|
|
|
if (aAddonsList.length > 0 || aInstallsList.length > 0) {
|
|
|
|
notifyInitialized();
|
2010-05-26 15:00:00 -07:00
|
|
|
return;
|
2010-06-15 11:40:05 -07:00
|
|
|
}
|
2010-05-26 15:00:00 -07:00
|
|
|
|
|
|
|
gEventManager.registerInstallListener({
|
2010-06-24 12:50:04 -07:00
|
|
|
onDownloadStarted: function(aInstall) {
|
2010-05-26 15:00:00 -07:00
|
|
|
this._maybeShowCategory(aInstall);
|
|
|
|
},
|
|
|
|
|
|
|
|
onInstallStarted: function(aInstall) {
|
|
|
|
this._maybeShowCategory(aInstall);
|
|
|
|
},
|
|
|
|
|
|
|
|
onInstallEnded: function(aInstall, aAddon) {
|
|
|
|
this._maybeShowCategory(aAddon);
|
|
|
|
},
|
|
|
|
|
|
|
|
onExternalInstall: function(aAddon, aExistingAddon, aRequiresRestart) {
|
|
|
|
this._maybeShowCategory(aAddon);
|
|
|
|
},
|
|
|
|
|
|
|
|
_maybeShowCategory: function(aAddon) {
|
|
|
|
if (type == aAddon.type) {
|
|
|
|
self.get(aId).hidden = false;
|
|
|
|
gEventManager.unregisterInstallListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2010-06-24 12:50:04 -07:00
|
|
|
|
|
|
|
notifyInitialized();
|
2010-05-26 15:00:00 -07:00
|
|
|
});
|
|
|
|
});
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2010-08-11 09:55:12 -07:00
|
|
|
shutdown: function() {
|
|
|
|
// Force persist of hidden state. See bug 15232
|
|
|
|
var self = this;
|
|
|
|
this._maybeHidden.forEach(function(aId) {
|
|
|
|
var item = self.get(aId);
|
|
|
|
item.setAttribute("hidden", !!item.hidden);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2010-08-27 15:23:53 -07:00
|
|
|
select: function(aId, aPreviousView) {
|
|
|
|
var view = gViewController.parseViewId(aId);
|
|
|
|
if (view.type == "detail") {
|
|
|
|
aId = aPreviousView;
|
|
|
|
view = gViewController.parseViewId(aPreviousView);
|
|
|
|
}
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
if (this.node.selectedItem &&
|
2010-11-08 09:58:38 -08:00
|
|
|
this.node.selectedItem.value == aId) {
|
|
|
|
this.node.selectedItem.hidden = false;
|
|
|
|
this.node.selectedItem.disabled = false;
|
2010-05-06 11:12:59 -07:00
|
|
|
return;
|
2010-11-08 09:58:38 -08:00
|
|
|
}
|
2009-06-20 17:04:07 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
if (view.type == "search")
|
|
|
|
var item = this._search;
|
|
|
|
else
|
|
|
|
var item = this.get(aId);
|
2009-06-20 17:04:07 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
if (item) {
|
|
|
|
item.hidden = false;
|
2010-06-02 02:13:03 -07:00
|
|
|
item.disabled = false;
|
2010-05-06 11:12:59 -07:00
|
|
|
this.node.suppressOnSelect = true;
|
|
|
|
this.node.selectedItem = item;
|
|
|
|
this.node.suppressOnSelect = false;
|
|
|
|
this.node.ensureElementIsVisible(item);
|
2010-08-27 15:23:53 -07:00
|
|
|
// When supressing onselect last-selected doesn't get updated
|
|
|
|
this.node.setAttribute("last-selected", item.id);
|
2009-06-20 17:04:07 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
this.maybeHideSearch();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
get: function(aId) {
|
|
|
|
var items = document.getElementsByAttribute("value", aId);
|
|
|
|
if (items.length)
|
|
|
|
return items[0];
|
|
|
|
return null;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
setBadge: function(aId, aCount) {
|
|
|
|
let item = this.get(aId);
|
|
|
|
if (item)
|
|
|
|
item.badgeCount = aCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
maybeHideSearch: function() {
|
|
|
|
var view = gViewController.parseViewId(this.node.selectedItem.value);
|
|
|
|
this._search.disabled = view.type != "search";
|
|
|
|
}
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var gHeader = {
|
|
|
|
_search: null,
|
|
|
|
_dest: "",
|
2010-04-29 10:37:34 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
initialize: function() {
|
|
|
|
this._search = document.getElementById("header-search");
|
2008-01-28 12:13:14 -08:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
this._search.addEventListener("command", function(aEvent) {
|
|
|
|
var query = aEvent.target.value;
|
2010-07-19 16:01:23 -07:00
|
|
|
if (query.length == 0)
|
|
|
|
return false;
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
gViewController.loadView("addons://search/" + encodeURIComponent(query));
|
|
|
|
}, false);
|
2010-10-26 10:45:15 -07:00
|
|
|
|
|
|
|
if (this.shouldShowNavButtons) {
|
|
|
|
document.getElementById("back-btn").hidden = false;
|
|
|
|
document.getElementById("forward-btn").hidden = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get shouldShowNavButtons() {
|
|
|
|
var docshellItem = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShellTreeItem);
|
|
|
|
|
|
|
|
// If there is no outer frame then make the buttons visible
|
|
|
|
if (docshellItem.rootTreeItem == docshellItem)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
var outerWin = docshellItem.rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindow);
|
|
|
|
var outerDoc = outerWin.document;
|
|
|
|
var node = outerDoc.getElementById("back-button");
|
|
|
|
// If the outer frame has no back-button then make the buttons visible
|
|
|
|
if (!node)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If the back-button or any of its parents are hidden then make the buttons
|
|
|
|
// visible
|
|
|
|
while (node != outerDoc) {
|
|
|
|
var style = outerWin.getComputedStyle(node, "");
|
|
|
|
if (style.display == "none")
|
|
|
|
return true;
|
|
|
|
if (style.visibility != "visible")
|
|
|
|
return true;
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
get searchQuery() {
|
|
|
|
return this._search.value;
|
|
|
|
},
|
|
|
|
|
|
|
|
set searchQuery(aQuery) {
|
|
|
|
this._search.value = aQuery;
|
2010-07-19 16:01:23 -07:00
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
|
|
|
|
var gDiscoverView = {
|
|
|
|
node: null,
|
|
|
|
enabled: true,
|
2010-09-14 16:27:32 -07:00
|
|
|
// Set to true after the view is first shown. If initialization completes
|
|
|
|
// after this then it must also load the discover homepage
|
|
|
|
loaded: false,
|
2010-05-06 11:12:59 -07:00
|
|
|
_browser: null,
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
if (Services.prefs.getPrefType(PREF_DISCOVERURL) == Services.prefs.PREF_INVALID) {
|
|
|
|
this.enabled = false;
|
|
|
|
gCategories.get("addons://discover/").hidden = true;
|
|
|
|
return;
|
2010-05-01 11:04:44 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
this.node = document.getElementById("discover-view");
|
|
|
|
this._browser = document.getElementById("discover-browser");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var url = Cc["@mozilla.org/toolkit/URLFormatterService;1"]
|
|
|
|
.getService(Ci.nsIURLFormatter)
|
|
|
|
.formatURLPref(PREF_DISCOVERURL);
|
2010-05-14 12:57:58 -07:00
|
|
|
|
2010-11-08 09:59:20 -08:00
|
|
|
var browser = gDiscoverView._browser;
|
|
|
|
|
|
|
|
if (Services.prefs.getBoolPref(PREF_BACKGROUND_UPDATE) == false) {
|
|
|
|
browser.homePage = url;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-24 12:50:04 -07:00
|
|
|
gPendingInitializations++;
|
2010-05-14 12:57:58 -07:00
|
|
|
AddonManager.getAllAddons(function(aAddons) {
|
|
|
|
var list = {};
|
|
|
|
aAddons.forEach(function(aAddon) {
|
|
|
|
list[aAddon.id] = {
|
|
|
|
name: aAddon.name,
|
|
|
|
version: aAddon.version,
|
|
|
|
type: aAddon.type,
|
|
|
|
userDisabled: aAddon.userDisabled,
|
|
|
|
isCompatible: aAddon.isCompatible,
|
|
|
|
isBlocklisted: aAddon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-09-14 16:27:32 -07:00
|
|
|
browser.homePage = url + "#" + JSON.stringify(list);
|
|
|
|
|
2010-10-04 15:39:20 -07:00
|
|
|
if (gDiscoverView.loaded) {
|
|
|
|
browser.addEventListener("load", function() {
|
|
|
|
browser.removeEventListener("load", arguments.callee, true);
|
|
|
|
notifyInitialized();
|
|
|
|
}, true);
|
|
|
|
browser.goHome();
|
|
|
|
} else {
|
2010-10-04 15:36:07 -07:00
|
|
|
notifyInitialized();
|
2010-10-04 15:39:20 -07:00
|
|
|
}
|
2010-05-14 12:57:58 -07:00
|
|
|
});
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2008-01-28 06:22:37 -08:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
show: function() {
|
2010-10-04 15:39:20 -07:00
|
|
|
if (!this.loaded) {
|
|
|
|
this.loaded = true;
|
2010-10-04 15:36:07 -07:00
|
|
|
|
2010-10-04 15:39:20 -07:00
|
|
|
var browser = gDiscoverView._browser;
|
|
|
|
browser.addEventListener("load", function() {
|
|
|
|
browser.removeEventListener("load", arguments.callee, true);
|
|
|
|
gViewController.updateCommands();
|
|
|
|
gViewController.notifyViewChanged();
|
|
|
|
}, true);
|
|
|
|
browser.goHome();
|
2010-10-04 15:36:07 -07:00
|
|
|
} else {
|
|
|
|
gViewController.updateCommands();
|
2010-10-04 15:39:20 -07:00
|
|
|
gViewController.notifyViewChanged();
|
2010-10-04 15:36:07 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-10-04 15:39:20 -07:00
|
|
|
hide: function() { },
|
2010-10-04 15:36:07 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
getSelectedAddon: function() null
|
|
|
|
};
|
2008-01-28 06:22:37 -08:00
|
|
|
|
2008-09-04 03:11:52 -07:00
|
|
|
|
2010-07-19 16:01:23 -07:00
|
|
|
var gCachedAddons = {};
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var gSearchView = {
|
|
|
|
node: null,
|
2010-08-24 11:23:46 -07:00
|
|
|
_filter: null,
|
2010-05-06 11:12:59 -07:00
|
|
|
_sorters: null,
|
2010-10-06 17:20:06 -07:00
|
|
|
_loading: null,
|
2010-05-06 11:12:59 -07:00
|
|
|
_listBox: null,
|
|
|
|
_emptyNotice: null,
|
2010-08-27 19:45:11 -07:00
|
|
|
_allResultsLink: null,
|
2010-07-19 16:01:23 -07:00
|
|
|
_lastQuery: null,
|
2010-08-27 19:45:11 -07:00
|
|
|
_lastRemoteTotal: 0,
|
2010-07-19 16:01:23 -07:00
|
|
|
_pendingSearches: 0,
|
2008-09-04 03:11:52 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
initialize: function() {
|
|
|
|
this.node = document.getElementById("search-view");
|
2010-08-24 11:23:46 -07:00
|
|
|
this._filter = document.getElementById("search-filter-radiogroup");
|
2010-05-06 11:12:59 -07:00
|
|
|
this._sorters = document.getElementById("search-sorters");
|
|
|
|
this._sorters.handler = this;
|
2010-10-06 17:20:06 -07:00
|
|
|
this._loading = document.getElementById("search-loading");
|
2010-05-06 11:12:59 -07:00
|
|
|
this._listBox = document.getElementById("search-list");
|
|
|
|
this._emptyNotice = document.getElementById("search-list-empty");
|
2010-08-27 19:45:11 -07:00
|
|
|
this._allResultsLink = document.getElementById("search-allresults-link");
|
2008-09-04 03:11:52 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var self = this;
|
|
|
|
this._listBox.addEventListener("keydown", function(aEvent) {
|
|
|
|
if (aEvent.keyCode == aEvent.DOM_VK_ENTER ||
|
|
|
|
aEvent.keyCode == aEvent.DOM_VK_RETURN) {
|
|
|
|
var item = self._listBox.selectedItem;
|
|
|
|
if (item)
|
|
|
|
item.showInDetailView();
|
2010-05-01 11:04:44 -07:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
}, false);
|
2010-07-19 16:01:23 -07:00
|
|
|
|
2010-08-24 11:23:46 -07:00
|
|
|
this._filter.addEventListener("command", function() self.updateView(), false);
|
2010-07-19 16:01:23 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
shutdown: function() {
|
|
|
|
if (AddonRepository.isSearching)
|
|
|
|
AddonRepository.cancelSearch();
|
|
|
|
},
|
|
|
|
|
|
|
|
get isSearching() {
|
|
|
|
return this._pendingSearches > 0;
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2008-09-04 03:11:52 -07:00
|
|
|
|
2010-06-16 20:13:20 -07:00
|
|
|
show: function(aQuery, aRequest) {
|
2010-09-28 10:29:24 -07:00
|
|
|
gEventManager.registerInstallListener(this);
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
this.showEmptyNotice(false);
|
2010-08-27 19:45:11 -07:00
|
|
|
this.showAllResultsLink(0);
|
2010-10-06 17:20:06 -07:00
|
|
|
this.showLoading(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
gHeader.searchQuery = aQuery;
|
|
|
|
aQuery = aQuery.trim().toLocaleLowerCase();
|
2010-07-19 16:01:23 -07:00
|
|
|
if (this._lastQuery == aQuery) {
|
|
|
|
this.updateView();
|
|
|
|
gViewController.notifyViewChanged();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._lastQuery = aQuery;
|
|
|
|
|
|
|
|
if (AddonRepository.isSearching)
|
|
|
|
AddonRepository.cancelSearch();
|
2008-09-30 03:59:42 -07:00
|
|
|
|
2010-08-27 19:45:11 -07:00
|
|
|
while (this._listBox.firstChild.localName == "richlistitem")
|
|
|
|
this._listBox.removeChild(this._listBox.firstChild);
|
2008-01-28 06:22:37 -08:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var self = this;
|
2010-07-19 16:01:23 -07:00
|
|
|
gCachedAddons = {};
|
|
|
|
this._pendingSearches = 2;
|
|
|
|
this._sorters.setSort("relevancescore", false);
|
2010-06-16 20:13:20 -07:00
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
var elements = [];
|
|
|
|
|
2010-07-19 16:01:23 -07:00
|
|
|
function createSearchResults(aObjsList, aIsInstall, aIsRemote) {
|
|
|
|
aObjsList.forEach(function(aObj) {
|
2010-05-06 11:12:59 -07:00
|
|
|
let score = 0;
|
|
|
|
if (aQuery.length > 0) {
|
2010-07-19 16:01:23 -07:00
|
|
|
score = self.getMatchScore(aObj, aQuery);
|
|
|
|
if (score == 0 && !aIsRemote)
|
|
|
|
return;
|
2010-05-06 11:12:59 -07:00
|
|
|
}
|
2008-01-28 06:22:37 -08:00
|
|
|
|
2010-08-23 10:46:05 -07:00
|
|
|
let item = createItem(aObj, aIsInstall, aIsRemote);
|
2010-05-06 11:12:59 -07:00
|
|
|
item.setAttribute("relevancescore", score);
|
2010-07-19 16:01:23 -07:00
|
|
|
if (aIsRemote)
|
|
|
|
gCachedAddons[aObj.id] = aObj;
|
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
elements.push(item);
|
2010-07-19 16:01:23 -07:00
|
|
|
});
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-19 16:01:23 -07:00
|
|
|
function finishSearch(createdCount) {
|
2010-11-30 14:18:00 -08:00
|
|
|
if (elements.length > 0) {
|
|
|
|
sortElements(elements, self._sorters.sortBy, self._sorters.ascending);
|
|
|
|
elements.forEach(function(aElement) {
|
|
|
|
self._listBox.insertBefore(aElement, self._listBox.lastChild);
|
|
|
|
});
|
|
|
|
self.updateListAttributes();
|
|
|
|
}
|
2010-07-19 16:01:23 -07:00
|
|
|
|
|
|
|
self._pendingSearches--;
|
|
|
|
self.updateView();
|
|
|
|
|
|
|
|
if (!self.isSearching)
|
|
|
|
gViewController.notifyViewChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
getAddonsAndInstalls(null, function(aAddons, aInstalls) {
|
|
|
|
if (gViewController && aRequest != gViewController.currentViewRequest)
|
|
|
|
return;
|
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
createSearchResults(aAddons, false, false);
|
|
|
|
createSearchResults(aInstalls, true, false);
|
|
|
|
finishSearch();
|
2010-07-19 16:01:23 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
var maxRemoteResults = 0;
|
|
|
|
try {
|
|
|
|
maxRemoteResults = Services.prefs.getIntPref(PREF_MAXRESULTS);
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
if (maxRemoteResults <= 0) {
|
|
|
|
finishSearch(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddonRepository.searchAddons(aQuery, maxRemoteResults, {
|
|
|
|
searchFailed: function() {
|
|
|
|
if (gViewController && aRequest != gViewController.currentViewRequest)
|
|
|
|
return;
|
|
|
|
|
2010-08-27 19:45:11 -07:00
|
|
|
self._lastRemoteTotal = 0;
|
|
|
|
|
2010-07-19 16:01:23 -07:00
|
|
|
// XXXunf Better handling of AMO search failure. See bug 579502
|
|
|
|
finishSearch(0); // Silently fail
|
|
|
|
},
|
|
|
|
|
|
|
|
searchSucceeded: function(aAddonsList, aAddonCount, aTotalResults) {
|
|
|
|
if (gViewController && aRequest != gViewController.currentViewRequest)
|
|
|
|
return;
|
|
|
|
|
2010-08-27 19:45:11 -07:00
|
|
|
if (aTotalResults > maxRemoteResults)
|
|
|
|
self._lastRemoteTotal = aTotalResults;
|
|
|
|
else
|
|
|
|
self._lastRemoteTotal = 0;
|
|
|
|
|
2010-07-19 16:01:23 -07:00
|
|
|
var createdCount = createSearchResults(aAddonsList, false, true);
|
|
|
|
finishSearch(createdCount);
|
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
});
|
|
|
|
},
|
2010-10-06 17:20:06 -07:00
|
|
|
|
|
|
|
showLoading: function(aLoading) {
|
|
|
|
this._loading.hidden = !aLoading;
|
|
|
|
this._listBox.hidden = aLoading;
|
|
|
|
},
|
2007-09-05 18:20:11 -07:00
|
|
|
|
2010-07-19 16:01:23 -07:00
|
|
|
updateView: function() {
|
2010-08-24 11:23:46 -07:00
|
|
|
var showLocal = this._filter.value == "local";
|
2010-07-19 16:01:23 -07:00
|
|
|
this._listBox.setAttribute("local", showLocal);
|
2010-08-24 11:23:46 -07:00
|
|
|
this._listBox.setAttribute("remote", !showLocal);
|
2010-07-19 16:01:23 -07:00
|
|
|
|
2010-10-06 17:20:06 -07:00
|
|
|
this.showLoading(this.isSearching && !showLocal);
|
2010-07-19 16:01:23 -07:00
|
|
|
if (!this.isSearching) {
|
|
|
|
var isEmpty = true;
|
|
|
|
var results = this._listBox.getElementsByTagName("richlistitem");
|
|
|
|
for (let i = 0; i < results.length; i++) {
|
|
|
|
var isRemote = (results[i].getAttribute("remote") == "true");
|
2010-08-24 11:23:46 -07:00
|
|
|
if ((isRemote && !showLocal) || (!isRemote && showLocal)) {
|
2010-07-19 16:01:23 -07:00
|
|
|
isEmpty = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.showEmptyNotice(isEmpty);
|
2010-08-27 19:45:11 -07:00
|
|
|
this.showAllResultsLink(this._lastRemoteTotal);
|
2010-07-19 16:01:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gViewController.updateCommands();
|
|
|
|
},
|
|
|
|
|
2010-07-26 12:42:06 -07:00
|
|
|
hide: function() {
|
2010-09-28 10:29:24 -07:00
|
|
|
gEventManager.unregisterInstallListener(this);
|
2010-12-10 18:32:10 -08:00
|
|
|
doPendingUninstalls(this._listBox);
|
2010-07-26 12:42:06 -07:00
|
|
|
},
|
2007-09-05 18:20:11 -07:00
|
|
|
|
2010-07-19 16:01:23 -07:00
|
|
|
getMatchScore: function(aObj, aQuery) {
|
2010-05-06 11:12:59 -07:00
|
|
|
var score = 0;
|
2010-07-19 16:01:23 -07:00
|
|
|
score += this.calculateMatchScore(aObj.name, aQuery,
|
2010-05-06 11:12:59 -07:00
|
|
|
SEARCH_SCORE_MULTIPLIER_NAME);
|
2010-07-19 16:01:23 -07:00
|
|
|
score += this.calculateMatchScore(aObj.description, aQuery,
|
2010-05-06 11:12:59 -07:00
|
|
|
SEARCH_SCORE_MULTIPLIER_DESCRIPTION);
|
|
|
|
return score;
|
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
calculateMatchScore: function(aStr, aQuery, aMultiplier) {
|
|
|
|
var score = 0;
|
2010-05-06 11:21:55 -07:00
|
|
|
if (!aStr || aQuery.length == 0)
|
2010-05-06 11:12:59 -07:00
|
|
|
return score;
|
|
|
|
|
|
|
|
aStr = aStr.trim().toLocaleLowerCase();
|
2010-08-06 09:36:29 -07:00
|
|
|
var haystack = aStr.split(/\s+/);
|
|
|
|
var needles = aQuery.split(/\s+/);
|
2010-05-06 11:12:59 -07:00
|
|
|
|
|
|
|
for (let n = 0; n < needles.length; n++) {
|
|
|
|
for (let h = 0; h < haystack.length; h++) {
|
|
|
|
if (haystack[h] == needles[n]) {
|
|
|
|
// matching whole words is best
|
|
|
|
score += SEARCH_SCORE_MATCH_WHOLEWORD;
|
|
|
|
} else {
|
|
|
|
let i = haystack[h].indexOf(needles[n]);
|
|
|
|
if (i == 0) // matching on word boundries is also good
|
|
|
|
score += SEARCH_SCORE_MATCH_WORDBOUNDRY;
|
|
|
|
else if (i > 0) // substring matches not so good
|
|
|
|
score += SEARCH_SCORE_MATCH_SUBSTRING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
// give progressively higher score for longer queries, since longer queries
|
|
|
|
// are more likely to be unique and therefore more relevant.
|
|
|
|
if (needles.length > 1 && aStr.indexOf(aQuery) != -1)
|
|
|
|
score += needles.length;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
return score * aMultiplier;
|
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
showEmptyNotice: function(aShow) {
|
|
|
|
this._emptyNotice.hidden = !aShow;
|
2010-10-06 17:20:06 -07:00
|
|
|
this._listBox.hidden = aShow;
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-27 19:45:11 -07:00
|
|
|
showAllResultsLink: function(aTotalResults) {
|
|
|
|
if (aTotalResults == 0) {
|
|
|
|
this._allResultsLink.hidden = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var linkStr = gStrings.ext.GetStringFromName("showAllSearchResults");
|
|
|
|
linkStr = PluralForm.get(aTotalResults, linkStr);
|
|
|
|
linkStr = linkStr.replace("#1", aTotalResults);
|
2010-10-06 17:20:06 -07:00
|
|
|
this._allResultsLink.setAttribute("value", linkStr);
|
2010-08-27 19:45:11 -07:00
|
|
|
|
2010-10-06 17:20:06 -07:00
|
|
|
this._allResultsLink.setAttribute("href",
|
|
|
|
AddonRepository.getSearchURL(this._lastQuery));
|
2010-08-27 19:45:11 -07:00
|
|
|
this._allResultsLink.hidden = false;
|
|
|
|
},
|
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
updateListAttributes: function() {
|
2010-10-06 17:20:06 -07:00
|
|
|
var item = this._listBox.querySelector("richlistitem[remote='true'][first]");
|
|
|
|
if (item)
|
|
|
|
item.removeAttribute("first");
|
|
|
|
item = this._listBox.querySelector("richlistitem[remote='true'][last]");
|
|
|
|
if (item)
|
|
|
|
item.removeAttribute("last");
|
|
|
|
var items = this._listBox.querySelectorAll("richlistitem[remote='true']");
|
|
|
|
if (items.length > 0) {
|
|
|
|
items[0].setAttribute("first", true);
|
|
|
|
items[items.length - 1].setAttribute("last", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
item = this._listBox.querySelector("richlistitem:not([remote='true'])[first]");
|
|
|
|
if (item)
|
|
|
|
item.removeAttribute("first");
|
|
|
|
item = this._listBox.querySelector("richlistitem:not([remote='true'])[last]");
|
|
|
|
if (item)
|
|
|
|
item.removeAttribute("last");
|
|
|
|
items = this._listBox.querySelectorAll("richlistitem:not([remote='true'])");
|
|
|
|
if (items.length > 0) {
|
|
|
|
items[0].setAttribute("first", true);
|
|
|
|
items[items.length - 1].setAttribute("last", true);
|
|
|
|
}
|
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
onSortChanged: function(aSortBy, aAscending) {
|
|
|
|
var footer = this._listBox.lastChild;
|
|
|
|
this._listBox.removeChild(footer);
|
|
|
|
|
|
|
|
sortList(this._listBox, aSortBy, aAscending);
|
|
|
|
this.updateListAttributes();
|
|
|
|
|
2010-08-27 19:45:11 -07:00
|
|
|
this._listBox.appendChild(footer);
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-28 10:29:24 -07:00
|
|
|
onDownloadCancelled: function(aInstall) {
|
|
|
|
this.removeInstall(aInstall);
|
|
|
|
},
|
|
|
|
|
|
|
|
onInstallCancelled: function(aInstall) {
|
|
|
|
this.removeInstall(aInstall);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeInstall: function(aInstall) {
|
|
|
|
for (let i = 0; i < this._listBox.childNodes.length; i++) {
|
|
|
|
let item = this._listBox.childNodes[i];
|
|
|
|
if (item.mInstall == aInstall) {
|
|
|
|
this._listBox.removeChild(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
getSelectedAddon: function() {
|
|
|
|
var item = this._listBox.selectedItem;
|
|
|
|
if (item)
|
|
|
|
return item.mAddon;
|
|
|
|
return null;
|
2010-07-26 12:42:06 -07:00
|
|
|
},
|
2010-07-26 11:40:46 -07:00
|
|
|
|
2010-07-26 12:42:06 -07:00
|
|
|
getListItemForID: function(aId) {
|
|
|
|
var listitem = this._listBox.firstChild;
|
|
|
|
while (listitem) {
|
|
|
|
if (listitem.getAttribute("status") == "installed" && listitem.mAddon.id == aId)
|
|
|
|
return listitem;
|
|
|
|
listitem = listitem.nextSibling;
|
|
|
|
}
|
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var gListView = {
|
|
|
|
node: null,
|
|
|
|
_listBox: null,
|
|
|
|
_emptyNotice: null,
|
|
|
|
_sorters: null,
|
2010-12-10 13:01:08 -08:00
|
|
|
_type: null,
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
initialize: function() {
|
|
|
|
this.node = document.getElementById("list-view");
|
|
|
|
this._sorters = document.getElementById("list-sorters");
|
|
|
|
this._sorters.handler = this;
|
|
|
|
this._listBox = document.getElementById("addon-list");
|
|
|
|
this._emptyNotice = document.getElementById("addon-list-empty");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var self = this;
|
|
|
|
this._listBox.addEventListener("keydown", function(aEvent) {
|
|
|
|
if (aEvent.keyCode == aEvent.DOM_VK_ENTER ||
|
|
|
|
aEvent.keyCode == aEvent.DOM_VK_RETURN) {
|
|
|
|
var item = self._listBox.selectedItem;
|
|
|
|
if (item)
|
|
|
|
item.showInDetailView();
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-16 20:13:20 -07:00
|
|
|
show: function(aType, aRequest) {
|
2010-12-10 13:01:08 -08:00
|
|
|
this._type = aType;
|
2010-12-06 16:31:32 -08:00
|
|
|
this.node.setAttribute("type", aType);
|
2010-05-06 11:12:59 -07:00
|
|
|
this.showEmptyNotice(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
while (this._listBox.itemCount > 0)
|
|
|
|
this._listBox.removeItemAt(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var self = this;
|
2010-12-10 13:01:08 -08:00
|
|
|
getAddonsAndInstalls(aType, function(aAddonsList, aInstallsList) {
|
2010-06-24 12:50:04 -07:00
|
|
|
if (gViewController && aRequest != gViewController.currentViewRequest)
|
2010-05-06 11:12:59 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
var elements = [];
|
2010-05-06 11:12:59 -07:00
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
for (let i = 0; i < aAddonsList.length; i++)
|
|
|
|
elements.push(createItem(aAddonsList[i]));
|
2010-11-30 14:18:00 -08:00
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
for (let i = 0; i < aInstallsList.length; i++)
|
|
|
|
elements.push(createItem(aInstallsList[i], true));
|
|
|
|
|
2010-12-10 13:01:08 -08:00
|
|
|
self.showEmptyNotice(elements.length == 0);
|
2010-11-30 14:18:00 -08:00
|
|
|
if (elements.length > 0) {
|
|
|
|
sortElements(elements, self._sorters.sortBy, self._sorters.ascending);
|
|
|
|
elements.forEach(function(aElement) {
|
|
|
|
self._listBox.appendChild(aElement);
|
|
|
|
});
|
|
|
|
}
|
2008-01-28 09:11:48 -08:00
|
|
|
|
2010-06-24 12:50:04 -07:00
|
|
|
gEventManager.registerInstallListener(self);
|
2010-05-06 11:12:59 -07:00
|
|
|
gViewController.updateCommands();
|
2010-06-16 20:13:20 -07:00
|
|
|
gViewController.notifyViewChanged();
|
2010-05-06 11:12:59 -07:00
|
|
|
});
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
hide: function() {
|
|
|
|
gEventManager.unregisterInstallListener(this);
|
2010-12-10 18:32:10 -08:00
|
|
|
doPendingUninstalls(this._listBox);
|
2010-05-01 11:04:44 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
showEmptyNotice: function(aShow) {
|
|
|
|
this._emptyNotice.hidden = !aShow;
|
2010-04-29 10:37:34 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onSortChanged: function(aSortBy, aAscending) {
|
2010-11-30 14:18:00 -08:00
|
|
|
sortList(this._listBox, aSortBy, aAscending);
|
2010-04-29 10:37:34 -07:00
|
|
|
},
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onExternalInstall: function(aAddon, aExistingAddon, aRequiresRestart) {
|
2010-10-18 11:11:05 -07:00
|
|
|
// The existing list item will take care of upgrade installs
|
|
|
|
if (aExistingAddon)
|
|
|
|
return;
|
|
|
|
|
2010-12-10 13:01:08 -08:00
|
|
|
this.addItem(aAddon);
|
|
|
|
},
|
|
|
|
|
|
|
|
onDownloadStarted: function(aInstall) {
|
|
|
|
this.addItem(aInstall, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
onInstallStarted: function(aInstall) {
|
|
|
|
this.addItem(aInstall, true);
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onDownloadCancelled: function(aInstall) {
|
2010-12-10 13:01:08 -08:00
|
|
|
this.removeItem(aInstall, true);
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onInstallCancelled: function(aInstall) {
|
2010-12-10 13:01:08 -08:00
|
|
|
this.removeItem(aInstall, true);
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2010-04-29 10:21:04 -07:00
|
|
|
|
2010-10-06 10:14:46 -07:00
|
|
|
onInstallEnded: function(aInstall) {
|
|
|
|
// Remove any install entries for upgrades, their status will appear against
|
|
|
|
// the existing item
|
|
|
|
if (aInstall.existingAddon)
|
2010-12-10 13:01:08 -08:00
|
|
|
this.removeItem(aInstall, true);
|
2010-10-06 10:14:46 -07:00
|
|
|
},
|
|
|
|
|
2010-12-10 13:01:08 -08:00
|
|
|
addItem: function(aObj, aIsInstall) {
|
|
|
|
if (aObj.type != this._type)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let prop = aIsInstall ? "mInstall" : "mAddon";
|
|
|
|
for (let i = 0; i < this._listBox.itemCount; i++) {
|
2010-05-06 11:12:59 -07:00
|
|
|
let item = this._listBox.childNodes[i];
|
2010-12-10 13:01:08 -08:00
|
|
|
if (item[prop] == aObj)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let item = createItem(aObj, aIsInstall);
|
|
|
|
this._listBox.insertBefore(item, this._listBox.firstChild);
|
|
|
|
this.showEmptyNotice(false);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeItem: function(aObj, aIsInstall) {
|
|
|
|
let prop = aIsInstall ? "mInstall" : "mAddon";
|
|
|
|
|
|
|
|
for (let i = 0; i < this._listBox.itemCount; i++) {
|
|
|
|
let item = this._listBox.childNodes[i];
|
|
|
|
if (item[prop] == aObj) {
|
2010-05-06 11:12:59 -07:00
|
|
|
this._listBox.removeChild(item);
|
2010-12-10 13:01:08 -08:00
|
|
|
this.showEmptyNotice(this._listBox.itemCount == 0);
|
2010-05-01 11:04:44 -07:00
|
|
|
return;
|
2010-04-29 10:37:34 -07:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
}
|
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
getSelectedAddon: function() {
|
|
|
|
var item = this._listBox.selectedItem;
|
|
|
|
if (item)
|
|
|
|
return item.mAddon;
|
|
|
|
return null;
|
2010-07-26 12:42:06 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getListItemForID: function(aId) {
|
|
|
|
var listitem = this._listBox.firstChild;
|
|
|
|
while (listitem) {
|
|
|
|
if (listitem.getAttribute("status") == "installed" && listitem.mAddon.id == aId)
|
|
|
|
return listitem;
|
|
|
|
listitem = listitem.nextSibling;
|
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
}
|
|
|
|
};
|
2009-10-19 12:08:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
var gDetailView = {
|
|
|
|
node: null,
|
|
|
|
_addon: null,
|
|
|
|
_loadingTimer: null,
|
2010-09-13 23:56:54 -07:00
|
|
|
_updatePrefs: null,
|
2010-06-02 02:13:03 -07:00
|
|
|
_autoUpdate: null,
|
2009-09-17 02:03:33 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
initialize: function() {
|
|
|
|
this.node = document.getElementById("detail-view");
|
2008-01-28 12:13:14 -08:00
|
|
|
|
2010-06-02 02:13:03 -07:00
|
|
|
this._autoUpdate = document.getElementById("detail-autoUpdate");
|
2010-04-29 10:21:04 -07:00
|
|
|
|
|
|
|
var self = this;
|
2010-09-01 09:57:48 -07:00
|
|
|
this._autoUpdate.addEventListener("command", function() {
|
2010-09-13 23:56:54 -07:00
|
|
|
self._addon.applyBackgroundUpdates = self._autoUpdate.value;
|
2010-04-29 10:21:04 -07:00
|
|
|
}, true);
|
2010-09-13 23:56:54 -07:00
|
|
|
|
|
|
|
this._updatePrefs = Services.prefs.getBranch("extensions.update.");
|
|
|
|
this._updatePrefs.QueryInterface(Ci.nsIPrefBranch2);
|
|
|
|
},
|
|
|
|
|
|
|
|
shutdown: function() {
|
|
|
|
this._updatePrefs.removeObserver("", this);
|
|
|
|
delete this._updatePrefs;
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function(aSubject, aTopic, aData) {
|
|
|
|
if (aTopic == "nsPref:changed" && aData == "autoUpdateDefault") {
|
|
|
|
this.onPropertyChanged(["applyBackgroundUpdates"]);
|
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-01 09:57:48 -07:00
|
|
|
_updateView: function(aAddon, aIsRemote) {
|
2010-09-13 23:56:54 -07:00
|
|
|
this._updatePrefs.addObserver("", this, false);
|
2010-09-01 09:57:48 -07:00
|
|
|
this.clearLoading();
|
|
|
|
|
|
|
|
this._addon = aAddon;
|
|
|
|
gEventManager.registerAddonListener(this, aAddon.id);
|
2010-10-18 11:11:05 -07:00
|
|
|
gEventManager.registerInstallListener(this);
|
2010-09-01 09:57:48 -07:00
|
|
|
|
|
|
|
this.node.setAttribute("type", aAddon.type);
|
|
|
|
|
2010-10-06 15:05:50 -07:00
|
|
|
document.getElementById("detail-name").textContent = aAddon.name;
|
2010-09-01 09:57:48 -07:00
|
|
|
var icon = aAddon.icon64URL ? aAddon.icon64URL : aAddon.iconURL;
|
|
|
|
document.getElementById("detail-icon").src = icon ? icon : null;
|
|
|
|
document.getElementById("detail-creator").setCreator(aAddon.creator, aAddon.homepageURL);
|
|
|
|
|
|
|
|
var version = document.getElementById("detail-version");
|
|
|
|
if (aAddon.version) {
|
|
|
|
version.hidden = false;
|
|
|
|
version.value = aAddon.version;
|
|
|
|
} else {
|
|
|
|
version.hidden = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var screenshot = document.getElementById("detail-screenshot");
|
|
|
|
if (aAddon.screenshots && aAddon.screenshots.length > 0) {
|
2010-09-06 00:00:47 -07:00
|
|
|
if (aAddon.screenshots[0].thumbnailURL)
|
|
|
|
screenshot.src = aAddon.screenshots[0].thumbnailURL;
|
2010-09-01 09:57:48 -07:00
|
|
|
else
|
|
|
|
screenshot.src = aAddon.screenshots[0].url;
|
|
|
|
screenshot.hidden = false;
|
|
|
|
} else {
|
|
|
|
screenshot.hidden = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var desc = document.getElementById("detail-desc");
|
|
|
|
desc.textContent = aAddon.fullDescription ? aAddon.fullDescription
|
|
|
|
: aAddon.description;
|
|
|
|
|
|
|
|
var contributions = document.getElementById("detail-contributions");
|
2010-09-09 19:17:08 -07:00
|
|
|
if ("contributionURL" in aAddon && aAddon.contributionURL) {
|
2010-09-01 09:57:48 -07:00
|
|
|
contributions.hidden = false;
|
|
|
|
var amount = document.getElementById("detail-contrib-suggested");
|
2010-12-08 14:41:50 -08:00
|
|
|
amount.value = gStrings.ext.formatStringFromName("contributionAmount2",
|
2010-09-01 09:57:48 -07:00
|
|
|
[aAddon.contributionAmount],
|
|
|
|
1);
|
|
|
|
} else {
|
|
|
|
contributions.hidden = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var updateDateRow = document.getElementById("detail-dateUpdated");
|
|
|
|
if (aAddon.updateDate) {
|
|
|
|
var date = formatDate(aAddon.updateDate);
|
|
|
|
updateDateRow.value = date;
|
|
|
|
} else {
|
|
|
|
updateDateRow.value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO if the add-on was downloaded from releases.mozilla.org link to the
|
|
|
|
// AMO profile (bug 590344)
|
|
|
|
if (false) {
|
|
|
|
document.getElementById("detail-repository-row").hidden = false;
|
|
|
|
document.getElementById("detail-homepage-row").hidden = true;
|
|
|
|
var repository = document.getElementById("detail-repository");
|
|
|
|
repository.value = aAddon.homepageURL;
|
|
|
|
repository.href = aAddon.homepageURL;
|
|
|
|
} else if (aAddon.homepageURL) {
|
|
|
|
document.getElementById("detail-repository-row").hidden = true;
|
|
|
|
document.getElementById("detail-homepage-row").hidden = false;
|
|
|
|
var homepage = document.getElementById("detail-homepage");
|
|
|
|
homepage.value = aAddon.homepageURL;
|
|
|
|
homepage.href = aAddon.homepageURL;
|
|
|
|
} else {
|
|
|
|
document.getElementById("detail-repository-row").hidden = true;
|
|
|
|
document.getElementById("detail-homepage-row").hidden = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var rating = document.getElementById("detail-rating");
|
|
|
|
if (aAddon.averageRating) {
|
|
|
|
rating.averageRating = aAddon.averageRating;
|
|
|
|
rating.hidden = false;
|
|
|
|
} else {
|
|
|
|
rating.hidden = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var reviews = document.getElementById("detail-reviews");
|
|
|
|
if (aAddon.reviewURL) {
|
|
|
|
var text = gStrings.ext.GetStringFromName("numReviews");
|
|
|
|
text = PluralForm.get(aAddon.reviewCount, text)
|
|
|
|
text = text.replace("#1", aAddon.reviewCount);
|
|
|
|
reviews.value = text;
|
|
|
|
reviews.hidden = false;
|
|
|
|
reviews.href = aAddon.reviewURL;
|
|
|
|
} else {
|
|
|
|
reviews.hidden = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById("detail-rating-row").hidden = !aAddon.averageRating && !aAddon.reviewURL;
|
|
|
|
|
|
|
|
var sizeRow = document.getElementById("detail-size");
|
|
|
|
if (aAddon.size && aIsRemote) {
|
|
|
|
let [size, unit] = DownloadUtils.convertByteUnits(parseInt(aAddon.size));
|
2010-10-29 12:04:20 -07:00
|
|
|
let formatted = gStrings.dl.GetStringFromName("doneSize");
|
2010-09-01 09:57:48 -07:00
|
|
|
formatted = formatted.replace("#1", size).replace("#2", unit);
|
|
|
|
sizeRow.value = formatted;
|
|
|
|
} else {
|
|
|
|
sizeRow.value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var downloadsRow = document.getElementById("detail-downloads");
|
|
|
|
if (aAddon.totalDownloads && aIsRemote) {
|
|
|
|
var downloads = aAddon.totalDownloads;
|
|
|
|
downloadsRow.value = downloads;
|
|
|
|
} else {
|
|
|
|
downloadsRow.value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var canUpdate = !aIsRemote && hasPermission(aAddon, "upgrade");
|
|
|
|
document.getElementById("detail-updates-row").hidden = !canUpdate;
|
|
|
|
|
|
|
|
if ("applyBackgroundUpdates" in aAddon) {
|
|
|
|
this._autoUpdate.hidden = false;
|
|
|
|
this._autoUpdate.value = aAddon.applyBackgroundUpdates;
|
2010-09-13 23:56:54 -07:00
|
|
|
let hideFindUpdates = shouldAutoUpdate(this._addon);
|
2010-10-15 10:00:03 -07:00
|
|
|
document.getElementById("detail-findUpdates-btn").hidden = hideFindUpdates;
|
2010-09-01 09:57:48 -07:00
|
|
|
} else {
|
|
|
|
this._autoUpdate.hidden = true;
|
2010-10-15 10:00:03 -07:00
|
|
|
document.getElementById("detail-findUpdates-btn").hidden = false;
|
2010-09-01 09:57:48 -07:00
|
|
|
}
|
|
|
|
|
2010-10-15 10:00:03 -07:00
|
|
|
document.getElementById("detail-prefs-btn").hidden = !aIsRemote && !aAddon.optionsURL;
|
2010-10-07 10:28:04 -07:00
|
|
|
|
|
|
|
var gridRows = document.querySelectorAll("#detail-grid rows row");
|
|
|
|
for (var i = 0, first = true; i < gridRows.length; ++i) {
|
|
|
|
if (first && window.getComputedStyle(gridRows[i], null).getPropertyValue("display") != "none") {
|
|
|
|
gridRows[i].setAttribute("first-row", true);
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
gridRows[i].removeAttribute("first-row");
|
|
|
|
}
|
|
|
|
}
|
2010-09-01 09:57:48 -07:00
|
|
|
|
|
|
|
this.updateState();
|
|
|
|
|
|
|
|
gViewController.updateCommands();
|
|
|
|
gViewController.notifyViewChanged();
|
|
|
|
},
|
|
|
|
|
2010-06-16 20:13:20 -07:00
|
|
|
show: function(aAddonId, aRequest) {
|
2010-05-06 11:12:59 -07:00
|
|
|
var self = this;
|
|
|
|
this._loadingTimer = setTimeout(function() {
|
|
|
|
self.node.setAttribute("loading-extended", true);
|
|
|
|
}, LOADING_MSG_DELAY);
|
|
|
|
|
2010-06-16 20:13:20 -07:00
|
|
|
var view = gViewController.currentViewId;
|
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
AddonManager.getAddonByID(aAddonId, function(aAddon) {
|
2010-06-16 20:13:20 -07:00
|
|
|
if (gViewController && aRequest != gViewController.currentViewRequest)
|
|
|
|
return;
|
|
|
|
|
2010-09-01 09:57:48 -07:00
|
|
|
if (aAddon) {
|
|
|
|
self._updateView(aAddon, false);
|
|
|
|
return;
|
2010-05-06 11:12:59 -07:00
|
|
|
}
|
2007-08-25 16:36:25 -07:00
|
|
|
|
2010-09-01 09:57:48 -07:00
|
|
|
// Look for an add-on pending install
|
|
|
|
AddonManager.getAllInstalls(function(aInstalls) {
|
|
|
|
for (let i = 0; i < aInstalls.length; i++) {
|
|
|
|
if (aInstalls[i].state == AddonManager.STATE_INSTALLED &&
|
|
|
|
aInstalls[i].addon.id == aAddonId) {
|
|
|
|
self._updateView(aInstalls[i].addon, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-08-25 16:36:25 -07:00
|
|
|
|
2010-09-01 09:57:48 -07:00
|
|
|
if (aAddonId in gCachedAddons) {
|
|
|
|
self._updateView(gCachedAddons[aAddonId], true);
|
|
|
|
return;
|
|
|
|
}
|
2007-08-25 16:36:25 -07:00
|
|
|
|
2010-09-01 09:57:48 -07:00
|
|
|
// This case should never happen in normal operation
|
|
|
|
});
|
2010-05-06 11:12:59 -07:00
|
|
|
});
|
|
|
|
},
|
2007-08-09 19:47:48 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
hide: function() {
|
2010-09-13 23:56:54 -07:00
|
|
|
this._updatePrefs.removeObserver("", this);
|
2010-05-06 11:12:59 -07:00
|
|
|
this.clearLoading();
|
|
|
|
gEventManager.unregisterAddonListener(this, this._addon.id);
|
2010-09-01 09:57:48 -07:00
|
|
|
gEventManager.unregisterInstallListener(this);
|
2010-05-06 11:12:59 -07:00
|
|
|
this._addon = null;
|
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
updateState: function() {
|
|
|
|
gViewController.updateCommands();
|
|
|
|
|
2010-09-01 09:57:48 -07:00
|
|
|
var pending = this._addon.pendingOperations;
|
|
|
|
if (pending != AddonManager.PENDING_NONE) {
|
|
|
|
this.node.removeAttribute("notification");
|
|
|
|
|
|
|
|
var pending = null;
|
|
|
|
["enable", "disable", "install", "uninstall", "upgrade"].forEach(function(aOp) {
|
|
|
|
if (isPending(this._addon, aOp))
|
|
|
|
pending = aOp;
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.node.setAttribute("pending", pending);
|
|
|
|
document.getElementById("detail-pending").textContent = gStrings.ext.formatStringFromName(
|
|
|
|
"details.notification." + pending,
|
|
|
|
[this._addon.name, gStrings.brandShortName], 2
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.node.removeAttribute("pending");
|
|
|
|
|
|
|
|
if (this._addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED) {
|
|
|
|
this.node.setAttribute("notification", "error");
|
|
|
|
document.getElementById("detail-error").textContent = gStrings.ext.formatStringFromName(
|
|
|
|
"details.notification.blocked",
|
|
|
|
[this._addon.name], 1
|
|
|
|
);
|
|
|
|
var errorLink = document.getElementById("detail-error-link");
|
|
|
|
errorLink.value = gStrings.ext.GetStringFromName("details.notification.blocked.link");
|
|
|
|
errorLink.href = Services.urlFormatter.formatURLPref("extensions.blocklist.detailsURL");
|
|
|
|
errorLink.hidden = false;
|
|
|
|
} else if (!this._addon.isCompatible) {
|
|
|
|
this.node.setAttribute("notification", "warning");
|
|
|
|
document.getElementById("detail-warning").textContent = gStrings.ext.formatStringFromName(
|
|
|
|
"details.notification.incompatible",
|
|
|
|
[this._addon.name, gStrings.brandShortName, gStrings.appVersion], 3
|
|
|
|
);
|
|
|
|
document.getElementById("detail-warning-link").hidden = true;
|
|
|
|
} else if (this._addon.blocklistState == Ci.nsIBlocklistService.STATE_SOFTBLOCKED) {
|
|
|
|
this.node.setAttribute("notification", "warning");
|
|
|
|
document.getElementById("detail-warning").textContent = gStrings.ext.formatStringFromName(
|
|
|
|
"details.notification.softblocked",
|
|
|
|
[this._addon.name], 1
|
|
|
|
);
|
|
|
|
var warningLink = document.getElementById("detail-warning-link");
|
|
|
|
warningLink.value = gStrings.ext.GetStringFromName("details.notification.softblocked.link");
|
|
|
|
warningLink.href = Services.urlFormatter.formatURLPref("extensions.blocklist.detailsURL");
|
|
|
|
warningLink.hidden = false;
|
2010-09-01 09:58:42 -07:00
|
|
|
} else if (this._addon.blocklistState == Ci.nsIBlocklistService.STATE_OUTDATED) {
|
|
|
|
this.node.setAttribute("notification", "warning");
|
|
|
|
document.getElementById("detail-warning").textContent = gStrings.ext.formatStringFromName(
|
|
|
|
"details.notification.outdated",
|
|
|
|
[this._addon.name], 1
|
|
|
|
);
|
|
|
|
var warningLink = document.getElementById("detail-warning-link");
|
|
|
|
warningLink.value = gStrings.ext.GetStringFromName("details.notification.outdated.link");
|
|
|
|
warningLink.href = Services.urlFormatter.formatURLPref("plugins.update.url");
|
|
|
|
warningLink.hidden = false;
|
2010-09-01 09:57:48 -07:00
|
|
|
} else {
|
|
|
|
this.node.removeAttribute("notification");
|
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
}
|
2007-08-29 01:16:15 -07:00
|
|
|
|
2010-09-01 09:57:48 -07:00
|
|
|
this.node.setAttribute("active", this._addon.isActive);
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
clearLoading: function() {
|
|
|
|
if (this._loadingTimer) {
|
|
|
|
clearTimeout(this._loadingTimer);
|
|
|
|
this._loadingTimer = null;
|
|
|
|
}
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
this.node.removeAttribute("loading-extended");
|
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
getSelectedAddon: function() {
|
|
|
|
return this._addon;
|
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onEnabling: function() {
|
|
|
|
this.updateState();
|
|
|
|
},
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onEnabled: function() {
|
|
|
|
this.updateState();
|
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onDisabling: function() {
|
|
|
|
this.updateState();
|
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onDisabled: function() {
|
|
|
|
this.updateState();
|
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onUninstalling: function() {
|
|
|
|
this.updateState();
|
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onUninstalled: function() {
|
2010-08-27 15:23:53 -07:00
|
|
|
gViewController.popState();
|
2010-05-06 11:12:59 -07:00
|
|
|
},
|
2010-05-01 11:04:44 -07:00
|
|
|
|
2010-05-06 11:12:59 -07:00
|
|
|
onOperationCancelled: function() {
|
|
|
|
this.updateState();
|
2010-06-02 02:13:03 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onPropertyChanged: function(aProperties) {
|
|
|
|
if (aProperties.indexOf("applyBackgroundUpdates") != -1) {
|
2010-09-01 09:57:48 -07:00
|
|
|
this._autoUpdate.value = this._addon.applyBackgroundUpdates;
|
2010-09-13 23:56:54 -07:00
|
|
|
let hideFindUpdates = shouldAutoUpdate(this._addon);
|
2010-10-15 10:00:03 -07:00
|
|
|
document.getElementById("detail-findUpdates-btn").hidden = hideFindUpdates;
|
2010-06-02 02:13:03 -07:00
|
|
|
}
|
2010-09-01 09:57:48 -07:00
|
|
|
},
|
|
|
|
|
2010-10-18 11:11:05 -07:00
|
|
|
onExternalInstall: function(aAddon, aExistingAddon, aNeedsRestart) {
|
|
|
|
// Only care about upgrades for the currently displayed add-on
|
|
|
|
if (!aExistingAddon || aExistingAddon.id != this._addon.id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!aNeedsRestart)
|
|
|
|
this._updateView(aAddon, false);
|
|
|
|
else
|
|
|
|
this.updateState();
|
|
|
|
},
|
|
|
|
|
2010-09-01 09:57:48 -07:00
|
|
|
onInstallCancelled: function(aInstall) {
|
|
|
|
if (aInstall.addon.id == this._addon.id)
|
|
|
|
gViewController.popState();
|
2010-06-02 02:13:03 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var gUpdatesView = {
|
|
|
|
node: null,
|
|
|
|
_listBox: null,
|
|
|
|
_emptyNotice: null,
|
|
|
|
_sorters: null,
|
2010-09-10 01:20:12 -07:00
|
|
|
_updateSelected: null,
|
2010-06-02 02:13:03 -07:00
|
|
|
_updatePrefs: null,
|
|
|
|
_categoryItem: null,
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
this.node = document.getElementById("updates-view");
|
|
|
|
this._listBox = document.getElementById("updates-list");
|
|
|
|
this._emptyNotice = document.getElementById("updates-list-empty");
|
|
|
|
this._sorters = document.getElementById("updates-sorters");
|
|
|
|
this._sorters.handler = this;
|
|
|
|
|
|
|
|
this._categoryItem = gCategories.get("addons://updates/available");
|
|
|
|
|
2010-10-15 10:00:03 -07:00
|
|
|
this._updateSelected = document.getElementById("update-selected-btn");
|
2010-09-10 01:20:12 -07:00
|
|
|
this._updateSelected.addEventListener("command", function() {
|
|
|
|
gUpdatesView.installSelected();
|
|
|
|
}, false);
|
|
|
|
|
2010-06-02 02:13:03 -07:00
|
|
|
this._updatePrefs = Services.prefs.getBranch("extensions.update.");
|
|
|
|
this._updatePrefs.QueryInterface(Ci.nsIPrefBranch2);
|
|
|
|
this._updatePrefs.addObserver("", this, false);
|
|
|
|
this.updateAvailableCount(true);
|
|
|
|
|
|
|
|
AddonManager.addAddonListener(this);
|
|
|
|
AddonManager.addInstallListener(this);
|
|
|
|
},
|
2010-08-02 17:59:51 -07:00
|
|
|
|
2010-06-02 02:13:03 -07:00
|
|
|
shutdown: function() {
|
|
|
|
AddonManager.removeAddonListener(this);
|
|
|
|
AddonManager.removeInstallListener(this);
|
|
|
|
this._updatePrefs.removeObserver("", this);
|
|
|
|
delete this._updatePrefs;
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function(aType, aRequest) {
|
|
|
|
document.getElementById("empty-availableUpdates-msg").hidden = aType != "available";
|
|
|
|
document.getElementById("empty-recentUpdates-msg").hidden = aType != "recent";
|
|
|
|
this.showEmptyNotice(false);
|
|
|
|
|
|
|
|
while (this._listBox.itemCount > 0)
|
|
|
|
this._listBox.removeItemAt(0);
|
|
|
|
|
2010-09-10 01:20:12 -07:00
|
|
|
this.node.setAttribute("updatetype", aType);
|
2010-06-02 02:13:03 -07:00
|
|
|
if (aType == "recent")
|
|
|
|
this._showRecentUpdates(aRequest);
|
|
|
|
else
|
|
|
|
this._showAvailableUpdates(false, aRequest);
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
2010-09-10 01:20:12 -07:00
|
|
|
this._updateSelected.hidden = true;
|
2010-12-07 15:41:03 -08:00
|
|
|
this._categoryItem.disabled = this._categoryItem.badgeCount == 0;
|
2010-12-10 18:32:10 -08:00
|
|
|
doPendingUninstalls(this._listBox);
|
2010-06-02 02:13:03 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_showRecentUpdates: function(aRequest) {
|
|
|
|
var self = this;
|
|
|
|
AddonManager.getAllAddons(function(aAddonsList) {
|
|
|
|
if (gViewController && aRequest != gViewController.currentViewRequest)
|
|
|
|
return;
|
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
var elements = [];
|
2010-06-02 02:13:03 -07:00
|
|
|
let threshold = Date.now() - UPDATES_RECENT_TIMESPAN;
|
|
|
|
aAddonsList.forEach(function(aAddon) {
|
|
|
|
if (!aAddon.updateDate || aAddon.updateDate.getTime() < threshold)
|
|
|
|
return;
|
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
elements.push(createItem(aAddon));
|
2010-06-02 02:13:03 -07:00
|
|
|
});
|
|
|
|
|
2010-12-10 13:01:08 -08:00
|
|
|
self.showEmptyNotice(elements.length == 0);
|
2010-11-30 14:18:00 -08:00
|
|
|
if (elements.length > 0) {
|
|
|
|
sortElements(elements, self._sorters.sortBy, self._sorters.ascending);
|
|
|
|
elements.forEach(function(aElement) {
|
|
|
|
self._listBox.appendChild(aElement);
|
|
|
|
});
|
|
|
|
}
|
2010-06-02 02:13:03 -07:00
|
|
|
|
|
|
|
gViewController.notifyViewChanged();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_showAvailableUpdates: function(aIsRefresh, aRequest) {
|
2010-09-10 01:20:12 -07:00
|
|
|
/* Disable the Update Selected button so it can't get clicked
|
|
|
|
before everything is initialized asynchronously.
|
|
|
|
It will get re-enabled by maybeDisableUpdateSelected(). */
|
|
|
|
this._updateSelected.disabled = true;
|
|
|
|
|
2010-06-02 02:13:03 -07:00
|
|
|
var self = this;
|
|
|
|
AddonManager.getAllInstalls(function(aInstallsList) {
|
2010-11-08 10:00:13 -08:00
|
|
|
if (!aIsRefresh && gViewController && aRequest &&
|
|
|
|
aRequest != gViewController.currentViewRequest)
|
2010-06-02 02:13:03 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (aIsRefresh) {
|
2010-09-10 01:20:12 -07:00
|
|
|
self.showEmptyNotice(false);
|
|
|
|
self._updateSelected.hidden = true;
|
|
|
|
|
2010-06-02 02:13:03 -07:00
|
|
|
while (self._listBox.itemCount > 0)
|
|
|
|
self._listBox.removeItemAt(0);
|
|
|
|
}
|
|
|
|
|
2010-11-30 14:18:00 -08:00
|
|
|
var elements = [];
|
|
|
|
|
2010-06-02 02:13:03 -07:00
|
|
|
aInstallsList.forEach(function(aInstall) {
|
|
|
|
if (!self.isManualUpdate(aInstall))
|
|
|
|
return;
|
|
|
|
|
|
|
|
let item = createItem(aInstall.existingAddon);
|
|
|
|
item.setAttribute("upgrade", true);
|
2010-09-10 01:20:12 -07:00
|
|
|
item.addEventListener("IncludeUpdateChanged", function() {
|
|
|
|
self.maybeDisableUpdateSelected();
|
|
|
|
}, false);
|
2010-11-30 14:18:00 -08:00
|
|
|
elements.push(item);
|
2010-06-02 02:13:03 -07:00
|
|
|
});
|
|
|
|
|
2010-12-10 13:01:08 -08:00
|
|
|
self.showEmptyNotice(elements.length == 0);
|
2010-11-30 14:18:00 -08:00
|
|
|
if (elements.length > 0) {
|
2010-09-10 01:20:12 -07:00
|
|
|
self._updateSelected.hidden = false;
|
2010-11-30 14:18:00 -08:00
|
|
|
sortElements(elements, self._sorters.sortBy, self._sorters.ascending);
|
|
|
|
elements.forEach(function(aElement) {
|
|
|
|
self._listBox.appendChild(aElement);
|
|
|
|
});
|
2010-09-10 01:20:12 -07:00
|
|
|
}
|
2010-06-02 02:13:03 -07:00
|
|
|
|
|
|
|
// ensure badge count is in sync
|
|
|
|
self._categoryItem.badgeCount = self._listBox.itemCount;
|
|
|
|
|
2010-09-10 01:20:12 -07:00
|
|
|
gViewController.notifyViewChanged();
|
2010-06-02 02:13:03 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
showEmptyNotice: function(aShow) {
|
|
|
|
this._emptyNotice.hidden = !aShow;
|
|
|
|
},
|
|
|
|
|
|
|
|
isManualUpdate: function(aInstall, aOnlyAvailable) {
|
|
|
|
var isManual = aInstall.existingAddon &&
|
2010-09-13 23:56:54 -07:00
|
|
|
!shouldAutoUpdate(aInstall.existingAddon);
|
2010-06-02 02:13:03 -07:00
|
|
|
if (isManual && aOnlyAvailable)
|
|
|
|
return isInState(aInstall, "available");
|
|
|
|
return isManual;
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function(aSubject, aTopic, aData) {
|
2010-09-13 23:56:54 -07:00
|
|
|
if (aTopic != "nsPref:changed")
|
|
|
|
return;
|
2010-06-02 02:13:03 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
maybeRefresh: function() {
|
2010-12-07 15:41:03 -08:00
|
|
|
if (gViewController.currentViewId == "addons://updates/available")
|
2010-06-02 02:13:03 -07:00
|
|
|
this._showAvailableUpdates(true);
|
2010-12-07 15:41:03 -08:00
|
|
|
this.updateAvailableCount();
|
2010-06-02 02:13:03 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
updateAvailableCount: function(aInitializing) {
|
|
|
|
if (aInitializing)
|
|
|
|
gPendingInitializations++;
|
|
|
|
var self = this;
|
|
|
|
AddonManager.getAllInstalls(function(aInstallsList) {
|
|
|
|
var count = aInstallsList.filter(function(aInstall) {
|
|
|
|
return self.isManualUpdate(aInstall, true);
|
|
|
|
}).length;
|
2010-12-07 15:41:03 -08:00
|
|
|
self._categoryItem.disabled = gViewController.currentViewObj != self &&
|
|
|
|
count == 0;
|
2010-06-02 02:13:03 -07:00
|
|
|
self._categoryItem.badgeCount = count;
|
|
|
|
if (aInitializing)
|
|
|
|
notifyInitialized();
|
|
|
|
});
|
|
|
|
},
|
2010-09-10 01:20:12 -07:00
|
|
|
|
|
|
|
maybeDisableUpdateSelected: function() {
|
|
|
|
for (let i = 0; i < this._listBox.childNodes.length; i++) {
|
|
|
|
let item = this._listBox.childNodes[i];
|
|
|
|
if (item.includeUpdate) {
|
|
|
|
this._updateSelected.disabled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._updateSelected.disabled = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
installSelected: function() {
|
|
|
|
for (let i = 0; i < this._listBox.childNodes.length; i++) {
|
|
|
|
let item = this._listBox.childNodes[i];
|
|
|
|
if (item.includeUpdate)
|
2010-11-08 10:00:13 -08:00
|
|
|
item.upgrade();
|
2010-09-10 01:20:12 -07:00
|
|
|
}
|
2010-11-08 10:00:13 -08:00
|
|
|
|
|
|
|
this._updateSelected.disabled = true;
|
2010-09-10 01:20:12 -07:00
|
|
|
},
|
2010-08-02 17:59:51 -07:00
|
|
|
|
2010-06-02 02:13:03 -07:00
|
|
|
getSelectedAddon: function() {
|
|
|
|
var item = this._listBox.selectedItem;
|
|
|
|
if (item)
|
|
|
|
return item.mAddon;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
getListItemForID: function(aId) {
|
|
|
|
var listitem = this._listBox.firstChild;
|
|
|
|
while (listitem) {
|
|
|
|
if (listitem.mAddon.id == aId)
|
|
|
|
return listitem;
|
|
|
|
listitem = listitem.nextSibling;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
onSortChanged: function(aSortBy, aAscending) {
|
2010-11-30 14:18:00 -08:00
|
|
|
sortList(this._listBox, aSortBy, aAscending);
|
2010-06-02 02:13:03 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onNewInstall: function(aInstall) {
|
|
|
|
if (!this.isManualUpdate(aInstall))
|
|
|
|
return;
|
|
|
|
this.maybeRefresh();
|
|
|
|
},
|
2010-08-02 17:59:51 -07:00
|
|
|
|
2010-12-07 15:41:03 -08:00
|
|
|
onInstallStarted: function(aInstall) {
|
|
|
|
this.updateAvailableCount();
|
2010-06-02 02:13:03 -07:00
|
|
|
},
|
|
|
|
|
2010-11-08 10:00:13 -08:00
|
|
|
onInstallCancelled: function(aInstall) {
|
|
|
|
if (!this.isManualUpdate(aInstall))
|
|
|
|
return;
|
|
|
|
this.maybeRefresh();
|
|
|
|
},
|
|
|
|
|
2010-06-02 02:13:03 -07:00
|
|
|
onPropertyChanged: function(aAddon, aProperties) {
|
|
|
|
if (aProperties.indexOf("applyBackgroundUpdates") != -1)
|
2010-12-07 15:41:03 -08:00
|
|
|
this.updateAvailableCount();
|
2010-05-01 11:04:44 -07:00
|
|
|
}
|
2010-05-06 11:12:59 -07:00
|
|
|
};
|
2010-06-16 19:46:11 -07:00
|
|
|
|
|
|
|
|
|
|
|
var gDragDrop = {
|
|
|
|
onDragOver: function(aEvent) {
|
|
|
|
var types = aEvent.dataTransfer.types;
|
|
|
|
if (types.contains("text/uri-list") ||
|
|
|
|
types.contains("text/x-moz-url") ||
|
|
|
|
types.contains("application/x-moz-file"))
|
|
|
|
aEvent.preventDefault();
|
|
|
|
},
|
|
|
|
|
|
|
|
onDrop: function(aEvent) {
|
2010-06-24 12:50:04 -07:00
|
|
|
var dataTransfer = aEvent.dataTransfer;
|
2010-06-16 19:46:11 -07:00
|
|
|
var urls = [];
|
|
|
|
|
|
|
|
// Convert every dropped item into a url
|
|
|
|
for (var i = 0; i < dataTransfer.mozItemCount; i++) {
|
|
|
|
var url = dataTransfer.mozGetDataAt("text/uri-list", i);
|
|
|
|
if (url) {
|
|
|
|
urls.push(url);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
url = dataTransfer.mozGetDataAt("text/x-moz-url", i);
|
|
|
|
if (url) {
|
|
|
|
urls.push(url.split("\n")[0]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var file = dataTransfer.mozGetDataAt("application/x-moz-file", i);
|
|
|
|
if (file) {
|
|
|
|
urls.push(Services.io.newFileURI(file).spec);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var pos = 0;
|
|
|
|
var installs = [];
|
|
|
|
|
|
|
|
function buildNextInstall() {
|
|
|
|
if (pos == urls.length) {
|
|
|
|
if (installs.length > 0) {
|
|
|
|
// Display the normal install confirmation for the installs
|
|
|
|
AddonManager.installAddonsFromWebpage("application/x-xpinstall", this,
|
|
|
|
null, installs);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddonManager.getInstallForURL(urls[pos++], function(aInstall) {
|
|
|
|
installs.push(aInstall);
|
|
|
|
buildNextInstall();
|
|
|
|
}, "application/x-xpinstall");
|
|
|
|
}
|
|
|
|
|
|
|
|
buildNextInstall();
|
|
|
|
|
|
|
|
aEvent.preventDefault();
|
|
|
|
}
|
|
|
|
};
|