From 18d1bc714d25792e663ac577e1e6a48f6f017d57 Mon Sep 17 00:00:00 2001 From: "morse%netscape.com" Date: Wed, 18 Nov 1998 04:38:13 +0000 Subject: [PATCH] update for single signon --- layout/forms/nsTextControlFrame.cpp | 50 +++++++++++++- layout/html/forms/src/nsFormFrame.cpp | 68 +++++++++++++++++++- layout/html/forms/src/nsTextControlFrame.cpp | 50 +++++++++++++- network/module/nsINetService.h | 11 ++++ network/module/nsNetService.cpp | 16 +++++ network/module/nsNetService.h | 7 ++ 6 files changed, 195 insertions(+), 7 deletions(-) diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index 58a5bdd1d82..ac94719cd0a 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -40,6 +40,16 @@ #include "nsIDOMHTMLInputElement.h" #include "nsIDOMHTMLTextAreaElement.h" +#ifdef SingleSignon +#include "nsIDocument.h" +#include "prmem.h" +#include "nsIURL.h" +#include "nsINetService.h" +#include "nsIServiceManager.h" +static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID); +static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID); +#endif + static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kTextCID, NS_TEXTFIELD_CID); static NS_DEFINE_IID(kTextAreaCID, NS_TEXTAREA_CID); @@ -331,13 +341,49 @@ nsTextControlFrame::PostCreateWidget(nsIPresContext* aPresContext, SetColors(*aPresContext); PRUint32 ignore; - nsAutoString value; - GetText(&value); nsITextAreaWidget* textArea = nsnull; nsITextWidget* text = nsnull; if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) { + +#ifdef SingleSignon + /* get name of text */ + nsAutoString name; + GetName(&name); + + /* get url name */ + char *URLName; + nsIURL* docURL = nsnull; + nsIDocument* doc = nsnull; + mContent->GetDocument(doc); + if (nsnull != doc) { + docURL = doc->GetDocumentURL(); + NS_RELEASE(doc); + URLName = (char*)PR_Malloc(PL_strlen(docURL->GetSpec())+1); + PL_strcpy(URLName, docURL->GetSpec()); + } + + /* invoke single-signon to get previously-used value of text */ + nsINetService *service; + nsresult res = nsServiceManager::GetService(kNetServiceCID, + kINetServiceIID, + (nsISupports **)&service); + if ((NS_OK == res) && (nsnull != service)) { + char* valueString = NULL; + res = service->SI_RestoreSignonData(URLName, name.ToNewCString(), &valueString); + NS_RELEASE(service); + if (valueString && *valueString) { + value = nsAutoString(valueString); + } else { + GetText(&value); + } + } + +#else + GetText(&value); +#endif + text->SetText(value, ignore); PRInt32 maxLength; nsresult result = GetMaxLength(&maxLength); diff --git a/layout/html/forms/src/nsFormFrame.cpp b/layout/html/forms/src/nsFormFrame.cpp index 9f42e145b96..820ea9a8a4a 100644 --- a/layout/html/forms/src/nsFormFrame.cpp +++ b/layout/html/forms/src/nsFormFrame.cpp @@ -56,6 +56,13 @@ #include "prmem.h" #include "prenv.h" +#ifdef SingleSignon +#include "proto.h" +#include "nsINetService.h" +#include "nsIServiceManager.h" +static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID); +static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID); +#endif //---------------------------------------------------------------------- static NS_DEFINE_IID(kIFormManagerIID, NS_IFORMMANAGER_IID); @@ -514,12 +521,37 @@ void nsFormFrame::ProcessAsURLEncoded(PRBool isPost, nsString& aData, nsIFormCon { nsString buf; PRBool firstTime = PR_TRUE; - PRUint32 numChildren = mFormControls.Count(); + +#ifdef SingleSignon +#define MAX_ARRAY_SIZE 50 + char* name_array[MAX_ARRAY_SIZE]; + char* value_array[MAX_ARRAY_SIZE]; + uint8 type_array[MAX_ARRAY_SIZE]; + LO_FormSubmitData submit; + + submit.value_cnt = 0; + submit.type_array = (PA_Block)type_array; + submit.name_array = (PA_Block)name_array; + submit.value_array = (PA_Block)value_array; + + /* get url name as ascii string */ + char *URLName; + nsIURL* docURL = nsnull; + nsIDocument* doc = nsnull; + mContent->GetDocument(doc); + if (nsnull != doc) { + docURL = doc->GetDocumentURL(); + NS_RELEASE(doc); + URLName = (char*)PR_Malloc(PL_strlen(docURL->GetSpec())+1); + PL_strcpy(URLName, docURL->GetSpec()); + } +#endif + // collect and encode the data from the children controls for (PRUint32 childX = 0; childX < numChildren; childX++) { - nsIFormControlFrame* child = (nsIFormControlFrame*) mFormControls.ElementAt(childX); - if (child && child->IsSuccessful(aFrame)) { + nsIFormControlFrame* child = (nsIFormControlFrame*) mFormControls.ElementAt(childX); + if (child && child->IsSuccessful(aFrame)) { PRInt32 numValues = 0; PRInt32 maxNumValues = child->GetMaxNumValues(); if (maxNumValues <= 0) { @@ -528,6 +560,20 @@ void nsFormFrame::ProcessAsURLEncoded(PRBool isPost, nsString& aData, nsIFormCon nsString* names = new nsString[maxNumValues]; nsString* values = new nsString[maxNumValues]; if (PR_TRUE == child->GetNamesValues(maxNumValues, numValues, values, names)) { +#ifdef SingleSignon + PRInt32 type; + child->GetType(&type); + if (type == NS_FORM_INPUT_PASSWORD) { + type_array[submit.value_cnt] = FORM_TYPE_PASSWORD; + } else { + type_array[submit.value_cnt] = FORM_TYPE_TEXT; + } + value_array[submit.value_cnt] = + values[0].ToNewCString(); + name_array[submit.value_cnt] = + names[0].ToNewCString(); + submit.value_cnt++; +#endif for (int valueX = 0; valueX < numValues; valueX++) { if (PR_TRUE == firstTime) { firstTime = PR_FALSE; @@ -548,6 +594,22 @@ void nsFormFrame::ProcessAsURLEncoded(PRBool isPost, nsString& aData, nsIFormCon } } +#ifdef SingleSignon + nsINetService *service; + nsresult res = nsServiceManager::GetService(kNetServiceCID, + kINetServiceIID, + (nsISupports **)&service); + if ((NS_OK == res) && (nsnull != service)) { + res = service->SI_RememberSignonData(URLName, &submit); + NS_RELEASE(service); + } + PR_FREEIF(URLName); + while (submit.value_cnt--) { + PR_FREEIF(name_array[submit.value_cnt]); + PR_FREEIF(value_array[submit.value_cnt]); + } +#endif + aData.SetLength(0); if (isPost) { char size[16]; diff --git a/layout/html/forms/src/nsTextControlFrame.cpp b/layout/html/forms/src/nsTextControlFrame.cpp index 58a5bdd1d82..ac94719cd0a 100644 --- a/layout/html/forms/src/nsTextControlFrame.cpp +++ b/layout/html/forms/src/nsTextControlFrame.cpp @@ -40,6 +40,16 @@ #include "nsIDOMHTMLInputElement.h" #include "nsIDOMHTMLTextAreaElement.h" +#ifdef SingleSignon +#include "nsIDocument.h" +#include "prmem.h" +#include "nsIURL.h" +#include "nsINetService.h" +#include "nsIServiceManager.h" +static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID); +static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID); +#endif + static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); static NS_DEFINE_IID(kTextCID, NS_TEXTFIELD_CID); static NS_DEFINE_IID(kTextAreaCID, NS_TEXTAREA_CID); @@ -331,13 +341,49 @@ nsTextControlFrame::PostCreateWidget(nsIPresContext* aPresContext, SetColors(*aPresContext); PRUint32 ignore; - nsAutoString value; - GetText(&value); nsITextAreaWidget* textArea = nsnull; nsITextWidget* text = nsnull; if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) { + +#ifdef SingleSignon + /* get name of text */ + nsAutoString name; + GetName(&name); + + /* get url name */ + char *URLName; + nsIURL* docURL = nsnull; + nsIDocument* doc = nsnull; + mContent->GetDocument(doc); + if (nsnull != doc) { + docURL = doc->GetDocumentURL(); + NS_RELEASE(doc); + URLName = (char*)PR_Malloc(PL_strlen(docURL->GetSpec())+1); + PL_strcpy(URLName, docURL->GetSpec()); + } + + /* invoke single-signon to get previously-used value of text */ + nsINetService *service; + nsresult res = nsServiceManager::GetService(kNetServiceCID, + kINetServiceIID, + (nsISupports **)&service); + if ((NS_OK == res) && (nsnull != service)) { + char* valueString = NULL; + res = service->SI_RestoreSignonData(URLName, name.ToNewCString(), &valueString); + NS_RELEASE(service); + if (valueString && *valueString) { + value = nsAutoString(valueString); + } else { + GetText(&value); + } + } + +#else + GetText(&value); +#endif + text->SetText(value, ignore); PRInt32 maxLength; nsresult result = GetMaxLength(&maxLength); diff --git a/network/module/nsINetService.h b/network/module/nsINetService.h index 419b7123bac..e8b8f383d5d 100644 --- a/network/module/nsINetService.h +++ b/network/module/nsINetService.h @@ -24,6 +24,10 @@ #include "nsIURL.h" #include "nsIStreamListener.h" +#ifdef SingleSignon +#include "lo_ele.h" +#endif + /* XXX: This should be moved to ns/xpcom/src/nserror.h */ #define NS_OK 0 #define NS_FALSE 1 @@ -99,6 +103,13 @@ struct nsINetService : public nsISupports */ NS_IMETHOD SetCookieString(nsIURL *aURL, const nsString& aCookie)=0; +#ifdef SingleSignon + NS_IMETHOD SI_RememberSignonData + (char* URLName, LO_FormSubmitData *submit)=0; + NS_IMETHOD SI_RestoreSignonData + (char* URLNAME, char* name, char** value)=0; +#endif + /** * Get the http proxy used for http transactions. * diff --git a/network/module/nsNetService.cpp b/network/module/nsNetService.cpp index bd2f99d2f7b..331b9dc54c8 100644 --- a/network/module/nsNetService.cpp +++ b/network/module/nsNetService.cpp @@ -582,6 +582,22 @@ nsNetlibService::SetCookieString(nsIURL *aURL, const nsString& aCookie) return NS_OK; } +#ifdef SingleSignon +NS_IMETHODIMP +nsNetlibService::SI_RememberSignonData + (char* URLName, LO_FormSubmitData *submit) { + ::SI_RememberSignonData(URLName, submit); + return NS_OK; +} + +NS_IMETHODIMP +nsNetlibService::SI_RestoreSignonData + (char* URLName, char* name, char** value) { + ::SI_RestoreSignonData(URLName, name, value); + return NS_OK; +} + +#endif NS_IMETHODIMP nsNetlibService::GetProxyHTTP(nsString& aProxyHTTP) { diff --git a/network/module/nsNetService.h b/network/module/nsNetService.h index 18ad30e84b0..1cb117c90e2 100644 --- a/network/module/nsNetService.h +++ b/network/module/nsNetService.h @@ -47,6 +47,13 @@ public: NS_IMETHOD GetCookieString(nsIURL *aURL, nsString& aCookie); NS_IMETHOD SetCookieString(nsIURL *aURL, const nsString& aCookie); +#ifdef SingleSignon + NS_IMETHOD SI_RememberSignonData + (char* URLName, LO_FormSubmitData *submit); + NS_IMETHOD SI_RestoreSignonData + (char* URLNAME, char* name, char** value); +#endif + NS_IMETHOD GetProxyHTTP(nsString& aProxyHTTP); NS_IMETHOD SetProxyHTTP(nsString& aProxyHTTP); NS_IMETHOD GetHTTPOneOne(PRBool& aOneOne);