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,30 +67,46 @@ static nsIStreamListener *getStreamListener(URL_Struct *URL_s)
return res; return res;
} }
static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID);
static nsINetSupport *getNetSupport(URL_Struct *URL_s) static nsINetSupport *getNetSupport(URL_Struct *URL_s)
{ {
nsIStreamListener *isl = getStreamListener(URL_s); nsINetSupport *netSupport = nsnull;
if (isl) {
nsINetSupport *ins; /* Access the nsConnectionInfo object off of the URL Struct fe_data */
isl->QueryInterface(kINetSupportIID, (void **) &ins); if ((nsnull != URL_s) && (nsnull != URL_s->fe_data)) {
isl->Release(); nsConnectionInfo *pConn = (nsConnectionInfo *)URL_s->fe_data;
return ins;
/* 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, void stub_Alert(MWContext *context,
const char *msg) const char *msg)
{ {
nsINetSupport *ins; nsINetSupport *ins;
if (nsnull != (ins = getNetSupport(context->modular_data))) { if (nsnull != (ins = getNetSupport(context->modular_data))) {
nsString str(msg); nsAutoString str(msg);
ins->Alert(str);
ins->Release(); ins->Alert(str);
} else { NS_RELEASE(ins);;
printf("Alert: %s", msg); }
} /* No nsINetSupport interface... */
else {
printf("Alert: %s", msg);
}
} }
extern "C" void FE_Alert(MWContext *context, const char *msg) extern "C" void FE_Alert(MWContext *context, const char *msg)
@ -115,46 +131,54 @@ extern "C" char * fe_GetProgramDirectory(char *buffer, int length) {
XP_Bool stub_Confirm(MWContext *context, XP_Bool stub_Confirm(MWContext *context,
const char *msg) const char *msg)
{ {
nsINetSupport *ins; nsINetSupport *ins;
XP_Bool bResult = FALSE;
if (nsnull != (ins = getNetSupport(context->modular_data))) { if (nsnull != (ins = getNetSupport(context->modular_data))) {
XP_Bool res; nsAutoString str(msg);
nsString str(msg);
res = ins->Confirm(str); bResult = ins->Confirm(str);
ins->Release(); NS_RELEASE(ins);
return res; }
} else { /* No nsINetSupport interface... */
printf("Confirm: %s", msg); else {
} printf("Confirm: %s", msg);
return FALSE; }
return bResult;
} }
char *stub_Prompt(MWContext *context, char *stub_Prompt(MWContext *context,
const char *msg, const char *msg,
const char *def) const char *def)
{ {
nsINetSupport *ins; nsINetSupport *ins;
char *result = nsnull;
if (nsnull != (ins = getNetSupport(context->modular_data))) { if (nsnull != (ins = getNetSupport(context->modular_data))) {
nsString str(msg); nsAutoString str(msg);
nsString defStr(def); nsAutoString defStr(def);
nsString res; nsAutoString 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; if (ins->Prompt(msg, defStr, res)) {
NS_RELEASE(ins);
result = res.ToNewCString();
}
NS_RELEASE(ins);
}
/* No nsINetSupport interface... */
else {
char buf[256];
printf("%s\n", msg);
printf("Prompt: ");
scanf("%s", buf);
if (PL_strlen(buf)) {
result = PL_strdup(buf);
}
}
return result;
} }
PRIVATE XP_Bool PRIVATE XP_Bool
@ -163,62 +187,74 @@ stub_PromptUsernameAndPassword(MWContext *context,
char **username, char **username,
char **password) char **password)
{ {
nsINetSupport *ins; nsINetSupport *ins;
XP_Bool bResult = FALSE;
if (nsnull != (ins = getNetSupport(context->modular_data))) { if (nsnull != (ins = getNetSupport(context->modular_data))) {
nsString str(msg); nsAutoString str(msg);
nsString userStr; nsAutoString userStr;
nsString pwdStr; nsAutoString 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; if (ins->PromptUserAndPassword(msg, userStr, pwdStr)) {
*username = userStr.ToNewCString();
*password = pwdStr.ToNewCString();
bResult = TRUE;
}
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) {
bResult = TRUE;
} else {
PR_FREEIF(*username);
PR_FREEIF(*password);
}
}
return bResult;
} }
char *stub_PromptPassword(MWContext *context, char *stub_PromptPassword(MWContext *context,
const char *msg) const char *msg)
{ {
nsINetSupport *ins; nsINetSupport *ins;
char *result = nsnull;
if (nsnull != (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; if (nsnull != (ins = getNetSupport(context->modular_data))) {
nsAutoString str(msg);
nsAutoString res;
if (ins->PromptPassword(msg, res)) {
result = res.ToNewCString();
}
NS_RELEASE(ins);
}
/* No nsINetSupport interface... */
else {
char buf[256];
printf("%s\n", msg);
printf("Password: ");
scanf("%s", buf);
if (PL_strlen(buf)) {
result = PL_strdup(buf);
}
}
return result;
} }
PRIVATE void stub_GraphProgressInit(MWContext *context, PRIVATE void stub_GraphProgressInit(MWContext *context,