Bug 511091: Support custom icons for disabled extensions. r=robstrong
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 20 Aug 2009 10:59:07 +0100
changeset 31680 9f8181d17a140deae97c34e9d85870c68b1771db
parent 31679 325a834b759c3f96be465ab55c475bb81842d6d8
child 31681 d4e5fa9e2e914cd8221f5a146afadf70cd6b213e
push id8664
push userdtownsend@mozilla.com
push dateThu, 20 Aug 2009 10:05:45 +0000
treeherdermozilla-central@9f8181d17a14 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobstrong
bugs511091
milestone1.9.3a1pre
Bug 511091: Support custom icons for disabled extensions. r=robstrong
toolkit/mozapps/extensions/src/nsExtensionManager.js.in
toolkit/mozapps/extensions/test/addons/test_bug511091/icon.png
toolkit/mozapps/extensions/test/addons/test_bug511091/install.rdf
toolkit/mozapps/extensions/test/unit/test_bug511091.js
--- a/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
+++ b/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
@@ -7747,77 +7747,80 @@ ExtensionsDataSource.prototype = {
     return this._inner.GetSource(property, target, truthValue);
   },
 
   GetSources: function EMDS_GetSources(property, target, truthValue) {
     return this._inner.GetSources(property, target, truthValue);
   },
 
   /**
-   * Gets an URL to a theme's image file
+   * Gets an URL to an item's image file
    * @param   item
    *          The RDF Resource representing the item
    * @param   fileName
    *          The file to locate a URL for
-   * @param   fallbackURL
-   *          If the location fails, supply this URL instead
    * @returns An RDF Resource to the URL discovered, or the fallback
    *          if the discovery failed.
    */
