Moved the implementation of the nsINetSupport interface from the nsdocumentBindInfo over to the URL container...

This commit is contained in:
rpotts%netscape.com 1998-11-03 08:01:29 +00:00
parent fc6879b139
commit 9a4a51d584

View File

@ -67,16 +67,29 @@ static nsIStreamListener *getStreamListener(URL_Struct *URL_s)
return res;
}
static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID);
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;
nsINetSupport *netSupport = nsnull;
/* Access the nsConnectionInfo object off of the URL Struct fe_data */
if ((nsnull != URL_s) && (nsnull != URL_s->fe_data)) {
nsConnectionInfo *pConn = (nsConnectionInfo *)URL_s->fe_data;
/* Now get the nsIURL held by the nsConnectionInfo... */
if ((nsnull != pConn) && (nsnull != pConn->pURL)) {
nsISupports *container;
/* The nsINetSupport interface will be implemented by the container */
container = pConn->pURL->GetContainer();
if (nsnull != container) {
container->QueryInterface(kINetSupportIID, (void **) &netSupport);
NS_RELEASE(container);
}
return NULL;
}
}
return netSupport;
}
void stub_Alert(MWContext *context,
@ -85,10 +98,13 @@ void stub_Alert(MWContext *context,
nsINetSupport *ins;
if (nsnull != (ins = getNetSupport(context->modular_data))) {
nsString str(msg);
nsAutoString str(msg);
ins->Alert(str);
ins->Release();
} else {
NS_RELEASE(ins);;
}
/* No nsINetSupport interface... */
else {
printf("Alert: %s", msg);
}
}
@ -116,17 +132,19 @@ XP_Bool stub_Confirm(MWContext *context,
const char *msg)
{
nsINetSupport *ins;
XP_Bool bResult = FALSE;
if (nsnull != (ins = getNetSupport(context->modular_data))) {
XP_Bool res;
nsString str(msg);
res = ins->Confirm(str);
ins->Release();
return res;
} else {
nsAutoString str(msg);
bResult = ins->Confirm(str);
NS_RELEASE(ins);
}
/* No nsINetSupport interface... */
else {
printf("Confirm: %s", msg);
}
return FALSE;
return bResult;
}
char *stub_Prompt(MWContext *context,
@ -134,27 +152,33 @@ char *stub_Prompt(MWContext *context,
const char *def)
{
nsINetSupport *ins;
char *result = nsnull;
if (nsnull != (ins = getNetSupport(context->modular_data))) {
nsString str(msg);
nsString defStr(def);
nsString res;
nsAutoString str(msg);
nsAutoString defStr(def);
nsAutoString res;
if (ins->Prompt(msg, defStr, res)) {
ins->Release();
return res.ToNewCString();
NS_RELEASE(ins);
result = res.ToNewCString();
}
ins->Release();
} else {
NS_RELEASE(ins);
}
/* No nsINetSupport interface... */
else {
char buf[256];
printf("%s\n", msg);
printf("Prompt: ");
scanf("%s", buf);
if (PL_strlen(buf)) {
return PL_strdup(buf);
result = PL_strdup(buf);
}
}
return NULL;
return result;
}
PRIVATE XP_Bool
@ -164,61 +188,73 @@ stub_PromptUsernameAndPassword(MWContext *context,
char **password)
{
nsINetSupport *ins;
XP_Bool bResult = FALSE;
if (nsnull != (ins = getNetSupport(context->modular_data))) {
nsString str(msg);
nsString userStr;
nsString pwdStr;
nsAutoString str(msg);
nsAutoString userStr;
nsAutoString pwdStr;
if (ins->PromptUserAndPassword(msg, userStr, pwdStr)) {
ins->Release();
*username = userStr.ToNewCString();
*password = pwdStr.ToNewCString();
return TRUE;
bResult = TRUE;
}
ins->Release();
} else {
NS_RELEASE(ins);
}
/* No nsINetSupport interface... */
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;
}
bResult = TRUE;
} else {
PR_FREEIF(*username);
PR_FREEIF(*password);
}
}
return FALSE;
return bResult;
}
char *stub_PromptPassword(MWContext *context,
const char *msg)
{
nsINetSupport *ins;
char *result = nsnull;
if (nsnull != (ins = getNetSupport(context->modular_data))) {
nsString str(msg);
nsString res;
nsAutoString str(msg);
nsAutoString res;
if (ins->PromptPassword(msg, res)) {
ins->Release();
return res.ToNewCString();
result = res.ToNewCString();
}
ins->Release();
} else {
NS_RELEASE(ins);
}
/* No nsINetSupport interface... */
else {
char buf[256];
printf("%s\n", msg);
printf("Password: ");
scanf("%s", buf);
if (PL_strlen(buf)) {
return PL_strdup(buf);
result = PL_strdup(buf);
}
}
return NULL;
return result;
}
PRIVATE void stub_GraphProgressInit(MWContext *context,