Bug 1356334: Part 4 - Add a helper to synchronously get an extension's name from its ID. r=billm
authorKris Maglione <maglione.k@gmail.com>
Fri, 11 Aug 2017 21:22:18 -0700
changeset 375515 7ebfb0df0958366c63048e2b943ce4f3827fbcf0
parent 375514 4b9185a04fe62a75a5a5b97947cb47f81ba2bfd3
child 375516 6aa43c3fc0c5fa4cf17714bbe8617990503ab1ef
push id93944
push usermaglione.k@gmail.com
push dateFri, 18 Aug 2017 18:06:51 +0000
treeherdermozilla-inbound@6f57bca8977c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1356334
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1356334: Part 4 - Add a helper to synchronously get an extension's name from its ID. r=billm MozReview-Commit-ID: 8nuvM4PR7XR
caps/nsIAddonPolicyService.idl
dom/webidl/WebExtensionPolicy.webidl
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/ExtensionPolicyService.cpp
toolkit/components/extensions/WebExtensionPolicy.cpp
toolkit/components/extensions/WebExtensionPolicy.h
toolkit/components/extensions/extension-process-script.js
--- a/caps/nsIAddonPolicyService.idl
+++ b/caps/nsIAddonPolicyService.idl
@@ -48,16 +48,22 @@ interface nsIAddonPolicyService : nsISup
   /**
    * Returns true if unprivileged code associated with the given addon may load
    * data from |aURI|.  If |aExplicit| is true, the <all_urls> permission and
    * permissive host globs are ignored when checking for a match.
    */
   boolean addonMayLoadURI(in AString aAddonId, in nsIURI aURI, [optional] in boolean aExplicit);
 
   /**
+   * Returns the name of the WebExtension with the given ID, or the ID string
+   * if no matching add-on can be found.
+   */
+  AString getExtensionName(in AString aAddonId);
+
+  /**
    * Returns true if a given extension:// URI is web-accessible.
    */
   boolean extensionURILoadableByAnyone(in nsIURI aURI);
 
   /**
    * Maps an extension URI to the ID of the addon it belongs to.
    */
   AString extensionURIToAddonId(in nsIURI aURI);