-  _getThemeImageURL: function EMDS__getThemeImageURL(item, fileName, fallbackURL) {
+  _getImageURL: function EMDS__getImageURL(item, fileName) {
     var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
     var installLocation = this._em.getInstallLocation(id);
     if (!installLocation)
       return fallbackURL;
     var file = installLocation.getItemFile(id, fileName)
     if (file.exists())
       return gRDF.GetResource(getURLSpecFromFile(file));
 
-    return fallbackURL ? gRDF.GetResource(fallbackURL) : null;
+    return null;
   },
 
   /**
    * Get the em:iconURL property (icon url of the item)
    */
   _rdfGet_iconURL: function EMDS__rdfGet_iconURL(item, property) {
     var id = stripPrefix(item.Value, PREFIX_ITEM_URI);
     var type = this.getItemProperty(id, "type");
-    if (type & Ci.nsIUpdateItem.TYPE_THEME)
-      return this._getThemeImageURL(item, "icon.png", URI_GENERIC_ICON_THEME);
-
-    if (inSafeMode())
-      return gRDF.GetResource(URI_GENERIC_ICON_XPINSTALL);
-
-    var hasIconURL = this._inner.hasArcOut(item, property);
-    // If the addon doesn't have an IconURL property or it is disabled use the
-    // generic icon URL instead.
-    if (!hasIconURL || this.getItemProperty(id, "isDisabled") == "true")
-      return gRDF.GetResource(URI_GENERIC_ICON_XPINSTALL);
-    var iconURL = stringData(this._inner.GetTarget(item, property, true));
-    try {
-      var uri = newURI(iconURL);
-      var scheme = uri.scheme;
-      // Only allow chrome URIs or when installing http(s) URIs.
-      if (scheme == "chrome" || (scheme == "http" || scheme == "https") &&
-          this._inner.hasArcOut(item, EM_R("downloadURL")))
-        return null;
-    }
-    catch (e) {
-    }
-    // Use a generic icon URL for addons that have an invalid iconURL.
+
+    // Try to pick an icon from the item's install folder
+    iconURL = this._getImageURL(item, "icon.png");
+    if (iconURL)
+      return iconURL;
+
+    if (type == Ci.nsIUpdateItem.TYPE_THEME)
+      return gRDF.GetResource(URI_GENERIC_ICON_THEME);
+
+    // Only look for an iconURL if the item is not disabled and safe mode isn't
+    // active
+    if (!inSafeMode() && this.getItemProperty(id, "isDisabled") != "true") {
+      var iconURL = stringData(this._inner.GetTarget(item, property, true));
+      if (iconURL) {
+        try {
+          var uri = newURI(iconURL);
+          var scheme = uri.scheme;
+          // Only allow chrome URIs normally. When an item is being installed
+          // allow http(s) URIs.
+          if (scheme == "chrome" || (scheme == "http" || scheme == "https") &&
+              this._inner.hasArcOut(item, EM_R("downloadURL")))
+            return null;
+        }
+        catch (e) {
+        }
+      }
+    }
+
     return gRDF.GetResource(URI_GENERIC_ICON_XPINSTALL);
   },
 
   /**
    * Get the em:previewImage property (preview image of the item)
    */
   _rdfGet_previewImage: function EMDS__rdfGet_previewImage(item, property) {
     var type = this.getItemProperty(stripPrefix(item.Value, PREFIX_ITEM_URI), "type");
-    if (type != -1 && type & Ci.nsIUpdateItem.TYPE_THEME)
-      return this._getThemeImageURL(item, "preview.png", null);
+    if (type == Ci.nsIUpdateItem.TYPE_THEME)
+      return this._getImageURL(item, "preview.png");
     return null;
   },
 
   /**
    * If we're in safe mode, the item is disabled by the user or app, or the
    * item is to not an extension then don't offer an options url.
    */
   _rdfGet_optionsURL: function EMDS__rdfGet_optionsURL(item, property) {
new file mode 100644
index 0000000000000000000000000000000000000000..a86d0070049f7d1d07e074844499155d9c0b80da
GIT binary patch
literal 1937
zc$@)|2X6R@P)<h;3K|Lk000e1NJLTq001BW001Be1^@s6b9#F80000PbVXQnQ*UN;
zcVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBU(Gf6~2RCwC7S8HrsM-@JE=RWp&*X!MF
zytcQoTRU+`+9V{Tp#`-SueSUE+Dd67giuu)gao33M4}QBmH$u#0;#`>6j1*lRH=j%
zrK&)*NTDiiXxirCk~pb|ohII7*V*+xy!SmboVoX|y(#O5Qn**gp1Egs=9_cAbLI@0
zn3#ao9vnmPpMpZ-PogcT6Ywz}bqx#CC;oWfGm1*Suc$OZGzFOL183r;%5?MF69*=$
z9|wfGn*LjdzVuvwA-C_24R-@2DsX%ar3cPlJ^ApII5Uc4?nD6oje<~C*uB*0x~cEG
zZFD<S*;Od{m!RxjhKu$T<g)7kbvwTN^se!h=DA@2vA=cAP{9>8a3MgTa3O6Vz+z3%
z3>|th+E@oS{-*#!eXC}<w(sDQB3w9R9{y=LEvU~moWuK%{p0@$fK_J}o<2WyF5JBk
zJchyH!kK?Vd8+n9923M5aYGN0VHmT$n+r^o>^Fb+`8RL-^ycAIG8MYQbv!ur=IP?^
zA3M4m^)(b1g)hUU6~Tq^{rHPte4MJvlg#6<;%KKG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
z3p1gaHGa!;YQobgcwj^S*dSzUY>z@=4^=f785@ULtc0Ym*YYr*0jYv}<VSBmuw&2Y
z=3y)UjMfL681+Gs7Ob)}rw-4^quiGObV9^do*<E3@hMqF=uM`fux(@5FFLbW0ky&e
z6`Bo^X+&QZ0Cg2`eLgLZ>XV12-$1#4=Obe~G2vwbJD5N5;)Qon*9-yd+`A#mRq59N
z)8bNnQg>^igdB45j4cL0ElduQP9_+v5CBPZuV*AFNyHE<t`)2kf4J~^d@#vf`Y2xL
zg1`zWBMkfiW1eW;i-rn=%K7@Q{`T|J&&vsRe`EZfTkg#tBxB21f$=s$gLom)ajy_D
z2ri2ib@JtljV%ujgBN%}DeXGnfH?s3v{A-pMNU8{DJE1CRLpoyzwuw=1LiM<V03w5
z?Q@~~y#R6g_#=ZDT>&I=Dd@X7IkD}*TV5av5u=|SIyAQVc9?9u*LA!t959L2yVi?I
z$UNJ#p@;Nz9aQHv=pQPWtzF(jimIgh2MdXkTMXm5D*%FXDf;@j8d|j~=7GbeB+)qU
zE_J5{8Wt=>@G<84D(4KGz*%;@gIP-wG4?rG6@c_p%e685O3?J0*GbjE!$V}Dc<~Z6
z%l2DWCg=Y$JN=<!ENC#lFb{L~wd=-~tTM<N(K2lK+=1=)tfeFqZY%ivkkP*dEfM8$
zM4$HX^oxSVD_WN(@gn-{vFE3bN;0`E{{iPt?<ZL^y_-<zb14=vDv}uUuE8}J@NSZ+
z*Acqgw;BMcl+4Sb^u=xHxPk{Ud)+vut=M9+cu2<MwRU0CnT_MIb(EI8ye<deKLQK@
X^rN=UD@q{t00000NkvXXu0mjfc;&rl
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/test_bug511091/install.rdf
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+
+  <Description about="urn:mozilla:install-manifest">
+    <em:id>bug511091@tests.mozilla.org</em:id>
+    <em:version>1.0</em:version>
+
+    <em:targetApplication>
+      <Description>
+        <em:id>xpcshell@tests.mozilla.org</em:id>
+        <em:minVersion>1</em:minVersion>
+        <em:maxVersion>1</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+
+    <!-- Front End MetaData -->
+    <em:name>Icon test</em:name>
+    <em:iconURL>chrome://foo/content/bar</em:iconURL>
+
+  </Description>
+</RDF>
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/unit/test_bug511091.js
@@ -0,0 +1,75 @@
+/* ***** 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 mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ *      Dave Townsend <dtownsend@oxymoronical.com>.
+ *
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * 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 ID = "bug511091@tests.mozilla.org";
+const ADDON = "test_bug511091";
+
+function run_test()
+{
+  // Setup for test
+  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1");
+
+  // Install test add-on
+  startupEM();
+  gEM.installItemFromFile(do_get_addon(ADDON), NS_INSTALL_LOCATION_APPPROFILE);
+  var addon = gEM.getItemForID(ID);
+  do_check_neq(addon, null);
+  do_check_eq(getManifestProperty(ID, "iconURL"), "chrome://mozapps/skin/xpinstall/xpinstallItemGeneric.png");
+  restartEM();
+
+  var location = gEM.getInstallLocation(ID);
+  var file = location.getItemFile(ID, "icon.png");
+  var ioservice = Components.classes["@mozilla.org/network/io-service;1"]
+                            .getService(Components.interfaces.nsIIOService);
+
+  var addon = gEM.getItemForID(ID);
+  do_check_neq(addon, null);
+  var uri = ioservice.newURI(getManifestProperty(ID, "iconURL"), null, null);
+  uri.QueryInterface(Components.interfaces.nsIFileURL);
+  do_check_true(uri.file.equals(file));
+  gEM.disableItem(ID);
+  restartEM();
+
+  addon = gEM.getItemForID(ID);
+  do_check_neq(addon, null);
+  uri = ioservice.newURI(getManifestProperty(ID, "iconURL"), null, null);
+  uri.QueryInterface(Components.interfaces.nsIFileURL);
+  do_check_true(uri.file.equals(file));
+
+  shutdownEM();
+}