Bug 1256999 - Use nsIDocument for ImageCacheKey. r=bz r=seth
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Mon, 11 Apr 2016 11:00:03 +0200
changeset 320338 1258adc301a8a61b1cb401c28144202ba35825ea
parent 320337 3b53ecaae8f278470d5551c377d3580ff8af9d05
child 320343 17dfb6404d37023c552fdb7065be449a00e53ccc
push idunknown
push userunknown
push dateunknown
reviewersbz, seth
bugs1256999
milestone48.0a1
Bug 1256999 - Use nsIDocument for ImageCacheKey. r=bz r=seth
image/ImageCacheKey.cpp
image/ImageCacheKey.h
image/imgLoader.cpp
--- a/image/ImageCacheKey.cpp
+++ b/image/ImageCacheKey.cpp
@@ -6,17 +6,16 @@
 #include "ImageCacheKey.h"
 
 #include "mozilla/Move.h"
 #include "File.h"
 #include "ImageURL.h"
 #include "nsHostObjectProtocolHandler.h"
 #include "nsString.h"
 #include "mozilla/dom/workers/ServiceWorkerManager.h"
-#include "nsIDOMDocument.h"
 #include "nsIDocument.h"
 #include "nsPrintfCString.h"
 
 namespace mozilla {
 
 using namespace dom;
 
 namespace image {
@@ -41,31 +40,31 @@ BlobSerial(ImageURL* aURI)
   if (NS_SUCCEEDED(NS_GetBlobForBlobURISpec(spec, getter_AddRefs(blob))) &&
       blob) {
     return Some(blob->GetSerialNumber());
   }
 
   return Nothing();
 }
 
-ImageCacheKey::ImageCacheKey(nsIURI* aURI, nsIDOMDocument* aDocument)
+ImageCacheKey::ImageCacheKey(nsIURI* aURI, nsIDocument* aDocument)
   : mURI(new ImageURL(aURI))
   , mControlledDocument(GetControlledDocumentToken(aDocument))
   , mIsChrome(URISchemeIs(mURI, "chrome"))
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (URISchemeIs(mURI, "blob")) {
     mBlobSerial = BlobSerial(mURI);
   }
 
   mHash = ComputeHash(mURI, mBlobSerial, mControlledDocument);
 }
 
