/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
static uint32_t ComputeImageFlags(nsIURI* uri, const nsCString& aMimeType, bool isMultiPart) { // We default to the static globals. bool isDiscardable = StaticPrefs::image_mem_discardable(); bool doDecodeImmediately = StaticPrefs::image_decode_immediately_enabled();
// We want UI to be as snappy as possible and not to flicker. Disable // discarding for chrome URLS. if (uri->SchemeIs("chrome")) {
isDiscardable = false;
}
// We don't want resources like the "loading" icon to be discardable either. if (uri->SchemeIs("resource")) {
isDiscardable = false;
}
// For multipart/x-mixed-replace, we basically want a direct channel to the // decoder. Disable everything for this case. if (isMultiPart) {
isDiscardable = false;
}
// We have all the information we need.
uint32_t imageFlags = Image::INIT_FLAG_NONE; if (isDiscardable) {
imageFlags |= Image::INIT_FLAG_DISCARDABLE;
} if (doDecodeImmediately) {
imageFlags |= Image::INIT_FLAG_DECODE_IMMEDIATELY;
} if (isMultiPart) {
imageFlags |= Image::INIT_FLAG_TRANSIENT;
}
// Synchronously decode metadata (including size) if we have a data URI since // the data is immediately available. if (uri->SchemeIs("data")) {
imageFlags |= Image::INIT_FLAG_SYNC_LOAD;
}
#ifdef DEBUG // Record the image load for startup performance testing. if (aURI->SchemeIs("resource") || aURI->SchemeIs("chrome")) {
NotifyImageLoading(aURI);
} #endif
// Select the type of image to create based on MIME type. if (aMimeType.EqualsLiteral(IMAGE_SVG_XML)) { return CreateVectorImage(aRequest, aProgressTracker, aMimeType, aURI,
imageFlags, aInnerWindowId);
} else { return CreateRasterImage(aRequest, aProgressTracker, aMimeType, aURI,
imageFlags, aInnerWindowId);
}
}
// Marks an image as having an error before returning it. template <typename T> static already_AddRefed<Image> BadImage(constchar* aMessage,
RefPtr<T>& aImage) {
aImage->SetHasError(); return aImage.forget();
}
// Use the file size as a size hint for file channels.
nsCOMPtr<nsIFileChannel> fileChannel(do_QueryInterface(aRequest)); if (fileChannel) {
nsCOMPtr<nsIFile> file;
nsresult rv = fileChannel->GetFile(getter_AddRefs(file)); if (NS_SUCCEEDED(rv)) {
int64_t filesize;
rv = file->GetFileSize(&filesize); if (NS_SUCCEEDED(rv)) { return std::max(SaturateToInt32(filesize), 0);
}
}
}
// Fallback - neither http nor file. We'll use dynamic allocation. return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.