Bug 422772 - reduce narrow Windows API calls in embedding, original patch by Brad Lassey <blassey@mozilla.com>, r=bsmedberg
authorBrian Crowder <crowder@fiverocks.com>
Wed, 27 Aug 2008 14:44:54 -0700
changeset 18479 73d8df3129ac6a0ddd0d0b99aaa6704441f67a70
parent 18478 b9de55a635d57beecab07b06791670573bfb1b7f
child 18480 4dd270901e745533c34ba54108d6d3b2c3574b40
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs422772
milestone1.9.1a2pre
Bug 422772 - reduce narrow Windows API calls in embedding, original patch by Brad Lassey <blassey@mozilla.com>, r=bsmedberg
embedding/browser/activex/src/plugin/LegacyPlugin.cpp
embedding/browser/activex/src/plugin/XPCDocument.cpp
embedding/browser/activex/src/plugin/XPConnect.cpp
extensions/auth/nsAuthSSPI.cpp
--- a/embedding/browser/activex/src/plugin/LegacyPlugin.cpp
+++ b/embedding/browser/activex/src/plugin/LegacyPlugin.cpp
@@ -298,18 +298,17 @@ ShowError(MozAxPluginErrors errorCode, c
         }
         break;
     case MozAxErrorCouldNotCreateControl:
         {
             USES_CONVERSION;
             LPOLESTR szClsid;
             StringFromCLSID(clsid, &szClsid);
             _sntprintf(szBuffer, kBufSize - 1,
-                _T("Could not create the control %s. Check that it has been installed on your computer "
-                   "and that this page correctly references it."), OLE2T(szClsid));
+                _T("Could not create the control %s. Check that it has been installed on your computer and that this page correctly references it."), OLE2T(szClsid));
             CoTaskMemFree(szClsid);
             szMsg = szBuffer;
         }
         break;
     }
     szBuffer[kBufSize - 1] = TCHAR('\0');
     if (szMsg)
         MessageBox(NULL, szMsg, _T("ActiveX Error"), MB_OK | MB_ICONWARNING);
--- a/embedding/browser/activex/src/plugin/XPCDocument.cpp
+++ b/embedding/browser/activex/src/plugin/XPCDocument.cpp
@@ -1910,17 +1910,17 @@ END_COM_MAP()
         if (doc)
         {
             nsIURI *baseURI = doc->GetBaseURI();
             nsCAutoString spec;
             if (baseURI &&
                 NS_SUCCEEDED(baseURI->GetSpec(spec)))
             {
                 USES_CONVERSION;
-                if (FAILED(CreateURLMoniker(NULL, T2CW(spec.get()), &baseURLMoniker)))
+                if (FAILED(CreateURLMoniker(NULL, A2CW(spec.get()), &baseURLMoniker)))
                     return E_UNEXPECTED;
             }
         }
 
         // Make the moniker
         HRESULT hr = CreateURLMoniker(baseURLMoniker, szName, ppmk);
         if (SUCCEEDED(hr) && !*ppmk)
             hr = E_FAIL;
