Bug 1529001 - fxmonitor: properly package l10n in the build system. r=johannh
authorNihanth Subramanya <nhnt11@gmail.com>
Wed, 27 Feb 2019 14:19:57 +0000
changeset 519418 dce3ee76ccd90b2a86866d8b71eff3f95da117f4
parent 519417 8f33527974b47fd89c50cc691fa93b91a48d6619
child 519419 66a4a5cb3fc7603baa4fe83c98b3b83b5b33075c
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1529001
milestone67.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 1529001 - fxmonitor: properly package l10n in the build system. r=johannh Differential Revision: https://phabricator.services.mozilla.com/D20366
browser/base/content/test/static/browser_all_files_referenced.js
browser/extensions/fxmonitor/locale/en-US/strings.properties
browser/extensions/fxmonitor/locales/en-US/fxmonitor.properties
browser/extensions/fxmonitor/locales/jar.mn
browser/extensions/fxmonitor/locales/moz.build
browser/extensions/fxmonitor/moz.build
browser/extensions/fxmonitor/privileged/FirefoxMonitor.jsm
browser/locales/Makefile.in
browser/locales/filter.py
browser/locales/l10n.ini
browser/locales/l10n.toml
--- a/browser/base/content/test/static/browser_all_files_referenced.js
+++ b/browser/base/content/test/static/browser_all_files_referenced.js
@@ -275,18 +275,21 @@ function parseManifest(manifestUri) {
   return fetchFile(manifestUri.spec).then(data => {
     for (let line of data.split("\n")) {
       let [type, ...argv] = line.split(/\s+/);
       if (type == "content" || type == "skin" || type == "locale") {
         let chromeUri = `chrome://${argv[0]}/${type}/`;
         // The webcompat reporter's locale directory may not exist if
         // the addon is preffed-off, and since it's a hack until we
         // get bz1425104 landed, we'll just skip it for now.
+        // Same issue with fxmonitor, which is also pref'd off.
         if (chromeUri === "chrome://webcompat-reporter/locale/") {
           gChromeMap.set("chrome://webcompat-reporter/locale/", true);
+        } else if (chromeUri === "chrome://fxmonitor/locale/") {
+          gChromeMap.set("chrome://fxmonitor/locale/", true);
         } else {
           trackChromeUri(chromeUri);
         }
       } else if (type == "override" || type == "overlay") {
         // Overlays aren't really overrides, but behave the same in
         // that the overlay is only referenced if the original xul
         // file is referenced somewhere.
         let os = "os=" + Services.appinfo.OS;
rename from browser/extensions/fxmonitor/locale/en-US/strings.properties
rename to browser/extensions/fxmonitor/locales/en-US/fxmonitor.properties
new file mode 100644
--- /dev/null
+++ b/browser/extensions/fxmonitor/locales/jar.mn
@@ -0,0 +1,8 @@
+#filter substitution
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+[features/fxmonitor@mozilla.org] @AB_CD@.jar:
+% locale fxmonitor @AB_CD@ %locale/@AB_CD@/
+  locale/@AB_CD@/fxmonitor.properties (%fxmonitor.properties)
new file mode 100644
--- /dev/null
+++ b/browser/extensions/fxmonitor/locales/moz.build
@@ -0,0 +1,7 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+JAR_MANIFESTS += ['jar.mn']
--- a/browser/extensions/fxmonitor/moz.build
+++ b/browser/extensions/fxmonitor/moz.build
@@ -2,16 +2,18 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
 DEFINES['MOZ_APP_MAXVERSION'] = CONFIG['MOZ_APP_MAXVERSION']
 
+DIRS += ['locales']
+
 FINAL_TARGET_FILES.features['fxmonitor@mozilla.org'] += [
   'background.js',
   'manifest.json'
 ]
 
 FINAL_TARGET_FILES.features['fxmonitor@mozilla.org']['assets'] += [
   'assets/alert.svg',
   'assets/monitor32.svg'
@@ -25,14 +27,10 @@ FINAL_TARGET_FILES.features['fxmonitor@m
 ]
 
 FINAL_TARGET_FILES.features['fxmonitor@mozilla.org']['privileged']['subscripts'] += [
   'privileged/subscripts/EveryWindow.jsm',
   'privileged/subscripts/Globals.jsm',
   'privileged/subscripts/PanelUI.jsm'
 ]
 
-FINAL_TARGET_FILES.features['fxmonitor@mozilla.org']['locale']['en-US'] += [
-  'locale/en-US/strings.properties'
-]
-
 with Files('**'):
   BUG_COMPONENT = ('Firefox', 'Firefox Monitor')
--- a/browser/extensions/fxmonitor/privileged/FirefoxMonitor.jsm
+++ b/browser/extensions/fxmonitor/privileged/FirefoxMonitor.jsm
@@ -17,17 +17,18 @@ this.FirefoxMonitor = {
 
   // Reference to the extension object from the WebExtension context.
   // Used for getting URIs for resources packaged in the extension.
   extension: null,
 
   // Whether we've started observing for the user visiting a breached site.
   observerAdded: false,
 
-  // loadStrings loads a stringbundle into this property.
+  // This is here for documentation, will be redefined to a lazy getter
+  // that creates and returns a string bundle in loadStrings().
   strings: null,
 
   // This is here for documentation, will be redefined to a pref getter
   // using XPCOMUtils.defineLazyPreferenceGetter in init().
   enabled: null,
 
   kEnabledPref: "extensions.fxmonitor.enabled",
 
@@ -78,17 +79,16 @@ this.FirefoxMonitor = {
       }
     );
 
     if (this.enabled) {
       this.startObserving();
     }
   },
 
-
   // Used to enforce idempotency of delayedInit. delayedInit is
   // called in startObserving() to ensure we load our strings, etc.
   _delayedInited: false,
   async delayedInit() {
     if (this._delayedInited) {
       return;
     }
 
@@ -140,37 +140,37 @@ this.FirefoxMonitor = {
       this.kFirstAlertShownPref, false);
 
     await this.loadStrings();
     await this.loadBreaches();
 
     this._delayedInited = true;
   },
 
-  async loadStrings() {
-    // Services.strings.createBundle has a whitelist of URL schemes that it
-    // accepts. moz-extension: is not one of them, so we work around that
-    // by reading the file manually and creating a data: URL (allowed).
-    let response;
-    let locale = Services.locale.defaultLocale;
-    try {
-      response = await fetch(this.getURL(`locale/${locale}/strings.properties`));
-    } catch (e) {
-      Cu.reportError(`Firefox Monitor: no strings available for ${locale}. Falling back to en-US.`);
-      response = await fetch(this.getURL(`locale/en-US/strings.properties`));
+  loadStrings() {
+    let l10nManifest;
+    if (this.extension.rootURI instanceof Ci.nsIJARURI) {
+      l10nManifest = this.extension.rootURI.JARFile
+                            .QueryInterface(Ci.nsIFileURL).file;
+    } else if (this.extension.rootURI instanceof Ci.nsIFileURL) {
+      l10nManifest = this.extension.rootURI.file;
     }
-    let buffer = await response.arrayBuffer();
-    let binary = "";
-    let bytes = new Uint8Array(buffer);
-    let len = bytes.byteLength;
-    for (let i = 0; i < len; i++) {
-      binary += String.fromCharCode(bytes[i]);
+
+    if (l10nManifest) {
+      Components.manager.addBootstrappedManifestLocation(l10nManifest);
+
+      XPCOMUtils.defineLazyGetter(this, "strings", () => {
+        return Services.strings.createBundle(
+          "chrome://fxmonitor/locale/fxmonitor.properties");
+      });
+    } else {
+      // Something is very strange if we reach this line, so we throw
+      // in order to prevent init from completing and burst the stack.
+      throw "Cannot find fxmonitor chrome.manifest for registering translated strings";
     }
-    let b64 = btoa(binary);
-    this.strings = Services.strings.createBundle(`data:text/plain;base64,${b64}`);
   },
 
   kRemoteSettingsKey: "fxmonitor-breaches",
   async loadBreaches() {
     let populateSites = (data) => {
       this.domainMap.clear();
       data.forEach(site => {
         if (!site.Domain || !site.Name || !site.PwnCount || !site.BreachDate || !site.AddedDate) {
--- a/browser/locales/Makefile.in
+++ b/browser/locales/Makefile.in
@@ -56,16 +56,17 @@ libs-%:
 	$(if $(filter en-US,$(AB_CD)),, @$(MAKE) merge-$*)
 	$(NSINSTALL) -D $(DIST)/install
 	@$(MAKE) -C ../../toolkit/locales libs-$* XPI_ROOT_APPID='$(XPI_ROOT_APPID)'
 	@$(MAKE) -C ../../services/sync/locales AB_CD=$* XPI_NAME=locale-$*
 	@$(MAKE) -C ../../extensions/spellcheck/locales AB_CD=$* XPI_NAME=locale-$*
 ifneq (,$(wildcard ../extensions/formautofill/locales))
 	@$(MAKE) -C ../extensions/formautofill/locales AB_CD=$* XPI_NAME=locale-$*
 endif
+	@$(MAKE) -C ../extensions/fxmonitor/locales AB_CD=$* XPI_NAME=locale-$*
 	@$(MAKE) -C ../extensions/webcompat-reporter/locales AB_CD=$* XPI_NAME=locale-$*
 	@$(MAKE) -C ../../devtools/client/locales AB_CD=$* XPI_NAME=locale-$* XPI_ROOT_APPID='$(XPI_ROOT_APPID)'
 	@$(MAKE) -C ../../devtools/startup/locales AB_CD=$* XPI_NAME=locale-$* XPI_ROOT_APPID='$(XPI_ROOT_APPID)'
 	@$(MAKE) libs AB_CD=$* XPI_NAME=locale-$* PREF_DIR=$(PREF_DIR)
 	@$(MAKE) multilocale.txt-$* AB_CD=$* XPI_NAME=locale-$*
 	@$(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY)/locales AB_CD=$* XPI_NAME=locale-$*
 
 chrome-%: AB_CD=$*
@@ -73,16 +74,17 @@ chrome-%: IS_LANGUAGE_REPACK=1
 chrome-%:
 	$(if $(filter en-US,$(AB_CD)),, @$(MAKE) merge-$*)
 	@$(MAKE) -C ../../toolkit/locales chrome-$*
 	@$(MAKE) -C ../../services/sync/locales chrome AB_CD=$*
 	@$(MAKE) -C ../../extensions/spellcheck/locales chrome AB_CD=$*
 ifneq (,$(wildcard ../extensions/formautofill/locales))
 	@$(MAKE) -C ../extensions/formautofill/locales chrome AB_CD=$*
 endif
+	@$(MAKE) -C ../extensions/fxmonitor/locales chrome AB_CD=$*
 	@$(MAKE) -C ../../devtools/client/locales chrome AB_CD=$*
 	@$(MAKE) -C ../../devtools/startup/locales chrome AB_CD=$*
 	@$(MAKE) chrome AB_CD=$*
 	@$(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY)/locales chrome AB_CD=$*
 	@$(MAKE) -C ../extensions/webcompat-reporter/locales chrome AB_CD=$*
 
 package-win32-installer: $(SUBMAKEFILES)
 	$(MAKE) -C ../installer/windows CONFIG_DIR=l10ngen ZIP_IN='$(ZIP_OUT)' installer
--- a/browser/locales/filter.py
+++ b/browser/locales/filter.py
@@ -5,16 +5,17 @@
 
 def test(mod, path, entity=None):
     import re
     # ignore anything but Firefox
     if mod not in ("netwerk", "dom", "toolkit", "security/manager",
                    "devtools/client", "devtools/shared", "devtools/startup",
                    "browser",
                    "browser/extensions/formautofill",
+                   "browser/extensions/fxmonitor",
                    "browser/extensions/webcompat-reporter",
                    "extensions/spellcheck",
                    "other-licenses/branding/firefox",
                    "browser/branding/official",
                    "services/sync"):
         return "ignore"
     if mod not in ("browser", "extensions/spellcheck"):
         # we only have exceptions for browser and extensions/spellcheck
--- a/browser/locales/l10n.ini
+++ b/browser/locales/l10n.ini
@@ -8,16 +8,17 @@ all = browser/locales/all-locales
 
 [compare]
 dirs = browser
      other-licenses/branding/firefox
      browser/branding/official
      devtools/client
      devtools/startup
      browser/extensions/formautofill
+     browser/extensions/fxmonitor
      browser/extensions/webcompat-reporter
 
 [includes]
 # non-central apps might want to use %(topsrcdir)s here, or other vars
 # RFE: that needs to be supported by compare-locales, too, though
 toolkit = toolkit/locales/l10n.ini
 services_sync = services/sync/locales/l10n.ini
 
--- a/browser/locales/l10n.toml
+++ b/browser/locales/l10n.toml
@@ -124,16 +124,20 @@ locales = [
     reference = "browser/branding/official/locales/en-US/**"
     l10n = "{l}browser/branding/official/**"
 
 [[paths]]
     reference = "browser/extensions/formautofill/locales/en-US/**"
     l10n = "{l}browser/extensions/formautofill/**"
 
 [[paths]]
+    reference = "browser/extensions/fxmonitor/locales/en-US/**"
+    l10n = "{l}browser/extensions/fxmonitor/**"
+
+[[paths]]
     reference = "browser/extensions/webcompat-reporter/locales/en-US/**"
     l10n = "{l}browser/extensions/webcompat-reporter/**"
 
 [[paths]]
     reference = "services/sync/locales/en-US/**"
     l10n = "{l}services/sync/**"