1.  Reduce complexity in launching code.

nsPSMShimLayer.c
1.  Read and Write should timeout
2.  Read and Write should return errors... duh.
2.  PR_IN_PROGRESS_ERROR on Connect should be returned

nsPSMUICallbacks.cpp
1. Use the modal flag to open new windows.

nsSSLIOLayer.cpp
1.  disable Nagle algorithm

r=valeski@netscape.com
This commit is contained in:
dougt%netscape.com 2000-05-24 22:51:27 +00:00
Родитель ab5bd11ffb
Коммит c88bbbf48b
6 изменённых файлов: 110 добавлений и 171 удалений

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

@ -26,7 +26,7 @@
[scriptable, uuid(d92be9b0-601b-11d3-8c4a-000064657374)]
interface nsIPSMUIHandler : nsISupports
{
void DisplayURI(in long width, in long height, in string urlStr);
void DisplayURI(in long width, in long height, in PRBool modal, in string urlStr);
void PromptForFile(in wstring prompt, in string fileRegEx, in boolean shouldFileExist, out string outFile);
};

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

@ -41,10 +41,8 @@
#include "nsIPref.h"
#include "nsIProfile.h"
#include "nsILocalFile.h"
#ifdef XP_MAC
#include "nsILocalFileMac.h"
#endif
#include "nsSpecialSystemDirectory.h"
#include "nsDirectoryService.h"
#include "rsrcids.h"
@ -65,8 +63,7 @@
#define PSM_FILE_NAME "psm.exe"
#elif XP_UNIX
#define PSM_FILE_NAME "start-psm"
#define PSM_FILE_LOCATION "/opt/netscape/security/start-psm"
#else
#else XP_MAC
#define PSM_FILE_NAME "psm"
#endif
@ -417,8 +414,37 @@ nsPSMComponent::GetControlConnection( CMT_CONTROL * *_retval )
if (nsPSMMutexInit() != PR_SUCCESS)
return NS_ERROR_FAILURE;
// Try to see if it is open already
mControl = CMT_ControlConnect(&nsPSMMutexTbl, &nsPSMShimTbl);
// Find the one in the bin directory
if (mControl == nsnull)
{
nsCOMPtr<nsILocalFile> psmAppFile;
NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv);
if (NS_FAILED(rv)) return rv;
directoryService->Get("system.OS_CurrentProcessDirectory",
NS_GET_IID(nsIFile),
getter_AddRefs(psmAppFile));
psmAppFile->Append("psm");
psmAppFile->Append(PSM_FILE_NAME);
PRBool isExecutable, exists;
psmAppFile->Exists(&exists);
psmAppFile->IsExecutable(&isExecutable);
if (exists && isExecutable)
{
nsXPIDLCString path;
psmAppFile->GetPath(getter_Copies(path));
// FIX THIS. using a file path is totally wrong here.
mControl = CMT_EstablishControlConnection((char*)(const char*)path, &nsPSMShimTbl, &nsPSMMutexTbl);
}
}
// Get the one in the version registry
if (mControl == nsnull)
{
//Try to find it.
@ -438,98 +464,7 @@ nsPSMComponent::GetControlConnection( CMT_CONTROL * *_retval )
}
}
#ifndef XP_MAC
if (mControl == nsnull)
{
nsSpecialSystemDirectory sysDir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
nsFileSpec spec = sysDir;
spec += "psm/";
spec += PSM_FILE_NAME;
if (spec.Exists())
{
mControl = CMT_EstablishControlConnection((char *)spec.GetNativePathCString(), &nsPSMShimTbl, &nsPSMMutexTbl);
}
}
#else
if (mControl == nsnull)
{
// Attempt to locate "Personal Security Manager" in "Essential Files".
nsCOMPtr<nsILocalFile> aPSMApp = do_CreateInstance(NS_LOCAL_FILE_PROGID, &rv);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsILocalFileMac> psmAppMacFile = do_QueryInterface(aPSMApp, &rv);
if (NS_SUCCEEDED(rv))
{
rv = psmAppMacFile->InitFindingAppByCreatorCode('nPSM');
if (NS_SUCCEEDED(rv))
{
rv = psmAppMacFile->LaunchAppWithDoc(nsnull, PR_TRUE);
if (NS_SUCCEEDED(rv))
{
const PRUint32 kMaxWaitTicks = 180; // max 3 seconds
PRUint32 endTicks = ::TickCount() + kMaxWaitTicks;
do
{
EventRecord theEvent;
WaitNextEvent(0, &theEvent, 5, NULL);
mControl = CMT_ControlConnect(&nsPSMMutexTbl, &nsPSMShimTbl);
} while (!mControl && (::TickCount() < endTicks));
}
}
}
}
NS_ASSERTION(NS_SUCCEEDED(rv), "Launching Personal Security Manager failed");
}
#endif
#ifdef XP_UNIX
if (mControl == nsnull)
{
nsFileSpec psmSpec(PSM_FILE_LOCATION);
if (psmSpec.Exists())
{
mControl = CMT_EstablishControlConnection(PSM_FILE_LOCATION, &nsPSMShimTbl, &nsPSMMutexTbl);
}
}
#endif
if (mControl == nsnull)
{
char* filePath = nsnull;
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
if(NS_SUCCEEDED(rv))
{
NS_WITH_SERVICE(nsIStringBundleService, service, kCStringBundleServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsILocale* locale = nsnull;
nsCOMPtr<nsIStringBundle> stringBundle;
rv = service->CreateBundle(SECURITY_STRING_BUNDLE_URL, locale, getter_AddRefs(stringBundle));
if (NS_FAILED(rv)) return rv;
PRUnichar *ptrv = nsnull;
rv = stringBundle->GetStringFromName( NS_ConvertASCIItoUCS2("FindText").GetUnicode(), &ptrv);
if (NS_FAILED(rv)) return rv;
handler->PromptForFile(ptrv, PSM_FILE_NAME, PR_TRUE, &filePath);
nsAllocator::Free(ptrv);
}
if (! filePath)
return NS_ERROR_FAILURE;
mControl = CMT_EstablishControlConnection(filePath, &nsPSMShimTbl, &nsPSMMutexTbl);
}
if (!mControl || InitPSMUICallbacks(mControl) != PR_SUCCESS)
goto failure;
@ -542,16 +477,23 @@ nsPSMComponent::GetControlConnection( CMT_CONTROL * *_retval )
rv = profile->GetCurrentProfileDir(&profileSpec);
if (NS_FAILED(rv)) goto failure;;
#ifdef XP_MAC
profileSpec += "Security";
// make sure the dir exists
profileSpec.CreateDirectory();
#endif
rv = profile->GetCurrentProfile(&profileName);
if (NS_FAILED(rv)) goto failure;
CMTStatus psmStatus;
nsCAutoString profilenameC;
profilenameC.AssignWithConversion(profileName);
psmStatus = CMT_Hello( mControl,
PROTOCOL_VERSION,
profilenameC,
(char*)profileSpec.GetNativePathCString());
PROTOCOL_VERSION,
profilenameC,
(char*)profileSpec.GetNativePathCString());
if (psmStatus == CMTFailure)
{

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

@ -30,9 +30,13 @@
#include <unistd.h>
#endif
#define PSM_TIMEOUT_IN_SEC 30
#define NSPSMSHIMMAXFD 50
static PRIntervalTime gTimeout = PR_INTERVAL_NO_WAIT;
CMT_SocketFuncs nsPSMShimTbl =
{
nsPSMShimGetSocket,
@ -52,6 +56,13 @@ nsPSMShimGetSocket(int unixSock)
PRStatus rv;
PRFileDesc *fd;
CMSocket *sock;
PRSocketOptionData sockopt;
if (PR_INTERVAL_NO_WAIT == gTimeout)
{
gTimeout = PR_SecondsToInterval(PSM_TIMEOUT_IN_SEC);
}
if (unixSock)
@ -65,19 +76,17 @@ nsPSMShimGetSocket(int unixSock)
}
else
{
PRSocketOptionData sockopt;
fd = PR_NewTCPSocket();
PR_ASSERT(fd);
/* disable Nagle algorithm delay for control sockets */
sockopt.option = PR_SockOpt_NoDelay;
sockopt.value.no_delay = PR_TRUE;
rv = PR_SetSocketOption(fd, &sockopt);
PR_ASSERT(PR_SUCCESS == rv);
}
/* disable Nagle algorithm delay for control sockets */
sockopt.option = PR_SockOpt_NoDelay;
sockopt.value.no_delay = PR_TRUE;
rv = PR_SetSocketOption(fd, &sockopt);
PR_ASSERT(PR_SUCCESS == rv);
sock = (CMSocket *)PR_Malloc(sizeof(CMSocket));
if (sock == NULL)
@ -85,7 +94,7 @@ nsPSMShimGetSocket(int unixSock)
sock->fd = fd;
sock->isUnix = unixSock;
memset(&sock->netAddr, 0, sizeof(PRNetAddr));
return (CMTSocket)sock;
@ -94,9 +103,9 @@ nsPSMShimGetSocket(int unixSock)
CMTStatus
nsPSMShimConnect(CMTSocket sock, short port, char *path)
{
CMTStatus rv = CMTSuccess;
PRStatus err;
PRErrorCode errcode;
CMTStatus rv = CMTSuccess;
CMSocket *cmSock = (CMSocket *)sock;
if (!sock) return CMTFailure;
@ -128,28 +137,17 @@ nsPSMShimConnect(CMTSocket sock, short port, char *path)
cmSock->netAddr.inet.port = PR_htons(port);
cmSock->netAddr.inet.ip = PR_htonl(PR_INADDR_LOOPBACK);
}
err = PR_Connect( cmSock->fd, &cmSock->netAddr, PR_INTERVAL_MAX );
if (err == PR_FAILURE)
{
errcode = PR_GetError();
/* TODO: verify PR_INVALID_ARGUMENT_ERROR continue with connect */
switch (errcode)
{
case PR_IS_CONNECTED_ERROR:
case PR_IN_PROGRESS_ERROR:
rv = CMTSuccess;
break;
default:
rv = CMTFailure;
break;
}
if (PR_IS_CONNECTED_ERROR != errcode)
rv = CMTFailure;
}
return rv;
}
@ -184,15 +182,21 @@ nsPSMShimVerifyUnixSocket(CMTSocket sock)
size_t
nsPSMShimSend(CMTSocket sock, void *buffer, size_t length)
{
PRInt32 total;
CMSocket *cmSock = (CMSocket *)sock;
if (!sock) return CMTFailure;
return PR_Send(cmSock->fd, buffer, length, 0, gTimeout);
}
total = PR_Send(cmSock->fd, buffer, length, 0, PR_INTERVAL_NO_TIMEOUT);
size_t
nsPSMShimReceive(CMTSocket sock, void *buffer, size_t bufSize)
{
CMSocket *cmSock = (CMSocket *)sock;
if (!sock) return CMTFailure;
/* TODO: for now, return 0 if there's an error */
return (total < 0) ? 0 : total;
return PR_Recv(cmSock->fd, buffer, bufSize, 0, gTimeout);
}
@ -235,19 +239,6 @@ nsPSMShimSelect(CMTSocket *socks, int numsocks, int poll)
return NULL;
}
size_t
nsPSMShimReceive(CMTSocket sock, void *buffer, size_t bufSize)
{
PRInt32 total;
CMSocket *cmSock = (CMSocket *)sock;
if (!sock) return CMTFailure;
total = PR_Recv(cmSock->fd, buffer, bufSize, 0, PR_INTERVAL_NO_TIMEOUT);
/* TODO: for now, return 0 if there's an error */
return (total < 0) ? 0 : total;
}
CMTStatus
nsPSMShimShutdown(CMTSocket sock)

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

