nsresult SpdyInformation::GetNPNVersionIndex(const nsACString &npnString, uint8_t *result) { if (npnString.IsEmpty()) return NS_ERROR_FAILURE; if (npnString.Equals(VersionString[0])) *result = Version[0]; else if (npnString.Equals(VersionString[1])) *result = Version[1]; else return NS_ERROR_FAILURE; return NS_OK; }
nsresult SpdyInformation::GetNPNVersionIndex(const nsACString &npnString, uint8_t *result) { if (npnString.IsEmpty()) return NS_ERROR_FAILURE; for (uint32_t index = 0; index < kCount; ++index) { if (npnString.Equals(VersionString[index])) { *result = Version[index]; return NS_OK; } } return NS_ERROR_FAILURE; }
IndexedDatabaseManager::AsyncUsageRunnable::AsyncUsageRunnable( nsIURI* aURI, const nsACString& aOrigin, nsIIndexedDatabaseUsageCallback* aCallback) : mURI(aURI), mOrigin(aOrigin), mCallback(aCallback), mUsage(0), mFileUsage(0), mCanceled(0) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(aURI, "Null pointer!"); NS_ASSERTION(!aOrigin.IsEmpty(), "Empty origin!"); NS_ASSERTION(aCallback, "Null pointer!"); }
nsresult nsUrlClassifierStreamUpdater::FetchUpdate(nsIURI *aUpdateUrl, const nsACString & aRequestBody, const nsACString & aStreamTable, const nsACString & aServerMAC) { nsresult rv; uint32_t loadFlags = nsIChannel::INHIBIT_CACHING | nsIChannel::LOAD_BYPASS_CACHE; rv = NS_NewChannel(getter_AddRefs(mChannel), aUpdateUrl, nullptr, nullptr, this, loadFlags); NS_ENSURE_SUCCESS(rv, rv); mBeganStream = false; // If aRequestBody is empty, construct it for the test. if (!aRequestBody.IsEmpty()) { rv = AddRequestBody(aRequestBody); NS_ENSURE_SUCCESS(rv, rv); } // Set the appropriate content type for file/data URIs, for unit testing // purposes. // This is only used for testing and should be deleted. bool match; if ((NS_SUCCEEDED(aUpdateUrl->SchemeIs("file", &match)) && match) || (NS_SUCCEEDED(aUpdateUrl->SchemeIs("data", &match)) && match)) { mChannel->SetContentType(NS_LITERAL_CSTRING("application/vnd.google.safebrowsing-update")); } // Create a custom LoadContext for SafeBrowsing, so we can use callbacks on // the channel to query the appId which allows separation of safebrowsing // cookies in a separate jar. nsCOMPtr<nsIInterfaceRequestor> sbContext = new mozilla::LoadContext(NECKO_SAFEBROWSING_APP_ID); rv = mChannel->SetNotificationCallbacks(sbContext); NS_ENSURE_SUCCESS(rv, rv); // Make the request rv = mChannel->AsyncOpen(this, nullptr); NS_ENSURE_SUCCESS(rv, rv); mStreamTable = aStreamTable; mServerMAC = aServerMAC; return NS_OK; }
nsresult nsDOMStoragePersistentDB::EnsureQuotaUsageLoaded(const nsACString& aQuotaKey) { if (aQuotaKey.IsEmpty() || mQuotaUseByUncached.Get(aQuotaKey, nullptr)) { return NS_OK; } else if (mWasRemoveAllCalled || mIsRemoveAllPending) { mQuotaUseByUncached.Put(aQuotaKey, 0); return NS_OK; } Telemetry::AutoTimer<Telemetry::LOCALDOMSTORAGE_FETCH_QUOTA_USE_MS> timer; // Fetch information about all the scopes belonging to this site nsCOMPtr<mozIStorageStatement> stmt; stmt = mReadStatements.GetCachedStatement( "SELECT scope, SUM(LENGTH(key) + LENGTH(value)) " "FROM ( " "SELECT scope, key, value FROM webappsstore2 " "WHERE scope LIKE :quotaKey" ") " "GROUP BY scope" ); NS_ENSURE_STATE(stmt); mozStorageStatementScoper scope(stmt); nsresult rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("quotaKey"), aQuotaKey + NS_LITERAL_CSTRING("%")); NS_ENSURE_SUCCESS(rv, rv); int32_t uncachedSize = 0; bool exists; while (NS_SUCCEEDED(rv = stmt->ExecuteStep(&exists)) && exists) { nsAutoCString scopeName; rv = stmt->GetUTF8String(0, scopeName); NS_ENSURE_SUCCESS(rv, rv); int32_t quotaUsage; rv = stmt->GetInt32(1, "aUsage); NS_ENSURE_SUCCESS(rv, rv); if (!mCache.IsScopeCached(scopeName)) { uncachedSize += quotaUsage; } } mQuotaUseByUncached.Put(aQuotaKey, uncachedSize); return NS_OK; }
void nsJAR::ReportError(const nsACString &aFilename, int16_t errorCode) { //-- Generate error message nsAutoString message; message.AssignLiteral("Signature Verification Error: the signature on "); if (!aFilename.IsEmpty()) AppendASCIItoUTF16(aFilename, message); else message.AppendLiteral("this .jar archive"); message.AppendLiteral(" is invalid because "); switch(errorCode) { case JAR_NOT_SIGNED: message.AppendLiteral("the archive did not contain a valid PKCS7 signature."); break; case JAR_INVALID_SIG: message.AppendLiteral("the digital signature (*.RSA) file is not a valid signature of the signature instruction file (*.SF)."); break; case JAR_INVALID_UNKNOWN_CA: message.AppendLiteral("the certificate used to sign this file has an unrecognized issuer."); break; case JAR_INVALID_MANIFEST: message.AppendLiteral("the signature instruction file (*.SF) does not contain a valid hash of the MANIFEST.MF file."); break; case JAR_INVALID_ENTRY: message.AppendLiteral("the MANIFEST.MF file does not contain a valid hash of the file being verified."); break; case JAR_NO_MANIFEST: message.AppendLiteral("the archive did not contain a manifest."); break; default: message.AppendLiteral("of an unknown problem."); } // Report error in JS console nsCOMPtr<nsIConsoleService> console(do_GetService("@mozilla.org/consoleservice;1")); if (console) { console->LogStringMessage(message.get()); } #ifdef DEBUG char* messageCstr = ToNewCString(message); if (!messageCstr) return; fprintf(stderr, "%s\n", messageCstr); nsMemory::Free(messageCstr); #endif }
bool Throw(JSContext* aCx, nsresult aRv, const nsACString& aMessage) { if (aRv == NS_ERROR_UNCATCHABLE_EXCEPTION) { // Nuke any existing exception on aCx, to make sure we're uncatchable. JS_ClearPendingException(aCx); return false; } if (JS_IsExceptionPending(aCx)) { // Don't clobber the existing exception. return false; } CycleCollectedJSRuntime* runtime = CycleCollectedJSRuntime::Get(); nsCOMPtr<nsIException> existingException = runtime->GetPendingException(); // Make sure to clear the pending exception now. Either we're going to reuse // it (and we already grabbed it), or we plan to throw something else and this // pending exception is no longer relevant. runtime->SetPendingException(nullptr); // Ignore the pending exception if we have a non-default message passed in. if (aMessage.IsEmpty() && existingException) { nsresult nr; if (NS_SUCCEEDED(existingException->GetResult(&nr)) && aRv == nr) { // Reuse the existing exception. if (!ThrowExceptionObject(aCx, existingException)) { // If we weren't able to throw an exception we're // most likely out of memory JS_ReportOutOfMemory(aCx); } return false; } } RefPtr<Exception> finalException = CreateException(aCx, aRv, aMessage); MOZ_ASSERT(finalException); if (!ThrowExceptionObject(aCx, finalException)) { // If we weren't able to throw an exception we're // most likely out of memory JS_ReportOutOfMemory(aCx); } return false; }
SRIMetadata::SRIMetadata(const nsACString& aToken) : mAlgorithmType(SRIMetadata::UNKNOWN_ALGORITHM), mEmpty(false) { MOZ_ASSERT(!aToken.IsEmpty()); // callers should check this first SRIMETADATALOG(("SRIMetadata::SRIMetadata, aToken='%s'", PromiseFlatCString(aToken).get())); int32_t hyphen = aToken.FindChar('-'); if (hyphen == -1) { SRIMETADATAERROR(("SRIMetadata::SRIMetadata, invalid (no hyphen)")); return; // invalid metadata } // split the token into its components mAlgorithm = Substring(aToken, 0, hyphen); uint32_t hashStart = hyphen + 1; if (hashStart >= aToken.Length()) { SRIMETADATAERROR(("SRIMetadata::SRIMetadata, invalid (missing digest)")); return; // invalid metadata } int32_t question = aToken.FindChar('?'); if (question == -1) { mHashes.AppendElement(Substring(aToken, hashStart, aToken.Length() - hashStart)); } else { MOZ_ASSERT(question > 0); if (static_cast<uint32_t>(question) <= hashStart) { SRIMETADATAERROR(("SRIMetadata::SRIMetadata, invalid (options w/o digest)")); return; // invalid metadata } mHashes.AppendElement(Substring(aToken, hashStart, question - hashStart)); } if (mAlgorithm.EqualsLiteral("sha256")) { mAlgorithmType = nsICryptoHash::SHA256; } else if (mAlgorithm.EqualsLiteral("sha384")) { mAlgorithmType = nsICryptoHash::SHA384; } else if (mAlgorithm.EqualsLiteral("sha512")) { mAlgorithmType = nsICryptoHash::SHA512; } SRIMETADATALOG(("SRIMetadata::SRIMetadata, hash='%s'; alg='%s'", mHashes[0].get(), mAlgorithm.get())); }
//-------------------------------------------------------------- NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsACString& aAlias, nsACString& oResult) { if (aAlias.IsEmpty()) return NS_ERROR_NULL_POINTER; NS_TIMELINE_START_TIMER("nsCharsetAlias2:GetPreferred"); // Delay loading charsetalias.properties by hardcoding the most // frequent aliases. Note that it's possible to recur in to this // function *while loading* charsetalias.properties (see bug 190951), // so we might have an |mDelegate| already that isn't valid yet, but // the load is guaranteed to be "UTF-8" so things will be OK. for (PRUint32 index = 0; index < NS_ARRAY_LENGTH(kAliases); index++) { if (aAlias.LowerCaseEqualsASCII(kAliases[index][0])) { oResult.Assign(nsDependentCString(kAliases[index][1], NS_PTR_TO_UINT32(kAliases[index][2]))); NS_TIMELINE_STOP_TIMER("nsCharsetAlias2:GetPreferred"); return NS_OK; } } oResult.Truncate(); if(!mDelegate) { //load charsetalias.properties string bundle with all remaining aliases // we may need to protect the following section with a lock so we won't call the // 'new nsGREResProperties' from two different threads mDelegate = new nsGREResProperties( NS_LITERAL_CSTRING("charsetalias.properties") ); NS_ASSERTION(mDelegate, "cannot create nsGREResProperties"); if(nsnull == mDelegate) return NS_ERROR_OUT_OF_MEMORY; } NS_TIMELINE_STOP_TIMER("nsCharsetAlias2:GetPreferred"); NS_TIMELINE_MARK_TIMER("nsCharsetAlias2:GetPreferred"); nsCAutoString key(aAlias); ToLowerCase(key); // hack for now, have to fix nsGREResProperties, but we can't until // string bundles use UTF8 keys nsAutoString result; nsresult rv = mDelegate->Get(NS_ConvertASCIItoUTF16(key), result); LossyAppendUTF16toASCII(result, oResult); return rv; }
// static bool IndexedDatabaseManager::TabContextMayAccessOrigin(const TabContext& aContext, const nsACString& aOrigin) { NS_ASSERTION(!aOrigin.IsEmpty(), "Empty origin!"); // If aContext is for a browser element, it's allowed only to access other // browser elements. But if aContext is not for a browser element, it may // access both browser and non-browser elements. nsAutoCString pattern; QuotaManager::GetOriginPatternStringMaybeIgnoreBrowser( aContext.OwnOrContainingAppId(), aContext.IsBrowserElement(), pattern); return PatternMatchesOrigin(pattern, aOrigin); }
NS_IMETHODIMP PresentationService::SendSessionBinaryMsg(const nsAString& aSessionId, uint8_t aRole, const nsACString& aData) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(!aData.IsEmpty()); MOZ_ASSERT(!aSessionId.IsEmpty()); MOZ_ASSERT(aRole == nsIPresentationService::ROLE_CONTROLLER || aRole == nsIPresentationService::ROLE_RECEIVER); RefPtr<PresentationSessionInfo> info = GetSessionInfo(aSessionId, aRole); if (NS_WARN_IF(!info)) { return NS_ERROR_NOT_AVAILABLE; } return info->SendBinaryMsg(aData); }
nsresult nsNPAPIPluginInstance::Initialize(nsNPAPIPlugin *aPlugin, nsPluginInstanceOwner* aOwner, const nsACString& aMIMEType) { PROFILER_LABEL_FUNC(js::ProfileEntry::Category::OTHER); PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("nsNPAPIPluginInstance::Initialize this=%p\n",this)); NS_ENSURE_ARG_POINTER(aPlugin); NS_ENSURE_ARG_POINTER(aOwner); mPlugin = aPlugin; mOwner = aOwner; if (!aMIMEType.IsEmpty()) { mMIMEType = ToNewCString(aMIMEType); } return Start(); }
static nsresult ConvertLocaleToCharsetUsingDeprecatedConfig(const nsACString& locale, nsACString& oResult) { if (!(locale.IsEmpty())) { nsCAutoString localeKey; localeKey.AssignLiteral("locale.all."); localeKey.Append(locale); if (NS_SUCCEEDED(nsUConvPropertySearch::SearchPropertyValue(kUnixCharsets, ArrayLength(kUnixCharsets), localeKey, oResult))) { return NS_OK; } } NS_ERROR("unable to convert locale to charset using deprecated config"); oResult.AssignLiteral("ISO-8859-1"); return NS_SUCCESS_USING_FALLBACK_LOCALE; }
//-------------------------------------------------------------- NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsACString& aAlias, nsACString& oResult) { if (aAlias.IsEmpty()) return NS_ERROR_NULL_POINTER; NS_TIMELINE_START_TIMER("nsCharsetAlias2:GetPreferred"); nsCAutoString key(aAlias); ToLowerCase(key); nsresult rv = nsUConvPropertySearch::SearchPropertyValue(kAliases, NS_ARRAY_LENGTH(kAliases), key, oResult); NS_TIMELINE_STOP_TIMER("nsCharsetAlias2:GetPreferred"); NS_TIMELINE_MARK_TIMER("nsCharsetAlias2:GetPreferred"); return rv; }
NS_IMETHODIMP sbTagLibChannelFileIOManager::SetChannelRestart( const nsACString &aChannelID, PRBool aRestart) { sbTagLibChannelFileIOManager::Channel *pChannel; nsresult rv; /* Validate parameters. */ NS_ENSURE_FALSE(aChannelID.IsEmpty(), NS_ERROR_INVALID_ARG); /* Set the channel restart flag. */ rv = GetChannel(aChannelID, &pChannel); NS_ENSURE_SUCCESS(rv, rv); pChannel->restart = aRestart; return (NS_OK); }
nsresult nsHttpHeaderArray::SetHeader(nsHttpAtom header, const nsACString &value, PRBool merge) { nsEntry *entry = nsnull; PRInt32 index; index = LookupEntry(header, &entry); // If an empty value is passed in, then delete the header entry... // unless we are merging, in which case this function becomes a NOP. if (value.IsEmpty()) { if (!merge && entry) mHeaders.RemoveElementAt(index); return NS_OK; } // Create a new entry, or... if (!entry) { entry = mHeaders.AppendElement(); //new nsEntry(header, value); if (!entry) return NS_ERROR_OUT_OF_MEMORY; entry->header = header; entry->value = value; } // Append the new value to the existing value iff... else if (merge && CanAppendToHeader(header)) { if (header == nsHttp::Set_Cookie || header == nsHttp::WWW_Authenticate || header == nsHttp::Proxy_Authenticate) // Special case these headers and use a newline delimiter to // delimit the values from one another as commas may appear // in the values of these headers contrary to what the spec says. entry->value.Append('\n'); else // Delimit each value from the others using a comma (per HTTP spec) entry->value.AppendLiteral(", "); entry->value.Append(value); } // Replace the existing string with the new value else entry->value = value; return NS_OK; }
nsresult nsChromeRegistryChrome::GetSelectedLocale(const nsACString& aPackage, nsACString& aLocale) { nsCString realpackage; nsresult rv = OverrideLocalePackage(aPackage, realpackage); if (NS_FAILED(rv)) return rv; PackageEntry* entry; if (!mPackagesHash.Get(realpackage, &entry)) return NS_ERROR_FILE_NOT_FOUND; aLocale = entry->locales.GetSelected(mSelectedLocale, nsProviderArray::LOCALE); if (aLocale.IsEmpty()) return NS_ERROR_FAILURE; return NS_OK; }
nsresult nsMsgFolderCache::AddCacheElement(const nsACString& key, nsIMdbRow *row, nsIMsgFolderCacheElement **result) { nsMsgFolderCacheElement *cacheElement = new nsMsgFolderCacheElement; NS_ENSURE_TRUE(cacheElement, NS_ERROR_OUT_OF_MEMORY); nsCOMPtr<nsIMsgFolderCacheElement> folderCacheEl(do_QueryInterface(cacheElement)); cacheElement->SetMDBRow(row); cacheElement->SetOwningCache(this); nsCString hashStrKey(key); // if caller didn't pass in key, try to get it from row. if (key.IsEmpty()) folderCacheEl->GetStringProperty("key", hashStrKey); folderCacheEl->SetKey(hashStrKey); m_cacheElements.Put(hashStrKey, folderCacheEl); if (result) folderCacheEl.swap(*result); return NS_OK; }
/** * Add data to the context that should be verified. */ nsresult ContentVerifier::Update(const nsACString& aData) { nsNSSShutDownPreventionLock locker; if (isAlreadyShutDown()) { return NS_ERROR_INVALID_SIGNATURE; } if (!aData.IsEmpty()) { if (VFY_Update(mCx.get(), (const unsigned char*)nsPromiseFlatCString(aData).get(), aData.Length()) != SECSuccess) { return NS_ERROR_INVALID_SIGNATURE; } } return NS_OK; }
NS_IMETHODIMP nsJAR::FindEntries(const nsACString &aPattern, nsIUTF8StringEnumerator **result) { NS_ENSURE_ARG_POINTER(result); nsZipFind *find; nsresult rv = mZip->FindInit(aPattern.IsEmpty()? nullptr : PromiseFlatCString(aPattern).get(), &find); NS_ENSURE_SUCCESS(rv, rv); nsIUTF8StringEnumerator *zipEnum = new nsJAREnumerator(find); if (!zipEnum) { delete find; return NS_ERROR_OUT_OF_MEMORY; } NS_ADDREF(*result = zipEnum); return NS_OK; }
nsCOMArray<msgIAddressObject> EncodedHeader(const nsACString &aHeader, const char *aCharset) { nsCOMArray<msgIAddressObject> retval; if (aHeader.IsEmpty()) { return retval; } nsCOMPtr<nsIMsgHeaderParser> headerParser(services::GetHeaderParser()); NS_ENSURE_TRUE(headerParser, retval); msgIAddressObject **addresses = nullptr; uint32_t length; nsresult rv = headerParser->ParseEncodedHeader(aHeader, aCharset, false, &length, &addresses); MOZ_ASSERT(NS_SUCCEEDED(rv), "This should never fail!"); if (NS_SUCCEEDED(rv) && length > 0 && addresses) { retval.Adopt(addresses, length); } return retval; }
/* static */ nsresult sbURIChecker::FixupDomain( const nsACString& aDomain, nsACString& _retval ) { // aDomain may be empty if ( aDomain.IsEmpty() ) { _retval.Truncate(); return NS_OK; } nsCString domain(aDomain); domain.Trim("./"); ToLowerCase(domain); _retval.Assign(domain); return NS_OK; }
void IndexedDatabaseManager::InvalidateFileManagers(PersistenceType aPersistenceType, const nsACString& aOrigin) { AssertIsOnIOThread(); MOZ_ASSERT(!aOrigin.IsEmpty()); FileManagerInfo* info; if (!mFileManagerInfos.Get(aOrigin, &info)) { return; } info->InvalidateAndRemoveFileManagers(aPersistenceType); if (!info->HasFileManagers()) { mFileManagerInfos.Remove(aOrigin); } }
NS_IMETHODIMP nsAbMDBDirectory::CardForEmailAddress(const nsACString &aEmailAddress, nsIAbCard ** aAbCard) { NS_ENSURE_ARG_POINTER(aAbCard); *aAbCard = nullptr; // Ensure that if we've not been given an email address we never match // so that we don't fail out unnecessarily and we don't match a blank email // address against random cards that the user hasn't supplied an email for. if (aEmailAddress.IsEmpty()) return NS_OK; nsresult rv = NS_OK; if (!mDatabase) rv = GetAbDatabase(); if (rv == NS_ERROR_FILE_NOT_FOUND) { // If file wasn't found, the card cannot exist. return NS_OK; } NS_ENSURE_SUCCESS(rv, rv); // Convert Email to lower case in UTF-16 format. This correctly lower-cases // it and doing this change means that we can use a hash lookup in the // database rather than searching and comparing each line individually. NS_ConvertUTF8toUTF16 lowerEmail(aEmailAddress); ToLowerCase(lowerEmail); // If lower email is empty, something went wrong somewhere, e.g. the conversion. // Hence, don't go looking for a card with no email address. Something is wrong. if (lowerEmail.IsEmpty()) return NS_ERROR_FAILURE; mDatabase->GetCardFromAttribute(this, kLowerPriEmailColumn, NS_ConvertUTF16toUTF8(lowerEmail), false, aAbCard); if (!*aAbCard) { mDatabase->GetCardFromAttribute(this, kLower2ndEmailColumn, NS_ConvertUTF16toUTF8(lowerEmail), false, aAbCard); } return NS_OK; }
NS_IMETHODIMP InterceptedChannelContent::StartSynthesizedResponse(nsIInputStream* aBody, nsIInterceptedBodyCallback* aBodyCallback, nsICacheInfoChannel* aCacheInfoChannel, const nsACString& aFinalURLSpec, bool aResponseRedirected) { if (NS_WARN_IF(mClosed)) { return NS_ERROR_NOT_AVAILABLE; } EnsureSynthesizedResponse(); nsCOMPtr<nsIURI> originalURI; mChannel->GetURI(getter_AddRefs(originalURI)); nsCOMPtr<nsIURI> responseURI; if (!aFinalURLSpec.IsEmpty()) { nsresult rv = NS_NewURI(getter_AddRefs(responseURI), aFinalURLSpec); NS_ENSURE_SUCCESS(rv, rv); } else if (mSecureUpgrade) { nsresult rv = NS_GetSecureUpgradedURI(originalURI, getter_AddRefs(responseURI)); NS_ENSURE_SUCCESS(rv, rv); } else { responseURI = originalURI; } bool equal = false; originalURI->Equals(responseURI, &equal); if (!equal) { mChannel->ForceIntercepted(aBody, aBodyCallback, aCacheInfoChannel); mChannel->BeginNonIPCRedirect(responseURI, *mSynthesizedResponseHead.ptr(), aResponseRedirected); } else { mChannel->OverrideWithSynthesizedResponse(mSynthesizedResponseHead.ref(), aBody, aBodyCallback, mStreamListener, aCacheInfoChannel); } return NS_OK; }
NS_IMETHODIMP nsMIMEInfoAndroid::ExtensionExists(const nsACString & aExtension, bool *aRetVal) { NS_ASSERTION(!aExtension.IsEmpty(), "no extension"); bool found = false; PRUint32 extCount = mExtensions.Length(); if (extCount < 1) return NS_OK; for (PRUint8 i=0; i < extCount; i++) { const nsCString& ext = mExtensions[i]; if (ext.Equals(aExtension, nsCaseInsensitiveCStringComparator())) { found = true; break; } } *aRetVal = found; return NS_OK; }
NS_IMETHODIMP HttpBaseChannel::SetUploadStream(nsIInputStream *stream, const nsACString &contentType, PRInt32 contentLength) { // NOTE: for backwards compatibility and for compatibility with old style // plugins, |stream| may include headers, specifically Content-Type and // Content-Length headers. in this case, |contentType| and |contentLength| // would be unspecified. this is traditionally the case of a POST request, // and so we select POST as the request method if contentType and // contentLength are unspecified. if (stream) { if (contentType.IsEmpty()) { mUploadStreamHasHeaders = true; mRequestHead.SetMethod(nsHttp::Post); // POST request } else { if (contentLength < 0) { // Not really kosher to assume Available == total length of // stream, but apparently works for the streams we see here. stream->Available((PRUint32 *) &contentLength); if (contentLength < 0) { NS_ERROR("unable to determine content length"); return NS_ERROR_FAILURE; } } // SetRequestHeader propagates headers to chrome if HttpChannelChild nsCAutoString contentLengthStr; contentLengthStr.AppendInt(PRInt64(contentLength)); SetRequestHeader(NS_LITERAL_CSTRING("Content-Length"), contentLengthStr, false); SetRequestHeader(NS_LITERAL_CSTRING("Content-Type"), contentType, false); mUploadStreamHasHeaders = false; mRequestHead.SetMethod(nsHttp::Put); // PUT request } } else { mUploadStreamHasHeaders = false; mRequestHead.SetMethod(nsHttp::Get); // revert to GET request } mUploadStream = stream; return NS_OK; }
static void DispatchNotification(nsISupports* aSubject, const NotificationAndReportStringId& aNotification, bool aIsSolved, const nsAString& aFormats, const nsAString& aDecodeIssue, const nsACString& aDocURL, const nsAString& aResourceURL) { if (!aSubject) { return; } dom::DecoderDoctorNotification data; data.mType = aNotification.mNotificationType; data.mIsSolved = aIsSolved; data.mDecoderDoctorReportId.Assign( NS_ConvertUTF8toUTF16(aNotification.mReportStringId)); if (!aFormats.IsEmpty()) { data.mFormats.Construct(aFormats); } if (!aDecodeIssue.IsEmpty()) { data.mDecodeIssue.Construct(aDecodeIssue); } if (!aDocURL.IsEmpty()) { data.mDocURL.Construct(NS_ConvertUTF8toUTF16(aDocURL)); } if (!aResourceURL.IsEmpty()) { data.mResourceURL.Construct(aResourceURL); } nsAutoString json; data.ToJSON(json); if (json.IsEmpty()) { DD_WARN("DecoderDoctorDiagnostics/DispatchEvent() - Could not create json for dispatch"); // No point in dispatching this notification without data, the front-end // wouldn't know what to display. return; } DD_DEBUG("DecoderDoctorDiagnostics/DispatchEvent() %s", NS_ConvertUTF16toUTF8(json).get()); nsCOMPtr<nsIObserverService> obs = services::GetObserverService(); if (obs) { obs->NotifyObservers(aSubject, "decoder-doctor-notification", json.get()); } }
NS_IMETHODIMP nsAnnotationService::GetAnnotationURI(nsIURI* aURI, const nsACString& aName, nsIURI** _result) { if (aName.IsEmpty()) return NS_ERROR_INVALID_ARG; nsCAutoString annoSpec; nsresult rv = aURI->GetSpec(annoSpec); NS_ENSURE_SUCCESS(rv, rv); nsCAutoString spec; spec.AssignLiteral("moz-anno:"); spec += aName; spec += NS_LITERAL_CSTRING(":"); spec += annoSpec; return NS_NewURI(_result, spec); }
nsresult nsBasePrincipal::SetCertificate(const nsACString& aFingerprint, const nsACString& aSubjectName, const nsACString& aPrettyName, nsISupports* aCert) { NS_ENSURE_STATE(!mCert); if (aFingerprint.IsEmpty()) { return NS_ERROR_INVALID_ARG; } mCert = new Certificate(aFingerprint, aSubjectName, aPrettyName, aCert); if (!mCert) { return NS_ERROR_OUT_OF_MEMORY; } return NS_OK; }