Bug 1242966 - Make services/crypto eslintable. r=rnewman
authorHector Zhao <bzhao@mozilla.com>
Tue, 26 Jan 2016 23:01:32 +0800
changeset 327107 adf78202a5bb40a743cbf0ccf4da12083f2ed598
parent 327106 ad188676eb21005a369b270dd989b12747265d8d
child 327108 c09055940ce92b4af917ff156fca0b67cfc36fa6
push id10194
push userdmitchell@mozilla.com
push dateFri, 29 Jan 2016 17:28:53 +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
@@ -1,21 +1,20 @@
 /* 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/. */
 
 this.EXPORTED_SYMBOLS = ["WeaveCrypto"];
 
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cr = Components.results;
+var {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
 
-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 +126,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