2001-01-23 01:01:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#ifndef mozilla_image_imgRequest_h
|
|
|
|
#define mozilla_image_imgRequest_h
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2008-12-23 01:20:46 +03:00
|
|
|
#include "nsIChannelEventSink.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-01-23 01:01:03 +03:00
|
|
|
#include "nsIStreamListener.h"
|
2013-09-28 22:28:42 +04:00
|
|
|
#include "nsIThreadRetargetableStreamListener.h"
|
2007-11-09 05:55:41 +03:00
|
|
|
#include "nsIPrincipal.h"
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2001-05-08 08:21:49 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2013-09-28 22:28:42 +04:00
|
|
|
#include "nsProxyRelease.h"
|
2017-12-07 03:52:51 +03:00
|
|
|
#include "nsString.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2010-08-05 06:15:55 +04:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2015-03-24 05:37:45 +03:00
|
|
|
#include "mozilla/Mutex.h"
|
2015-05-20 20:21:13 +03:00
|
|
|
#include "ImageCacheKey.h"
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2002-12-24 17:30:12 +03:00
|
|
|
class imgCacheValidator;
|
2012-06-26 08:20:12 +04:00
|
|
|
class imgLoader;
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
class imgRequestProxy;
|
2008-09-05 03:00:42 +04:00
|
|
|
class imgCacheEntry;
|
2013-09-07 17:01:08 +04:00
|
|
|
class nsIProperties;
|
|
|
|
class nsIRequest;
|
|
|
|
class nsITimedChannel;
|
|
|
|
class nsIURI;
|
2019-07-25 11:23:32 +03:00
|
|
|
class nsIReferrerInfo;
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
|
2010-08-14 08:09:48 +04:00
|
|
|
namespace mozilla {
|
2021-05-05 18:23:25 +03:00
|
|
|
enum CORSMode : uint8_t;
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2010-08-14 08:09:48 +04:00
|
|
|
class Image;
|
2014-11-15 07:10:47 +03:00
|
|
|
class ProgressTracker;
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-08-14 08:09:48 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
struct NewPartResult;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class imgRequest final : public nsIStreamListener,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIThreadRetargetableStreamListener,
|
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIAsyncVerifyRedirectCallback {
|
2014-11-15 07:10:47 +03:00
|
|
|
typedef mozilla::image::Image Image;
|
2015-05-20 20:21:13 +03:00
|
|
|
typedef mozilla::image::ImageCacheKey ImageCacheKey;
|
2014-11-15 07:10:47 +03:00
|
|
|
typedef mozilla::image::ProgressTracker ProgressTracker;
|
2019-08-21 16:24:45 +03:00
|
|
|
typedef mozilla::dom::ReferrerPolicy ReferrerPolicy;
|
2014-11-15 07:10:47 +03:00
|
|
|
|
2015-03-24 05:37:46 +03:00
|
|
|
public:
|
2015-05-20 20:21:13 +03:00
|
|
|
imgRequest(imgLoader* aLoader, const ImageCacheKey& aCacheKey);
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2013-09-28 22:28:42 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2015-03-24 05:37:46 +03:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
|
2001-10-12 10:43:52 +04:00
|
|
|
|
2020-11-18 12:05:59 +03:00
|
|
|
[[nodiscard]] nsresult Init(nsIURI* aURI, nsIURI* aFinalURI,
|
|
|
|
bool aHadInsecureRedirect, nsIRequest* aRequest,
|
|
|
|
nsIChannel* aChannel, imgCacheEntry* aCacheEntry,
|
|
|
|
mozilla::dom::Document* aLoadingDocument,
|
|
|
|
nsIPrincipal* aTriggeringPrincipal,
|
2021-05-05 18:23:25 +03:00
|
|
|
mozilla::CORSMode aCORSMode,
|
2020-11-18 12:05:59 +03:00
|
|
|
nsIReferrerInfo* aReferrerInfo);
|
2001-10-12 10:43:52 +04:00
|
|
|
|
2014-09-06 01:36:11 +04:00
|
|
|
void ClearLoader();
|
|
|
|
|
2010-05-11 07:27:41 +04:00
|
|
|
// Callers must call imgRequestProxy::Notify later.
|
2015-03-31 21:06:00 +03:00
|
|
|
void AddProxy(imgRequestProxy* proxy);
|
2006-06-01 22:35:21 +04:00
|
|
|
|
2020-07-30 11:55:24 +03:00
|
|
|
// Whether a given document is allowed to reuse this request without any
|
|
|
|
// revalidation.
|
|
|
|
bool CanReuseWithoutValidation(mozilla::dom::Document*) const;
|
|
|
|
|
2015-03-31 21:06:00 +03:00
|
|
|
nsresult RemoveProxy(imgRequestProxy* proxy, nsresult aStatus);
|
2001-02-26 07:22:47 +03:00
|
|
|
|
2008-12-23 01:20:46 +03:00
|
|
|
// Cancel, but also ensure that all work done in Init() is undone. Call this
|
|
|
|
// only when the channel has failed to open, and so calling Cancel() on it
|
|
|
|
// won't be sufficient.
|
|
|
|
void CancelAndAbort(nsresult aStatus);
|
|
|
|
|
2013-10-16 03:33:11 +04:00
|
|
|
// Called or dispatched by cancel for main thread only execution.
|
|
|
|
void ContinueCancel(nsresult aStatus);
|
|
|
|
|
2014-06-09 02:15:00 +04:00
|
|
|
// Called or dispatched by EvictFromCache for main thread only execution.
|
|
|
|
void ContinueEvict();
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
// Request that we start decoding the image as soon as data becomes available.
|
2015-10-30 02:37:42 +03:00
|
|
|
void StartDecoding();
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
inline uint64_t InnerWindowID() const { return mInnerWindowId; }
|
2019-09-17 16:16:19 +03:00
|
|
|
void SetInnerWindowID(uint64_t aInnerWindowId) {
|
|
|
|
mInnerWindowId = aInnerWindowId;
|
|
|
|
}
|
2010-12-20 19:21:59 +03:00
|
|
|
|
2011-07-01 21:03:33 +04:00
|
|
|
// Set the cache validation information (expiry time, whether we must
|
|
|
|
// validate, etc) on the cache entry based on the request information.
|
|
|
|
// If this function is called multiple times, the information set earliest
|
|
|
|
// wins.
|
|
|
|
static void SetCacheValidation(imgCacheEntry* aEntry, nsIRequest* aRequest);
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
bool GetMultipart() const;
|
2012-05-19 23:32:37 +04:00
|
|
|
|
2014-12-16 04:40:43 +03:00
|
|
|
// Returns whether we went through an insecure (non-HTTPS) redirect at some
|
2017-11-13 11:31:24 +03:00
|
|
|
// point during loading. This does not consider the final URI.
|
2015-03-30 02:25:48 +03:00
|
|
|
bool HadInsecureRedirect() const;
|
2014-12-16 04:40:43 +03:00
|
|
|
|
2011-07-14 22:47:34 +04:00
|
|
|
// The CORS mode for which we loaded this image.
|
2021-05-05 18:23:25 +03:00
|
|
|
mozilla::CORSMode GetCORSMode() const { return mCORSMode; }
|
2011-07-14 22:47:34 +04:00
|
|
|
|
2019-07-25 11:23:32 +03:00
|
|
|
// The ReferrerInfo in effect when loading this image.
|
|
|
|
nsIReferrerInfo* GetReferrerInfo() const { return mReferrerInfo; }
|
2014-11-18 16:46:53 +03:00
|
|
|
|
2011-07-14 22:47:32 +04:00
|
|
|
// The principal for the document that loaded this image. Used when trying to
|
|
|
|
// validate a CORS image load.
|
2017-10-03 06:38:30 +03:00
|
|
|
already_AddRefed<nsIPrincipal> GetTriggeringPrincipal() const {
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = mTriggeringPrincipal;
|
2011-07-14 22:47:32 +04:00
|
|
|
return principal.forget();
|
|
|
|
}
|
|
|
|
|
2014-11-15 07:10:47 +03:00
|
|
|
// Return the ProgressTracker associated with this imgRequest. It may live
|
|
|
|
// in |mProgressTracker| or in |mImage.mProgressTracker|, depending on whether
|
2012-10-12 20:11:21 +04:00
|
|
|
// mImage has been instantiated yet.
|
2015-03-24 05:37:45 +03:00
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker() const;
|
2012-10-12 20:11:21 +04:00
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
/// Returns the Image associated with this imgRequest, if it's ready.
|
|
|
|
already_AddRefed<Image> GetImage() const;
|
|
|
|
|
2012-10-12 20:11:20 +04:00
|
|
|
// Get the current principal of the image. No AddRefing.
|
2012-12-09 21:23:19 +04:00
|
|
|
inline nsIPrincipal* GetPrincipal() const { return mPrincipal.get(); }
|
2012-10-12 20:11:20 +04:00
|
|
|
|
2015-05-20 20:21:13 +03:00
|
|
|
/// Get the ImageCacheKey associated with this request.
|
|
|
|
const ImageCacheKey& CacheKey() const { return mCacheKey; }
|
|
|
|
|
2012-10-12 20:11:21 +04:00
|
|
|
// Resize the cache entry to 0 if it exists
|
|
|
|
void ResetCacheEntry();
|
|
|
|
|
2013-09-28 22:28:42 +04:00
|
|
|
// OK to use on any thread.
|
2018-06-06 03:42:57 +03:00
|
|
|
nsresult GetURI(nsIURI** aURI);
|
2017-11-13 11:31:24 +03:00
|
|
|
nsresult GetFinalURI(nsIURI** aURI);
|
2015-04-28 21:45:45 +03:00
|
|
|
bool IsChrome() const;
|
2017-09-25 18:44:49 +03:00
|
|
|
bool IsData() const;
|
2012-10-12 20:11:21 +04:00
|
|
|
|
2014-07-19 05:47:11 +04:00
|
|
|
nsresult GetImageErrorCode(void);
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
/// Returns a non-owning pointer to this imgRequest's MIME type.
|
|
|
|
const char* GetMimeType() const { return mContentType.get(); }
|
|
|
|
|
|
|
|
/// @return the priority of the underlying network request, or
|
|
|
|
/// PRIORITY_NORMAL if it doesn't support nsISupportsPriority.
|
|
|
|
int32_t Priority() const;
|
|
|
|
|
|
|
|
/// Adjust the priority of the underlying network request by @aDelta on behalf
|
|
|
|
/// of @aProxy.
|
|
|
|
void AdjustPriority(imgRequestProxy* aProxy, int32_t aDelta);
|
|
|
|
|
2017-03-22 14:52:15 +03:00
|
|
|
void BoostPriority(uint32_t aCategory);
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
/// Returns a weak pointer to the underlying request.
|
|
|
|
nsIRequest* GetRequest() const { return mRequest; }
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
nsITimedChannel* GetTimedChannel() const { return mTimedChannel; }
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
imgCacheValidator* GetValidator() const { return mValidator; }
|
|
|
|
void SetValidator(imgCacheValidator* aValidator) { mValidator = aValidator; }
|
2015-03-24 05:37:45 +03:00
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
void* LoadId() const { return mLoadId; }
|
2015-03-24 05:37:45 +03:00
|
|
|
void SetLoadId(void* aLoadId) { mLoadId = aLoadId; }
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
/// Reset the cache entry after we've dropped our reference to it. Used by
|
|
|
|
/// imgLoader when our cache entry is re-requested after we've dropped our
|
|
|
|
/// reference to it.
|
|
|
|
void SetCacheEntry(imgCacheEntry* aEntry);
|
|
|
|
|
|
|
|
/// Returns whether we've got a reference to the cache entry.
|
|
|
|
bool HasCacheEntry() const;
|
|
|
|
|
|
|
|
/// Set whether this request is stored in the cache. If it isn't, regardless
|
|
|
|
/// of whether this request has a non-null mCacheEntry, this imgRequest won't
|
|
|
|
/// try to update or modify the image cache.
|
|
|
|
void SetIsInCache(bool aCacheable);
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
void EvictFromCache();
|
|
|
|
void RemoveFromCache();
|
|
|
|
|
2015-03-24 05:37:46 +03:00
|
|
|
// Sets properties for this image; will dispatch to main thread if needed.
|
|
|
|
void SetProperties(const nsACString& aContentType,
|
|
|
|
const nsACString& aContentDisposition);
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
nsIProperties* Properties() const { return mProperties; }
|
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
bool HasConsumers() const;
|
|
|
|
|
2019-05-02 02:05:47 +03:00
|
|
|
bool ImageAvailable() const;
|
|
|
|
|
2020-05-11 17:43:05 +03:00
|
|
|
bool IsDeniedCrossSiteCORSRequest() const {
|
|
|
|
return mIsDeniedCrossSiteCORSRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsCrossSiteNoCORSRequest() const { return mIsCrossSiteNoCORSRequest; }
|
|
|
|
|
2001-10-12 10:43:52 +04:00
|
|
|
private:
|
2015-03-24 05:37:46 +03:00
|
|
|
friend class FinishPreparingForNewPartRunnable;
|
|
|
|
|
|
|
|
virtual ~imgRequest();
|
|
|
|
|
|
|
|
void FinishPreparingForNewPart(const NewPartResult& aResult);
|
|
|
|
|
2001-10-12 10:43:52 +04:00
|
|
|
void Cancel(nsresult aStatus);
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2014-11-27 05:00:15 +03:00
|
|
|
// Update the cache entry size based on the image container.
|
|
|
|
void UpdateCacheEntrySize();
|
|
|
|
|
2015-10-30 02:37:42 +03:00
|
|
|
/// Returns true if StartDecoding() was called.
|
2015-03-24 05:37:45 +03:00
|
|
|
bool IsDecodeRequested() const;
|
|
|
|
|
2017-03-22 14:52:15 +03:00
|
|
|
void AdjustPriorityInternal(int32_t aDelta);
|
|
|
|
|
2012-06-26 08:20:12 +04:00
|
|
|
// Weak reference to parent loader; this request cannot outlive its owner.
|
|
|
|
imgLoader* mLoader;
|
2006-03-11 23:32:47 +03:00
|
|
|
nsCOMPtr<nsIRequest> mRequest;
|
2011-07-01 21:03:40 +04:00
|
|
|
// The original URI we were loaded with. This is the same as the URI we are
|
2013-09-28 22:28:42 +04:00
|
|
|
// keyed on in the cache. We store a string here to avoid off main thread
|
|
|
|
// refcounting issues with nsStandardURL.
|
2018-06-06 03:42:57 +03:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2011-07-01 21:03:40 +04:00
|
|
|
// The URI of the resource we ended up loading after all redirects, etc.
|
2017-11-13 11:31:24 +03:00
|
|
|
nsCOMPtr<nsIURI> mFinalURI;
|
2017-10-03 06:38:30 +03:00
|
|
|
// The principal which triggered the load of this image. Generally either
|
|
|
|
// the principal of the document the image is being loaded into, or of the
|
|
|
|
// stylesheet which specified the image to load. Used when validating for
|
|
|
|
// CORS.
|
|
|
|
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
2011-07-14 22:47:32 +04:00
|
|
|
// The principal of this image.
|
2007-11-09 05:55:41 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2005-03-24 00:09:02 +03:00
|
|
|
nsCOMPtr<nsIProperties> mProperties;
|
2008-12-23 01:20:46 +03:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mPrevChannelSink;
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2011-06-10 01:11:57 +04:00
|
|
|
nsCOMPtr<nsITimedChannel> mTimedChannel;
|
|
|
|
|
2004-07-19 22:53:02 +04:00
|
|
|
nsCString mContentType;
|
2001-03-16 05:40:04 +03:00
|
|
|
|
2015-03-31 21:06:00 +03:00
|
|
|
/* we hold on to this to this so long as we have observers */
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgCacheEntry> mCacheEntry;
|
2001-10-17 09:57:29 +04:00
|
|
|
|
2015-05-20 20:21:13 +03:00
|
|
|
/// The key under which this imgRequest is stored in the image cache.
|
|
|
|
ImageCacheKey mCacheKey;
|
|
|
|
|
2015-03-31 21:06:00 +03:00
|
|
|
void* mLoadId;
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2015-08-25 05:49:33 +03:00
|
|
|
/// Raw pointer to the first proxy that was added to this imgRequest. Use only
|
|
|
|
/// pointer comparisons; there's no guarantee this will remain valid.
|
|
|
|
void* mFirstProxy;
|
|
|
|
|
2015-03-31 21:06:00 +03:00
|
|
|
imgCacheValidator* mValidator;
|
2010-08-05 06:15:55 +04:00
|
|
|
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
|
|
|
|
nsCOMPtr<nsIChannel> mNewRedirectChannel;
|
2010-12-20 19:21:59 +03:00
|
|
|
|
2011-08-25 00:44:35 +04:00
|
|
|
// The ID of the inner window origin, used for error reporting.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t mInnerWindowId;
|
2010-12-20 19:21:59 +03:00
|
|
|
|
2011-07-14 22:47:34 +04:00
|
|
|
// The CORS mode (defined in imgIRequest) this image was loaded with. By
|
2021-05-05 18:23:25 +03:00
|
|
|
// default, CORS_NONE.
|
|
|
|
mozilla::CORSMode mCORSMode;
|
2011-07-14 22:47:34 +04:00
|
|
|
|
2019-07-25 11:23:32 +03:00
|
|
|
// The ReferrerInfo used for this image.
|
|
|
|
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
|
2014-11-18 16:46:53 +03:00
|
|
|
|
2014-07-19 05:47:11 +04:00
|
|
|
nsresult mImageErrorCode;
|
|
|
|
|
2017-03-22 14:52:15 +03:00
|
|
|
// The categories of prioritization strategy that have been requested.
|
|
|
|
uint32_t mBoostCategoriesRequested = 0;
|
|
|
|
|
2019-05-02 02:05:47 +03:00
|
|
|
// If we've called OnImageAvailable.
|
|
|
|
bool mImageAvailable;
|
2020-05-26 05:06:00 +03:00
|
|
|
bool mIsDeniedCrossSiteCORSRequest;
|
|
|
|
bool mIsCrossSiteNoCORSRequest;
|
2019-05-02 02:05:47 +03:00
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
mutable mozilla::Mutex mMutex;
|
2009-09-16 04:33:14 +04:00
|
|
|
|
2015-03-24 05:37:45 +03:00
|
|
|
// Member variables protected by mMutex. Note that *all* flags in our bitfield
|
|
|
|
// are protected by mMutex; if you're adding a new flag that isn'protected, it
|
|
|
|
// must not be a part of this bitfield.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> mProgressTracker;
|
|
|
|
RefPtr<Image> mImage;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsMultiPartChannel : 1;
|
|
|
|
bool mIsInCache : 1;
|
2015-03-24 05:37:45 +03:00
|
|
|
bool mDecodeRequested : 1;
|
2015-01-07 12:37:20 +03:00
|
|
|
bool mNewPartPending : 1;
|
2014-12-16 04:40:43 +03:00
|
|
|
bool mHadInsecureRedirect : 1;
|
2001-01-23 01:01:03 +03:00
|
|
|
};
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#endif // mozilla_image_imgRequest_h
|