bug 1282977 handle developer in manifest r=kmag
authorAndy McKay <amckay@mozilla.com>
Thu, 15 Sep 2016 16:37:16 -0700
changeset 316783 23887d112341a01d14e2a65b87b7a49601e17ed2
parent 316782 2f033b5b7fd6eaff5cc7a6e5209e52f0a77ee607
child 316784 5322af204cb05bea9336b2a500cc65f6a2549575
push id32926
push userryanvm@gmail.com
push dateFri, 07 Oct 2016 00:31:25 +0000
treeherderautoland@23887d112341 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1282977
milestone52.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 1282977 handle developer in manifest r=kmag MozReview-Commit-ID: BsGflddsodd
toolkit/components/extensions/schemas/manifest.json
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
--- a/toolkit/components/extensions/schemas/manifest.json
+++ b/toolkit/components/extensions/schemas/manifest.json
@@ -53,17 +53,17 @@
           },
 
           "description": {
             "type": "string",
             "optional": true,
             "preprocess": "localize"
           },
 
-          "creator": {
+          "author": {
             "type": "string",
             "optional": true,
             "preprocess": "localize"
           },
 
           "version": {
             "type": "string",
             "optional": false
@@ -175,17 +175,35 @@
             },
             "optional": true
           },
 
           "web_accessible_resources": {
             "type": "array",
             "items": { "type": "string" },
             "optional": true
+          },
+
+          "developer": {
+            "type": "object",
+            "optional": true,
+            "properties": {
+              "name": {
+                "type": "string",
+                "optional": true,
+                "preprocess": "localize"
+              },
+              "url": {
+                "type": "string",
+                "optional": true,
+                "preprocess": "localize"
+              }
+            }
           }
+
         },
 
         "additionalProperties": { "$ref": "UnrecognizedProperty" }
       },
       {
         "id": "Permission",
         "choices": [
           {
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -971,21 +971,34 @@ var loadManifestFromWebManifest = Task.a
 
   addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DEFAULT;
 
   function getLocale(aLocale) {
     // Use the raw manifest, here, since we need values with their
     // localization placeholders still in place.
     let rawManifest = extension.rawManifest;
 
+    let creator = rawManifest.author;
+    let homepageURL = rawManifest.homepage_url;
+
+    // Allow developer to override creator and homepage_url.
+    if (rawManifest.developer) {
+      if (rawManifest.developer.name) {
+        creator = rawManifest.developer.name;
+      }
+      if (rawManifest.developer.url) {
+        homepageURL = rawManifest.developer.url;
+      }
+    }
+
     let result = {
       name: extension.localize(rawManifest.name, aLocale),
       description: extension.localize(rawManifest.description, aLocale),
-      creator: extension.localize(rawManifest.creator, aLocale),
-      homepageURL: extension.localize(rawManifest.homepage_url, aLocale),
+      creator: extension.localize(creator, aLocale),
+      homepageURL: extension.localize(homepageURL, aLocale),
 
       developers: null,
       translators: null,
       contributors: null,
       locales: [aLocale],
     };
     return result;
   }
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
@@ -14,21 +14,21 @@ profileDir.append("extensions");
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
 startupManager();
 
 const { GlobalManager, Management } = Components.utils.import("resource://gre/modules/Extension.jsm", {});
 
 function promiseAddonStartup() {
   return new Promise(resolve => {
     let listener = (evt, extension) => {
-      Management.off("startup", listener);
+      Management.off("ready", listener);
       resolve(extension);
     };
 
-    Management.on("startup", listener);
+    Management.on("ready", listener);
   });
 }
 
 function promiseInstallWebExtension(aData) {
   let addonFile = createTempWebExtensionFile(aData);
 
   return promiseInstallAllFiles([addonFile]).then(() => {
     Services.obs.notifyObservers(addonFile, "flush-cache-entry", null);
@@ -348,8 +348,57 @@ add_task(function* test_experiments_api(
   let addon = addons.pop();
   equal(addon.id, ID, "Add-on should be installed as an API extension");
 
   addons = yield new Promise(resolve => AddonManager.getAddonsByTypes(["extension"], resolve));
   equal(addons.pop().id, ID, "Add-on type should be aliased to extension");
 
   addon.uninstall();
 });
+
+add_task(function* developerShouldOverride() {
+  let addon = yield promiseInstallWebExtension({
+    manifest: {
+      default_locale: "en",
+      developer: {
+        name: "__MSG_name__",
+        url: "__MSG_url__"
+      },
+      author: "Will be overridden by developer",
+      homepage_url: "https://will.be.overridden",
+    },
+    files: {
+      "_locales/en/messages.json": `{
+        "name": {
+          "message": "en name"
+        },
+        "url": {
+          "message": "https://example.net/en"
+        }
+      }`
+    }
+  });
+
+  addon = yield promiseAddonByID(addon.id);
+  equal(addon.creator, "en name");
+  equal(addon.homepageURL, "https://example.net/en");
+  addon.uninstall();
+});
+
+add_task(function* developerEmpty() {
+  for (let developer of [{}, null, {name: null, url: null}]) {
+    let addon = yield promiseInstallWebExtension({
+      manifest: {
+        author: "Some author",
+        developer: developer,
+        homepage_url: "https://example.net",
+        manifest_version: 2,
+        name: "Web Extension Name",
+        version: "1.0",
+      }
+    });
+
+    addon = yield promiseAddonByID(addon.id);
+    equal(addon.creator, "Some author");
+    equal(addon.homepageURL, "https://example.net");
+    addon.uninstall();
+  }
+});
\ No newline at end of file