--- a/embedding/browser/activex/src/plugin/XPConnect.cpp
+++ b/embedding/browser/activex/src/plugin/XPConnect.cpp
@@ -367,17 +367,17 @@ nsScriptablePeer::ConvertVariants(VARIAN
 
     // NOTE: THIS IS AN UGLY BACKWARDS COMPATIBILITY HACK TO WORKAROUND
     // XPCOM GLUE'S INABILITY TO FIND A CERTAIN ENTRY POINT IN MOZ1.0.x/NS7.0!
     // DO NOT TAUNT THE HACK
     if (NS_FAILED(rv))
     {
         // do_CreateInstance macro is broken so load the component manager by
         // hand and get it to create the component.
-        HMODULE hlib = ::LoadLibrary("xpcom.dll");
+        HMODULE hlib = ::LoadLibraryW(L"xpcom.dll");
         if (hlib)
         {
             nsIComponentManager *pManager = nsnull; // A frozen interface, even in 1.0.x
             typedef nsresult (PR_CALLBACK *Moz1XGetComponentManagerFunc)(nsIComponentManager* *result);
             Moz1XGetComponentManagerFunc compMgr = (Moz1XGetComponentManagerFunc)
                 ::GetProcAddress(hlib, "NS_GetComponentManager");
             if (compMgr)
             {
--- a/extensions/auth/nsAuthSSPI.cpp
+++ b/extensions/auth/nsAuthSSPI.cpp
@@ -47,16 +47,18 @@
 
 #include "nsAuthSSPI.h"
 #include "nsIServiceManager.h"
 #include "nsIDNSService.h"
 #include "nsIDNSRecord.h"
 #include "nsNetCID.h"
 #include "nsCOMPtr.h"
 
+#include <windows.h>
+
 #define SEC_SUCCESS(Status) ((Status) >= 0)
 
 #ifndef KERB_WRAP_NO_ENCRYPT
 #define KERB_WRAP_NO_ENCRYPT 0x80000001
 #endif
 
 #ifndef SECBUFFER_PADDING
 #define SECBUFFER_PADDING 9
@@ -98,44 +100,44 @@ static const char *MapErrorCode(int rc)
 }
 #else
 #define MapErrorCode(_rc) ""
 #endif
 
 //-----------------------------------------------------------------------------
 
 static HINSTANCE                 sspi_lib; 
-static PSecurityFunctionTable    sspi;
+static PSecurityFunctionTableW   sspi;
 
 static nsresult
 InitSSPI()
 {
-    PSecurityFunctionTable (*initFun)(void);
+    PSecurityFunctionTableW (*initFun)(void);
 
     LOG(("  InitSSPI\n"));
 
-    sspi_lib = LoadLibrary("secur32.dll");
+    sspi_lib = LoadLibraryW(L"secur32.dll");
     if (!sspi_lib) {
-        sspi_lib = LoadLibrary("security.dll");
+        sspi_lib = LoadLibraryW(L"security.dll");
         if (!sspi_lib) {
             LOG(("SSPI library not found"));
             return NS_ERROR_UNEXPECTED;
         }
     }
 
-    initFun = (PSecurityFunctionTable (*)(void))
-            GetProcAddress(sspi_lib, "InitSecurityInterfaceA");
+    initFun = (PSecurityFunctionTableW (*)(void))
+            GetProcAddress(sspi_lib, "InitSecurityInterfaceW");
     if (!initFun) {
-        LOG(("InitSecurityInterfaceA not found"));
+        LOG(("InitSecurityInterfaceW not found"));
         return NS_ERROR_UNEXPECTED;
     }
 
     sspi = initFun();
     if (!sspi) {
-        LOG(("InitSecurityInterfaceA failed"));
+        LOG(("InitSecurityInterfaceW failed"));
         return NS_ERROR_UNEXPECTED;
     }
 
     return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 
@@ -237,43 +239,41 @@ nsAuthSSPI::Init(const char *serviceName
     nsresult rv;
 
     // XXX lazy initialization like this assumes that we are single threaded
     if (!sspi) {
         rv = InitSSPI();
         if (NS_FAILED(rv))
             return rv;
     }
-
-    SEC_CHAR *package;
+    SEC_WCHAR *package;
 
-    package = (SEC_CHAR *) pTypeName[(int)mPackage];
-
+    package = (SEC_WCHAR *) pTypeName[(int)mPackage];
     if (mPackage != PACKAGE_TYPE_NTLM)
     {
         rv = MakeSN(serviceName, mServiceName);
         if (NS_FAILED(rv))
             return rv;
         mServiceFlags = serviceFlags;
     }
 
     SECURITY_STATUS rc;
 
-    PSecPkgInfo pinfo;
-    rc = (sspi->QuerySecurityPackageInfo)(package, &pinfo);
+    PSecPkgInfoW pinfo;
+    rc = (sspi->QuerySecurityPackageInfoW)(package, &pinfo);
     if (rc != SEC_E_OK) {
         LOG(("%s package not found\n", package));
         return NS_ERROR_UNEXPECTED;
     }
     mMaxTokenLen = pinfo->cbMaxToken;
     (sspi->FreeContextBuffer)(pinfo);
 
     TimeStamp useBefore;
 
-    rc = (sspi->AcquireCredentialsHandle)(NULL,
+    rc = (sspi->AcquireCredentialsHandleW)(NULL,
                                           package,
                                           SECPKG_CRED_OUTBOUND,
                                           NULL,
                                           NULL,
                                           NULL,
                                           NULL,
                                           &mCred,
                                           &useBefore);
@@ -331,25 +331,23 @@ nsAuthSSPI::GetNextToken(const void *inT
     obd.cBuffers = 1;
     obd.pBuffers = &ob;
     ob.BufferType = SECBUFFER_TOKEN;
     ob.cbBuffer = mMaxTokenLen;
     ob.pvBuffer = nsMemory::Alloc(ob.cbBuffer);
     if (!ob.pvBuffer)
         return NS_ERROR_OUT_OF_MEMORY;
     memset(ob.pvBuffer, 0, ob.cbBuffer);
-
-    SEC_CHAR *sn;
-
+    SEC_WCHAR *sn;
     if (mPackage == PACKAGE_TYPE_NTLM)
         sn = NULL;
     else
-        sn = (SEC_CHAR *) mServiceName.get();
+        sn = (SEC_WCHAR *) mServiceName.get();
 
-    rc = (sspi->InitializeSecurityContext)(&mCred,
+    rc = (sspi->InitializeSecurityContextW)(&mCred,
                                            ctxIn,
                                            sn,
                                            ctxReq,
                                            0,
                                            SECURITY_NATIVE_DREP,
                                            inToken ? &ibd : NULL,
                                            0,
                                            &mCtxt,
@@ -456,17 +454,17 @@ nsAuthSSPI::Wrap(const void *inToken,
                  PRUint32   *outTokenLen)
 {
     SECURITY_STATUS rc;
 
     SecBufferDesc ibd;
     secBuffers bufs;
     SecPkgContext_Sizes sizes;
 
-    rc = (sspi->QueryContextAttributes)(
+    rc = (sspi->QueryContextAttributesW)(
          &mCtxt,
          SECPKG_ATTR_SIZES,
          &sizes);
 
     if (!SEC_SUCCESS(rc))  
         return NS_ERROR_FAILURE;
     
     ibd.cBuffers = 3;