Index: configure
===================================================================
RCS file: /cvsroot/mozilla/configure,v
retrieving revision 1.1492.2.129
diff -u -p -6 -r1.1492.2.129 configure
--- configure	26 Mar 2008 19:13:06 -0000	1.1492.2.129
+++ configure	4 Jan 2009 12:56:07 -0000
@@ -19335,12 +19335,115 @@ echo "configure:19305: checking CAIRO_LI
 fi
 
 
 
 
 
+
+
+  succeeded=no
+
+  if test -z "$PKG_CONFIG"; then
+    # Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:19352: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_path_PKG_CONFIG'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  case "$PKG_CONFIG" in
+  /*)
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  ?:/*)			 
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a dos path.
+  ;;
+  *)
+  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
+  ac_dummy="$PATH"
+  for ac_dir in $ac_dummy; do 
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$ac_word; then
+      ac_cv_path_PKG_CONFIG="$ac_dir/$ac_word"
+      break
+    fi
+  done
+  IFS="$ac_save_ifs"
+  test -z "$ac_cv_path_PKG_CONFIG" && ac_cv_path_PKG_CONFIG="no"
+  ;;
+esac
+fi
+PKG_CONFIG="$ac_cv_path_PKG_CONFIG"
+if test -n "$PKG_CONFIG"; then
+  echo "$ac_t""$PKG_CONFIG" 1>&6
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+  fi
+
+  if test "$PKG_CONFIG" = "no" ; then
+     echo "*** The pkg-config script could not be found. Make sure it is"
+     echo "*** in your path, or set the PKG_CONFIG environment variable"
+     echo "*** to the full path to pkg-config."
+     echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config."
+  else
+     PKG_CONFIG_MIN_VERSION=0.9.0
+     if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
+        echo $ac_n "checking for nss-shared-helper""... $ac_c" 1>&6
+echo "configure:19396: checking for nss-shared-helper" >&5
+
+        if $PKG_CONFIG --exists "nss-shared-helper" ; then
+            echo "$ac_t""yes" 1>&6
+            succeeded=yes
+
+            echo $ac_n "checking NSSHELPER_CFLAGS""... $ac_c" 1>&6
+echo "configure:19403: checking NSSHELPER_CFLAGS" >&5
+            NSSHELPER_CFLAGS=`$PKG_CONFIG --cflags "nss-shared-helper"`
+            echo "$ac_t""$NSSHELPER_CFLAGS" 1>&6
+
+            echo $ac_n "checking NSSHELPER_LIBS""... $ac_c" 1>&6
+echo "configure:19408: checking NSSHELPER_LIBS" >&5
+            ## don't use --libs since that can do evil things like add
+            ## -Wl,--export-dynamic
+            NSSHELPER_LIBS="`$PKG_CONFIG --libs-only-L \"nss-shared-helper\"` `$PKG_CONFIG --libs-only-l \"nss-shared-helper\"`"
+            echo "$ac_t""$NSSHELPER_LIBS" 1>&6
+        else
+            NSSHELPER_CFLAGS=""
+            NSSHELPER_LIBS=""
+            ## If we have a custom action on failure, don't print errors, but 
+            ## do set a variable so people can do so.
+            NSSHELPER_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "nss-shared-helper"`
+            
+        fi
+
+        
+        
+     else
+        echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
+        echo "*** See http://www.freedesktop.org/software/pkgconfig"
+     fi
+  fi
+
+  if test $succeeded = yes; then
+     MOZ_ENABLE_NSSHELPER=1
+  else
+     MOZ_ENABLE_NSSHELPER=
+  fi
+
+
+if test "$MOZ_ENABLE_NSSHELPER"; then
+  cat >> confdefs.h <<\EOF
+#define MOZ_ENABLE_NSSHELPER 1
+EOF
+
+fi
+
+
+
+
 # Check whether --enable-xul or --disable-xul was given.
 if test "${enable_xul+set}" = set; then
   enableval="$enable_xul"
   if test "$enableval" = "no"; then
     MOZ_XUL= 
   elif test "$enableval" = "yes"; then
@@ -20581,12 +20684,15 @@ s%@ATSUI_FONT_FEATURE@%$ATSUI_FONT_FEATU
 s%@PNG_FUNCTIONS_FEATURE@%$PNG_FUNCTIONS_FEATURE%g
 s%@CAIRO_CFLAGS@%$CAIRO_CFLAGS%g
 s%@CAIRO_LIBS@%$CAIRO_LIBS%g
 s%@MOZ_TREE_CAIRO@%$MOZ_TREE_CAIRO%g
 s%@MOZ_CAIRO_CFLAGS@%$MOZ_CAIRO_CFLAGS%g
 s%@MOZ_CAIRO_LIBS@%$MOZ_CAIRO_LIBS%g
+s%@NSSHELPER_CFLAGS@%$NSSHELPER_CFLAGS%g
+s%@NSSHELPER_LIBS@%$NSSHELPER_LIBS%g
+s%@MOZ_ENABLE_NSSHELPER@%$MOZ_ENABLE_NSSHELPER%g
 s%@MOZ_XUL@%$MOZ_XUL%g
 s%@MOZ_PYTHON@%$MOZ_PYTHON%g
 s%@MOZ_PYTHON_PREFIX@%$MOZ_PYTHON_PREFIX%g
 s%@MOZ_PYTHON_INCLUDES@%$MOZ_PYTHON_INCLUDES%g
 s%@MOZ_PYTHON_LIBS@%$MOZ_PYTHON_LIBS%g
 s%@MOZ_PYTHON_VER@%$MOZ_PYTHON_VER%g
Index: configure.in
===================================================================
RCS file: /cvsroot/mozilla/configure.in,v
retrieving revision 1.1503.2.111
diff -u -p -6 -r1.1503.2.111 configure.in
--- configure.in	26 Mar 2008 19:03:05 -0000	1.1503.2.111
+++ configure.in	4 Jan 2009 12:56:10 -0000
@@ -6806,12 +6806,27 @@ fi
 
 AC_SUBST(MOZ_TREE_CAIRO)
 AC_SUBST(MOZ_CAIRO_CFLAGS)
 AC_SUBST(MOZ_CAIRO_LIBS)
 
 dnl ========================================================
+dnl Check for nss-shared-helper
+dnl ========================================================
+
+PKG_CHECK_MODULES(NSSHELPER, nss-shared-helper, 
+  [MOZ_ENABLE_NSSHELPER=1],
+  [MOZ_ENABLE_NSSHELPER=])
+
+if test "$MOZ_ENABLE_NSSHELPER"; then
+  AC_DEFINE(MOZ_ENABLE_NSSHELPER)
+fi
+AC_SUBST(MOZ_ENABLE_NSSHELPER)
+AC_SUBST(NSSHELPER_CFLAGS)
+AC_SUBST(NSSHELPER_LIBS)
+
+dnl ========================================================
 dnl disable xul
 dnl ========================================================
 MOZ_ARG_DISABLE_BOOL(xul,
 [  --disable-xul           Disable XUL],
     MOZ_XUL= )
 if test "$MOZ_XUL"; then
Index: calendar/sunbird/app/Makefile.in
===================================================================
RCS file: /cvsroot/mozilla/calendar/sunbird/app/Makefile.in,v
retrieving revision 1.21.2.23
diff -u -p -6 -r1.21.2.23 Makefile.in
--- calendar/sunbird/app/Makefile.in	4 May 2008 01:32:07 -0000	1.21.2.23
+++ calendar/sunbird/app/Makefile.in	4 Jan 2009 12:56:11 -0000
@@ -139,12 +139,16 @@ endif
 endif
 
 ifdef MOZ_JPROF
 LIBS += -ljprof
 endif
 
+ifdef MOZ_ENABLE_NSSHELPER
+LIBS += $(NSSHELPER_LIBS)
+endif
+
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
Index: config/autoconf.mk.in
===================================================================
RCS file: /cvsroot/mozilla/config/autoconf.mk.in,v
retrieving revision 3.363.2.20
diff -u -p -6 -r3.363.2.20 autoconf.mk.in
--- config/autoconf.mk.in	14 Sep 2006 18:07:03 -0000	3.363.2.20
+++ config/autoconf.mk.in	4 Jan 2009 12:56:11 -0000
@@ -492,12 +492,16 @@ GLIB_CFLAGS	= @GLIB_CFLAGS@
 GLIB_LIBS	= @GLIB_LIBS@
 GLIB_GMODULE_LIBS	= @GLIB_GMODULE_LIBS@
 LIBIDL_CFLAGS = @LIBIDL_CFLAGS@
 LIBIDL_LIBS = @LIBIDL_LIBS@
 STATIC_LIBIDL = @STATIC_LIBIDL@
 
+MOZ_ENABLE_NSSHELPER = @MOZ_ENABLE_NSSHELPER@
+NSSHELPER_CFLAGS = @NSSHELPER_CFLAGS@
+NSSHELPER_LIBS = @NSSHELPER_LIBS@
+
 MOZ_NATIVE_MAKEDEPEND	= @SYSTEM_MAKEDEPEND@
 
 # Used for LD_LIBRARY_PATH
 LIBS_PATH       = @LIBS_PATH@
 
 MOZ_AUTO_DEPS	= @MOZ_AUTO_DEPS@
Index: security/manager/ssl/src/Makefile.in
===================================================================
RCS file: /cvsroot/mozilla/security/manager/ssl/src/Makefile.in,v
retrieving revision 1.67.2.5
diff -u -p -6 -r1.67.2.5 Makefile.in
--- security/manager/ssl/src/Makefile.in	4 Jun 2008 20:42:03 -0000	1.67.2.5
+++ security/manager/ssl/src/Makefile.in	4 Jan 2009 12:56:25 -0000
@@ -128,17 +128,18 @@ REQUIRES	= nspr \
 EXTRA_DEPS = $(NSS_DEP_LIBS)
 
 DEFINES += -DNSS_ENABLE_ECC
 
 # Use local includes because they are inserted before INCLUDES
 # so that Mozilla's nss.h is used, not glibc's
-LOCAL_INCLUDES += $(NSS_CFLAGS)
+LOCAL_INCLUDES += $(NSS_CFLAGS) $(NSSHELPER_CFLAGS)
 
 EXTRA_DSO_LDOPTS += \
 		$(MOZ_UNICHARUTIL_LIBS) \
 		$(MOZ_COMPONENT_LIBS) \
 		$(MOZ_JS_LIBS) \
+		$(NSSHELPER_LIBS) \
 		$(NSS_LIBS) \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
Index: security/manager/ssl/src/nsNSSComponent.cpp
===================================================================
RCS file: /cvsroot/mozilla/security/manager/ssl/src/nsNSSComponent.cpp,v
retrieving revision 1.126.2.9
diff -u -p -6 -r1.126.2.9 nsNSSComponent.cpp
--- security/manager/ssl/src/nsNSSComponent.cpp	30 Jun 2008 22:54:11 -0000	1.126.2.9
+++ security/manager/ssl/src/nsNSSComponent.cpp	4 Jan 2009 12:56:26 -0000
@@ -41,12 +41,19 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#ifdef MOZ_ENABLE_NSSHELPER
+#pragma GCC visibility push(default)
+#include <nss-shared-helper.h>
+#pragma GCC visibility pop
+#include "prenv.h"
+#endif
+
 #include "nsNSSComponent.h"
 #include "nsNSSCallbacks.h"
 #include "nsNSSIOLayer.h"
 #include "nsSSLThread.h"
 #include "nsCertVerificationThread.h"
 #include "nsNSSEvent.h"
@@ -1422,13 +1429,27 @@ nsNSSComponent::InitializeNSS(PRBool sho
     // If we could assume i18n will not change between profiles, one call per application
     // run were sufficient. As I can't predict what happens in the future, let's repeat
     // this call for every re-init of NSS.
 
     ConfigureInternalPKCS11Token();
 
-    SECStatus init_rv = ::NSS_InitReadWrite(profileStr.get());
+    SECStatus init_rv = SECFailure;
+#ifdef MOZ_ENABLE_NSSHELPER
+    if (PR_GetEnv("MOZ_SB_NO_NSSHELPER")) {
+      init_rv = ::NSS_InitReadWrite(profileStr.get());
+    } else {
+      init_rv = ::nsshelp_open_db("MOZ_APP_DISPLAYNAME", profileStr.get(), 0);
+
+      if (init_rv != SECSuccess) {
+        PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("can not init NSS using nsshelp_open_db in %s\n", profileStr.get()));
+        init_rv = ::NSS_InitReadWrite(profileStr.get());
+      }
+    }
+#else
+    init_rv = ::NSS_InitReadWrite(profileStr.get());
+#endif
 
     if (init_rv != SECSuccess) {
       PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("can not init NSS r/w in %s\n", profileStr.get()));
 
       if (supress_warning_preference) {
         which_nss_problem = problem_none;