-ImageCacheKey::ImageCacheKey(ImageURL* aURI, nsIDOMDocument* aDocument)
+ImageCacheKey::ImageCacheKey(ImageURL* aURI, nsIDocument* aDocument)
   : mURI(aURI)
   , mControlledDocument(GetControlledDocumentToken(aDocument))
   , mIsChrome(URISchemeIs(mURI, "chrome"))
 {
   MOZ_ASSERT(aURI);
 
   if (URISchemeIs(mURI, "blob")) {
     mBlobSerial = BlobSerial(mURI);
@@ -136,28 +135,27 @@ ImageCacheKey::ComputeHash(ImageURL* aUR
 
   // For non-blob URIs, we hash the URI spec.
   nsAutoCString spec;
   aURI->GetSpec(spec);
   return HashString(spec + ptr);
 }
 
 /* static */ void*
-ImageCacheKey::GetControlledDocumentToken(nsIDOMDocument* aDocument)
+ImageCacheKey::GetControlledDocumentToken(nsIDocument* aDocument)
 {
   // For non-controlled documents, we just return null.  For controlled
   // documents, we cast the pointer into a void* to avoid dereferencing
   // it (since we only use it for comparisons), and return it.
   void* pointer = nullptr;
   using dom::workers::ServiceWorkerManager;
   RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
-  nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDocument);
-  if (doc && swm) {
+  if (aDocument && swm) {
     ErrorResult rv;
-    if (swm->IsControlled(doc, rv)) {
-      pointer = doc;
+    if (swm->IsControlled(aDocument, rv)) {
+      pointer = aDocument;
     }
   }
   return pointer;
 }
 
 } // namespace image
 } // namespace mozilla
--- a/image/ImageCacheKey.h
+++ b/image/ImageCacheKey.h
@@ -7,17 +7,17 @@
  * ImageCacheKey is the key type for the image cache (see imgLoader.h).
  */
 
 #ifndef mozilla_image_src_ImageCacheKey_h
 #define mozilla_image_src_ImageCacheKey_h
 
 #include "mozilla/Maybe.h"
 
-class nsIDOMDocument;
+class nsIDocument;
 class nsIURI;
 
 namespace mozilla {
 namespace image {
 
 class ImageURL;
 
 /**
@@ -26,18 +26,18 @@ class ImageURL;
  * We key the cache on the initial URI (before any redirects), with some
  * canonicalization applied. See ComputeHash() for the details.
  * Controlled documents do not share their cache entries with
  * non-controlled documents, or other controlled documents.
  */
 class ImageCacheKey final
 {
 public:
-  ImageCacheKey(nsIURI* aURI, nsIDOMDocument* aDocument);
-  ImageCacheKey(ImageURL* aURI, nsIDOMDocument* aDocument);
+  ImageCacheKey(nsIURI* aURI, nsIDocument* aDocument);
+  ImageCacheKey(ImageURL* aURI, nsIDocument* aDocument);
 
   ImageCacheKey(const ImageCacheKey& aOther);
   ImageCacheKey(ImageCacheKey&& aOther);
 
   bool operator==(const ImageCacheKey& aOther) const;
   uint32_t Hash() const { return mHash; }
 
   /// A weak pointer to the URI spec for this cache entry. For logging only.
@@ -49,17 +49,17 @@ public:
   /// A token indicating which service worker controlled document this entry
   /// belongs to, if any.
   void* ControlledDocument() const { return mControlledDocument; }
 
 private:
   static uint32_t ComputeHash(ImageURL* aURI,
                               const Maybe<uint64_t>& aBlobSerial,
                               void* aControlledDocument);
-  static void* GetControlledDocumentToken(nsIDOMDocument* aDocument);
+  static void* GetControlledDocumentToken(nsIDocument* aDocument);
 
   RefPtr<ImageURL> mURI;
   Maybe<uint64_t> mBlobSerial;
   void* mControlledDocument;
   uint32_t mHash;
   bool mIsChrome;
 };
 
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -1324,21 +1324,22 @@ imgLoader::ClearCache(bool chrome)
     return ClearChromeImageCache();
   } else {
     return ClearImageCache();
   }
 }
 
 NS_IMETHODIMP
 imgLoader::FindEntryProperties(nsIURI* uri,
-                               nsIDOMDocument* doc,
+                               nsIDOMDocument* aDOMDoc,
                                nsIProperties** _retval)
 {
   *_retval = nullptr;
 
+  nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDoc);
   ImageCacheKey key(uri, doc);
   imgCacheTable& cache = GetCache(key);
 
   RefPtr<imgCacheEntry> entry;
   if (cache.Get(key, getter_AddRefs(entry)) && entry) {
     if (mCacheTracker && entry->HasNoProxies()) {
       mCacheTracker->MarkUsed(entry);
     }
@@ -2094,18 +2095,17 @@ imgLoader::LoadImage(nsIURI* aURI,
   }
 
   RefPtr<imgCacheEntry> entry;
 
   // Look in the cache for our URI, and then validate it.
   // XXX For now ignore aCacheKey. We will need it in the future
   // for correctly dealing with image load requests that are a result
   // of post data.
-  nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(aLoadingDocument);
-  ImageCacheKey key(aURI, doc);
+  ImageCacheKey key(aURI, aLoadingDocument);
   imgCacheTable& cache = GetCache(key);
 
   if (cache.Get(key, getter_AddRefs(entry)) && entry) {
     if (ValidateEntry(entry, aURI, aInitialDocumentURI, aReferrerURI,
                       aReferrerPolicy, aLoadGroup, aObserver, aLoadingDocument,
                       requestFlags, aContentPolicyType, true, _retval,
                       aLoadingPrincipal, corsmode)) {
       request = entry->GetRequest();
@@ -2319,17 +2319,17 @@ imgLoader::LoadImageWithChannel(nsIChann
                "imgLoader::LoadImageWithChannel -- NULL channel pointer");
 
   MOZ_ASSERT(NS_UsePrivateBrowsing(channel) == mRespectPrivacy);
 
   RefPtr<imgRequest> request;
 
   nsCOMPtr<nsIURI> uri;
   channel->GetURI(getter_AddRefs(uri));
-  nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(aCX);
+  nsCOMPtr<nsIDocument> doc = do_QueryInterface(aCX);
   ImageCacheKey key(uri, doc);
 
   nsLoadFlags requestFlags = nsIRequest::LOAD_NORMAL;
   channel->GetLoadFlags(&requestFlags);
 
   RefPtr<imgCacheEntry> entry;
 
   if (requestFlags & nsIRequest::LOAD_BYPASS_CACHE) {