From f94aa8151ecb3cfc2ec3265c23dd422f7e0e39cb Mon Sep 17 00:00:00 2001 From: "darin%meer.net" Date: Sun, 7 Nov 2004 23:59:35 +0000 Subject: [PATCH] fixes bug 219400 "remove callers of nsServiceManager:: methods" r=bsmedberg --- .../bookmarks/src/nsBookmarksService.cpp | 77 +- chrome/src/nsChromeRegistry.cpp | 20 +- chrome/src/nsChromeUIDataSource.cpp | 9 +- editor/libeditor/text/nsInternetCiter.cpp | 13 +- editor/libeditor/text/nsWrapUtils.cpp | 13 +- extensions/sql/base/src/mozSqlResult.cpp | 5 +- extensions/sql/base/src/mozSqlService.cpp | 14 +- extensions/wallet/src/wallet.cpp | 8 +- extensions/xmlterm/base/mozXMLTermShell.cpp | 10 +- gfx/src/cairo/nsFontMetricsXft.cpp | 6 +- gfx/src/freetype/nsFreeType.cpp | 4 +- gfx/src/gtk/mozilla-decoder.cpp | 3 +- gfx/src/gtk/nsFontMetricsGTK.cpp | 6 +- gfx/src/gtk/nsFontMetricsXft.cpp | 6 +- gfx/src/mac/nsMacUnicodeFontInfo.cpp | 3 +- gfx/src/os2/nsFontMetricsOS2.cpp | 3 +- gfx/src/os2/nsOS2Uni.cpp | 3 +- gfx/src/photon/nsFontMetricsPh.cpp | 2 +- gfx/src/ps/nsPostScriptObj.cpp | 2 +- gfx/src/windows/nsFontMetricsWin.cpp | 10 +- gfx/src/x11shared/nsFT2FontCatalog.cpp | 4 +- intl/ctl/src/nsUnicodeToTIS620.cpp | 23 +- intl/lwbrk/tests/TestLineBreak.cpp | 36 +- intl/uconv/src/nsTextToSubURI.cpp | 18 +- intl/uconv/tests/convperf.cpp | 8 +- intl/uconv/tests/nsTestUConv.cpp | 5 +- intl/uconv/tests/nsconv.cpp | 16 +- intl/unicharutil/tests/UnicharSelfTest.cpp | 26 +- js/src/xpconnect/src/nsXPConnect.cpp | 4 +- js/src/xpconnect/src/xpcjsid.cpp | 10 +- layout/forms/nsIsIndexFrame.cpp | 6 +- layout/generic/nsTextTransformer.cpp | 8 +- layout/html/base/src/nsTextTransformer.cpp | 1856 ----------------- layout/html/forms/src/nsIsIndexFrame.cpp | 604 ------ mailnews/mime/src/mimedrft.cpp | 6 +- mailnews/mime/src/mimei.cpp | 1 - mailnews/mime/src/mimemoz2.cpp | 6 +- modules/oji/src/jvmmgr.cpp | 3 +- modules/oji/tests/src/JM/get_jm.cpp | 4 +- modules/oji/tests/src/JNI/getjni/get_jni.cpp | 4 +- modules/oji/tests/src/LCM/get_lcm.cpp | 4 +- modules/oji/tests/src/TM/get_tm.cpp | 4 +- modules/plugin/samples/simple/npsimple.cpp | 26 +- .../plugin/samples/testevents/npevents.cpp | 26 +- .../converters/nsDirIndexParser.cpp | 4 +- netwerk/test/TestCallbacks.cpp | 4 +- rdf/base/src/nsContainerEnumerator.cpp | 10 +- rdf/base/src/nsRDFContainer.cpp | 34 +- rdf/base/src/nsRDFContainerUtils.cpp | 10 +- rdf/base/src/nsRDFContentSink.cpp | 23 +- rdf/base/src/nsRDFXMLDataSource.cpp | 8 +- rdf/base/src/nsRDFXMLSerializer.cpp | 10 +- rdf/chrome/src/nsChromeRegistry.cpp | 19 +- rdf/chrome/src/nsChromeUIDataSource.cpp | 9 +- rdf/datasource/src/nsFileSystemDataSource.cpp | 7 +- rdf/util/src/nsRDFResource.cpp | 6 +- security/manager/ssl/src/nsNSSComponent.cpp | 26 +- .../history/src/nsGlobalHistory.cpp | 9 +- webshell/tests/viewer/nsBrowserWindow.cpp | 15 +- webshell/tests/viewer/nsViewerApp.cpp | 57 - webshell/tests/viewer/nsWebCrawler.cpp | 10 +- widget/src/cocoa/nsCocoaWindow.mm | 9 +- widget/src/gtk/nsGtkIMEHelper.cpp | 7 +- widget/src/windows/nsNativeDragTarget.cpp | 6 +- widget/src/windows/nsWindow.cpp | 6 +- widget/src/xpwidgets/nsBaseWidget.cpp | 8 +- xpcom/build/nsXPComInit.cpp | 1 - xpcom/components/nsIServiceManagerObsolete.h | 44 - xpcom/components/nsServiceManagerObsolete.cpp | 16 +- xpcom/proxy/public/nsProxiedService.h | 84 +- xpcom/proxy/tests/proxytests.cpp | 58 +- xpcom/tests/TestCallTemplates.cpp | 4 - xpcom/tests/TestServMgr.cpp | 19 +- .../bookmarks/src/nsBookmarksService.cpp | 77 +- .../history/src/nsGlobalHistory.cpp | 9 +- xpfe/components/intl/nsCharsetMenu.cpp | 5 +- .../related/src/nsRelatedLinksHandler.cpp | 27 +- .../search/src/nsInternetSearchService.cpp | 26 +- xpinstall/src/nsInstall.cpp | 17 +- xpinstall/src/nsUpdateNotification.cpp | 8 +- 80 files changed, 383 insertions(+), 3234 deletions(-) diff --git a/browser/components/bookmarks/src/nsBookmarksService.cpp b/browser/components/bookmarks/src/nsBookmarksService.cpp index 9d0a199ccc3..534416c01ff 100644 --- a/browser/components/bookmarks/src/nsBookmarksService.cpp +++ b/browser/components/bookmarks/src/nsBookmarksService.cpp @@ -206,26 +206,23 @@ bm_AddRefGlobals() if (gRefCnt++ == 0) { nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**) &gRDF); + rv = CallGetService(kRDFServiceCID, &gRDF); + if (NS_FAILED(rv)) { + NS_ERROR("unable to get RDF service"); + return rv; + } - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); - if (NS_FAILED(rv)) return rv; + rv = CallGetService(kRDFContainerUtilsCID, &gRDFC); + if (NS_FAILED(rv)) { + NS_ERROR("unable to get RDF container utils"); + return rv; + } - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, - NS_GET_IID(nsIRDFContainerUtils), - (nsISupports**) &gRDFC); - - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF container utils"); - if (NS_FAILED(rv)) return rv; - - rv = nsServiceManager::GetService(kCharsetAliasCID, - NS_GET_IID(nsICharsetAlias), - (nsISupports**) &gCharsetAlias); - - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get charset alias service"); - if (NS_FAILED(rv)) return rv; + rv = CallGetService(kCharsetAliasCID, &gCharsetAlias); + if (NS_FAILED(rv)) { + NS_ERROR("unable to get charset alias service"); + return rv; + } gRDF->GetResource(NS_LITERAL_CSTRING(kURINC_BookmarksTopRoot), &kNC_BookmarksTopRoot); @@ -356,23 +353,9 @@ bm_ReleaseGlobals() { if (--gRefCnt == 0) { - if (gRDF) - { - nsServiceManager::ReleaseService(kRDFServiceCID, gRDF); - gRDF = nsnull; - } - - if (gRDFC) - { - nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFC); - gRDFC = nsnull; - } - - if (gCharsetAlias) - { - nsServiceManager::ReleaseService(kCharsetAliasCID, gCharsetAlias); - gCharsetAlias = nsnull; - } + NS_IF_RELEASE(gRDF); + NS_IF_RELEASE(gRDFC); + NS_IF_RELEASE(gCharsetAlias); NS_IF_RELEASE(kNC_Bookmark); NS_IF_RELEASE(kNC_BookmarkSeparator); @@ -1105,11 +1088,9 @@ BookmarkParser::ParseMetaTag(const nsString &aLine, nsIUnicodeDecoder **decoder) if (charset.Length() < 1) return NS_ERROR_UNEXPECTED; // found a charset, now try and get a decoder from it to Unicode - nsICharsetConverterManager *charsetConv = nsnull; - rv = nsServiceManager::GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), - (nsISupports**)&charsetConv); - if (NS_SUCCEEDED(rv) && (charsetConv)) + nsICharsetConverterManager *charsetConv; + rv = CallGetService(kCharsetConverterManagerCID, &charsetConv); + if (NS_SUCCEEDED(rv)) { rv = charsetConv->GetUnicodeDecoderRaw(charset.get(), decoder); NS_RELEASE(charsetConv); @@ -1673,17 +1654,19 @@ nsBookmarksService::Init() if (NS_FAILED(rv)) return rv; /* create a URL for the string resource file */ - nsCOMPtr uri; - if (NS_SUCCEEDED(rv = mNetService->NewURI(bookmark_properties, nsnull, nsnull, - getter_AddRefs(uri)))) + nsCOMPtr uri; + mNetService->NewURI(bookmark_properties, nsnull, nsnull, + getter_AddRefs(uri)); + if (uri) { /* create a bundle for the localization */ - nsCOMPtr stringService; - if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kStringBundleServiceCID, - NS_GET_IID(nsIStringBundleService), getter_AddRefs(stringService)))) + nsCOMPtr stringService = + do_GetService(kStringBundleServiceCID); + if (stringService) { nsCAutoString spec; - if (NS_SUCCEEDED(rv = uri->GetSpec(spec))) + uri->GetSpec(spec); + if (!uri.IsEmpty()) { stringService->CreateBundle(spec.get(), getter_AddRefs(mBundle)); } diff --git a/chrome/src/nsChromeRegistry.cpp b/chrome/src/nsChromeRegistry.cpp index e8536740a13..7d12c61c9f3 100644 --- a/chrome/src/nsChromeRegistry.cpp +++ b/chrome/src/nsChromeRegistry.cpp @@ -182,16 +182,8 @@ nsChromeRegistry::~nsChromeRegistry() delete mDataSourceTable; } - if (mRDFService) { - nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService); - mRDFService = nsnull; - } - - if (mRDFContainerUtils) { - nsServiceManager::ReleaseService(kRDFContainerUtilsCID, mRDFContainerUtils); - mRDFContainerUtils = nsnull; - } - + NS_IF_RELEASE(mRDFService); + NS_IF_RELEASE(mRDFContainerUtils); } NS_IMPL_THREADSAFE_ISUPPORTS5(nsChromeRegistry, @@ -251,14 +243,10 @@ nsChromeRegistry::Init() gChromeRegistry = this; nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**)&mRDFService); + rv = CallGetService(kRDFServiceCID, &mRDFService); NS_ENSURE_SUCCESS(rv, rv); - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, - NS_GET_IID(nsIRDFContainerUtils), - (nsISupports**)&mRDFContainerUtils); + rv = CallGetService(kRDFContainerUtilsCID, &mRDFContainerUtils); NS_ENSURE_SUCCESS(rv, rv); rv = mRDFService->GetResource(nsDependentCString(kURICHROME_baseURL), diff --git a/chrome/src/nsChromeUIDataSource.cpp b/chrome/src/nsChromeUIDataSource.cpp index 4cf7b7f9ae2..1edf533a990 100644 --- a/chrome/src/nsChromeUIDataSource.cpp +++ b/chrome/src/nsChromeUIDataSource.cpp @@ -67,9 +67,7 @@ nsChromeUIDataSource::nsChromeUIDataSource(nsIRDFDataSource* aComposite) mComposite->AddObserver(this); nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**)&mRDFService); + rv = CallGetService(kRDFServiceCID, &mRDFService); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); mRDFService->RegisterDataSource(this, PR_TRUE); @@ -79,10 +77,7 @@ nsChromeUIDataSource::~nsChromeUIDataSource() { mRDFService->UnregisterDataSource(this); - if (mRDFService) { - nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService); - mRDFService = nsnull; - } + NS_IF_RELEASE(mRDFService); } // we require a special implementation of Release, which knows about diff --git a/editor/libeditor/text/nsInternetCiter.cpp b/editor/libeditor/text/nsInternetCiter.cpp index 8c5709f1a1b..31b37855a17 100644 --- a/editor/libeditor/text/nsInternetCiter.cpp +++ b/editor/libeditor/text/nsInternetCiter.cpp @@ -206,22 +206,21 @@ nsInternetCiter::Rewrap(const nsAString& aInString, nsCOMPtr lineBreaker; nsILineBreakerFactory *lf; nsresult rv; - rv = nsServiceManager::GetService(NS_LWBRK_CONTRACTID, - NS_GET_IID(nsILineBreakerFactory), - (nsISupports **)&lf); + rv = CallGetService(NS_LWBRK_CONTRACTID, &lf); if (NS_SUCCEEDED(rv)) { nsAutoString lbarg; - rv = lf->GetBreaker(lbarg, getter_AddRefs(lineBreaker)); - nsServiceManager::ReleaseService(NS_LWBRK_CONTRACTID, lf); + lf->GetBreaker(lbarg, getter_AddRefs(lineBreaker)); + NS_RELEASE(lf); } // Loop over lines in the input string, rewrapping each one. - PRUint32 length = aInString.Length(); + PRUint32 length; PRUint32 posInString = 0; PRUint32 outStringCol = 0; PRUint32 citeLevel = 0; - const nsPromiseFlatString &tString = PromiseFlatString(aInString);//MJUDGE SCC NEED HELP + const nsPromiseFlatString &tString = PromiseFlatString(aInString); + length = tString.Length(); #ifdef DEBUG_wrapping int loopcount = 0; #endif diff --git a/editor/libeditor/text/nsWrapUtils.cpp b/editor/libeditor/text/nsWrapUtils.cpp index 6b5db55b0ff..88a709f947c 100644 --- a/editor/libeditor/text/nsWrapUtils.cpp +++ b/editor/libeditor/text/nsWrapUtils.cpp @@ -59,22 +59,19 @@ nsWrapUtils::Rewrap(const nsAString& aInString, nsCOMPtr lineBreaker; nsILineBreakerFactory *lf; - nsresult rv; - rv = nsServiceManager::GetService(NS_LWBRK_CONTRACTID, - NS_GET_IID(nsILineBreakerFactory), - (nsISupports **)&lf); + nsresult rv = CallGetService(NS_LWBRK_CONTRACTID, &lf); if (NS_SUCCEEDED(rv)) { nsAutoString lbarg; - rv = lf->GetBreaker(lbarg, getter_AddRefs(lineBreaker)); - nsServiceManager::ReleaseService(NS_LWBRK_CONTRACTID, lf); + lf->GetBreaker(lbarg, getter_AddRefs(lineBreaker)); + NS_RELEASE(lf); } aOutString.Truncate(); // Now we either have a line breaker, or we don't. - PRInt32 length = aInString.Length(); - nsString tString(aInString); + const nsPromiseFlatString &tString = PromiseFlatString(aInString); + PRInt32 length = tString.Length(); const PRUnichar* unicodeStr = tString.get(); for (i = 0; i < length; ) // loop over lines { diff --git a/extensions/sql/base/src/mozSqlResult.cpp b/extensions/sql/base/src/mozSqlResult.cpp index 70abd4d9b61..1d3214f53cb 100644 --- a/extensions/sql/base/src/mozSqlResult.cpp +++ b/extensions/sql/base/src/mozSqlResult.cpp @@ -77,8 +77,7 @@ mozSqlResult::Init() nsresult rv; if (gRefCnt++ == 0) { - rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), - (nsISupports**) &gRDFService); + rv = CallGetService(kRDFServiceCID, &gRDFService); if (NS_FAILED(rv)) return rv; rv = CallCreateInstance(kDateTimeFormatCID, &gFormat); @@ -145,7 +144,7 @@ mozSqlResult::~mozSqlResult() NS_IF_RELEASE(kSQL_ResultRoot); NS_IF_RELEASE(gFormat); - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); + NS_IF_RELEASE(gRDFService); gRDFService = nsnull; } } diff --git a/extensions/sql/base/src/mozSqlService.cpp b/extensions/sql/base/src/mozSqlService.cpp index 4eb809ea753..1fab6abfde0 100644 --- a/extensions/sql/base/src/mozSqlService.cpp +++ b/extensions/sql/base/src/mozSqlService.cpp @@ -85,11 +85,8 @@ mozSqlService::~mozSqlService() NS_IF_RELEASE(kSQL_Database); NS_IF_RELEASE(kSQL_Priority); - nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils); - gRDFContainerUtils = nsnull; - - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); - gRDFService = nsnull; + NS_IF_RELEASE(gRDFContainerUtils); + NS_IF_RELEASE(gRDFService); } NS_IMPL_ISUPPORTS3(mozSqlService, @@ -109,13 +106,10 @@ mozSqlService::Init() { nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), - (nsISupports**) &gRDFService); + rv = CallGetService(kRDFServiceCID, &gRDFService); if (NS_FAILED(rv)) return rv; - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, NS_GET_IID(nsIRDFContainerUtils), - (nsISupports**) &gRDFContainerUtils); - + rv = CallGetService(kRDFContainerUtilsCID, &gRDFContainerUtils); if (NS_FAILED(rv)) return rv; gRDFService->GetResource(NS_LITERAL_CSTRING("SQL:AliasesRoot"), diff --git a/extensions/wallet/src/wallet.cpp b/extensions/wallet/src/wallet.cpp index 1259f67e698..bd3fd1a1544 100644 --- a/extensions/wallet/src/wallet.cpp +++ b/extensions/wallet/src/wallet.cpp @@ -1778,10 +1778,8 @@ wallet_StepForwardOrBack //#include "nsIUGenCategory.h" //#include "nsUnicharUtilCIID.h" //static NS_DEFINE_IID(kUnicharUtilCID, NS_UNICHARUTIL_CID); -//static NS_DEFINE_IID(kIUGenCategoryIID, NS_IUGENCATEGORY_IID); //#include "nsICaseConversion.h" -//static NS_DEFINE_IID(kICaseConversionIID, NS_ICASECONVERSION_IID); //static nsICaseConversion* gCaseConv = nsnull; static void @@ -1870,12 +1868,10 @@ wallet_ResolvePositionalSchema(nsIDOMNode* elementNode, nsACString& schema) { /* break out if an alphanumeric character is found */ -// nsresult res = nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID, -// (nsISupports**)&gCaseConv); +// nsresult res = CallGetService(kUnicharUtilCID, &gCaseConv); // // nsIUGenCategory* intl = nsnull; -// nsresult rv = nsServiceManager::GetService(kUnicharUtilCID, kIUGenCategoryIID, -// (nsISupports**)&intl); +// nsresult rv = CallGetService(kUnicharUtilCID, &intl); // Whaaaaaa, intl is never released here! // if (NS_SUCCEEDED(rv) && intl) { // PRBool accept; diff --git a/extensions/xmlterm/base/mozXMLTermShell.cpp b/extensions/xmlterm/base/mozXMLTermShell.cpp index 493f08bf51e..3875a8df150 100644 --- a/extensions/xmlterm/base/mozXMLTermShell.cpp +++ b/extensions/xmlterm/base/mozXMLTermShell.cpp @@ -381,17 +381,11 @@ NS_IMETHODIMP mozXMLTermShell::SendText(const PRUnichar* aString, NS_IMETHODIMP mozXMLTermShell::Exit() { - nsIAppShellService* appShell = nsnull; - XMLT_LOG(mozXMLTermShell::Exit,10,("\n")); // Create the Application Shell instance... // XXXbsmedberg what the hell is this? - nsresult result = nsServiceManager::GetService(NS_APPSHELLSERVICE_CONTRACTID, - NS_GET_IID(nsIAppShellService), - (nsISupports**)&appShell); - if (NS_SUCCEEDED(result)) { - nsServiceManager::ReleaseService(NS_APPSHELLSERVICE_CONTRACTID, appShell); - } + nsCOMPtr appShell = + do_GetService(NS_APPSHELLSERVICE_CONTRACTID); return NS_OK; } diff --git a/gfx/src/cairo/nsFontMetricsXft.cpp b/gfx/src/cairo/nsFontMetricsXft.cpp index 5d05988a898..a4b0e69dff4 100644 --- a/gfx/src/cairo/nsFontMetricsXft.cpp +++ b/gfx/src/cairo/nsFontMetricsXft.cpp @@ -455,8 +455,7 @@ nsFontMetricsXft::Init(const nsFont& aFont, nsIAtom* aLangGroup, mPixelSize = 1; } if (!gInitialized) { - nsServiceManager::GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharsetManager); + CallGetService(kCharsetConverterManagerCID, &gCharsetManager); if (!gCharsetManager) { FreeGlobals(); return NS_ERROR_FAILURE; @@ -2711,8 +2710,7 @@ GetConverter(const char* aEncoding, nsIUnicodeEncoder **aConverter) nsresult rv; if (!gCharsetManager) { - nsServiceManager::GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), (nsISupports**)&gCharsetManager); + CallGetService(kCharsetConverterManagerCID, &gCharsetManager); if (!gCharsetManager) { FreeGlobals(); return NS_ERROR_FAILURE; diff --git a/gfx/src/freetype/nsFreeType.cpp b/gfx/src/freetype/nsFreeType.cpp index 799c37cb357..8f4e00fbe2d 100644 --- a/gfx/src/freetype/nsFreeType.cpp +++ b/gfx/src/freetype/nsFreeType.cpp @@ -783,9 +783,7 @@ nsFreeType2::GetCharSetManager() // // get the sCharSetManager // - nsServiceManager::GetService(kCharSetManagerCID, - NS_GET_IID(nsICharsetConverterManager), - (nsISupports**) &sCharSetManager); + CallGetService(kCharSetManagerCID, &sCharSetManager); NS_ASSERTION(sCharSetManager,"failed to create the charset manager"); } return sCharSetManager; diff --git a/gfx/src/gtk/mozilla-decoder.cpp b/gfx/src/gtk/mozilla-decoder.cpp index b8b76c9a86a..609595f1485 100644 --- a/gfx/src/gtk/mozilla-decoder.cpp +++ b/gfx/src/gtk/mozilla-decoder.cpp @@ -242,8 +242,7 @@ mozilla_decoder_get_charset (PangoFcDecoder *decoder, priv->charset = FcCharSetCreate(); if (!gCharsetManager) { - nsServiceManager::GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), (nsISupports**)&gCharsetManager); + CallGetService(kCharsetConverterManagerCID, &gCharsetManager); } nsCOMPtr encoder; diff --git a/gfx/src/gtk/nsFontMetricsGTK.cpp b/gfx/src/gtk/nsFontMetricsGTK.cpp index c1476975b35..bdeabe18ab6 100644 --- a/gfx/src/gtk/nsFontMetricsGTK.cpp +++ b/gfx/src/gtk/nsFontMetricsGTK.cpp @@ -1093,14 +1093,12 @@ InitGlobals(nsIDeviceContext *aDevice) aDevice->GetCanonicalPixelScale(gDevScale); - nsServiceManager::GetService(kCharSetManagerCID, - NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharSetManager); + CallGetService(kCharSetManagerCID, &gCharSetManager); if (!gCharSetManager) { FreeGlobals(); return NS_ERROR_FAILURE; } - nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), - (nsISupports**) &gPref); + CallGetService(kPrefCID, &gPref); if (!gPref) { FreeGlobals(); return NS_ERROR_FAILURE; diff --git a/gfx/src/gtk/nsFontMetricsXft.cpp b/gfx/src/gtk/nsFontMetricsXft.cpp index eab00d586c0..cdbf53f0bab 100644 --- a/gfx/src/gtk/nsFontMetricsXft.cpp +++ b/gfx/src/gtk/nsFontMetricsXft.cpp @@ -426,8 +426,7 @@ nsFontMetricsXft::Init(const nsFont& aFont, nsIAtom* aLangGroup, mPixelSize = 1; } if (!gInitialized) { - nsServiceManager::GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharsetManager); + CallGetService(kCharsetConverterManagerCID, &gCharsetManager); if (!gCharsetManager) { FreeGlobals(); return NS_ERROR_FAILURE; @@ -2537,8 +2536,7 @@ GetConverter(const char* aEncoding, nsIUnicodeEncoder **aConverter) nsresult rv; if (!gCharsetManager) { - nsServiceManager::GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), (nsISupports**)&gCharsetManager); + CallGetService(kCharsetConverterManagerCID, &gCharsetManager); if (!gCharsetManager) { FreeGlobals(); return NS_ERROR_FAILURE; diff --git a/gfx/src/mac/nsMacUnicodeFontInfo.cpp b/gfx/src/mac/nsMacUnicodeFontInfo.cpp index 15bcdd56d10..8d5a586cfe1 100644 --- a/gfx/src/mac/nsMacUnicodeFontInfo.cpp +++ b/gfx/src/mac/nsMacUnicodeFontInfo.cpp @@ -529,8 +529,7 @@ GetConverter(const nsCString& aFontName, nsIUnicodeEncoder** aConverter) if (!gCharsetManager) { - rv = nsServiceManager::GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharsetManager); + rv = CallGetService(kCharsetConverterManagerCID, &gCharsetManager); if(NS_FAILED(rv)) return rv; } diff --git a/gfx/src/os2/nsFontMetricsOS2.cpp b/gfx/src/os2/nsFontMetricsOS2.cpp index f68a388dec0..6232dd05b96 100644 --- a/gfx/src/os2/nsFontMetricsOS2.cpp +++ b/gfx/src/os2/nsFontMetricsOS2.cpp @@ -214,8 +214,7 @@ static nsFontCleanupObserver *gFontCleanupObserver; static nsresult InitGlobals(void) { - nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), - (nsISupports**) &gPref); + CallGetService(kPrefCID, &gPref); if (!gPref) { FreeGlobals(); return NS_ERROR_FAILURE; diff --git a/gfx/src/os2/nsOS2Uni.cpp b/gfx/src/os2/nsOS2Uni.cpp index 6f81a8949e2..1cafeeeb185 100644 --- a/gfx/src/os2/nsOS2Uni.cpp +++ b/gfx/src/os2/nsOS2Uni.cpp @@ -81,8 +81,7 @@ nsISupports* OS2Uni::GetUconvObject(int aCodePage, ConverterRequest aReq) { if (gCharsetManager == nsnull) { - nsServiceManager::GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharsetManager); + CallGetService(kCharsetConverterManagerCID, &gCharsetManager); } nsresult rv; diff --git a/gfx/src/photon/nsFontMetricsPh.cpp b/gfx/src/photon/nsFontMetricsPh.cpp index 9a6282e4dbf..563be3dd5ba 100644 --- a/gfx/src/photon/nsFontMetricsPh.cpp +++ b/gfx/src/photon/nsFontMetricsPh.cpp @@ -87,7 +87,7 @@ nsFontMetricsPh::nsFontMetricsPh() static nsresult InitGlobals() { - nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), (nsISupports**) &gPref); + CallGetService(kPrefCID, &gPref); if (!gPref) return NS_ERROR_FAILURE; gFontMetricsCache = new nsHashtable(); diff --git a/gfx/src/ps/nsPostScriptObj.cpp b/gfx/src/ps/nsPostScriptObj.cpp index d85c83d556f..68ebd4db5dc 100644 --- a/gfx/src/ps/nsPostScriptObj.cpp +++ b/gfx/src/ps/nsPostScriptObj.cpp @@ -200,7 +200,7 @@ nsPostScriptObj::nsPostScriptObj() : { PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("nsPostScriptObj::nsPostScriptObj()\n")); - nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), (nsISupports**) &gPrefs); + CallGetService(kPrefCID, &gPrefs); gLangGroups = new nsHashtable(); } diff --git a/gfx/src/windows/nsFontMetricsWin.cpp b/gfx/src/windows/nsFontMetricsWin.cpp index 5b4685d8d00..72c37190bb3 100644 --- a/gfx/src/windows/nsFontMetricsWin.cpp +++ b/gfx/src/windows/nsFontMetricsWin.cpp @@ -279,14 +279,12 @@ static nsFontCleanupObserver *gFontCleanupObserver; static nsresult InitGlobals(void) { - nsServiceManager::GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharsetManager); + CallGetService(kCharsetConverterManagerCID, &gCharsetManager); if (!gCharsetManager) { FreeGlobals(); return NS_ERROR_FAILURE; } - nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), - (nsISupports**) &gPref); + CallGetService(kPrefCID, &gPref); if (!gPref) { FreeGlobals(); return NS_ERROR_FAILURE; @@ -386,8 +384,8 @@ static void CheckFontLangGroup(nsIAtom* lang1, nsIAtom* lang2, const char* lang3 if (lang1 == lang2) { nsresult res = NS_OK; if (!gFontPackageProxy) { - res = nsServiceManager::GetService("@mozilla.org/intl/fontpackageservice;1", - NS_GET_IID(nsIFontPackageProxy), (nsISupports**) &gFontPackageProxy); + res = CallGetService("@mozilla.org/intl/fontpackageservice;1", + &gFontPackageProxy); if (NS_FAILED(res)) { NS_ERROR("Cannot get the font package proxy"); return; diff --git a/gfx/src/x11shared/nsFT2FontCatalog.cpp b/gfx/src/x11shared/nsFT2FontCatalog.cpp index 0da2b2f465a..654d05c1e80 100644 --- a/gfx/src/x11shared/nsFT2FontCatalog.cpp +++ b/gfx/src/x11shared/nsFT2FontCatalog.cpp @@ -1214,9 +1214,7 @@ nsFT2FontCatalog::InitGlobals(FT_Library lib) nsulCodePageRangeLanguage *crl = nsnull; - nsServiceManager::GetService(NS_PREF_CONTRACTID, - NS_GET_IID(nsIPref), - (nsISupports**) &sPref); + CallGetService(NS_PREF_CONTRACTID, &sPref); if (!sPref) goto cleanup_and_return; diff --git a/intl/ctl/src/nsUnicodeToTIS620.cpp b/intl/ctl/src/nsUnicodeToTIS620.cpp index ac592044f94..30332f28b5d 100644 --- a/intl/ctl/src/nsUnicodeToTIS620.cpp +++ b/intl/ctl/src/nsUnicodeToTIS620.cpp @@ -90,39 +90,32 @@ NS_IMETHODIMP nsUnicodeToTIS620::Convert(const PRUnichar* input, char* output, PRInt32* aDestLength) { - PRSize outLen = 0; + PRSize outLen = 0; #ifdef DEBUG_prabhath_no_shaper printf("Debug/Test Case of No thai pango shaper Object\n"); // Comment out mCtlObj == nsnull for test purposes #endif if (mCtlObj == nsnull) { - nsICharsetConverterManager* gCharSetManager = nsnull; - nsIUnicodeEncoder* gDefaultTISConverter = nsnull; - nsresult res; - nsServiceManager::GetService(kCharSetManagerCID, - NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharSetManager); - #ifdef DEBUG_prabhath printf("ERROR: No CTL IMPLEMENTATION - Default Thai Conversion"); // CP874 is the default converter for thai ; // In case mCtlObj is absent (no CTL support), use it to convert. #endif - if (!gCharSetManager) + nsCOMPtr charsetMgr = + do_GetService(kCharSetManagerCID); + if (!charsetMgr) return NS_ERROR_FAILURE; - res = gCharSetManager->GetUnicodeEncoderRaw("TIS-620", &gDefaultTISConverter); - - if (!gDefaultTISConverter) { + nsCOMPtr encoder; + charsetMgr->GetUnicodeEncoderRaw("TIS-620", getter_AddRefs(encoder)); + if (!encoder) { NS_WARNING("cannot get default converter for tis-620"); - NS_IF_RELEASE(gCharSetManager); return NS_ERROR_FAILURE; } - gDefaultTISConverter->Convert(input, aSrcLength, output, aDestLength); - NS_IF_RELEASE(gCharSetManager); - NS_IF_RELEASE(gDefaultTISConverter); + encoder->Convert(input, aSrcLength, output, aDestLength); return NS_OK; } diff --git a/intl/lwbrk/tests/TestLineBreak.cpp b/intl/lwbrk/tests/TestLineBreak.cpp index ef90a92d176..3557401290a 100644 --- a/intl/lwbrk/tests/TestLineBreak.cpp +++ b/intl/lwbrk/tests/TestLineBreak.cpp @@ -38,7 +38,7 @@ #include "nsXPCOM.h" #include "nsIComponentManager.h" #include "nsISupports.h" -#include "nsIServiceManager.h" +#include "nsIServiceManagerUtils.h" #include "nsILineBreakerFactory.h" #include "nsILineBreaker.h" #include "nsIWordBreakerFactory.h" @@ -52,8 +52,6 @@ IMPL_NS_IBREAKSTATE( nsBreakState ) NS_DEFINE_CID(kLWBrkCID, NS_LWBRK_CID); -NS_DEFINE_IID(kILineBreakerFactory, NS_ILINEBREAKERFACTORY_IID); -NS_DEFINE_IID(kIWordBreakerFactory, NS_IWORDBREAKERFACTORY_IID); static char teng1[] = @@ -220,9 +218,7 @@ PRBool TestLineBreaker() nsILineBreakerFactory *t = NULL; nsresult res; PRBool ok = PR_TRUE; - res = nsServiceManager::GetService(kLWBrkCID, - kILineBreakerFactory, - (nsISupports**) &t); + res = CallGetService(kLWBrkCID, &t); printf("Test 1 - GetService():\n"); if(NS_FAILED(res) || ( t == NULL ) ) { @@ -230,13 +226,11 @@ PRBool TestLineBreaker() ok = PR_FALSE; } else { #ifdef WORD_AROUND_SERVICE_MANAGER_ASSERT - res = nsServiceManager::ReleaseService(kLWBrkCID, t); + NS_RELEASE(t); #endif } - res = nsServiceManager::GetService(kLWBrkCID, - kILineBreakerFactory, - (nsISupports**) &t); + res = CallGetService(kLWBrkCID, &t); if(NS_FAILED(res) || ( t == NULL ) ) { printf("\t2nd GetService failed\n"); @@ -288,7 +282,7 @@ PRBool TestLineBreaker() } #ifdef WORD_AROUND_SERVICE_MANAGER_ASSERT - res = nsServiceManager::ReleaseService(kLWBrkCID, t); + NS_RELEASE(t); #endif } printf("==================================\n"); @@ -306,21 +300,17 @@ PRBool TestWordBreaker() nsIWordBreakerFactory *t = NULL; nsresult res; PRBool ok = PR_TRUE; - res = nsServiceManager::GetService(kLWBrkCID, - kIWordBreakerFactory, - (nsISupports**) &t); + res = CallGetService(kLWBrkCID, &t); printf("Test 1 - GetService():\n"); if(NS_FAILED(res) || ( t == NULL ) ) { printf("\t1st GetService failed\n"); ok = PR_FALSE; } else { - res = nsServiceManager::ReleaseService(kLWBrkCID, t); + NS_RELEASE(t); } - res = nsServiceManager::GetService(kLWBrkCID, - kIWordBreakerFactory, - (nsISupports**) &t); + res = CallGetService(kLWBrkCID, &t); if(NS_FAILED(res) || ( t == NULL ) ) { printf("\t2nd GetService failed\n"); @@ -371,7 +361,7 @@ PRBool TestWordBreaker() NS_IF_RELEASE(lb); } - res = nsServiceManager::ReleaseService(kLWBrkCID, t); + NS_RELEASE(t); } printf("==================================\n"); printf("Finish nsIWordBreakerFactory Test \n"); @@ -413,9 +403,7 @@ void SamplePrintWordWithBreak() PRUint32 numOfFragment = sizeof(wb) / sizeof(char*); nsIWordBreakerFactory *t = NULL; - nsresult res = nsServiceManager::GetService(kLWBrkCID, - kIWordBreakerFactory, - (nsISupports**) &t); + nsresult res = CallGetService(kLWBrkCID, &t); nsIWordBreaker *wbk; nsAutoString wb_arg; @@ -474,9 +462,7 @@ void SampleFindWordBreakFromPosition(PRUint32 fragN, PRUint32 offset) PRUint32 numOfFragment = sizeof(wb) / sizeof(char*); nsIWordBreakerFactory *t = NULL; - nsresult res = nsServiceManager::GetService(kLWBrkCID, - kIWordBreakerFactory, - (nsISupports**) &t); + nsresult res = CallGetService(kLWBrkCID, &t); nsIWordBreaker *wbk; nsAutoString wb_arg; diff --git a/intl/uconv/src/nsTextToSubURI.cpp b/intl/uconv/src/nsTextToSubURI.cpp index 165e955b6b6..1373a230149 100644 --- a/intl/uconv/src/nsTextToSubURI.cpp +++ b/intl/uconv/src/nsTextToSubURI.cpp @@ -64,17 +64,15 @@ NS_IMETHODIMP nsTextToSubURI::ConvertAndEscape( if(nsnull == _retval) return NS_ERROR_NULL_POINTER; *_retval = nsnull; - nsIUnicodeEncoder *encoder = nsnull; nsresult rv = NS_OK; // Get Charset, get the encoder. - nsICharsetConverterManager * ccm = nsnull; - rv = nsServiceManager::GetService(kCharsetConverterManagerCID , - NS_GET_IID(nsICharsetConverterManager), - (nsISupports**)&ccm); - if(NS_SUCCEEDED(rv) && (nsnull != ccm)) { + nsICharsetConverterManager *ccm; + rv = CallGetService(kCharsetConverterManagerCID, &ccm); + if(NS_SUCCEEDED(rv)) { + nsIUnicodeEncoder *encoder; rv = ccm->GetUnicodeEncoder(charset, &encoder); - nsServiceManager::ReleaseService( kCharsetConverterManagerCID, ccm); + NS_RELEASE(ccm); if (NS_SUCCEEDED(rv)) { rv = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, (PRUnichar)'?'); if(NS_SUCCEEDED(rv)) @@ -109,7 +107,7 @@ NS_IMETHODIMP nsTextToSubURI::ConvertAndEscape( if(pBuf != buf) PR_Free(pBuf); } - NS_IF_RELEASE(encoder); + NS_RELEASE(encoder); } } @@ -152,10 +150,10 @@ NS_IMETHODIMP nsTextToSubURI::UnEscapeAndConvert( } } } - NS_IF_RELEASE(decoder); + NS_RELEASE(decoder); } } - PR_FREEIF(unescaped); + PR_Free(unescaped); return rv; } diff --git a/intl/uconv/tests/convperf.cpp b/intl/uconv/tests/convperf.cpp index 1b2c359acd6..d7de19a840b 100644 --- a/intl/uconv/tests/convperf.cpp +++ b/intl/uconv/tests/convperf.cpp @@ -112,11 +112,9 @@ void msEncode(UINT cp, const PRUnichar *src, int main(int argc, const char** argv) { - nsresult res= NS_OK; - nsICharsetConverterManager* ccMain=nsnull; - // get ccMain; - nsServiceManager::GetService(kCharsetConverterManagerCID, - kICharsetConverterManagerIID, (nsISupports**) &ccMain); + nsresult res; + nsCOMPtr ccMain = + do_GetService(kCharsetConverterManagerCID, &res); if(NS_FAILED(res)) { fprintf(stderr, "Cannot get Character Converter Manager %x\n", res); diff --git a/intl/uconv/tests/nsTestUConv.cpp b/intl/uconv/tests/nsTestUConv.cpp index f184b9d6372..28bd989ec7d 100644 --- a/intl/uconv/tests/nsTestUConv.cpp +++ b/intl/uconv/tests/nsTestUConv.cpp @@ -1069,9 +1069,8 @@ nsresult testUTF7Encoder() nsresult testPlatformCharset() { - nsIPlatformCharset * cinfo; - nsresult res = nsServiceManager::GetService(kPlatformCharsetCID, - NS_GET_IID(nsIPlatformCharset), (nsISupports **)&cinfo); + nsIPlatformCharset *cinfo; + nsresult res = CallGetService(kPlatformCharsetCID, &cinfo); if (NS_FAILED(res)) { printf("ERROR at GetService() code=0x%x.\n",res); return res; diff --git a/intl/uconv/tests/nsconv.cpp b/intl/uconv/tests/nsconv.cpp index 84052097445..a423892648d 100644 --- a/intl/uconv/tests/nsconv.cpp +++ b/intl/uconv/tests/nsconv.cpp @@ -49,7 +49,6 @@ #include "nsICharsetAlias.h" static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); -static NS_DEFINE_IID(kICharsetConverterManagerIID, NS_ICHARSETCONVERTERMANAGER_IID); #include #include @@ -79,14 +78,12 @@ int main(int argc, const char** argv) FILE* infile = 0; FILE* outfile = 0; nsresult res= NS_OK; - nsICharsetConverterManager* ccMain=nsnull; - nsICharsetAlias* aliasmgr = nsnull; NS_InitXPCOM2(nsnull, nsnull, nsnull); // get ccMain; - res = nsServiceManager::GetService(kCharsetConverterManagerCID, - kICharsetConverterManagerIID, (nsISupports**) &ccMain); + nsCOMPtr ccMain = + do_GetService(kCharsetConverterManagerCID, &res); if(NS_FAILED(res)) { fprintf(stderr, "Cannot get Character Converter Manager %x\n", res); @@ -94,12 +91,11 @@ int main(int argc, const char** argv) } // Get the charset alias manager - res = nsServiceManager::GetService(NS_CHARSETALIAS_CONTRACTID, NS_GET_IID(nsICharsetAlias), - (nsISupports**) &aliasmgr); + nsCOMPtr aliasmgr = + do_GetService(NS_CHARSETALIAS_CONTRACTID, &res); if (NS_FAILED(res)) { fprintf(stderr, "Cannot get Charset Alias Manager %x\n", res); - nsServiceManager::ReleaseService(kCharsetConverterManagerCID, ccMain); return -1; } @@ -221,8 +217,6 @@ int main(int argc, const char** argv) fprintf(stderr, "Done!\n"); NS_IF_RELEASE(encoder); NS_IF_RELEASE(decoder); - nsServiceManager::ReleaseService(kCharsetConverterManagerCID, ccMain); - nsServiceManager::ReleaseService(NS_CHARSETALIAS_CONTRACTID, aliasmgr); return 0; } usage(); @@ -234,7 +228,5 @@ int main(int argc, const char** argv) fclose(outfile); NS_IF_RELEASE(encoder); NS_IF_RELEASE(decoder); - nsServiceManager::ReleaseService(kCharsetConverterManagerCID, ccMain); - nsServiceManager::ReleaseService(NS_CHARSETALIAS_CONTRACTID, aliasmgr); return -1; } diff --git a/intl/unicharutil/tests/UnicharSelfTest.cpp b/intl/unicharutil/tests/UnicharSelfTest.cpp index 78df3264378..d77d76094f9 100644 --- a/intl/unicharutil/tests/UnicharSelfTest.cpp +++ b/intl/unicharutil/tests/UnicharSelfTest.cpp @@ -55,7 +55,6 @@ #include "nsString.h" NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID); -NS_DEFINE_IID(kCaseConversionIID, NS_ICASECONVERSION_IID); NS_DEFINE_CID(kEntityConverterCID, NS_ENTITYCONVERTER_CID); NS_DEFINE_CID(kSaveAsCharsetCID, NS_SAVEASCHARSET_CID); NS_DEFINE_CID(kUnicodeNormalizerCID, NS_UNICODE_NORMALIZER_CID); @@ -271,20 +270,16 @@ void TestCaseConversion() printf("==============================\n"); nsICaseConversion *t = NULL; nsresult res; - res = nsServiceManager::GetService(kUnicharUtilCID, - kCaseConversionIID, - (nsISupports**) &t); + res = CallGetService(kUnicharUtilCID, &t); printf("Test 1 - GetService():\n"); if(NS_FAILED(res) || ( t == NULL ) ) { printf("\t1st GetService failed\n"); } else { - res = nsServiceManager::ReleaseService(kUnicharUtilCID, t); + NS_RELEASE(t); } - res = nsServiceManager::GetService(kUnicharUtilCID, - kCaseConversionIID, - (nsISupports**) &t); + res = CallGetService(kUnicharUtilCID, &t); if(NS_FAILED(res) || ( t == NULL ) ) { printf("\t2nd GetService failed\n"); @@ -365,7 +360,7 @@ void TestCaseConversion() printf("Test 7 - ToTitle(PRUnichar*, PRUnichar*, PRUint32):\n"); printf("!!! To Be Implemented !!!\n"); - res = nsServiceManager::ReleaseService(kUnicharUtilCID, t); + NS_RELEASE(t); } printf("==============================\n"); printf("Finish nsICaseConversion Test \n"); @@ -545,20 +540,16 @@ void TestNormalization() printf("==============================\n"); nsIUnicodeNormalizer *t = NULL; nsresult res; - res = nsServiceManager::GetService(kUnicodeNormalizerCID, - NS_GET_IID(nsIUnicodeNormalizer), - (nsISupports**) &t); + res = CallGetService(kUnicodeNormalizerCID, &t); printf("Test 1 - GetService():\n"); if(NS_FAILED(res) || ( t == NULL ) ) { printf("\t1st Norm GetService failed\n"); } else { - res = nsServiceManager::ReleaseService(kUnicodeNormalizerCID, t); + NS_RELEASE(t); } - res = nsServiceManager::GetService(kUnicodeNormalizerCID, - NS_GET_IID(nsIUnicodeNormalizer), - (nsISupports**) &t); + res = CallGetService(kUnicodeNormalizerCID, &t); if(NS_FAILED(res) || ( t == NULL ) ) { printf("\t2nd GetService failed\n"); @@ -572,8 +563,7 @@ void TestNormalization() printf(" Failed in NFD UnicodeNormalizer test. \n"); } - - res = nsServiceManager::ReleaseService(kUnicodeNormalizerCID, t); + NS_RELEASE(t); } printf("==============================\n"); printf("Finish nsIUnicodeNormalizer Test \n"); diff --git a/js/src/xpconnect/src/nsXPConnect.cpp b/js/src/xpconnect/src/nsXPConnect.cpp index 4538c450a80..00945bc0304 100644 --- a/js/src/xpconnect/src/nsXPConnect.cpp +++ b/js/src/xpconnect/src/nsXPConnect.cpp @@ -76,9 +76,7 @@ nsXPConnect::nsXPConnect() dont_AddRef(XPTI_GetInterfaceInfoManager()); CallQueryInterface(iim, &mInterfaceInfoManager); - nsServiceManager::GetService(XPC_CONTEXT_STACK_CONTRACTID, - NS_GET_IID(nsIThreadJSContextStack), - (nsISupports **)&mContextStack); + CallGetService(XPC_CONTEXT_STACK_CONTRACTID, &mContextStack); #ifdef XPC_TOOLS_SUPPORT { diff --git a/js/src/xpconnect/src/xpcjsid.cpp b/js/src/xpconnect/src/xpcjsid.cpp index 2aa0bf297d5..4c22f05a96f 100644 --- a/js/src/xpconnect/src/xpcjsid.cpp +++ b/js/src/xpconnect/src/xpcjsid.cpp @@ -888,11 +888,13 @@ nsJSCID::GetService(nsISupports **_retval) else iid = NS_GET_IID(nsISupports); - nsCOMPtr srvc; - nsresult rv; + nsCOMPtr svcMgr; + nsresult rv = NS_GetServiceManager(getter_AddRefs(svcMgr)); + if (NS_FAILED(rv)) + return rv; - rv = nsServiceManager::GetService(*mDetails.GetID(), iid, - getter_AddRefs(srvc), nsnull); + nsCOMPtr srvc; + rv = svcMgr->GetService(*mDetails.GetID(), iid, getter_AddRefs(srvc)); NS_ASSERTION(NS_FAILED(rv) || srvc, "service manager returned success, but service is null!"); if(NS_FAILED(rv) || !srvc) return NS_ERROR_XPC_GS_RETURNED_FAILURE; diff --git a/layout/forms/nsIsIndexFrame.cpp b/layout/forms/nsIsIndexFrame.cpp index b5e90749e11..79c42c1b680 100644 --- a/layout/forms/nsIsIndexFrame.cpp +++ b/layout/forms/nsIsIndexFrame.cpp @@ -501,12 +501,10 @@ NS_IMETHODIMP nsIsIndexFrame::GetEncoder(nsIUnicodeEncoder** encoder) // Get Charset, get the encoder. nsICharsetConverterManager * ccm = nsnull; - rv = nsServiceManager::GetService(kCharsetConverterManagerCID , - NS_GET_IID(nsICharsetConverterManager), - (nsISupports**)&ccm); + rv = CallGetService(kCharsetConverterManagerCID, &ccm); if(NS_SUCCEEDED(rv) && (nsnull != ccm)) { rv = ccm->GetUnicodeEncoderRaw(charset.get(), encoder); - nsServiceManager::ReleaseService( kCharsetConverterManagerCID, ccm); + NS_RELEASE(ccm); if (nsnull == encoder) { rv = NS_ERROR_FAILURE; } diff --git a/layout/generic/nsTextTransformer.cpp b/layout/generic/nsTextTransformer.cpp index 60e129feed8..80f73870d64 100644 --- a/layout/generic/nsTextTransformer.cpp +++ b/layout/generic/nsTextTransformer.cpp @@ -142,8 +142,7 @@ static nsresult EnsureCaseConv() { nsresult res = NS_OK; if (!gCaseConv) { - res = nsServiceManager::GetService(kUnicharUtilCID, NS_GET_IID(nsICaseConversion), - (nsISupports**)&gCaseConv); + res = CallGetService(kUnicharUtilCID, &gCaseConv); NS_ASSERTION( NS_SUCCEEDED(res), "cannot get UnicharUtil"); NS_ASSERTION( gCaseConv != NULL, "cannot get UnicharUtil"); } @@ -158,10 +157,7 @@ nsTextTransformer::Shutdown() nsContentUtils::UnregisterPrefCallback(kWordSelectStopAtPunctuationPref, WordSelectPrefCallback, nsnull); - if (gCaseConv) { - nsServiceManager::ReleaseService(kUnicharUtilCID, gCaseConv); - gCaseConv = nsnull; - } + NS_IF_RELEASE(gCaseConv); } // For now, we have only a couple of characters to strip out. If we get diff --git a/layout/html/base/src/nsTextTransformer.cpp b/layout/html/base/src/nsTextTransformer.cpp index 60e129feed8..e69de29bb2d 100644 --- a/layout/html/base/src/nsTextTransformer.cpp +++ b/layout/html/base/src/nsTextTransformer.cpp @@ -1,1856 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#include -#include "nsCOMPtr.h" -#include "nsTextTransformer.h" -#include "nsContentUtils.h" -#include "nsIContent.h" -#include "nsIFrame.h" -#include "nsITextContent.h" -#include "nsStyleConsts.h" -#include "nsILineBreaker.h" -#include "nsIWordBreaker.h" -#include "nsIServiceManager.h" -#include "nsUnicharUtilCIID.h" -#include "nsUnicharUtils.h" -#include "nsICaseConversion.h" -#include "prenv.h" -#ifdef IBMBIDI -#include "nsLayoutAtoms.h" -#endif - - -PRBool nsTextTransformer::sWordSelectListenerPrefChecked = PR_FALSE; -PRBool nsTextTransformer::sWordSelectEatSpaceAfter = PR_FALSE; -PRBool nsTextTransformer::sWordSelectStopAtPunctuation = PR_FALSE; -static const char kWordSelectEatSpaceAfterPref[] = "layout.word_select.eat_space_to_next_word"; -static const char kWordSelectStopAtPunctuationPref[] = "layout.word_select.stop_at_punctuation"; - -// static -int -nsTextTransformer::WordSelectPrefCallback(const char* aPref, void* aClosure) -{ - sWordSelectEatSpaceAfter = nsContentUtils::GetBoolPref(kWordSelectEatSpaceAfterPref); - sWordSelectStopAtPunctuation = nsContentUtils::GetBoolPref(kWordSelectStopAtPunctuationPref); - - return 0; -} - -nsAutoTextBuffer::nsAutoTextBuffer() - : mBuffer(mAutoBuffer), - mBufferLen(NS_TEXT_TRANSFORMER_AUTO_WORD_BUF_SIZE) -{ -} - -nsAutoTextBuffer::~nsAutoTextBuffer() -{ - if (mBuffer && (mBuffer != mAutoBuffer)) { - delete [] mBuffer; - } -} - -nsresult -nsAutoTextBuffer::GrowBy(PRInt32 aAtLeast, PRBool aCopyToHead) -{ - PRInt32 newSize = mBufferLen * 2; - if (newSize < mBufferLen + aAtLeast) { - newSize = mBufferLen + aAtLeast + 100; - } - return GrowTo(newSize, aCopyToHead); -} - -nsresult -nsAutoTextBuffer::GrowTo(PRInt32 aNewSize, PRBool aCopyToHead) -{ - if (aNewSize > mBufferLen) { - PRUnichar* newBuffer = new PRUnichar[aNewSize]; - if (!newBuffer) { - return NS_ERROR_OUT_OF_MEMORY; - } - memcpy(&newBuffer[aCopyToHead ? 0 : mBufferLen], - mBuffer, sizeof(PRUnichar) * mBufferLen); - if (mBuffer != mAutoBuffer) { - delete [] mBuffer; - } - mBuffer = newBuffer; - mBufferLen = aNewSize; - } - return NS_OK; -} - -//---------------------------------------------------------------------- - -static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID); - -static nsICaseConversion* gCaseConv = nsnull; - -nsresult -nsTextTransformer::Initialize() -{ - // read in our global word selection prefs - if ( !sWordSelectListenerPrefChecked ) { - sWordSelectListenerPrefChecked = PR_TRUE; - - sWordSelectEatSpaceAfter = - nsContentUtils::GetBoolPref(kWordSelectEatSpaceAfterPref); - sWordSelectStopAtPunctuation = - nsContentUtils::GetBoolPref(kWordSelectStopAtPunctuationPref); - - nsContentUtils::RegisterPrefCallback(kWordSelectEatSpaceAfterPref, - WordSelectPrefCallback, nsnull); - nsContentUtils::RegisterPrefCallback(kWordSelectStopAtPunctuationPref, - WordSelectPrefCallback, nsnull); - } - - return NS_OK; -} -static nsresult EnsureCaseConv() -{ - nsresult res = NS_OK; - if (!gCaseConv) { - res = nsServiceManager::GetService(kUnicharUtilCID, NS_GET_IID(nsICaseConversion), - (nsISupports**)&gCaseConv); - NS_ASSERTION( NS_SUCCEEDED(res), "cannot get UnicharUtil"); - NS_ASSERTION( gCaseConv != NULL, "cannot get UnicharUtil"); - } - return res; -} - -void -nsTextTransformer::Shutdown() -{ - nsContentUtils::UnregisterPrefCallback(kWordSelectEatSpaceAfterPref, - WordSelectPrefCallback, nsnull); - nsContentUtils::UnregisterPrefCallback(kWordSelectStopAtPunctuationPref, - WordSelectPrefCallback, nsnull); - - if (gCaseConv) { - nsServiceManager::ReleaseService(kUnicharUtilCID, gCaseConv); - gCaseConv = nsnull; - } -} - -// For now, we have only a couple of characters to strip out. If we get -// any more, change this to use a bitset to lookup into. -// CH_SHY - soft hyphen (discretionary hyphen) -#ifdef IBMBIDI -// added BIDI formatting codes -#define IS_DISCARDED(_ch) \ - (((_ch) == CH_SHY) || ((_ch) == '\r') || IS_BIDI_CONTROL(_ch)) -#else -#define IS_DISCARDED(_ch) \ - (((_ch) == CH_SHY) || ((_ch) == '\r')) -#endif - - -#define MAX_UNIBYTE 127 - -MOZ_DECL_CTOR_COUNTER(nsTextTransformer) - -nsTextTransformer::nsTextTransformer(nsILineBreaker* aLineBreaker, - nsIWordBreaker* aWordBreaker, - nsPresContext* aPresContext) - : mFrag(nsnull), - mOffset(0), - mMode(eNormal), - mLineBreaker(aLineBreaker), - mWordBreaker(aWordBreaker), - mBufferPos(0), - mTextTransform(NS_STYLE_TEXT_TRANSFORM_NONE), - mFlags(0) -{ - MOZ_COUNT_CTOR(nsTextTransformer); - - mLanguageSpecificTransformType = - aPresContext->LanguageSpecificTransformType(); - -#ifdef IBMBIDI - mPresContext = aPresContext; -#endif - if (aLineBreaker == nsnull && aWordBreaker == nsnull ) - NS_ASSERTION(0, "invalid creation of nsTextTransformer"); - -#ifdef DEBUG - static PRBool firstTime = PR_TRUE; - if (firstTime) { - firstTime = PR_FALSE; - SelfTest(aLineBreaker, aWordBreaker, aPresContext); - } -#endif -} - -nsTextTransformer::~nsTextTransformer() -{ - MOZ_COUNT_DTOR(nsTextTransformer); -} - -nsresult -nsTextTransformer::Init(nsIFrame* aFrame, - nsIContent* aContent, - PRInt32 aStartingOffset, - PRBool aForceArabicShaping, - PRBool aLeaveAsAscii) -{ - /* - * If the document has Bidi content, check whether we need to do - * Arabic shaping. - * - * Does the frame contains Arabic characters - * (mCharType == eCharType_RightToLeftArabic)? - * Are we rendering character by character (aForceArabicShaping == - * PR_TRUE)? If so, we always do our own Arabic shaping, even if - * the platform has native shaping support. Otherwise, we only do - * shaping if the platform has no shaping support. - * - * We do numeric shaping in all Bidi documents. - */ - if (mPresContext->BidiEnabled()) { - mCharType = (nsCharType)NS_PTR_TO_INT32(mPresContext->PropertyTable()->GetProperty(aFrame, nsLayoutAtoms::charType)); - if (mCharType == eCharType_RightToLeftArabic) { - if (aForceArabicShaping) { - SetNeedsArabicShaping(PR_TRUE); - } - else { - if (!mPresContext->IsBidiSystem()) { - SetNeedsArabicShaping(PR_TRUE); - } - } - } - SetNeedsNumericShaping(PR_TRUE); - } - - // Get the contents text content - nsresult rv; - nsCOMPtr tc = do_QueryInterface(aContent, &rv); - if (tc.get()) { - mFrag = tc->Text(); - - // Sanitize aStartingOffset - if (aStartingOffset < 0) { - NS_WARNING("bad starting offset"); - aStartingOffset = 0; - } - else if (aStartingOffset > mFrag->GetLength()) { - NS_WARNING("bad starting offset"); - aStartingOffset = mFrag->GetLength(); - } - mOffset = aStartingOffset; - - // Get the frames text style information - const nsStyleText* styleText = aFrame->GetStyleText(); - if (NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace) { - mMode = ePreformatted; - } - else if (NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace) { - mMode = ePreWrap; - } - mTextTransform = styleText->mTextTransform; - - if (aLeaveAsAscii) { // See if the text fragment is 1-byte text - SetLeaveAsAscii(PR_TRUE); - // XXX Currently we only leave it as ascii for normal text and not for preformatted - // or preformatted wrapped text or language specific transforms - if (mFrag->Is2b() || (eNormal != mMode) || - (mLanguageSpecificTransformType != - eLanguageSpecificTransformType_None)) - // We don't step down from Unicode to ascii - SetLeaveAsAscii(PR_FALSE); - } - else - SetLeaveAsAscii(PR_FALSE); - } - return rv; -} - -//---------------------------------------------------------------------- - -// wordlen==1, contentlen=newOffset-currentOffset, isWhitespace=t -PRInt32 -nsTextTransformer::ScanNormalWhiteSpace_F() -{ - const nsTextFragment* frag = mFrag; - PRInt32 fragLen = frag->GetLength(); - PRInt32 offset = mOffset; - - for (; offset < fragLen; offset++) { - PRUnichar ch = frag->CharAt(offset); - if (!XP_IS_SPACE(ch)) { - // If character is not discardable then stop looping, otherwise - // let the discarded character collapse with the other spaces. - if (!IS_DISCARDED(ch)) { - break; - } - } - } - - // Make sure we have enough room in the transform buffer - if (mBufferPos >= mTransformBuf.mBufferLen) { - mTransformBuf.GrowBy(128); - } - - if (TransformedTextIsAscii()) { - unsigned char* bp = (unsigned char*)mTransformBuf.mBuffer; - bp[mBufferPos++] = ' '; - } else { - mTransformBuf.mBuffer[mBufferPos++] = PRUnichar(' '); - } - return offset; -} - -void -nsTextTransformer::ConvertTransformedTextToUnicode() -{ - // Go backwards over the characters and convert them. - PRInt32 lastChar = mBufferPos - 1; - unsigned char* cp1 = (unsigned char*)mTransformBuf.mBuffer + lastChar; - PRUnichar* cp2 = mTransformBuf.mBuffer + lastChar; - - NS_ASSERTION(mTransformBuf.mBufferLen >= mBufferPos, - "transform buffer is too small"); - for (PRInt32 count = mBufferPos; count > 0; count--) { - *cp2-- = PRUnichar(*cp1--); - } -} - -// wordlen==*aWordLen, contentlen=newOffset-currentOffset, isWhitespace=f -PRInt32 -nsTextTransformer::ScanNormalAsciiText_F(PRInt32* aWordLen, - PRBool* aWasTransformed) -{ - const nsTextFragment* frag = mFrag; - PRInt32 fragLen = frag->GetLength(); - PRInt32 offset = mOffset; - PRInt32 prevBufferPos = mBufferPos; - const unsigned char* cp = (const unsigned char*)frag->Get1b() + offset; - union { - unsigned char* bp1; - PRUnichar* bp2; - }; - bp2 = mTransformBuf.GetBuffer(); - if (TransformedTextIsAscii()) { - bp1 += mBufferPos; - } else { - bp2 += mBufferPos; - } - - for (; offset < fragLen; offset++) { - unsigned char ch = *cp++; - if (XP_IS_SPACE(ch)) { - break; - } - if (CH_NBSP == ch) { - ch = ' '; - *aWasTransformed = PR_TRUE; - } - else if (IS_DISCARDED(ch)) { - // Strip discarded characters from the transformed output - continue; - } - if (ch > MAX_UNIBYTE) { - // The text has a multibyte character so we can no longer leave the - // text as ascii text - SetHasMultibyte(PR_TRUE); - - if (TransformedTextIsAscii()) { - SetTransformedTextIsAscii(PR_FALSE); - *aWasTransformed = PR_TRUE; - - // Transform any existing ascii text to Unicode - if (mBufferPos > 0) { - ConvertTransformedTextToUnicode(); - bp2 = mTransformBuf.GetBuffer() + mBufferPos; - } - } - } - if (mBufferPos >= mTransformBuf.mBufferLen) { - nsresult rv = mTransformBuf.GrowBy(128); - if (NS_FAILED(rv)) { - // If we run out of space then just truncate the text - break; - } - bp2 = mTransformBuf.GetBuffer(); - if (TransformedTextIsAscii()) { - bp1 += mBufferPos; - } else { - bp2 += mBufferPos; - } - } - if (TransformedTextIsAscii()) { - *bp1++ = ch; - } else { - *bp2++ = PRUnichar(ch); - } - mBufferPos++; - } - - *aWordLen = mBufferPos - prevBufferPos; - return offset; -} - -PRInt32 -nsTextTransformer::ScanNormalAsciiText_F_ForWordBreak(PRInt32* aWordLen, - PRBool* aWasTransformed, - PRBool aIsKeyboardSelect) -{ - const nsTextFragment* frag = mFrag; - PRInt32 fragLen = frag->GetLength(); - PRInt32 offset = mOffset; - PRInt32 prevBufferPos = mBufferPos; - PRBool breakAfterThis = PR_FALSE; - const unsigned char* cp = (const unsigned char*)frag->Get1b() + offset; - union { - unsigned char* bp1; - PRUnichar* bp2; - }; - bp2 = mTransformBuf.GetBuffer(); - if (TransformedTextIsAscii()) { - bp1 += mBufferPos; - } else { - bp2 += mBufferPos; - } - PRBool readingAlphaNumeric = PR_TRUE; //only used in sWordSelectStopAtPunctuation - - // We must know if we are starting in alpha numerics. - // Treat high bit chars as alphanumeric, otherwise we get stuck on accented letters - // We can't trust isalnum() results for isalnum() - // Therefore we don't stop at non-ascii (high bit) punctuation, - // which is just fine. The punctuation we care about is low bit. - if (sWordSelectStopAtPunctuation && offset < fragLen) - readingAlphaNumeric = isalnum((unsigned char)*cp) || !IS_ASCII_CHAR(*cp); - - for (; offset < fragLen && !breakAfterThis; offset++) { - unsigned char ch = *cp++; - if (CH_NBSP == ch) { - ch = ' '; - *aWasTransformed = PR_TRUE; - if (offset == mOffset) - breakAfterThis = PR_TRUE; - else - break; - } - else if (XP_IS_SPACE(ch)) { - break; - } - else if (sWordSelectStopAtPunctuation && - readingAlphaNumeric && !isalnum(ch) && IS_ASCII_CHAR(ch)) { - if (!aIsKeyboardSelect) - break; - // For keyboard move-by-word, need to pass by at least - // one alphanumeric char before stopping at punct - readingAlphaNumeric = PR_FALSE; - } - else if (sWordSelectStopAtPunctuation && - !readingAlphaNumeric && (isalnum(ch) || !IS_ASCII_CHAR(ch))) { - // On some platforms, punctuation breaks for word selection - break; - } - else if (IS_DISCARDED(ch)) { - // Strip discarded characters from the transformed output - continue; - } - if (ch > MAX_UNIBYTE) { - // The text has a multibyte character so we can no longer leave the - // text as ascii text - SetHasMultibyte(PR_TRUE); - - if (TransformedTextIsAscii()) { - SetTransformedTextIsAscii(PR_FALSE); - *aWasTransformed = PR_TRUE; - - // Transform any existing ascii text to Unicode - if (mBufferPos > 0) { - ConvertTransformedTextToUnicode(); - bp2 = mTransformBuf.GetBuffer() + mBufferPos; - } - } - } - if (mBufferPos >= mTransformBuf.mBufferLen) { - nsresult rv = mTransformBuf.GrowBy(128); - if (NS_FAILED(rv)) { - // If we run out of space then just truncate the text - break; - } - bp2 = mTransformBuf.GetBuffer(); - if (TransformedTextIsAscii()) { - bp1 += mBufferPos; - } else { - bp2 += mBufferPos; - } - } - if (TransformedTextIsAscii()) { - *bp1++ = ch; - } else { - *bp2++ = PRUnichar(ch); - } - mBufferPos++; - } - - *aWordLen = mBufferPos - prevBufferPos; - return offset; -} - - -// wordlen==*aWordLen, contentlen=newOffset-currentOffset, isWhitespace=f -PRInt32 -nsTextTransformer::ScanNormalUnicodeText_F(PRBool aForLineBreak, - PRInt32* aWordLen, - PRBool* aWasTransformed) -{ - const nsTextFragment* frag = mFrag; - const PRUnichar* cp0 = frag->Get2b(); - PRInt32 fragLen = frag->GetLength(); -#ifdef IBMBIDI - if (*aWordLen > 0 && *aWordLen < fragLen) { - fragLen = *aWordLen; - } -#endif - PRInt32 offset = mOffset; - - PRUnichar firstChar = frag->CharAt(offset++); - -#ifdef IBMBIDI - // Need to strip BIDI controls even when those are 'firstChars'. - // This doesn't seem to produce bug 14280 (or similar bugs). - while (offset < fragLen && IS_BIDI_CONTROL(firstChar) ) { - firstChar = frag->CharAt(offset++); - } -#endif // IBMBIDI - - if (firstChar > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE); - - // Only evaluate complex breaking logic if there are more characters - // beyond the first to look at. - PRInt32 numChars = 1; - if (offset < fragLen) { - const PRUnichar* cp = cp0 + offset; - PRBool breakBetween = PR_FALSE; - if (aForLineBreak) { - mLineBreaker->BreakInBetween(&firstChar, 1, cp, (fragLen-offset), &breakBetween); - } - else { - mWordBreaker->BreakInBetween(&firstChar, 1, cp, (fragLen-offset), &breakBetween); - } - - // don't transform the first character until after BreakInBetween is called - // Kipp originally did this at the top of the function, which was too early. - // see bug 14280 - if (CH_NBSP == firstChar) { - firstChar = ' '; - *aWasTransformed = PR_TRUE; - } - nsresult rv = mTransformBuf.GrowTo(mBufferPos + 1); - if (NS_FAILED(rv)) { - *aWordLen = 0; - return offset - 1; - } - - mTransformBuf.mBuffer[mBufferPos++] = firstChar; - - if (!breakBetween) { - // Find next position - PRBool tryNextFrag; - PRUint32 next; - if (aForLineBreak) { - mLineBreaker->Next(cp0, fragLen, offset, &next, &tryNextFrag); - } - else { - mWordBreaker->NextWord(cp0, fragLen, offset, &next, &tryNextFrag); - } - numChars = (PRInt32) (next - (PRUint32) offset) + 1; - - // Since we know the number of characters we're adding grow the buffer - // now before we start copying - nsresult rv = mTransformBuf.GrowTo(mBufferPos + numChars); - if (NS_FAILED(rv)) { - numChars = mTransformBuf.GetBufferLength() - mBufferPos; - } - - offset += numChars - 1; - - // 1. convert nbsp into space - // 2. check for discarded characters - // 3. check mHasMultibyte flag - // 4. copy buffer - PRUnichar* bp = &mTransformBuf.mBuffer[mBufferPos]; - const PRUnichar* end = cp + numChars - 1; - while (cp < end) { - PRUnichar ch = *cp++; - if (CH_NBSP == ch) { - ch = ' '; - } - else if (IS_DISCARDED(ch) || (ch == 0x0a) || (ch == 0x0d)) { - // Strip discarded characters from the transformed output - numChars--; - continue; - } - if (ch > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE); - *bp++ = ch; - mBufferPos++; - } - } - } - else - { // transform the first character - // we do this here, rather than at the top of the function (like Kipp originally had it) - // because if we must call BreakInBetween, then we must do so before the transformation - // this is the case where BreakInBetween does not need to be called at all. - // see bug 14280 - if (CH_NBSP == firstChar) { - firstChar = ' '; - *aWasTransformed = PR_TRUE; - } - nsresult rv = mTransformBuf.GrowTo(mBufferPos + 1); - if (NS_FAILED(rv)) { - *aWordLen = 0; - return offset - 1; - } - mTransformBuf.mBuffer[mBufferPos++] = firstChar; - } - - *aWordLen = numChars; - return offset; -} - -// wordlen==*aWordLen, contentlen=newOffset-currentOffset, isWhitespace=t -PRInt32 -nsTextTransformer::ScanPreWrapWhiteSpace_F(PRInt32* aWordLen) -{ - const nsTextFragment* frag = mFrag; - PRInt32 fragLen = frag->GetLength(); - PRInt32 offset = mOffset; - PRUnichar* bp = mTransformBuf.GetBuffer() + mBufferPos; - PRUnichar* endbp = mTransformBuf.GetBufferEnd(); - PRInt32 prevBufferPos = mBufferPos; - - for (; offset < fragLen; offset++) { - // This function is used for both Unicode and ascii strings so don't - // make any assumptions about what kind of data it is - PRUnichar ch = frag->CharAt(offset); - if (!XP_IS_SPACE(ch) || (ch == '\t') || (ch == '\n')) { - if (IS_DISCARDED(ch)) { - // Keep looping if this is a discarded character - continue; - } - break; - } - if (bp == endbp) { - PRInt32 oldLength = bp - mTransformBuf.GetBuffer(); - nsresult rv = mTransformBuf.GrowBy(1000); - if (NS_FAILED(rv)) { - // If we run out of space (unlikely) then just chop the input - break; - } - bp = mTransformBuf.GetBuffer() + oldLength; - endbp = mTransformBuf.GetBufferEnd(); - } - *bp++ = ' '; - mBufferPos++; - } - - *aWordLen = mBufferPos - prevBufferPos; - return offset; -} - -// wordlen==*aWordLen, contentlen=newOffset-currentOffset, isWhitespace=f -PRInt32 -nsTextTransformer::ScanPreData_F(PRInt32* aWordLen, - PRBool* aWasTransformed) -{ - const nsTextFragment* frag = mFrag; - PRInt32 fragLen = frag->GetLength(); - PRInt32 offset = mOffset; - PRUnichar* bp = mTransformBuf.GetBuffer() + mBufferPos; - PRUnichar* endbp = mTransformBuf.GetBufferEnd(); - PRInt32 prevBufferPos = mBufferPos; - - for (; offset < fragLen; offset++) { - // This function is used for both Unicode and ascii strings so don't - // make any assumptions about what kind of data it is - PRUnichar ch = frag->CharAt(offset); - if ((ch == '\t') || (ch == '\n')) { - break; - } - if (CH_NBSP == ch) { - ch = ' '; - *aWasTransformed = PR_TRUE; - } - else if (IS_DISCARDED(ch)) { - continue; - } - if (ch > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE); - if (bp == endbp) { - PRInt32 oldLength = bp - mTransformBuf.GetBuffer(); - nsresult rv = mTransformBuf.GrowBy(1000); - if (NS_FAILED(rv)) { - // If we run out of space (unlikely) then just chop the input - break; - } - bp = mTransformBuf.GetBuffer() + oldLength; - endbp = mTransformBuf.GetBufferEnd(); - } - *bp++ = ch; - mBufferPos++; - } - - *aWordLen = mBufferPos - prevBufferPos; - return offset; -} - -// wordlen==*aWordLen, contentlen=newOffset-currentOffset, isWhitespace=f -PRInt32 -nsTextTransformer::ScanPreAsciiData_F(PRInt32* aWordLen, - PRBool* aWasTransformed) -{ - const nsTextFragment* frag = mFrag; - PRUnichar* bp = mTransformBuf.GetBuffer() + mBufferPos; - PRUnichar* endbp = mTransformBuf.GetBufferEnd(); - const unsigned char* cp = (const unsigned char*) frag->Get1b(); - const unsigned char* end = cp + frag->GetLength(); - PRInt32 prevBufferPos = mBufferPos; - cp += mOffset; - - while (cp < end) { - PRUnichar ch = (PRUnichar) *cp++; - if ((ch == '\t') || (ch == '\n')) { - cp--; - break; - } - if (CH_NBSP == ch) { - ch = ' '; - *aWasTransformed = PR_TRUE; - } - else if (IS_DISCARDED(ch)) { - continue; - } - if (ch > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE); - if (bp == endbp) { - PRInt32 oldLength = bp - mTransformBuf.GetBuffer(); - nsresult rv = mTransformBuf.GrowBy(1000); - if (NS_FAILED(rv)) { - // If we run out of space (unlikely) then just chop the input - break; - } - bp = mTransformBuf.GetBuffer() + oldLength; - endbp = mTransformBuf.GetBufferEnd(); - } - *bp++ = ch; - mBufferPos++; - } - - *aWordLen = mBufferPos - prevBufferPos; - return cp - ((const unsigned char*)frag->Get1b()); -} - -//---------------------------------------- - -static void -AsciiToLowerCase(unsigned char* aText, PRInt32 aWordLen) -{ - while (aWordLen-- > 0) { - *aText = tolower(*aText); - aText++; - } -} - -static void -AsciiToUpperCase(unsigned char* aText, PRInt32 aWordLen) -{ - while (aWordLen-- > 0) { - *aText = toupper(*aText); - aText++; - } -} - -#define kSzlig 0x00DF -static PRInt32 CountGermanSzlig(const PRUnichar* aText, PRInt32 len) -{ - PRInt32 i,cnt; - for(i=0,cnt=0; i= aText) ) - { - if(kSzlig == *src ) - { - *dest-- = PRUnichar('S'); - *dest-- = PRUnichar('S'); - src--; - } else { - *dest-- = *src--; - } - } -} - -void -nsTextTransformer::LanguageSpecificTransform(PRUnichar* aText, PRInt32 aLen, - PRBool* aWasTransformed) -{ - if (mLanguageSpecificTransformType == - eLanguageSpecificTransformType_Japanese) { - for (PRInt32 i = 0; i < aLen; i++) { - if (aText[i] == 0x5C) { // BACKSLASH - aText[i] = 0xA5; // YEN SIGN - SetHasMultibyte(PR_TRUE); - *aWasTransformed = PR_TRUE; - } -#if 0 - /* - * We considered doing this, but since some systems may not have fonts - * with this OVERLINE glyph, we decided not to do this. - */ - else if (aText[i] == 0x7E) { // TILDE - aText[i] = 0x203E; // OVERLINE - SetHasMultibyte(PR_TRUE); - *aWasTransformed = PR_TRUE; - } -#endif - } - } - /* we once do transformation for Korean, but later decide to remove it */ - /* see bug 88050 for more information */ -} - -PRUnichar* -nsTextTransformer::GetNextWord(PRBool aInWord, - PRInt32* aWordLenResult, - PRInt32* aContentLenResult, - PRBool* aIsWhiteSpaceResult, - PRBool* aWasTransformed, - PRBool aResetTransformBuf, - PRBool aForLineBreak, - PRBool aIsKeyboardSelect) -{ - const nsTextFragment* frag = mFrag; - PRInt32 fragLen = frag->GetLength(); -#ifdef IBMBIDI - if (*aWordLenResult > 0 && *aWordLenResult < fragLen) { - fragLen = *aWordLenResult; - } -#endif - PRInt32 offset = mOffset; - PRInt32 wordLen = 0; - PRBool isWhitespace = PR_FALSE; - PRUnichar* result = nsnull; - PRBool prevBufferPos; - PRBool skippedWhitespace = PR_FALSE; - - // Initialize OUT parameter - *aWasTransformed = PR_FALSE; - - // See if we should reset the current buffer position back to the - // beginning of the buffer - if (aResetTransformBuf) { - mBufferPos = 0; - SetTransformedTextIsAscii(LeaveAsAscii()); - } - prevBufferPos = mBufferPos; - - // Fix word breaking problem w/ PREFORMAT and PREWRAP - // for word breaking, we should really go to the normal code - if((! aForLineBreak) && (eNormal != mMode)) - mMode = eNormal; - - while (offset < fragLen) { - PRUnichar firstChar = frag->CharAt(offset); - - // Eat up any discarded characters before dispatching - if (IS_DISCARDED(firstChar)) { - offset++; - continue; - } - - switch (mMode) { - default: - case eNormal: - if (XP_IS_SPACE(firstChar)) { - offset = ScanNormalWhiteSpace_F(); - - // if this is just a '\n', and characters before and after it are CJK chars, - // we will skip this one. - if (firstChar == '\n' && - offset - mOffset == 1 && - mOffset > 0 && - offset < fragLen) - { - PRUnichar lastChar = frag->CharAt(mOffset - 1); - PRUnichar nextChar = frag->CharAt(offset); - if (IS_CJ_CHAR(lastChar) && IS_CJ_CHAR(nextChar)) { - skippedWhitespace = PR_TRUE; - --mBufferPos; - mOffset = offset; - continue; } - } - if (firstChar != ' ') { - *aWasTransformed = PR_TRUE; - } - wordLen = 1; - isWhitespace = PR_TRUE; - } - else if (CH_NBSP == firstChar && !aForLineBreak) { - wordLen = 1; - isWhitespace = PR_TRUE; - *aWasTransformed = PR_TRUE; - - // Make sure we have enough room in the transform buffer - if (mBufferPos >= mTransformBuf.mBufferLen) { - mTransformBuf.GrowBy(128); - } - - offset++; - if (TransformedTextIsAscii()) { - ((unsigned char*)mTransformBuf.mBuffer)[mBufferPos++] = ' '; - } else { - mTransformBuf.mBuffer[mBufferPos++] = PRUnichar(' '); - } - } - else if (frag->Is2b()) { -#ifdef IBMBIDI - wordLen = *aWordLenResult; -#endif - offset = ScanNormalUnicodeText_F(aForLineBreak, &wordLen, aWasTransformed); - } - else { - if (!aForLineBreak) - offset = ScanNormalAsciiText_F_ForWordBreak(&wordLen, - aWasTransformed, - aIsKeyboardSelect); - else - offset = ScanNormalAsciiText_F(&wordLen, aWasTransformed); - } - break; - - case ePreformatted: - if (('\n' == firstChar) || ('\t' == firstChar)) { - mTransformBuf.mBuffer[mBufferPos++] = firstChar; - offset++; - wordLen = 1; - isWhitespace = PR_TRUE; - } - else if (frag->Is2b()) { - offset = ScanPreData_F(&wordLen, aWasTransformed); - } - else { - offset = ScanPreAsciiData_F(&wordLen, aWasTransformed); - } - break; - - case ePreWrap: - if (XP_IS_SPACE(firstChar)) { - if (('\n' == firstChar) || ('\t' == firstChar)) { - mTransformBuf.mBuffer[mBufferPos++] = firstChar; - offset++; - wordLen = 1; - } - else { - offset = ScanPreWrapWhiteSpace_F(&wordLen); - } - isWhitespace = PR_TRUE; - } - else if (frag->Is2b()) { -#ifdef IBMBIDI - wordLen = *aWordLenResult; -#endif - offset = ScanNormalUnicodeText_F(aForLineBreak, &wordLen, aWasTransformed); - } - else { - if (!aForLineBreak) - offset = ScanNormalAsciiText_F_ForWordBreak(&wordLen, aWasTransformed, - aIsKeyboardSelect); - else - offset = ScanNormalAsciiText_F(&wordLen, aWasTransformed); - } - break; - } - - if (TransformedTextIsAscii()) { - unsigned char* wordPtr = (unsigned char*)mTransformBuf.mBuffer + prevBufferPos; - - if (!isWhitespace) { - switch (mTextTransform) { - case NS_STYLE_TEXT_TRANSFORM_CAPITALIZE: - *wordPtr = toupper(*wordPtr); - break; - case NS_STYLE_TEXT_TRANSFORM_LOWERCASE: - AsciiToLowerCase(wordPtr, wordLen); - break; - case NS_STYLE_TEXT_TRANSFORM_UPPERCASE: - AsciiToUpperCase(wordPtr, wordLen); - break; - } - NS_ASSERTION(mLanguageSpecificTransformType == - eLanguageSpecificTransformType_None, - "should not be ASCII for language specific transforms"); - } - result = (PRUnichar*)wordPtr; - - } else { - result = &mTransformBuf.mBuffer[prevBufferPos]; - - if (!isWhitespace) { - switch (mTextTransform) { - case NS_STYLE_TEXT_TRANSFORM_CAPITALIZE: - if(NS_SUCCEEDED(EnsureCaseConv())) - gCaseConv->ToTitle(result, result, wordLen, !aInWord); - // if the first character is szlig - if(kSzlig == *result) - { - if ((prevBufferPos + wordLen + 1) >= mTransformBuf.mBufferLen) { - mTransformBuf.GrowBy(128); - result = &mTransformBuf.mBuffer[prevBufferPos]; - } - PRUnichar* src = result + wordLen; - while(src>result) - { - *(src+1) = *src; - src--; - } - result[0] = PRUnichar('S'); - result[1] = PRUnichar('S'); - wordLen++; - } - break; - case NS_STYLE_TEXT_TRANSFORM_LOWERCASE: - if(NS_SUCCEEDED(EnsureCaseConv())) - gCaseConv->ToLower(result, result, wordLen); - break; - case NS_STYLE_TEXT_TRANSFORM_UPPERCASE: - { - if(NS_SUCCEEDED(EnsureCaseConv())) - gCaseConv->ToUpper(result, result, wordLen); - - // first we search for German Szlig - PRInt32 szligCnt = CountGermanSzlig(result, wordLen); - if(szligCnt > 0) { - // Make sure we have enough room in the transform buffer - if ((prevBufferPos + wordLen + szligCnt) >= mTransformBuf.mBufferLen) - { - mTransformBuf.GrowBy(128); - result = &mTransformBuf.mBuffer[prevBufferPos]; - } - ReplaceGermanSzligToSS(result, wordLen, szligCnt); - wordLen += szligCnt; - } - } - break; - } - if (mLanguageSpecificTransformType != - eLanguageSpecificTransformType_None) { - LanguageSpecificTransform(result, wordLen, aWasTransformed); - } - if (NeedsArabicShaping()) { - DoArabicShaping(result, wordLen, aWasTransformed); - } - if (NeedsNumericShaping()) { - DoNumericShaping(result, wordLen, aWasTransformed); - } - } - } - - break; - } - - *aIsWhiteSpaceResult = isWhitespace; - *aWordLenResult = wordLen; - *aContentLenResult = offset - mOffset; - - // we need to adjust the length if a '\n' has been skip between CJK chars - *aContentLenResult += (skippedWhitespace ? 1 : 0); - - // If the word length doesn't match the content length then we transformed - // the text - if ((mTextTransform != NS_STYLE_TEXT_TRANSFORM_NONE) || - (*aWordLenResult != *aContentLenResult)) { - *aWasTransformed = PR_TRUE; - mBufferPos = prevBufferPos + *aWordLenResult; - } - - mOffset = offset; - - NS_ASSERTION(mBufferPos == prevBufferPos + *aWordLenResult, "internal error"); - return result; -} - -//---------------------------------------------------------------------- - -// wordlen==1, contentlen=newOffset-currentOffset, isWhitespace=t -PRInt32 -nsTextTransformer::ScanNormalWhiteSpace_B() -{ - const nsTextFragment* frag = mFrag; - PRInt32 offset = mOffset; - - while (--offset >= 0) { - PRUnichar ch = frag->CharAt(offset); - if (!XP_IS_SPACE(ch)) { - // If character is not discardable then stop looping, otherwise - // let the discarded character collapse with the other spaces. - if (!IS_DISCARDED(ch)) { - break; - } - } - } - - mTransformBuf.mBuffer[mTransformBuf.mBufferLen - 1] = ' '; - return offset; -} - -// wordlen==*aWordLen, contentlen=newOffset-currentOffset, isWhitespace=f -PRInt32 -nsTextTransformer::ScanNormalAsciiText_B(PRInt32* aWordLen, PRBool aIsKeyboardSelect) -{ - const nsTextFragment* frag = mFrag; - PRInt32 offset = mOffset; - PRUnichar* bp = mTransformBuf.GetBufferEnd(); - PRUnichar* startbp = mTransformBuf.GetBuffer(); - - PRUnichar ch = frag->CharAt(offset - 1); - // Treat high bit chars as alphanumeric, otherwise we get stuck on accented letters - // We can't trust isalnum() results for isalnum() - // Therefore we don't stop at non-ascii (high bit) punctuation, - // which is just fine. The punctuation we care about is low bit. - PRBool readingAlphaNumeric = isalnum(ch) || !IS_ASCII_CHAR(ch); - - while (--offset >= 0) { - PRUnichar ch = frag->CharAt(offset); - if (CH_NBSP == ch) { - ch = ' '; - } - if (XP_IS_SPACE(ch)) { - break; - } - else if (IS_DISCARDED(ch)) { - continue; - } - else if (sWordSelectStopAtPunctuation && readingAlphaNumeric && - !isalnum(ch) && IS_ASCII_CHAR(ch)) { - // Break on ascii punctuation - break; - } - else if (sWordSelectStopAtPunctuation && !readingAlphaNumeric && - (isalnum(ch) || !IS_ASCII_CHAR(ch))) { - if (!aIsKeyboardSelect) - break; - readingAlphaNumeric = PR_TRUE; - } - - if (ch > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE); - if (bp == startbp) { - PRInt32 oldLength = mTransformBuf.mBufferLen; - nsresult rv = mTransformBuf.GrowBy(1000); - if (NS_FAILED(rv)) { - // If we run out of space (unlikely) then just chop the input - break; - } - bp = mTransformBuf.GetBufferEnd() - oldLength; - startbp = mTransformBuf.GetBuffer(); - } - *--bp = ch; - } - - *aWordLen = mTransformBuf.GetBufferEnd() - bp; - return offset; -} - -// wordlen==*aWordLen, contentlen=newOffset-currentOffset, isWhitespace=f -PRInt32 -nsTextTransformer::ScanNormalUnicodeText_B(PRBool aForLineBreak, - PRInt32* aWordLen) -{ - const nsTextFragment* frag = mFrag; - const PRUnichar* cp0 = frag->Get2b(); - PRInt32 offset = mOffset - 1; - - PRUnichar firstChar = frag->CharAt(offset); - -#ifdef IBMBIDI - PRInt32 limit = (*aWordLen > 0) ? *aWordLen : 0; - - while (offset > limit && IS_BIDI_CONTROL(firstChar) ) { - firstChar = frag->CharAt(--offset); - } -#endif - - mTransformBuf.mBuffer[mTransformBuf.mBufferLen - 1] = firstChar; - if (firstChar > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE); - - PRInt32 numChars = 1; - -#ifdef IBMBIDI - if (offset > limit) { -#else - if (offset > 0) { -#endif - const PRUnichar* cp = cp0 + offset; - PRBool breakBetween = PR_FALSE; - if (aForLineBreak) { - mLineBreaker->BreakInBetween(cp0, offset + 1, - mTransformBuf.GetBufferEnd()-1, 1, - &breakBetween); - } - else { - mWordBreaker->BreakInBetween(cp0, offset + 1, - mTransformBuf.GetBufferEnd()-1, 1, - &breakBetween); - } - - if (!breakBetween) { - // Find next position - PRBool tryPrevFrag; - PRUint32 prev; - if (aForLineBreak) { - mLineBreaker->Prev(cp0, offset, offset, &prev, &tryPrevFrag); - } - else { - mWordBreaker->PrevWord(cp0, offset, offset, &prev, &tryPrevFrag); - } - numChars = (PRInt32) ((PRUint32) offset - prev) + 1; - - // Grow buffer before copying - nsresult rv = mTransformBuf.GrowTo(numChars); - if (NS_FAILED(rv)) { - numChars = mTransformBuf.GetBufferLength(); - } - - // 1. convert nbsp into space - // 2. check mHasMultibyte flag - // 3. copy buffer - PRUnichar* bp = mTransformBuf.GetBufferEnd() - 1; - const PRUnichar* end = cp - numChars + 1; - while (cp > end) { - PRUnichar ch = *--cp; - if (CH_NBSP == ch) { - ch = ' '; - } - else if (IS_DISCARDED(ch)) { - continue; - } - if (ch > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE); - *--bp = ch; - } - - // Recompute offset and numChars in case we stripped something - offset = offset - numChars; - numChars = mTransformBuf.GetBufferEnd() - bp; - } - } - else - offset--; - - *aWordLen = numChars; - return offset; -} - -// wordlen==*aWordLen, contentlen=newOffset-currentOffset, isWhitespace=t -PRInt32 -nsTextTransformer::ScanPreWrapWhiteSpace_B(PRInt32* aWordLen) -{ - const nsTextFragment* frag = mFrag; - PRInt32 offset = mOffset; - PRUnichar* bp = mTransformBuf.GetBufferEnd(); - PRUnichar* startbp = mTransformBuf.GetBuffer(); - - while (--offset >= 0) { - PRUnichar ch = frag->CharAt(offset); - if (!XP_IS_SPACE(ch) || (ch == '\t') || (ch == '\n')) { - // Keep looping if this is a discarded character - if (IS_DISCARDED(ch)) { - continue; - } - break; - } - if (bp == startbp) { - PRInt32 oldLength = mTransformBuf.mBufferLen; - nsresult rv = mTransformBuf.GrowBy(1000); - if (NS_FAILED(rv)) { - // If we run out of space (unlikely) then just chop the input - break; - } - bp = mTransformBuf.GetBufferEnd() - oldLength; - startbp = mTransformBuf.GetBuffer(); - } - *--bp = ' '; - } - - *aWordLen = mTransformBuf.GetBufferEnd() - bp; - return offset; -} - -// wordlen==*aWordLen, contentlen=newOffset-currentOffset, isWhitespace=f -PRInt32 -nsTextTransformer::ScanPreData_B(PRInt32* aWordLen) -{ - const nsTextFragment* frag = mFrag; - PRInt32 offset = mOffset; - PRUnichar* bp = mTransformBuf.GetBufferEnd(); - PRUnichar* startbp = mTransformBuf.GetBuffer(); - - while (--offset >= 0) { - PRUnichar ch = frag->CharAt(offset); - if ((ch == '\t') || (ch == '\n')) { - break; - } - if (CH_NBSP == ch) { - ch = ' '; - } - else if (IS_DISCARDED(ch)) { - continue; - } - if (ch > MAX_UNIBYTE) SetHasMultibyte(PR_TRUE); - if (bp == startbp) { - PRInt32 oldLength = mTransformBuf.mBufferLen; - nsresult rv = mTransformBuf.GrowBy(1000); - if (NS_FAILED(rv)) { - // If we run out of space (unlikely) then just chop the input - offset++; - break; - } - bp = mTransformBuf.GetBufferEnd() - oldLength; - startbp = mTransformBuf.GetBuffer(); - } - *--bp = ch; - } - - *aWordLen = mTransformBuf.GetBufferEnd() - bp; - return offset; -} - -//---------------------------------------- - -PRUnichar* -nsTextTransformer::GetPrevWord(PRBool aInWord, - PRInt32* aWordLenResult, - PRInt32* aContentLenResult, - PRBool* aIsWhiteSpaceResult, - PRBool aForLineBreak, - PRBool aIsKeyboardSelect) -{ - const nsTextFragment* frag = mFrag; - PRInt32 offset = mOffset; - PRInt32 wordLen = 0; - PRBool isWhitespace = PR_FALSE; - PRUnichar* result = nsnull; - - // Fix word breaking problem w/ PREFORMAT and PREWRAP - // for word breaking, we should really go to the normal code - if((! aForLineBreak) && (eNormal != mMode)) - mMode = eNormal; - -#ifdef IBMBIDI - PRInt32 limit = (*aWordLenResult > 0) ? *aWordLenResult : 0; - while (--offset >= limit) { -#else - while (--offset >= 0) { -#endif - PRUnichar firstChar = frag->CharAt(offset); - - // Eat up any discarded characters before dispatching - if (IS_DISCARDED(firstChar)) { - continue; - } - - switch (mMode) { - default: - case eNormal: - if (XP_IS_SPACE(firstChar)) { - offset = ScanNormalWhiteSpace_B(); - wordLen = 1; - isWhitespace = PR_TRUE; - } - else if (CH_NBSP == firstChar && !aForLineBreak) { - wordLen = 1; - isWhitespace = PR_TRUE; - mTransformBuf.mBuffer[mTransformBuf.mBufferLen - 1] = ' '; - offset--; - } else if (frag->Is2b()) { -#ifdef IBMBIDI - wordLen = *aWordLenResult; -#endif - offset = ScanNormalUnicodeText_B(aForLineBreak, &wordLen); - } - else { - offset = ScanNormalAsciiText_B(&wordLen, aIsKeyboardSelect); - } - break; - - case ePreformatted: - if (('\n' == firstChar) || ('\t' == firstChar)) { - mTransformBuf.mBuffer[mTransformBuf.mBufferLen-1] = firstChar; - offset--; // make sure we overshoot - wordLen = 1; - isWhitespace = PR_TRUE; - } - else { - offset = ScanPreData_B(&wordLen); - } - break; - - case ePreWrap: - if (XP_IS_SPACE(firstChar)) { - if (('\n' == firstChar) || ('\t' == firstChar)) { - mTransformBuf.mBuffer[mTransformBuf.mBufferLen-1] = firstChar; - offset--; // make sure we overshoot - wordLen = 1; - } - else { - offset = ScanPreWrapWhiteSpace_B(&wordLen); - } - isWhitespace = PR_TRUE; - } - else if (frag->Is2b()) { -#ifdef IBMBIDI - wordLen = *aWordLenResult; -#endif - offset = ScanNormalUnicodeText_B(aForLineBreak, &wordLen); - } - else { - offset = ScanNormalAsciiText_B(&wordLen, aIsKeyboardSelect); - } - break; - } - - // Backwards scanning routines *always* overshoot by one for the - // returned offset value. - offset = offset + 1; - - result = mTransformBuf.GetBufferEnd() - wordLen; - - if (!isWhitespace) { - switch (mTextTransform) { - case NS_STYLE_TEXT_TRANSFORM_CAPITALIZE: - if(NS_SUCCEEDED(EnsureCaseConv())) - gCaseConv->ToTitle(result, result, wordLen, !aInWord); - break; - case NS_STYLE_TEXT_TRANSFORM_LOWERCASE: - if(NS_SUCCEEDED(EnsureCaseConv())) - gCaseConv->ToLower(result, result, wordLen); - break; - case NS_STYLE_TEXT_TRANSFORM_UPPERCASE: - if(NS_SUCCEEDED(EnsureCaseConv())) - gCaseConv->ToUpper(result, result, wordLen); - break; - } - } - break; - } - - *aWordLenResult = wordLen; - *aContentLenResult = mOffset - offset; - *aIsWhiteSpaceResult = isWhitespace; - - mOffset = offset; - return result; -} - -void -nsTextTransformer::DoArabicShaping(PRUnichar* aText, - PRInt32& aTextLength, - PRBool* aWasTransformed) -{ - if (aTextLength <= 0) - return; - - PRInt32 newLen; - PRBool isVisual = mPresContext->IsVisualMode(); - - nsAutoString buf; - buf.SetLength(aTextLength); - PRUnichar* buffer = buf.BeginWriting(); - - ArabicShaping(aText, buf.Length(), buffer, (PRUint32 *)&newLen, !isVisual, !isVisual); - - aTextLength = newLen; - *aWasTransformed = PR_TRUE; - - StripZeroWidthJoinControls(buffer, aText, aTextLength, aWasTransformed); -} - -void -nsTextTransformer::DoNumericShaping(PRUnichar* aText, - PRInt32& aTextLength, - PRBool* aWasTransformed) -{ - if (aTextLength <= 0) - return; - - PRUint32 bidiOptions = mPresContext->GetBidi(); - - switch (GET_BIDI_OPTION_NUMERAL(bidiOptions)) { - - case IBMBIDI_NUMERAL_HINDI: - HandleNumbers(aText, aTextLength, IBMBIDI_NUMERAL_HINDI); - break; - - case IBMBIDI_NUMERAL_ARABIC: - HandleNumbers(aText, aTextLength, IBMBIDI_NUMERAL_ARABIC); - break; - - case IBMBIDI_NUMERAL_REGULAR: - - switch (mCharType) { - - case eCharType_EuropeanNumber: - HandleNumbers(aText, aTextLength, IBMBIDI_NUMERAL_ARABIC); - break; - - case eCharType_ArabicNumber: - HandleNumbers(aText, aTextLength, IBMBIDI_NUMERAL_HINDI); - break; - - default: - break; - } - break; - - case IBMBIDI_NUMERAL_HINDICONTEXT: - if (((GET_BIDI_OPTION_DIRECTION(bidiOptions)==IBMBIDI_TEXTDIRECTION_RTL) && - (IS_ARABIC_DIGIT (aText[0]))) || - (eCharType_ArabicNumber == mCharType)) - HandleNumbers(aText, aTextLength, IBMBIDI_NUMERAL_HINDI); - else if (eCharType_EuropeanNumber == mCharType) - HandleNumbers(aText, aTextLength, IBMBIDI_NUMERAL_ARABIC); - break; - - case IBMBIDI_NUMERAL_NOMINAL: - default: - break; - } -} - -void -nsTextTransformer::StripZeroWidthJoinControls(PRUnichar* aSource, - PRUnichar* aTarget, - PRInt32& aTextLength, - PRBool* aWasTransformed) -{ - PRUnichar *src, *dest; - PRInt32 stripped = 0; - - src = aSource; - dest = aTarget; - - for (PRInt32 i = 0; i < aTextLength; ++i) { - while (*src == CH_ZWNJ || *src == CH_ZWJ) { - ++stripped; - ++src; - *aWasTransformed = PR_TRUE; - } - *dest++ = *src++; - } - aTextLength -= stripped; -} - -//---------------------------------------------------------------------- -// Self test logic for this class. This will (hopefully) make sure -// that the forward and backward word iterator methods continue to -// function as people change things... - -#ifdef DEBUG -struct SelfTestSection { - int length; - int* data; -}; - -#define NUM_MODES 3 - -struct SelfTestData { - const PRUnichar* text; - SelfTestSection modes[NUM_MODES]; -}; - -static PRUint8 preModeValue[NUM_MODES] = { - NS_STYLE_WHITESPACE_NORMAL, - NS_STYLE_WHITESPACE_PRE, - NS_STYLE_WHITESPACE_MOZ_PRE_WRAP -}; - -static PRUnichar test1text[] = { - 'o', 'n', 'c', 'e', ' ', 'u', 'p', 'o', 'n', '\t', - 'a', ' ', 's', 'h', 'o', 'r', 't', ' ', 't', 'i', 'm', 'e', 0 -}; -static int test1Results[] = { 4, 1, 4, 1, 1, 1, 5, 1, 4 }; -static int test1PreResults[] = { 9, 1, 12 }; -static int test1PreWrapResults[] = { 4, 1, 4, 1, 1, 1, 5, 1, 4 }; - -static PRUnichar test2text[] = { - 0xF6, 'n', 'c', 'e', ' ', 0xFB, 'p', 'o', 'n', '\t', - 0xE3, ' ', 's', 'h', 0xF3, 'r', 't', ' ', 't', 0xEE, 'm', 'e', ' ', 0 -}; -static int test2Results[] = { 4, 1, 4, 1, 1, 1, 5, 1, 4, 1 }; -static int test2PreResults[] = { 9, 1, 13 }; -static int test2PreWrapResults[] = { 4, 1, 4, 1, 1, 1, 5, 1, 4, 1 }; - -static PRUnichar test3text[] = { - 0x0152, 'n', 'c', 'e', ' ', 'x', 'y', '\t', 'z', 'y', ' ', 0 -}; -static int test3Results[] = { 4, 1, 2, 1, 2, 1, }; -static int test3PreResults[] = { 7, 1, 3, }; -static int test3PreWrapResults[] = { 4, 1, 2, 1, 2, 1, }; - -static PRUnichar test4text[] = { - 'o', 'n', CH_SHY, 'c', 'e', ' ', CH_SHY, ' ', 'u', 'p', 'o', 'n', '\t', - 'a', ' ', 's', 'h', 'o', 'r', 't', ' ', 't', 'i', 'm', 'e', 0 -}; -static int test4Results[] = { 4, 1, 4, 1, 1, 1, 5, 1, 4 }; -static int test4PreResults[] = { 10, 1, 12 }; -static int test4PreWrapResults[] = { 4, 2, 4, 1, 1, 1, 5, 1, 4 }; - -static PRUnichar test5text[] = { - CH_SHY, 0 -}; -static int test5Results[] = { 0 }; -static int test5PreResults[] = { 0 }; -static int test5PreWrapResults[] = { 0 }; - -#if 0 -static PRUnichar test6text[] = { - 0x30d5, 0x30b8, 0x30c6, 0x30ec, 0x30d3, 0x306e, 0x97f3, 0x697d, - 0x756a, 0x7d44, 0x300c, 'H', 'E', 'Y', '!', ' ', 'H', 'E', 'Y', '!', - '\t', 'H', 'E', 'Y', '!', 0x300d, 0x306e, 0x30db, 0x30fc, 0x30e0, - 0x30da, 0x30fc, 0x30b8, 0x3002, 0 -}; -static int test6Results[] = { 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - 5, 1, 4, 1, 5, - 1, 2, 1, 2, 2 }; -static int test6PreResults[] = { 20, 1, 13 }; -static int test6PreWrapResults[] = { 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - 5, 1, 4, 1, 5, - 1, 2, 1, 2, 2 }; -#endif - -static SelfTestData tests[] = { - { test1text, - { { sizeof(test1Results)/sizeof(int), test1Results, }, - { sizeof(test1PreResults)/sizeof(int), test1PreResults, }, - { sizeof(test1PreWrapResults)/sizeof(int), test1PreWrapResults, } } - }, - { test2text, - { { sizeof(test2Results)/sizeof(int), test2Results, }, - { sizeof(test2PreResults)/sizeof(int), test2PreResults, }, - { sizeof(test2PreWrapResults)/sizeof(int), test2PreWrapResults, } } - }, - { test3text, - { { sizeof(test3Results)/sizeof(int), test3Results, }, - { sizeof(test3PreResults)/sizeof(int), test3PreResults, }, - { sizeof(test3PreWrapResults)/sizeof(int), test3PreWrapResults, } } - }, - { test4text, - { { sizeof(test4Results)/sizeof(int), test4Results, }, - { sizeof(test4PreResults)/sizeof(int), test4PreResults, }, - { sizeof(test4PreWrapResults)/sizeof(int), test4PreWrapResults, } } - }, - { test5text, - { { sizeof(test5Results)/sizeof(int), test5Results, }, - { sizeof(test5PreResults)/sizeof(int), test5PreResults, }, - { sizeof(test5PreWrapResults)/sizeof(int), test5PreWrapResults, } } - }, -#if 0 - { test6text, - { { sizeof(test6Results)/sizeof(int), test6Results, }, - { sizeof(test6PreResults)/sizeof(int), test6PreResults, }, - { sizeof(test6PreWrapResults)/sizeof(int), test6PreWrapResults, } } - }, -#endif -}; - -#define NUM_TESTS (sizeof(tests) / sizeof(tests[0])) - -void -nsTextTransformer::SelfTest(nsILineBreaker* aLineBreaker, - nsIWordBreaker* aWordBreaker, - nsPresContext* aPresContext) -{ - PRBool gNoisy = PR_FALSE; - if (PR_GetEnv("GECKO_TEXT_TRANSFORMER_NOISY_SELF_TEST")) { - gNoisy = PR_TRUE; - } - - PRBool error = PR_FALSE; - PRInt32 testNum = 0; - SelfTestData* st = tests; - SelfTestData* last = st + NUM_TESTS; - for (; st < last; st++) { - PRUnichar* bp; - PRInt32 wordLen, contentLen; - PRBool ws, transformed; - - PRBool isAsciiTest = PR_TRUE; - const PRUnichar* cp = st->text; - while (*cp) { - if (*cp > 255) { - isAsciiTest = PR_FALSE; - break; - } - cp++; - } - - nsTextFragment frag(st->text); - nsTextTransformer tx(aLineBreaker, aWordBreaker, aPresContext); - - for (PRInt32 preMode = 0; preMode < NUM_MODES; preMode++) { - // Do forwards test - if (gNoisy) { - nsAutoString uc2(st->text); - printf("%s forwards test: '", isAsciiTest ? "ascii" : "unicode"); - fputs(NS_ConvertUCS2toUTF8(uc2).get(), stdout); - printf("'\n"); - } - tx.Init2(&frag, 0, preModeValue[preMode], NS_STYLE_TEXT_TRANSFORM_NONE); - - int* expectedResults = st->modes[preMode].data; - int resultsLen = st->modes[preMode].length; - -#ifdef IBMBIDI - wordLen = -1; -#endif - while ((bp = tx.GetNextWord(PR_FALSE, &wordLen, &contentLen, &ws, &transformed))) { - if (gNoisy) { - nsAutoString tmp(bp, wordLen); - printf(" '"); - fputs(NS_ConvertUCS2toUTF8(tmp).get(), stdout); - printf("': ws=%s wordLen=%d (%d) contentLen=%d (offset=%d)\n", - ws ? "yes" : "no", - wordLen, *expectedResults, contentLen, tx.mOffset); - } - if (*expectedResults != wordLen) { - error = PR_TRUE; - break; - } - expectedResults++; -#ifdef IBMBIDI - wordLen = -1; -#endif - } - if (expectedResults != st->modes[preMode].data + resultsLen) { - if (st->modes[preMode].data[0] != 0) { - error = PR_TRUE; - } - } - - // Do backwards test - if (gNoisy) { - nsAutoString uc2(st->text); - printf("%s backwards test: '", isAsciiTest ? "ascii" : "unicode"); - fputs(NS_ConvertUCS2toUTF8(uc2).get(), stdout); - printf("'\n"); - } - tx.Init2(&frag, frag.GetLength(), NS_STYLE_WHITESPACE_NORMAL, - NS_STYLE_TEXT_TRANSFORM_NONE); - expectedResults = st->modes[preMode].data + resultsLen; -#ifdef IBMBIDI - wordLen = -1; -#endif - while ((bp = tx.GetPrevWord(PR_FALSE, &wordLen, &contentLen, &ws))) { - --expectedResults; - if (gNoisy) { - nsAutoString tmp(bp, wordLen); - printf(" '"); - fputs(NS_ConvertUCS2toUTF8(tmp).get(), stdout); - printf("': ws=%s wordLen=%d contentLen=%d (offset=%d)\n", - ws ? "yes" : "no", - wordLen, contentLen, tx.mOffset); - } - if (*expectedResults != wordLen) { - error = PR_TRUE; - break; - } -#ifdef IBMBIDI - wordLen = -1; -#endif - } - if (expectedResults != st->modes[preMode].data) { - if (st->modes[preMode].data[0] != 0) { - error = PR_TRUE; - } - } - - if (error) { - fprintf(stderr, "nsTextTransformer: self test %d failed\n", testNum); - } - else if (gNoisy) { - fprintf(stdout, "nsTextTransformer: self test %d succeeded\n", testNum); - } - - testNum++; - } - } - if (error) { - NS_ABORT(); - } -} - -nsresult -nsTextTransformer::Init2(const nsTextFragment* aFrag, - PRInt32 aStartingOffset, - PRUint8 aWhiteSpace, - PRUint8 aTextTransform) -{ - mFrag = aFrag; - - // Sanitize aStartingOffset - if (aStartingOffset < 0) { - NS_WARNING("bad starting offset"); - aStartingOffset = 0; - } - else if (aStartingOffset > mFrag->GetLength()) { - NS_WARNING("bad starting offset"); - aStartingOffset = mFrag->GetLength(); - } - mOffset = aStartingOffset; - - // Get the frames text style information - if (NS_STYLE_WHITESPACE_PRE == aWhiteSpace) { - mMode = ePreformatted; - } - else if (NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == aWhiteSpace) { - mMode = ePreWrap; - } - mTextTransform = aTextTransform; - - return NS_OK; -} -#endif /* DEBUG */ diff --git a/layout/html/forms/src/nsIsIndexFrame.cpp b/layout/html/forms/src/nsIsIndexFrame.cpp index b5e90749e11..e69de29bb2d 100644 --- a/layout/html/forms/src/nsIsIndexFrame.cpp +++ b/layout/html/forms/src/nsIsIndexFrame.cpp @@ -1,604 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIsIndexFrame.h" - -#include "nsIContent.h" -#include "prtypes.h" -#include "nsIAtom.h" -#include "nsPresContext.h" -#include "nsIHTMLContent.h" -#include "nsHTMLAtoms.h" -#include "nsIPresState.h" -#include "nsWidgetsCID.h" -#include "nsIComponentManager.h" -#include "nsIView.h" -#include "nsHTMLParts.h" -#include "nsIDOMHTMLInputElement.h" -#include "nsINameSpaceManager.h" -#include "nsCOMPtr.h" -#include "nsISupportsArray.h" -#include "nsIDOMElement.h" -#include "nsIDOMDocument.h" -#include "nsIDocument.h" -#include "nsIPresShell.h" -#include "nsIDOMHTMLInputElement.h" -#include "nsIStatefulFrame.h" -#include "nsXPCOM.h" -#include "nsISupportsPrimitives.h" -#include "nsIComponentManager.h" -#include "nsITextContent.h" -#include "nsHTMLParts.h" -#include "nsLinebreakConverter.h" -#include "nsILinkHandler.h" -#include "nsIHTMLDocument.h" -#include "nsXPIDLString.h" -#include "nsReadableUtils.h" -#include "nsNetUtil.h" -#include "nsICharsetConverterManager.h" -#include "nsEscape.h" -#include "nsIDOMKeyListener.h" -#include "nsIDOMKeyEvent.h" -#include "nsIFormControlFrame.h" -#include "nsINodeInfo.h" -#include "nsIDOMEventReceiver.h" -#include "nsContentCID.h" -#include "nsNodeInfoManager.h" -#include "nsContentCreatorFunctions.h" - -static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); - -nsresult -NS_NewIsIndexFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) -{ - NS_PRECONDITION(aNewFrame, "null OUT ptr"); - if (nsnull == aNewFrame) { - return NS_ERROR_NULL_POINTER; - } - nsIsIndexFrame* it = new (aPresShell) nsIsIndexFrame(); - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - *aNewFrame = it; - return NS_OK; -} - -nsIsIndexFrame::nsIsIndexFrame() -{ - //Shrink the area around it's contents - SetFlags(NS_BLOCK_SHRINK_WRAP | NS_BLOCK_SPACE_MGR); -} - -nsIsIndexFrame::~nsIsIndexFrame() -{ - // remove ourself as a listener of the text control (bug 40533) - if (mInputContent) { - nsCOMPtr reciever(do_QueryInterface(mInputContent)); - reciever->RemoveEventListenerByIID(this, NS_GET_IID(nsIDOMKeyListener)); - } -} - -NS_IMETHODIMP -nsIsIndexFrame::Paint(nsPresContext* aPresContext, - nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect, - nsFramePaintLayer aWhichLayer, - PRUint32 aFlags) -{ - PRBool isVisible; - if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_TRUE, &isVisible)) && !isVisible) { - return NS_OK; - } - return nsAreaFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); -} - -NS_IMETHODIMP -nsIsIndexFrame::UpdatePromptLabel() -{ - if (!mTextContent) return NS_ERROR_UNEXPECTED; - - nsresult result = NS_OK; - - // Get the text from the "prompt" attribute. - // If it is zero length, set it to a default value (localized) - nsAutoString prompt; - if (mContent) { - nsCOMPtr htmlContent = do_QueryInterface(mContent, &result); - if ((NS_OK == result) && htmlContent) { - nsHTMLValue value; - result = htmlContent->GetHTMLAttribute(nsHTMLAtoms::prompt, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(prompt); - } - } - } - } - if (prompt.IsEmpty()) { - // Generate localized label. - // 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); - } - - mTextContent->SetText(prompt, PR_TRUE); - - return NS_OK; -} - -NS_IMETHODIMP -nsIsIndexFrame::GetInputFrame(nsPresContext* aPresContext, - nsIFormControlFrame** oFrame) -{ - nsIPresShell *presShell = aPresContext->GetPresShell(); - if (!mInputContent) NS_WARNING("null content - cannot restore state"); - if (presShell && mInputContent) { - nsIFrame *frame; - presShell->GetPrimaryFrameFor(mInputContent, &frame); - if (frame) { - return frame->QueryInterface(NS_GET_IID(nsIFormControlFrame), (void**) oFrame); - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsIsIndexFrame::GetInputValue(nsPresContext* aPresContext, - nsString& oString) -{ - nsIFormControlFrame* frame = nsnull; - GetInputFrame(aPresContext, &frame); - if (frame) { - ((nsNewFrame*)frame)->GetValue(oString, PR_FALSE); - } - return NS_OK; -} - -NS_IMETHODIMP -nsIsIndexFrame::SetInputValue(nsPresContext* aPresContext, - const nsString aString) -{ - nsIFormControlFrame* frame = nsnull; - GetInputFrame(aPresContext, &frame); - if (frame) { - ((nsNewFrame*)frame)->SetValue(aString); - } - return NS_OK; -} - -void -nsIsIndexFrame::SetFocus(PRBool aOn, PRBool aRepaint) -{ - nsIFormControlFrame* frame = nsnull; - GetInputFrame(mPresContext, &frame); - if (frame) { - frame->SetFocus(aOn, aRepaint); - } -} - -NS_IMETHODIMP -nsIsIndexFrame::CreateAnonymousContent(nsPresContext* aPresContext, - nsISupportsArray& aChildList) -{ - nsresult result; - - // Get the node info manager (used to create hr's and input's) - nsCOMPtr doc = mContent->GetDocument(); - nsNodeInfoManager *nimgr = doc->NodeInfoManager(); - - // Create an hr - nsCOMPtr hrInfo; - nimgr->GetNodeInfo(nsHTMLAtoms::hr, nsnull, kNameSpaceID_None, - getter_AddRefs(hrInfo)); - - nsCOMPtr prehr; - result = NS_NewHTMLElement(getter_AddRefs(prehr), hrInfo); - NS_ENSURE_SUCCESS(result, result); - - result = aChildList.AppendElement(prehr); - - // Add a child text content node for the label - if (NS_SUCCEEDED(result)) { - nsCOMPtr labelContent; - NS_NewTextNode(getter_AddRefs(labelContent)); - if (labelContent) { - // set the value of the text node and add it to the child list - mTextContent.swap(labelContent); - UpdatePromptLabel(); - aChildList.AppendElement(mTextContent); - } - } - - // Create text input field - nsCOMPtr inputInfo; - nimgr->GetNodeInfo(nsHTMLAtoms::input, nsnull, kNameSpaceID_None, - getter_AddRefs(inputInfo)); - - result = NS_NewHTMLElement(getter_AddRefs(mInputContent), inputInfo); - NS_ENSURE_SUCCESS(result, result); - - mInputContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::type, NS_LITERAL_STRING("text"), PR_FALSE); - - aChildList.AppendElement(mInputContent); - - // Register as an event listener to submit on Enter press - nsCOMPtr receiver(do_QueryInterface(mInputContent)); - receiver->AddEventListenerByIID(this, NS_GET_IID(nsIDOMKeyListener)); - - // Create an hr - nsCOMPtr posthr; - result = NS_NewHTMLElement(getter_AddRefs(posthr), hrInfo); - NS_ENSURE_SUCCESS(result, result); - - aChildList.AppendElement(posthr); - - return result; -} - -// Frames are not refcounted, no need to AddRef -NS_IMETHODIMP -nsIsIndexFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) -{ - NS_PRECONDITION(0 != aInstancePtr, "null ptr"); - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } else if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) { - *aInstancePtr = (void*)(nsIAnonymousContentCreator*) this; - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) { - *aInstancePtr = (void*)(nsIStatefulFrame*) this; - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIDOMKeyListener))) { - *aInstancePtr = (void*)(nsIDOMKeyListener*) this; - return NS_OK; - } - return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); -} - -void -nsIsIndexFrame::ScrollIntoView(nsPresContext* aPresContext) -{ - if (aPresContext) { - nsIPresShell *presShell = aPresContext->GetPresShell(); - if (presShell) { - presShell->ScrollFrameIntoView(this, - NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE,NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE); - } - } -} - - -NS_IMETHODIMP nsIsIndexFrame::Reflow(nsPresContext* aPresContext, - nsHTMLReflowMetrics& aDesiredSize, - const nsHTMLReflowState& aReflowState, - nsReflowStatus& aStatus) -{ - DO_GLOBAL_REFLOW_COUNT("nsIsIndexFrame", aReflowState.reason); - DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); - - // The Areaframe takes care of all our reflow - // (except for when style is used to change its size?) - nsresult rv = nsAreaFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus); - if (aDesiredSize.mComputeMEW) { - aDesiredSize.SetMEWToActualWidth(aReflowState.mStylePosition->mWidth.GetUnit()); - } - NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); - return rv; -} - -NS_IMETHODIMP -nsIsIndexFrame::AttributeChanged(nsPresContext* aPresContext, - nsIContent* aChild, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aModType) -{ - nsresult rv = NS_OK; - if (nsHTMLAtoms::prompt == aAttribute) { - rv = UpdatePromptLabel(); - } else { - rv = nsAreaFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aModType); - } - return rv; -} - - -nsresult -nsIsIndexFrame::KeyPress(nsIDOMEvent* aEvent) -{ - nsCOMPtr keyEvent = do_QueryInterface(aEvent); - if (keyEvent) { - PRUint32 code; - keyEvent->GetKeyCode(&code); - if (code == 0) { - keyEvent->GetCharCode(&code); - } - if (nsIDOMKeyEvent::DOM_VK_RETURN == code) { - OnSubmit(mPresContext); - aEvent->PreventDefault(); // XXX Needed? - } - } - - return NS_OK; -} - -#ifdef NS_DEBUG -NS_IMETHODIMP -nsIsIndexFrame::GetFrameName(nsAString& aResult) const -{ - return MakeFrameName(NS_LITERAL_STRING("IsIndex"), aResult); -} -#endif - -// submission -// much of this is cut and paste from nsFormFrame::OnSubmit -NS_IMETHODIMP -nsIsIndexFrame::OnSubmit(nsPresContext* aPresContext) -{ - if (!mContent || !mInputContent) { - return NS_ERROR_UNEXPECTED; - } - - nsresult result = NS_OK; - - // Begin ProcessAsURLEncoded - nsAutoString data; - - nsCOMPtr encoder; - if(NS_FAILED(GetEncoder(getter_AddRefs(encoder)))) // Non-fatal error - encoder = nsnull; - - nsAutoString value; - GetInputValue(aPresContext, value); - URLEncode(value, encoder, data); - // End ProcessAsURLEncoded - - // make the url string - nsILinkHandler *handler = aPresContext->GetLinkHandler(); - - nsAutoString href; - - // Get the document. - // We'll need it now to form the URL we're submitting to. - // We'll also need it later to get the DOM window when notifying form submit observers (bug 33203) - nsCOMPtr document = mContent->GetDocument(); - if (!document) return NS_OK; // No doc means don't submit, see Bug 28988 - - // Resolve url to an absolute url - nsIURI *docURL = document->GetBaseURI(); - if (!docURL) { - NS_ERROR("No Base URL found in Form Submit!\n"); - return NS_OK; // No base URL -> exit early, see Bug 30721 - } - - // If an action is not specified and we are inside - // a HTML document then reload the URL. This makes us - // compatible with 4.x browsers. - // If we are in some other type of document such as XML or - // XUL, do nothing. This prevents undesirable reloading of - // a document inside XUL. - - nsresult rv; - nsCOMPtr htmlDoc; - htmlDoc = do_QueryInterface(document, &rv); - if (NS_FAILED(rv)) { - // Must be a XML, XUL or other non-HTML document type - // so do nothing. - return NS_OK; - } - - // Necko's MakeAbsoluteURI doesn't reuse the baseURL's rel path if it is - // passed a zero length rel path. - nsCAutoString relPath; - docURL->GetSpec(relPath); - if (!relPath.IsEmpty()) { - CopyUTF8toUTF16(relPath, href); - - // If re-using the same URL, chop off old query string (bug 25330) - PRInt32 queryStart = href.FindChar('?'); - if (kNotFound != queryStart) { - href.Truncate(queryStart); - } - } else { - NS_ERROR("Rel path couldn't be formed in form submit!\n"); - return NS_ERROR_OUT_OF_MEMORY; - } - - // Add the URI encoded form values to the URI - // Get the scheme of the URI. - nsCOMPtr actionURL; - nsXPIDLCString scheme; - PRBool isJSURL = PR_FALSE; - const nsACString &docCharset = document->GetDocumentCharacterSet(); - const nsPromiseFlatCString& flatDocCharset = PromiseFlatCString(docCharset); - - if (NS_SUCCEEDED(result = NS_NewURI(getter_AddRefs(actionURL), href, - flatDocCharset.get(), - docURL))) { - result = actionURL->SchemeIs("javascript", &isJSURL); - } - // Append the URI encoded variable/value pairs for GET's - if (!isJSURL) { // Not for JS URIs, see bug 26917 - if (href.FindChar('?') == kNotFound) { // Add a ? if needed - href.Append(PRUnichar('?')); - } else { // Adding to existing query string - if (href.Last() != '&' && href.Last() != '?') { // Add a & if needed - href.Append(PRUnichar('&')); - } - } - href.Append(data); - } - nsCOMPtr uri; - result = NS_NewURI(getter_AddRefs(uri), href, - flatDocCharset.get(), docURL); - if (NS_FAILED(result)) return result; - - // Now pass on absolute url to the click handler - if (handler) { - handler->OnLinkClick(mContent, eLinkVerb_Replace, - uri, - nsnull, nsnull); - } - return result; -} - -void nsIsIndexFrame::GetSubmitCharset(nsCString& oCharset) -{ - oCharset.AssignLiteral("UTF-8"); // default to utf-8 - // XXX - // We may want to get it from the HTML 4 Accept-Charset attribute first - // see 17.3 The FORM element in HTML 4 for details - - // Get the charset from document - nsIDocument* doc = mContent->GetDocument(); - if (doc) { - oCharset = doc->GetDocumentCharacterSet(); - } -} - -NS_IMETHODIMP nsIsIndexFrame::GetEncoder(nsIUnicodeEncoder** encoder) -{ - *encoder = nsnull; - nsCAutoString charset; - nsresult rv = NS_OK; - GetSubmitCharset(charset); - - // Get Charset, get the encoder. - nsICharsetConverterManager * ccm = nsnull; - rv = nsServiceManager::GetService(kCharsetConverterManagerCID , - NS_GET_IID(nsICharsetConverterManager), - (nsISupports**)&ccm); - if(NS_SUCCEEDED(rv) && (nsnull != ccm)) { - rv = ccm->GetUnicodeEncoderRaw(charset.get(), encoder); - nsServiceManager::ReleaseService( kCharsetConverterManagerCID, ccm); - if (nsnull == encoder) { - rv = NS_ERROR_FAILURE; - } - if (NS_SUCCEEDED(rv)) { - rv = (*encoder)->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, (PRUnichar)'?'); - } - } - return NS_OK; -} - -// XXX i18n helper routines -char* -nsIsIndexFrame::UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen, nsIUnicodeEncoder* encoder) -{ - char* res = nsnull; - if(NS_SUCCEEDED(encoder->Reset())) - { - PRInt32 maxByteLen = 0; - if(NS_SUCCEEDED(encoder->GetMaxLength(aSrc, (PRInt32) aLen, &maxByteLen))) - { - res = new char[maxByteLen+1]; - if(nsnull != res) - { - PRInt32 reslen = maxByteLen; - PRInt32 reslen2 ; - PRInt32 srclen = aLen; - encoder->Convert(aSrc, &srclen, res, &reslen); - reslen2 = maxByteLen-reslen; - encoder->Finish(res+reslen, &reslen2); - res[reslen+reslen2] = '\0'; - } - } - - } - return res; -} - -// XXX i18n helper routines -void -nsIsIndexFrame::URLEncode(const nsString& aString, nsIUnicodeEncoder* encoder, nsString& oString) -{ - char* inBuf = nsnull; - if(encoder) - inBuf = UnicodeToNewBytes(aString.get(), aString.Length(), encoder); - - if(nsnull == inBuf) - inBuf = ToNewCString(aString); - - // convert to CRLF breaks - char* convertedBuf = nsLinebreakConverter::ConvertLineBreaks(inBuf, - nsLinebreakConverter::eLinebreakAny, nsLinebreakConverter::eLinebreakNet); - delete [] inBuf; - - char* outBuf = nsEscape(convertedBuf, url_XPAlphas); - oString.AssignASCII(outBuf); - nsCRT::free(outBuf); - nsMemory::Free(convertedBuf); -} - -//---------------------------------------------------------------------- -// nsIStatefulFrame -//---------------------------------------------------------------------- -NS_IMETHODIMP -nsIsIndexFrame::SaveState(nsPresContext* aPresContext, nsIPresState** aState) -{ - NS_ENSURE_ARG_POINTER(aState); - - // Get the value string - nsAutoString stateString; - nsresult res = GetInputValue(aPresContext, stateString); - NS_ENSURE_SUCCESS(res, res); - - if (! stateString.IsEmpty()) { - - // Construct a pres state and store value in it. - res = NS_NewPresState(aState); - NS_ENSURE_SUCCESS(res, res); - res = (*aState)->SetStateProperty(NS_LITERAL_STRING("value"), stateString); - } - - return res; -} - -NS_IMETHODIMP -nsIsIndexFrame::RestoreState(nsPresContext* aPresContext, nsIPresState* aState) -{ - NS_ENSURE_ARG_POINTER(aState); - - // Set the value to the stored state. - nsAutoString stateString; - nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("value"), stateString); - NS_ENSURE_SUCCESS(res, res); - - return SetInputValue(aPresContext, stateString); -} diff --git a/mailnews/mime/src/mimedrft.cpp b/mailnews/mime/src/mimedrft.cpp index 12b26b564f6..87818fac396 100644 --- a/mailnews/mime/src/mimedrft.cpp +++ b/mailnews/mime/src/mimedrft.cpp @@ -1655,7 +1655,7 @@ mime_parse_stream_complete (nsMIMESession *stream) // Release the prefs service MimeObject *obj = (mdd ? mdd->obj : 0); if ( (obj) && (obj->options) && (obj->options->prefs) ) - nsServiceManager::ReleaseService(kPrefCID, obj->options->prefs); + obj->options->prefs->Release(); mdd->identity = nsnull; PR_Free(mdd->url_name); @@ -2107,8 +2107,8 @@ mime_bridge_create_draft_stream( mdd->options->decompose_file_output_fn = mime_decompose_file_output_fn; mdd->options->decompose_file_close_fn = mime_decompose_file_close_fn; - rv = nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), (nsISupports**)&(mdd->options->prefs)); - if (! (mdd->options->prefs && NS_SUCCEEDED(rv))) + rv = CallGetService(kPrefCID, &(mdd->options->prefs)); + if (NS_FAILED(rv)) goto FAIL; #ifdef ENABLE_SMIME diff --git a/mailnews/mime/src/mimei.cpp b/mailnews/mime/src/mimei.cpp index ce6d67c267d..d5f34b2b11f 100644 --- a/mailnews/mime/src/mimei.cpp +++ b/mailnews/mime/src/mimei.cpp @@ -222,7 +222,6 @@ mime_locate_external_content_handler(const char *content_type, contentTypeHandlerInitStruct *ctHandlerInfo) { MimeObjectClass *newObj = NULL; - nsCID classID = {0}; char lookupID[256]; nsCOMPtr ctHandler; nsresult rv; diff --git a/mailnews/mime/src/mimemoz2.cpp b/mailnews/mime/src/mimemoz2.cpp index 0f3aa55a043..358949bb207 100644 --- a/mailnews/mime/src/mimemoz2.cpp +++ b/mailnews/mime/src/mimemoz2.cpp @@ -956,7 +956,7 @@ mime_display_stream_complete (nsMIMESession *stream) // Release the prefs service if ( (obj->options) && (obj->options->prefs) ) - nsServiceManager::ReleaseService(kPrefCID, obj->options->prefs); + obj->options->prefs->Release(); if ((obj->options) && (obj->options->headers == MimeHeadersOnly)) abortNow = PR_TRUE; @@ -1537,7 +1537,7 @@ mime_bridge_create_display_stream( // memset(msd->options, 0, sizeof(*msd->options)); msd->options->format_out = format_out; // output format - rv = nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), (nsISupports**)&(msd->options->prefs)); + rv = CallGetService(kPrefCID, &(msd->options->prefs)); if (! (msd->options->prefs && NS_SUCCEEDED(rv))) { PR_FREEIF(msd); @@ -1548,7 +1548,7 @@ mime_bridge_create_display_stream( rv = CallCreateInstance(MOZ_TXTTOHTMLCONV_CONTRACTID, &(msd->options->conv)); if (NS_FAILED(rv)) { - nsServiceManager::ReleaseService(kPrefCID, msd->options->prefs); + msd->options->prefs->Release(); PR_FREEIF(msd); return nsnull; } diff --git a/modules/oji/src/jvmmgr.cpp b/modules/oji/src/jvmmgr.cpp index dd106a74060..930e41e78a5 100644 --- a/modules/oji/src/jvmmgr.cpp +++ b/modules/oji/src/jvmmgr.cpp @@ -58,8 +58,7 @@ extern nsPluginManager* thePluginManager; PR_IMPLEMENT(void) JVM_ReleaseJVMMgr(nsJVMManager* mgr) { - nsresult err = nsServiceManager::ReleaseService(kJVMManagerCID, (nsISupports*)((nsIJVMManager*)mgr)); - PR_ASSERT(err == NS_OK); + mgr->Release(); } static nsIJVMPlugin* diff --git a/modules/oji/tests/src/JM/get_jm.cpp b/modules/oji/tests/src/JM/get_jm.cpp index 5d7deab7654..02fc21288b3 100755 --- a/modules/oji/tests/src/JM/get_jm.cpp +++ b/modules/oji/tests/src/JM/get_jm.cpp @@ -39,8 +39,8 @@ #include nsresult GetJVMManager(nsIJVMManager** jvmMngr) { - *jvmMngr = nsnull; - nsresult rv = nsServiceManager::GetService(kJVMManagerCID, kIJVMManagerIID, (nsISupports**)jvmMngr); + *jvmMngr; + nsresult rv = CallGetService(kJVMManagerCID, jvmMngr); if (rv != NS_OK || !jvmMngr) { fprintf(stderr, "ERROR: Can't get JVM manager !\n"); return NS_ERROR_FAILURE; diff --git a/modules/oji/tests/src/JNI/getjni/get_jni.cpp b/modules/oji/tests/src/JNI/getjni/get_jni.cpp index 977c1731209..cf4b6925fc1 100755 --- a/modules/oji/tests/src/JNI/getjni/get_jni.cpp +++ b/modules/oji/tests/src/JNI/getjni/get_jni.cpp @@ -41,7 +41,7 @@ nsresult GetJNI(JNIEnv** env) { nsIJVMManager *jvmMngr = nsnull; nsresult rv = NS_OK; *env = nsnull; - rv = nsServiceManager::GetService(kJVMManagerCID, kIJVMManagerIID, (nsISupports**)&jvmMngr); + rv = CallGetService(kJVMManagerCID, &jvmMngr); if (rv != NS_OK || !jvmMngr) { fprintf(stderr, "ERROR: Can't get JVM manager !\n"); return NS_ERROR_FAILURE; @@ -51,4 +51,4 @@ nsresult GetJNI(JNIEnv** env) { fprintf(stderr, "ERROR: Can't get JNI env !\n"); return NS_ERROR_FAILURE; } - \ No newline at end of file + diff --git a/modules/oji/tests/src/LCM/get_lcm.cpp b/modules/oji/tests/src/LCM/get_lcm.cpp index 5de21a4f123..fb328ee8639 100755 --- a/modules/oji/tests/src/LCM/get_lcm.cpp +++ b/modules/oji/tests/src/LCM/get_lcm.cpp @@ -41,10 +41,10 @@ nsresult GetLiveConnectManager(nsILiveConnectManager** lcMngr) { *lcMngr = nsnull; nsresult rv = NS_OK; - rv = nsServiceManager::GetService(kJVMManagerCID, kILiveConnectManagerIID, (nsISupports**)lcMngr); + rv = CallGetService(kJVMManagerCID, lcMngr); if (rv != NS_OK || !lcMngr) { fprintf(stderr, "ERROR: Can't get LiveConnect manager !\n"); return NS_ERROR_FAILURE; } return NS_OK; -} \ No newline at end of file +} diff --git a/modules/oji/tests/src/TM/get_tm.cpp b/modules/oji/tests/src/TM/get_tm.cpp index de6bc065ae1..bb86e36a9b6 100755 --- a/modules/oji/tests/src/TM/get_tm.cpp +++ b/modules/oji/tests/src/TM/get_tm.cpp @@ -41,11 +41,11 @@ nsresult GetThreadManager(nsIThreadManager** thrdMngr) { *thrdMngr = nsnull; nsresult rv; - rv = nsServiceManager::GetService(kJVMManagerCID, kIThreadManagerIID, (nsISupports**)thrdMngr); + rv = CallGetService(kJVMManagerCID, thrdMngr); if (rv != NS_OK || !thrdMngr) { fprintf(stderr, "ERROR: Can't get Thread manager !\n"); return NS_ERROR_FAILURE; } return NS_OK; } - \ No newline at end of file + diff --git a/modules/plugin/samples/simple/npsimple.cpp b/modules/plugin/samples/simple/npsimple.cpp index 7066d0ee3f2..f1cec7b7c08 100644 --- a/modules/plugin/samples/simple/npsimple.cpp +++ b/modules/plugin/samples/simple/npsimple.cpp @@ -454,9 +454,18 @@ SimplePluginInstance::RegisterSelf(nsIComponentManager* aCompMgr, { nsresult rv; + nsIServiceManager *svcMgr; + rv = aCompMgr->QueryInterface(NS_GET_IID(nsIServiceManager), + NS_REINTERPRET_CAST(void**, &svcMgr)); + if (NS_FAILED(rv)) + return rv; + nsIPluginManager* pm; - rv = nsServiceManager::GetService(kPluginManagerCID, NS_GET_IID(nsIPluginManager), - NS_REINTERPRET_CAST(nsISupports**, &pm)); + rv = svcMgr->GetService(kPluginManagerCID, + NS_GET_IID(nsIPluginManager), + NS_REINTERPRET_CAST(void**, &pm)); + NS_RELEASE(svcMgr); + if (NS_SUCCEEDED(rv)) { rv = pm->RegisterPlugin(kSimplePluginCID, kPluginName, @@ -481,9 +490,18 @@ SimplePluginInstance::UnregisterSelf(nsIComponentManager* aCompMgr, { nsresult rv; + nsIServiceManager *svcMgr; + rv = aCompMgr->QueryInterface(NS_GET_IID(nsIServiceManager), + NS_REINTERPRET_CAST(void**, &svcMgr)); + if (NS_FAILED(rv)) + return rv; + nsIPluginManager* pm; - rv = nsServiceManager::GetService(kPluginManagerCID, NS_GET_IID(nsIPluginManager), - NS_REINTERPRET_CAST(nsISupports**, &pm)); + rv = svcMgr->GetService(kPluginManagerCID, + NS_GET_IID(nsIPluginManager), + NS_REINTERPRET_CAST(void**, &pm)); + NS_RELEASE(svcMgr); + if (NS_SUCCEEDED(rv)) { rv = pm->UnregisterPlugin(kSimplePluginCID); NS_RELEASE(pm); diff --git a/modules/plugin/samples/testevents/npevents.cpp b/modules/plugin/samples/testevents/npevents.cpp index 799cc9924cc..5d88adfce4c 100644 --- a/modules/plugin/samples/testevents/npevents.cpp +++ b/modules/plugin/samples/testevents/npevents.cpp @@ -303,9 +303,18 @@ EventsPluginInstance::RegisterSelf(nsIComponentManager* aCompMgr, { nsresult rv; + nsIServiceManager *svcMgr; + rv = aCompMgr->QueryInterface(NS_GET_IID(nsIServiceManager), + NS_REINTERPRET_CAST(void**, &svcMgr)); + if (NS_FAILED(rv)) + return rv; + nsIPluginManager* pm; - rv = nsServiceManager::GetService(kPluginManagerCID, NS_GET_IID(nsIPluginManager), - NS_REINTERPRET_CAST(nsISupports**, &pm)); + rv = svcMgr->GetService(kPluginManagerCID, + NS_GET_IID(nsIPluginManager), + NS_REINTERPRET_CAST(void**, &pm)); + NS_RELEASE(svcMgr); + if (NS_SUCCEEDED(rv)) { rv = pm->RegisterPlugin(kEventsPluginCID, kPluginName, @@ -330,9 +339,18 @@ EventsPluginInstance::UnregisterSelf(nsIComponentManager* aCompMgr, { nsresult rv; + nsIServiceManager *svcMgr; + rv = aCompMgr->QueryInterface(NS_GET_IID(nsIServiceManager), + NS_REINTERPRET_CAST(void**, &svcMgr)); + if (NS_FAILED(rv)) + return rv; + nsIPluginManager* pm; - rv = nsServiceManager::GetService(kPluginManagerCID, NS_GET_IID(nsIPluginManager), - NS_REINTERPRET_CAST(nsISupports**, &pm)); + rv = svcMgr->GetService(kPluginManagerCID, + NS_GET_IID(nsIPluginManager), + NS_REINTERPRET_CAST(void**, &pm)); + NS_RELEASE(svcMgr); + if (NS_SUCCEEDED(rv)) { rv = pm->UnregisterPlugin(kEventsPluginCID); NS_RELEASE(pm); diff --git a/netwerk/streamconv/converters/nsDirIndexParser.cpp b/netwerk/streamconv/converters/nsDirIndexParser.cpp index 5a436611fb2..6b4c7d5a341 100644 --- a/netwerk/streamconv/converters/nsDirIndexParser.cpp +++ b/netwerk/streamconv/converters/nsDirIndexParser.cpp @@ -91,9 +91,7 @@ nsDirIndexParser::Init() { nsresult rv; // XXX not threadsafe if (gRefCntParser++ == 0) - rv = nsServiceManager::GetService(NS_ITEXTTOSUBURI_CONTRACTID, - NS_GET_IID(nsITextToSubURI), - NS_REINTERPRET_CAST(nsISupports**, &gTextToSubURI)); + rv = CallGetService(NS_ITEXTTOSUBURI_CONTRACTID, &gTextToSubURI); else rv = NS_OK; diff --git a/netwerk/test/TestCallbacks.cpp b/netwerk/test/TestCallbacks.cpp index 216cb4e7fd4..92bd4845dc3 100644 --- a/netwerk/test/TestCallbacks.cpp +++ b/netwerk/test/TestCallbacks.cpp @@ -293,9 +293,7 @@ nsresult StartLoad(const char *aURISpec) { if (NS_FAILED(rv)) return rv; - nsCOMPtr serv; - rv = nsServiceManager::GetService(kIOServiceCID, NS_GET_IID(nsIIOService), - getter_AddRefs(serv)); + nsCOMPtr serv = do_GetService(kIOServiceCID, &rv); if (NS_FAILED(rv)) return rv; // create a uri diff --git a/rdf/base/src/nsContainerEnumerator.cpp b/rdf/base/src/nsContainerEnumerator.cpp index 90e4d0de834..ba4dceeb42c 100644 --- a/rdf/base/src/nsContainerEnumerator.cpp +++ b/rdf/base/src/nsContainerEnumerator.cpp @@ -126,9 +126,7 @@ ContainerEnumeratorImpl::Init() NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource"); if (NS_FAILED(rv)) return rv; - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, - NS_GET_IID(nsIRDFContainerUtils), - NS_REINTERPRET_CAST(nsISupports**, &gRDFC)); + rv = CallGetService(kRDFContainerUtilsCID, &gRDFC); if (NS_FAILED(rv)) return rv; } @@ -140,11 +138,7 @@ ContainerEnumeratorImpl::~ContainerEnumeratorImpl() { if (--gRefCnt == 0) { NS_IF_RELEASE(kRDF_nextVal); - - if (gRDFC) { - nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFC); - gRDFC = nsnull; - } + NS_IF_RELEASE(gRDFC); } } diff --git a/rdf/base/src/nsRDFContainer.cpp b/rdf/base/src/nsRDFContainer.cpp index 9403ad653ea..d41af59ac33 100644 --- a/rdf/base/src/nsRDFContainer.cpp +++ b/rdf/base/src/nsRDFContainer.cpp @@ -415,23 +415,21 @@ RDFContainerImpl::Init() if (gRefCnt++ == 0) { nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**) &gRDFService); - - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); - if (NS_FAILED(rv)) return rv; + rv = CallGetService(kRDFServiceCID, &gRDFService); + if (NS_FAILED(rv)) { + NS_ERROR("unable to get RDF service"); + return rv; + } rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "nextVal"), &kRDF_nextVal); if (NS_FAILED(rv)) return rv; - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, - NS_GET_IID(nsIRDFContainerUtils), - (nsISupports**) &gRDFContainerUtils); - - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF container utils service"); - if (NS_FAILED(rv)) return rv; + rv = CallGetService(kRDFContainerUtilsCID, &gRDFContainerUtils); + if (NS_FAILED(rv)) { + NS_ERROR("unable to get RDF container utils service"); + return rv; + } } return NS_OK; @@ -449,16 +447,8 @@ RDFContainerImpl::~RDFContainerImpl() NS_IF_RELEASE(mDataSource); if (--gRefCnt == 0) { - if (gRDFContainerUtils) { - nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils); - gRDFContainerUtils = nsnull; - } - - if (gRDFService) { - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); - gRDFService = nsnull; - } - + NS_IF_RELEASE(gRDFContainerUtils); + NS_IF_RELEASE(gRDFService); NS_IF_RELEASE(kRDF_nextVal); } } diff --git a/rdf/base/src/nsRDFContainerUtils.cpp b/rdf/base/src/nsRDFContainerUtils.cpp index 6bdfd5ce0cb..6efb79aa906 100644 --- a/rdf/base/src/nsRDFContainerUtils.cpp +++ b/rdf/base/src/nsRDFContainerUtils.cpp @@ -358,9 +358,7 @@ RDFContainerUtilsImpl::RDFContainerUtilsImpl() if (gRefCnt++ == 0) { nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**) &gRDFService); + rv = CallGetService(kRDFServiceCID, &gRDFService); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); if (NS_SUCCEEDED(rv)) { @@ -388,11 +386,7 @@ RDFContainerUtilsImpl::~RDFContainerUtilsImpl() #endif if (--gRefCnt == 0) { - if (gRDFService) { - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); - gRDFService = nsnull; - } - + NS_IF_RELEASE(gRDFService); NS_IF_RELEASE(kRDF_instanceOf); NS_IF_RELEASE(kRDF_nextVal); NS_IF_RELEASE(kRDF_Bag); diff --git a/rdf/base/src/nsRDFContentSink.cpp b/rdf/base/src/nsRDFContentSink.cpp index 4f080a564cb..78e9044c4c7 100644 --- a/rdf/base/src/nsRDFContentSink.cpp +++ b/rdf/base/src/nsRDFContentSink.cpp @@ -357,10 +357,7 @@ RDFContentSinkImpl::RDFContentSinkImpl() mDocumentURL(nsnull) { if (gRefCnt++ == 0) { - nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, - kIRDFServiceIID, - (nsISupports**) &gRDFService); + nsresult rv = CallGetService(kRDFServiceCID, &gRDFService); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); if (NS_SUCCEEDED(rv)) { @@ -379,9 +376,7 @@ RDFContentSinkImpl::RDFContentSinkImpl() } - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, - NS_GET_IID(nsIRDFContainerUtils), - (nsISupports**) &gRDFContainerUtils); + rv = CallGetService(kRDFContainerUtilsCID, &gRDFContainerUtils); NS_RegisterStaticAtoms(rdf_atoms, NS_ARRAY_LENGTH(rdf_atoms)); } @@ -443,24 +438,14 @@ RDFContentSinkImpl::~RDFContentSinkImpl() if (--gRefCnt == 0) { - if (gRDFService) { - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); - gRDFService = nsnull; - } - - - if (gRDFContainerUtils) { - nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils); - gRDFContainerUtils = nsnull; - } - + NS_IF_RELEASE(gRDFService); + NS_IF_RELEASE(gRDFContainerUtils); NS_IF_RELEASE(kRDF_type); NS_IF_RELEASE(kRDF_instanceOf); NS_IF_RELEASE(kRDF_Alt); NS_IF_RELEASE(kRDF_Bag); NS_IF_RELEASE(kRDF_Seq); NS_IF_RELEASE(kRDF_nextVal); - } } diff --git a/rdf/base/src/nsRDFXMLDataSource.cpp b/rdf/base/src/nsRDFXMLDataSource.cpp index 0e7cfddb708..14a1950718e 100644 --- a/rdf/base/src/nsRDFXMLDataSource.cpp +++ b/rdf/base/src/nsRDFXMLDataSource.cpp @@ -514,12 +514,8 @@ RDFXMLDataSourceImpl::~RDFXMLDataSourceImpl(void) NS_RELEASE(mInner); - if (--gRefCnt == 0) { - if (gRDFService) { - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); - gRDFService = nsnull; - } - } + if (--gRefCnt == 0) + NS_IF_RELEASE(gRDFService); } diff --git a/rdf/base/src/nsRDFXMLSerializer.cpp b/rdf/base/src/nsRDFXMLSerializer.cpp index 7a32e08ab4d..764746982e5 100644 --- a/rdf/base/src/nsRDFXMLSerializer.cpp +++ b/rdf/base/src/nsRDFXMLSerializer.cpp @@ -112,9 +112,7 @@ nsRDFXMLSerializer::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult) &kRDF_Alt); if (NS_FAILED(rv)) break; - rv = nsServiceManager::GetService("@mozilla.org/rdf/container-utils;1", - NS_GET_IID(nsIRDFContainerUtils), - (nsISupports**) &gRDFC); + rv = CallGetService("@mozilla.org/rdf/container-utils;1", &gRDFC); if (NS_FAILED(rv)) break; } while (0); @@ -139,11 +137,7 @@ nsRDFXMLSerializer::~nsRDFXMLSerializer() NS_IF_RELEASE(kRDF_instanceOf); NS_IF_RELEASE(kRDF_type); NS_IF_RELEASE(kRDF_nextVal); - - if (gRDFC) { - nsServiceManager::ReleaseService("@mozilla.org/rdf/container-utils;1", gRDFC); - gRDFC = nsnull; - } + NS_IF_RELEASE(gRDFC); } } diff --git a/rdf/chrome/src/nsChromeRegistry.cpp b/rdf/chrome/src/nsChromeRegistry.cpp index cb1fe2bf2ae..77eafd22df5 100644 --- a/rdf/chrome/src/nsChromeRegistry.cpp +++ b/rdf/chrome/src/nsChromeRegistry.cpp @@ -176,15 +176,8 @@ nsChromeRegistry::~nsChromeRegistry() delete mDataSourceTable; } - if (mRDFService) { - nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService); - mRDFService = nsnull; - } - - if (mRDFContainerUtils) { - nsServiceManager::ReleaseService(kRDFContainerUtilsCID, mRDFContainerUtils); - mRDFContainerUtils = nsnull; - } + NS_IF_RELEASE(mRDFService); + NS_IF_RELEASE(mRDFContainerUtils); } @@ -231,14 +224,10 @@ nsChromeRegistry::Init() gChromeRegistry = this; nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**)&mRDFService); + rv = CallGetService(kRDFServiceCID, &mRDFService); NS_ENSURE_SUCCESS(rv, rv); - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, - NS_GET_IID(nsIRDFContainerUtils), - (nsISupports**)&mRDFContainerUtils); + rv = CallGetService(kRDFContainerUtilsCID, &mRDFContainerUtils); NS_ENSURE_SUCCESS(rv, rv); rv = mRDFService->GetResource(nsDependentCString(kURICHROME_selectedSkin), diff --git a/rdf/chrome/src/nsChromeUIDataSource.cpp b/rdf/chrome/src/nsChromeUIDataSource.cpp index 6c36496b828..4e511849482 100644 --- a/rdf/chrome/src/nsChromeUIDataSource.cpp +++ b/rdf/chrome/src/nsChromeUIDataSource.cpp @@ -67,9 +67,7 @@ nsChromeUIDataSource::nsChromeUIDataSource(nsIRDFDataSource* aComposite) mComposite->AddObserver(this); nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**)&mRDFService); + rv = CallGetService(kRDFServiceCID, &mRDFService); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); mRDFService->RegisterDataSource(this, PR_TRUE); @@ -79,10 +77,7 @@ nsChromeUIDataSource::~nsChromeUIDataSource() { mRDFService->UnregisterDataSource(this); - if (mRDFService) { - nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService); - mRDFService = nsnull; - } + NS_IF_RELEASE(mRDFService); } // we require a special implementation of Release, which knows about diff --git a/rdf/datasource/src/nsFileSystemDataSource.cpp b/rdf/datasource/src/nsFileSystemDataSource.cpp index 220c027c404..fd0bbe22af2 100644 --- a/rdf/datasource/src/nsFileSystemDataSource.cpp +++ b/rdf/datasource/src/nsFileSystemDataSource.cpp @@ -282,9 +282,7 @@ FileSystemDataSource::FileSystemDataSource(void) #ifdef DEBUG nsresult rv = #endif - nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**) &gRDFService); + rv = CallGetService(kRDFServiceCID, &gRDFService); PR_ASSERT(NS_SUCCEEDED(rv)); @@ -409,8 +407,7 @@ FileSystemDataSource::~FileSystemDataSource (void) NS_RELEASE(kLiteralFalse); gFileSystemDataSource = nsnull; - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); - gRDFService = nsnull; + NS_RELEASE(gRDFService); } } diff --git a/rdf/util/src/nsRDFResource.cpp b/rdf/util/src/nsRDFResource.cpp index 007c6051687..bb3c5590d37 100644 --- a/rdf/util/src/nsRDFResource.cpp +++ b/rdf/util/src/nsRDFResource.cpp @@ -71,10 +71,8 @@ nsRDFResource::~nsRDFResource(void) gRDFService->UnregisterResource(this); - if (--gRDFServiceRefCnt == 0) { - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); - gRDFService = nsnull; - } + if (--gRDFServiceRefCnt == 0) + NS_RELEASE(gRDFService); } NS_IMPL_THREADSAFE_ISUPPORTS2(nsRDFResource, nsIRDFResource, nsIRDFNode) diff --git a/security/manager/ssl/src/nsNSSComponent.cpp b/security/manager/ssl/src/nsNSSComponent.cpp index de95fc1f426..34f76574009 100644 --- a/security/manager/ssl/src/nsNSSComponent.cpp +++ b/security/manager/ssl/src/nsNSSComponent.cpp @@ -1876,29 +1876,19 @@ nsresult getNSSDialogs(void **_result, REFNSIID aIID, const char *contract) { nsresult rv; - nsCOMPtr result; - nsCOMPtr proxiedResult; - rv = nsServiceManager::GetService(contract, - aIID, - getter_AddRefs(result)); + nsCOMPtr svc = do_GetService(contract, &rv); if (NS_FAILED(rv)) return rv; - nsCOMPtr proxyman(do_GetService(NS_XPCOMPROXY_CONTRACTID)); - if (!proxyman) - return NS_ERROR_FAILURE; + nsCOMPtr proxyman = + do_GetService(NS_XPCOMPROXY_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return rv; - proxyman->GetProxyForObject(NS_UI_THREAD_EVENTQ, - aIID, result, PROXY_SYNC, - getter_AddRefs(proxiedResult)); - - if (!proxiedResult) { - return NS_ERROR_FAILURE; - } - - rv = proxiedResult->QueryInterface(aIID, _result); - + rv = proxyman->GetProxyForObject(NS_UI_THREAD_EVENTQ, + aIID, svc, PROXY_SYNC, + _result); return rv; } diff --git a/toolkit/components/history/src/nsGlobalHistory.cpp b/toolkit/components/history/src/nsGlobalHistory.cpp index e82d5eaf364..59d33c66b58 100644 --- a/toolkit/components/history/src/nsGlobalHistory.cpp +++ b/toolkit/components/history/src/nsGlobalHistory.cpp @@ -542,10 +542,7 @@ nsGlobalHistory::~nsGlobalHistory() NS_IF_RELEASE(mStore); if (--gRefCnt == 0) { - if (gRDFService) { - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); - gRDFService = nsnull; - } + NS_IF_RELEASE(gRDFService); NS_IF_RELEASE(kNC_Page); NS_IF_RELEASE(kNC_Date); @@ -2482,9 +2479,7 @@ nsGlobalHistory::Init() } if (gRefCnt++ == 0) { - rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**) &gRDFService); + rv = CallGetService(kRDFServiceCID, &gRDFService); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); if (NS_FAILED(rv)) return rv; diff --git a/webshell/tests/viewer/nsBrowserWindow.cpp b/webshell/tests/viewer/nsBrowserWindow.cpp index ccaf821a742..9916460b8c5 100644 --- a/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/webshell/tests/viewer/nsBrowserWindow.cpp @@ -969,9 +969,7 @@ nsBrowserWindow::DispatchMenuItem(PRInt32 aID) nsIPresShell* shell; shell = nsnull; shell = GetPresShell(); - res = nsServiceManager::GetService(kWalletServiceCID, - kIWalletServiceIID, - (nsISupports **)&walletservice); + res = CallGetService(kWalletServiceCID, &walletservice); if ((NS_OK == res) && (nsnull != walletservice)) { nsString urlString2; // res = walletservice->WALLET_Prefill(shell, (PRVCY_QPREFILL == aID)); @@ -995,9 +993,7 @@ nsBrowserWindow::DispatchMenuItem(PRInt32 aID) /* set a cookie for the javascript wallet editor */ - res = nsServiceManager::GetService(kWalletServiceCID, - kIWalletServiceIID, - (nsISupports **)&walletservice); + res = CallGetService(kWalletServiceCID, &walletservice); if ((NS_OK == res) && (nsnull != walletservice)) { nsIURI * url; nsCOMPtr service(do_GetService(kIOServiceCID, &res)); @@ -1031,9 +1027,7 @@ nsBrowserWindow::DispatchMenuItem(PRInt32 aID) #if defined(SingleSignon) case PRVCY_DISPLAY_SIGNONS: - res = nsServiceManager::GetService(kWalletServiceCID, - kIWalletServiceIID, - (nsISupports **)&walletservice); + res = CallGetService(kWalletServiceCID, &walletservice); if ((NS_OK == res) && (nsnull != walletservice)) { // res = walletservice->SI_DisplaySignonInfoAsHTML(); NS_RELEASE(walletservice); @@ -1215,8 +1209,7 @@ GetTitleSuffix(void) { nsString* suffix = new nsString(" - Failed"); nsIStringBundleService* service = nsnull; - nsresult ret = nsServiceManager::GetService(kStringBundleServiceCID, - kIStringBundleServiceIID, (nsISupports**) &service); + nsresult ret = CallGetService(kStringBundleServiceCID, &service); if (NS_FAILED(ret)) { return suffix; } diff --git a/webshell/tests/viewer/nsViewerApp.cpp b/webshell/tests/viewer/nsViewerApp.cpp index 29064fc7c03..1ce5ea669ae 100644 --- a/webshell/tests/viewer/nsViewerApp.cpp +++ b/webshell/tests/viewer/nsViewerApp.cpp @@ -204,51 +204,6 @@ nsViewerApp::Destroy() NS_IF_RELEASE(mPrefService); } -class nsTestFormProcessor : public nsIFormProcessor { -public: - nsTestFormProcessor(); - NS_IMETHOD ProcessValue(nsIDOMHTMLElement *aElement, - const nsString& aName, - nsString& aValue); - - NS_IMETHOD ProvideContent(const nsString& aFormType, - nsVoidArray& aContent, - nsString& aAttribute); - NS_DECL_ISUPPORTS -}; - - - -NS_IMPL_ISUPPORTS1(nsTestFormProcessor, nsIFormProcessor) - -nsTestFormProcessor::nsTestFormProcessor() -{ -} - -NS_METHOD -nsTestFormProcessor::ProcessValue(nsIDOMHTMLElement *aElement, - const nsString& aName, - nsString& aValue) -{ -#ifdef DEBUG_kmcclusk - char *name = ToNewCString(aName); - char *value = ToNewCString(aValue); - printf("ProcessValue: name %s value %s\n", name, value); - delete [] name; - delete [] value; -#endif - - return NS_OK; -} - -NS_METHOD nsTestFormProcessor::ProvideContent(const nsString& aFormType, - nsVoidArray& aContent, - nsString& aAttribute) -{ - return NS_OK; -} - - nsresult nsViewerApp::SetupRegistry() { @@ -275,15 +230,6 @@ nsViewerApp::SetupRegistry() #endif } - // Register a form processor. The form processor has the opportunity to - // modify the value's passed during form submission. - nsTestFormProcessor* testFormProcessor = new nsTestFormProcessor(); - nsCOMPtr formProcessor; - rv = testFormProcessor->QueryInterface(kISupportsIID, getter_AddRefs(formProcessor)); - if (NS_SUCCEEDED(rv) && formProcessor) { - rv = nsServiceManager::RegisterService(kFormProcessorCID, formProcessor); - } - return NS_OK; } @@ -356,9 +302,6 @@ nsViewerApp::Exit() NS_RELEASE(mAppShell); } - // Unregister the test form processor registered in nsViewerApp::SetupRegistry - rv = nsServiceManager::UnregisterService(kFormProcessorCID); - return rv; } diff --git a/webshell/tests/viewer/nsWebCrawler.cpp b/webshell/tests/viewer/nsWebCrawler.cpp index 917eaa2b3ee..579cfe3d4b8 100644 --- a/webshell/tests/viewer/nsWebCrawler.cpp +++ b/webshell/tests/viewer/nsWebCrawler.cpp @@ -985,16 +985,13 @@ static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); static nsresult QueueEvent(PLEvent* aEvent) { - nsISupports* is; - nsresult rv = nsServiceManager::GetService(kEventQueueServiceCID, - kIEventQueueServiceIID, - &is, - nsnull); + nsresult rv; + nsCOMPtr eqs = + do_GetService(kEventQueueServiceCID, &rv); if (NS_FAILED(rv)) { return rv; } - nsCOMPtr eqs = do_QueryInterface(is); if (eqs) { nsCOMPtr eq; rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eq)); @@ -1003,7 +1000,6 @@ QueueEvent(PLEvent* aEvent) } } - nsServiceManager::ReleaseService(kEventQueueServiceCID, is, nsnull); return rv; } diff --git a/widget/src/cocoa/nsCocoaWindow.mm b/widget/src/cocoa/nsCocoaWindow.mm index 7e01adf731f..845954ea541 100644 --- a/widget/src/cocoa/nsCocoaWindow.mm +++ b/widget/src/cocoa/nsCocoaWindow.mm @@ -147,9 +147,7 @@ nsCocoaWindow :: DragTrackingHandler ( DragTrackingMessage theMessage, WindowPtr case kDragTrackingEnterWindow: { // get our drag service for the duration of the drag. - nsresult rv = nsServiceManager::GetService(kCDragServiceCID, - NS_GET_IID(nsIDragService), - (nsISupports **)&sDragService); + nsresult rv = CallGetService(kCDragServiceCID, &sDragService); NS_ASSERTION ( sDragService, "Couldn't get a drag service, we're in biiig trouble" ); // tell the session about this drag @@ -217,10 +215,7 @@ nsCocoaWindow :: DragTrackingHandler ( DragTrackingMessage theMessage, WindowPtr ::HideDragHilite ( theDrag ); // we're _really_ done with it, so let go of the service. - if ( sDragService ) { - nsServiceManager::ReleaseService(kCDragServiceCID, sDragService); - sDragService = nsnull; - } + NS_IF_RELEASE( sDragService ); break; } diff --git a/widget/src/gtk/nsGtkIMEHelper.cpp b/widget/src/gtk/nsGtkIMEHelper.cpp index 64cf535e79b..401aa05ec87 100644 --- a/widget/src/gtk/nsGtkIMEHelper.cpp +++ b/widget/src/gtk/nsGtkIMEHelper.cpp @@ -137,13 +137,10 @@ void nsGtkIMEHelper::SetupUnicodeDecoder() charset.AssignLiteral("ISO-8859-1"); // default } nsICharsetConverterManager* manager = nsnull; - nsresult res = nsServiceManager:: - GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), - (nsISupports**)&manager); + nsresult res = CallGetService(kCharsetConverterManagerCID, &manager); if (manager && NS_SUCCEEDED(res)) { manager->GetUnicodeDecoderRaw(charset.get(), &mDecoder); - nsServiceManager::ReleaseService(kCharsetConverterManagerCID, manager); + NS_RELEASE(manager); } } NS_ASSERTION(mDecoder, "cannot get decoder"); diff --git a/widget/src/windows/nsNativeDragTarget.cpp b/widget/src/windows/nsNativeDragTarget.cpp index 3c0de25585c..a2d762130af 100644 --- a/widget/src/windows/nsNativeDragTarget.cpp +++ b/widget/src/windows/nsNativeDragTarget.cpp @@ -81,9 +81,7 @@ nsNativeDragTarget::nsNativeDragTarget(nsIWidget * aWnd) /* * Create/Get the DragService that we have implemented */ - nsServiceManager::GetService(kCDragServiceCID, - kIDragServiceIID, - (nsISupports**)&mDragService); + CallGetService(kCDragServiceCID, &mDragService); } @@ -92,7 +90,7 @@ nsNativeDragTarget::nsNativeDragTarget(nsIWidget * aWnd) //----------------------------------------------------- nsNativeDragTarget::~nsNativeDragTarget() { - nsServiceManager::ReleaseService(kCDragServiceCID, mDragService); + NS_RELEASE(mDragService); } //----------------------------------------------------- diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 88bf4dbab26..6927fab46cb 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -4442,11 +4442,9 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT case WM_DESTROYCLIPBOARD: { nsIClipboard* clipboard; - nsresult rv = nsServiceManager::GetService(kCClipboardCID, - NS_GET_IID(nsIClipboard), - (nsISupports **)&clipboard); + nsresult rv = CallGetService(kCClipboardCID, &clipboard); clipboard->EmptyClipboard(nsIClipboard::kGlobalClipboard); - nsServiceManager::ReleaseService(kCClipboardCID, clipboard); + NS_RELEASE(clipboard); } break; diff --git a/widget/src/xpwidgets/nsBaseWidget.cpp b/widget/src/xpwidgets/nsBaseWidget.cpp index 80d905201c7..b13fdc0ebf7 100644 --- a/widget/src/xpwidgets/nsBaseWidget.cpp +++ b/widget/src/xpwidgets/nsBaseWidget.cpp @@ -1172,9 +1172,7 @@ debug_PrefChangedCallback(const char * name,void * closure) nsIPref * prefs = nsnull; - nsresult rv = nsServiceManager::GetService(kPrefCID, - NS_GET_IID(nsIPref), - (nsISupports**) &prefs); + nsresult rv = CallGetService(kPrefCID, &prefs); NS_ASSERTION(NS_SUCCEEDED(rv),"Could not get prefs service."); NS_ASSERTION(nsnull != prefs,"Prefs services is null."); @@ -1204,9 +1202,7 @@ debug_RegisterPrefCallbacks() nsIPref * prefs = nsnull; - nsresult rv = nsServiceManager::GetService(kPrefCID, - NS_GET_IID(nsIPref), - (nsISupports**) &prefs); + nsresult rv = CallGetService(kPrefCID, &prefs); NS_ASSERTION(NS_SUCCEEDED(rv),"Could not get prefs service."); NS_ASSERTION(nsnull != prefs,"Prefs services is null."); diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp index a6b19665240..50ad1d8a056 100644 --- a/xpcom/build/nsXPComInit.cpp +++ b/xpcom/build/nsXPComInit.cpp @@ -802,7 +802,6 @@ nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr) if (nsComponentManagerImpl::gComponentManager) { nsComponentManagerImpl::gComponentManager->FreeServices(); } - nsServiceManager::ShutdownGlobalServiceManager(nsnull); if (currentQ) { currentQ->ProcessPendingEvents(); diff --git a/xpcom/components/nsIServiceManagerObsolete.h b/xpcom/components/nsIServiceManagerObsolete.h index dc229c7623b..5f2acc01947 100644 --- a/xpcom/components/nsIServiceManagerObsolete.h +++ b/xpcom/components/nsIServiceManagerObsolete.h @@ -200,51 +200,7 @@ public: {0x81, 0x63, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \ } -class nsIShutdownListener; - - -template -inline -nsresult -CallGetService( const nsCID &aClass, - nsIShutdownListener* shutdownListener, - DestinationType** aDestination) -{ - NS_PRECONDITION(aDestination, "null parameter"); - - return nsServiceManager::GetService(aClass, - NS_GET_IID(DestinationType), - NS_REINTERPRET_CAST(nsISupports**, aDestination), - shutdownListener); -} - -template -inline -nsresult -CallGetService( const char *aContractID, - nsIShutdownListener* shutdownListener, - DestinationType** aDestination) -{ - NS_PRECONDITION(aContractID, "null parameter"); - NS_PRECONDITION(aDestination, "null parameter"); - - return nsServiceManager::GetService(aContractID, - NS_GET_IID(DestinationType), - NS_REINTERPRET_CAST(nsISupports**, aDestination), - shutdownListener); -} - //////////////////////////////////////////////////////////////////////////////// #endif /* nsIServiceManagerObsolete_h___ */ - - - - - - - - - - diff --git a/xpcom/components/nsServiceManagerObsolete.cpp b/xpcom/components/nsServiceManagerObsolete.cpp index dd6856d6020..f1ec60e4bfb 100644 --- a/xpcom/components/nsServiceManagerObsolete.cpp +++ b/xpcom/components/nsServiceManagerObsolete.cpp @@ -62,6 +62,7 @@ nsServiceManager::GetGlobalServiceManager(nsIServiceManager* *result) nsresult nsServiceManager::ShutdownGlobalServiceManager(nsIServiceManager* *result) { + NS_NOTREACHED("nsServiceManager::ShutdownGlobalServiceManager is deprecated"); return NS_OK; } @@ -70,7 +71,8 @@ nsServiceManager::GetService(const nsCID& aClass, const nsIID& aIID, nsISupports* *result, nsIShutdownListener* shutdownListener) { - + NS_NOTREACHED("nsServiceManager::GetService is deprecated"); + if (nsComponentManagerImpl::gComponentManager == nsnull) return NS_ERROR_UNEXPECTED; @@ -81,6 +83,8 @@ nsresult nsServiceManager::ReleaseService(const nsCID& aClass, nsISupports* service, nsIShutdownListener* shutdownListener) { + NS_NOTREACHED("nsServiceManager::ReleaseService is deprecated"); + NS_IF_RELEASE(service); return NS_OK; } @@ -88,6 +92,7 @@ nsServiceManager::ReleaseService(const nsCID& aClass, nsISupports* service, nsresult nsServiceManager::RegisterService(const nsCID& aClass, nsISupports* aService) { + NS_NOTREACHED("nsServiceManager::RegisterService is deprecated"); if (nsComponentManagerImpl::gComponentManager == nsnull) return NS_ERROR_UNEXPECTED; @@ -98,7 +103,8 @@ nsServiceManager::RegisterService(const nsCID& aClass, nsISupports* aService) nsresult nsServiceManager::UnregisterService(const nsCID& aClass) { - + NS_NOTREACHED("nsServiceManager::UnregisterService is deprecated"); + if (nsComponentManagerImpl::gComponentManager == nsnull) return NS_ERROR_UNEXPECTED; @@ -113,6 +119,7 @@ nsServiceManager::GetService(const char* aContractID, const nsIID& aIID, nsISupports* *result, nsIShutdownListener* shutdownListener) { + NS_NOTREACHED("nsServiceManager::GetService is deprecated"); if (nsComponentManagerImpl::gComponentManager == nsnull) return NS_ERROR_UNEXPECTED; @@ -124,6 +131,8 @@ nsresult nsServiceManager::ReleaseService(const char* aContractID, nsISupports* service, nsIShutdownListener* shutdownListener) { + NS_NOTREACHED("nsServiceManager::ReleaseService is deprecated"); + NS_RELEASE(service); return NS_OK; } @@ -131,6 +140,7 @@ nsServiceManager::ReleaseService(const char* aContractID, nsISupports* service, nsresult nsServiceManager::RegisterService(const char* aContractID, nsISupports* aService) { + NS_NOTREACHED("nsServiceManager::RegisterService is deprecated"); if (nsComponentManagerImpl::gComponentManager == nsnull) return NS_ERROR_UNEXPECTED; @@ -141,6 +151,8 @@ nsServiceManager::RegisterService(const char* aContractID, nsISupports* aService nsresult nsServiceManager::UnregisterService(const char* aContractID) { + NS_NOTREACHED("nsServiceManager::UnregisterService is deprecated"); + // Don't create the global service manager here because we might // be shutting down, and releasing all the services in its // destructor diff --git a/xpcom/proxy/public/nsProxiedService.h b/xpcom/proxy/public/nsProxiedService.h index 3a39ade121d..7ab4adb8808 100644 --- a/xpcom/proxy/public/nsProxiedService.h +++ b/xpcom/proxy/public/nsProxiedService.h @@ -36,8 +36,8 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef __nsProxiedServiceManager_h_ -#define __nsProxiedServiceManager_h_ +#ifndef nsProxiedService_h_ +#define nsProxiedService_h_ #include "nsIServiceManager.h" #include "nsIProxyObjectManager.h" @@ -94,71 +94,45 @@ class nsProxiedService { - public: - +public: nsProxiedService(const nsCID &aClass, const nsIID &aIID, - nsIEventQueue* pIProxyQueue, PRBool always, nsresult*rv) + nsIEventQueue* aEventQ, PRBool always, nsresult* rv) { - *rv = nsServiceManager::GetService(aClass, - aIID, - getter_AddRefs(mService)); - if (NS_FAILED(*rv)) return; - InitProxy(aIID, pIProxyQueue, always, rv); + nsCOMPtr svc = do_GetService(aClass, rv); + if (NS_SUCCEEDED(*rv)) + InitProxy(svc, aIID, aEventQ, always, rv); } nsProxiedService(const char* aContractID, const nsIID &aIID, - nsIEventQueue* pIProxyQueue, PRBool always, nsresult*rv) + nsIEventQueue* aEventQ, PRBool always, nsresult* rv) { - *rv = nsServiceManager::GetService(aContractID, - aIID, - getter_AddRefs(mService)); - if (NS_FAILED(*rv)) return; - InitProxy(aIID, pIProxyQueue, always, rv); - } - - void InitProxy(const nsIID &aIID, nsIEventQueue* pIProxyQueue, - PRBool always, nsresult*rv) - { - static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); - - nsCOMPtr pIProxyObjectManager = - do_GetService(kProxyObjectManagerCID, rv); - if (NS_FAILED(*rv)) return; - - PRInt32 proxyType = PROXY_SYNC; - if (always) proxyType |= PROXY_ALWAYS; - *rv = pIProxyObjectManager->GetProxyForObject(pIProxyQueue, - aIID, - mService, - proxyType, - getter_AddRefs(mProxiedService)); + nsCOMPtr svc = do_GetService(aContractID, rv); + if (NS_SUCCEEDED(*rv)) + InitProxy(svc, aIID, aEventQ, always, rv); } - ~nsProxiedService() + operator nsISupports*() const { + return mProxiedService; } - nsISupports* operator->() const - { - NS_PRECONDITION(mProxiedService != 0, "Your code should test the error result from the constructor."); - return mProxiedService; - } +private: - PRBool operator==(const nsISupports* other) - { - return ((mProxiedService == other) || (mService == other)); - } + void InitProxy(nsISupports *aObj, const nsIID &aIID, + nsIEventQueue* aEventQ, PRBool always, nsresult*rv) + { + PRInt32 proxyType = PROXY_SYNC; + if (always) + proxyType |= PROXY_ALWAYS; - operator nsISupports*() const - { - return mProxiedService; - } + *rv = NS_GetProxyForObject(aEventQ, + aIID, + aObj, + proxyType, + getter_AddRefs(mProxiedService)); + } - protected: - nsCOMPtr mProxiedService; - nsCOMPtr mService; - - }; + nsCOMPtr mProxiedService; +}; - -#endif //__nsProxiedServiceManager_h_ +#endif // nsProxiedService_h_ diff --git a/xpcom/proxy/tests/proxytests.cpp b/xpcom/proxy/tests/proxytests.cpp index 20693463dd8..cb537dc5aa5 100644 --- a/xpcom/proxy/tests/proxytests.cpp +++ b/xpcom/proxy/tests/proxytests.cpp @@ -131,25 +131,21 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsTestXPCFoo2, nsITestProxy) NS_IMETHODIMP nsTestXPCFoo2::Test(PRInt32 p1, PRInt32 p2, PRInt32* retval) { -printf("calling back to caller!\n\n"); + printf("calling back to caller!\n\n"); - nsIProxyObjectManager* manager; - nsITestProxy * proxyObject; - - nsServiceManager::GetService( NS_XPCOMPROXY_CONTRACTID, - NS_GET_IID(nsIProxyObjectManager), - (nsISupports **)&manager); + nsCOMPtr manager = + do_GetService(NS_XPCOMPROXY_CONTRACTID); - printf("ProxyObjectManager: %p \n", manager); + printf("ProxyObjectManager: %p \n", (void *) manager.get()); PR_ASSERT(manager); - manager->GetProxyForObject((nsIEventQueue*)p1, NS_GET_IID(nsITestProxy), this, PROXY_SYNC, (void**)&proxyObject); + nsCOMPtr proxyObject; + manager->GetProxyForObject((nsIEventQueue*)p1, NS_GET_IID(nsITestProxy), + this, PROXY_SYNC, (void**)&proxyObject); proxyObject->Test3(nsnull, nsnull); printf("Deleting Proxy Object\n"); - NS_RELEASE(proxyObject); - return NS_OK; } @@ -184,13 +180,10 @@ void TestCase_TwoClassesOneInterface(void *arg) ArgsStruct *argsStruct = (ArgsStruct*) arg; - nsIProxyObjectManager* manager; - - nsServiceManager::GetService( NS_XPCOMPROXY_CONTRACTID, - NS_GET_IID(nsIProxyObjectManager), - (nsISupports **)&manager); + nsCOMPtr manager = + do_GetService(NS_XPCOMPROXY_CONTRACTID); - printf("ProxyObjectManager: %p \n", manager); + printf("ProxyObjectManager: %p \n", (void *) manager.get()); PR_ASSERT(manager); @@ -254,14 +247,10 @@ void TestCase_NestedLoop(void *arg) { ArgsStruct *argsStruct = (ArgsStruct*) arg; + nsCOMPtr manager = + do_GetService(NS_XPCOMPROXY_CONTRACTID); - nsIProxyObjectManager* manager; - - nsServiceManager::GetService( NS_XPCOMPROXY_CONTRACTID, - NS_GET_IID(nsIProxyObjectManager), - (nsISupports **)&manager); - - printf("ProxyObjectManager: %p \n", manager); + printf("ProxyObjectManager: %p\n", (void *) manager.get()); PR_ASSERT(manager); @@ -319,11 +308,8 @@ void TestCase_2(void *arg) ArgsStruct *argsStruct = (ArgsStruct*) arg; - nsIProxyObjectManager* manager; - - nsServiceManager::GetService( NS_XPCOMPROXY_CONTRACTID, - NS_GET_IID(nsIProxyObjectManager), - (nsISupports **)&manager); + nsCOMPtr manager = + do_GetService(NS_XPCOMPROXY_CONTRACTID); PR_ASSERT(manager); @@ -349,11 +335,8 @@ void TestCase_nsISupports(void *arg) ArgsStruct *argsStruct = (ArgsStruct*) arg; - nsIProxyObjectManager* manager; - - nsServiceManager::GetService( NS_XPCOMPROXY_CONTRACTID, - NS_GET_IID(nsIProxyObjectManager), - (nsISupports **)&manager); + nsCOMPtr manager = + do_GetService(NS_XPCOMPROXY_CONTRACTID); PR_ASSERT(manager); @@ -427,11 +410,8 @@ static void PR_CALLBACK EventLoop( void *arg ) printf("Verifing calling Proxy on eventQ thread.\n"); - nsIProxyObjectManager* manager; - - nsServiceManager::GetService( NS_XPCOMPROXY_CONTRACTID, - NS_GET_IID(nsIProxyObjectManager), - (nsISupports **)&manager); + nsCOMPtr manager = + do_GetService(NS_XPCOMPROXY_CONTRACTID); PR_ASSERT(manager); diff --git a/xpcom/tests/TestCallTemplates.cpp b/xpcom/tests/TestCallTemplates.cpp index 3ec9c29a68a..2fd64891276 100644 --- a/xpcom/tests/TestCallTemplates.cpp +++ b/xpcom/tests/TestCallTemplates.cpp @@ -113,12 +113,8 @@ int main() CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, &myITestService); /* Test CallGetService */ - nsIShutdownListener *myShutdownListener = nsnull; CallGetService(kTestServiceCID, &myITestService); - CallGetService(kTestServiceCID, myShutdownListener, &myITestService); CallGetService(NS_TEST_SERVICE_CONTRACTID, &myITestService); - CallGetService(NS_TEST_SERVICE_CONTRACTID, myShutdownListener, - &myITestService); /* Test CallGetInterface */ nsIInterfaceRequestor *myInterfaceRequestor = diff --git a/xpcom/tests/TestServMgr.cpp b/xpcom/tests/TestServMgr.cpp index 8eaaaa777b3..b4b591c1ff4 100644 --- a/xpcom/tests/TestServMgr.cpp +++ b/xpcom/tests/TestServMgr.cpp @@ -53,8 +53,7 @@ BeginTest(int testNumber) { nsresult err; NS_ASSERTION(myServ == NULL, "myServ not reset"); - err = nsServiceManager::GetService(kIMyServiceCID, NS_GET_IID(IMyService), - (nsISupports**)&myServ); + err = CallGetService(kIMyServiceCID, &myServ); return err; } @@ -67,9 +66,7 @@ EndTest(int testNumber) err = myServ->Doit(); if (err != NS_OK) return err; - err = nsServiceManager::ReleaseService(kIMyServiceCID, myServ); - if (err != NS_OK) return err; - myServ = NULL; + NS_RELEASE(myServ); } printf("test %d succeeded\n", testNumber); @@ -93,17 +90,22 @@ SimpleTest(int testNumber) nsresult AsyncShutdown(int testNumber) { - nsresult err; + nsresult err = NS_OK; // If the AsyncShutdown was truly asynchronous and happened on another // thread, we'd have to protect all accesses to myServ throughout this // code with a monitor. + // XXX-darin: say what?!? + + /* err = nsServiceManager::UnregisterService(kIMyServiceCID); if (err == NS_ERROR_SERVICE_NOT_AVAILABLE) { printf("async shutdown -- service not found\n"); return NS_OK; } + */ + return err; } @@ -125,8 +127,7 @@ AsyncNoShutdownTest(int testNumber) // Create some other user of kIMyServiceCID, preventing it from // really going away: IMyService* otherClient; - err = nsServiceManager::GetService(kIMyServiceCID, NS_GET_IID(IMyService), - (nsISupports**)&otherClient); + err = CallGetService(kIMyServiceCID, &otherClient); if (err != NS_OK) return err; err = AsyncShutdown(testNumber); @@ -134,7 +135,7 @@ AsyncNoShutdownTest(int testNumber) err = EndTest(testNumber); // Finally, release the other client. - err = nsServiceManager::ReleaseService(kIMyServiceCID, otherClient); + NS_RELEASE(otherClient); return err; } diff --git a/xpfe/components/bookmarks/src/nsBookmarksService.cpp b/xpfe/components/bookmarks/src/nsBookmarksService.cpp index dafdec6be3e..ba1fa532fc4 100644 --- a/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -204,26 +204,23 @@ bm_AddRefGlobals() if (gRefCnt++ == 0) { nsresult rv; - rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**) &gRDF); + rv = CallGetService(kRDFServiceCID, &gRDF); + if (NS_FAILED(rv)) { + NS_ERROR("unable to get RDF service"); + return rv; + } - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); - if (NS_FAILED(rv)) return rv; + rv = CallGetService(kRDFContainerUtilsCID, &gRDFC); + if (NS_FAILED(rv)) { + NS_ERROR("unable to get RDF container utils"); + return rv; + } - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, - NS_GET_IID(nsIRDFContainerUtils), - (nsISupports**) &gRDFC); - - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF container utils"); - if (NS_FAILED(rv)) return rv; - - rv = nsServiceManager::GetService(kCharsetAliasCID, - NS_GET_IID(nsICharsetAlias), - (nsISupports**) &gCharsetAlias); - - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get charset alias service"); - if (NS_FAILED(rv)) return rv; + rv = CallGetService(kCharsetAliasCID, &gCharsetAlias); + if (NS_FAILED(rv)) { + NS_ERROR("unable to get charset alias service"); + return rv; + } nsCOMPtr ls = do_GetService(NS_LOCALESERVICE_CONTRACTID); if (ls) { @@ -346,23 +343,9 @@ bm_ReleaseGlobals() { if (--gRefCnt == 0) { - if (gRDF) - { - nsServiceManager::ReleaseService(kRDFServiceCID, gRDF); - gRDF = nsnull; - } - - if (gRDFC) - { - nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFC); - gRDFC = nsnull; - } - - if (gCharsetAlias) - { - nsServiceManager::ReleaseService(kCharsetAliasCID, gCharsetAlias); - gCharsetAlias = nsnull; - } + NS_IF_RELEASE(gRDF); + NS_IF_RELEASE(gRDFC); + NS_IF_RELEASE(gCharsetAlias); NS_IF_RELEASE(gCollation); @@ -1022,11 +1005,9 @@ BookmarkParser::ParseMetaTag(const nsString &aLine, nsIUnicodeDecoder **decoder) if (charset.Length() < 1) return NS_ERROR_UNEXPECTED; // found a charset, now try and get a decoder from it to Unicode - nsICharsetConverterManager *charsetConv = nsnull; - rv = nsServiceManager::GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), - (nsISupports**)&charsetConv); - if (NS_SUCCEEDED(rv) && (charsetConv)) + nsICharsetConverterManager *charsetConv; + rv = CallGetService(kCharsetConverterManagerCID, &charsetConv); + if (NS_SUCCEEDED(rv)) { rv = charsetConv->GetUnicodeDecoderRaw(charset.get(), decoder); NS_RELEASE(charsetConv); @@ -1670,17 +1651,19 @@ nsBookmarksService::Init() if (NS_FAILED(rv)) return rv; /* create a URL for the string resource file */ - nsCOMPtr uri; - if (NS_SUCCEEDED(rv = mNetService->NewURI(bookmark_properties, nsnull, nsnull, - getter_AddRefs(uri)))) + nsCOMPtr uri; + mNetService->NewURI(bookmark_properties, nsnull, nsnull, + getter_AddRefs(uri)); + if (uri) { /* create a bundle for the localization */ - nsCOMPtr stringService; - if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kStringBundleServiceCID, - NS_GET_IID(nsIStringBundleService), getter_AddRefs(stringService)))) + nsCOMPtr stringService = + do_GetService(kStringBundleServiceCID); + if (stringService) { nsCAutoString spec; - if (NS_SUCCEEDED(rv = uri->GetSpec(spec))) + uri->GetSpec(spec); + if (!spec.IsEmpty()) { stringService->CreateBundle(spec.get(), getter_AddRefs(mBundle)); } diff --git a/xpfe/components/history/src/nsGlobalHistory.cpp b/xpfe/components/history/src/nsGlobalHistory.cpp index 1bd41755d55..abd2634e505 100644 --- a/xpfe/components/history/src/nsGlobalHistory.cpp +++ b/xpfe/components/history/src/nsGlobalHistory.cpp @@ -529,10 +529,7 @@ nsGlobalHistory::~nsGlobalHistory() NS_IF_RELEASE(mStore); if (--gRefCnt == 0) { - if (gRDFService) { - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); - gRDFService = nsnull; - } + NS_IF_RELEASE(gRDFService); NS_IF_RELEASE(kNC_Page); NS_IF_RELEASE(kNC_Date); @@ -2463,9 +2460,7 @@ nsGlobalHistory::Init() } if (gRefCnt++ == 0) { - rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**) &gRDFService); + rv = CallGetService(kRDFServiceCID, &gRDFService); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); if (NS_FAILED(rv)) return rv; diff --git a/xpfe/components/intl/nsCharsetMenu.cpp b/xpfe/components/intl/nsCharsetMenu.cpp index e0e1a903ce1..9c84b855ecb 100644 --- a/xpfe/components/intl/nsCharsetMenu.cpp +++ b/xpfe/components/intl/nsCharsetMenu.cpp @@ -745,8 +745,7 @@ nsresult nsCharsetMenu::Init() mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_type), &kRDF_type); nsIRDFContainerUtils * rdfUtil = NULL; - res = nsServiceManager::GetService(kRDFContainerUtilsCID, - NS_GET_IID(nsIRDFContainerUtils), (nsISupports **)&rdfUtil); + res = CallGetService(kRDFContainerUtilsCID, &rdfUtil); if (NS_FAILED(res)) goto done; res = rdfUtil->MakeSeq(mInner, kNC_BrowserAutodetMenuRoot, NULL); @@ -779,7 +778,7 @@ nsresult nsCharsetMenu::Init() if (NS_FAILED(res)) goto done; done: - if (rdfUtil != NULL) nsServiceManager::ReleaseService(kRDFContainerUtilsCID,rdfUtil); + NS_IF_RELEASE(rdfUtil); if (NS_FAILED(res)) return res; } mInitialized = NS_SUCCEEDED(res); diff --git a/xpfe/components/related/src/nsRelatedLinksHandler.cpp b/xpfe/components/related/src/nsRelatedLinksHandler.cpp index 59bc6efcd32..289bffebac3 100644 --- a/xpfe/components/related/src/nsRelatedLinksHandler.cpp +++ b/xpfe/components/related/src/nsRelatedLinksHandler.cpp @@ -196,7 +196,7 @@ RelatedLinksStreamListener::~RelatedLinksStreamListener() NS_IF_RELEASE(kNC_RelatedLinksRoot); mUnicodeDecoder = nsnull; - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); + NS_IF_RELEASE(gRDFService); } } @@ -207,20 +207,16 @@ RelatedLinksStreamListener::Init() { if (gRefCnt++ == 0) { - nsresult rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**) &gRDFService); - - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); + nsresult rv = CallGetService(kRDFServiceCID, &gRDFService); if (NS_FAILED(rv)) + { + NS_ERROR("unable to get RDF service"); return(rv); + } - nsICharsetConverterManager *charsetConv = nsnull; - - rv = nsServiceManager::GetService(kCharsetConverterManagerCID, - NS_GET_IID(nsICharsetConverterManager), - (nsISupports**)&charsetConv); - if (NS_SUCCEEDED(rv) && (charsetConv)) + nsICharsetConverterManager *charsetConv; + rv = CallGetService(kCharsetConverterManagerCID, &charsetConv); + if (NS_SUCCEEDED(rv)) { rv = charsetConv->GetUnicodeDecoderRaw("UTF-8", getter_AddRefs(mUnicodeDecoder)); @@ -612,8 +608,7 @@ RelatedLinksHandlerImpl::~RelatedLinksHandlerImpl() NS_IF_RELEASE(kNC_RelatedLinksTopic); NS_IF_RELEASE(kNC_Child); - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); - gRDFService = nsnull; + NS_IF_RELEASE(gRDFService); } } @@ -626,9 +621,7 @@ RelatedLinksHandlerImpl::Init() if (gRefCnt++ == 0) { - rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), - (nsISupports**) &gRDFService); + rv = CallGetService(kRDFServiceCID, &gRDFService); if (NS_FAILED(rv)) return rv; gRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_RelatedLinksRoot), diff --git a/xpfe/components/search/src/nsInternetSearchService.cpp b/xpfe/components/search/src/nsInternetSearchService.cpp index 1c7edd27160..6261f21d7da 100755 --- a/xpfe/components/search/src/nsInternetSearchService.cpp +++ b/xpfe/components/search/src/nsInternetSearchService.cpp @@ -432,14 +432,10 @@ InternetSearchDataSource::InternetSearchDataSource(void) { if (gRefCnt++ == 0) { - nsresult rv = nsServiceManager::GetService(kRDFServiceCID, - NS_GET_IID(nsIRDFService), (nsISupports**) &gRDFService); - PR_ASSERT(NS_SUCCEEDED(rv)); - - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, - NS_GET_IID(nsIRDFContainerUtils), - (nsISupports**) &gRDFC); + nsresult rv = CallGetService(kRDFServiceCID, &gRDFService); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); + rv = CallGetService(kRDFContainerUtilsCID, &gRDFC); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF container utils"); gRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_SearchEngineRoot), @@ -545,8 +541,8 @@ InternetSearchDataSource::InternetSearchDataSource(void) gRDFService->GetLiteral(NS_LITERAL_STRING("true").get(), &kTrueLiteral); - rv = nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), getter_AddRefs(prefs)); - if (NS_SUCCEEDED(rv) && (prefs)) + prefs = do_GetService(kPrefCID); + if (prefs) { prefs->RegisterCallback("browser.search.mode", searchModePrefCallback, this); prefs->GetIntPref("browser.search.mode", &gBrowserSearchMode); @@ -635,18 +631,12 @@ InternetSearchDataSource::~InternetSearchDataSource (void) prefs = nsnull; } - if (gRDFC) - { - nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFC); - gRDFC = nsnull; - } + NS_IF_RELEASE(gRDFC); if (gRDFService) { gRDFService->UnregisterDataSource(this); - - nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService); - gRDFService = nsnull; + NS_RELEASE(gRDFService); } } } @@ -956,7 +946,7 @@ InternetSearchDataSource::Init() return(rv); rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), nsnull); - PR_ASSERT(NS_SUCCEEDED(rv)); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create load group"); if (!mTimer) { diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index 1b980c0907d..fe8c93d8a97 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -109,11 +109,9 @@ #endif static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); -static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); -static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID); #define kInstallLocaleProperties "chrome://global/locale/commonDialogs.properties" @@ -182,7 +180,6 @@ nsInstallInfo::~nsInstallInfo() MOZ_COUNT_DTOR(nsInstallInfo); } -static NS_DEFINE_IID(kISoftwareUpdateIID, NS_ISOFTWAREUPDATE_IID); static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); @@ -210,9 +207,7 @@ nsInstall::nsInstall(nsIZipReader * theJARFile) mJarFileData = theJARFile; nsISoftwareUpdate *su; - nsresult rv = nsServiceManager::GetService(kSoftwareUpdateCID, - kISoftwareUpdateIID, - (nsISupports**) &su); + nsresult rv = CallGetService(kSoftwareUpdateCID, &su); if (NS_SUCCEEDED(rv)) { @@ -1201,15 +1196,14 @@ nsInstall::LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aRetur } // initialize string bundle and related services - ret = nsServiceManager::GetService(kStringBundleServiceCID, - kIStringBundleServiceIID, (nsISupports**) &service); + ret = CallGetService(kStringBundleServiceCID, &service); if (NS_FAILED(ret)) goto cleanup; - ret = nsServiceManager::GetService(kEventQueueServiceCID, - kIEventQueueServiceIID, (nsISupports**) &pEventQueueService); + ret = CallGetService(kEventQueueServiceCID, &pEventQueueService); if (NS_FAILED(ret)) goto cleanup; ret = pEventQueueService->CreateThreadEventQueue(); + NS_RELEASE(pEventQueueService); if (NS_FAILED(ret)) goto cleanup; @@ -1220,7 +1214,7 @@ nsInstall::LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aRetur ret = NS_GetURLSpecFromFile(resFile, spec); if (NS_FAILED(ret)) { NS_WARNING("cannot get url spec\n"); - nsServiceManager::ReleaseService(kStringBundleServiceCID, service); + NS_RELEASE(service); return ret; } ret = service->CreateBundle(spec.get(), &bundle); @@ -1275,7 +1269,6 @@ cleanup: // release services NS_IF_RELEASE( service ); - NS_IF_RELEASE( pEventQueueService ); // release file, URL, StringBundle, Enumerator NS_IF_RELEASE( url ); diff --git a/xpinstall/src/nsUpdateNotification.cpp b/xpinstall/src/nsUpdateNotification.cpp index aa4a8015407..d0d7b41dfeb 100644 --- a/xpinstall/src/nsUpdateNotification.cpp +++ b/xpinstall/src/nsUpdateNotification.cpp @@ -101,11 +101,7 @@ nsXPINotifierImpl::nsXPINotifierImpl() nsXPINotifierImpl::~nsXPINotifierImpl() { - if (mRDF) - { - nsServiceManager::ReleaseService(kRDFServiceCID, mRDF); - mRDF = nsnull; - } + NS_IF_RELEASE(mRDF); NS_IF_RELEASE(kXPI_NotifierSources); NS_IF_RELEASE(kXPI_NotifierPackages); @@ -202,7 +198,7 @@ nsXPINotifierImpl::Init() PRBool moreElements; // Read the distributor registry - rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDF); + rv = CallGetService(kRDFServiceCID, &mRDF); if (NS_FAILED(rv)) return rv; if (! kXPI_NotifierSources)