--- a/dom/webidl/WebExtensionPolicy.webidl
+++ b/dom/webidl/WebExtensionPolicy.webidl
@@ -30,16 +30,22 @@ interface WebExtensionPolicy {
   /**
    * The file: or jar: URL to use for the base of the extension's
    * moz-extension: URL root.
    */
   [Constant]
   readonly attribute ByteString baseURL;
 
   /**
+   * The extension's user-visible name.
+   */
+  [Constant]
+  readonly attribute DOMString name;
+
+  /**
    * The content security policy string to apply to all pages loaded from the
    * extension's moz-extension: protocol.
    */
   [Constant]
   readonly attribute DOMString contentSecurityPolicy;
 
 
   /**
@@ -137,16 +143,18 @@ interface WebExtensionPolicy {
 
 dictionary WebExtensionInit {
   required DOMString id;
 
   required ByteString mozExtensionHostname;
 
   required DOMString baseURL;
 
+  DOMString name = "";
+
   required WebExtensionLocalizeCallback localizeCallback;
 
   required MatchPatternSet allowedOrigins;
 
   sequence<DOMString> permissions = [];
 
   sequence<MatchGlob> webAccessibleResources = [];
 
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -988,16 +988,17 @@ this.Extension = class extends Extension
 
   // Representation of the extension to send to content
   // processes. This should include anything the content process might
   // need.
   serialize() {
     return {
       id: this.id,
       uuid: this.uuid,
+      name: this.name,
       instanceId: this.instanceId,
       manifest: this.manifest,
       resourceURL: this.resourceURL,
       baseURL: this.baseURI.spec,
       contentScripts: this.contentScripts,
       webAccessibleResources: this.webAccessibleResources.map(res => res.glob),
       whiteListedHosts: this.whiteListedHosts.patterns.map(pat => pat.pattern),
       localeData: this.localeData.serialize(),
--- a/toolkit/components/extensions/ExtensionPolicyService.cpp
+++ b/toolkit/components/extensions/ExtensionPolicyService.cpp
@@ -373,16 +373,27 @@ ExtensionPolicyService::AddonMayLoadURI(
   if (WebExtensionPolicy* policy = GetByID(aAddonId)) {
     *aResult = policy->CanAccessURI(aURI, aExplicit);
     return NS_OK;
   }
   return NS_ERROR_INVALID_ARG;
 }
 
 nsresult
+ExtensionPolicyService::GetExtensionName(const nsAString& aAddonId,
+                                         nsAString& aName)
+{
+  if (WebExtensionPolicy* policy = GetByID(aAddonId)) {
+    aName.Assign(policy->Name());
+    return NS_OK;
+  }
+  return NS_ERROR_INVALID_ARG;
+}
+
+nsresult
 ExtensionPolicyService::ExtensionURILoadableByAnyone(nsIURI* aURI, bool* aResult)
 {
   URLInfo url(aURI);
   if (WebExtensionPolicy* policy = GetByURL(url)) {
     *aResult = policy->IsPathWebAccessible(url.FilePath());
     return NS_OK;
   }
   return NS_ERROR_INVALID_ARG;
--- a/toolkit/components/extensions/WebExtensionPolicy.cpp
+++ b/toolkit/components/extensions/WebExtensionPolicy.cpp
@@ -84,16 +84,17 @@ Proto()
  * WebExtensionPolicy
  *****************************************************************************/
 
 WebExtensionPolicy::WebExtensionPolicy(GlobalObject& aGlobal,
                                        const WebExtensionInit& aInit,
                                        ErrorResult& aRv)
   : mId(NS_AtomizeMainThread(aInit.mId))
   , mHostname(aInit.mMozExtensionHostname)
+  , mName(aInit.mName)
   , mContentSecurityPolicy(aInit.mContentSecurityPolicy)
   , mLocalizeCallback(aInit.mLocalizeCallback)
   , mPermissions(new AtomSet(aInit.mPermissions))
   , mHostPermissions(aInit.mAllowedOrigins)
 {
   mWebAccessiblePaths.AppendElements(aInit.mWebAccessibleResources);
 
   if (!aInit.mBackgroundScripts.IsNull()) {
--- a/toolkit/components/extensions/WebExtensionPolicy.h
+++ b/toolkit/components/extensions/WebExtensionPolicy.h
@@ -77,16 +77,25 @@ public:
   {
     return mPermissions->Contains(aPermission);
   }
 
   nsCString BackgroundPageHTML() const;
 
   void Localize(const nsAString& aInput, nsString& aResult) const;
 
+  const nsString& Name() const
+  {
+    return mName;
+  }
+  void GetName(nsAString& aName) const
+  {
+    aName = mName;
+  }
+
   const nsString& ContentSecurityPolicy() const
   {
     return mContentSecurityPolicy;
   }
   void GetContentSecurityPolicy(nsAString& aCSP) const
   {
     aCSP = mContentSecurityPolicy;
   }
@@ -148,16 +157,17 @@ private:
   bool Disable();
 
   nsCOMPtr<nsISupports> mParent;
 
   nsCOMPtr<nsIAtom> mId;
   nsCString mHostname;
   nsCOMPtr<nsIURI> mBaseURI;
 
+  nsString mName;
   nsString mContentSecurityPolicy;
 
   bool mActive = false;
 
   RefPtr<WebExtensionLocalizeCallback> mLocalizeCallback;
 
   RefPtr<AtomSet> mPermissions;
   RefPtr<MatchPatternSet> mHostPermissions;
--- a/toolkit/components/extensions/extension-process-script.js
+++ b/toolkit/components/extensions/extension-process-script.js
@@ -312,16 +312,17 @@ ExtensionManager = {
         localizeCallback = str => extensions.get(policy).localize(str);
         allowedOrigins = new MatchPatternSet(extension.whiteListedHosts);
         webAccessibleResources = extension.webAccessibleResources.map(host => new MatchGlob(host));
       }
 
       policy = new WebExtensionPolicy({
         id: extension.id,
         mozExtensionHostname: extension.uuid,
+        name: extension.name,
         baseURL: extension.resourceURL,
 
         permissions: Array.from(extension.permissions),
         allowedOrigins,
         webAccessibleResources,
 
         contentSecurityPolicy: extension.manifest.content_security_policy,