Hook up status remarks from netlib, add interface for prompts and alerts.

git-svn-id: svn://10.0.0.236/trunk@6099 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
scullin%netscape.com
1998-07-21 20:27:59 +00:00
parent 9ec6531e85
commit 629d196dca
10 changed files with 290 additions and 83 deletions

View File

@@ -4,6 +4,7 @@
nsIStreamListener.h
nsINetService.h
nsINetSupport.h
nsIRelatedLinks.h
nsIURL.h
nsIPostToServer.h

View File

@@ -37,6 +37,7 @@ REQUIRES = raptor js dbm nspr security pref xpcom util img \
EXPORTS = nsIStreamListener.h \
nsINetService.h \
nsINetSupport.h \
nsIURL.h \
nsIRelatedLinks.h \
nsIPostToServer.h \

View File

@@ -24,6 +24,7 @@ IGNORE_MANIFEST = 1
MODULE = netlib
EXPORTS = nsIStreamListener.h \
nsINetService.h \
nsINetSupport.h \
nsIURL.h \
nsIPostToServer.h \
nsIHttpUrl.h \
@@ -107,6 +108,7 @@ LLIBS=$(LLIBS) $(LIBNSPR) \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\xplib.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\dbm32.lib \
$(NETLIBS) \
$(NULL)
@@ -144,4 +146,13 @@ $(DLL): $(NETLIBS)
libs:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME) $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\netlib.lib $(DIST)\lib
$(MAKE_INSTALL) .\res\gopher-audio.gif $(DIST)\bin\res\network
$(MAKE_INSTALL) .\res\gopher-binary.gif $(DIST)\bin\res\network
$(MAKE_INSTALL) .\res\gopher-find.gif $(DIST)\bin\res\network
$(MAKE_INSTALL) .\res\gopher-image.gif $(DIST)\bin\res\network
$(MAKE_INSTALL) .\res\gopher-menu.gif $(DIST)\bin\res\network
$(MAKE_INSTALL) .\res\gopher-movie.gif $(DIST)\bin\res\network
$(MAKE_INSTALL) .\res\gopher-telnet.gif $(DIST)\bin\res\network
$(MAKE_INSTALL) .\res\gopher-text.gif $(DIST)\bin\res\network
$(MAKE_INSTALL) .\res\gopher-unknown.gif $(DIST)\bin\res\network

View File

@@ -20,3 +20,4 @@ EXPORTS
NET_ToggleTrace
NET_PollSockets
NS_NewRelatedLinks
kINetSupportIID

View File

@@ -33,11 +33,12 @@ public:
const nsString &aDefault,
nsString &aResult) = 0;
NS_IMETHOD_(PRBool) PasswordPrompt(const nsString &aText,
nsString &aUser,
nsString &aPassword) = 0;
NS_IMETHOD_(PRBool) PromptUserAndPassword(const nsString &aText,
nsString &aUser,
nsString &aPassword) = 0;
NS_IMETHOD_(PRBool) PromptPassword(const nsString &aText,
nsString &aPassword) = 0;
};
#endif

View File

