Bug 1293721 follow up: handle pre-existing absolute optionsURL r?kmag draft
authorAndrew Swan <aswan@mozilla.com>
Thu, 11 Aug 2016 09:59:03 -0700
changeset 399725 ad81ade5b8f39c5274cfdac1adc94af9089eb2af
parent 399267 e2f03a177c0a9685df0733258d58467a641ec149
child 528039 2186450577d519bb7eb9d5159727fce3708d0436
push id25960
push useraswan@mozilla.com
push dateThu, 11 Aug 2016 22:58:22 +0000
reviewerskmag
bugs1293721
milestone51.0a1
Bug 1293721 follow up: handle pre-existing absolute optionsURL r?kmag MozReview-Commit-ID: GafnS4ckUiY
toolkit/mozapps/extensions/internal/XPIProvider.jsm
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -81,16 +81,18 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                    "amIAddonPathService");
 
 XPCOMUtils.defineLazyGetter(this, "CertUtils", function() {
   let certUtils = {};
   Components.utils.import("resource://gre/modules/CertUtils.jsm", certUtils);
   return certUtils;
 });
 
+Cu.importGlobalProperties(["URL"]);
+
 const nsIFile = Components.Constructor("@mozilla.org/file/local;1", "nsIFile",
                                        "initWithPath");
 
 const PREF_DB_SCHEMA                  = "extensions.databaseSchema";
 const PREF_INSTALL_CACHE              = "extensions.installCache";
 const PREF_XPI_STATE                  = "extensions.xpiState";
 const PREF_BOOTSTRAP_ADDONS           = "extensions.bootstrappedAddons";
 const PREF_PENDING_OPERATIONS         = "extensions.pendingOperations";
@@ -7242,17 +7244,25 @@ AddonWrapper.prototype = {
   get optionsURL() {
     if (!this.isActive) {
       return null;
     }
 
     let addon = addonFor(this);
     if (addon.optionsURL) {
       if (this.isWebExtension) {
-        return ExtensionManagement.getURLForExtension(addon.id, addon.optionsURL);
+        // The internal object's optionsURL property comes from the addons
+        // DB and should be a relative URL.  However, extensions with
+        // options pages installed before bug 1293721 was fixed got absolute
+        // URLs in the addons db.  This code handles both cases.
+        let base = ExtensionManagement.getURLForExtension(addon.id);
+        if (!base) {
+          return null;
+        }
+        return new URL(addon.optionsURL, base).href;
       }
       return addon.optionsURL;
     }
 
     if (this.hasResource("options.xul"))
       return this.getResourceURI("options.xul").spec;
 
     return null;