diff --git a/toolkit/mozapps/extensions/AddonPathService.cpp b/toolkit/mozapps/extensions/AddonPathService.cpp index 71d4cb5a9668..d171f0aebdfc 100644 --- a/toolkit/mozapps/extensions/AddonPathService.cpp +++ b/toolkit/mozapps/extensions/AddonPathService.cpp @@ -14,12 +14,14 @@ #include "nsThreadUtils.h" #include "nsIIOService.h" #include "nsNetUtil.h" +#include "nsIAddonPolicyService.h" #include "nsIFileURL.h" #include "nsIResProtocolHandler.h" #include "nsIChromeRegistry.h" #include "nsIJARURI.h" #include "nsJSUtils.h" #include "mozilla/dom/ScriptSettings.h" +#include "mozilla/dom/ToJSValue.h" #include "mozilla/AddonPathService.h" #include "mozilla/Omnijar.h" @@ -65,6 +67,18 @@ AddonPathService::GetInstance() return sInstance; } +static JSAddonId* +ConvertAddonId(const nsAString& addonIdString) +{ + AutoSafeJSContext cx; + JS::RootedValue strv(cx); + if (!mozilla::dom::ToJSValue(cx, addonIdString, &strv)) { + return nullptr; + } + JS::RootedString str(cx, strv.toString()); + return JS::NewAddonId(cx, str); +} + JSAddonId* AddonPathService::Find(const nsAString& path) { @@ -107,11 +121,7 @@ AddonPathService::FindAddonId(const nsAString& path) NS_IMETHODIMP AddonPathService::InsertPath(const nsAString& path, const nsAString& addonIdString) { - AutoSafeJSContext cx; - JS::RootedString str(cx, JS_NewUCStringCopyN(cx, - addonIdString.BeginReading(), - addonIdString.Length())); - JSAddonId* addonId = JS::NewAddonId(cx, str); + JSAddonId* addonId = ConvertAddonId(addonIdString); // Add the new path in sorted order. PathEntryComparator comparator; @@ -198,8 +208,22 @@ MapURIToAddonID(nsIURI* aURI) return nullptr; } + bool equals; + nsresult rv; + if (NS_SUCCEEDED(aURI->SchemeIs("moz-extension", &equals)) && equals) { + nsCOMPtr service = do_GetService("@mozilla.org/addons/policy-service;1"); + if (service) { + nsString addonId; + rv = service->ExtensionURIToAddonId(aURI, addonId); + if (NS_FAILED(rv)) + return nullptr; + + return ConvertAddonId(addonId); + } + } + nsAutoString filePath; - nsresult rv = ResolveURI(aURI, filePath); + rv = ResolveURI(aURI, filePath); if (NS_FAILED(rv)) return nullptr; diff --git a/toolkit/mozapps/extensions/internal/XPIProvider.jsm b/toolkit/mozapps/extensions/internal/XPIProvider.jsm index e4c6f987770b..00f81f7e6fda 100644 --- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm +++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm @@ -54,6 +54,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "ResProtocolHandler", "@mozilla.org/network/protocol;1?name=resource", "nsIResProtocolHandler"); +XPCOMUtils.defineLazyServiceGetter(this, + "AddonPolicyService", + "@mozilla.org/addons/policy-service;1", + "nsIAddonPolicyService"); XPCOMUtils.defineLazyGetter(this, "CertUtils", function certUtilsLazyGetter() { let certUtils = {}; @@ -4028,6 +4032,10 @@ this.XPIProvider = { * @see amIAddonManager.mapURIToAddonID */ mapURIToAddonID: function XPI_mapURIToAddonID(aURI) { + if (aURI.scheme == "moz-extension") { + return AddonPolicyService.extensionURIToAddonId(aURI); + } + let resolved = this._resolveURIToFile(aURI); if (!resolved || !(resolved instanceof Ci.nsIFileURL)) return null;