Bug 1384509 - Move Bing, Google, Mozilla API key definitions to AppConstants.jsm and stop using preprocessor in nsURLFormatter.js. r=mossop
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Thu, 27 Jul 2017 02:20:37 +0200
changeset 422811 0a8da9b73bc8da062fdf28b632ee0bd71db773d9
parent 422810 e0d2ec43d7b204be47b195c566b55eb8723e5cc6
child 422812 9a61373374162e4698536f95c2245834a1c7b098
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1384509
milestone56.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 1384509 - Move Bing, Google, Mozilla API key definitions to AppConstants.jsm and stop using preprocessor in nsURLFormatter.js. r=mossop
toolkit/components/urlformatter/api_keys.in
toolkit/components/urlformatter/moz.build
toolkit/components/urlformatter/nsURLFormatter.js
toolkit/modules/AppConstants.jsm
toolkit/modules/moz.build
deleted file mode 100644
--- a/toolkit/components/urlformatter/api_keys.in
+++ /dev/null
@@ -1,4 +0,0 @@
-#define MOZ_MOZILLA_API_KEY @MOZ_MOZILLA_API_KEY@
-#define MOZ_GOOGLE_API_KEY @MOZ_GOOGLE_API_KEY@
-#define MOZ_BING_API_KEY @MOZ_BING_API_KEY@
-#define MOZ_BING_API_CLIENTID @MOZ_BING_API_CLIENTID@
--- a/toolkit/components/urlformatter/moz.build
+++ b/toolkit/components/urlformatter/moz.build
@@ -11,20 +11,13 @@ XPCSHELL_TESTS_MANIFESTS += ['tests/unit
 
 XPIDL_SOURCES += [
     'nsIURLFormatter.idl',
 ]
 
 XPIDL_MODULE = 'urlformatter'
 
 EXTRA_COMPONENTS += [
+    'nsURLFormatter.js',
     'nsURLFormatter.manifest',
 ]
 
-EXTRA_PP_COMPONENTS += [
-    'nsURLFormatter.js',
-]
-
-CONFIGURE_SUBST_FILES += [
-    'api_keys',
-]
-
 DEFINES['OBJDIR'] = OBJDIR
--- a/toolkit/components/urlformatter/nsURLFormatter.js
+++ b/toolkit/components/urlformatter/nsURLFormatter.js
@@ -1,11 +1,8 @@
-#filter substitution
-#include @OBJDIR@/api_keys
-
 /* 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/. */
 
  /**
  * @class nsURLFormatterService
  *
  * nsURLFormatterService exposes methods to substitute variables in URL formats.
@@ -17,16 +14,17 @@
  */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/AppConstants.jsm");
 
 const PREF_APP_DISTRIBUTION           = "distribution.id";
 const PREF_APP_DISTRIBUTION_VERSION   = "distribution.version";
 
 XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils",
                                   "resource://gre/modules/UpdateUtils.jsm");
 
 function nsURLFormatterService() {
@@ -107,20 +105,20 @@ nsURLFormatterService.prototype = {
     PLATFORMVERSION:  function() { return this.appInfo.platformVersion; },
     PLATFORMBUILDID:  function() { return this.appInfo.platformBuildID; },
     APP:              function() { return this.appInfo.name.toLowerCase().replace(/ /, ""); },
     OS:               function() { return this.appInfo.OS; },
     XPCOMABI:         function() { return this.ABI; },
     BUILD_TARGET:     function() { return this.appInfo.OS + "_" + this.ABI; },
     OS_VERSION:       function() { return this.OSVersion; },
     CHANNEL:          () => UpdateUtils.UpdateChannel,
-    MOZILLA_API_KEY:  () => "@MOZ_MOZILLA_API_KEY@",
-    GOOGLE_API_KEY:   () => "@MOZ_GOOGLE_API_KEY@",
-    BING_API_CLIENTID:() => "@MOZ_BING_API_CLIENTID@",
-    BING_API_KEY:     () => "@MOZ_BING_API_KEY@",
+    MOZILLA_API_KEY:  () => AppConstants.MOZ_MOZILLA_API_KEY,
+    GOOGLE_API_KEY:   () => AppConstants.MOZ_GOOGLE_API_KEY,
+    BING_API_CLIENTID:() => AppConstants.MOZ_BING_API_CLIENTID,
+    BING_API_KEY:     () => AppConstants.MOZ_BING_API_KEY,
     DISTRIBUTION:     function() { return this.distribution.id; },
     DISTRIBUTION_VERSION: function() { return this.distribution.version; }
   },
 
   formatURL: function uf_formatURL(aFormat) {
     var _this = this;
     var replacementCallback = function(aMatch, aKey) {
       if (aKey in _this._defaults) {
@@ -152,15 +150,15 @@ nsURLFormatterService.prototype = {
       } catch(ex) {}
     }
 
     return this.formatURL(format);
   },
 
   trimSensitiveURLs: function uf_trimSensitiveURLs(aMsg) {
     // Only the google API key is sensitive for now.
-    return "@MOZ_GOOGLE_API_KEY@" ? aMsg.replace(/@MOZ_GOOGLE_API_KEY@/g,
+    return AppConstants.MOZ_GOOGLE_API_KEY ? aMsg.replace(RegExp(AppConstants.MOZ_GOOGLE_API_KEY, 'g'),
                                                  "[trimmed-google-api-key]")
                                   : aMsg;
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsURLFormatterService]);
--- a/toolkit/modules/AppConstants.jsm
+++ b/toolkit/modules/AppConstants.jsm
@@ -326,16 +326,21 @@ this.AppConstants = Object.freeze({
   INSTALL_LOCALE: "@AB_CD@",
   MOZ_WIDGET_TOOLKIT: "@MOZ_WIDGET_TOOLKIT@",
   ANDROID_PACKAGE_NAME: "@ANDROID_PACKAGE_NAME@",
   MOZ_B2G_VERSION: @MOZ_B2G_VERSION@,
   MOZ_B2G_OS_NAME: @MOZ_B2G_OS_NAME@,
 
   DEBUG_JS_MODULES: "@DEBUG_JS_MODULES@",
 
+  MOZ_BING_API_CLIENTID: "@MOZ_BING_API_CLIENTID@",
+  MOZ_BING_API_KEY: "@MOZ_BING_API_KEY@",
+  MOZ_GOOGLE_API_KEY: "@MOZ_GOOGLE_API_KEY@",
+  MOZ_MOZILLA_API_KEY: "@MOZ_MOZILLA_API_KEY@",
+
   // URL to the hg revision this was built from (e.g.
   // "https://hg.mozilla.org/mozilla-central/rev/6256ec9113c1")
   // On unofficial builds, this is an empty string.
 #ifndef MOZ_SOURCE_URL
 #define MOZ_SOURCE_URL
 #endif
   SOURCE_REVISION_URL: "@MOZ_SOURCE_URL@",
 
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -292,17 +292,21 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'wind
     EXTRA_JS_MODULES += [
         'WindowsRegistry.jsm',
     ]
 
 for var in ('ANDROID_PACKAGE_NAME',
             'MOZ_APP_NAME',
             'MOZ_APP_VERSION',
             'MOZ_APP_VERSION_DISPLAY',
+            'MOZ_BING_API_CLIENTID',
+            'MOZ_BING_API_KEY',
+            'MOZ_GOOGLE_API_KEY',
             'MOZ_MACBUNDLE_NAME',
+            'MOZ_MOZILLA_API_KEY',
             'MOZ_WIDGET_TOOLKIT',
             'DLL_PREFIX',
             'DLL_SUFFIX',
             'DEBUG_JS_MODULES'):
             DEFINES[var] = CONFIG[var]
 
 for var in ('MOZ_TOOLKIT_SEARCH',
             'MOZ_SYSTEM_NSS',