@@ -79,6 +79,9 @@ public:
{ 0x45d234d0, 0xc6c9, 0x11d1, \
{0xbe, 0xa2, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
NS_DECLARE_ID(kIStreamListenerIID, 0x45d234d0, 0xc6c9, 0x11d1,
0xbe, 0xa2, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc);
/**
* The nsIStreamListener interface provides the necessary notifications
* during both synchronous and asynchronous URL loading.

View File

@@ -1,2 +1,4 @@
#define NS_IMPL_IDS
#include "nsINetSupport.h"
#include "nsIStreamListener.h"
#include "nsIPref.h"

View File

@@ -35,7 +35,7 @@ extern "C" {
#include "nsINetContainerApplication.h"
/* XXX: Legacy definitions... */
MWContext *new_stub_context();
MWContext *new_stub_context(URL_Struct *URL_s);
void free_stub_context(MWContext *window_id);
static void bam_exit_routine(URL_Struct *URL_s, int status, MWContext *window_id);
@@ -94,7 +94,9 @@ nsNetlibService::nsNetlibService(nsINetContainerApplication *aContainerApp)
{
NS_INIT_REFCNT();
m_stubContext = new_stub_context();
/*
m_stubContext = new_stub_context();
*/
/* Initialize netlib with 32 sockets... */
NET_InitNetLib(0, 32);
@@ -108,6 +110,8 @@ nsNetlibService::nsNetlibService(nsINetContainerApplication *aContainerApp)
NET_CacheConverter);
NET_RegisterContentTypeConverter("*", FO_NGLAYOUT, NULL,
NET_NGLayoutConverter);
NET_RegisterContentTypeConverter(APPLICATION_HTTP_INDEX, FO_NGLAYOUT,
NULL, NET_HTTPIndexFormatToHTMLConverter);
NET_RegisterUniversalEncodingConverter("chunked",
NULL,
@@ -163,10 +167,12 @@ nsNetlibService::~nsNetlibService()
{
TRACEMSG(("nsNetlibService is being destroyed...\n"));
if (NULL != m_stubContext) {
/*
if (NULL != m_stubContext) {
free_stub_context((MWContext *)m_stubContext);
m_stubContext = NULL;
}
}
*/
NS_IF_RELEASE(mContainer);
NET_ShutdownNetLib();
@@ -174,7 +180,7 @@ nsNetlibService::~nsNetlibService()
nsresult nsNetlibService::OpenStream(nsIURL *aUrl,
nsIStreamListener *aConsumer)
nsIStreamListener *aConsumer)
{
URL_Struct *URL_s;
nsConnectionInfo *pConn;
@@ -221,16 +227,23 @@ nsresult nsNetlibService::OpenStream(nsIURL *aUrl,
* XXX: Currently the return value form InitializeURLInfo(...) is
* ignored... Should the connection abort if it fails?
*/
result = aUrl->QueryInterface(kIProtocolConnectionIID, (void**)&pProtocol);
if (NS_OK == result) {
pProtocol->InitializeURLInfo(URL_s);
NS_RELEASE(pProtocol);
}
result = aUrl->QueryInterface(kIProtocolConnectionIID, (void**)&pProtocol);
if (NS_OK == result) {
pProtocol->InitializeURLInfo(URL_s);
NS_RELEASE(pProtocol);
}
MWContext *stubContext = new_stub_context(URL_s);
/* Start the URL load... */
/*
NET_GetURL (URL_s, // URL_Struct
FO_CACHE_AND_NGLAYOUT, // FO_Present_type
(MWContext *)m_stubContext, // MWContext
bam_exit_routine); // Exit routine...
*/
NET_GetURL (URL_s, /* URL_Struct */
FO_CACHE_AND_NGLAYOUT, /* FO_Present_type */
(MWContext *)m_stubContext, /* MWContext */
(MWContext *)stubContext, /* MWContext */
bam_exit_routine); /* Exit routine... */
/* Remember, the URL_s may have been freed ! */
@@ -312,10 +325,18 @@ nsresult nsNetlibService::OpenBlockingStream(nsIURL *aUrl,
/* printf("+++ Loading %s\n", aUrl); */
MWContext *stubContext = new_stub_context(URL_s);
/* Start the URL load... */
/*
NET_GetURL (URL_s, // URL_Struct
FO_CACHE_AND_NGLAYOUT, // FO_Present_type
(MWContext *)m_stubContext, // MWContext
bam_exit_routine); // Exit routine...
*/
NET_GetURL (URL_s, /* URL_Struct */
FO_CACHE_AND_NGLAYOUT, /* FO_Present_type */
(MWContext *)m_stubContext, /* MWContext */
(MWContext *) stubContext, /* MWContext */
bam_exit_routine); /* Exit routine... */
/* Remember, the URL_s may have been freed ! */
@@ -485,5 +506,8 @@ static void bam_exit_routine(URL_Struct *URL_s, int status, MWContext *window_id
/* Delete the URL_Struct... */
NET_FreeURLStruct(URL_s);
}
if (NULL != window_id) {
// free_stub_context(window_id);
}
}

View File

@@ -42,7 +42,7 @@ extern "C" {
extern "C" {
#if defined(XP_UNIX) || defined(XP_WIN)
#if defined(XP_UNIX)
DB *
dbopen(const char *fname, int flags,int mode, DBTYPE type,
const void *openinfo)
@@ -755,7 +755,9 @@ XP_FileOpen(const char * name, XP_FileType type, const XP_FilePerm perm)
switch (type) {
case xpURL:
case xpFileToPost: {
case xpFileToPost:
case xpHTTPCookie:
{
XP_File fp;
char* newName = WH_FileName(name, type);
@@ -822,7 +824,13 @@ WH_FileName (const char *NetName, XP_FileType type)
{
MOZ_FUNCTION_STUB;
if ((type == xpURL) || (type == xpFileToPost)) {
if (type == xpHTTPCookie) {
#ifdef XP_PC
return PL_strdup("cookies.txt");
#else
return PL_strdup("cookies");
#endif
} else if ((type == xpURL) || (type == xpFileToPost)) {
/*
* This is the body of XP_NetToDosFileName(...) which is implemented
* for Windows only in fegui.cpp
@@ -955,12 +963,6 @@ char *INTL_ResourceCharSet(void)
*---------------------------------------------------------------------------
*/
void FE_Alert(MWContext *pContext, const char *pMsg)
{
MOZ_FUNCTION_STUB;
}
int32 FE_GetContextID(MWContext *pContext)
{
MOZ_FUNCTION_STUB;

View File

@@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
@@ -22,9 +22,11 @@
#include "structs.h"
#include "ctxtfunc.h"
#include "xp_list.h"
#include "plstr.h"
#include "nsString.h"
#include "nsIStreamListener.h"
#include "nsINetSupport.h"
#include "nsNetStream.h"
/****************************************************************************/
@@ -45,27 +47,181 @@ stub_noop(int x, ...)
return 0;
}
PRIVATE void stub_GraphProgressInit(MWContext *context,
URL_Struct *URL_s,
int32 content_length)
static nsIStreamListener *getStreamListener(URL_Struct *URL_s)
{
nsConnectionInfo *pConn;
if (NULL != URL_s->fe_data) {
if (URL_s->load_background)
return;
nsIStreamListener *res = NULL;
if (URL_s->fe_data) {
/*
* Retrieve the nsConnectionInfo object from the fe_data field
* of the URL_Struct...
*/
pConn = (nsConnectionInfo *)URL_s->fe_data;
if ((NULL != pConn) && (NULL != pConn->pConsumer)) {
nsAutoString status;
pConn->pConsumer->OnProgress(pConn->pURL, 0, content_length, status);
nsConnectionInfo *pConn = (nsConnectionInfo *)URL_s->fe_data;
if (pConn) {
res = pConn->pConsumer;
}
}
NS_IF_ADDREF(res);
return res;
}
static nsINetSupport *getNetSupport(URL_Struct *URL_s)
{
nsIStreamListener *isl = getStreamListener(URL_s);
if (isl) {
nsINetSupport *ins;
isl->QueryInterface(kINetSupportIID, (void **) &ins);
isl->Release();
return ins;
}
return NULL;
}
void stub_Alert(MWContext *context,
const char *msg)
{
nsINetSupport *ins;
if (ins = getNetSupport(context->modular_data)) {
nsString str(msg);
ins->Alert(str);
ins->Release();
} else {
printf("Alert: %s", msg);
}
}
extern "C" void FE_Alert(MWContext *context, const char *msg)
{
stub_Alert(context, msg);
}
XP_Bool stub_Confirm(MWContext *context,
const char *msg)
{
nsINetSupport *ins;
if (ins = getNetSupport(context->modular_data)) {
XP_Bool res;
nsString str(msg);
res = ins->Confirm(str);
ins->Release();
return res;
} else {
printf("Confirm: %s", msg);
}
return FALSE;
}
char *stub_Prompt(MWContext *context,
const char *msg,
const char *def)
{
nsINetSupport *ins;
if (ins = getNetSupport(context->modular_data)) {
nsString str(msg);
nsString defStr(def);
nsString res;
if (ins->Prompt(msg, defStr, res)) {
ins->Release();
return res.ToNewCString();
}
ins->Release();
} else {
char buf[256];
printf("%s\n", msg);
printf("Prompt: ");
scanf("%s", buf);
if (PL_strlen(buf)) {
return PL_strdup(buf);
}
}
return NULL;
}
PRIVATE XP_Bool
stub_PromptUsernameAndPassword(MWContext *context,
const char *msg,
char **username,
char **password)
{
nsINetSupport *ins;
if (ins = getNetSupport(context->modular_data)) {
nsString str(msg);
nsString userStr;
nsString pwdStr;
if (ins->PromptUserAndPassword(msg, userStr, pwdStr)) {
ins->Release();
*username = userStr.ToNewCString();
*password = pwdStr.ToNewCString();
return TRUE;
}
ins->Release();
} else {
char buf[256];
printf("%s\n", msg);
printf("Username: ");
scanf("%s", buf);
*username = PL_strdup(buf);
printf("Password: ");
scanf("%s", buf);
*password = PL_strdup(buf);
if (**username) {
return TRUE;
}
PR_FREEIF(*username);
PR_FREEIF(*password);
}
return FALSE;
}
char *stub_PromptPassword(MWContext *context,
const char *msg)
{
nsINetSupport *ins;
if (ins = getNetSupport(context->modular_data)) {
nsString str(msg);
nsString res;
if (ins->PromptPassword(msg, res)) {
ins->Release();
return res.ToNewCString();
}
ins->Release();
} else {
char buf[256];
printf("%s\n", msg);
printf("Password: ");
scanf("%s", buf);
if (PL_strlen(buf)) {
return PL_strdup(buf);
}
}
return NULL;
}
PRIVATE void stub_GraphProgressInit(MWContext *context,
URL_Struct *URL_s,
int32 content_length)
{
nsIStreamListener *pListener;
if (URL_s->load_background)
return;
if (pListener = getStreamListener(URL_s)) {
nsConnectionInfo *pConn = (nsConnectionInfo *) URL_s->fe_data;
nsAutoString status;
pListener->OnProgress(pConn->pURL, 0, content_length, status);
pListener->Release();
}
}
@@ -75,22 +231,17 @@ PRIVATE void stub_GraphProgress(MWContext *context,
int32 bytes_since_last_time,
int32 content_length)
{
nsConnectionInfo *pConn;
nsIStreamListener *pListener;
if (NULL != URL_s->fe_data) {
if (URL_s->load_background)
return;
/*
* Retrieve the nsConnectionInfo object from the fe_data field
* of the URL_Struct...
*/
pConn = (nsConnectionInfo *)URL_s->fe_data;
if ((NULL != pConn) && (NULL != pConn->pConsumer)) {
nsAutoString status;
if (URL_s->load_background)
return;
pConn->pConsumer->OnProgress(pConn->pURL, bytes_received,
content_length, status);
}
if (pListener = getStreamListener(URL_s)) {
nsConnectionInfo *pConn = (nsConnectionInfo *) URL_s->fe_data;
nsAutoString status;
pListener->OnProgress(pConn->pURL, bytes_received,
content_length, status);
pListener->Release();
}
}
@@ -99,32 +250,39 @@ PRIVATE void stub_GraphProgressDestroy(MWContext *context,
int32 content_length,
int32 total_bytes_read)
{
nsConnectionInfo *pConn;
/*
* XXX: Currently this function never calls OnProgress(...) because
* netlib calls FE_GraphProgressDestroy(...) after closing the
* stream... So, OnStopBinding(...) has already been called and
* the nsConnectionInfo->pConsumer has been released and NULLed...
*/
if (NULL != URL_s->fe_data) {
if (URL_s->load_background)
return;
/*
* Retrieve the nsConnectionInfo object from the fe_data field
* of the URL_Struct...
*/
pConn = (nsConnectionInfo *)URL_s->fe_data;
if ((NULL != pConn) && (NULL != pConn->pConsumer)) {
nsAutoString status;
nsIStreamListener *pListener;
pConn->pConsumer->OnProgress(pConn->pURL, total_bytes_read,
content_length, status);
}
if (URL_s->load_background)
return;
if (pListener = getStreamListener(URL_s)) {
nsConnectionInfo *pConn = (nsConnectionInfo *) URL_s->fe_data;
nsAutoString status;
pListener->OnProgress(pConn->pURL, total_bytes_read,
content_length, status);
}
}
PRIVATE void stub_Progress(MWContext *context, const char *msg)
{
nsIStreamListener *pListener;
if (pListener = getStreamListener(context->modular_data)) {
nsConnectionInfo *pConn =
(nsConnectionInfo *) context->modular_data->fe_data;
nsAutoString status(msg);
pListener->OnProgress(pConn->pURL, -1, -1, status);
pListener->Release();
} else {
printf("%s\n", msg);
}
}
#define MAKE_FE_TYPES_PREFIX(func) func##_t
@@ -183,8 +341,8 @@ PRIVATE void stub_GraphProgressDestroy(MWContext *context,
#define stub_EndPreSection (EndPreSection_t)stub_noop
#define stub_SetProgressBarPercent (SetProgressBarPercent_t)stub_noop
#define stub_SetBackgroundColor (SetBackgroundColor_t)stub_noop
#define stub_Progress (Progress_t)stub_noop
#define stub_Alert (Alert_t)stub_noop
#define stub_Progress (Progress_t)stub_Progress
#define stub_Alert (Alert_t)stub_Alert
#define stub_SetCallNetlibAllTheTime (SetCallNetlibAllTheTime_t)stub_noop
#define stub_ClearCallNetlibAllTheTime (ClearCallNetlibAllTheTime_t)stub_noop
#define stub_GraphProgressInit (GraphProgressInit_t)stub_GraphProgressInit
@@ -194,11 +352,11 @@ PRIVATE void stub_GraphProgressDestroy(MWContext *context,
#define stub_UseFancyNewsgroupListing (UseFancyNewsgroupListing_t)stub_noop
#define stub_FileSortMethod (FileSortMethod_t)stub_noop
#define stub_ShowAllNewsArticles (ShowAllNewsArticles_t)stub_noop
#define stub_Confirm (Confirm_t)stub_noop
#define stub_Prompt (Prompt_t)stub_noop
#define stub_Confirm (Confirm_t)stub_Confirm
#define stub_Prompt (Prompt_t)stub_Prompt
#define stub_PromptWithCaption (PromptWithCaption_t)stub_noop
#define stub_PromptUsernameAndPassword (PromptUsernameAndPassword_t)stub_noop
#define stub_PromptPassword (PromptPassword_t)stub_noop
#define stub_PromptUsernameAndPassword (PromptUsernameAndPassword_t)stub_PromptUsernameAndPassword
#define stub_PromptPassword (PromptPassword_t)stub_PromptPassword
#define stub_EnableClicking (EnableClicking_t)stub_noop
#define stub_AllConnectionsComplete (AllConnectionsComplete_t)stub_noop
#define stub_ImageSize (ImageSize_t)stub_noop
@@ -227,7 +385,7 @@ ContextFuncs stub_context_funcs;
XP_List *stub_context_list = NULL;
MWContext *new_stub_context()
MWContext *new_stub_context(URL_Struct *URL_s)
{
static int funcsInitialized = 0;
MWContext *context;
@@ -247,6 +405,7 @@ MWContext *new_stub_context()
if (nsnull != context) {
context->funcs = &stub_context_funcs;
context->type = MWContextBrowser;
context->modular_data = URL_s;
if (nsnull != stub_context_list) {
XP_ListAddObjectToEnd(stub_context_list, context);
@@ -260,13 +419,15 @@ void free_stub_context(MWContext *window_id)
{
TRACEMSG(("Freeing stub context...\n"));
if (stub_context_list) {
PRBool result;
result = XP_ListRemoveObject(stub_context_list, window_id);
PR_ASSERT(PR_TRUE == result);
if (window_id) {
if (stub_context_list) {
PRBool result;
result = XP_ListRemoveObject(stub_context_list, window_id);
PR_ASSERT(PR_TRUE == result);
}
free(window_id);
}
free(window_id);
}