bug 1282977 handle developer in manifest r?kmag draft
authorAndy McKay <amckay@mozilla.com>
Fri, 22 Jul 2016 15:38:15 -0700
changeset 392111 59016b22b50fd7b3c26f1c1e77641d739bb1be0e
parent 391305 e0bc88708ffed39aaab1fbc0ac461d93561195de
child 392112 5cb66a0f8b59584f11e66693c1b04e9ddd4e0b65
push id23941
push userbmo:amckay@mozilla.com
push dateSat, 23 Jul 2016 02:14:46 +0000
reviewerskmag
bugs1282977
milestone50.0a1
bug 1282977 handle developer in manifest r?kmag MozReview-Commit-ID: Ja5J0Tu2x1E
toolkit/components/extensions/schemas/manifest.json
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/addons/webextension_4/_locales/en/messages.json
toolkit/mozapps/extensions/test/addons/webextension_4/_locales/fr/messages.json
toolkit/mozapps/extensions/test/addons/webextension_4/manifest.json
toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
--- a/toolkit/components/extensions/schemas/manifest.json
+++ b/toolkit/components/extensions/schemas/manifest.json
@@ -170,17 +170,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
@@ -949,21 +949,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.creator;
+    let homepageURL = rawManifest.homepage_url;
+
+    // Allow developer to override creator and homepage_url.
+    if ('developer' in rawManifest) {
+      if ('name' in rawManifest.developer) {
+        creator = rawManifest.developer.name;
+      }
+      if ('url' in rawManifest.developer) {
+        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;
   }
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/webextension_4/_locales/en/messages.json
@@ -0,0 +1,8 @@
+{
+  "name": {
+    "message": "en name"
+  },
+  "url": {
+    "message": "https://example.net/en"
+  }
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/webextension_4/_locales/fr/messages.json
@@ -0,0 +1,8 @@
+{
+  "name": {
+    "message": "fr name"
+  },
+  "url": {
+    "message": "https://example.net/fr"
+  }
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/addons/webextension_4/manifest.json
@@ -0,0 +1,16 @@
+{
+  "name": "Some name",
+  "description": "Some description",
+  "version": "1.0",
+  "manifest_version": 2,
+  "default_locale": "en",
+  "developer": {
+      "name": "__MSG_name__",
+      "url": "__MSG_url__"
+  },
+  "applications": {
+    "gecko": {
+      "id": "webextension4@tests.mozilla.org"
+    }
+  }
+}
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension.js
@@ -289,8 +289,56 @@ add_task(function* test_options_ui() {
   equal(addon.optionsType, AddonManager.OPTIONS_TYPE_TAB,
         "Addon should have a TAB options type");
 
   ok(OPTIONS_RE.test(addon.optionsURL),
      "Addon should have a moz-extension: options URL for /options.html");
 
   addon.uninstall();
 });
+
+
+add_task(function* developerShouldOverride() {
+  const ID = "webextension4@tests.mozilla.org";
+
+  yield promiseInstallAllFiles([do_get_addon("webextension_4")], true);
+  yield promiseAddonStartup();
+
+  let addon = yield promiseAddonByID(ID);
+  addon.userDisabled = true;
+
+  // Test that it overrode.
+  do_check_eq(addon.creator, "en name");
+  do_check_eq(addon.homepageURL, "https://example.net/en");
+
+  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
+  yield promiseRestartManager();
+  addon = yield promiseAddonByID(ID);
+
+  // Test that it overrode and localised.
+  do_check_eq(addon.creator, "fr name");
+  do_check_eq(addon.homepageURL, "https://example.net/fr");
+  addon.uninstall();
+});
+
+
+add_task(function* developerEmpty() {
+  writeWebManifestForExtension({
+    name: "Web Extension Name",
+    version: "1.0",
+    manifest_version: 2,
+    creator: "Some creator",
+    developer: {},
+    applications: {
+      gecko: {
+        id: ID
+      }
+    }
+
+  }, profileDir);
+
+  yield promiseRestartManager();
+
+  let addon = yield promiseAddonByID(ID);
+  do_check_eq(addon.creator, "Some creator");
+  do_check_eq(addon.homepageURL, null);
+  addon.uninstall();
+});