Bug 1548835 - Load moz-extension:// URIs from the cache over reloading. r=tnikkel
authorAndrew Osmond <aosmond@mozilla.com>
Thu, 16 May 2019 14:55:19 -0400
changeset 533179 885f2b742a0252362ff92730c7602802863d9757
parent 533140 afd2db10c864309a1e58f055e380c98248fb25a1
child 533180 bc17771ceb28c31cd06889be51ae2eda72efc451
child 533198 d4b9c8af4f70127df8ec75c5f82abf6ef49c71aa
push id11276
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:11:24 +0000
treeherdermozilla-beta@847755a7c325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel
bugs1548835, 1373258, 1406134
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1548835 - Load moz-extension:// URIs from the cache over reloading. 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
image/imgLoader.cpp
image/imgLoader.h
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -2006,16 +2006,27 @@ void imgLoader::AddToUncachedImages(imgR
   mUncachedImages.PutEntry(aRequest);
 }
 
 void imgLoader::RemoveFromUncachedImages(imgRequest* aRequest) {
   MutexAutoLock lock(mUncachedImagesMutex);
   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)
 
 #define LOAD_FLAGS_VALIDATE_MASK                              \
   (nsIRequest::VALIDATE_ALWAYS | nsIRequest::VALIDATE_NEVER | \
    nsIRequest::VALIDATE_ONCE_PER_SESSION)
 
 NS_IMETHODIMP
@@ -2090,24 +2101,17 @@ nsresult imgLoader::LoadImage(
         aLoadingDocument->GetDocumentLoadGroup();
     MOZ_ASSERT(docLoadGroup == aLoadGroup);
   }
 #endif
 
   // 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;
     }
   }
   //
   // Merge the default load flags with those passed in via aLoadFlags.
   // Currently, *only* the caching, validation and background load flags
   // are merged...
   //
@@ -2374,23 +2378,17 @@ nsresult imgLoader::LoadImageWithChannel
 
   OriginAttributes attrs = loadInfo->GetOriginAttributes();
 
   ImageCacheKey key(uri, attrs, doc);
 
   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;
   }
 
   RefPtr<imgCacheEntry> entry;
 
   if (requestFlags & nsIRequest::LOAD_BYPASS_CACHE) {
     RemoveFromCache(key);
   } else {
--- a/image/imgLoader.h
+++ b/image/imgLoader.h
@@ -339,16 +339,18 @@ class imgLoader final : public imgILoade
   // happens, by calling imgRequest::SetCacheEntry() when an entry with no
   // observers is re-requested.
   bool SetHasNoProxies(imgRequest* aRequest, imgCacheEntry* aEntry);
   bool SetHasProxies(imgRequest* aRequest);
 
  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,
                      imgINotificationObserver* aObserver, nsISupports* aCX,
                      mozilla::dom::Document* aLoadingDocument,
                      nsLoadFlags aLoadFlags,
                      nsContentPolicyType aContentPolicyType,
                      bool aCanMakeNewChannel, bool* aNewChannelCreated,