NS_IMETHODIMP HttpBaseChannel::GetContentType(nsACString& aContentType) { if (!mResponseHead) { aContentType.Truncate(); return NS_ERROR_NOT_AVAILABLE; } if (!mResponseHead->ContentType().IsEmpty()) { aContentType = mResponseHead->ContentType(); return NS_OK; } aContentType.AssignLiteral(UNKNOWN_CONTENT_TYPE); return NS_OK; }
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 nsFaviconService::GetFaviconData(nsIURI* aFaviconURI, nsACString& aMimeType, PRUint32* aDataLen, PRUint8** aData) { NS_ENSURE_ARG(aFaviconURI); NS_ENSURE_ARG_POINTER(aDataLen); NS_ENSURE_ARG_POINTER(aData); nsCOMPtr<nsIURI> defaultFaviconURI; nsresult rv = GetDefaultFavicon(getter_AddRefs(defaultFaviconURI)); NS_ENSURE_SUCCESS(rv, rv); PRBool isDefaultFavicon = PR_FALSE; rv = defaultFaviconURI->Equals(aFaviconURI, &isDefaultFavicon); NS_ENSURE_SUCCESS(rv, rv); // If we're getting the default favicon, we need to handle it separately since // it's not in the database. if (isDefaultFavicon) { nsCAutoString defaultData; rv = GetDefaultFaviconData(defaultData); NS_ENSURE_SUCCESS(rv, rv); PRUint8* bytes = reinterpret_cast<PRUint8*>(ToNewCString(defaultData)); NS_ENSURE_STATE(bytes); *aData = bytes; *aDataLen = defaultData.Length(); aMimeType.AssignLiteral(DEFAULT_MIME_TYPE); return NS_OK; } DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBGetData); rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("icon_url"), aFaviconURI); NS_ENSURE_SUCCESS(rv, rv); PRBool hasResult = PR_FALSE; if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) { rv = stmt->GetUTF8String(1, aMimeType); NS_ENSURE_SUCCESS(rv, rv); return stmt->GetBlob(0, aDataLen, aData); } return NS_ERROR_NOT_AVAILABLE; }
static inline bool PreprocessHostname(bool aLocalDomain, const nsACString &aInput, nsIIDNService *aIDN, nsACString &aACE) { if (aLocalDomain) { aACE.AssignLiteral("localhost"); return true; } if (!aIDN || IsASCII(aInput)) { aACE = aInput; return true; } return IsUTF8(aInput) && NS_SUCCEEDED(aIDN->ConvertUTF8toACE(aInput, aACE)); }
nsresult nsExpandedPrincipal::GetOriginInternal(nsACString& aOrigin) { aOrigin.AssignLiteral("[Expanded Principal ["); for (size_t i = 0; i < mPrincipals.Length(); ++i) { if (i != 0) { aOrigin.AppendLiteral(", "); } nsAutoCString subOrigin; nsresult rv = mPrincipals.ElementAt(i)->GetOrigin(subOrigin); NS_ENSURE_SUCCESS(rv, rv); aOrigin.Append(subOrigin); } aOrigin.Append("]]"); return NS_OK; }
nsresult nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAString& locale, nsACString& oResult) { // locked for thread safety { nsAutoLock guard(gLock); if (!gInfo_deprecated) { nsGREResProperties *info = new nsGREResProperties(NS_LITERAL_CSTRING("unixcharset.properties")); NS_ASSERTION(info, "cannot create nsGREResProperties"); gInfo_deprecated = info; } } if (gInfo_deprecated && !(locale.IsEmpty())) { nsAutoString platformLocaleKey; // note: NS_LITERAL_STRING("locale." OSTYPE ".") does not compile on AIX platformLocaleKey.AssignLiteral("locale."); platformLocaleKey.AppendWithConversion(OSTYPE); platformLocaleKey.AppendLiteral("."); platformLocaleKey.Append(locale); nsAutoString charset; nsresult res = gInfo_deprecated->Get(platformLocaleKey, charset); if (NS_SUCCEEDED(res)) { LossyCopyUTF16toASCII(charset, oResult); return NS_OK; } nsAutoString localeKey; localeKey.AssignLiteral("locale.all."); localeKey.Append(locale); res = gInfo_deprecated->Get(localeKey, charset); if (NS_SUCCEEDED(res)) { LossyCopyUTF16toASCII(charset, oResult); return NS_OK; } } NS_ERROR("unable to convert locale to charset using deprecated config"); mCharset.AssignLiteral("ISO-8859-1"); oResult.AssignLiteral("ISO-8859-1"); return NS_SUCCESS_USING_FALLBACK_LOCALE; }
/* attribute long type; */ NS_IMETHODIMP calRecurrenceRule::GetType(nsACString &aType) { switch (mIcalRecur.freq) { #define RECUR_HELPER(x) \ case ICAL_##x##_RECURRENCE: aType.AssignLiteral( #x ); break RECUR_HELPER(SECONDLY); RECUR_HELPER(MINUTELY); RECUR_HELPER(HOURLY); RECUR_HELPER(DAILY); RECUR_HELPER(WEEKLY); RECUR_HELPER(MONTHLY); RECUR_HELPER(YEARLY); #undef RECUR_HELPER default: aType.AssignLiteral(""); } return NS_OK; }
NS_IMETHODIMP nsPlatformCharset::GetDefaultCharsetForLocale(const nsAString& localeName, nsACString &oResult) { nsresult rv; nsCOMPtr<nsIMacLocale> pMacLocale; pMacLocale = do_GetService(NS_MACLOCALE_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { short script, language, region; rv = pMacLocale->GetPlatformLocale(localeName, &script, &language, ®ion); if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(MapToCharset(script, region, oResult))) { return NS_OK; } } } // fallback oResult.AssignLiteral("x-mac-roman"); return NS_SUCCESS_USING_FALLBACK_LOCALE; }
void MediaEngineWebRTCAudioCaptureSource::GetUUID(nsACString &aUUID) const { nsID uuid; char uuidBuffer[NSID_LENGTH]; nsCString asciiString; ErrorResult rv; rv = nsContentUtils::GenerateUUIDInPlace(uuid); if (rv.Failed()) { aUUID.AssignLiteral(""); return; } uuid.ToProvidedString(uuidBuffer); asciiString.AssignASCII(uuidBuffer); // Remove {} and the null terminator aUUID.Assign(Substring(asciiString, 1, NSID_LENGTH - 3)); }
// nsFaviconService::OptimizeFaviconImage // // Given a blob of data (a image file already read into a buffer), optimize // its size by recompressing it as a 16x16 PNG. nsresult nsFaviconService::OptimizeFaviconImage(const uint8_t* aData, uint32_t aDataLen, const nsACString& aMimeType, nsACString& aNewData, nsACString& aNewMimeType) { nsresult rv; nsCOMPtr<imgITools> imgtool = do_CreateInstance("@mozilla.org/image/tools;1"); nsCOMPtr<nsIInputStream> stream; rv = NS_NewByteInputStream(getter_AddRefs(stream), reinterpret_cast<const char*>(aData), aDataLen, NS_ASSIGNMENT_DEPEND); NS_ENSURE_SUCCESS(rv, rv); // decode image nsCOMPtr<imgIContainer> container; rv = imgtool->DecodeImageData(stream, aMimeType, getter_AddRefs(container)); NS_ENSURE_SUCCESS(rv, rv); aNewMimeType.AssignLiteral(DEFAULT_MIME_TYPE); // scale and recompress nsCOMPtr<nsIInputStream> iconStream; rv = imgtool->EncodeScaledImage(container, aNewMimeType, mOptimizedIconDimension, mOptimizedIconDimension, EmptyString(), getter_AddRefs(iconStream)); NS_ENSURE_SUCCESS(rv, rv); // Read the stream into a new buffer. rv = NS_ConsumeStream(iconStream, UINT32_MAX, aNewData); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }
static void GetSubmitCharset(nsGenericHTMLElement* aForm, nsACString& oCharset) { oCharset.AssignLiteral("UTF-8"); // default to utf-8 nsAutoString acceptCharsetValue; aForm->GetAttr(kNameSpaceID_None, nsGkAtoms::acceptcharset, acceptCharsetValue); PRInt32 charsetLen = acceptCharsetValue.Length(); if (charsetLen > 0) { PRInt32 offset=0; PRInt32 spPos=0; // get charset from charsets one by one do { spPos = acceptCharsetValue.FindChar(PRUnichar(' '), offset); PRInt32 cnt = ((-1==spPos)?(charsetLen-offset):(spPos-offset)); if (cnt > 0) { nsAutoString uCharset; acceptCharsetValue.Mid(uCharset, offset, cnt); if (NS_SUCCEEDED(nsCharsetAlias::GetPreferred(NS_LossyConvertUTF16toASCII(uCharset), oCharset))) return; } offset = spPos + 1; } while (spPos != -1); } // if there are no accept-charset or all the charset are not supported // Get the charset from document nsIDocument* doc = aForm->GetDocument(); if (doc) { oCharset = doc->GetDocumentCharacterSet(); } }
NS_IMETHODIMP nsMsgBrkMBoxStore::GetStoreType(nsACString& aType) { aType.AssignLiteral("mbox"); return NS_OK; }
NS_IMETHODIMP nsAbLDAPDirectory::GetPropertiesChromeURI(nsACString &aResult) { aResult.AssignLiteral("chrome://messenger/content/addressbook/pref-directory-add.xul"); return NS_OK; }
NS_IMETHODIMP nsIconChannel::GetContentType(nsACString &aContentType) { aContentType.AssignLiteral(IMAGE_ICO); return NS_OK; }
NS_IMETHODIMP SimpleTimer::GetName(nsACString& aName) { aName.AssignLiteral("SimpleTimer"); return NS_OK; }
NS_IMETHODIMP nsViewSourceHandler::GetScheme(nsACString &result) { result.AssignLiteral(VIEW_SOURCE); return NS_OK; }
NS_IMETHODIMP nsAnnoProtocolHandler::GetScheme(nsACString& aScheme) { aScheme.AssignLiteral("moz-anno"); return NS_OK; }
NS_IMETHODIMP nsWyciwygChannel::GetContentCharset(nsACString &aContentCharset) { aContentCharset.AssignLiteral("UTF-16"); return NS_OK; }
NS_IMETHODIMP AppProtocolHandler::GetScheme(nsACString &aResult) { aResult.AssignLiteral("app"); return NS_OK; }
void MediaEngineDefaultAudioSource::GetUUID(nsACString& aUUID) { aUUID.AssignLiteral("B7CBD7C1-53EF-42F9-8353-73F61C70C092"); return; }
NS_IMETHODIMP nsMailboxServer::GetLocalStoreType(nsACString& type) { type.AssignLiteral("mailbox"); return NS_OK; }
NS_IMETHODIMP nsAboutProtocolHandler::GetScheme(nsACString &result) { result.AssignLiteral("about"); return NS_OK; }
NS_IMETHOD GetName(nsACString& aName) override { aName.AssignLiteral("nsGeolocationRequest::TimerCallbackHolder"); return NS_OK; }
void MediaEngineDefaultVideoSource::GetUUID(nsACString& aUUID) { aUUID.AssignLiteral("1041FCBD-3F12-4F7B-9E9B-1EC556DD5676"); return; }
NS_IMETHODIMP nsFeedSniffer::GetMIMETypeFromContent(nsIRequest* request, const uint8_t* data, uint32_t length, nsACString& sniffedType) { nsCOMPtr<nsIHttpChannel> channel(do_QueryInterface(request)); if (!channel) return NS_ERROR_NO_INTERFACE; // Check that this is a GET request, since you can't subscribe to a POST... nsCAutoString method; channel->GetRequestMethod(method); if (!method.Equals("GET")) { sniffedType.Truncate(); return NS_OK; } // We need to find out if this is a load of a view-source document. In this // case we do not want to override the content type, since the source display // does not need to be converted from feed format to XUL. More importantly, // we don't want to change the content type from something // nsContentDLF::CreateInstance knows about (e.g. application/xml, text/html // etc) to something that only the application fe knows about (maybe.feed) // thus deactivating syntax highlighting. nsCOMPtr<nsIURI> originalURI; channel->GetOriginalURI(getter_AddRefs(originalURI)); nsCAutoString scheme; originalURI->GetScheme(scheme); if (scheme.EqualsLiteral("view-source")) { sniffedType.Truncate(); return NS_OK; } // Check the Content-Type to see if it is set correctly. If it is set to // something specific that we think is a reliable indication of a feed, don't // bother sniffing since we assume the site maintainer knows what they're // doing. nsCAutoString contentType; channel->GetContentType(contentType); bool noSniff = contentType.EqualsLiteral(TYPE_RSS) || contentType.EqualsLiteral(TYPE_ATOM); // Check to see if this was a feed request from the location bar or from // the feed: protocol. This is also a reliable indication. // The value of the header doesn't matter. if (!noSniff) { nsCAutoString sniffHeader; nsresult foundHeader = channel->GetRequestHeader(NS_LITERAL_CSTRING("X-Moz-Is-Feed"), sniffHeader); noSniff = NS_SUCCEEDED(foundHeader); } if (noSniff) { // check for an attachment after we have a likely feed. if(HasAttachmentDisposition(channel)) { sniffedType.Truncate(); return NS_OK; } // set the feed header as a response header, since we have good metadata // telling us that the feed is supposed to be RSS or Atom channel->SetResponseHeader(NS_LITERAL_CSTRING("X-Moz-Is-Feed"), NS_LITERAL_CSTRING("1"), false); sniffedType.AssignLiteral(TYPE_MAYBE_FEED); return NS_OK; } // Don't sniff arbitrary types. Limit sniffing to situations that // we think can reasonably arise. if (!contentType.EqualsLiteral(TEXT_HTML) && !contentType.EqualsLiteral(APPLICATION_OCTET_STREAM) && // Same criterion as XMLHttpRequest. Should we be checking for "+xml" // and check for text/xml and application/xml by hand instead? contentType.Find("xml") == -1) { sniffedType.Truncate(); return NS_OK; } // Now we need to potentially decompress data served with // Content-Encoding: gzip nsresult rv = ConvertEncodedData(request, data, length); if (NS_FAILED(rv)) return rv; // We cap the number of bytes to scan at MAX_BYTES to prevent picking up // false positives by accidentally reading document content, e.g. a "how to // make a feed" page. const char* testData; if (mDecodedData.IsEmpty()) { testData = (const char*)data; length = NS_MIN(length, MAX_BYTES); } else { testData = mDecodedData.get(); length = NS_MIN(mDecodedData.Length(), MAX_BYTES); } // The strategy here is based on that described in: // http://blogs.msdn.com/rssteam/articles/PublishersGuide.aspx // for interoperarbility purposes. // Thus begins the actual sniffing. nsDependentCSubstring dataString((const char*)testData, length); bool isFeed = false; // RSS 0.91/0.92/2.0 isFeed = ContainsTopLevelSubstring(dataString, "<rss"); // Atom 1.0 if (!isFeed) isFeed = ContainsTopLevelSubstring(dataString, "<feed"); // RSS 1.0 if (!isFeed) { isFeed = ContainsTopLevelSubstring(dataString, "<rdf:RDF") && dataString.Find(NS_RDF) != -1 && dataString.Find(NS_RSS) != -1; } // If we sniffed a feed, coerce our internal type if (isFeed && !HasAttachmentDisposition(channel)) sniffedType.AssignLiteral(TYPE_MAYBE_FEED); else sniffedType.Truncate(); return NS_OK; }
NS_IMETHODIMP udptHttppHandler::GetScheme(nsACString &aScheme) { aScheme.AssignLiteral("httpp"); return NS_OK; }
NS_IMETHODIMP nsIconChannel::GetContentType(nsACString &aContentType) { aContentType.AssignLiteral("image/x-icon"); return NS_OK; }
NS_IMETHODIMP DecoderDoctorDocumentWatcher::GetName(nsACString& aName) { aName.AssignLiteral("DecoderDoctorDocumentWatcher_timer"); return NS_OK; }
NS_IMETHODIMP nsDeviceProtocolHandler::GetScheme(nsACString &aResult) { aResult.AssignLiteral("moz-device"); return NS_OK; }
NS_IMETHODIMP nsWyciwygChannel::GetContentType(nsACString &aContentType) { aContentType.AssignLiteral(WYCIWYG_TYPE); return NS_OK; }