bug 101562 - dont' use necko to unnecessarily create URIs just to load a string bundle. r=harishd, sr=attinasi

This commit is contained in:
alecf%netscape.com 2001-09-26 00:36:45 +00:00
Родитель c88b339267
Коммит 753cedd34e
12 изменённых файлов: 46 добавлений и 110 удалений

Просмотреть файл

@ -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<nsIIOService> pNetService(do_GetService(kIOServiceCID, &rv));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIURI> uri;
rv = pNetService->NewURI(aPropFileName, nsnull, getter_AddRefs(uri));
if (NS_SUCCEEDED(rv)) {
// Create bundle
nsCOMPtr<nsIStringBundleService> 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<nsIStringBundleService> stringService =
do_GetService(kStringBundleServiceCID, &rv);
if (NS_SUCCEEDED(rv))
rv = stringService->CreateBundle(aPropFileName, aBundle);
return rv;
}

Просмотреть файл

@ -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<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1");
if (!filePicker)

Просмотреть файл

@ -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<nsIStringBundle> bundle;
// Create a URL for the string resource file
// Create a bundle for the localization
nsCOMPtr<nsIIOService> pNetService(do_GetService(kIOServiceCID, &rv));
if (NS_SUCCEEDED(rv) && pNetService) {
nsCOMPtr<nsIURI> uri;
rv = pNetService->NewURI(aPropFileName, nsnull, getter_AddRefs(uri));
if (NS_SUCCEEDED(rv) && uri) {
// Create bundle
nsCOMPtr<nsIStringBundleService> 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<nsIStringBundleService> 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 {

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;

Просмотреть файл

@ -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<nsITextContent> text = do_QueryInterface(mTextContent);
result = text->SetText(prompt.get(), prompt.Length(), PR_TRUE);

Просмотреть файл

@ -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<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1");
if (!filePicker)

Просмотреть файл

@ -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<nsIStringBundle> bundle;
// Create a URL for the string resource file
// Create a bundle for the localization
nsCOMPtr<nsIIOService> pNetService(do_GetService(kIOServiceCID, &rv));
if (NS_SUCCEEDED(rv) && pNetService) {
nsCOMPtr<nsIURI> uri;
rv = pNetService->NewURI(aPropFileName, nsnull, getter_AddRefs(uri));
if (NS_SUCCEEDED(rv) && uri) {
// Create bundle
nsCOMPtr<nsIStringBundleService> 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<nsIStringBundleService> 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 {

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;

Просмотреть файл

@ -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<nsITextContent> text = do_QueryInterface(mTextContent);
result = text->SetText(prompt.get(), prompt.Length(), PR_TRUE);

Просмотреть файл

@ -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<nsIIOService> pNetService(do_GetService(kIOServiceCID, &rv));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIURI> uri;
rv = pNetService->NewURI(aPropFileName, nsnull, getter_AddRefs(uri));
if (NS_SUCCEEDED(rv)) {
// Create bundle
nsCOMPtr<nsIStringBundleService> 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<nsIStringBundleService> stringService =
do_GetService(kStringBundleServiceCID, &rv);
if (NS_SUCCEEDED(rv))
rv = stringService->CreateBundle(aPropFileName, aBundle);
return rv;
}