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 399630 f574964e696e877f824b16bf83ec4444c87f6b06
parent 399267 e2f03a177c0a9685df0733258d58467a641ec149
child 527991 35be7fbb3a1395896e791e7baeef4626eed58d4c
push id25904
push useraswan@mozilla.com
push dateThu, 11 Aug 2016 17:50:00 +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,22 @@ 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);
+        return new URL(addon.optionsURL, base).href;
       }
       return addon.optionsURL;
     }
 
     if (this.hasResource("options.xul"))
       return this.getResourceURI("options.xul").spec;
 
     return null;