Bug 1460940 - Remove nsIDOMDocument uses in image/. r?bz
MozReview-Commit-ID: HUiegmeFLo4
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -3638,18 +3638,17 @@ bool
nsContentUtils::IsImageInCache(nsIURI* aURI, nsIDocument* aDocument)
{
imgILoader* loader = GetImgLoaderForDocument(aDocument);
nsCOMPtr<imgICache> cache = do_QueryInterface(loader);
// If something unexpected happened we return false, otherwise if props
// is set, the image is cached and we return true
nsCOMPtr<nsIProperties> props;
- nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aDocument);
- nsresult rv = cache->FindEntryProperties(aURI, domDoc, getter_AddRefs(props));
+ nsresult rv = cache->FindEntryProperties(aURI, aDocument, getter_AddRefs(props));
return (NS_SUCCEEDED(rv) && props);
}
// static
int32_t
nsContentUtils::CORSModeToLoadImageFlags(mozilla::CORSMode aMode)
{
switch (aMode) {
--- a/image/imgICache.idl
+++ b/image/imgICache.idl
@@ -3,20 +3,21 @@
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface imgIRequest;
interface nsIDocument;
-interface nsIDOMDocument;
interface nsIProperties;
interface nsIURI;
+webidl Document;
+
/**
* imgICache interface
*
* @author Stuart Parmenter <pavlov@netscape.com>
* @version 0.1
* @see imagelib2
*/
[scriptable, builtinclass, uuid(bfdf23ff-378e-402e-8a6c-840f0c82b6c3)]
@@ -33,17 +34,17 @@ interface imgICache : nsISupports
/**
* Evict images from the cache.
*
* @param uri The URI to remove.
* @param doc The document to remove the cache entry for.
* @throws NS_ERROR_NOT_AVAILABLE if \a uri was unable to be removed from
* the cache.
*/
- [noscript] void removeEntry(in nsIURI uri, [optional] in nsIDOMDocument doc);
+ [noscript] void removeEntry(in nsIURI uri, [optional] in Document doc);
/**
* Find Properties
* Used to get properties such as 'type' and 'content-disposition'
* 'type' is a nsISupportsCString containing the images' mime type such as
* 'image/png'
* 'content-disposition' will be a nsISupportsCString containing the header
* If you call this before any data has been loaded from a URI, it will
@@ -52,17 +53,17 @@ interface imgICache : nsISupports
* Hopefully this will be removed with bug 805119
*
* @param uri The URI to look up.
* @param doc Optional pointer to the document that the cache entry belongs to.
* @returns NULL if the URL was not found in the cache
*/
[must_use]
nsIProperties findEntryProperties(in nsIURI uri,
- [optional] in nsIDOMDocument doc);
+ [optional] in Document doc);
/**
* Make this cache instance respect private browsing notifications. This
* entails clearing the chrome and content caches whenever the
* last-pb-context-exited notification is observed.
*/
void respectPrivacyNotifications();
--- a/image/imgITools.idl
+++ b/image/imgITools.idl
@@ -6,21 +6,22 @@
#include "nsISupports.idl"
interface nsIEventTarget;
interface nsIInputStream;
interface imgIContainer;
interface imgILoader;
interface imgICache;
-interface nsIDOMDocument;
interface imgIScriptedNotificationObserver;
interface imgINotificationObserver;
interface imgIContainerCallback;
+webidl Document;
+
[scriptable, builtinclass, uuid(4c2383a4-931c-484d-8c4a-973590f66e3f)]
interface imgITools : nsISupports
{
/**
* decodeImageFromBuffer
* Caller provides an buffer, a buffer size and a mimetype. We read from
* the stream and decompress it (according to the specified mime type) and
* return the resulting imgIContainer.
@@ -113,29 +114,29 @@ interface imgITools : nsISupports
/**
* getImgLoaderForDocument
* Retrieve an image loader that reflects the privacy status of the given
* document.
*
* @param doc
* A document. Must not be null.
*/
- imgILoader getImgLoaderForDocument(in nsIDOMDocument doc);
+ imgILoader getImgLoaderForDocument(in Document doc);
/**
* getImgLoaderForDocument
* Retrieve an image cache that reflects the privacy status of the given
* document.
*
* @param doc
* A document. Null is allowed, but must _only_ be passed
* when there is no way to obtain a relevant document for
* the current context in which a cache is desired.
*/
- imgICache getImgCacheForDocument(in nsIDOMDocument doc);
+ imgICache getImgCacheForDocument(in Document doc);
/**
* encodeCroppedImage
* Caller provides an image container, and the mime type it should be
* encoded to. We return an input stream for the encoded image data.
* The encoded image is cropped to the specified dimensions.
*
* The given offset and size must not exceed the image bounds.
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -56,17 +56,16 @@
#include "prtime.h"
// we want to explore making the document own the load group
// so we can associate the document URI with the load group.
// until this point, we have an evil hack:
#include "nsIHttpChannelInternal.h"
#include "nsILoadContext.h"
#include "nsILoadGroupChild.h"
-#include "nsIDOMDocument.h"
#include "nsIDocShell.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::image;
using namespace mozilla::net;
MOZ_DEFINE_MALLOC_SIZE_OF(ImagesMallocSizeOf)
@@ -1467,56 +1466,53 @@ imgLoader::ClearCache(bool chrome)
return ClearChromeImageCache();
}
return ClearImageCache();
}
NS_IMETHODIMP
imgLoader::RemoveEntry(nsIURI* aURI,
- nsIDOMDocument* aDOMDoc)
+ nsIDocument* aDoc)
{
- nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDoc);
if (aURI) {
OriginAttributes attrs;
- if (doc) {
- nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
+ if (aDoc) {
+ nsCOMPtr<nsIPrincipal> principal = aDoc->NodePrincipal();
if (principal) {
attrs = principal->OriginAttributesRef();
}
}
nsresult rv = NS_OK;
- ImageCacheKey key(aURI, attrs, doc, rv);
+ ImageCacheKey key(aURI, attrs, aDoc, rv);
if (NS_SUCCEEDED(rv) && RemoveFromCache(key)) {
return NS_OK;
}
}
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
imgLoader::FindEntryProperties(nsIURI* uri,
- nsIDOMDocument* aDOMDoc,
+ nsIDocument* aDoc,
nsIProperties** _retval)
{
*_retval = nullptr;
- nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDoc);
-
OriginAttributes attrs;
- if (doc) {
- nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
+ if (aDoc) {
+ nsCOMPtr<nsIPrincipal> principal = aDoc->NodePrincipal();
if (principal) {
attrs = principal->OriginAttributesRef();
}
}
nsresult rv;
- ImageCacheKey key(uri, attrs, doc, rv);
+ ImageCacheKey key(uri, attrs, aDoc, rv);
NS_ENSURE_SUCCESS(rv, rv);
imgCacheTable& cache = GetCache(key);
RefPtr<imgCacheEntry> entry;
if (cache.Get(key, getter_AddRefs(entry)) && entry) {
if (mCacheTracker && entry->HasNoProxies()) {
mCacheTracker->MarkUsed(entry);
}
--- a/image/imgTools.cpp
+++ b/image/imgTools.cpp
@@ -8,17 +8,16 @@
#include "DecodePool.h"
#include "gfxUtils.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/RefPtr.h"
#include "nsCOMPtr.h"
#include "nsIDocument.h"
-#include "nsIDOMDocument.h"
#include "nsError.h"
#include "imgLoader.h"
#include "imgICache.h"
#include "imgIContainer.h"
#include "imgIEncoder.h"
#include "nsStreamUtils.h"
#include "nsStringStream.h"
#include "nsContentUtils.h"
@@ -522,25 +521,24 @@ NS_IMETHODIMP
imgTools::CreateScriptedObserver(imgIScriptedNotificationObserver* aInner,
imgINotificationObserver** aObserver)
{
NS_ADDREF(*aObserver = new ScriptedNotificationObserver(aInner));
return NS_OK;
}
NS_IMETHODIMP
-imgTools::GetImgLoaderForDocument(nsIDOMDocument* aDoc, imgILoader** aLoader)
+imgTools::GetImgLoaderForDocument(nsIDocument* aDoc, imgILoader** aLoader)
{
- nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
- NS_IF_ADDREF(*aLoader = nsContentUtils::GetImgLoaderForDocument(doc));
+ NS_IF_ADDREF(*aLoader = nsContentUtils::GetImgLoaderForDocument(aDoc));
return NS_OK;
}
NS_IMETHODIMP
-imgTools::GetImgCacheForDocument(nsIDOMDocument* aDoc, imgICache** aCache)
+imgTools::GetImgCacheForDocument(nsIDocument* aDoc, imgICache** aCache)
{
nsCOMPtr<imgILoader> loader;
nsresult rv = GetImgLoaderForDocument(aDoc, getter_AddRefs(loader));
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(loader, aCache);
}
} // namespace image