@ -54,8 +54,10 @@ static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
static char * PromptUserCallback(void *arg, char *prompt, int isPasswd);
static char * FilePathPromptCallback(void *arg, char *prompt, char *fileRegEx, CMUint32 shouldFileExist);
static void ApplicationFreeCallback(char *userInput);
static void * CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, PRBool isModel,
char* urlStr, void *data);
static void * CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height,
CMBool isModal, char* urlStr, void *data);
extern "C" void CARTMAN_UIEventLoop(void *data);
@ -63,7 +65,7 @@ extern "C" void CARTMAN_UIEventLoop(void *data);
NS_IMPL_THREADSAFE_ISUPPORTS1(nsPSMUIHandlerImpl, nsIPSMUIHandler)
NS_METHOD
nsPSMUIHandlerImpl::DisplayURI(PRInt32 width, PRInt32 height, const char *urlStr)
nsPSMUIHandlerImpl::DisplayURI(PRInt32 width, PRInt32 height, PRBool modal, const char *urlStr)
{
nsresult rv;
nsCOMPtr<nsIDOMWindow> hiddenWindow;
@ -79,11 +81,17 @@ nsPSMUIHandlerImpl::DisplayURI(PRInt32 width, PRInt32 height, const char *urlStr
{
// Set up arguments for "window.open"
void *stackPtr;
char params[36];
if (modal) // if you change this, remember to change the buffer size above.
strcpy(params, "menubar=no,height=%d,width=%d,modal");
else
strcpy(params, "menubar=no,height=%d,width=%d");
char buffer[256];
PR_snprintf(buffer,
sizeof(buffer),
"menubar=no,height=%d,width=%d,modal",
params,
height,
width );
@ -266,7 +274,7 @@ PRStatus DisplayPSMUIDialog(PCMT_CONTROL control, const char *pickledStatus, con
return PR_FAILURE;
/* Fire the URL up in a window of its own. */
pwin = CartmanUIHandler(advRID, nsnull, width, height, PR_FALSE, (char*)urlItem.data, NULL);
pwin = CartmanUIHandler(advRID, nsnull, width, height, CM_FALSE, (char*)urlItem.data, NULL);
//allocated by cmt, we can free with free:
free(urlItem.data);
@ -276,14 +284,14 @@ PRStatus DisplayPSMUIDialog(PCMT_CONTROL control, const char *pickledStatus, con
void* CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, PRBool isModal, char* urlStr, void *data)
void* CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, CMBool isModal, char* urlStr, void *data)
{
nsresult rv = NS_OK;
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
if(NS_SUCCEEDED(rv))
handler->DisplayURI(width, height, urlStr);
handler->DisplayURI(width, height, isModal, urlStr);
return nsnull;
}

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

@ -120,7 +120,7 @@ nsSSLIOLayerConnect(PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeou
char* hostName;
infoObject->GetProxyName(&proxyName);
infoObject->GetHostName(&hostName);
if (!proxyName)
{
// Direct connection
@ -152,12 +152,9 @@ nsSSLIOLayerConnect(PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeou
#endif
}
Recycle(hostName);
Recycle(proxyName);
if (hostName) Recycle(hostName);
if (proxyName) Recycle(proxyName);
if (CMTSuccess == status)
{
// since our stuff can block, what we want to do is return PR_FAILURE,
@ -187,6 +184,8 @@ nsSSLIOLayerClose(PRFileDesc *fd)
CMT_CONTROL* control;
CMSocket* socket;
PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
infoObject->GetControlPtr(&control);
infoObject->GetSocketPtr(&socket);
infoObject->SetPickledStatus();
@ -505,13 +504,13 @@ nsSSLIOLayerNewSocket( const char *host,
sock = PR_NewTCPSocket();
if (! sock) return NS_ERROR_OUT_OF_MEMORY;
// Make the socket non-blocking...
PRSocketOptionData opt;
opt.option = PR_SockOpt_Nonblocking;
opt.value.non_blocking = PR_FALSE;
rv = PR_SetSocketOption(sock, &opt);
if (PR_SUCCESS != rv)
return PR_FAILURE;
/* disable Nagle algorithm delay for control sockets */
PRSocketOptionData sockopt;
sockopt.option = PR_SockOpt_NoDelay;
sockopt.value.no_delay = PR_TRUE;
rv = PR_SetSocketOption(sock, &sockopt);
PR_ASSERT(PR_SUCCESS == rv);
layer = PR_CreateIOLayerStub(nsSSLIOLayerIdentity, &nsSSLIOLayerMethods);
if (! layer)

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

@ -347,11 +347,10 @@ nsSecureBrowserUIImpl::OnStatusChange(nsIChannel* aChannel,
return res;
}
// if (aProgressStatusFlags == nsIWebProgress::flag_net_redirecting)
//{
// res = NS_ERROR_NOT_IMPLEMENTED;
// xxx need to fix.
//}
if (aProgressStatusFlags == nsIWebProgress::flag_net_redirecting)
{
// need to implmentent.
}
return res;
}