mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1558915 - Use infallible nsIURI::SchemeIs in image/ r=tnikkel
Differential Revision: https://phabricator.services.mozilla.com/D40459 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
b39394d528
commit
4e01ab1787
@ -410,9 +410,7 @@ void ImageResource::NotifyDrawingObservers() {
|
||||
return;
|
||||
}
|
||||
|
||||
bool match = false;
|
||||
if ((NS_FAILED(mURI->SchemeIs("resource", &match)) || !match) &&
|
||||
(NS_FAILED(mURI->SchemeIs("chrome", &match)) || !match)) {
|
||||
if (!mURI->SchemeIs("resource") && !mURI->SchemeIs("chrome")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,9 @@ ImageCacheKey::ImageCacheKey(nsIURI* aURI, const OriginAttributes& aAttrs,
|
||||
mControlledDocument(GetSpecialCaseDocumentToken(aDocument, aURI)),
|
||||
mTopLevelBaseDomain(GetTopLevelBaseDomain(aDocument, aURI)),
|
||||
mIsChrome(false) {
|
||||
if (SchemeIs("blob")) {
|
||||
if (mURI->SchemeIs("blob")) {
|
||||
mBlobSerial = BlobSerial(mURI);
|
||||
} else if (SchemeIs("chrome")) {
|
||||
} else if (mURI->SchemeIs("chrome")) {
|
||||
mIsChrome = true;
|
||||
}
|
||||
}
|
||||
@ -144,11 +144,6 @@ void ImageCacheKey::EnsureHash() const {
|
||||
mHash.emplace(hash);
|
||||
}
|
||||
|
||||
bool ImageCacheKey::SchemeIs(const char* aScheme) {
|
||||
bool matches = false;
|
||||
return NS_SUCCEEDED(mURI->SchemeIs(aScheme, &matches)) && matches;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void* ImageCacheKey::GetSpecialCaseDocumentToken(Document* aDocument,
|
||||
nsIURI* aURI) {
|
||||
|
@ -59,8 +59,6 @@ class ImageCacheKey final {
|
||||
void* ControlledDocument() const { return mControlledDocument; }
|
||||
|
||||
private:
|
||||
bool SchemeIs(const char* aScheme);
|
||||
|
||||
// For ServiceWorker we need to use the document as
|
||||
// token for the key. All those exceptions are handled by this method.
|
||||
static void* GetSpecialCaseDocumentToken(dom::Document* aDocument,
|
||||
|
@ -34,24 +34,18 @@ void ImageFactory::Initialize() {}
|
||||
|
||||
static uint32_t ComputeImageFlags(nsIURI* uri, const nsCString& aMimeType,
|
||||
bool isMultiPart) {
|
||||
nsresult rv;
|
||||
|
||||
// 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.
|
||||
bool isChrome = false;
|
||||
rv = uri->SchemeIs("chrome", &isChrome);
|
||||
if (NS_SUCCEEDED(rv) && isChrome) {
|
||||
if (uri->SchemeIs("chrome")) {
|
||||
isDiscardable = false;
|
||||
}
|
||||
|
||||
// We don't want resources like the "loading" icon to be discardable either.
|
||||
bool isResource = false;
|
||||
rv = uri->SchemeIs("resource", &isResource);
|
||||
if (NS_SUCCEEDED(rv) && isResource) {
|
||||
if (uri->SchemeIs("resource")) {
|
||||
isDiscardable = false;
|
||||
}
|
||||
|
||||
@ -75,9 +69,7 @@ static uint32_t ComputeImageFlags(nsIURI* uri, const nsCString& aMimeType,
|
||||
|
||||
// Synchronously decode metadata (including size) if we have a data URI since
|
||||
// the data is immediately available.
|
||||
bool isDataURI = false;
|
||||
rv = uri->SchemeIs("data", &isDataURI);
|
||||
if (NS_SUCCEEDED(rv) && isDataURI) {
|
||||
if (uri->SchemeIs("data")) {
|
||||
imageFlags |= Image::INIT_FLAG_SYNC_LOAD;
|
||||
}
|
||||
|
||||
@ -115,9 +107,7 @@ already_AddRefed<Image> ImageFactory::CreateImage(
|
||||
|
||||
#ifdef DEBUG
|
||||
// Record the image load for startup performance testing.
|
||||
bool match = false;
|
||||
if ((NS_SUCCEEDED(aURI->SchemeIs("resource", &match)) && match) ||
|
||||
(NS_SUCCEEDED(aURI->SchemeIs("chrome", &match)) && match)) {
|
||||
if (aURI->SchemeIs("resource") || aURI->SchemeIs("chrome")) {
|
||||
NotifyImageLoading(aURI);
|
||||
}
|
||||
#endif
|
||||
|
@ -198,10 +198,9 @@ nsresult nsIconChannel::InitWithGIO(nsIMozIconURI* aIconURI) {
|
||||
|
||||
// Get icon for file specified by URI
|
||||
if (fileURI) {
|
||||
bool isFile;
|
||||
nsAutoCString spec;
|
||||
fileURI->GetAsciiSpec(spec);
|
||||
if (NS_SUCCEEDED(fileURI->SchemeIs("file", &isFile)) && isFile) {
|
||||
if (fileURI->SchemeIs("file")) {
|
||||
GFile* file = g_file_new_for_uri(spec.get());
|
||||
GFileInfo* fileInfo =
|
||||
g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_ICON,
|
||||
|
@ -272,8 +272,7 @@ nsresult nsMozIconURI::SetSpecInternal(const nsACString& aSpec) {
|
||||
mIconURL = do_QueryInterface(uri);
|
||||
if (mIconURL) {
|
||||
// The inner URI should be a 'file:' one. If not, bail.
|
||||
bool isFile = false;
|
||||
if (!NS_SUCCEEDED(mIconURL->SchemeIs("file", &isFile)) || !isFile) {
|
||||
if (!mIconURL->SchemeIs("file")) {
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
mFileName.Truncate();
|
||||
|
@ -2029,9 +2029,7 @@ bool imgLoader::PreferLoadFromCache(nsIURI* aURI) const {
|
||||
// the moz-extension:// protocol), load it directly from the cache to prevent
|
||||
// re-decoding the image. See Bug 1373258.
|
||||
// TODO: Bug 1406134
|
||||
bool match = false;
|
||||
return (NS_SUCCEEDED(aURI->SchemeIs("moz-page-thumb", &match)) && match) ||
|
||||
(NS_SUCCEEDED(aURI->SchemeIs("moz-extension", &match)) && match);
|
||||
return aURI->SchemeIs("moz-page-thumb") || aURI->SchemeIs("moz-extension");
|
||||
}
|
||||
|
||||
#define LOAD_FLAGS_CACHE_MASK \
|
||||
@ -3000,15 +2998,12 @@ imgCacheValidator::AsyncOnChannelRedirect(
|
||||
// security code, which needs to know whether there is an insecure load at any
|
||||
// point in the redirect chain.
|
||||
nsCOMPtr<nsIURI> oldURI;
|
||||
bool isHttps = false;
|
||||
bool isChrome = false;
|
||||
bool schemeLocal = false;
|
||||
if (NS_FAILED(oldChannel->GetURI(getter_AddRefs(oldURI))) ||
|
||||
NS_FAILED(oldURI->SchemeIs("https", &isHttps)) ||
|
||||
NS_FAILED(oldURI->SchemeIs("chrome", &isChrome)) ||
|
||||
NS_FAILED(NS_URIChainHasFlags(
|
||||
oldURI, nsIProtocolHandler::URI_IS_LOCAL_RESOURCE, &schemeLocal)) ||
|
||||
(!isHttps && !isChrome && !schemeLocal)) {
|
||||
(!oldURI->SchemeIs("https") && !oldURI->SchemeIs("chrome") &&
|
||||
!schemeLocal)) {
|
||||
mHadInsecureRedirect = true;
|
||||
}
|
||||
|
||||
|
@ -111,14 +111,11 @@ nsresult imgRequest::Init(nsIURI* aURI, nsIURI* aFinalURI,
|
||||
// account, as it needs to be handled using more complicated rules than
|
||||
// earlier elements of the redirect chain.
|
||||
if (aURI != aFinalURI) {
|
||||
bool isHttps = false;
|
||||
bool isChrome = false;
|
||||
bool schemeLocal = false;
|
||||
if (NS_FAILED(aURI->SchemeIs("https", &isHttps)) ||
|
||||
NS_FAILED(aURI->SchemeIs("chrome", &isChrome)) ||
|
||||
NS_FAILED(NS_URIChainHasFlags(
|
||||
if (NS_FAILED(NS_URIChainHasFlags(
|
||||
aURI, nsIProtocolHandler::URI_IS_LOCAL_RESOURCE, &schemeLocal)) ||
|
||||
(!isHttps && !isChrome && !schemeLocal)) {
|
||||
(!aURI->SchemeIs("https") && !aURI->SchemeIs("chrome") &&
|
||||
!schemeLocal)) {
|
||||
mHadInsecureRedirect = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user