From 8bf4f6454a201baabf41b9371cf3d1984f58c3ef Mon Sep 17 00:00:00 2001 From: "dp%netscape.com" Date: Tue, 28 Aug 2001 22:32:03 +0000 Subject: [PATCH] bug #14889 Lazy loading wallet dll r=morse,gagan sr=jband a=asa --- .../content/public/nsIFormSubmitObserver.h | 2 + extensions/wallet/src/nsWalletFactory.cpp | 5 ++- extensions/wallet/src/nsWalletService.cpp | 42 +++++++++++++++++++ extensions/wallet/src/nsWalletService.h | 16 ++++++- .../html/forms/public/nsIFormSubmitObserver.h | 2 + layout/html/forms/src/nsFormFrame.cpp | 26 +++++++++++- layout/html/forms/src/nsFormFrame.h | 6 +++ xpfe/bootstrap/nsAppRunner.cpp | 6 --- 8 files changed, 95 insertions(+), 10 deletions(-) diff --git a/content/html/content/public/nsIFormSubmitObserver.h b/content/html/content/public/nsIFormSubmitObserver.h index cda297c4069..31ace3ed202 100644 --- a/content/html/content/public/nsIFormSubmitObserver.h +++ b/content/html/content/public/nsIFormSubmitObserver.h @@ -42,6 +42,8 @@ class nsIURI; { 0xa6cf9106, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } #define NS_FORMSUBMIT_SUBJECT "formsubmit" +#define NS_FIRST_FORMSUBMIT_CATEGORY "firstformsubmit" +#define NS_PASSWORDMANAGER_CATEGORY "passwordmanager" class nsIFormSubmitObserver : public nsISupports { public: diff --git a/extensions/wallet/src/nsWalletFactory.cpp b/extensions/wallet/src/nsWalletFactory.cpp index 4edf7de7c8f..c9c011b5a51 100644 --- a/extensions/wallet/src/nsWalletFactory.cpp +++ b/extensions/wallet/src/nsWalletFactory.cpp @@ -35,7 +35,10 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSingleSignOnPrompt, Init) // The list of components we register static nsModuleComponentInfo components[] = { { NS_WALLETSERVICE_CLASSNAME, NS_WALLETSERVICE_CID, - NS_WALLETSERVICE_CONTRACTID, nsWalletlibServiceConstructor }, + NS_WALLETSERVICE_CONTRACTID, nsWalletlibServiceConstructor, + nsWalletlibService::RegisterProc, + nsWalletlibService::UnregisterProc + }, { NS_PASSWORDMANAGER_CLASSNAME, NS_PASSWORDMANAGER_CID, NS_PASSWORDMANAGER_CONTRACTID, nsPasswordManagerConstructor }, { NS_SINGLESIGNONPROMPT_CLASSNAME, NS_SINGLESIGNONPROMPT_CID, diff --git a/extensions/wallet/src/nsWalletService.cpp b/extensions/wallet/src/nsWalletService.cpp index 975899a488e..cf419b05e4f 100644 --- a/extensions/wallet/src/nsWalletService.cpp +++ b/extensions/wallet/src/nsWalletService.cpp @@ -47,6 +47,7 @@ #include "nsIWindowWatcher.h" #include "nsIWebProgress.h" #include "nsXPIDLString.h" +#include "nsICategoryManager.h" // for making the leap from nsIDOMWindowInternal -> nsIPresShell #include "nsIScriptGlobalObject.h" @@ -213,6 +214,47 @@ NS_IMETHODIMP nsWalletlibService::Notify(nsIContent* formNode, nsIDOMWindowInter return NS_OK; } +NS_IMETHODIMP +nsWalletlibService::RegisterProc(nsIComponentManager *aCompMgr, + nsIFile *aPath, + const char *registryLocation, + const char *componentType, + const nsModuleComponentInfo *info) +{ + // Register ourselves into the NS_CATEGORY_HTTP_STARTUP + nsresult rv; + nsCOMPtr catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + nsXPIDLCString prevEntry; + catman->AddCategoryEntry(NS_FIRST_FORMSUBMIT_CATEGORY, "Form Manager", NS_WALLETSERVICE_CONTRACTID, + PR_TRUE, PR_TRUE, getter_Copies(prevEntry)); + + catman->AddCategoryEntry(NS_PASSWORDMANAGER_CATEGORY, "Password Manager", NS_WALLETSERVICE_CONTRACTID, + PR_TRUE, PR_TRUE, getter_Copies(prevEntry)); + return NS_OK; +} + +NS_IMETHODIMP +nsWalletlibService::UnregisterProc(nsIComponentManager *aCompMgr, + nsIFile *aPath, + const char *registryLocation, + const nsModuleComponentInfo *info) +{ + nsresult rv; + nsCOMPtr catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + catman->DeleteCategoryEntry(NS_FIRST_FORMSUBMIT_CATEGORY, + NS_WALLETSERVICE_CONTRACTID, PR_TRUE); + + catman->DeleteCategoryEntry(NS_PASSWORDMANAGER_CATEGORY, + NS_WALLETSERVICE_CONTRACTID, PR_TRUE); + + // Return value is not used from this function. + return NS_OK; +} + nsresult nsWalletlibService::Init() { nsresult rv; diff --git a/extensions/wallet/src/nsWalletService.h b/extensions/wallet/src/nsWalletService.h index 5226d126acc..835b9cdee25 100644 --- a/extensions/wallet/src/nsWalletService.h +++ b/extensions/wallet/src/nsWalletService.h @@ -32,6 +32,8 @@ #include "nsIDOMWindowInternal.h" #include "nsIURI.h" #include "nsIWebProgressListener.h" +#include "nsIComponentManager.h" +#include "nsIGenericFactory.h" class nsWalletlibService : public nsIWalletService, public nsIObserver, @@ -53,6 +55,18 @@ public: // NS_DECL_NSIFORMSUBMITOBSERVER NS_IMETHOD Notify(nsIContent* formNode, nsIDOMWindowInternal* window, nsIURI* actionURL, PRBool* cancelSubmit); + + // {Un}Register proc that do category {Un}Registration + static NS_METHOD RegisterProc(nsIComponentManager *aCompMgr, + nsIFile *aPath, + const char *registryLocation, + const char *componentType, + const nsModuleComponentInfo *info); + static NS_METHOD UnregisterProc(nsIComponentManager *aCompMgr, + nsIFile *aPath, + const char *registryLocation, + const nsModuleComponentInfo *info); + protected: virtual ~nsWalletlibService(); @@ -71,7 +85,7 @@ public: virtual ~nsSingleSignOnPrompt() {} nsresult Init(); - + protected: nsCOMPtr mPrompt; static PRBool mgRegisteredObserver; diff --git a/layout/html/forms/public/nsIFormSubmitObserver.h b/layout/html/forms/public/nsIFormSubmitObserver.h index cda297c4069..31ace3ed202 100644 --- a/layout/html/forms/public/nsIFormSubmitObserver.h +++ b/layout/html/forms/public/nsIFormSubmitObserver.h @@ -42,6 +42,8 @@ class nsIURI; { 0xa6cf9106, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } #define NS_FORMSUBMIT_SUBJECT "formsubmit" +#define NS_FIRST_FORMSUBMIT_CATEGORY "firstformsubmit" +#define NS_PASSWORDMANAGER_CATEGORY "passwordmanager" class nsIFormSubmitObserver : public nsISupports { public: diff --git a/layout/html/forms/src/nsFormFrame.cpp b/layout/html/forms/src/nsFormFrame.cpp index c6eb54f4ff6..0a3f66266f1 100644 --- a/layout/html/forms/src/nsFormFrame.cpp +++ b/layout/html/forms/src/nsFormFrame.cpp @@ -126,6 +126,11 @@ static NS_DEFINE_CID(kUBidiUtilCID, NS_UNICHARBIDIUTIL_CID); #endif //end +// Marks if the first form is submitted or not. Once we submit the first +// form, this will become PR_TRUE +PRBool nsFormFrame::gFirstFormSubmitted = PR_FALSE; +PRBool nsFormFrame::gInitPasswordManager = PR_FALSE; + NS_IMETHODIMP nsFormFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr) { @@ -444,6 +449,16 @@ void nsFormFrame::DoDefaultSelection(nsIPresContext* aPresContext, void nsFormFrame::AddFormControlFrame(nsIPresContext* aPresContext, nsIFormControlFrame& aFrame) { + PRInt32 type; + aFrame.GetType(&type); + if (!gInitPasswordManager && type == NS_FORM_INPUT_PASSWORD) { + // Initialize the password manager category + gInitPasswordManager = PR_TRUE; + NS_CreateServicesFromCategory(NS_PASSWORDMANAGER_CATEGORY, + NS_STATIC_CAST(nsISupports*,NS_STATIC_CAST(void*,this)), + NS_ConvertASCIItoUCS2(NS_PASSWORDMANAGER_CATEGORY).get()); + } + // Add this control to the list // Sort by content ID - this assures we submit in document order (bug 18728) PRInt32 i = mFormControls.Count(); @@ -480,8 +495,6 @@ void nsFormFrame::AddFormControlFrame(nsIPresContext* aPresContext, nsIFormContr // determine which radio buttons belong to which radio groups, unnamed radio buttons // don't go into any group since they can't be submitted. - PRInt32 type; - aFrame.GetType(&type); if (NS_FORM_INPUT_RADIO == type) { nsGfxRadioControlFrame* radioFrame = (nsGfxRadioControlFrame*)&aFrame; // gets the name of the radio group and the group @@ -847,6 +860,15 @@ nsFormFrame::OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame) result = NS_MakeAbsoluteURI(absURLSpec, href, docURL); if (NS_FAILED(result)) return result; + // If this is the first form, bring alive the first form submit + // category observers + if (!gFirstFormSubmitted) { + gFirstFormSubmitted = PR_TRUE; + NS_CreateServicesFromCategory(NS_FIRST_FORMSUBMIT_CATEGORY, + NS_STATIC_CAST(nsISupports*,NS_STATIC_CAST(void*,this)), + NS_ConvertASCIItoUCS2(NS_FIRST_FORMSUBMIT_CATEGORY).get()); + } + // Notify observers that the form is being submitted. result = NS_OK; nsCOMPtr service = diff --git a/layout/html/forms/src/nsFormFrame.h b/layout/html/forms/src/nsFormFrame.h index e41578dd849..6c9884a1378 100644 --- a/layout/html/forms/src/nsFormFrame.h +++ b/layout/html/forms/src/nsFormFrame.h @@ -82,6 +82,12 @@ public: NS_IMETHOD GetTarget(nsString* aTarget); NS_IMETHOD GetAction(nsString* aAction); + // Detection of first form to notify observers + static PRBool gFirstFormSubmitted; + // Detection of first password field to notify any password manager + // style modules + static PRBool gInitPasswordManager; + // static helper functions for nsIFormControls static PRBool GetDisabled(nsIFrame* aChildFrame, nsIContent* aContent = 0); diff --git a/xpfe/bootstrap/nsAppRunner.cpp b/xpfe/bootstrap/nsAppRunner.cpp index 206c3508ac2..f524536a4f7 100644 --- a/xpfe/bootstrap/nsAppRunner.cpp +++ b/xpfe/bootstrap/nsAppRunner.cpp @@ -44,7 +44,6 @@ #include "nsIDirectoryService.h" #include "nsAppDirectoryServiceDefs.h" #include "nsSpecialSystemDirectory.h" -#include "nsIWalletService.h" #include "nsIWindowMediator.h" #include "nsIDOMWindowInternal.h" #include "nsIClipboard.h" @@ -1375,11 +1374,6 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) NS_ASSERTION(NS_SUCCEEDED(rv), "failed to Ensure1Window"); if (NS_FAILED(rv)) return rv; - // Startup wallet service so it registers for notifications - NS_TIMELINE_ENTER("walletService"); - nsCOMPtr walletService(do_GetService(NS_WALLETSERVICE_CONTRACTID, &rv)); - NS_TIMELINE_LEAVE("walletService"); - // From this point on, should be true appShell->SetQuitOnLastWindowClosing(PR_TRUE); // Start main event loop