From afb6fcf901b48662534d975f60e30643630453dc Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 27 Jul 2017 02:20:37 +0200 Subject: [PATCH] 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 | 4 ---- toolkit/components/urlformatter/moz.build | 9 +-------- toolkit/components/urlformatter/nsURLFormatter.js | 14 ++++++-------- toolkit/modules/AppConstants.jsm | 5 +++++ toolkit/modules/moz.build | 4 ++++ 5 files changed, 16 insertions(+), 20 deletions(-) delete mode 100644 toolkit/components/urlformatter/api_keys.in diff --git a/toolkit/components/urlformatter/api_keys.in b/toolkit/components/urlformatter/api_keys.in deleted file mode 100644 index 3fa48dd9a76f..000000000000 --- 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@ diff --git a/toolkit/components/urlformatter/moz.build b/toolkit/components/urlformatter/moz.build index 5292de657495..6a13571494cc 100644 --- a/toolkit/components/urlformatter/moz.build +++ b/toolkit/components/urlformatter/moz.build @@ -16,15 +16,8 @@ XPIDL_SOURCES += [ XPIDL_MODULE = 'urlformatter' EXTRA_COMPONENTS += [ + 'nsURLFormatter.js', 'nsURLFormatter.manifest', ] -EXTRA_PP_COMPONENTS += [ - 'nsURLFormatter.js', -] - -CONFIGURE_SUBST_FILES += [ - 'api_keys', -] - DEFINES['OBJDIR'] = OBJDIR diff --git a/toolkit/components/urlformatter/nsURLFormatter.js b/toolkit/components/urlformatter/nsURLFormatter.js index 41f66e0e07a7..1a9b82641e86 100644 --- a/toolkit/components/urlformatter/nsURLFormatter.js +++ b/toolkit/components/urlformatter/nsURLFormatter.js @@ -1,6 +1,3 @@ -#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/. */ @@ -22,6 +19,7 @@ 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"; @@ -112,10 +110,10 @@ nsURLFormatterService.prototype = { 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; } }, @@ -157,7 +155,7 @@ nsURLFormatterService.prototype = { 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; } diff --git a/toolkit/modules/AppConstants.jsm b/toolkit/modules/AppConstants.jsm index 73edbce40457..986633969d32 100644 --- a/toolkit/modules/AppConstants.jsm +++ b/toolkit/modules/AppConstants.jsm @@ -331,6 +331,11 @@ this.AppConstants = Object.freeze({ 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. diff --git a/toolkit/modules/moz.build b/toolkit/modules/moz.build index 6e05a2c2147a..4be44ad54820 100644 --- a/toolkit/modules/moz.build +++ b/toolkit/modules/moz.build @@ -297,7 +297,11 @@ 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',