Bug 1406253 - Part 2: Implement nsIImageLoadingContent.currentRequestFinalURI. r?bz
ImageLoadingContent.currentURI returns the "URI" of currentRequest, which is
the URI used to start that request. Some consumers need to know the final URI
of that request instead.
If the image request gets redirected on loading (e.g. an add-on intercepts the
request), currentRequestFinalURI will be the redirected URI, while currentURI
would be the original URI before redirect.
MozReview-Commit-ID: 9lX063uAIp1
--- a/dom/base/nsImageLoadingContent.cpp
+++ b/dom/base/nsImageLoadingContent.cpp
@@ -752,16 +752,27 @@ nsImageLoadingContent::GetCurrentURI(nsI
{
NS_ENSURE_ARG_POINTER(aURI);
ErrorResult result;
*aURI = GetCurrentURI(result).take();
return result.StealNSResult();
}
+already_AddRefed<nsIURI>
+nsImageLoadingContent::GetCurrentRequestFinalURI()
+{
+ nsCOMPtr<nsIURI> uri;
+ if (mCurrentRequest) {
+ mCurrentRequest->GetFinalURI(getter_AddRefs(uri));
+ }
+
+ return uri.forget();
+}
+
NS_IMETHODIMP
nsImageLoadingContent::LoadImageWithChannel(nsIChannel* aChannel,
nsIStreamListener** aListener)
{
imgLoader* loader =
nsContentUtils::GetImgLoaderForChannel(aChannel, GetOurOwnerDoc());
if (!loader) {
return NS_ERROR_NULL_POINTER;
--- a/dom/base/nsImageLoadingContent.h
+++ b/dom/base/nsImageLoadingContent.h
@@ -65,16 +65,17 @@ public:
{
return mImageBlockingStatus;
}
already_AddRefed<imgIRequest>
GetRequest(int32_t aRequestType, mozilla::ErrorResult& aError);
int32_t
GetRequestType(imgIRequest* aRequest, mozilla::ErrorResult& aError);
already_AddRefed<nsIURI> GetCurrentURI(mozilla::ErrorResult& aError);
+ already_AddRefed<nsIURI> GetCurrentRequestFinalURI();
void ForceReload(const mozilla::dom::Optional<bool>& aNotify,
mozilla::ErrorResult& aError);
// XPCOM [optional] syntax helper
nsresult ForceReload(bool aNotify = true) {
return ForceReload(aNotify, 1);
}
--- a/dom/webidl/HTMLImageElement.webidl
+++ b/dom/webidl/HTMLImageElement.webidl
@@ -97,15 +97,19 @@ interface MozImageLoadingContent {
[ChromeOnly]
void removeObserver(imgINotificationObserver aObserver);
[ChromeOnly,Throws]
imgIRequest? getRequest(long aRequestType);
[ChromeOnly,Throws]
long getRequestType(imgIRequest aRequest);
[ChromeOnly,Throws]
readonly attribute URI? currentURI;
+ // Gets the final URI of the current request, if available.
+ // Otherwise, returns null.
+ [ChromeOnly]
+ readonly attribute URI? currentRequestFinalURI;
[ChromeOnly,Throws]
void forceReload(optional boolean aNotify);
[ChromeOnly]
void forceImageState(boolean aForce, unsigned long long aState);
};
HTMLImageElement implements MozImageLoadingContent;