Skip to content

Commit

Permalink
Bug 1548835 - Load moz-extension:// URIs from the cache over reloadin…
Browse files Browse the repository at this point in the history
…g. r=tnikkel

Similar to bug 1373258 and moz-page-thumb:// URIs, we are getting bitten
by the lack of caching support for non-HTTP channels. This may be
removed once bug 1406134 is implemented.

Differential Revision: https://phabricator.services.mozilla.com/D31515
  • Loading branch information
aosmond committed May 17, 2019
1 parent 1c6e3bd commit 065e80c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 13 additions & 15 deletions image/imgLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,17 @@ void imgLoader::RemoveFromUncachedImages(imgRequest* aRequest) {
mUncachedImages.RemoveEntry(aRequest);
}

bool imgLoader::PreferLoadFromCache(nsIURI* aURI) const {
// If we are trying to load an image from a protocol that doesn't support
// caching (e.g. thumbnails via the moz-page-thumb:// protocol, or icons via
// 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);
}

#define LOAD_FLAGS_CACHE_MASK \
(nsIRequest::LOAD_BYPASS_CACHE | nsIRequest::LOAD_FROM_CACHE)

Expand Down Expand Up @@ -2095,14 +2106,7 @@ nsresult imgLoader::LoadImage(
// Get the default load flags from the loadgroup (if possible)...
if (aLoadGroup) {
aLoadGroup->GetLoadFlags(&requestFlags);

// If we are trying to load a thumbnail via the moz-page-thumb:// protocol,
// load it directly from the cache to prevent re-decoding the image. See Bug
// 1373258
// TODO: Bug 1406134
bool isThumbnailScheme = false;
if (NS_SUCCEEDED(aURI->SchemeIs("moz-page-thumb", &isThumbnailScheme)) &&
isThumbnailScheme) {
if (PreferLoadFromCache(aURI)) {
requestFlags |= nsIRequest::LOAD_FROM_CACHE;
}
}
Expand Down Expand Up @@ -2379,13 +2383,7 @@ nsresult imgLoader::LoadImageWithChannel(nsIChannel* channel,
nsLoadFlags requestFlags = nsIRequest::LOAD_NORMAL;
channel->GetLoadFlags(&requestFlags);

// If we are trying to load a thumbnail via the moz-page-thumb:// protocol,
// load it directly from the cache to prevent re-decoding the image. See Bug
// 1373258
// TODO: Bug 1406134
bool isThumbnailScheme = false;
if (NS_SUCCEEDED(uri->SchemeIs("moz-page-thumb", &isThumbnailScheme)) &&
isThumbnailScheme) {
if (PreferLoadFromCache(uri)) {
requestFlags |= nsIRequest::LOAD_FROM_CACHE;
}

Expand Down
2 changes: 2 additions & 0 deletions image/imgLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ class imgLoader final : public imgILoader,
private: // methods
static already_AddRefed<imgLoader> CreateImageLoader();

bool PreferLoadFromCache(nsIURI* aURI) const;

bool ValidateEntry(imgCacheEntry* aEntry, nsIURI* aKey,
nsIURI* aInitialDocumentURI, nsIURI* aReferrerURI,
ReferrerPolicy aReferrerPolicy, nsILoadGroup* aLoadGroup,
Expand Down

0 comments on commit 065e80c

Please sign in to comment.