Bug 418703 - [relanding] reduce narrow windows API calls (necko patch), original patch by Brad Lassey <blassey@mozilla.com>, r=biesi

This commit is contained in:
Brian Crowder 2008-08-14 14:30:58 -07:00
Родитель 7f7df267a9
Коммит 1869a13cd5
7 изменённых файлов: 84 добавлений и 83 удалений

Просмотреть файл

@ -43,6 +43,7 @@
#include <windows.h>
#include <winsvc.h>
#include "nsString.h"
#include "nsAutodialWin.h"
#include "prlog.h"
@ -100,7 +101,7 @@ nsRASAutodial::nsRASAutodial()
mNumRASConnectionEntries(0),
mAutodialServiceDialingLocation(-1)
{
mOSVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
mOSVerInfo.dwOSVersionInfoSize = sizeof(mOSVerInfo);
GetVersionEx(&mOSVerInfo);
// Initializations that can be made again since RAS OS settings can
@ -139,8 +140,8 @@ nsresult nsRASAutodial::Init()
mNumRASConnectionEntries = NumRASEntries();
// Get the name of the default entry.
nsresult result = GetDefaultEntryName(mDefaultEntryName,
RAS_MaxEntryName + 1);
nsresult result = GetDefaultEntryName(mDefaultEntryName,
sizeof(mDefaultEntryName));
return result;
}
@ -205,9 +206,9 @@ int nsRASAutodial::QueryAutodialBehavior()
// If we get to here, then the service is not going to dial on error, so we
// can dial ourselves if the control panel settings are set up that way.
HKEY hKey = 0;
LONG result = ::RegOpenKeyEx(
LONG result = ::RegOpenKeyExW(
HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
0,
KEY_READ,
&hKey);
@ -223,7 +224,7 @@ int nsRASAutodial::QueryAutodialBehavior()
DWORD onDemand = 0;
DWORD paramSize = sizeof(DWORD);
result = ::RegQueryValueEx(hKey, "EnableAutodial", nsnull, &entryType, (LPBYTE)&autodial, &paramSize);
result = ::RegQueryValueExW(hKey, L"EnableAutodial", nsnull, &entryType, (LPBYTE)&autodial, &paramSize);
if (result != ERROR_SUCCESS)
{
::RegCloseKey(hKey);
@ -231,7 +232,7 @@ int nsRASAutodial::QueryAutodialBehavior()
return AUTODIAL_NEVER;
}
result = ::RegQueryValueEx(hKey, "NoNetAutodial", nsnull, &entryType, (LPBYTE)&onDemand, &paramSize);
result = ::RegQueryValueExW(hKey, L"NoNetAutodial", nsnull, &entryType, (LPBYTE)&onDemand, &paramSize);
if (result != ERROR_SUCCESS)
{
::RegCloseKey(hKey);
@ -269,9 +270,9 @@ static nsresult DoPPCConnection()
// Make the connection to the new network
CONNMGR_CONNECTIONINFO conn_info;
memset(&conn_info, 0, sizeof(CONNMGR_CONNECTIONINFO));
memset(&conn_info, 0, sizeof(conn_info));
conn_info.cbSize = sizeof(CONNMGR_CONNECTIONINFO);
conn_info.cbSize = sizeof(conn_info);
conn_info.dwParams = CONNMGR_PARAM_GUIDDESTNET;
conn_info.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
conn_info.guidDestNet = IID_DestNetInternet;
@ -321,7 +322,7 @@ static nsresult DoPPCConnection()
// Return values:
// NS_OK: dialing was successful and caller should retry
// all other values indicate that the caller should not retry
nsresult nsRASAutodial::DialDefault(const char* hostName)
nsresult nsRASAutodial::DialDefault(const PRUnichar* hostName)
{
#ifndef WINCE
mDontRetryUntil = 0;
@ -373,8 +374,8 @@ nsresult nsRASAutodial::DialDefault(const char* hostName)
LOGD(("Autodial: Dialing default: %s.",mDefaultEntryName));
RASDIALDLG rasDialDlg;
memset(&rasDialDlg, 0, sizeof(RASDIALDLG));
rasDialDlg.dwSize = sizeof(RASDIALDLG);
memset(&rasDialDlg, 0, sizeof(rasDialDlg));
rasDialDlg.dwSize = sizeof(rasDialDlg);
PRBool dialed =
(*mpRasDialDlg)(nsnull, mDefaultEntryName, nsnull, &rasDialDlg);
@ -404,8 +405,8 @@ nsresult nsRASAutodial::DialDefault(const char* hostName)
LOGD(("Autodial: Prompting for phonebook entry."));
RASPBDLG rasPBDlg;
memset(&rasPBDlg, 0, sizeof(RASPBDLG));
rasPBDlg.dwSize = sizeof(RASPBDLG);
memset(&rasPBDlg, 0, sizeof(rasPBDlg));
rasPBDlg.dwSize = sizeof(rasPBDlg);
PRBool dialed = (*mpRasPhonebookDlg)(nsnull, nsnull, &rasPBDlg);
@ -443,8 +444,8 @@ PRBool nsRASAutodial::IsRASConnected()
{
DWORD connections;
RASCONN rasConn;
rasConn.dwSize = sizeof(RASCONN);
DWORD structSize = sizeof(RASCONN);
rasConn.dwSize = sizeof(rasConn);
DWORD structSize = sizeof(rasConn);
if (!LoadRASapi32DLL())
return NS_ERROR_NULL_POINTER;
@ -462,15 +463,15 @@ PRBool nsRASAutodial::IsRASConnected()
}
// Get the first RAS dial entry name from the phonebook.
nsresult nsRASAutodial::GetFirstEntryName(char* entryName, int bufferSize)
nsresult nsRASAutodial::GetFirstEntryName(PRUnichar* entryName, int bufferSize)
{
// Need to load the DLL if not loaded yet.
if (!LoadRASapi32DLL())
return NS_ERROR_NULL_POINTER;
RASENTRYNAME rasEntryName;
rasEntryName.dwSize = sizeof(RASENTRYNAME);
DWORD cb = sizeof(RASENTRYNAME);
RASENTRYNAMEW rasEntryName;
rasEntryName.dwSize = sizeof(rasEntryName);
DWORD cb = sizeof(rasEntryName);
DWORD cEntries = 0;
DWORD result =
@ -479,9 +480,8 @@ nsresult nsRASAutodial::GetFirstEntryName(char* entryName, int bufferSize)
// ERROR_BUFFER_TOO_SMALL is OK because we only need one struct.
if (result == ERROR_SUCCESS || result == ERROR_BUFFER_TOO_SMALL)
{
#ifndef WINCE
strncpy(entryName, rasEntryName.szEntryName, bufferSize);
#endif
wcsncpy(entryName, rasEntryName.szEntryName,
bufferSize / sizeof(*entryName));
return NS_OK;
}
@ -495,9 +495,9 @@ int nsRASAutodial::NumRASEntries()
if (!LoadRASapi32DLL())
return 0;
RASENTRYNAME rasEntryName;
rasEntryName.dwSize = sizeof(RASENTRYNAME);
DWORD cb = sizeof(RASENTRYNAME);
RASENTRYNAMEW rasEntryName;
rasEntryName.dwSize = sizeof(rasEntryName);
DWORD cb = sizeof(rasEntryName);
DWORD cEntries = 0;
@ -514,7 +514,7 @@ int nsRASAutodial::NumRASEntries()
}
// Get the name of the default dial entry.
nsresult nsRASAutodial::GetDefaultEntryName(char* entryName, int bufferSize)
nsresult nsRASAutodial::GetDefaultEntryName(PRUnichar* entryName, int bufferSize)
{
// No RAS dialup entries.
if (mNumRASConnectionEntries <= 0)
@ -535,8 +535,8 @@ nsresult nsRASAutodial::GetDefaultEntryName(char* entryName, int bufferSize)
// or HKLM/Software/Microsoft/RAS Autodial/Default/DefaultInternet.
// For Windows 2K: HKCU/RemoteAccess/InternetProfile.
char* key = nsnull;
char* val = nsnull;
const PRUnichar* key = nsnull;
const PRUnichar* val = nsnull;
HKEY hKey = 0;
LONG result = 0;
@ -545,10 +545,10 @@ nsresult nsRASAutodial::GetDefaultEntryName(char* entryName, int bufferSize)
if ((mOSVerInfo.dwMajorVersion == 4) // Windows NT
|| ((mOSVerInfo.dwMajorVersion == 5) && (mOSVerInfo.dwMinorVersion == 0))) // Windows 2000
{
key = "RemoteAccess";
val = "InternetProfile";
key = L"RemoteAccess";
val = L"InternetProfile";
result = ::RegOpenKeyEx(
result = ::RegOpenKeyExW(
HKEY_CURRENT_USER,
key,
0,
@ -562,12 +562,12 @@ nsresult nsRASAutodial::GetDefaultEntryName(char* entryName, int bufferSize)
}
else // Windows XP
{
key = "Software\\Microsoft\\RAS Autodial\\Default";
val = "DefaultInternet";
key = L"Software\\Microsoft\\RAS Autodial\\Default";
val = L"DefaultInternet";
// Try HKCU first.
result = ::RegOpenKeyEx(
result = ::RegOpenKeyExW(
HKEY_CURRENT_USER,
key,
0,
@ -577,7 +577,7 @@ nsresult nsRASAutodial::GetDefaultEntryName(char* entryName, int bufferSize)
if (result != ERROR_SUCCESS)
{
// If not present, try HKLM.
result = ::RegOpenKeyEx(
result = ::RegOpenKeyExW(
HKEY_LOCAL_MACHINE,
key,
0,
@ -595,7 +595,7 @@ nsresult nsRASAutodial::GetDefaultEntryName(char* entryName, int bufferSize)
DWORD entryType = 0;
DWORD buffSize = bufferSize;
result = ::RegQueryValueEx(hKey,
result = ::RegQueryValueExW(hKey,
val,
nsnull,
&entryType,
@ -631,7 +631,7 @@ PRBool nsRASAutodial::IsAutodialServiceRunning()
}
SC_HANDLE hService =
OpenService(hSCManager, "RasAuto", SERVICE_QUERY_STATUS);
OpenServiceW(hSCManager, L"RasAuto", SERVICE_QUERY_STATUS);
if (hSCManager == nsnull)
{
@ -655,23 +655,23 @@ PRBool nsRASAutodial::IsAutodialServiceRunning()
}
// Add the specified address to the autodial directory.
PRBool nsRASAutodial::AddAddressToAutodialDirectory(const char* hostName)
PRBool nsRASAutodial::AddAddressToAutodialDirectory(const PRUnichar* hostName)
{
// Need to load the DLL if not loaded yet.
if (!LoadRASapi32DLL())
return PR_FALSE;
// First see if there is already a db entry for this address.
RASAUTODIALENTRY autodialEntry;
autodialEntry.dwSize = sizeof(RASAUTODIALENTRY);
DWORD size = sizeof(RASAUTODIALENTRY);
RASAUTODIALENTRYW autodialEntry;
autodialEntry.dwSize = sizeof(autodialEntry);
DWORD size = sizeof(autodialEntry);
DWORD entries = 0;
DWORD result = (*mpRasGetAutodialAddress)(hostName,
nsnull,
&autodialEntry,
&size,
&entries);
nsnull,
&autodialEntry,
&size,
&entries);
// If there is already at least 1 entry in db for this address, return.
if (result != ERROR_FILE_NOT_FOUND)
@ -680,16 +680,16 @@ PRBool nsRASAutodial::AddAddressToAutodialDirectory(const char* hostName)
return PR_FALSE;
}
autodialEntry.dwSize = sizeof(RASAUTODIALENTRY);
autodialEntry.dwSize = sizeof(autodialEntry);
autodialEntry.dwFlags = 0;
autodialEntry.dwDialingLocation = mAutodialServiceDialingLocation;
GetDefaultEntryName(autodialEntry.szEntry, RAS_MaxEntryName);
GetDefaultEntryName(autodialEntry.szEntry, sizeof(autodialEntry.szEntry));
result = (*mpRasSetAutodialAddress)(hostName,
0,
&autodialEntry,
sizeof(RASAUTODIALENTRY),
1);
0,
&autodialEntry,
sizeof(autodialEntry),
1);
if (result != ERROR_SUCCESS)
{
@ -698,7 +698,7 @@ PRBool nsRASAutodial::AddAddressToAutodialDirectory(const char* hostName)
}
LOGD(("Autodial: Added address %s to RAS autodial db for entry %s.",
hostName, autodialEntry.szEntry));
hostName, NS_ConvertUTF16toUTF8(autodialEntry.szEntry).get()));
return PR_TRUE;
}
@ -707,9 +707,9 @@ PRBool nsRASAutodial::AddAddressToAutodialDirectory(const char* hostName)
int nsRASAutodial::GetCurrentLocation()
{
HKEY hKey = 0;
LONG result = ::RegOpenKeyEx(
LONG result = ::RegOpenKeyExW(
HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Windows\\CurrentVersion\\Telephony\\Locations",
L"Software\\Microsoft\\Windows\\CurrentVersion\\Telephony\\Locations",
0,
KEY_READ,
&hKey);
@ -724,7 +724,7 @@ int nsRASAutodial::GetCurrentLocation()
DWORD location = 0;
DWORD paramSize = sizeof(DWORD);
result = ::RegQueryValueEx(hKey, "CurrentID", nsnull, &entryType, (LPBYTE)&location, &paramSize);
result = ::RegQueryValueExW(hKey, L"CurrentID", nsnull, &entryType, (LPBYTE)&location, &paramSize);
if (result != ERROR_SUCCESS)
{
::RegCloseKey(hKey);
@ -762,7 +762,7 @@ PRBool nsRASAutodial::LoadRASapi32DLL()
{
if (!mhRASapi32)
{
mhRASapi32 = ::LoadLibrary("rasapi32.dll");
mhRASapi32 = ::LoadLibraryW(L"rasapi32.dll");
if ((UINT)mhRASapi32 > 32)
{
// RasEnumConnections
@ -811,16 +811,16 @@ PRBool nsRASAutodial::LoadRASdlgDLL()
{
if (!mhRASdlg)
{
mhRASdlg = ::LoadLibrary("rasdlg.dll");
mhRASdlg = ::LoadLibraryW(L"rasdlg.dll");
if ((UINT)mhRASdlg > 32)
{
// RasPhonebookDlg
mpRasPhonebookDlg =
(tRASPHONEBOOKDLG)::GetProcAddress(mhRASdlg, "RasPhonebookDlgA");
(tRASPHONEBOOKDLG)::GetProcAddress(mhRASdlg, "RasPhonebookDlgW");
// RasDialDlg
mpRasDialDlg =
(tRASDIALDLG)::GetProcAddress(mhRASdlg, "RasDialDlgA");
(tRASDIALDLG)::GetProcAddress(mhRASdlg, "RasDialDlgW");
}
}

Просмотреть файл

@ -52,21 +52,21 @@ typedef struct tagRASAUTODIALENTRYA {
DWORD dwSize;
DWORD dwFlags;
DWORD dwDialingLocation;
CHAR szEntry[RAS_MaxEntryName + 1];
} RASAUTODIALENTRYA, *LPRASAUTODIALENTRYA;
typedef RASAUTODIALENTRYA RASAUTODIALENTRY, *LPRASAUTODIALENTRY;
PRUnichar szEntry[RAS_MaxEntryName + 1];
} RASAUTODIALENTRYW, *LPRASAUTODIALENTRYW;
typedef RASAUTODIALENTRYW RASAUTODIALENTRY, *LPRASAUTODIALENTRY;
#define RASADP_LoginSessionDisable 1
#endif // WINVER
// Loading the RAS DLL dynamically.
typedef DWORD (WINAPI* tRASPHONEBOOKDLG)(LPTSTR,LPTSTR,LPRASPBDLG);
typedef DWORD (WINAPI* tRASDIALDLG)(LPTSTR,LPTSTR,LPTSTR,LPRASDIALDLG);
typedef DWORD (WINAPI* tRASPHONEBOOKDLG)(LPWSTR,LPWSTR,LPRASPBDLG);
typedef DWORD (WINAPI* tRASDIALDLG)(LPWSTR,LPWSTR,LPWSTR,LPRASDIALDLG);
typedef DWORD (WINAPI* tRASENUMCONNECTIONS)(LPRASCONN,LPDWORD,LPDWORD);
typedef DWORD (WINAPI* tRASENUMENTRIES)(LPTSTR,LPTSTR,LPRASENTRYNAME,LPDWORD,LPDWORD);
typedef DWORD (WINAPI* tRASSETAUTODIALADDRESS)(LPCTSTR,DWORD,LPRASAUTODIALENTRY,DWORD,DWORD);
typedef DWORD (WINAPI* tRASGETAUTODIALADDRESS)(LPCTSTR,LPDWORD,LPRASAUTODIALENTRY,LPDWORD,LPDWORD);
typedef DWORD (WINAPI* tRASENUMENTRIES)(LPWSTR,LPWSTR,LPRASENTRYNAMEW,LPDWORD,LPDWORD);
typedef DWORD (WINAPI* tRASSETAUTODIALADDRESS)(LPCWSTR,DWORD,LPRASAUTODIALENTRYW,DWORD,DWORD);
typedef DWORD (WINAPI* tRASGETAUTODIALADDRESS)(LPCWSTR,LPDWORD,LPRASAUTODIALENTRYW,LPDWORD,LPDWORD);
typedef DWORD (WINAPI* tRASGETAUTODIALENABLE)(DWORD,LPBOOL);
typedef DWORD (WINAPI* tRASGETAUTODIALPARAM)(DWORD,LPVOID,LPDWORD);
// For Windows NT 4, 2000, and XP, we sometimes want to open the RAS dialup
@ -107,10 +107,10 @@ private:
int NumRASEntries();
// Get the name of the default connection from the OS.
nsresult GetDefaultEntryName(char* entryName, int bufferSize);
nsresult GetDefaultEntryName(PRUnichar* entryName, int bufferSize);
// Get the name of the first RAS dial entry from the OS.
nsresult GetFirstEntryName(char* entryName, int bufferSize);
nsresult GetFirstEntryName(PRUnichar* entryName, int bufferSize);
// Check to see if RAS already has a dialup connection going.
PRBool IsRASConnected();
@ -119,7 +119,7 @@ private:
int QueryAutodialBehavior();
// Add the specified address to the autodial directory.
PRBool AddAddressToAutodialDirectory(const char* hostName);
PRBool AddAddressToAutodialDirectory(const PRUnichar* hostName);
// Get the current TAPI dialing location.
int GetCurrentLocation();
@ -145,7 +145,7 @@ private:
int mNumRASConnectionEntries;
// Default connection entry name.
char mDefaultEntryName[RAS_MaxEntryName + 1];
PRUnichar mDefaultEntryName[RAS_MaxEntryName + 1];
// Don't try to dial again within a few seconds of when user pressed cancel.
static PRIntervalTime mDontRetryUntil;
@ -184,7 +184,7 @@ public:
nsresult Init();
// Dial the default RAS dialup connection.
nsresult DialDefault(const char* hostName);
nsresult DialDefault(const PRUnichar* hostName);
// Should we try to dial on network error?
PRBool ShouldDialOnNetworkError();

Просмотреть файл

@ -44,7 +44,7 @@
PRBool
nsNativeConnectionHelper::OnConnectionFailed(const char* hostName)
nsNativeConnectionHelper::OnConnectionFailed(const PRUnichar* hostName)
{
nsRASAutodial autodial;

Просмотреть файл

@ -50,7 +50,7 @@ public:
*
* Return PR_TRUE if the connection should be re-attempted.
*/
static PRBool OnConnectionFailed(const char* hostName);
static PRBool OnConnectionFailed(const PRUnichar* hostName);
/**
* IsAutoDialEnabled

Просмотреть файл

@ -1252,8 +1252,10 @@ nsSocketTransport::RecoverFromError()
if (!tryAgain) {
PRBool autodialEnabled;
gSocketTransportService->GetAutodialEnabled(&autodialEnabled);
if (autodialEnabled)
tryAgain = nsNativeConnectionHelper::OnConnectionFailed(SocketHost().get());
if (autodialEnabled) {
tryAgain = nsNativeConnectionHelper::OnConnectionFailed(
NS_ConvertUTF8toUTF16(SocketHost()).get());
}
}
#endif

Просмотреть файл

@ -114,23 +114,22 @@ nsFileProtocolHandler::ReadURLFile(nsIFile* aFile, nsIURI** aURI)
rv = NS_ERROR_NOT_AVAILABLE;
IUniformResourceLocator* urlLink = nsnull;
IUniformResourceLocatorW* urlLink = nsnull;
result = ::CoCreateInstance(CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER,
IID_IUniformResourceLocator, (void**)&urlLink);
IID_IUniformResourceLocatorW, (void**)&urlLink);
if (SUCCEEDED(result) && urlLink) {
IPersistFile* urlFile = nsnull;
result = urlLink->QueryInterface(IID_IPersistFile, (void**)&urlFile);
if (SUCCEEDED(result) && urlFile) {
result = urlFile->Load(path.get(), STGM_READ);
if (SUCCEEDED(result) ) {
LPSTR lpTemp = nsnull;
LPWSTR lpTemp = nsnull;
// The URL this method will give us back seems to be already
// escaped. Hence, do not do escaping of our own.
result = urlLink->GetURL(&lpTemp);
if (SUCCEEDED(result) && lpTemp) {
rv = NS_NewURI(aURI, lpTemp);
rv = NS_NewURI(aURI, NS_ConvertUTF16toUTF8(lpTemp));
// free the string that GetURL alloc'd
CoTaskMemFree(lpTemp);
}

Просмотреть файл

@ -75,7 +75,7 @@ static void InitIPHelperLibrary(void)
if (sIPHelper)
return;
sIPHelper = LoadLibraryA("iphlpapi.dll");
sIPHelper = LoadLibraryW(L"iphlpapi.dll");
if (!sIPHelper)
return;