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
|
|
|
|
2014-08-22 20:12:38 +00:00
|
|
|
#include "ImageLogging.h"
|
2001-02-20 23:27:48 +00:00
|
|
|
#include "imgRequestProxy.h"
|
2012-08-13 22:58:53 +00:00
|
|
|
#include "imgIOnloadBlocker.h"
|
2015-04-10 06:15:39 +00:00
|
|
|
#include "imgLoader.h"
|
2010-08-14 04:09:48 +00:00
|
|
|
#include "Image.h"
|
2013-04-05 21:14:34 +00:00
|
|
|
#include "ImageOps.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2013-09-07 13:01:08 +00:00
|
|
|
#include "nsCRTGlue.h"
|
|
|
|
#include "imgINotificationObserver.h"
|
2001-05-08 04:01:28 +00:00
|
|
|
|
2012-01-06 16:02:27 +00:00
|
|
|
using namespace mozilla::image;
|
2010-08-14 04:09:48 +00:00
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
// The split of imgRequestProxy and imgRequestProxyStatic means that
|
|
|
|
// certain overridden functions need to be usable in the destructor.
|
|
|
|
// Since virtual functions can't be used in that way, this class
|
|
|
|
// provides a behavioural trait for each class to use instead.
|
|
|
|
class ProxyBehaviour
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ProxyBehaviour() {}
|
|
|
|
|
2013-09-28 18:28:44 +00:00
|
|
|
virtual already_AddRefed<mozilla::image::Image> GetImage() const = 0;
|
|
|
|
virtual bool HasImage() const = 0;
|
2014-11-15 04:10:47 +00:00
|
|
|
virtual already_AddRefed<ProgressTracker> GetProgressTracker() const = 0;
|
2012-10-19 19:39:38 +00:00
|
|
|
virtual imgRequest* GetOwner() const = 0;
|
|
|
|
virtual void SetOwner(imgRequest* aOwner) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RequestBehaviour : public ProxyBehaviour
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RequestBehaviour() : mOwner(nullptr), mOwnerHasImage(false) {}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
virtual already_AddRefed<mozilla::image::Image>GetImage() const override;
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool HasImage() const override;
|
|
|
|
virtual already_AddRefed<ProgressTracker> GetProgressTracker() const override;
|
2012-10-19 19:39:38 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual imgRequest* GetOwner() const override {
|
2012-10-19 19:39:38 +00:00
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void SetOwner(imgRequest* aOwner) override {
|
2012-10-19 19:39:38 +00:00
|
|
|
mOwner = aOwner;
|
2013-04-26 03:30:29 +00:00
|
|
|
|
|
|
|
if (mOwner) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProgressTracker> ownerProgressTracker = GetProgressTracker();
|
2014-11-15 04:10:47 +00:00
|
|
|
mOwnerHasImage = ownerProgressTracker && ownerProgressTracker->HasImage();
|
2013-04-26 03:30:29 +00:00
|
|
|
} else {
|
|
|
|
mOwnerHasImage = false;
|
|
|
|
}
|
2012-10-19 19:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// We maintain the following invariant:
|
|
|
|
// The proxy is registered at most with a single imgRequest as an observer,
|
|
|
|
// and whenever it is, mOwner points to that object. This helps ensure that
|
|
|
|
// imgRequestProxy::~imgRequestProxy unregisters the proxy as an observer
|
|
|
|
// from whatever request it was registered with (if any). This, in turn,
|
|
|
|
// means that imgRequest::mObservers will not have any stale pointers in it.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequest> mOwner;
|
2012-10-19 19:39:38 +00:00
|
|
|
|
|
|
|
bool mOwnerHasImage;
|
|
|
|
};
|
|
|
|
|
2013-09-28 18:28:44 +00:00
|
|
|
already_AddRefed<mozilla::image::Image>
|
2012-10-19 19:39:38 +00:00
|
|
|
RequestBehaviour::GetImage() const
|
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (!mOwnerHasImage) {
|
2012-10-19 19:39:38 +00:00
|
|
|
return nullptr;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 04:10:47 +00:00
|
|
|
return progressTracker->GetImage();
|
2012-10-19 19:39:38 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
already_AddRefed<ProgressTracker>
|
|
|
|
RequestBehaviour::GetProgressTracker() const
|
2012-10-19 19:39:38 +00:00
|
|
|
{
|
|
|
|
// NOTE: It's possible that our mOwner has an Image that it didn't notify
|
|
|
|
// us about, if we were Canceled before its Image was constructed.
|
|
|
|
// (Canceling removes us as an observer, so mOwner has no way to notify us).
|
2014-11-15 04:10:47 +00:00
|
|
|
// That's why this method uses mOwner->GetProgressTracker() instead of just
|
|
|
|
// mOwner->mProgressTracker -- we might have a null mImage and yet have an
|
|
|
|
// mOwner with a non-null mImage (and a null mProgressTracker pointer).
|
|
|
|
return mOwner->GetProgressTracker();
|
2012-10-19 19:39:38 +00:00
|
|
|
}
|
|
|
|
|
2011-06-09 21:11:57 +00:00
|
|
|
NS_IMPL_ADDREF(imgRequestProxy)
|
|
|
|
NS_IMPL_RELEASE(imgRequestProxy)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(imgRequestProxy)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, imgIRequest)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(imgIRequest)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequest)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsPriority)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISecurityInfoProvider)
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsITimedChannel,
|
|
|
|
TimedChannel() != nullptr)
|
2011-06-09 21:11:57 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2001-02-22 02:06:24 +00:00
|
|
|
imgRequestProxy::imgRequestProxy() :
|
2012-10-19 19:39:38 +00:00
|
|
|
mBehaviour(new RequestBehaviour),
|
2012-07-30 14:20:58 +00:00
|
|
|
mURI(nullptr),
|
|
|
|
mListener(nullptr),
|
2001-07-17 01:14:40 +00:00
|
|
|
mLoadFlags(nsIRequest::LOAD_NORMAL),
|
2010-08-26 06:21:34 +00:00
|
|
|
mLockCount(0),
|
2010-09-08 00:33:02 +00:00
|
|
|
mAnimationConsumers(0),
|
2011-10-17 14:59:28 +00:00
|
|
|
mCanceled(false),
|
|
|
|
mIsInLoadGroup(false),
|
|
|
|
mListenerIsStrongRef(false),
|
|
|
|
mDecodeRequested(false),
|
2014-11-17 22:29:56 +00:00
|
|
|
mDeferNotifications(false)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
|
|
|
/* member initializers and constructor code */
|
2001-05-08 04:01:28 +00:00
|
|
|
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-02-20 23:27:48 +00:00
|
|
|
imgRequestProxy::~imgRequestProxy()
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
|
|
|
/* destructor code */
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_PRECONDITION(!mListener,
|
|
|
|
"Someone forgot to properly cancel this request!");
|
2008-12-19 22:35:50 +00:00
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
// Unlock the image the proper number of times if we're holding locks on
|
|
|
|
// it. Note that UnlockImage() decrements mLockCount each time it's called.
|
|
|
|
while (mLockCount) {
|
2010-05-14 20:47:59 +00:00
|
|
|
UnlockImage();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2010-09-08 00:33:02 +00:00
|
|
|
ClearAnimationConsumers();
|
|
|
|
|
2006-06-01 18:35:21 +00:00
|
|
|
// Explicitly set mListener to null to ensure that the RemoveProxy
|
|
|
|
// call below can't send |this| to an arbitrary listener while |this|
|
2008-03-19 19:07:59 +00:00
|
|
|
// is being destroyed. This is all belt-and-suspenders in view of the
|
|
|
|
// above assert.
|
|
|
|
NullOutListener();
|
2001-03-06 04:46:20 +00:00
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
if (GetOwner()) {
|
2012-10-22 16:44:53 +00:00
|
|
|
/* Call RemoveProxy with a successful status. This will keep the
|
|
|
|
channel, if still downloading data, from being canceled if 'this' is
|
|
|
|
the last observer. This allows the image to continue to download and
|
|
|
|
be cached even if no one is using it currently.
|
|
|
|
*/
|
|
|
|
mCanceled = true;
|
2012-10-19 19:39:38 +00:00
|
|
|
GetOwner()->RemoveProxy(this, NS_OK);
|
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
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
nsresult
|
|
|
|
imgRequestProxy::Init(imgRequest* aOwner,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
ImageURL* aURI,
|
|
|
|
imgINotificationObserver* aObserver)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_PRECONDITION(!GetOwner() && !mListener,
|
|
|
|
"imgRequestProxy is already initialized");
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
LOG_SCOPE_WITH_PARAM(GetImgLog(), "imgRequestProxy::Init", "request",
|
|
|
|
aOwner);
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(mAnimationConsumers == 0, "Cannot have animation before Init");
|
2010-09-08 00:33:02 +00:00
|
|
|
|
2012-12-19 21:28:54 +00:00
|
|
|
mBehaviour->SetOwner(aOwner);
|
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
|
|
|
mListener = aObserver;
|
2008-03-19 19:07:59 +00:00
|
|
|
// Make sure to addref mListener before the AddProxy call below, since
|
|
|
|
// that call might well want to release it if the imgRequest has
|
|
|
|
// already seen OnStopRequest.
|
|
|
|
if (mListener) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mListenerIsStrongRef = true;
|
2008-03-19 19:07:59 +00:00
|
|
|
NS_ADDREF(mListener);
|
|
|
|
}
|
2003-05-14 05:42:06 +00:00
|
|
|
mLoadGroup = aLoadGroup;
|
2010-05-11 03:27:41 +00:00
|
|
|
mURI = aURI;
|
2001-03-06 04:46:20 +00:00
|
|
|
|
2009-01-11 08:06:41 +00:00
|
|
|
// Note: AddProxy won't send all the On* notifications immediately
|
2015-03-25 17:59:00 +00:00
|
|
|
if (GetOwner()) {
|
2012-10-19 19:39:38 +00:00
|
|
|
GetOwner()->AddProxy(this);
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2002-01-15 05:23:33 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
nsresult
|
|
|
|
imgRequestProxy::ChangeOwner(imgRequest* aNewOwner)
|
2002-01-15 05:23:33 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_PRECONDITION(GetOwner(),
|
|
|
|
"Cannot ChangeOwner on a proxy without an owner!");
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2012-10-22 16:44:53 +00:00
|
|
|
if (mCanceled) {
|
2015-03-25 17:59:00 +00:00
|
|
|
// Ensure that this proxy has received all notifications to date
|
|
|
|
// before we clean it up when removing it from the old owner below.
|
2012-10-22 16:44:53 +00:00
|
|
|
SyncNotifyListener();
|
|
|
|
}
|
|
|
|
|
2010-05-14 20:47:59 +00:00
|
|
|
// If we're holding locks, unlock the old image.
|
2010-08-26 06:21:34 +00:00
|
|
|
// Note that UnlockImage decrements mLockCount each time it's called.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t oldLockCount = mLockCount;
|
2015-03-25 17:59:00 +00:00
|
|
|
while (mLockCount) {
|
2010-05-14 20:47:59 +00:00
|
|
|
UnlockImage();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2010-05-14 20:47:59 +00:00
|
|
|
|
2010-09-08 00:33:02 +00:00
|
|
|
// If we're holding animation requests, undo them.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t oldAnimationConsumers = mAnimationConsumers;
|
2010-09-08 00:33:02 +00:00
|
|
|
ClearAnimationConsumers();
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
// Were we decoded before?
|
2011-09-29 06:19:26 +00:00
|
|
|
bool wasDecoded = false;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 04:10:47 +00:00
|
|
|
if (progressTracker->HasImage() &&
|
2015-03-25 17:59:00 +00:00
|
|
|
progressTracker->GetImageStatus() &
|
|
|
|
imgIRequest::STATUS_FRAME_COMPLETE) {
|
2011-10-17 14:59:28 +00:00
|
|
|
wasDecoded = true;
|
2010-08-23 22:44:07 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
GetOwner()->RemoveProxy(this, NS_IMAGELIB_CHANGING_OWNER);
|
2012-10-22 16:44:53 +00:00
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
mBehaviour->SetOwner(aNewOwner);
|
2012-10-22 16:44:53 +00:00
|
|
|
|
|
|
|
// If we were locked, apply the locks here
|
2015-03-25 17:59:00 +00:00
|
|
|
for (uint32_t i = 0; i < oldLockCount; i++) {
|
2012-10-22 16:44:53 +00:00
|
|
|
LockImage();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2011-01-26 18:52:42 +00:00
|
|
|
// If we had animation requests, restore them here. Note that we
|
|
|
|
// do this *after* RemoveProxy, which clears out animation consumers
|
|
|
|
// (see bug 601723).
|
2015-03-25 17:59:00 +00:00
|
|
|
for (uint32_t i = 0; i < oldAnimationConsumers; i++) {
|
2011-01-26 18:52:42 +00:00
|
|
|
IncrementAnimationConsumers();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2011-01-26 18:52:42 +00:00
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
GetOwner()->AddProxy(this);
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2009-09-16 00:33:14 +00:00
|
|
|
// If we were decoded, or if we'd previously requested a decode, request a
|
|
|
|
// decode on the new image
|
2015-03-24 02:37:45 +00:00
|
|
|
if (wasDecoded || mDecodeRequested) {
|
|
|
|
StartDecoding();
|
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2001-02-20 22:43:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
void
|
|
|
|
imgRequestProxy::AddToLoadGroup()
|
2003-05-14 05:42:06 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mIsInLoadGroup, "Whaa, we're already in the loadgroup!");
|
|
|
|
|
|
|
|
if (!mIsInLoadGroup && mLoadGroup) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mLoadGroup->AddRequest(this, nullptr);
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsInLoadGroup = true;
|
2003-05-14 05:42:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
void
|
|
|
|
imgRequestProxy::RemoveFromLoadGroup(bool releaseLoadGroup)
|
2003-05-14 05:42:06 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (!mIsInLoadGroup) {
|
2003-05-14 05:42:06 +00:00
|
|
|
return;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2003-05-14 05:42:06 +00:00
|
|
|
|
|
|
|
/* calling RemoveFromLoadGroup may cause the document to finish
|
|
|
|
loading, which could result in our death. We need to make sure
|
|
|
|
that we stay alive long enough to fight another battle... at
|
|
|
|
least until we exit this function.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<imgIRequest> kungFuDeathGrip(this);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mLoadGroup->RemoveRequest(this, nullptr, NS_OK);
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsInLoadGroup = false;
|
2003-05-14 05:42:06 +00:00
|
|
|
|
2005-10-03 22:27:20 +00:00
|
|
|
if (releaseLoadGroup) {
|
|
|
|
// We're done with the loadgroup, release it.
|
2012-07-30 14:20:58 +00:00
|
|
|
mLoadGroup = nullptr;
|
2005-10-03 22:27:20 +00:00
|
|
|
}
|
2003-05-14 05:42:06 +00:00
|
|
|
}
|
|
|
|
|
2001-05-08 04:01:28 +00:00
|
|
|
|
2001-03-06 04:46:20 +00:00
|
|
|
/** nsIRequest / imgIRequest methods **/
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetName(nsACString& aName)
|
2001-03-06 04:46:20 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
aName.Truncate();
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
if (mURI) {
|
2010-05-11 03:27:41 +00:00
|
|
|
mURI->GetSpec(aName);
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
return NS_OK;
|
2001-03-06 04:46:20 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::IsPending(bool* _retval)
|
2001-03-06 04:46:20 +00:00
|
|
|
{
|
2006-11-09 22:47:43 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-03-06 04:46:20 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetStatus(nsresult* aStatus)
|
2001-03-06 04:46:20 +00:00
|
|
|
{
|
2009-01-30 19:13:52 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-03-06 04:46:20 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::Cancel(nsresult status)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (mCanceled) {
|
2001-02-22 02:06:24 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2001-02-22 02:06:24 +00:00
|
|
|
|
2012-10-29 23:32:10 +00:00
|
|
|
LOG_SCOPE(GetImgLog(), "imgRequestProxy::Cancel");
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mCanceled = true;
|
2001-03-25 11:57:25 +00:00
|
|
|
|
2008-12-19 22:35:50 +00:00
|
|
|
nsCOMPtr<nsIRunnable> ev = new imgCancelRunnable(this, status);
|
|
|
|
return NS_DispatchToCurrentThread(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgRequestProxy::DoCancel(nsresult status)
|
|
|
|
{
|
2012-10-19 19:39:38 +00:00
|
|
|
if (GetOwner()) {
|
|
|
|
GetOwner()->RemoveProxy(this, status);
|
2012-10-11 16:35:43 +00:00
|
|
|
}
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2008-03-19 19:07:59 +00:00
|
|
|
NullOutListener();
|
2008-12-19 22:35:50 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::CancelAndForgetObserver(nsresult aStatus)
|
2008-12-19 22:35:50 +00:00
|
|
|
{
|
2011-10-14 20:15:56 +00:00
|
|
|
// If mCanceled is true but mListener is non-null, that means
|
|
|
|
// someone called Cancel() on us but the imgCancelRunnable is still
|
|
|
|
// pending. We still need to null out mListener before returning
|
|
|
|
// from this function in this case. That means we want to do the
|
|
|
|
// RemoveProxy call right now, because we need to deliver the
|
|
|
|
// onStopRequest.
|
2015-03-25 17:59:00 +00:00
|
|
|
if (mCanceled && !mListener) {
|
2008-12-19 22:35:50 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2008-12-19 22:35:50 +00:00
|
|
|
|
2012-10-29 23:32:10 +00:00
|
|
|
LOG_SCOPE(GetImgLog(), "imgRequestProxy::CancelAndForgetObserver");
|
2008-12-19 22:35:50 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mCanceled = true;
|
2008-12-19 22:35:50 +00:00
|
|
|
|
2010-03-08 19:34:52 +00:00
|
|
|
// Now cheat and make sure our removal from loadgroup happens async
|
2011-09-29 06:19:26 +00:00
|
|
|
bool oldIsInLoadGroup = mIsInLoadGroup;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsInLoadGroup = false;
|
2010-05-14 20:47:59 +00:00
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
if (GetOwner()) {
|
|
|
|
GetOwner()->RemoveProxy(this, aStatus);
|
2012-10-11 16:35:43 +00:00
|
|
|
}
|
2008-12-19 22:35:50 +00:00
|
|
|
|
2010-03-08 19:34:52 +00:00
|
|
|
mIsInLoadGroup = oldIsInLoadGroup;
|
|
|
|
|
|
|
|
if (mIsInLoadGroup) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2010-04-20 23:21:35 +00:00
|
|
|
NS_NewRunnableMethod(this, &imgRequestProxy::DoRemoveFromLoadGroup);
|
2010-03-08 19:34:52 +00:00
|
|
|
NS_DispatchToCurrentThread(ev);
|
|
|
|
}
|
|
|
|
|
2008-12-19 22:35:50 +00:00
|
|
|
NullOutListener();
|
2006-06-01 18:35:21 +00:00
|
|
|
|
2001-04-13 05:37:29 +00:00
|
|
|
return NS_OK;
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2012-10-04 20:02:15 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::StartDecoding()
|
|
|
|
{
|
|
|
|
// Flag this, so we know to transfer the request if our owner changes
|
|
|
|
mDecodeRequested = true;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-24 02:37:45 +00:00
|
|
|
if (image) {
|
|
|
|
return image->StartDecoding();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetOwner()) {
|
|
|
|
GetOwner()->RequestDecode();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-10-04 20:02:15 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::RequestDecode()
|
|
|
|
{
|
2009-09-16 00:33:14 +00:00
|
|
|
// Flag this, so we know to transfer the request if our owner changes
|
2011-10-17 14:59:28 +00:00
|
|
|
mDecodeRequested = true;
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-24 02:37:45 +00:00
|
|
|
if (image) {
|
|
|
|
return image->RequestDecode();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetOwner()) {
|
|
|
|
GetOwner()->RequestDecode();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2009-09-12 22:44:18 +00:00
|
|
|
}
|
|
|
|
|
2012-10-04 20:02:15 +00:00
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::LockImage()
|
|
|
|
{
|
2010-08-26 06:21:34 +00:00
|
|
|
mLockCount++;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-25 17:59:00 +00:00
|
|
|
if (image) {
|
2013-09-28 18:28:44 +00:00
|
|
|
return image->LockImage();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2010-08-26 06:21:34 +00:00
|
|
|
return NS_OK;
|
2009-09-12 22:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::UnlockImage()
|
|
|
|
{
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "calling unlock but no locks!");
|
2010-05-14 20:47:59 +00:00
|
|
|
|
2010-08-26 06:21:34 +00:00
|
|
|
mLockCount--;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-25 17:59:00 +00:00
|
|
|
if (image) {
|
2013-09-28 18:28:44 +00:00
|
|
|
return image->UnlockImage();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2010-08-26 06:21:34 +00:00
|
|
|
return NS_OK;
|
2009-09-12 22:44:18 +00:00
|
|
|
}
|
|
|
|
|
2012-03-10 06:29:28 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::RequestDiscard()
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-25 17:59:00 +00:00
|
|
|
if (image) {
|
2013-09-28 18:28:44 +00:00
|
|
|
return image->RequestDiscard();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2012-03-10 06:29:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-08 00:33:02 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::IncrementAnimationConsumers()
|
|
|
|
{
|
|
|
|
mAnimationConsumers++;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-25 17:59:00 +00:00
|
|
|
if (image) {
|
2013-09-28 18:28:44 +00:00
|
|
|
image->IncrementAnimationConsumers();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2010-09-08 00:33:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::DecrementAnimationConsumers()
|
|
|
|
{
|
|
|
|
// We may get here if some responsible code called Increment,
|
|
|
|
// then called us, but we have meanwhile called ClearAnimationConsumers
|
|
|
|
// because we needed to get rid of them earlier (see
|
|
|
|
// imgRequest::RemoveProxy), and hence have nothing left to
|
|
|
|
// decrement. (In such a case we got rid of the animation consumers
|
|
|
|
// early, but not the observer.)
|
|
|
|
if (mAnimationConsumers > 0) {
|
|
|
|
mAnimationConsumers--;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-25 17:59:00 +00:00
|
|
|
if (image) {
|
2013-09-28 18:28:44 +00:00
|
|
|
image->DecrementAnimationConsumers();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2010-09-08 00:33:02 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgRequestProxy::ClearAnimationConsumers()
|
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
while (mAnimationConsumers > 0) {
|
2010-09-08 00:33:02 +00:00
|
|
|
DecrementAnimationConsumers();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2010-09-08 00:33:02 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::Suspend()
|
2001-03-06 04:46:20 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::Resume()
|
2001-03-06 04:46:20 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetLoadGroup(nsILoadGroup** loadGroup)
|
2001-04-10 06:01:08 +00:00
|
|
|
{
|
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
|
|
|
NS_IF_ADDREF(*loadGroup = mLoadGroup.get());
|
|
|
|
return NS_OK;
|
2001-04-10 06:01:08 +00:00
|
|
|
}
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::SetLoadGroup(nsILoadGroup* loadGroup)
|
2001-04-10 06:01:08 +00:00
|
|
|
{
|
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
|
|
|
mLoadGroup = loadGroup;
|
|
|
|
return NS_OK;
|
2001-04-10 06:01:08 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetLoadFlags(nsLoadFlags* flags)
|
2001-04-10 06:01:08 +00:00
|
|
|
{
|
2001-07-17 01:14:40 +00:00
|
|
|
*flags = mLoadFlags;
|
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
|
|
|
return NS_OK;
|
2001-04-10 06:01:08 +00:00
|
|
|
}
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::SetLoadFlags(nsLoadFlags flags)
|
2001-04-10 06:01:08 +00:00
|
|
|
{
|
2001-07-17 01:14:40 +00:00
|
|
|
mLoadFlags = flags;
|
|
|
|
return NS_OK;
|
2001-04-10 06:01:08 +00:00
|
|
|
}
|
|
|
|
|
2001-03-06 04:46:20 +00:00
|
|
|
/** imgIRequest methods **/
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImage(imgIContainer** aImage)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2013-09-28 18:28:44 +00:00
|
|
|
NS_ENSURE_TRUE(aImage, NS_ERROR_NULL_POINTER);
|
2010-08-23 22:44:07 +00:00
|
|
|
// It's possible that our owner has an image but hasn't notified us of it -
|
|
|
|
// that'll happen if we get Canceled before the owner instantiates its image
|
|
|
|
// (because Canceling unregisters us as a listener on mOwner). If we're
|
|
|
|
// in that situation, just grab the image off of mOwner.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = GetImage();
|
2013-09-28 18:28:44 +00:00
|
|
|
nsCOMPtr<imgIContainer> imageToReturn;
|
2015-03-24 02:37:45 +00:00
|
|
|
if (image) {
|
2013-09-28 18:28:44 +00:00
|
|
|
imageToReturn = do_QueryInterface(image);
|
2015-03-24 02:37:45 +00:00
|
|
|
}
|
|
|
|
if (!imageToReturn && GetOwner()) {
|
|
|
|
imageToReturn = GetOwner()->GetImage();
|
|
|
|
}
|
|
|
|
if (!imageToReturn) {
|
2001-03-25 11:57:25 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-24 02:37:45 +00:00
|
|
|
}
|
2001-03-25 11:57:25 +00:00
|
|
|
|
2013-09-28 18:28:44 +00:00
|
|
|
imageToReturn.swap(*aImage);
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
return NS_OK;
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImageStatus(uint32_t* aStatus)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 04:10:47 +00:00
|
|
|
*aStatus = progressTracker->GetImageStatus();
|
2001-03-25 11:57:25 +00:00
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
return NS_OK;
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImageErrorCode(nsresult* aStatus)
|
2014-07-19 01:47:11 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (!GetOwner()) {
|
2014-07-19 01:47:11 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2014-07-19 01:47:11 +00:00
|
|
|
|
|
|
|
*aStatus = GetOwner()->GetImageErrorCode();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetURI(nsIURI** aURI)
|
2013-09-28 18:28:42 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread to convert URI");
|
|
|
|
nsCOMPtr<nsIURI> uri = mURI->ToIURI();
|
|
|
|
uri.forget(aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
nsresult
|
|
|
|
imgRequestProxy::GetCurrentURI(nsIURI** aURI)
|
2014-11-10 22:06:24 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (!GetOwner()) {
|
2014-11-10 22:06:24 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2014-11-10 22:06:24 +00:00
|
|
|
|
|
|
|
return GetOwner()->GetCurrentURI(aURI);
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
nsresult
|
|
|
|
imgRequestProxy::GetURI(ImageURL** aURI)
|
2001-02-22 02:06:24 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (!mURI) {
|
2001-03-25 11:57:25 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2001-03-25 11:57:25 +00:00
|
|
|
|
2010-05-11 03:27:41 +00:00
|
|
|
NS_ADDREF(*aURI = mURI);
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-02-22 02:06:24 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetNotificationObserver(imgINotificationObserver** aObserver)
|
2001-03-22 23:16:52 +00:00
|
|
|
{
|
2012-10-12 16:11:22 +00:00
|
|
|
*aObserver = mListener;
|
|
|
|
NS_IF_ADDREF(*aObserver);
|
2001-03-22 23:16:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetMimeType(char** aMimeType)
|
2001-10-12 07:59:21 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (!GetOwner()) {
|
2001-10-12 07:59:21 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2001-10-12 07:59:21 +00:00
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
const char* type = GetOwner()->GetMimeType();
|
|
|
|
if (!type) {
|
2001-10-12 07:59:21 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2001-10-12 07:59:21 +00:00
|
|
|
|
2009-03-29 11:46:12 +00:00
|
|
|
*aMimeType = NS_strdup(type);
|
2001-10-12 07:59:21 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-12 16:11:22 +00:00
|
|
|
static imgRequestProxy* NewProxy(imgRequestProxy* /*aThis*/)
|
|
|
|
{
|
|
|
|
return new imgRequestProxy();
|
|
|
|
}
|
|
|
|
|
|
|
|
imgRequestProxy* NewStaticProxy(imgRequestProxy* aThis)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrincipal> currentPrincipal;
|
|
|
|
aThis->GetImagePrincipal(getter_AddRefs(currentPrincipal));
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = aThis->GetImage();
|
2013-09-28 18:28:44 +00:00
|
|
|
return new imgRequestProxyStatic(image, currentPrincipal);
|
2012-10-12 16:11:22 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::Clone(imgINotificationObserver* aObserver,
|
|
|
|
imgIRequest** aClone)
|
2012-10-12 12:43:01 +00:00
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
imgRequestProxy* proxy;
|
|
|
|
result = Clone(aObserver, &proxy);
|
|
|
|
*aClone = proxy;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult imgRequestProxy::Clone(imgINotificationObserver* aObserver,
|
|
|
|
imgRequestProxy** aClone)
|
2012-10-12 16:11:22 +00:00
|
|
|
{
|
|
|
|
return PerformClone(aObserver, NewProxy, aClone);
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
nsresult
|
|
|
|
imgRequestProxy::PerformClone(imgINotificationObserver* aObserver,
|
|
|
|
imgRequestProxy* (aAllocFn)(imgRequestProxy*),
|
|
|
|
imgRequestProxy** aClone)
|
2004-03-09 03:57:51 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aClone, "Null out param");
|
2010-05-14 20:47:59 +00:00
|
|
|
|
2012-10-29 23:32:10 +00:00
|
|
|
LOG_SCOPE(GetImgLog(), "imgRequestProxy::Clone");
|
2010-05-14 20:47:59 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*aClone = nullptr;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequestProxy> clone = aAllocFn(this);
|
2004-03-09 03:57:51 +00:00
|
|
|
|
|
|
|
// It is important to call |SetLoadFlags()| before calling |Init()| because
|
|
|
|
// |Init()| adds the request to the loadgroup.
|
2006-06-01 18:35:21 +00:00
|
|
|
// When a request is added to a loadgroup, its load flags are merged
|
|
|
|
// with the load flags of the loadgroup.
|
|
|
|
// XXXldb That's not true anymore. Stuff from imgLoader adds the
|
|
|
|
// request to the loadgroup.
|
2004-03-09 03:57:51 +00:00
|
|
|
clone->SetLoadFlags(mLoadFlags);
|
2015-03-25 17:59:00 +00:00
|
|
|
nsresult rv = clone->Init(mBehaviour->GetOwner(), mLoadGroup,
|
|
|
|
mURI, aObserver);
|
|
|
|
if (NS_FAILED(rv)) {
|
2004-03-09 03:57:51 +00:00
|
|
|
return rv;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2004-03-09 03:57:51 +00:00
|
|
|
|
2015-04-10 06:15:39 +00:00
|
|
|
if (GetOwner() && GetOwner()->GetValidator()) {
|
|
|
|
clone->SetNotificationsDeferred(true);
|
|
|
|
GetOwner()->GetValidator()->AddProxy(clone);
|
|
|
|
}
|
|
|
|
|
2010-05-11 03:27:41 +00:00
|
|
|
// Assign to *aClone before calling Notify so that if the caller expects to
|
|
|
|
// only be notified for requests it's already holding pointers to it won't be
|
|
|
|
// surprised.
|
2010-05-14 20:47:59 +00:00
|
|
|
NS_ADDREF(*aClone = clone);
|
2004-09-20 22:46:22 +00:00
|
|
|
|
2010-07-28 21:52:14 +00:00
|
|
|
// This is wrong!!! We need to notify asynchronously, but there's code that
|
|
|
|
// assumes that we don't. This will be fixed in bug 580466.
|
|
|
|
clone->SyncNotifyListener();
|
2004-03-09 03:57:51 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-22 23:16:52 +00:00
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImagePrincipal(nsIPrincipal** aPrincipal)
|
2007-11-09 02:55:41 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (!GetOwner()) {
|
2007-11-09 02:55:41 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2007-11-09 02:55:41 +00:00
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
NS_ADDREF(*aPrincipal = GetOwner()->GetPrincipal());
|
2010-05-11 03:27:41 +00:00
|
|
|
return NS_OK;
|
2007-11-09 02:55:41 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetMultipart(bool* aMultipart)
|
2012-05-19 19:32:37 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (!GetOwner()) {
|
2012-05-19 19:32:37 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2012-05-19 19:32:37 +00:00
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
*aMultipart = GetOwner()->GetMultipart();
|
2012-05-19 19:32:37 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetCORSMode(int32_t* aCorsMode)
|
2011-07-14 18:47:34 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (!GetOwner()) {
|
2011-07-14 18:47:34 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2011-07-14 18:47:34 +00:00
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
*aCorsMode = GetOwner()->GetCORSMode();
|
2011-07-14 18:47:34 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-21 20:58:01 +00:00
|
|
|
/** nsISupportsPriority methods **/
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetPriority(int32_t* priority)
|
2005-02-21 20:58:01 +00:00
|
|
|
{
|
2012-10-19 19:39:38 +00:00
|
|
|
NS_ENSURE_STATE(GetOwner());
|
|
|
|
*priority = GetOwner()->Priority();
|
2005-02-21 20:58:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::SetPriority(int32_t priority)
|
2005-02-21 20:58:01 +00:00
|
|
|
{
|
2012-10-19 19:39:38 +00:00
|
|
|
NS_ENSURE_STATE(GetOwner() && !mCanceled);
|
|
|
|
GetOwner()->AdjustPriority(this, priority - GetOwner()->Priority());
|
2005-02-21 20:58:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::AdjustPriority(int32_t priority)
|
2005-02-21 20:58:01 +00:00
|
|
|
{
|
2013-02-16 01:00:03 +00:00
|
|
|
// We don't require |!mCanceled| here. This may be called even if we're
|
|
|
|
// cancelled, because it's invoked as part of the process of removing an image
|
|
|
|
// from the load group.
|
|
|
|
NS_ENSURE_STATE(GetOwner());
|
2012-10-19 19:39:38 +00:00
|
|
|
GetOwner()->AdjustPriority(this, priority);
|
2005-02-21 20:58:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-01 20:53:59 +00:00
|
|
|
/** nsISecurityInfoProvider methods **/
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetSecurityInfo(nsISupports** _retval)
|
2008-09-01 20:53:59 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (GetOwner()) {
|
2012-10-19 19:39:38 +00:00
|
|
|
return GetOwner()->GetSecurityInfo(_retval);
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2008-09-01 20:53:59 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2008-09-01 20:53:59 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetHasTransferredData(bool* hasData)
|
2009-02-16 14:11:30 +00:00
|
|
|
{
|
2012-10-19 19:39:38 +00:00
|
|
|
if (GetOwner()) {
|
|
|
|
*hasData = GetOwner()->HasTransferredData();
|
2009-02-16 14:11:30 +00:00
|
|
|
} else {
|
|
|
|
// The safe thing to do is to claim we have data
|
2011-10-17 14:59:28 +00:00
|
|
|
*hasData = true;
|
2009-02-16 14:11:30 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-07 09:35:20 +00:00
|
|
|
static const char*
|
|
|
|
NotificationTypeToString(int32_t aType)
|
|
|
|
{
|
|
|
|
switch(aType)
|
|
|
|
{
|
|
|
|
case imgINotificationObserver::SIZE_AVAILABLE: return "SIZE_AVAILABLE";
|
|
|
|
case imgINotificationObserver::FRAME_UPDATE: return "FRAME_UPDATE";
|
|
|
|
case imgINotificationObserver::FRAME_COMPLETE: return "FRAME_COMPLETE";
|
|
|
|
case imgINotificationObserver::LOAD_COMPLETE: return "LOAD_COMPLETE";
|
|
|
|
case imgINotificationObserver::DECODE_COMPLETE: return "DECODE_COMPLETE";
|
|
|
|
case imgINotificationObserver::DISCARD: return "DISCARD";
|
|
|
|
case imgINotificationObserver::UNLOCKED_DRAW: return "UNLOCKED_DRAW";
|
|
|
|
case imgINotificationObserver::IS_ANIMATED: return "IS_ANIMATED";
|
|
|
|
case imgINotificationObserver::HAS_TRANSPARENCY: return "HAS_TRANSPARENCY";
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Notification list should be exhaustive");
|
|
|
|
return "(unknown notification)";
|
2003-03-17 16:09:02 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 09:35:20 +00:00
|
|
|
void
|
2015-04-21 15:04:57 +00:00
|
|
|
imgRequestProxy::Notify(int32_t aType, const mozilla::gfx::IntRect* aRect)
|
2009-09-12 22:44:18 +00:00
|
|
|
{
|
2015-01-07 09:35:20 +00:00
|
|
|
MOZ_ASSERT(aType != imgINotificationObserver::LOAD_COMPLETE,
|
|
|
|
"Should call OnLoadComplete");
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2015-01-07 09:35:20 +00:00
|
|
|
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::Notify", "type",
|
|
|
|
NotificationTypeToString(aType));
|
2013-02-25 00:59:22 +00:00
|
|
|
|
2015-01-07 09:35:20 +00:00
|
|
|
if (!mListener || mCanceled) {
|
|
|
|
return;
|
2013-02-25 00:59:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 09:35:20 +00:00
|
|
|
// Make sure the listener stays alive while we notify.
|
|
|
|
nsCOMPtr<imgINotificationObserver> listener(mListener);
|
2014-11-17 19:16:45 +00:00
|
|
|
|
2015-01-07 09:35:20 +00:00
|
|
|
mListener->Notify(this, aType, aRect);
|
2011-11-09 21:39:15 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 09:35:20 +00:00
|
|
|
void
|
|
|
|
imgRequestProxy::OnLoadComplete(bool aLastPart)
|
2001-03-06 04:46:20 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
|
2015-05-11 20:42:30 +00:00
|
|
|
nsAutoCString name;
|
|
|
|
GetName(name);
|
|
|
|
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::OnLoadComplete",
|
|
|
|
"name", name.get());
|
|
|
|
}
|
|
|
|
|
2008-03-21 06:13:11 +00:00
|
|
|
// There's all sorts of stuff here that could kill us (the OnStopRequest call
|
|
|
|
// on the listener, the removal from the loadgroup, the release of the
|
|
|
|
// listener, etc). Don't let them do it.
|
|
|
|
nsCOMPtr<imgIRequest> kungFuDeathGrip(this);
|
2001-04-09 00:45:06 +00:00
|
|
|
|
2013-02-13 19:57:16 +00:00
|
|
|
if (mListener && !mCanceled) {
|
2006-06-01 18:35:21 +00:00
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
2012-10-12 16:11:22 +00:00
|
|
|
nsCOMPtr<imgINotificationObserver> kungFuDeathGrip(mListener);
|
2012-10-12 16:11:23 +00:00
|
|
|
mListener->Notify(this, imgINotificationObserver::LOAD_COMPLETE, nullptr);
|
2005-10-03 22:27:20 +00:00
|
|
|
}
|
|
|
|
|
2006-06-01 18:35:21 +00:00
|
|
|
// If we're expecting more data from a multipart channel, re-add ourself
|
|
|
|
// to the loadgroup so that the document doesn't lose track of the load.
|
2005-10-03 22:27:20 +00:00
|
|
|
// If the request is already a background request and there's more data
|
|
|
|
// coming, we can just leave the request in the loadgroup as-is.
|
2014-11-17 22:29:56 +00:00
|
|
|
if (aLastPart || (mLoadFlags & nsIRequest::LOAD_BACKGROUND) == 0) {
|
|
|
|
RemoveFromLoadGroup(aLastPart);
|
2005-10-03 22:27:20 +00:00
|
|
|
// More data is coming, so change the request to be a background request
|
|
|
|
// and put it back in the loadgroup.
|
2014-11-17 22:29:56 +00:00
|
|
|
if (!aLastPart) {
|
2005-10-03 22:27:20 +00:00
|
|
|
mLoadFlags |= nsIRequest::LOAD_BACKGROUND;
|
|
|
|
AddToLoadGroup();
|
|
|
|
}
|
|
|
|
}
|
2008-03-19 19:07:59 +00:00
|
|
|
|
2014-11-17 22:29:56 +00:00
|
|
|
if (mListenerIsStrongRef && aLastPart) {
|
2008-03-19 19:07:59 +00:00
|
|
|
NS_PRECONDITION(mListener, "How did that happen?");
|
|
|
|
// Drop our strong ref to the listener now that we're done with
|
|
|
|
// everything. Note that this can cancel us and other fun things
|
|
|
|
// like that. Don't add anything in this method after this point.
|
2012-10-12 16:11:22 +00:00
|
|
|
imgINotificationObserver* obs = mListener;
|
2011-10-17 14:59:28 +00:00
|
|
|
mListenerIsStrongRef = false;
|
2008-03-19 19:07:59 +00:00
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
2001-03-06 04:46:20 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 09:35:20 +00:00
|
|
|
void
|
|
|
|
imgRequestProxy::BlockOnload()
|
2012-08-13 22:58:53 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
|
2015-05-11 20:42:30 +00:00
|
|
|
nsAutoCString name;
|
|
|
|
GetName(name);
|
|
|
|
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::BlockOnload",
|
|
|
|
"name", name.get());
|
|
|
|
}
|
2012-08-13 22:58:53 +00:00
|
|
|
|
|
|
|
nsCOMPtr<imgIOnloadBlocker> blocker = do_QueryInterface(mListener);
|
|
|
|
if (blocker) {
|
|
|
|
blocker->BlockOnload(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-07 09:35:20 +00:00
|
|
|
void
|
|
|
|
imgRequestProxy::UnblockOnload()
|
2012-08-13 22:58:53 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
if (MOZ_LOG_TEST(GetImgLog(), LogLevel::Debug)) {
|
2015-05-11 20:42:30 +00:00
|
|
|
nsAutoCString name;
|
|
|
|
GetName(name);
|
|
|
|
LOG_FUNC_WITH_PARAM(GetImgLog(), "imgRequestProxy::UnblockOnload",
|
|
|
|
"name", name.get());
|
|
|
|
}
|
2012-08-13 22:58:53 +00:00
|
|
|
|
|
|
|
nsCOMPtr<imgIOnloadBlocker> blocker = do_QueryInterface(mListener);
|
|
|
|
if (blocker) {
|
|
|
|
blocker->UnblockOnload(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
void
|
|
|
|
imgRequestProxy::NullOutListener()
|
2008-03-19 19:07:59 +00:00
|
|
|
{
|
2010-09-08 00:33:02 +00:00
|
|
|
// If we have animation consumers, then they don't matter anymore
|
2015-03-25 17:59:00 +00:00
|
|
|
if (mListener) {
|
2010-09-08 00:33:02 +00:00
|
|
|
ClearAnimationConsumers();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2010-09-08 00:33:02 +00:00
|
|
|
|
2008-03-19 19:07:59 +00:00
|
|
|
if (mListenerIsStrongRef) {
|
|
|
|
// Releasing could do weird reentery stuff, so just play it super-safe
|
2012-10-12 16:11:22 +00:00
|
|
|
nsCOMPtr<imgINotificationObserver> obs;
|
2008-03-19 19:07:59 +00:00
|
|
|
obs.swap(mListener);
|
2011-10-17 14:59:28 +00:00
|
|
|
mListenerIsStrongRef = false;
|
2008-03-19 19:07:59 +00:00
|
|
|
} else {
|
2012-07-30 14:20:58 +00:00
|
|
|
mListener = nullptr;
|
2008-03-19 19:07:59 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-11 04:02:13 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetStaticRequest(imgIRequest** aReturn)
|
2012-10-12 12:43:01 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
imgRequestProxy* proxy;
|
2012-10-12 12:43:01 +00:00
|
|
|
nsresult result = GetStaticRequest(&proxy);
|
|
|
|
*aReturn = proxy;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
imgRequestProxy::GetStaticRequest(imgRequestProxy** aReturn)
|
2009-12-11 04:02:13 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aReturn = nullptr;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = GetImage();
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool animated;
|
2012-10-12 16:11:21 +00:00
|
|
|
if (!image || (NS_SUCCEEDED(image->GetAnimated(&animated)) && !animated)) {
|
2010-05-11 03:27:41 +00:00
|
|
|
// Early exit - we're not animated, so we don't have to do anything.
|
|
|
|
NS_ADDREF(*aReturn = this);
|
|
|
|
return NS_OK;
|
2009-12-11 04:02:13 +00:00
|
|
|
}
|
|
|
|
|
2013-03-11 01:43:38 +00:00
|
|
|
// Check for errors in the image. Callers code rely on GetStaticRequest
|
|
|
|
// failing in this case, though with FrozenImage there's no technical reason
|
|
|
|
// for it anymore.
|
|
|
|
if (image->HasError()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-05-14 20:47:59 +00:00
|
|
|
|
2013-03-11 01:43:38 +00:00
|
|
|
// We are animated. We need to create a frozen version of this image.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> frozenImage = ImageOps::Freeze(image);
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2010-05-14 20:47:59 +00:00
|
|
|
// Create a static imgRequestProxy with our new extracted frame.
|
2012-10-12 16:11:20 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> currentPrincipal;
|
|
|
|
GetImagePrincipal(getter_AddRefs(currentPrincipal));
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<imgRequestProxy> req = new imgRequestProxyStatic(frozenImage,
|
2013-03-11 01:43:38 +00:00
|
|
|
currentPrincipal);
|
2012-12-19 21:28:54 +00:00
|
|
|
req->Init(nullptr, nullptr, mURI, nullptr);
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2009-12-11 04:02:13 +00:00
|
|
|
NS_ADDREF(*aReturn = req);
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2009-12-11 04:02:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
void
|
|
|
|
imgRequestProxy::NotifyListener()
|
2010-05-11 03:27:41 +00:00
|
|
|
{
|
2010-07-28 21:52:14 +00:00
|
|
|
// It would be nice to notify the observer directly in the status tracker
|
|
|
|
// instead of through the proxy, but there are several places we do extra
|
|
|
|
// processing when we receive notifications (like OnStopRequest()), and we
|
|
|
|
// need to check mCanceled everywhere too.
|
2010-05-11 03:27:41 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2012-10-19 19:39:38 +00:00
|
|
|
if (GetOwner()) {
|
2010-07-28 21:52:14 +00:00
|
|
|
// Send the notifications to our listener asynchronously.
|
2014-11-15 04:10:47 +00:00
|
|
|
progressTracker->Notify(this);
|
2010-07-28 21:52:14 +00:00
|
|
|
} else {
|
|
|
|
// We don't have an imgRequest, so we can only notify the clone of our
|
|
|
|
// current state, but we still have to do that asynchronously.
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(HasImage(),
|
|
|
|
"if we have no imgRequest, we should have an Image");
|
2014-11-15 04:10:47 +00:00
|
|
|
progressTracker->NotifyCurrentState(this);
|
2010-07-28 21:52:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
void
|
|
|
|
imgRequestProxy::SyncNotifyListener()
|
2010-07-28 21:52:14 +00:00
|
|
|
{
|
|
|
|
// It would be nice to notify the observer directly in the status tracker
|
|
|
|
// instead of through the proxy, but there are several places we do extra
|
|
|
|
// processing when we receive notifications (like OnStopRequest()), and we
|
|
|
|
// need to check mCanceled everywhere too.
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 04:10:47 +00:00
|
|
|
progressTracker->SyncNotify(this);
|
2010-08-23 22:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-12 16:11:21 +00:00
|
|
|
imgRequestProxy::SetHasImage()
|
2010-08-23 22:44:07 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 04:10:47 +00:00
|
|
|
MOZ_ASSERT(progressTracker);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Image> image = progressTracker->GetImage();
|
2013-09-28 18:28:44 +00:00
|
|
|
MOZ_ASSERT(image);
|
2010-08-23 22:44:07 +00:00
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
// Force any private status related to the owner to reflect
|
|
|
|
// the presence of an image;
|
|
|
|
mBehaviour->SetOwner(mBehaviour->GetOwner());
|
2010-08-23 22:44:07 +00:00
|
|
|
|
2010-08-26 06:21:34 +00:00
|
|
|
// Apply any locks we have
|
2015-03-25 17:59:00 +00:00
|
|
|
for (uint32_t i = 0; i < mLockCount; ++i) {
|
2012-10-12 16:11:21 +00:00
|
|
|
image->LockImage();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2010-09-08 00:33:02 +00:00
|
|
|
|
|
|
|
// Apply any animation consumers we have
|
2015-03-25 17:59:00 +00:00
|
|
|
for (uint32_t i = 0; i < mAnimationConsumers; i++) {
|
2012-10-12 16:11:21 +00:00
|
|
|
image->IncrementAnimationConsumers();
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2010-08-23 22:44:07 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
already_AddRefed<ProgressTracker>
|
|
|
|
imgRequestProxy::GetProgressTracker() const
|
2010-08-23 22:44:07 +00:00
|
|
|
{
|
2014-11-15 04:10:47 +00:00
|
|
|
return mBehaviour->GetProgressTracker();
|
2012-10-12 16:11:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-28 18:28:44 +00:00
|
|
|
already_AddRefed<mozilla::image::Image>
|
2012-10-12 16:11:21 +00:00
|
|
|
imgRequestProxy::GetImage() const
|
|
|
|
{
|
2012-10-19 19:39:38 +00:00
|
|
|
return mBehaviour->GetImage();
|
|
|
|
}
|
|
|
|
|
2013-09-28 18:28:44 +00:00
|
|
|
bool
|
|
|
|
RequestBehaviour::HasImage() const
|
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (!mOwnerHasImage) {
|
2013-09-28 18:28:44 +00:00
|
|
|
return false;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 04:10:47 +00:00
|
|
|
return progressTracker ? progressTracker->HasImage() : false;
|
2013-09-28 18:28:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
imgRequestProxy::HasImage() const
|
|
|
|
{
|
|
|
|
return mBehaviour->HasImage();
|
|
|
|
}
|
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
imgRequest*
|
|
|
|
imgRequestProxy::GetOwner() const
|
|
|
|
{
|
|
|
|
return mBehaviour->GetOwner();
|
2012-10-12 01:34:23 +00:00
|
|
|
}
|
2012-10-12 16:11:20 +00:00
|
|
|
|
|
|
|
////////////////// imgRequestProxyStatic methods
|
|
|
|
|
2012-10-19 19:39:38 +00:00
|
|
|
class StaticBehaviour : public ProxyBehaviour
|
2012-10-12 16:11:20 +00:00
|
|
|
{
|
2012-10-19 19:39:38 +00:00
|
|
|
public:
|
2014-09-02 16:20:24 +00:00
|
|
|
explicit StaticBehaviour(mozilla::image::Image* aImage) : mImage(aImage) {}
|
2012-10-12 16:11:20 +00:00
|
|
|
|
2013-09-28 18:28:44 +00:00
|
|
|
virtual already_AddRefed<mozilla::image::Image>
|
2015-03-21 16:28:04 +00:00
|
|
|
GetImage() const override {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::image::Image> image = mImage;
|
2013-09-28 18:28:44 +00:00
|
|
|
return image.forget();
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool HasImage() const override {
|
2012-10-19 19:39:38 +00:00
|
|
|
return mImage;
|
|
|
|
}
|
2012-10-12 16:11:20 +00:00
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
virtual already_AddRefed<ProgressTracker> GetProgressTracker()
|
|
|
|
const override {
|
2014-11-15 04:10:47 +00:00
|
|
|
return mImage->GetProgressTracker();
|
2012-10-19 19:39:38 +00:00
|
|
|
}
|
2012-10-12 16:11:21 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual imgRequest* GetOwner() const override {
|
2012-10-19 19:39:38 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void SetOwner(imgRequest* aOwner) override {
|
2015-03-25 17:59:00 +00:00
|
|
|
MOZ_ASSERT(!aOwner,
|
|
|
|
"We shouldn't be giving static requests a non-null owner.");
|
2012-10-19 19:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Our image. We have to hold a strong reference here, because that's normally
|
|
|
|
// the job of the underlying request.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::image::Image> mImage;
|
2012-10-19 19:39:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
imgRequestProxyStatic::imgRequestProxyStatic(mozilla::image::Image* aImage,
|
|
|
|
nsIPrincipal* aPrincipal)
|
|
|
|
: mPrincipal(aPrincipal)
|
2012-10-12 16:11:21 +00:00
|
|
|
{
|
2015-10-17 10:53:28 +00:00
|
|
|
mBehaviour = mozilla::MakeUnique<StaticBehaviour>(aImage);
|
2012-10-12 16:11:21 +00:00
|
|
|
}
|
2012-10-12 16:11:21 +00:00
|
|
|
|
2015-03-25 17:59:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxyStatic::GetImagePrincipal(nsIPrincipal** aPrincipal)
|
2012-10-12 16:11:21 +00:00
|
|
|
{
|
2015-03-25 17:59:00 +00:00
|
|
|
if (!mPrincipal) {
|
2012-10-19 19:39:38 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 17:59:00 +00:00
|
|
|
}
|
2012-10-19 19:39:38 +00:00
|
|
|
|
|
|
|
NS_ADDREF(*aPrincipal = mPrincipal);
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-10-12 16:11:21 +00:00
|
|
|
}
|
2012-10-12 16:11:22 +00:00
|
|
|
|
2013-06-04 18:38:37 +00:00
|
|
|
nsresult
|
2012-10-12 16:11:22 +00:00
|
|
|
imgRequestProxyStatic::Clone(imgINotificationObserver* aObserver,
|
2013-06-04 18:38:37 +00:00
|
|
|
imgRequestProxy** aClone)
|
2012-10-12 16:11:22 +00:00
|
|
|
{
|
2013-06-04 18:38:37 +00:00
|
|
|
return PerformClone(aObserver, NewStaticProxy, aClone);
|
2012-10-12 16:11:22 +00:00
|
|
|
}
|