Bug 1242966 - Make services/crypto eslintable. r?rnewman draft
authorHector Zhao <bzhao@mozilla.com>
Tue, 26 Jan 2016 23:01:32 +0800
changeset 325812 885a4cc8dd3bb137c06c41a36a6c430d198ef5fb
parent 325811 e06ed9c1c7318e0b9e8cd53aa174fa0aaee1462d
child 325813 3df6ead76a9fa212e855290acbdae16f060db4a9
push id10050
push userbzhao@mozilla.com
push dateTue, 26 Jan 2016 15:27:25 +0000
reviewersrnewman
bugs1242966
milestone47.0a1
Bug 1242966 - Make services/crypto eslintable. r?rnewman
services/crypto/modules/WeaveCrypto.js
services/crypto/moz.build
toolkit/modules/AppConstants.jsm
toolkit/modules/moz.build
--- a/services/crypto/modules/WeaveCrypto.js
+++ b/services/crypto/modules/WeaveCrypto.js
@@ -2,20 +2,22 @@
  * 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/. */
 
 this.EXPORTED_SYMBOLS = ["WeaveCrypto"];
 
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 var Cr = Components.results;
+var Cu = Components.utils;
 
-Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/ctypes.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/ctypes.jsm");
+Cu.import('resource://gre/modules/AppConstants.jsm');
 
 /**
  * Shortcuts for some algorithm SEC OIDs.  Full list available here:
  * http://lxr.mozilla.org/seamonkey/source/security/nss/lib/util/secoidt.h
  */
 const DES_EDE3_CBC = 156;
 const AES_128_CBC  = 184;
 const AES_192_CBC  = 186;
@@ -127,26 +129,26 @@ WeaveCrypto.prototype = {
         // implicitly initialize NSS.
         Cc["@mozilla.org/psm;1"].getService(Ci.nsISupports);
 
         // Open the NSS library.
         let path = ctypes.libraryName("nss3");
 
         // XXX really want to be able to pass specific dlopen flags here.
         var nsslib;
-#ifdef MOZ_NATIVE_NSS
-        // Search platform-dependent library paths for system NSS.
-        this.log("Trying NSS library without path");
-        nsslib = ctypes.open(path);
-#else
-        let file = Services.dirsvc.get("GreBinD", Ci.nsILocalFile);
-        file.append(path);
-        this.log("Trying NSS library with path " + file.path);
-        nsslib = ctypes.open(file.path);
-#endif
+        if (AppConstants.MOZ_NATIVE_NSS) {
+            // Search platform-dependent library paths for system NSS.
+            this.log("Trying NSS library without path");
+            nsslib = ctypes.open(path);
+        } else {
+            let file = Services.dirsvc.get("GreBinD", Ci.nsILocalFile);
+            file.append(path);
+            this.log("Trying NSS library with path " + file.path);
+            nsslib = ctypes.open(file.path);
+        }
 
         this.log("Initializing NSS types and function declarations...");
 
         this.nss = {};
         this.nss_t = {};
 
         // nsprpub/pr/include/prtypes.h#435
         // typedef PRIntn PRBool; --> int
--- a/services/crypto/moz.build
+++ b/services/crypto/moz.build
@@ -8,20 +8,14 @@ with Files('**'):
     BUG_COMPONENT = ('Mozilla Services', 'Firefox Sync: Crypto')
 
 DIRS += ['component']
 
 XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
 
 EXTRA_JS_MODULES['services-crypto'] += [
     'modules/utils.js',
-]
-
-EXTRA_PP_JS_MODULES['services-crypto'] += [
     'modules/WeaveCrypto.js',
 ]
 
 EXTRA_COMPONENTS += [
     'cryptoComponents.manifest',
 ]
-
-if CONFIG['MOZ_NATIVE_NSS']:
-    DEFINES['MOZ_NATIVE_NSS'] = 1
--- a/toolkit/modules/AppConstants.jsm
+++ b/toolkit/modules/AppConstants.jsm
@@ -235,16 +235,23 @@ this.AppConstants = Object.freeze({
 
   MOZ_GRAPHENE:
 #ifdef MOZ_GRAPHENE
   true,
 #else
   false,
 #endif
 
+  MOZ_NATIVE_NSS:
+#ifdef MOZ_NATIVE_NSS
+  true,
+#else
+  false,
+#endif
+
   MOZ_PLACES:
 #ifdef MOZ_PLACES
   true,
 #else
   false,
 #endif
 
   MOZ_REQUIRE_SIGNING:
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -113,11 +113,12 @@ for var in ('ANDROID_PACKAGE_NAME',
             'DLL_PREFIX',
             'DLL_SUFFIX',
             'DEBUG_JS_MODULES',
             'SOURCE_REV_URL'):
             DEFINES[var] = CONFIG[var]
 
 for var in ('MOZ_TOOLKIT_SEARCH',
             'MOZ_REQUIRE_SIGNING',
+            'MOZ_NATIVE_NSS',
             'MOZ_UPDATER'):
     if CONFIG[var]:
         DEFINES[var] = True