diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 5a931af4687..7a15e6495d7 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -469,6 +469,9 @@ public: eXBL_PROPERTIES, eXUL_PROPERTIES, eLAYOUT_PROPERTIES, + eFORMS_PROPERTIES, + ePRINTING_PROPERTIES, + eDOM_PROPERTIES, PropertiesFile_COUNT }; static nsresult ReportToConsole(PropertiesFile aFile, @@ -482,6 +485,24 @@ public: PRUint32 aErrorFlags, const char *aCategory); + /** + * Get the localized string named |aKey| in properties file |aFile|. + */ + static nsresult GetLocalizedString(PropertiesFile aFile, + const char* aKey, + nsString& aResult); + + /** + * Fill (with the parameters given) the localized string named |aKey| in + * properties file |aFile|. + */ + static nsresult FormatLocalizedString(PropertiesFile aFile, + const char* aKey, + const PRUnichar **aParams, + PRUint32 aParamsLength, + nsString& aResult); + + private: static nsresult doReparentContentWrapper(nsIContent *aChild, nsIDocument *aNewDocument, @@ -489,6 +510,8 @@ private: JSContext *cx, JSObject *parent_obj); + static nsresult EnsureStringBundle(PropertiesFile aFile); + static nsIDOMScriptObjectFactory *sDOMScriptObjectFactory; diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 1c35d8c9b2e..18125e3ead5 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -2141,14 +2141,72 @@ nsCxPusher::Pop() mScriptIsRunning = PR_FALSE; } -static const char gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT][48] = { +static const char gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT][56] = { // Must line up with the enum values in |PropertiesFile| enum. "chrome://global/locale/css.properties", "chrome://global/locale/xbl.properties", "chrome://global/locale/xul.properties", - "chrome://global/locale/layout_errors.properties" + "chrome://global/locale/layout_errors.properties", + "chrome://communicator/locale/layout/HtmlForm.properties", + "chrome://global/locale/printing.properties", + "chrome://communicator/locale/dom/dom.properties" }; +/* static */ nsresult +nsContentUtils::EnsureStringBundle(PropertiesFile aFile) +{ + if (!sStringBundles[aFile]) { + if (!sStringBundleService) { + nsresult rv = + CallGetService(NS_STRINGBUNDLE_CONTRACTID, &sStringBundleService); + NS_ENSURE_SUCCESS(rv, rv); + } + nsIStringBundle *bundle; + nsresult rv = + sStringBundleService->CreateBundle(gPropertiesFiles[aFile], &bundle); + NS_ENSURE_SUCCESS(rv, rv); + sStringBundles[aFile] = bundle; // transfer ownership + } + return NS_OK; +} + +/* static */ +nsresult nsContentUtils::GetLocalizedString(PropertiesFile aFile, + const char* aKey, + nsString& aResult) +{ + nsresult rv = EnsureStringBundle(aFile); + NS_ENSURE_SUCCESS(rv, rv); + nsIStringBundle *bundle = sStringBundles[aFile]; + + nsXPIDLString result; + rv = bundle->GetStringFromName(NS_ConvertASCIItoUCS2(aKey).get(), + getter_Copies(result)); + NS_ENSURE_SUCCESS(rv, rv); + aResult = result; + return NS_OK; +} + +/* static */ +nsresult nsContentUtils::FormatLocalizedString(PropertiesFile aFile, + const char* aKey, + const PRUnichar **aParams, + PRUint32 aParamsLength, + nsString& aResult) +{ + nsresult rv = EnsureStringBundle(aFile); + NS_ENSURE_SUCCESS(rv, rv); + nsIStringBundle *bundle = sStringBundles[aFile]; + + nsXPIDLString result; + rv = bundle->FormatStringFromName(NS_ConvertASCIItoUCS2(aKey).get(), + aParams, aParamsLength, + getter_Copies(result)); + NS_ENSURE_SUCCESS(rv, rv); + aResult = result; + return NS_OK; +} + /* static */ nsresult nsContentUtils::ReportToConsole(PropertiesFile aFile, const char *aMessageName, @@ -2162,25 +2220,14 @@ nsContentUtils::ReportToConsole(PropertiesFile aFile, const char *aCategory) { nsresult rv; - - nsIStringBundle *bundle = sStringBundles[aFile]; - if (!bundle) { - if (!sStringBundleService) { - rv = CallGetService(NS_STRINGBUNDLE_CONTRACTID, &sStringBundleService); - NS_ENSURE_SUCCESS(rv, rv); - } - if (!sConsoleService) { // only need to bother null-checking here - rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &sConsoleService); - NS_ENSURE_SUCCESS(rv, rv); - } - sStringBundleService->CreateBundle(gPropertiesFiles[aFile], &bundle); - sStringBundles[aFile] = bundle; // transfer ownership + if (!sConsoleService) { // only need to bother null-checking here + rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &sConsoleService); + NS_ENSURE_SUCCESS(rv, rv); } - nsXPIDLString errorText; - rv = bundle->FormatStringFromName(NS_ConvertASCIItoUCS2(aMessageName).get(), - aParams, aParamsLength, - getter_Copies(errorText)); + nsString errorText; + rv = FormatLocalizedString(aFile, aMessageName, aParams, aParamsLength, + errorText); NS_ENSURE_SUCCESS(rv, rv); nsCAutoString spec; diff --git a/content/html/content/src/nsFormSubmission.cpp b/content/html/content/src/nsFormSubmission.cpp index bc494bb771b..8fcc5b7b1f8 100644 --- a/content/html/content/src/nsFormSubmission.cpp +++ b/content/html/content/src/nsFormSubmission.cpp @@ -223,7 +223,7 @@ public: */ static nsresult SendJSWarning(nsIHTMLContent* aContent, - const nsAFlatString& aWarningName); + const char* aWarningName); /** * Send a warning to the JS console * @param aContent the content the warning is about @@ -233,7 +233,7 @@ SendJSWarning(nsIHTMLContent* aContent, */ static nsresult SendJSWarning(nsIHTMLContent* aContent, - const nsAFlatString& aWarningName, + const char* aWarningName, const nsAFlatString& aWarningArg1); /** * Send a warning to the JS console @@ -245,7 +245,7 @@ SendJSWarning(nsIHTMLContent* aContent, */ static nsresult SendJSWarning(nsIHTMLContent* aContent, - const nsAFlatString& aWarningName, + const char* aWarningName, const PRUnichar** aWarningArgs, PRUint32 aWarningArgsLen); @@ -339,7 +339,7 @@ nsFSURLEncoded::AddNameValuePair(nsIDOMHTMLElement* aSource, nsCOMPtr formControl = do_QueryInterface(aSource); if (formControl->GetType() == NS_FORM_INPUT_FILE) { nsCOMPtr content = do_QueryInterface(aSource); - SendJSWarning(content, NS_LITERAL_STRING("ForgotFileEnctypeWarning")); + SendJSWarning(content, "ForgotFileEnctypeWarning"); mWarnedFileControl = PR_TRUE; } } @@ -1072,14 +1072,14 @@ NS_INTERFACE_MAP_END static nsresult SendJSWarning(nsIHTMLContent* aContent, - const nsAFlatString& aWarningName) + const char* aWarningName) { return SendJSWarning(aContent, aWarningName, nsnull, 0); } static nsresult SendJSWarning(nsIHTMLContent* aContent, - const nsAFlatString& aWarningName, + const char* aWarningName, const nsAFlatString& aWarningArg1) { const PRUnichar* formatStrings[1] = { aWarningArg1.get() }; @@ -1088,65 +1088,25 @@ SendJSWarning(nsIHTMLContent* aContent, static nsresult SendJSWarning(nsIHTMLContent* aContent, - const nsAFlatString& aWarningName, + const char* aWarningName, const PRUnichar** aWarningArgs, PRUint32 aWarningArgsLen) { - nsresult rv = NS_OK; - - // // Get the document URL to use as the filename - // - nsCAutoString documentURISpec; nsIDocument* document = aContent->GetDocument(); + nsIURI *documentURI = nsnull; if (document) { - nsIURI *documentURI = document->GetDocumentURI(); + documentURI = document->GetDocumentURI(); NS_ENSURE_TRUE(documentURI, NS_ERROR_UNEXPECTED); - documentURI->GetPath(documentURISpec); } - // - // Get the error string - // - nsCOMPtr bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr bundle; - rv = bundleService->CreateBundle( - "chrome://communicator/locale/layout/HtmlForm.properties", - getter_AddRefs(bundle)); - NS_ENSURE_SUCCESS(rv, rv); - - nsXPIDLString warningStr; - if (aWarningArgsLen > 0) { - bundle->FormatStringFromName(aWarningName.get(), - aWarningArgs, aWarningArgsLen, - getter_Copies(warningStr)); - } else { - bundle->GetStringFromName(aWarningName.get(), getter_Copies(warningStr)); - } - - // - // Create the error - // - nsCOMPtr - scriptError(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID)); - NS_ENSURE_TRUE(scriptError, NS_ERROR_UNEXPECTED); - - rv = scriptError->Init(warningStr.get(), - NS_ConvertUTF8toUTF16(documentURISpec).get(), - nsnull, (uintN)0, - 0, nsIScriptError::warningFlag, - "HTML"); - NS_ENSURE_SUCCESS(rv,rv); - - // - // Send the error to the console - // - nsCOMPtr - consoleService(do_GetService(NS_CONSOLESERVICE_CONTRACTID)); - NS_ENSURE_TRUE(consoleService, NS_ERROR_UNEXPECTED); - - return consoleService->LogMessage(scriptError); + return nsContentUtils::ReportToConsole(nsContentUtils::eFORMS_PROPERTIES, + aWarningName, + aWarningArgs, aWarningArgsLen, + documentURI, + NS_LITERAL_STRING(""), 0, 0, + nsIScriptError::warningFlag, + "HTML"); } nsresult @@ -1207,7 +1167,7 @@ GetSubmissionFromForm(nsIHTMLContent* aForm, enctype == NS_FORM_ENCTYPE_TEXTPLAIN) { nsAutoString enctypeStr; aForm->GetAttr(kNameSpaceID_None, nsHTMLAtoms::enctype, enctypeStr); - SendJSWarning(aForm, NS_LITERAL_STRING("ForgotPostWarning"), PromiseFlatString(enctypeStr)); + SendJSWarning(aForm, "ForgotPostWarning", PromiseFlatString(enctypeStr)); } *aFormSubmission = new nsFSURLEncoded(charset, encoder, formProcessor, bidiOptions, method); diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 0fcd184824c..921689a7e36 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -100,7 +100,6 @@ #include "nsContentCID.h" #include "nsContentUtils.h" #include "nsIDocShell.h" -#include "nsFormControlHelper.h" #include "nsObjectFrame.h" #include "nsRuleNode.h" #include "nsIDOMMutationEvent.h" @@ -10372,8 +10371,8 @@ void nsCSSFrameConstructor::GetAlternateTextFor(nsIContent* aContent, // If there's no "value" attribute either, then use the localized string // for "Submit" as the alternate text. if (NS_CONTENT_ATTR_NOT_THERE == rv) { - nsFormControlHelper::GetLocalizedString(nsFormControlHelper::GetHTMLPropertiesFileName(), - NS_LITERAL_STRING("Submit").get(), aAltText); + nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES, + "Submit", aAltText); } } } diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index c123fc5394e..8f431e783f6 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -169,7 +169,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset // Print error dialog #include "nsIPrompt.h" #include "nsIWindowWatcher.h" -#include "nsIStringBundle.h" // Printing #include "nsPrintEngine.h" @@ -194,10 +193,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset #include "prenv.h" #include -static const char kDOMStringBundleURL[] = - "chrome://communicator/locale/dom/dom.properties"; - - #ifdef NS_DEBUG #undef NOISY_VIEWER @@ -989,21 +984,16 @@ DocumentViewerImpl::PermitUnload(PRBool *aPermitUnload) nsCOMPtr prompt(do_GetInterface(mContainer)); if (prompt) { - nsCOMPtr - stringService(do_GetService(NS_STRINGBUNDLE_CONTRACTID)); - NS_ENSURE_TRUE(stringService, NS_OK); - - nsCOMPtr bundle; - stringService->CreateBundle(kDOMStringBundleURL, getter_AddRefs(bundle)); - NS_ENSURE_TRUE(bundle, NS_OK); - - nsXPIDLString preMsg, postMsg; - nsresult rv; - rv = bundle->GetStringFromName(NS_LITERAL_STRING("OnBeforeUnloadPreMessage").get(), getter_Copies(preMsg)); - rv |= bundle->GetStringFromName(NS_LITERAL_STRING("OnBeforeUnloadPostMessage").get(), getter_Copies(postMsg)); + nsString preMsg, postMsg; + rv = nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES, + "OnBeforeUnloadPreMessage", + preMsg); + rv |= nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES, + "OnBeforeUnloadPostMessage", + postMsg); // GetStringFromName can succeed, yet give NULL strings back. - if (NS_FAILED(rv) || !preMsg || !postMsg) { + if (NS_FAILED(rv) || preMsg.IsEmpty() || postMsg.IsEmpty()) { NS_ERROR("Failed to get strings from dom.properties!"); return NS_OK; } diff --git a/layout/forms/Makefile.in b/layout/forms/Makefile.in index ef0a593ef04..6fcb118a4ed 100644 --- a/layout/forms/Makefile.in +++ b/layout/forms/Makefile.in @@ -65,6 +65,9 @@ REQUIRES = xpcom \ accessibility \ unicharutil \ commandhandler \ + xpconnect \ + js \ + pref \ $(NULL) EXPORTS = \ diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp index 0f12db664f6..970cedfcda6 100644 --- a/layout/forms/nsFileControlFrame.cpp +++ b/layout/forms/nsFileControlFrame.cpp @@ -73,6 +73,7 @@ #include "nsITextControlElement.h" #include "nsNodeInfoManager.h" #include "nsContentCreatorFunctions.h" +#include "nsContentUtils.h" #define SYNC_TEXT 0x1 #define SYNC_BUTTON 0x2 @@ -309,8 +310,8 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent) // Get Loc title nsString title; - nsFormControlHelper::GetLocalizedString(nsFormControlHelper::GetHTMLPropertiesFileName(), - NS_LITERAL_STRING("FileUpload").get(), title); + nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES, + "FileUpload", title); nsCOMPtr filePicker = do_CreateInstance("@mozilla.org/filepicker;1"); if (!filePicker) diff --git a/layout/forms/nsFormControlHelper.cpp b/layout/forms/nsFormControlHelper.cpp index 339e678c88d..0eb3dfca51f 100644 --- a/layout/forms/nsFormControlHelper.cpp +++ b/layout/forms/nsFormControlHelper.cpp @@ -381,35 +381,6 @@ nsFormControlHelper::GetValueAttr(nsIContent* aContent, nsAString* aResult) } //---------------------------------------------------------------------------------- -// 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 PRUnichar* aKey, nsString& oVal) -{ - NS_ENSURE_ARG_POINTER(aKey); - - nsresult rv; - - nsCOMPtr bundle; - - // Create a bundle for the localization - 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) { - nsXPIDLString valUni; - rv = bundle->GetStringFromName(aKey, getter_Copies(valUni)); - if (NS_SUCCEEDED(rv) && valUni) { - oVal.Assign(valUni); - } else { - oVal.Truncate(); - } - } - return rv; -} nsresult nsFormControlHelper::Reset(nsIFrame* aFrame, nsPresContext* aPresContext) diff --git a/layout/forms/nsFormControlHelper.h b/layout/forms/nsFormControlHelper.h index 6f1b09af341..36a4355e650 100644 --- a/layout/forms/nsFormControlHelper.h +++ b/layout/forms/nsFormControlHelper.h @@ -58,10 +58,6 @@ class nsStyleContext; #define NS_STRING_TRUE NS_LITERAL_STRING("1") #define NS_STRING_FALSE NS_LITERAL_STRING("0") -// for localization -#define FORM_PROPERTIES "chrome://communicator/locale/layout/HtmlForm.properties" - - /** * Enumeration of possible mouse states used to detect mouse clicks */ @@ -170,10 +166,6 @@ public: static nsresult GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap& aWrapProp); - // Localization Helper - static nsresult GetLocalizedString(const char * aPropFileName, const PRUnichar* aKey, nsString& oVal); - static const char * GetHTMLPropertiesFileName() { return FORM_PROPERTIES; } - // //------------------------------------------------------------------------------------- // Utility methods for managing checkboxes and radiobuttons diff --git a/layout/forms/nsGfxButtonControlFrame.cpp b/layout/forms/nsGfxButtonControlFrame.cpp index 3069626229d..79ec9206cfb 100644 --- a/layout/forms/nsGfxButtonControlFrame.cpp +++ b/layout/forms/nsGfxButtonControlFrame.cpp @@ -52,6 +52,7 @@ #include "nsReflowPath.h" #include "nsAutoPtr.h" #include "nsStyleSet.h" +#include "nsContentUtils.h" // MouseEvent suppression in PP #include "nsGUIEvent.h" @@ -284,23 +285,25 @@ else { nsresult nsGfxButtonControlFrame::GetDefaultLabel(nsString& aString) { - const char * propname = nsFormControlHelper::GetHTMLPropertiesFileName(); nsresult rv = NS_OK; PRInt32 type = GetFormControlType(); + const char *prop; if (type == NS_FORM_INPUT_RESET) { - rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Reset").get(), aString); + prop = "Reset"; } else if (type == NS_FORM_INPUT_SUBMIT) { - rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Submit").get(), aString); + prop = "Submit"; } else if (IsFileBrowseButton(type)) { - rv = nsFormControlHelper::GetLocalizedString(propname, NS_LITERAL_STRING("Browse").get(), aString); + prop = "Browse"; } else { aString.Truncate(); - rv = NS_OK; + return NS_OK; } - return rv; + + return nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES, + prop, aString); } NS_IMETHODIMP diff --git a/layout/forms/nsIsIndexFrame.cpp b/layout/forms/nsIsIndexFrame.cpp index 79c42c1b680..eaec3a5dc26 100644 --- a/layout/forms/nsIsIndexFrame.cpp +++ b/layout/forms/nsIsIndexFrame.cpp @@ -79,6 +79,7 @@ #include "nsContentCID.h" #include "nsNodeInfoManager.h" #include "nsContentCreatorFunctions.h" +#include "nsContentUtils.h" static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); @@ -153,8 +154,9 @@ nsIsIndexFrame::UpdatePromptLabel() // We can't make any assumption as to what the default would be // 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(), - NS_LITERAL_STRING("IsIndexPrompt").get(), prompt); + result = + nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES, + "IsIndexPrompt", prompt); } mTextContent->SetText(prompt, PR_TRUE); diff --git a/layout/generic/Makefile.in b/layout/generic/Makefile.in index 813af0c8b95..2bdcaadde6e 100644 --- a/layout/generic/Makefile.in +++ b/layout/generic/Makefile.in @@ -186,7 +186,6 @@ include $(topsrcdir)/config/rules.mk LOCAL_INCLUDES += \ -I$(srcdir) \ -I$(srcdir)/../base \ - -I$(srcdir)/../forms \ -I$(srcdir)/../tables \ -I$(srcdir)/../xul/base/src \ -I$(srcdir)/../../content/xul/content/src \ diff --git a/layout/generic/nsSimplePageSequence.cpp b/layout/generic/nsSimplePageSequence.cpp index 10af040c3a7..17f589345bc 100644 --- a/layout/generic/nsSimplePageSequence.cpp +++ b/layout/generic/nsSimplePageSequence.cpp @@ -58,12 +58,6 @@ static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID); #define OFFSET_NOT_SET -1 -// This is for localization of the "x of n" pages string -// this class contains a helper method we need to get -// a string from a string bundle -#include "nsFormControlHelper.h" -#define PRINTING_PROPERTIES "chrome://global/locale/printing.properties" - // Print Options #include "nsIPrintSettings.h" #include "nsIPrintOptions.h" @@ -573,7 +567,9 @@ nsSimplePageSequenceFrame::SetPageNumberFormat(const char* aPropName, const char // Doing this here so we only have to go get these formats once nsAutoString pageNumberFormat; // Now go get the Localized Page Formating String - nsresult rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, NS_ConvertUTF8toUCS2(aPropName).get(), pageNumberFormat); + nsresult rv = + nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES, + aPropName, pageNumberFormat); if (NS_FAILED(rv)) { // back stop formatting pageNumberFormat.AssignASCII(aDefPropVal); } @@ -716,14 +712,16 @@ nsSimplePageSequenceFrame::StartPrint(nsPresContext* aPresContext, // // Get default font name and size to be used for the headers and footers nsAutoString fontName; - rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, NS_LITERAL_STRING("fontname").get(), fontName); + rv = nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES, + "fontname", fontName); if (NS_FAILED(rv)) { fontName.AssignLiteral("serif"); } nsAutoString fontSizeStr; nscoord pointSize = 10;; - rv = nsFormControlHelper::GetLocalizedString(PRINTING_PROPERTIES, NS_LITERAL_STRING("fontsize").get(), fontSizeStr); + rv = nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES, + "fontsize", fontSizeStr); if (NS_SUCCEEDED(rv)) { PRInt32 errCode; pointSize = fontSizeStr.ToInteger(&errCode); diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index 5b277995fe3..0f0ab6fb5e5 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -97,8 +97,6 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset #include "nsIPrintingPromptService.h" static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingprompt-service;1"; -#define NS_ERROR_GFX_PRINTER_BUNDLE_URL "chrome://global/locale/printing.properties" - // Printing Timer #include "nsPagePrintTimer.h" @@ -2199,23 +2197,7 @@ nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting) PR_PL(("nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError=%lx, PRBool aIsPrinting=%d)\n", (long)aPrintError, (int)aIsPrinting)); - static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); - nsCOMPtr stringBundleService = do_GetService(kCStringBundleServiceCID); - - if (!stringBundleService) { - PR_PL(("ShowPrintErrorDialog: Failed to get StringBundle Service instance.\n")); - return; - } - nsCOMPtr myStringBundle; - nsresult rv = stringBundleService->CreateBundle(NS_ERROR_GFX_PRINTER_BUNDLE_URL, getter_AddRefs(myStringBundle)); - if (NS_FAILED(rv)) { - PR_PL(("ShowPrintErrorDialog(): CreateBundle() failure for NS_ERROR_GFX_PRINTER_BUNDLE_URL, rv=%lx\n", (long)rv)); - return; - } - - nsXPIDLString msg, - title; - nsAutoString stringName; + nsCAutoString stringName; switch(aPrintError) { @@ -2264,20 +2246,22 @@ nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting) #undef NS_ERROR_TO_LOCALIZED_PRINT_ERROR_MSG } - PR_PL(("ShowPrintErrorDialog: stringName='%s'\n", NS_LossyConvertUCS2toASCII(stringName).get())); + PR_PL(("ShowPrintErrorDialog: stringName='%s'\n", stringName.get())); - myStringBundle->GetStringFromName(stringName.get(), getter_Copies(msg)); - if (aIsPrinting) { - myStringBundle->GetStringFromName(NS_LITERAL_STRING("print_error_dialog_title").get(), getter_Copies(title)); - } else { - myStringBundle->GetStringFromName(NS_LITERAL_STRING("printpreview_error_dialog_title").get(), getter_Copies(title)); - } - - if (!msg) { - PR_PL(("ShowPrintErrorDialog(): msg==nsnull\n")); + nsString msg, title; + nsresult rv = + nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES, + stringName.get(), msg); + if (NS_FAILED(rv)) { + PR_PL(("GetLocalizedString failed\n")); return; } + rv = nsContentUtils::GetLocalizedString(nsContentUtils::ePRINTING_PROPERTIES, + aIsPrinting ? "print_error_dialog_title" + : "printpreview_error_dialog_title", + title); + nsCOMPtr wwatch = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); if (NS_FAILED(rv)) { PR_PL(("ShowPrintErrorDialog(): wwatch==nsnull\n")); @@ -2296,7 +2280,7 @@ nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting) return; } - dialog->Alert(title, msg); + dialog->Alert(title.get(), msg.get()); PR_PL(("ShowPrintErrorDialog(): alert displayed successfully.\n")); }