Bug 1497981 - Simplify ImageLoader::LoadImage. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 15 Oct 2018 12:24:58 +0000
changeset 499716 33e24166d90ba3d7ffa4202b53d1cfc17c563fd2
parent 499715 8de1d283e1b3e28f66dd8a6a0fe4e020e82ba3b3
child 499717 9c768db45a35b59f90d8ae1b8062af2e98539b28
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1497981
milestone64.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 1497981 - Simplify ImageLoader::LoadImage. r=heycam Has a single caller, from which we pass the arguments. We can just avoid that. Differential Revision: https://phabricator.services.mozilla.com/D8276
layout/style/ImageLoader.cpp
layout/style/ImageLoader.h
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
--- a/layout/style/ImageLoader.cpp
+++ b/layout/style/ImageLoader.cpp
@@ -447,26 +447,20 @@ ImageLoader::ClearFrames(nsPresContext* 
     }
   }
 
   mRequestToFrameMap.Clear();
   mFrameToRequestMap.Clear();
 }
 
 /* static */ void
-ImageLoader::LoadImage(nsIURI* aURI,
-                       nsIPrincipal* aOriginPrincipal,
-                       nsIURI* aReferrer,
-                       mozilla::net::ReferrerPolicy aPolicy,
-                       nsIDocument* aDocument,
-                       URLValue* aImage,
-                       CORSMode aCorsMode)
+ImageLoader::LoadImage(URLValue* aImage, nsIDocument* aLoadingDoc)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aDocument);
+  MOZ_ASSERT(aLoadingDoc);
   MOZ_ASSERT(aImage);
   MOZ_ASSERT(aImage->LoadID() != 0);
 
   if (aImage->LoadID() == 0) {
     MOZ_ASSERT_UNREACHABLE("Image should have a valid LoadID");
     return;
   }
 
@@ -476,28 +470,34 @@ ImageLoader::LoadImage(nsIURI* aURI,
     auto lookup = sImages->LookupForAdd(aImage->LoadID());
     if (lookup) {
       // This css::URLValue has already been loaded.
       return;
     }
     entry = lookup.OrInsert([]() { return new ImageTableEntry(); });
   }
 
-  if (!aURI) {
+  nsIURI* uri = aImage->GetURI();
+  if (!uri) {
     return;
   }
 
   int32_t loadFlags = nsIRequest::LOAD_NORMAL |
-                      nsContentUtils::CORSModeToLoadImageFlags(aCorsMode);
+                      nsContentUtils::CORSModeToLoadImageFlags(aImage->CorsMode());
+
+  URLExtraData* data = aImage->mExtraData;
+
 
   RefPtr<imgRequestProxy> request;
-  nsresult rv = nsContentUtils::LoadImage(aURI, aDocument, aDocument,
-                                          aOriginPrincipal, 0, aReferrer,
-                                          aPolicy,
-                                          nullptr, loadFlags,
+  nsresult rv = nsContentUtils::LoadImage(uri, aLoadingDoc, aLoadingDoc,
+                                          data->Principal(), 0,
+                                          data->GetReferrer(),
+                                          data->GetReferrerPolicy(),
+                                          nullptr,
+                                          loadFlags,
                                           NS_LITERAL_STRING("css"),
                                           getter_AddRefs(request));
 
   if (NS_FAILED(rv) || !request) {
     return;
   }
 
   entry->mCanonicalRequest = std::move(request);
--- a/layout/style/ImageLoader.h
+++ b/layout/style/ImageLoader.h
@@ -76,23 +76,17 @@ public:
 
   void SetAnimationMode(uint16_t aMode);
 
   // The prescontext for this ImageLoader's document. We need it to be passed
   // in because this can be called during presentation destruction after the
   // presshell pointer on the document has been cleared.
   void ClearFrames(nsPresContext* aPresContext);
 
-  static void LoadImage(nsIURI* aURI,
-                        nsIPrincipal* aPrincipal,
-                        nsIURI* aReferrer,
-                        mozilla::net::ReferrerPolicy aPolicy,
-                        nsIDocument* aDocument,
-                        URLValue* aImage,
-                        CORSMode aCorsMode);
+  static void LoadImage(URLValue* aImage, nsIDocument* aLoadingDoc);
 
   // Cancels the image load for the given css::URLValue and deregisters
   // it from any ImageLoaders it was registered with.
   //
   // May be called from any thread.
   static void DeregisterCSSImageFromAllLoaders(URLValue* aImage);
 
   void FlushUseCounters();
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -1000,23 +1000,17 @@ css::URLValue::LoadImage(nsIDocument* aD
   // images from aDocument.  Instead we do the image load from the original doc
   // and clone it to aDocument.
   nsIDocument* loadingDoc = aDocument->GetOriginalDocument();
   if (!loadingDoc) {
     loadingDoc = aDocument;
   }
 
   // Kick off the load in the loading document.
-  ImageLoader::LoadImage(GetURI(),
-                         mExtraData->Principal(),
-                         mExtraData->GetReferrer(),
-                         mExtraData->GetReferrerPolicy(),
-                         loadingDoc,
-                         this,
-                         mCORSMode);
+  ImageLoader::LoadImage(this, loadingDoc);
 
   // Register the image in the document that's using it.
   return aDocument->StyleImageLoader()->RegisterCSSImage(this);
 }
 
 size_t
 mozilla::css::GridTemplateAreasValue::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
 {
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -150,16 +150,18 @@ public:
   nsDependentCSubstring GetString() const;
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
   imgRequestProxy* LoadImage(nsIDocument* aDocument);
 
   uint64_t LoadID() const { return mLoadID; }
 
+  CORSMode CorsMode() const { return mCORSMode; }
+
 private:
   // mURI stores the lazily resolved URI.  This may be null if the URI is
   // invalid, even once resolved.
   mutable nsCOMPtr<nsIURI> mURI;
 
 public:
   RefPtr<URLExtraData> mExtraData;