--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -1521,18 +1521,17 @@ var gMainPane = {
let item = document.createElement("richlistitem");
item.setAttribute("type", visibleType.type);
item.setAttribute("typeDescription", visibleType.typeDescription);
if (visibleType.smallIcon)
item.setAttribute("typeIcon", visibleType.smallIcon);
item.setAttribute("actionDescription", visibleType.actionDescription);
if (!this._setIconClassForPreferredAction(visibleType, item)) {
- item.setAttribute("actionIcon",
- this._getIconURLForPreferredAction(visibleType));
+ item.setAttribute("actionIcon", visibleType.actionIcon);
}
this._list.appendChild(item);
if (visibleType.type === lastSelectedType) {
this._list.selectedItem = item;
}
}
@@ -1666,17 +1665,17 @@ var gMainPane = {
// Create a menu item for the OS default application, if any.
if (handlerInfo.hasDefaultHandler) {
var defaultMenuItem = document.createElement("menuitem");
defaultMenuItem.setAttribute("action", Ci.nsIHandlerInfo.useSystemDefault);
let label = gMainPane._prefsBundle.getFormattedString("useDefault",
[handlerInfo.defaultDescription]);
defaultMenuItem.setAttribute("label", label);
defaultMenuItem.setAttribute("tooltiptext", handlerInfo.defaultDescription);
- defaultMenuItem.setAttribute("image", this._getIconURLForSystemDefault(handlerInfo));
+ defaultMenuItem.setAttribute("image", handlerInfo.iconURLForSystemDefault);
menuPopup.appendChild(defaultMenuItem);
}
// Create menu items for possible handlers.
let preferredApp = handlerInfo.preferredApplicationHandler;
let possibleApps = handlerInfo.possibleApplicationHandlers.enumerate();
var possibleAppMenuItems = [];
@@ -1948,18 +1947,17 @@ var gMainPane = {
// Make sure the handler info object is flagged to indicate that there is
// now some user configuration for the type.
handlerInfo.handledOnlyByPlugin = false;
// Update the action label and image to reflect the new preferred action.
typeItem.setAttribute("actionDescription", handlerInfo.actionDescription);
if (!this._setIconClassForPreferredAction(handlerInfo, typeItem)) {
- typeItem.setAttribute("actionIcon",
- this._getIconURLForPreferredAction(handlerInfo));
+ typeItem.setAttribute("actionIcon", handlerInfo.actionIcon);
}
},
manageApp(aEvent) {
// Don't let the normal "on select action" handler get this event,
// as we handle it specially ourselves.
aEvent.stopPropagation();
@@ -1969,18 +1967,17 @@ var gMainPane = {
let onComplete = () => {
// Rebuild the actions menu so that we revert to the previous selection,
// or "Always ask" if the previous default application has been removed
this.rebuildActionsMenu();
// update the richlistitem too. Will be visible when selecting another row
typeItem.setAttribute("actionDescription", handlerInfo.actionDescription);
if (!this._setIconClassForPreferredAction(handlerInfo, typeItem)) {
- typeItem.setAttribute("actionIcon",
- this._getIconURLForPreferredAction(handlerInfo));
+ typeItem.setAttribute("actionIcon", handlerInfo.actionIcon);
}
};
gSubDialog.open("chrome://browser/content/preferences/applicationManager.xul",
"resizable=no", handlerInfo, onComplete);
},
@@ -2071,62 +2068,25 @@ var gMainPane = {
},
_setIconClassForPreferredAction(aHandlerInfo, aElement) {
// If this returns true, the attribute that CSS sniffs for was set to something
// so you shouldn't manually set an icon URI.
// This removes the existing actionIcon attribute if any, even if returning false.
aElement.removeAttribute("actionIcon");
- if (aHandlerInfo.alwaysAskBeforeHandling) {
- aElement.setAttribute(APP_ICON_ATTR_NAME, "ask");
+ if (aHandlerInfo.actionIconClass) {
+ aElement.setAttribute(APP_ICON_ATTR_NAME, aHandlerInfo.actionIconClass);
return true;
}
- switch (aHandlerInfo.preferredAction) {
- case Ci.nsIHandlerInfo.saveToDisk:
- aElement.setAttribute(APP_ICON_ATTR_NAME, "save");
- return true;
-
- case Ci.nsIHandlerInfo.handleInternally:
- if (isFeedType(aHandlerInfo.type)) {
- aElement.setAttribute(APP_ICON_ATTR_NAME, "feed");
- return true;
- } else if (aHandlerInfo instanceof InternalHandlerInfoWrapper) {
- aElement.setAttribute(APP_ICON_ATTR_NAME, "ask");
- return true;
- }
- break;
-
- case kActionUsePlugin:
- aElement.setAttribute(APP_ICON_ATTR_NAME, "plugin");
- return true;
- }
aElement.removeAttribute(APP_ICON_ATTR_NAME);
return false;
},
- _getIconURLForPreferredAction(aHandlerInfo) {
- switch (aHandlerInfo.preferredAction) {
- case Ci.nsIHandlerInfo.useSystemDefault:
- return this._getIconURLForSystemDefault(aHandlerInfo);
-
- case Ci.nsIHandlerInfo.useHelperApp:
- let preferredApp = aHandlerInfo.preferredApplicationHandler;
- if (this.isValidHandlerApp(preferredApp))
- return this._getIconURLForHandlerApp(preferredApp);
- // Explicit fall-through
-
- // This should never happen, but if preferredAction is set to some weird
- // value, then fall back to the generic application icon.
- default:
- return ICON_URL_APP;
- }
- },
-
_getIconURLForHandlerApp(aHandlerApp) {
if (aHandlerApp instanceof Ci.nsILocalHandlerApp)
return this._getIconURLForFile(aHandlerApp.executable);
if (aHandlerApp instanceof Ci.nsIWebHandlerApp)
return this._getIconURLForWebApp(aHandlerApp.uriTemplate);
if (aHandlerApp instanceof Ci.nsIWebContentHandlerInfo)
@@ -2155,39 +2115,16 @@ var gMainPane = {
// in the template replaced by the URL of the content being handled).
if (/^https?$/.test(uri.scheme) && Services.prefs.getBoolPref("browser.chrome.favicons"))
return uri.prePath + "/favicon.ico";
return "";
},
- _getIconURLForSystemDefault(aHandlerInfo) {
- // Handler info objects for MIME types on some OSes implement a property bag
- // interface from which we can get an icon for the default app, so if we're
- // dealing with a MIME type on one of those OSes, then try to get the icon.
- if ("wrappedHandlerInfo" in aHandlerInfo) {
- let wrappedHandlerInfo = aHandlerInfo.wrappedHandlerInfo;
-
- if (wrappedHandlerInfo instanceof Ci.nsIMIMEInfo &&
- wrappedHandlerInfo instanceof Ci.nsIPropertyBag) {
- try {
- let url = wrappedHandlerInfo.getProperty("defaultApplicationIconURL");
- if (url)
- return url + "?size=16";
- } catch (ex) { }
- }
- }
-
- // If this isn't a MIME type object on an OS that supports retrieving
- // the icon, or if we couldn't retrieve the icon for some other reason,
- // then use a generic icon.
- return ICON_URL_APP;
- },
-
// DOWNLOADS
/*
* Preferences:
*
* browser.download.useDownloadDir - bool
* True - Save files directly to the folder configured via the
* browser.download.folderList preference.
@@ -2629,16 +2566,78 @@ class HandlerInfoWrapper {
return gMainPane._prefsBundle.getFormattedString("usePluginIn",
[this.pluginName,
gMainPane._brandShortName]);
default:
throw new Error(`Unexpected preferredAction: ${this.preferredAction}`);
}
}
+ get actionIconClass() {
+ if (this.alwaysAskBeforeHandling) {
+ return "ask";
+ }
+
+ switch (this.preferredAction) {
+ case Ci.nsIHandlerInfo.saveToDisk:
+ return "save";
+
+ case Ci.nsIHandlerInfo.handleInternally:
+ if (isFeedType(this.type)) {
+ return "feed";
+ } else if (this instanceof InternalHandlerInfoWrapper) {
+ return "ask";
+ }
+
+ case kActionUsePlugin:
+ return "plugin";
+ }
+
+ return "";
+ }
+
+ get actionIcon() {
+ switch (this.preferredAction) {
+ case Ci.nsIHandlerInfo.useSystemDefault:
+ return this.iconURLForSystemDefault;
+
+ case Ci.nsIHandlerInfo.useHelperApp:
+ let preferredApp = this.preferredApplicationHandler;
+ if (gMainPane.isValidHandlerApp(preferredApp)) {
+ return gMainPane._getIconURLForHandlerApp(preferredApp);
+ }
+ // Explicit fall-through
+
+ // This should never happen, but if preferredAction is set to some weird
+ // value, then fall back to the generic application icon.
+ default:
+ return ICON_URL_APP;
+ }
+ }
+
+ get iconURLForSystemDefault() {
+ // Handler info objects for MIME types on some OSes implement a property bag
+ // interface from which we can get an icon for the default app, so if we're
+ // dealing with a MIME type on one of those OSes, then try to get the icon.
+ if (this.wrappedHandlerInfo instanceof Ci.nsIMIMEInfo &&
+ this.wrappedHandlerInfo instanceof Ci.nsIPropertyBag) {
+ try {
+ let url = this.wrappedHandlerInfo.getProperty("defaultApplicationIconURL");
+ if (url) {
+ return url + "?size=16";
+ }
+ } catch (ex) { }
+ }
+
+ // If this isn't a MIME type object on an OS that supports retrieving
+ // the icon, or if we couldn't retrieve the icon for some other reason,
+ // then use a generic icon.
+ return ICON_URL_APP;
+ }
+
get preferredApplicationHandler() {
return this.wrappedHandlerInfo.preferredApplicationHandler;
}
set preferredApplicationHandler(aNewValue) {
this.wrappedHandlerInfo.preferredApplicationHandler = aNewValue;
// Make sure the preferred handler is in the set of possible handlers.