Bug 1287010 - Use schema-generated i18n for all contexts r=billm
authorRob Wu <rob@robwu.nl>
Sat, 20 Aug 2016 15:49:20 -0700
changeset 311149 e4ce08beaf7474321a89ee4f45cf88e943f32618
parent 311148 aac2a4039d9a5a2d1256cd1c1aec9c4487eb41f3
child 311150 2427f8eb4e83add47679215a19cabbb81dcc12a1
push id30602
push userkwierso@gmail.com
push dateThu, 25 Aug 2016 23:53:05 +0000
treeherdermozilla-central@cd4ed9909dc9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1287010
milestone51.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 1287010 - Use schema-generated i18n for all contexts r=billm Use schema-generated i18n API for both content script and addon contexts, instead of just the addon context. MozReview-Commit-ID: AKDAFxNv6Zs
toolkit/components/extensions/ExtensionContent.jsm
toolkit/components/extensions/ext-i18n.js
toolkit/components/extensions/extensions-toolkit.manifest
toolkit/components/extensions/schemas/i18n.json
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -45,17 +45,16 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 Cu.import("resource://gre/modules/ExtensionUtils.jsm");
 var {
   runSafeSyncWithoutClone,
   BaseContext,
   LocaleData,
   Messenger,
   injectAPI,
   flushJarCache,
-  detectLanguage,
   getInnerWindowID,
   promiseDocumentReady,
   ChildAPIManager,
   SchemaAPIManager,
 } = ExtensionUtils;
 
 XPCOMUtils.defineLazyGetter(this, "console", ExtensionUtils.getConsole);
 
@@ -150,36 +149,16 @@ var api = context => {
       },
 
       get lastError() {
         return context.lastError;
       },
 
       inIncognitoContext: PrivateBrowsingUtils.isContentWindowPrivate(context.contentWindow),
     },
-
-    i18n: {
-      getMessage: function(messageName, substitutions) {
-        return context.extension.localizeMessage(messageName, substitutions, {cloneScope: context.cloneScope});
-      },
-
-      getAcceptLanguages: function(callback) {
-        let result = context.extension.localeData.acceptLanguages;
-        return context.wrapPromise(Promise.resolve(result), callback);
-      },
-
-      getUILanguage: function() {
-        return context.extension.localeData.uiLocale;
-      },
-
-      detectLanguage: function(text, callback) {
-        let result = detectLanguage(text);
-        return context.wrapPromise(result, callback);
-      },
-    },
   };
 };
 
 // Represents a content script.
 function Script(extension, options, deferred = PromiseUtils.defer()) {
   this.extension = extension;
   this.options = options;
   this.run_at = this.options.run_at;
--- a/toolkit/components/extensions/ext-i18n.js
+++ b/toolkit/components/extensions/ext-i18n.js
@@ -2,17 +2,17 @@
 
 var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/ExtensionUtils.jsm");
 var {
   detectLanguage,
 } = ExtensionUtils;
 
-extensions.registerSchemaAPI("i18n", "addon_parent", context => {
+function i18nApiFactory(context) {
   let {extension} = context;
   return {
     i18n: {
       getMessage: function(messageName, substitutions) {
         return extension.localizeMessage(messageName, substitutions, {cloneScope: context.cloneScope});
       },
 
       getAcceptLanguages: function() {
@@ -24,9 +24,11 @@ extensions.registerSchemaAPI("i18n", "ad
         return extension.localeData.uiLocale;
       },
 
       detectLanguage: function(text) {
         return detectLanguage(text);
       },
     },
   };
-});
+}
+extensions.registerSchemaAPI("i18n", "addon_child", i18nApiFactory);
+extensions.registerSchemaAPI("i18n", "content_child", i18nApiFactory);
--- a/toolkit/components/extensions/extensions-toolkit.manifest
+++ b/toolkit/components/extensions/extensions-toolkit.manifest
@@ -9,25 +9,28 @@ category webextension-scripts i18n chrom
 category webextension-scripts idle chrome://extensions/content/ext-idle.js
 category webextension-scripts webRequest chrome://extensions/content/ext-webRequest.js
 category webextension-scripts webNavigation chrome://extensions/content/ext-webNavigation.js
 category webextension-scripts runtime chrome://extensions/content/ext-runtime.js
 category webextension-scripts extension chrome://extensions/content/ext-extension.js
 category webextension-scripts storage chrome://extensions/content/ext-storage.js
 category webextension-scripts test chrome://extensions/content/ext-test.js
 
+# scripts specific for content process.
+category webextension-scripts-content i18n chrome://extensions/content/ext-i18n.js
+
 # schemas
 category webextension-schemas alarms chrome://extensions/content/schemas/alarms.json
 category webextension-schemas cookies chrome://extensions/content/schemas/cookies.json
 category webextension-schemas downloads chrome://extensions/content/schemas/downloads.json
 category webextension-schemas events chrome://extensions/content/schemas/events.json
 category webextension-schemas extension chrome://extensions/content/schemas/extension.json
 category webextension-schemas extension_types chrome://extensions/content/schemas/extension_types.json
 category webextension-schemas i18n chrome://extensions/content/schemas/i18n.json
 category webextension-schemas idle chrome://extensions/content/schemas/idle.json
 category webextension-schemas management chrome://extensions/content/schemas/management.json
 category webextension-schemas native_host_manifest chrome://extensions/content/schemas/native_host_manifest.json
 category webextension-schemas notifications chrome://extensions/content/schemas/notifications.json
 category webextension-schemas runtime chrome://extensions/content/schemas/runtime.json
 category webextension-schemas storage chrome://extensions/content/schemas/storage.json
 category webextension-schemas test chrome://extensions/content/schemas/test.json
 category webextension-schemas web_navigation chrome://extensions/content/schemas/web_navigation.json
-category webextension-schemas web_request chrome://extensions/content/schemas/web_request.json
\ No newline at end of file
+category webextension-schemas web_request chrome://extensions/content/schemas/web_request.json
--- a/toolkit/components/extensions/schemas/i18n.json
+++ b/toolkit/components/extensions/schemas/i18n.json
@@ -14,16 +14,18 @@
             "optional": "true"
           }
         }
       }
     ]
   },
   {
     "namespace": "i18n",
+    "restrictions": ["content"],
+    "defaultRestrictions": ["content"],
     "description": "Use the <code>browser.i18n</code> infrastructure to implement internationalization across your whole app or extension.",
     "types": [
       {
         "id": "LanguageCode",
         "type": "string",
         "description": "An ISO language code such as <code>en</code> or <code>fr</code>. For a complete list of languages supported by this method, see <a href='http://src.chromium.org/viewvc/chrome/trunk/src/third_party/cld/languages/internal/languages.cc'>kLanguageInfoTable</a>. For an unknown language, <code>und</code> will be returned, which means that [percentage] of the text is unknown to CLD"
       }
     ],