nsCanvasRenderingContextGLPrivate::nsCanvasRenderingContextGLPrivate() : mGLPbuffer(nsnull), mWidth(0), mHeight(0), mCanvasElement(nsnull) { // grab the xpconnect service if (!gXPConnect) { nsresult rv = CallGetService(nsIXPConnect::GetCID(), &gXPConnect); if (NS_FAILED(rv)) { NS_ERROR("Failed to get XPConnect!"); return; } } else { NS_ADDREF(gXPConnect); } if (!gJSRuntimeService) { nsresult rv = CallGetService("@mozilla.org/js/xpc/RuntimeService;1", &gJSRuntimeService); if (NS_FAILED(rv)) { // uh.. NS_ERROR("Failed to get JS RuntimeService!"); return; } gJSRuntimeService->GetRuntime(&gScriptRuntime); if (!gScriptRuntime) { NS_RELEASE(gJSRuntimeService); gJSRuntimeService = nsnull; NS_ERROR("Unable to get JS runtime from JS runtime service"); } } else { NS_ADDREF(gJSRuntimeService); } }
int main() { /* * NOTE: This does NOT demonstrate how these functions are * intended to be used. They are intended for filling in out * parameters that need to be |AddRef|ed. I'm just too lazy * to write lots of little getter functions for a test program * when I don't need to. */ NS_NOTREACHED("This test is not intended to run, only to compile!"); /* Test CallQueryInterface */ nsISupports *mySupportsPtr = reinterpret_cast<nsISupports*>(0x1000); nsITestService *myITestService = nsnull; CallQueryInterface(mySupportsPtr, &myITestService); nsTestService *myTestService = reinterpret_cast<nsTestService*>(mySupportsPtr); nsISupportsWeakReference *mySupportsWeakRef; CallQueryInterface(myTestService, &mySupportsWeakRef); nsCOMPtr<nsISupports> mySupportsCOMPtr = mySupportsPtr; CallQueryInterface(mySupportsCOMPtr, &myITestService); nsRefPtr<nsTestService> myTestServiceRefPtr = myTestService; CallQueryInterface(myTestServiceRefPtr, &mySupportsWeakRef); /* Test CallQueryReferent */ nsIWeakReference *myWeakRef = static_cast<nsIWeakReference*>(mySupportsPtr); CallQueryReferent(myWeakRef, &myITestService); /* Test CallCreateInstance */ CallCreateInstance(kTestServiceCID, mySupportsPtr, &myITestService); CallCreateInstance(kTestServiceCID, &myITestService); CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, mySupportsPtr, &myITestService); CallCreateInstance(NS_TEST_SERVICE_CONTRACTID, &myITestService); /* Test CallGetService */ CallGetService(kTestServiceCID, &myITestService); CallGetService(NS_TEST_SERVICE_CONTRACTID, &myITestService); /* Test CallGetInterface */ nsIInterfaceRequestor *myInterfaceRequestor = static_cast<nsIInterfaceRequestor*>(mySupportsPtr); CallGetInterface(myInterfaceRequestor, &myITestService); return 0; }
TEST(LineBreak, WordBreaker) { nsIWordBreaker *t = nullptr; nsresult res = CallGetService(kWBrkCID, &t); ASSERT_TRUE(NS_SUCCEEDED(res) && t); NS_IF_RELEASE(t); res = CallGetService(kWBrkCID, &t); ASSERT_TRUE(NS_SUCCEEDED(res) && t); ASSERT_TRUE(TestASCIIWB(t, teng1, wexp1, sizeof(wexp1) / sizeof(uint32_t))); ASSERT_TRUE(TestASCIIWB(t, teng2, wexp2, sizeof(wexp2) / sizeof(uint32_t))); ASSERT_TRUE(TestASCIIWB(t, teng3, wexp3, sizeof(wexp3) / sizeof(uint32_t))); NS_RELEASE(t); }
nsresult init() { nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); if (NS_FAILED(rv)) return rv; return CallGetService(kCharsetConverterManagerCID, &ccMan); }
TEST(NormalizationTest, Main) { if (sizeof(wchar_t) != 2) { printf("This test can only be run where sizeof(wchar_t) == 2\n"); return; } if (strlen(versionText) == 0) { printf("No testcases: to run the tests generate the header file using\n"); printf(" perl genNormalizationData.pl\n"); printf("in intl/unichar/tools and rebuild\n"); return; } printf("NormalizationTest: test nsIUnicodeNormalizer. UCD version: %s\n", versionText); normalizer = nullptr; nsresult res; res = CallGetService(kUnicodeNormalizerCID, &normalizer); ASSERT_FALSE(NS_FAILED(res)) << "GetService failed"; ASSERT_NE(nullptr, normalizer); TestPart0(); TestPart1(); TestPart2(); TestPart3(); NS_RELEASE(normalizer); }
nsresult AsyncNoShutdownTest(int testNumber) { // This test gets a service, and also gets an async request for shutdown, // but the service doesn't get shut down because some other client (who's // not participating in the async shutdown game as he should) is // continuing to hang onto the service. This causes myServ variable to // get set to NULL, but the service doesn't get unloaded right away as // it should. nsresult err; err = BeginTest(testNumber); if (err != NS_OK) return err; // Create some other user of kIMyServiceCID, preventing it from // really going away: IMyService* otherClient; err = CallGetService(kIMyServiceCID, &otherClient); if (err != NS_OK) return err; err = AsyncShutdown(testNumber); if (err != NS_OK) return err; err = EndTest(testNumber); // Finally, release the other client. NS_RELEASE(otherClient); return err; }
nsresult nsDirIndexParser::Init() { mLineStart = 0; mHasDescription = PR_FALSE; mFormat = nsnull; // get default charset to be used for directory listings (fallback to // ISO-8859-1 if pref is unavailable). NS_NAMED_LITERAL_CSTRING(kFallbackEncoding, "ISO-8859-1"); nsXPIDLString defCharset; nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (prefs) { nsCOMPtr<nsIPrefLocalizedString> prefVal; prefs->GetComplexValue("intl.charset.default", NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(prefVal)); if (prefVal) prefVal->ToString(getter_Copies(defCharset)); } if (!defCharset.IsEmpty()) LossyCopyUTF16toASCII(defCharset, mEncoding); // charset labels are always ASCII else mEncoding.Assign(kFallbackEncoding); nsresult rv; // XXX not threadsafe if (gRefCntParser++ == 0) rv = CallGetService(NS_ITEXTTOSUBURI_CONTRACTID, &gTextToSubURI); else rv = NS_OK; return rv; }
nsresult nsXULContentUtils::Init() { if (gRefCnt++ == 0) { nsresult rv = CallGetService(kRDFServiceCID, &gRDF); if (NS_FAILED(rv)) { return rv; } #define XUL_RESOURCE(ident, uri) \ PR_BEGIN_MACRO \ rv = gRDF->GetResource(NS_LITERAL_CSTRING(uri), &(ident)); \ if (NS_FAILED(rv)) return rv; \ PR_END_MACRO #define XUL_LITERAL(ident, val) \ PR_BEGIN_MACRO \ rv = gRDF->GetLiteral(NS_LITERAL_STRING(val).get(), &(ident)); \ if (NS_FAILED(rv)) return rv; \ PR_END_MACRO #include "nsXULResourceList.h" #undef XUL_RESOURCE #undef XUL_LITERAL rv = CallCreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &gFormat); if (NS_FAILED(rv)) { return rv; } } return NS_OK; }
LocalSearchDataSource::LocalSearchDataSource(void) { if (gRefCnt++ == 0) { nsresult rv = CallGetService(kRDFServiceCID, &gRDFService); PR_ASSERT(NS_SUCCEEDED(rv)); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"), &kNC_Child); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"), &kNC_Name); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"), &kNC_URL); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "FindObject"), &kNC_FindObject); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "pulse"), &kNC_pulse); gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "instanceOf"), &kRDF_InstanceOf); gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"), &kRDF_type); gLocalSearchDataSource = this; } }
nsresult nsDownloadManager::Init() { if (gRefCnt++ != 0) { NS_NOTREACHED("download manager should be used as a service"); return NS_ERROR_UNEXPECTED; // This will make the |CreateInstance| fail. } if (!mCurrDownloads.Init()) return NS_ERROR_FAILURE; nsresult rv; mRDFContainerUtils = do_GetService("@mozilla.org/rdf/container-utils;1", &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIObserverService> obsService = do_GetService("@mozilla.org/observer-service;1", &rv); if (NS_FAILED(rv)) return rv; rv = CallGetService("@mozilla.org/rdf/rdf-service;1", &gRDFService); if (NS_FAILED(rv)) return rv; gRDFService->GetResource(NS_LITERAL_CSTRING("NC:DownloadsRoot"), &gNC_DownloadsRoot); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "File"), &gNC_File); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"), &gNC_URL); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"), &gNC_Name); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "ProgressMode"), &gNC_ProgressMode); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "ProgressPercent"), &gNC_ProgressPercent); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Transferred"), &gNC_Transferred); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "DownloadState"), &gNC_DownloadState); gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "StatusText"), &gNC_StatusText); nsCAutoString downloadsDB; rv = GetProfileDownloadsFileURL(downloadsDB); if (NS_FAILED(rv)) return rv; rv = gRDFService->GetDataSourceBlocking(downloadsDB.get(), getter_AddRefs(mDataSource)); if (NS_FAILED(rv)) return rv; mListener = do_CreateInstance("@mozilla.org/download-manager/listener;1", &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; rv = bundleService->CreateBundle(DOWNLOAD_MANAGER_BUNDLE, getter_AddRefs(mBundle)); if (NS_FAILED(rv)) return rv; // The following two AddObserver calls must be the last lines in this function, // because otherwise, this function may fail (and thus, this object would be not // completely initialized), but the observerservice would still keep a reference // to us and notify us about shutdown, which may cause crashes. // failure to add an observer is not critical obsService->AddObserver(this, "profile-before-change", PR_FALSE); obsService->AddObserver(this, "profile-approve-change", PR_FALSE); return NS_OK; }
static nsresult InitGlobals() { CallGetService(NS_PREF_CONTRACTID, &gPref); if (!gPref) return NS_ERROR_FAILURE; gFontMetricsCache = new nsHashtable(); return NS_OK; }
nsresult BeginTest(int testNumber) { nsresult err; NS_ASSERTION(myServ == NULL, "myServ not reset"); err = CallGetService(kIMyServiceCID, &myServ); return err; }
void SamplePrintWordWithBreak() { PRUint32 numOfFragment = sizeof(wb) / sizeof(char*); nsIWordBreakerFactory *t = NULL; nsresult res = CallGetService(kLWBrkCID, &t); nsIWordBreaker *wbk; nsAutoString wb_arg; res = t->GetBreaker(wb_arg, &wbk); nsAutoString result; nsAutoString tmp; for(PRUint32 i = 0; i < numOfFragment; i++) { nsAutoString fragText; fragText.AssignWithConversion(wb[i]); // nsBreakState bk(fragText.get(), fragText.Length()); PRUint32 cur = 0; PRBool done; res = wbk->NextWord(fragText.get(), fragText.Length(), cur, &cur, &done); PRUint32 start = 0; for(PRUint32 j = 0; ! done ; j++) { tmp.Truncate(); fragText.Mid(tmp, start, cur - start); result.Append(tmp); result.AppendLiteral("^"); start = cur; wbk->NextWord(fragText.get(), fragText.Length(), cur, &cur, &done); } tmp.Truncate(); fragText.Mid(tmp, start, fragText.Length() - start); result.Append(tmp); if( i != (numOfFragment -1 )) { nsAutoString nextFragText; nextFragText.AssignWithConversion(wb[i+1]); PRBool canBreak = PR_TRUE; res = wbk->BreakInBetween( fragText.get(), fragText.Length(), nextFragText.get(), nextFragText.Length(), &canBreak ); if(canBreak) result.AppendLiteral("^"); fragText = nextFragText; } } printf("Output From SamplePrintWordWithBreak() \n\n"); printf("[%s]\n", NS_LossyConvertUCS2toASCII(result).get()); }
nsXFormsAccessibleBase::nsXFormsAccessibleBase() { if (!sXFormsService) { nsresult rv = CallGetService("@mozilla.org/xforms-utility-service;1", &sXFormsService); if (NS_FAILED(rv)) NS_WARNING("No XForms utility service."); } }
nsBox::nsBox() { MOZ_COUNT_CTOR(nsBox); //mX = 0; //mY = 0; if (!gGotTheme) { gGotTheme = PR_TRUE; CallGetService("@mozilla.org/chrome/chrome-native-theme;1", &gTheme); } }
NS_IMETHODIMP nsTextToSubURI::ConvertAndEscape( const char *charset, const PRUnichar *text, char **_retval) { if(nullptr == _retval) return NS_ERROR_NULL_POINTER; *_retval = nullptr; nsresult rv = NS_OK; // Get Charset, get the encoder. nsICharsetConverterManager *ccm; rv = CallGetService(kCharsetConverterManagerCID, &ccm); if(NS_SUCCEEDED(rv)) { nsIUnicodeEncoder *encoder; rv = ccm->GetUnicodeEncoder(charset, &encoder); NS_RELEASE(ccm); if (NS_SUCCEEDED(rv)) { rv = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nullptr, (PRUnichar)'?'); if(NS_SUCCEEDED(rv)) { char buf[256]; char *pBuf = buf; int32_t ulen = text ? NS_strlen(text) : 0; int32_t outlen = 0; if(NS_SUCCEEDED(rv = encoder->GetMaxLength(text, ulen, &outlen))) { if(outlen >= 256) { pBuf = (char*)NS_Alloc(outlen+1); } if(nullptr == pBuf) { outlen = 255; pBuf = buf; } int32_t bufLen = outlen; if(NS_SUCCEEDED(rv = encoder->Convert(text,&ulen, pBuf, &outlen))) { // put termination characters (e.g. ESC(B of ISO-2022-JP) if necessary int32_t finLen = bufLen - outlen; if (finLen > 0) { if (NS_SUCCEEDED(encoder->Finish((char *)(pBuf+outlen), &finLen))) outlen += finLen; } pBuf[outlen] = '\0'; *_retval = nsEscape(pBuf, url_XPAlphas); if(nullptr == *_retval) rv = NS_ERROR_OUT_OF_MEMORY; } } if(pBuf != buf) NS_Free(pBuf); } NS_RELEASE(encoder); } } return rv; }
RDFContentSinkImpl::RDFContentSinkImpl() : mText(nsnull), mTextLength(0), mTextSize(0), mState(eRDFContentSinkState_InProlog), mParseMode(eRDFContentSinkParseMode_Literal), mContextStack(nsnull), mDocumentURL(nsnull) { if (gRefCnt++ == 0) { nsresult rv = CallGetService(kRDFServiceCID, &gRDFService); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); if (NS_SUCCEEDED(rv)) { rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"), &kRDF_type); rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "instanceOf"), &kRDF_instanceOf); rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "Alt"), &kRDF_Alt); rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "Bag"), &kRDF_Bag); rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "Seq"), &kRDF_Seq); rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "nextVal"), &kRDF_nextVal); } rv = CallGetService(kRDFContainerUtilsCID, &gRDFContainerUtils); NS_RegisterStaticAtoms(rdf_atoms, NS_ARRAY_LENGTH(rdf_atoms)); } mNodeIDMap.Init(); #ifdef PR_LOGGING if (! gLog) gLog = PR_NewLogModule("nsRDFContentSink"); #endif }
static nsIUGenCategory* GetGenCategory() { if (!gGenCategory) { nsresult rv = CallGetService(NS_UNICHARCATEGORY_CONTRACTID, &gGenCategory); if (NS_FAILED(rv)) { NS_ERROR("Failed to get the Unicode character category service!"); gGenCategory = nsnull; } } return gGenCategory; }
nsresult nsRDFXMLSerializer::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult) { if (aOuter) return NS_ERROR_NO_AGGREGATION; nsCOMPtr<nsIRDFXMLSerializer> result = new nsRDFXMLSerializer(); if (! result) return NS_ERROR_OUT_OF_MEMORY; // The serializer object is here, addref gRefCnt so that the // destructor can safely release it. gRefCnt++; nsresult rv; rv = result->QueryInterface(aIID, aResult); if (NS_FAILED(rv)) return rv; if (gRefCnt == 1) do { nsCOMPtr<nsIRDFService> rdf = do_GetService("@mozilla.org/rdf/rdf-service;1", &rv); if (NS_FAILED(rv)) break; rv = rdf->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "instanceOf"), &kRDF_instanceOf); if (NS_FAILED(rv)) break; rv = rdf->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"), &kRDF_type); if (NS_FAILED(rv)) break; rv = rdf->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "nextVal"), &kRDF_nextVal); if (NS_FAILED(rv)) break; rv = rdf->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "Bag"), &kRDF_Bag); if (NS_FAILED(rv)) break; rv = rdf->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "Seq"), &kRDF_Seq); if (NS_FAILED(rv)) break; rv = rdf->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "Alt"), &kRDF_Alt); if (NS_FAILED(rv)) break; rv = CallGetService("@mozilla.org/rdf/container-utils;1", &gRDFC); if (NS_FAILED(rv)) break; } while (0); return rv; }
/* static */ nsXULPrototypeCache* nsXULPrototypeCache::GetInstance() { // Theoretically this can return nsnull and callers should handle that. if (!sInstance) { nsIXULPrototypeCache* cache; CallGetService(kXULPrototypeCacheCID, &cache); sInstance = static_cast<nsXULPrototypeCache*>(cache); } return sInstance; }
int main(int argc, char** argv) { if (sizeof(wchar_t) != 2) { printf("This test can only be run where sizeof(wchar_t) == 2\n"); return 1; } if (strlen(versionText) == 0) { printf("No testcases: to run the tests generate the header file using\n"); printf(" perl genNormalizationData.pl\n"); printf("in intl/unichar/tools and rebuild\n"); return 1; } printf("NormalizationTest: test nsIUnicodeNormalizer. UCD version: %s\n", versionText); if (argc <= 1) verboseMode = false; else if ((argc == 2) && (!strcmp(argv[1], "-v"))) verboseMode = true; else { printf(" Usage: NormalizationTest [OPTION]..\n"); printf("Options:\n"); printf(" -v Verbose mode\n"); return 1; } nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr); if (NS_FAILED(rv)) { printf("NS_InitXPCOM2 failed\n"); return 1; } normalizer = nullptr; nsresult res; res = CallGetService(kUnicodeNormalizerCID, &normalizer); if(NS_FAILED(res) || !normalizer) { printf("GetService failed\n"); return 1; } TestPart0(); TestPart1(); TestPart2(); TestPart3(); NS_RELEASE(normalizer); printf("Test finished \n"); return 0; }
NS_IMETHODIMP nsSocketProviderService::GetSocketProvider(const char *type, nsISocketProvider **result) { nsresult rv; nsCAutoString contractID( NS_LITERAL_CSTRING(NS_NETWORK_SOCKET_CONTRACTID_PREFIX) + nsDependentCString(type)); rv = CallGetService(contractID.get(), result); if (NS_FAILED(rv)) rv = NS_ERROR_UNKNOWN_SOCKET_TYPE; return rv; }
void TestNormalization() { printf("==============================\n"); printf("Start nsIUnicodeNormalizer Test \n"); printf("==============================\n"); nsIUnicodeNormalizer *t = nullptr; nsresult res; res = CallGetService(kUnicodeNormalizerCID, &t); printf("Test 1 - GetService():\n"); if(NS_FAILED(res) || !t) { printf("\t1st Norm GetService failed\n"); } else { NS_RELEASE(t); } res = CallGetService(kUnicodeNormalizerCID, &t); if(NS_FAILED(res) || !t) { printf("\t2nd GetService failed\n"); } else { printf("Test 2 - NormalizeUnicode(uint32_t, const nsAString&, nsAString&):\n"); nsAutoString resultStr; res = t->NormalizeUnicodeNFD(nsDependentString(normStr), resultStr); if (resultStr.Equals(nsDependentString(nfdForm))) { printf(" Succeeded in NFD UnicodeNormalizer test. \n"); } else { printf(" Failed in NFD UnicodeNormalizer test. \n"); } NS_RELEASE(t); } printf("==============================\n"); printf("Finish nsIUnicodeNormalizer Test \n"); printf("==============================\n"); }
static nsINativeKeyBindings* GetEditorKeyBindings() { static PRBool noBindings = PR_FALSE; if (!sNativeEditorBindings && !noBindings) { CallGetService(NS_NATIVEKEYBINDINGS_CONTRACTID_PREFIX "editor", &sNativeEditorBindings); if (!sNativeEditorBindings) { noBindings = PR_TRUE; } } return sNativeEditorBindings; }
//----------------------------------------------------- // construction //----------------------------------------------------- nsNativeDragTarget::nsNativeDragTarget(nsIWidget * aWnd) : m_cRef(0), mWindow(aWnd), mCanMove(PR_TRUE), mTookOwnRef(PR_FALSE), mDropTargetHelper(nsnull), mDragCancelled(PR_FALSE) { mHWnd = (HWND)mWindow->GetNativeData(NS_NATIVE_WINDOW); /* * Create/Get the DragService that we have implemented */ CallGetService(kCDragServiceCID, &mDragService); // Drag target helper for drag image support CoCreateInstance(CLSID_DragDropHelper, NULL, CLSCTX_INPROC_SERVER, IID_IDropTargetHelper, (LPVOID*)&mDropTargetHelper); }
FcCharSet * mozilla_decoder_get_charset (PangoFcDecoder *decoder, PangoFcFont *fcfont) { MozillaDecoderPrivate *priv = MOZILLA_DECODER_GET_PRIVATE(decoder); if (priv->charset) return priv->charset; // First time this has been accessed. Populate the charset. priv->charset = FcCharSetCreate(); if (!gCharsetManager) { CallGetService(kCharsetConverterManagerCID, &gCharsetManager); } nsCOMPtr<nsIUnicodeEncoder> encoder; nsCOMPtr<nsICharRepresentable> represent; if (!gCharsetManager) goto end; gCharsetManager->GetUnicodeEncoderRaw(priv->encoder, getter_AddRefs(encoder)); if (!encoder) goto end; encoder->SetOutputErrorBehavior(encoder->kOnError_Replace, nsnull, '?'); priv->uEncoder = encoder; represent = do_QueryInterface(encoder); if (!represent) goto end; PRUint32 map[UCS2_MAP_LEN]; memset(map, 0, sizeof(map)); represent->FillInfo(map); for (int i = 0; i < NUM_UNICODE_CHARS; i++) { if (IS_REPRESENTABLE(map, i)) FcCharSetAddChar(priv->charset, i); } end: return priv->charset; }
nsISupports* OS2Uni::GetUconvObject(int aCodePage, ConverterRequest aReq) { if (gCharsetManager == nullptr) { CallGetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &gCharsetManager); } nsresult rv; nsISupports* uco = nullptr; for (int i = 0; i < eCONVERTER_COUNT; i++) { if (aCodePage == gConverterInfo[i].mCodePage) { if (gConverterInfo[i].mEncoder == nullptr) { const char* convname; nsAutoCString charset; if (aCodePage == 0) { nsCOMPtr<nsIPlatformCharset> plat(do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { plat->GetCharset(kPlatformCharsetSel_FileName, charset); } else { // default to IBM850 if this should fail charset = "IBM850"; } convname = charset.get(); } else { convname = gConverterInfo[i].mConvName; } rv = gCharsetManager->GetUnicodeEncoderRaw(convname, &gConverterInfo[i].mEncoder); gConverterInfo[i].mEncoder-> SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nullptr, '?'); gCharsetManager->GetUnicodeDecoderRaw(convname, &gConverterInfo[i].mDecoder); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to get converter"); } if (aReq == eConv_Encoder) { uco = gConverterInfo[i].mEncoder; } else { uco = gConverterInfo[i].mDecoder; } break; } } return uco; }
NS_IMETHODIMP nsRDFResource::Init(const char* aURI) { NS_PRECONDITION(aURI != nullptr, "null ptr"); if (! aURI) return NS_ERROR_NULL_POINTER; mURI = aURI; if (gRDFServiceRefCnt++ == 0) { nsresult rv = CallGetService(kRDFServiceCID, &gRDFService); if (NS_FAILED(rv)) return rv; } // don't replace an existing resource with the same URI automatically return gRDFService->RegisterResource(this, true); }
void TestPrintWordWithBreak() { uint32_t numOfFragment = sizeof(wb) / sizeof(char*); nsIWordBreaker* wbk = nullptr; CallGetService(kWBrkCID, &wbk); nsAutoString result; for (uint32_t i = 0; i < numOfFragment; i++) { NS_ConvertASCIItoUTF16 fragText(wb[i]); int32_t cur = 0; cur = wbk->NextWord(fragText.get(), fragText.Length(), cur); uint32_t start = 0; for (uint32_t j = 0; cur != NS_WORDBREAKER_NEED_MORE_TEXT; j++) { result.Append(Substring(fragText, start, cur - start)); result.Append('^'); start = (cur >= 0 ? cur : cur - start); cur = wbk->NextWord(fragText.get(), fragText.Length(), cur); } result.Append(Substring(fragText, fragText.Length() - start)); if (i != numOfFragment - 1) { NS_ConvertASCIItoUTF16 nextFragText(wb[i+1]); bool canBreak = true; canBreak = wbk->BreakInBetween(fragText.get(), fragText.Length(), nextFragText.get(), nextFragText.Length()); if (canBreak) { result.Append('^'); } fragText.Assign(nextFragText); } } ASSERT_STREQ("is^ ^is^ ^a^ ^ is a intzation^ ^work^ation work.", NS_ConvertUTF16toUTF8(result).get()); NS_IF_RELEASE(wbk); }
nsresult nsHttpChannelAuthProvider::GetAuthenticator(const char *challenge, nsCString &authType, nsIHttpAuthenticator **auth) { LOG(("nsHttpChannelAuthProvider::GetAuthenticator [this=%p channel=%p]\n", this, mAuthChannel)); GetAuthType(challenge, authType); // normalize to lowercase ToLowerCase(authType); nsCAutoString contractid; contractid.Assign(NS_HTTP_AUTHENTICATOR_CONTRACTID_PREFIX); contractid.Append(authType); return CallGetService(contractid.get(), auth); }