2001-02-20 22:43:56 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00: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-02-20 22:43:56 +00:00
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#ifndef mozilla_image_imgRequestProxy_h
|
|
|
|
#define mozilla_image_imgRequestProxy_h
|
2010-05-14 20:47:59 +00:00
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
#include "imgIRequest.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2020-11-23 16:12:44 +00:00
|
|
|
#include "nsIPrincipal.h"
|
2005-02-21 20:58:01 +00:00
|
|
|
#include "nsISupportsPriority.h"
|
2011-06-09 21:11:57 +00:00
|
|
|
#include "nsITimedChannel.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2008-12-19 22:35:50 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2020-05-11 14:43:05 +00:00
|
|
|
#include "mozilla/PreloaderBase.h"
|
2013-10-16 01:35:44 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2015-10-17 10:53:28 +00:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2015-04-21 15:04:57 +00:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2015-01-07 09:35:20 +00:00
|
|
|
#include "IProgressObserver.h"
|
2001-10-12 06:43:52 +00:00
|
|
|
|
2001-02-20 23:35:22 +00:00
|
|
|
#define NS_IMGREQUESTPROXY_CID \
|
2001-02-20 22:43:56 +00:00
|
|
|
{ /* 20557898-1dd2-11b2-8f65-9c462ee2bc95 */ \
|
|
|
|
0x20557898, 0x1dd2, 0x11b2, { \
|
|
|
|
0x8f, 0x65, 0x9c, 0x46, 0x2e, 0xe2, 0xbc, 0x95 \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2018-02-07 12:27:27 +00:00
|
|
|
class imgCacheValidator;
|
2013-09-07 13:01:08 +00:00
|
|
|
class imgINotificationObserver;
|
2020-11-23 16:12:44 +00:00
|
|
|
class imgRequest;
|
2010-07-28 21:52:14 +00:00
|
|
|
class imgStatusNotifyRunnable;
|
2012-10-19 19:39:38 +00:00
|
|
|
class ProxyBehaviour;
|
2010-07-28 21:52:14 +00:00
|
|
|
|
2010-08-14 04:09:48 +00:00
|
|
|
namespace mozilla {
|
2012-01-06 16:02:27 +00:00
|
|
|
namespace image {
|
2010-08-14 04:09:48 +00:00
|
|
|
class Image;
|
2014-11-15 04:10:47 +00:00
|
|
|
class ProgressTracker;
|
2012-01-06 16:02:27 +00:00
|
|
|
} // namespace image
|
2010-08-14 04:09:48 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-05-11 14:43:05 +00:00
|
|
|
class imgRequestProxy : public mozilla::PreloaderBase,
|
|
|
|
public imgIRequest,
|
2015-01-07 09:35:20 +00:00
|
|
|
public mozilla::image::IProgressObserver,
|
2013-03-29 20:14:19 +00:00
|
|
|
public nsISupportsPriority,
|
2015-01-07 09:35:20 +00:00
|
|
|
public nsITimedChannel {
|
2014-06-23 18:49:08 +00:00
|
|
|
protected:
|
|
|
|
virtual ~imgRequestProxy();
|
|
|
|
|
2001-02-20 22:43:56 +00:00
|
|
|
public:
|
2019-01-02 13:05:23 +00:00
|
|
|
typedef mozilla::dom::Document Document;
|
2014-11-15 04:10:47 +00:00
|
|
|
typedef mozilla::image::Image Image;
|
|
|
|
typedef mozilla::image::ProgressTracker ProgressTracker;
|
|
|
|
|
2020-05-11 14:43:05 +00:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMGREQUESTPROXY_CID)
|
2014-11-15 04:10:47 +00:00
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(imgRequestProxy)
|
2001-02-20 22:43:56 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
2001-02-20 23:27:48 +00:00
|
|
|
NS_DECL_IMGIREQUEST
|
2001-03-06 04:46:20 +00:00
|
|
|
NS_DECL_NSIREQUEST
|
2005-02-21 20:58:01 +00:00
|
|
|
NS_DECL_NSISUPPORTSPRIORITY
|
2011-06-09 21:11:57 +00:00
|
|
|
// nsITimedChannel declared below
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2001-02-20 23:27:48 +00:00
|
|
|
imgRequestProxy();
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2010-05-11 03:27:41 +00:00
|
|
|
// Callers to Init or ChangeOwner are required to call NotifyListener after
|
|
|
|
// (although not immediately after) doing so.
|
2012-12-19 21:28:54 +00:00
|
|
|
nsresult Init(imgRequest* aOwner, nsILoadGroup* aLoadGroup,
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* aLoadingDocument, nsIURI* aURI,
|
2015-03-25 17:59:00 +00:00
|
|
|
imgINotificationObserver* aObserver);
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
nsresult ChangeOwner(imgRequest* aNewOwner); // this will change mOwner.
|
|
|
|
// Do not call this if the
|
|
|
|
// previous owner has already
|
|
|
|
// sent notifications out!
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2017-11-01 10:59:10 +00:00
|
|
|
// Add the request to the load group, if any. This should only be called once
|
|
|
|
// during initialization.
|
2003-05-14 05:42:06 +00:00
|
|
|
void AddToLoadGroup();
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
inline bool HasObserver() const { return mListener != nullptr; }
|
2010-05-14 20:47:59 +00:00
|
|
|
|
2010-07-28 21:52:14 +00:00
|
|
|
// Asynchronously notify this proxy's listener of the current state of the
|
|
|
|
// image, and, if we have an imgRequest mOwner, any status changes that
|
|
|
|
// happen between the time this function is called and the time the
|
|
|
|
// notification is scheduled.
|
2010-05-14 20:47:59 +00:00
|
|
|
void NotifyListener();
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2010-07-28 21:52:14 +00:00
|
|
|
// Synchronously notify this proxy's listener of the current state of the
|
|
|
|
// image. Only use this function if you are currently servicing an
|
|
|
|
// asynchronously-called function.
|
|
|
|
void SyncNotifyListener();
|
|
|
|
|
2015-01-07 09:35:20 +00:00
|
|
|
// imgINotificationObserver methods:
|
|
|
|
virtual void Notify(int32_t aType,
|
2015-04-21 15:04:57 +00:00
|
|
|
const mozilla::gfx::IntRect* aRect = nullptr) override;
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void OnLoadComplete(bool aLastPart) override;
|
2015-01-07 09:35:20 +00:00
|
|
|
|
|
|
|
// Other, internal-only methods:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void SetHasImage() override;
|
2015-01-07 09:35:20 +00:00
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
// Whether we want notifications from ProgressTracker to be deferred until
|
2018-02-07 12:27:27 +00:00
|
|
|
// an event it has scheduled has been fired and/or validation is complete.
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool NotificationsDeferred() const override {
|
2018-02-07 12:27:27 +00:00
|
|
|
return IsValidating() || mPendingNotify;
|
2010-08-02 19:44:49 +00:00
|
|
|
}
|
2018-02-07 12:27:27 +00:00
|
|
|
virtual void MarkPendingNotify() override { mPendingNotify = true; }
|
|
|
|
virtual void ClearPendingNotify() override { mPendingNotify = false; }
|
2018-02-07 12:27:27 +00:00
|
|
|
bool IsValidating() const { return mValidating; }
|
|
|
|
void MarkValidating();
|
|
|
|
void ClearValidating();
|
2010-08-02 19:44:49 +00:00
|
|
|
|
2017-07-19 18:15:11 +00:00
|
|
|
already_AddRefed<nsIEventTarget> GetEventTarget() const override;
|
|
|
|
|
2010-09-08 00:33:02 +00:00
|
|
|
// Removes all animation consumers that were created with
|
|
|
|
// IncrementAnimationConsumers. This is necessary since we need
|
|
|
|
// to do it before the proxy itself is destroyed. See
|
|
|
|
// imgRequest::RemoveProxy
|
|
|
|
void ClearAnimationConsumers();
|
|
|
|
|
2017-07-19 18:15:11 +00:00
|
|
|
nsresult SyncClone(imgINotificationObserver* aObserver,
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* aLoadingDocument, imgRequestProxy** aClone);
|
2017-07-19 18:15:11 +00:00
|
|
|
nsresult Clone(imgINotificationObserver* aObserver,
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* aLoadingDocument, imgRequestProxy** aClone);
|
2020-08-02 15:29:15 +00:00
|
|
|
already_AddRefed<imgRequestProxy> GetStaticRequest(
|
|
|
|
Document* aLoadingDocument);
|
2012-10-12 12:43:01 +00:00
|
|
|
|
2020-05-11 14:43:05 +00:00
|
|
|
imgRequest* GetOwner() const;
|
|
|
|
|
|
|
|
// PreloaderBase
|
2020-06-02 20:28:30 +00:00
|
|
|
// We are using the default image loader prioritization for preloads.
|
|
|
|
virtual void PrioritizeAsPreload() override {}
|
2020-05-11 14:43:05 +00:00
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
protected:
|
2014-11-15 04:10:47 +00:00
|
|
|
friend class mozilla::image::ProgressTracker;
|
2010-07-28 21:52:14 +00:00
|
|
|
friend class imgStatusNotifyRunnable;
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2008-12-19 22:35:50 +00:00
|
|
|
class imgCancelRunnable;
|
|
|
|
friend class imgCancelRunnable;
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class imgCancelRunnable : public mozilla::Runnable {
|
2008-12-19 22:35:50 +00:00
|
|
|
public:
|
|
|
|
imgCancelRunnable(imgRequestProxy* owner, nsresult status)
|
2017-02-11 06:11:48 +00:00
|
|
|
: Runnable("imgCancelRunnable"), mOwner(owner), mStatus(status) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD Run() override {
|
2008-12-19 22:35:50 +00:00
|
|
|
mOwner->DoCancel(mStatus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2008-12-19 22:35:50 +00:00
|
|
|
private:
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequestProxy> mOwner;
|
2008-12-19 22:35:50 +00:00
|
|
|
nsresult mStatus;
|
|
|
|
};
|
|
|
|
|
2017-11-01 10:59:10 +00:00
|
|
|
/* Remove from and forget the load group. */
|
|
|
|
void RemoveFromLoadGroup();
|
|
|
|
|
2019-09-12 09:00:52 +00:00
|
|
|
/* Remove from the load group and re-add as a background request. */
|
2017-11-01 10:59:10 +00:00
|
|
|
void MoveToBackgroundInLoadGroup();
|
|
|
|
|
2008-12-19 22:35:50 +00:00
|
|
|
/* Finish up canceling ourselves */
|
|
|
|
void DoCancel(nsresult status);
|
|
|
|
|
2008-03-19 19:07:59 +00:00
|
|
|
/* Do the proper refcount management to null out mListener */
|
|
|
|
void NullOutListener();
|
2010-03-08 19:34:52 +00:00
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
// Return the ProgressTracker associated with mOwner and/or mImage. It may
|
2010-08-23 22:44:07 +00:00
|
|
|
// live either on mOwner or mImage, depending on whether
|
|
|
|
// (a) we have an mOwner at all
|
|
|
|
// (b) whether mOwner has instantiated its image yet
|
2014-11-15 04:10:47 +00:00
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker() const;
|
2010-08-23 22:44:07 +00:00
|
|
|
|
2020-11-23 16:12:44 +00:00
|
|
|
nsITimedChannel* TimedChannel();
|
2011-06-09 21:11:57 +00:00
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
already_AddRefed<Image> GetImage() const;
|
2013-09-28 18:28:44 +00:00
|
|
|
bool HasImage() const;
|
2018-02-07 12:27:27 +00:00
|
|
|
imgCacheValidator* GetValidator() const;
|
2012-10-12 16:11:21 +00:00
|
|
|
|
2012-10-12 16:11:22 +00:00
|
|
|
nsresult PerformClone(imgINotificationObserver* aObserver,
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* aLoadingDocument, bool aSyncNotify,
|
2012-10-12 12:43:01 +00:00
|
|
|
imgRequestProxy** aClone);
|
2012-10-12 16:11:22 +00:00
|
|
|
|
2017-07-19 18:15:11 +00:00
|
|
|
virtual imgRequestProxy* NewClonedProxy();
|
|
|
|
|
2011-06-09 21:11:57 +00:00
|
|
|
public:
|
|
|
|
NS_FORWARD_SAFE_NSITIMEDCHANNEL(TimedChannel())
|
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
protected:
|
2015-10-17 10:53:28 +00:00
|
|
|
mozilla::UniquePtr<ProxyBehaviour> mBehaviour;
|
2012-10-19 19:39:38 +00:00
|
|
|
|
2001-02-20 22:43:56 +00:00
|
|
|
private:
|
2002-12-24 14:30:12 +00:00
|
|
|
friend class imgCacheValidator;
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2019-01-02 13:05:23 +00:00
|
|
|
void AddToOwner(Document* aLoadingDocument);
|
2018-02-07 12:27:27 +00:00
|
|
|
void RemoveFromOwner(nsresult aStatus);
|
2017-07-19 18:15:11 +00:00
|
|
|
|
2017-08-15 11:14:51 +00:00
|
|
|
nsresult DispatchWithTargetIfAvailable(already_AddRefed<nsIRunnable> aEvent);
|
2017-07-19 18:15:11 +00:00
|
|
|
|
2010-05-11 03:27:41 +00:00
|
|
|
// The URI of our request.
|
2018-06-06 00:42:57 +00:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2008-03-19 19:07:59 +00:00
|
|
|
// mListener is only promised to be a weak ref (see imgILoader.idl),
|
|
|
|
// but we actually keep a strong ref to it until we've seen our
|
|
|
|
// first OnStopRequest.
|
2015-06-15 18:21:00 +00:00
|
|
|
imgINotificationObserver* MOZ_UNSAFE_REF(
|
|
|
|
"Observers must call Cancel() or "
|
|
|
|
"CancelAndForgetObserver() before "
|
|
|
|
"they are destroyed") mListener;
|
|
|
|
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
2017-07-19 18:15:11 +00:00
|
|
|
nsCOMPtr<nsIEventTarget> mEventTarget;
|
2001-03-06 04:46:20 +00:00
|
|
|
|
2001-07-17 01:14:40 +00:00
|
|
|
nsLoadFlags mLoadFlags;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mLockCount;
|
|
|
|
uint32_t mAnimationConsumers;
|
2017-07-19 18:15:12 +00:00
|
|
|
bool mCanceled : 1;
|
|
|
|
bool mIsInLoadGroup : 1;
|
2017-11-01 10:59:10 +00:00
|
|
|
bool mForceDispatchLoadGroup : 1;
|
2017-07-19 18:15:12 +00:00
|
|
|
bool mListenerIsStrongRef : 1;
|
|
|
|
bool mDecodeRequested : 1;
|
2010-07-28 21:52:14 +00:00
|
|
|
|
|
|
|
// Whether we want to defer our notifications by the non-virtual Observer
|
|
|
|
// interfaces as image loads proceed.
|
2018-02-07 12:27:27 +00:00
|
|
|
bool mPendingNotify : 1;
|
2018-02-07 12:27:27 +00:00
|
|
|
bool mValidating : 1;
|
2017-07-19 18:15:12 +00:00
|
|
|
bool mHadListener : 1;
|
|
|
|
bool mHadDispatch : 1;
|
2012-10-12 01:34:22 +00:00
|
|
|
};
|
|
|
|
|
2020-05-11 14:43:05 +00:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(imgRequestProxy, NS_IMGREQUESTPROXY_CID)
|
|
|
|
|
2012-10-12 16:11:20 +00:00
|
|
|
// Used for static image proxies for which no requests are available, so
|
|
|
|
// certain behaviours must be overridden to compensate.
|
|
|
|
class imgRequestProxyStatic : public imgRequestProxy {
|
|
|
|
public:
|
2019-06-04 06:31:42 +00:00
|
|
|
imgRequestProxyStatic(Image* aImage, nsIPrincipal* aPrincipal,
|
|
|
|
bool hadCrossOriginRedirects);
|
2012-10-12 16:11:20 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD GetImagePrincipal(nsIPrincipal** aPrincipal) override;
|
2012-10-12 16:11:20 +00:00
|
|
|
|
2019-06-04 06:31:42 +00:00
|
|
|
NS_IMETHOD GetHadCrossOriginRedirects(
|
|
|
|
bool* aHadCrossOriginRedirects) override;
|
|
|
|
|
2012-10-12 16:11:20 +00:00
|
|
|
protected:
|
2017-07-19 18:15:11 +00:00
|
|
|
imgRequestProxy* NewClonedProxy() override;
|
2012-10-12 16:11:22 +00:00
|
|
|
|
2012-10-12 16:11:20 +00:00
|
|
|
// Our principal. We have to cache it, rather than accessing the underlying
|
|
|
|
// request on-demand, because static proxies don't have an underlying request.
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2019-06-04 06:31:42 +00:00
|
|
|
const bool mHadCrossOriginRedirects;
|
2012-10-12 16:11:20 +00:00
|
|
|
};
|
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#endif // mozilla_image_imgRequestProxy_h
|