From 68c098cad57a83a47746031146f3adf3ad0fa5f1 Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Wed, 26 Sep 2001 00:36:45 +0000 Subject: [PATCH] bug 101562 - dont' use necko to unnecessarily create URIs just to load a string bundle. r=harishd, sr=attinasi --- htmlparser/src/nsParserMsgUtils.cpp | 28 ++++----------- layout/forms/nsFileControlFrame.cpp | 2 +- layout/forms/nsFormControlHelper.cpp | 36 ++++++------------- layout/forms/nsFormControlHelper.h | 2 +- layout/forms/nsGfxButtonControlFrame.cpp | 8 ++--- layout/forms/nsIsIndexFrame.cpp | 2 +- layout/html/forms/src/nsFileControlFrame.cpp | 2 +- layout/html/forms/src/nsFormControlHelper.cpp | 36 ++++++------------- layout/html/forms/src/nsFormControlHelper.h | 2 +- .../forms/src/nsGfxButtonControlFrame.cpp | 8 ++--- layout/html/forms/src/nsIsIndexFrame.cpp | 2 +- parser/htmlparser/src/nsParserMsgUtils.cpp | 28 ++++----------- 12 files changed, 46 insertions(+), 110 deletions(-) diff --git a/htmlparser/src/nsParserMsgUtils.cpp b/htmlparser/src/nsParserMsgUtils.cpp index 5ef5ad87bc2e..13ad5842d218 100644 --- a/htmlparser/src/nsParserMsgUtils.cpp +++ b/htmlparser/src/nsParserMsgUtils.cpp @@ -21,8 +21,6 @@ */ #include "nsIServiceManager.h" -#include "nsIIOService.h" -#include "nsIURI.h" #include "nsIStringBundle.h" #include "nsITextContent.h" #include "nsISupportsArray.h" @@ -30,7 +28,6 @@ #include "nsParserMsgUtils.h" #include "nsNetCID.h" -static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); // This code is derived from nsFormControlHelper::GetLocalizedString() @@ -40,27 +37,14 @@ static nsresult GetBundle(const char * aPropFileName, nsIStringBundle **aBundle) NS_ENSURE_ARG_POINTER(aPropFileName); NS_ENSURE_ARG_POINTER(aBundle); - // Create a URL for the string resource file // Create a bundle for the localization nsresult rv; - nsCOMPtr pNetService(do_GetService(kIOServiceCID, &rv)); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr uri; - rv = pNetService->NewURI(aPropFileName, nsnull, getter_AddRefs(uri)); - if (NS_SUCCEEDED(rv)) { - - // Create bundle - nsCOMPtr stringService = - do_GetService(kStringBundleServiceCID, &rv); - if (NS_SUCCEEDED(rv)) { - nsXPIDLCString spec; - rv = uri->GetSpec(getter_Copies(spec)); - if (NS_SUCCEEDED(rv) && spec) { - rv = stringService->CreateBundle(spec, aBundle); - } - } - } - } + + nsCOMPtr stringService = + do_GetService(kStringBundleServiceCID, &rv); + if (NS_SUCCEEDED(rv)) + rv = stringService->CreateBundle(aPropFileName, aBundle); + return rv; } diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp index 56798d88eea2..ef14f1906272 100644 --- a/layout/forms/nsFileControlFrame.cpp +++ b/layout/forms/nsFileControlFrame.cpp @@ -285,7 +285,7 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent) // Get Loc title nsString title; nsFormControlHelper::GetLocalizedString(nsFormControlHelper::GetHTMLPropertiesFileName(), - "FileUpload", title); + NS_LITERAL_STRING("FileUpload").get(), title); nsCOMPtr filePicker = do_CreateInstance("@mozilla.org/filepicker;1"); if (!filePicker) diff --git a/layout/forms/nsFormControlHelper.cpp b/layout/forms/nsFormControlHelper.cpp index 2b3519c65606..d1b62abf52d0 100644 --- a/layout/forms/nsFormControlHelper.cpp +++ b/layout/forms/nsFormControlHelper.cpp @@ -57,14 +57,11 @@ // Needed for Localization #include "nsIServiceManager.h" -#include "nsIIOService.h" -#include "nsIURI.h" #include "nsIStringBundle.h" #include "nsITextContent.h" #include "nsISupportsArray.h" #include "nsXPIDLString.h" -static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); // done I10N @@ -882,37 +879,24 @@ nsFormControlHelper::GetInputElementValue(nsIContent* aContent, nsString* aText, // Return localised string for resource string (e.g. "Submit" -> "Submit Query") // This code is derived from nsBookmarksService::Init() and cookie_Localize() nsresult -nsFormControlHelper::GetLocalizedString(const char * aPropFileName, const char* aKey, nsString& oVal) +nsFormControlHelper::GetLocalizedString(const char * aPropFileName, const PRUnichar* aKey, nsString& oVal) { + NS_ENSURE_ARG_POINTER(aKey); + nsresult rv; + nsCOMPtr bundle; - // Create a URL for the string resource file // Create a bundle for the localization - nsCOMPtr pNetService(do_GetService(kIOServiceCID, &rv)); - if (NS_SUCCEEDED(rv) && pNetService) { - nsCOMPtr uri; - rv = pNetService->NewURI(aPropFileName, nsnull, getter_AddRefs(uri)); - if (NS_SUCCEEDED(rv) && uri) { - - // Create bundle - nsCOMPtr stringService = - do_GetService(kStringBundleServiceCID, &rv); - if (NS_SUCCEEDED(rv) && stringService) { - nsXPIDLCString spec; - rv = uri->GetSpec(getter_Copies(spec)); - if (NS_SUCCEEDED(rv) && spec) { - rv = stringService->CreateBundle(spec, getter_AddRefs(bundle)); - } - } - } - } + nsCOMPtr stringService = + do_GetService(kStringBundleServiceCID, &rv); + if (NS_SUCCEEDED(rv) && stringService) + rv = stringService->CreateBundle(aPropFileName, getter_AddRefs(bundle)); // Determine default label from string bundle - if (NS_SUCCEEDED(rv) && bundle && aKey) { + if (NS_SUCCEEDED(rv) && bundle) { nsXPIDLString valUni; - nsAutoString key; key.AssignWithConversion(aKey); - rv = bundle->GetStringFromName(key.get(), getter_Copies(valUni)); + rv = bundle->GetStringFromName(aKey, getter_Copies(valUni)); if (NS_SUCCEEDED(rv) && valUni) { oVal.Assign(valUni); } else { diff --git a/layout/forms/nsFormControlHelper.h b/layout/forms/nsFormControlHelper.h index dfc6eb691078..cfa66eb6187d 100644 --- a/layout/forms/nsFormControlHelper.h +++ b/layout/forms/nsFormControlHelper.h @@ -178,7 +178,7 @@ public: static nsresult GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap& aWrapProp); // Localization Helper - static nsresult GetLocalizedString(const char * aPropFileName, const char* aKey, nsString& oVal); + static nsresult GetLocalizedString(const char * aPropFileName, const PRUnichar* aKey, nsString& oVal); static const char * GetHTMLPropertiesFileName() { return FORM_PROPERTIES; } static nsresult GetDisabled(nsIContent* aContent, PRBool* oIsDisabled); diff --git a/layout/forms/nsGfxButtonControlFrame.cpp b/layout/forms/nsGfxButtonControlFrame.cpp index 23ded4a89c30..b35a994ed635 100644 --- a/layout/forms/nsGfxButtonControlFrame.cpp +++ b/layout/forms/nsGfxButtonControlFrame.cpp @@ -534,16 +534,16 @@ nsGfxButtonControlFrame::GetDefaultLabel(nsString& aString) PRInt32 type; GetType(&type); if (IsReset(type)) { - rv = nsFormControlHelper::GetLocalizedString(propname, "Reset", aString); + rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Reset").get(), aString); } else if (IsSubmit(type)) { - rv = nsFormControlHelper::GetLocalizedString(propname, "Submit", aString); + rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Submit").get(), aString); } else if (IsBrowse(type)) { - rv = nsFormControlHelper::GetLocalizedString(propname, "Browse", aString); + rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Browse").get(), aString); } else { - aString.AssignWithConversion(" "); + aString.Assign(NS_LITERAL_STRING(" ")); rv = NS_OK; } return rv; diff --git a/layout/forms/nsIsIndexFrame.cpp b/layout/forms/nsIsIndexFrame.cpp index f2c4265adee4..e983a1f999a2 100644 --- a/layout/forms/nsIsIndexFrame.cpp +++ b/layout/forms/nsIsIndexFrame.cpp @@ -146,7 +146,7 @@ nsIsIndexFrame::UpdatePromptLabel() // because the value is localized for non-english platforms, thus // it might not be the string "This is a searchable index. Enter search keywords: " result = nsFormControlHelper::GetLocalizedString(nsFormControlHelper::GetHTMLPropertiesFileName(), - "IsIndexPrompt", prompt); + NS_LITERAL_STRING("IsIndexPrompt").get(), prompt); } nsCOMPtr text = do_QueryInterface(mTextContent); result = text->SetText(prompt.get(), prompt.Length(), PR_TRUE); diff --git a/layout/html/forms/src/nsFileControlFrame.cpp b/layout/html/forms/src/nsFileControlFrame.cpp index 56798d88eea2..ef14f1906272 100644 --- a/layout/html/forms/src/nsFileControlFrame.cpp +++ b/layout/html/forms/src/nsFileControlFrame.cpp @@ -285,7 +285,7 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent) // Get Loc title nsString title; nsFormControlHelper::GetLocalizedString(nsFormControlHelper::GetHTMLPropertiesFileName(), - "FileUpload", title); + NS_LITERAL_STRING("FileUpload").get(), title); nsCOMPtr filePicker = do_CreateInstance("@mozilla.org/filepicker;1"); if (!filePicker) diff --git a/layout/html/forms/src/nsFormControlHelper.cpp b/layout/html/forms/src/nsFormControlHelper.cpp index 2b3519c65606..d1b62abf52d0 100644 --- a/layout/html/forms/src/nsFormControlHelper.cpp +++ b/layout/html/forms/src/nsFormControlHelper.cpp @@ -57,14 +57,11 @@ // Needed for Localization #include "nsIServiceManager.h" -#include "nsIIOService.h" -#include "nsIURI.h" #include "nsIStringBundle.h" #include "nsITextContent.h" #include "nsISupportsArray.h" #include "nsXPIDLString.h" -static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); // done I10N @@ -882,37 +879,24 @@ nsFormControlHelper::GetInputElementValue(nsIContent* aContent, nsString* aText, // Return localised string for resource string (e.g. "Submit" -> "Submit Query") // This code is derived from nsBookmarksService::Init() and cookie_Localize() nsresult -nsFormControlHelper::GetLocalizedString(const char * aPropFileName, const char* aKey, nsString& oVal) +nsFormControlHelper::GetLocalizedString(const char * aPropFileName, const PRUnichar* aKey, nsString& oVal) { + NS_ENSURE_ARG_POINTER(aKey); + nsresult rv; + nsCOMPtr bundle; - // Create a URL for the string resource file // Create a bundle for the localization - nsCOMPtr pNetService(do_GetService(kIOServiceCID, &rv)); - if (NS_SUCCEEDED(rv) && pNetService) { - nsCOMPtr uri; - rv = pNetService->NewURI(aPropFileName, nsnull, getter_AddRefs(uri)); - if (NS_SUCCEEDED(rv) && uri) { - - // Create bundle - nsCOMPtr stringService = - do_GetService(kStringBundleServiceCID, &rv); - if (NS_SUCCEEDED(rv) && stringService) { - nsXPIDLCString spec; - rv = uri->GetSpec(getter_Copies(spec)); - if (NS_SUCCEEDED(rv) && spec) { - rv = stringService->CreateBundle(spec, getter_AddRefs(bundle)); - } - } - } - } + nsCOMPtr stringService = + do_GetService(kStringBundleServiceCID, &rv); + if (NS_SUCCEEDED(rv) && stringService) + rv = stringService->CreateBundle(aPropFileName, getter_AddRefs(bundle)); // Determine default label from string bundle - if (NS_SUCCEEDED(rv) && bundle && aKey) { + if (NS_SUCCEEDED(rv) && bundle) { nsXPIDLString valUni; - nsAutoString key; key.AssignWithConversion(aKey); - rv = bundle->GetStringFromName(key.get(), getter_Copies(valUni)); + rv = bundle->GetStringFromName(aKey, getter_Copies(valUni)); if (NS_SUCCEEDED(rv) && valUni) { oVal.Assign(valUni); } else { diff --git a/layout/html/forms/src/nsFormControlHelper.h b/layout/html/forms/src/nsFormControlHelper.h index dfc6eb691078..cfa66eb6187d 100644 --- a/layout/html/forms/src/nsFormControlHelper.h +++ b/layout/html/forms/src/nsFormControlHelper.h @@ -178,7 +178,7 @@ public: static nsresult GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap& aWrapProp); // Localization Helper - static nsresult GetLocalizedString(const char * aPropFileName, const char* aKey, nsString& oVal); + static nsresult GetLocalizedString(const char * aPropFileName, const PRUnichar* aKey, nsString& oVal); static const char * GetHTMLPropertiesFileName() { return FORM_PROPERTIES; } static nsresult GetDisabled(nsIContent* aContent, PRBool* oIsDisabled); diff --git a/layout/html/forms/src/nsGfxButtonControlFrame.cpp b/layout/html/forms/src/nsGfxButtonControlFrame.cpp index 23ded4a89c30..b35a994ed635 100644 --- a/layout/html/forms/src/nsGfxButtonControlFrame.cpp +++ b/layout/html/forms/src/nsGfxButtonControlFrame.cpp @@ -534,16 +534,16 @@ nsGfxButtonControlFrame::GetDefaultLabel(nsString& aString) PRInt32 type; GetType(&type); if (IsReset(type)) { - rv = nsFormControlHelper::GetLocalizedString(propname, "Reset", aString); + rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Reset").get(), aString); } else if (IsSubmit(type)) { - rv = nsFormControlHelper::GetLocalizedString(propname, "Submit", aString); + rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Submit").get(), aString); } else if (IsBrowse(type)) { - rv = nsFormControlHelper::GetLocalizedString(propname, "Browse", aString); + rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Browse").get(), aString); } else { - aString.AssignWithConversion(" "); + aString.Assign(NS_LITERAL_STRING(" ")); rv = NS_OK; } return rv; diff --git a/layout/html/forms/src/nsIsIndexFrame.cpp b/layout/html/forms/src/nsIsIndexFrame.cpp index f2c4265adee4..e983a1f999a2 100644 --- a/layout/html/forms/src/nsIsIndexFrame.cpp +++ b/layout/html/forms/src/nsIsIndexFrame.cpp @@ -146,7 +146,7 @@ nsIsIndexFrame::UpdatePromptLabel() // because the value is localized for non-english platforms, thus // it might not be the string "This is a searchable index. Enter search keywords: " result = nsFormControlHelper::GetLocalizedString(nsFormControlHelper::GetHTMLPropertiesFileName(), - "IsIndexPrompt", prompt); + NS_LITERAL_STRING("IsIndexPrompt").get(), prompt); } nsCOMPtr text = do_QueryInterface(mTextContent); result = text->SetText(prompt.get(), prompt.Length(), PR_TRUE); diff --git a/parser/htmlparser/src/nsParserMsgUtils.cpp b/parser/htmlparser/src/nsParserMsgUtils.cpp index 5ef5ad87bc2e..13ad5842d218 100644 --- a/parser/htmlparser/src/nsParserMsgUtils.cpp +++ b/parser/htmlparser/src/nsParserMsgUtils.cpp @@ -21,8 +21,6 @@ */ #include "nsIServiceManager.h" -#include "nsIIOService.h" -#include "nsIURI.h" #include "nsIStringBundle.h" #include "nsITextContent.h" #include "nsISupportsArray.h" @@ -30,7 +28,6 @@ #include "nsParserMsgUtils.h" #include "nsNetCID.h" -static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); // This code is derived from nsFormControlHelper::GetLocalizedString() @@ -40,27 +37,14 @@ static nsresult GetBundle(const char * aPropFileName, nsIStringBundle **aBundle) NS_ENSURE_ARG_POINTER(aPropFileName); NS_ENSURE_ARG_POINTER(aBundle); - // Create a URL for the string resource file // Create a bundle for the localization nsresult rv; - nsCOMPtr pNetService(do_GetService(kIOServiceCID, &rv)); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr uri; - rv = pNetService->NewURI(aPropFileName, nsnull, getter_AddRefs(uri)); - if (NS_SUCCEEDED(rv)) { - - // Create bundle - nsCOMPtr stringService = - do_GetService(kStringBundleServiceCID, &rv); - if (NS_SUCCEEDED(rv)) { - nsXPIDLCString spec; - rv = uri->GetSpec(getter_Copies(spec)); - if (NS_SUCCEEDED(rv) && spec) { - rv = stringService->CreateBundle(spec, aBundle); - } - } - } - } + + nsCOMPtr stringService = + do_GetService(kStringBundleServiceCID, &rv); + if (NS_SUCCEEDED(rv)) + rv = stringService->CreateBundle(aPropFileName, aBundle); + return rv; }