2001-02-21 01:43:56 +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-02-21 01:43:56 +03:00
|
|
|
|
2001-02-21 02:27:48 +03:00
|
|
|
#include "imgRequestProxy.h"
|
2017-10-25 01:22:55 +03:00
|
|
|
|
|
|
|
#include "ImageLogging.h"
|
2015-04-10 09:15:39 +03:00
|
|
|
#include "imgLoader.h"
|
2010-08-14 08:09:48 +04:00
|
|
|
#include "Image.h"
|
2013-04-06 01:14:34 +04:00
|
|
|
#include "ImageOps.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
#include "nsCRTGlue.h"
|
|
|
|
#include "imgINotificationObserver.h"
|
2017-07-19 21:15:11 +03:00
|
|
|
#include "mozilla/dom/TabGroup.h" // for TabGroup
|
|
|
|
#include "mozilla/dom/DocGroup.h" // for DocGroup
|
2017-10-25 01:22:55 +03:00
|
|
|
#include "mozilla/Move.h"
|
2017-07-19 21:15:12 +03:00
|
|
|
#include "mozilla/Telemetry.h" // for Telemetry
|
2001-05-08 08:01:28 +04:00
|
|
|
|
2017-10-25 01:22:55 +03:00
|
|
|
using namespace mozilla;
|
2012-01-06 20:02:27 +04:00
|
|
|
using namespace mozilla::image;
|
2018-02-28 21:34:51 +03:00
|
|
|
using mozilla::Move;
|
2010-08-14 08:09:48 +04:00
|
|
|
|
2012-10-19 23:39:38 +04: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:
|
2016-11-16 18:39:43 +03:00
|
|
|
virtual ~ProxyBehaviour() = default;
|
2012-10-19 23:39:38 +04:00
|
|
|
|
2013-09-28 22:28:44 +04:00
|
|
|
virtual already_AddRefed<mozilla::image::Image> GetImage() const = 0;
|
|
|
|
virtual bool HasImage() const = 0;
|
2014-11-15 07:10:47 +03:00
|
|
|
virtual already_AddRefed<ProgressTracker> GetProgressTracker() const = 0;
|
2012-10-19 23:39:38 +04:00
|
|
|
virtual imgRequest* GetOwner() const = 0;
|
|
|
|
virtual void SetOwner(imgRequest* aOwner) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RequestBehaviour : public ProxyBehaviour
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RequestBehaviour() : mOwner(nullptr), mOwnerHasImage(false) {}
|
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
already_AddRefed<mozilla::image::Image>GetImage() const override;
|
|
|
|
bool HasImage() const override;
|
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker() const override;
|
2012-10-19 23:39:38 +04:00
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
imgRequest* GetOwner() const override {
|
2012-10-19 23:39:38 +04:00
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
void SetOwner(imgRequest* aOwner) override {
|
2012-10-19 23:39:38 +04:00
|
|
|
mOwner = aOwner;
|
2013-04-26 07:30:29 +04:00
|
|
|
|
|
|
|
if (mOwner) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> ownerProgressTracker = GetProgressTracker();
|
2014-11-15 07:10:47 +03:00
|
|
|
mOwnerHasImage = ownerProgressTracker && ownerProgressTracker->HasImage();
|
2013-04-26 07:30:29 +04:00
|
|
|
} else {
|
|
|
|
mOwnerHasImage = false;
|
|
|
|
}
|
2012-10-19 23:39:38 +04: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 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> mOwner;
|
2012-10-19 23:39:38 +04:00
|
|
|
|
|
|
|
bool mOwnerHasImage;
|
|
|
|
};
|
|
|
|
|
2013-09-28 22:28:44 +04:00
|
|
|
already_AddRefed<mozilla::image::Image>
|
2012-10-19 23:39:38 +04:00
|
|
|
RequestBehaviour::GetImage() const
|
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!mOwnerHasImage) {
|
2012-10-19 23:39:38 +04:00
|
|
|
return nullptr;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 07:10:47 +03:00
|
|
|
return progressTracker->GetImage();
|
2012-10-19 23:39:38 +04:00
|
|
|
}
|
|
|
|
|
2014-11-15 07:10:47 +03:00
|
|
|
already_AddRefed<ProgressTracker>
|
|
|
|
RequestBehaviour::GetProgressTracker() const
|
2012-10-19 23:39:38 +04: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 07:10:47 +03: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 23:39:38 +04:00
|
|
|
}
|
|
|
|
|
2011-06-10 01:11:57 +04: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 20:59:00 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsITimedChannel,
|
|
|
|
TimedChannel() != nullptr)
|
2011-06-10 01:11:57 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2001-02-22 05:06:24 +03:00
|
|
|
imgRequestProxy::imgRequestProxy() :
|
2012-10-19 23:39:38 +04:00
|
|
|
mBehaviour(new RequestBehaviour),
|
2012-07-30 18:20:58 +04:00
|
|
|
mURI(nullptr),
|
|
|
|
mListener(nullptr),
|
2001-07-17 05:14:40 +04:00
|
|
|
mLoadFlags(nsIRequest::LOAD_NORMAL),
|
2010-08-26 10:21:34 +04:00
|
|
|
mLockCount(0),
|
2010-09-08 04:33:02 +04:00
|
|
|
mAnimationConsumers(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mCanceled(false),
|
|
|
|
mIsInLoadGroup(false),
|
2017-11-01 13:59:10 +03:00
|
|
|
mForceDispatchLoadGroup(false),
|
2011-10-17 18:59:28 +04:00
|
|
|
mListenerIsStrongRef(false),
|
|
|
|
mDecodeRequested(false),
|
2018-02-07 15:27:27 +03:00
|
|
|
mPendingNotify(false),
|
2018-02-07 15:27:27 +03:00
|
|
|
mValidating(false),
|
2017-07-19 21:15:12 +03:00
|
|
|
mHadListener(false),
|
|
|
|
mHadDispatch(false)
|
2001-02-21 01:43:56 +03:00
|
|
|
{
|
|
|
|
/* member initializers and constructor code */
|
2017-07-25 18:14:00 +03:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::imgRequestProxy");
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2001-02-21 02:27:48 +03:00
|
|
|
imgRequestProxy::~imgRequestProxy()
|
2001-02-21 01:43:56 +03:00
|
|
|
{
|
|
|
|
/* destructor code */
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_PRECONDITION(!mListener,
|
|
|
|
"Someone forgot to properly cancel this request!");
|
2008-12-20 01:35:50 +03:00
|
|
|
|
2017-07-19 21:15:12 +03:00
|
|
|
// If we had a listener, that means we would have issued notifications. With
|
|
|
|
// bug 1359833, we added support for main thread scheduler groups. Each
|
|
|
|
// imgRequestProxy may have its own associated listener, document and/or
|
|
|
|
// scheduler group. Typically most imgRequestProxy belong to the same
|
|
|
|
// document, or have no listener, which means we will want to execute all main
|
|
|
|
// thread code in that shared scheduler group. Less frequently, there may be
|
|
|
|
// multiple imgRequests and they have separate documents, which means that
|
|
|
|
// when we issue state notifications, some or all need to be dispatched to the
|
|
|
|
// appropriate scheduler group for each request. This should be rare, so we
|
|
|
|
// want to monitor the frequency of dispatching in the wild.
|
|
|
|
if (mHadListener) {
|
|
|
|
mozilla::Telemetry::Accumulate(mozilla::Telemetry::IMAGE_REQUEST_DISPATCHED,
|
|
|
|
mHadDispatch);
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03: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-15 00:47:59 +04:00
|
|
|
UnlockImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
ClearAnimationConsumers();
|
|
|
|
|
2006-06-01 22:35:21 +04: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 22:07:59 +03:00
|
|
|
// is being destroyed. This is all belt-and-suspenders in view of the
|
|
|
|
// above assert.
|
|
|
|
NullOutListener();
|
2001-03-06 07:46:20 +03:00
|
|
|
|
2018-02-07 15:27:27 +03: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;
|
|
|
|
RemoveFromOwner(NS_OK);
|
2017-07-25 18:14:00 +03:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
RemoveFromLoadGroup();
|
2017-07-25 18:14:00 +03:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::~imgRequestProxy");
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
nsresult
|
|
|
|
imgRequestProxy::Init(imgRequest* aOwner,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
2017-07-19 21:15:11 +03:00
|
|
|
nsIDocument* aLoadingDocument,
|
2015-03-25 20:59:00 +03:00
|
|
|
ImageURL* aURI,
|
|
|
|
imgINotificationObserver* aObserver)
|
2001-02-21 01:43:56 +03:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_PRECONDITION(!GetOwner() && !mListener,
|
|
|
|
"imgRequestProxy is already initialized");
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequestProxy::Init", "request",
|
2015-03-25 20:59:00 +03:00
|
|
|
aOwner);
|
2001-02-23 11:36:51 +03:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mAnimationConsumers == 0, "Cannot have animation before Init");
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2012-12-20 01:28:54 +04: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 06:42:56 +04:00
|
|
|
mListener = aObserver;
|
2017-07-19 21:15:11 +03:00
|
|
|
// Make sure to addref mListener before the AddToOwner call below, since
|
2008-03-19 22:07:59 +03:00
|
|
|
// that call might well want to release it if the imgRequest has
|
|
|
|
// already seen OnStopRequest.
|
|
|
|
if (mListener) {
|
2017-07-19 21:15:12 +03:00
|
|
|
mHadListener = true;
|
2011-10-17 18:59:28 +04:00
|
|
|
mListenerIsStrongRef = true;
|
2008-03-19 22:07:59 +03:00
|
|
|
NS_ADDREF(mListener);
|
|
|
|
}
|
2003-05-14 09:42:06 +04:00
|
|
|
mLoadGroup = aLoadGroup;
|
2010-05-11 07:27:41 +04:00
|
|
|
mURI = aURI;
|
2001-03-06 07:46:20 +03:00
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
// Note: AddToOwner won't send all the On* notifications immediately
|
|
|
|
AddToOwner(aLoadingDocument);
|
2002-01-15 08:23:33 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
nsresult
|
|
|
|
imgRequestProxy::ChangeOwner(imgRequest* aNewOwner)
|
2002-01-15 08:23:33 +03:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_PRECONDITION(GetOwner(),
|
|
|
|
"Cannot ChangeOwner on a proxy without an owner!");
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2012-10-22 20:44:53 +04:00
|
|
|
if (mCanceled) {
|
2015-03-25 20:59:00 +03: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 20:44:53 +04:00
|
|
|
SyncNotifyListener();
|
|
|
|
}
|
|
|
|
|
2010-05-15 00:47:59 +04:00
|
|
|
// If we're holding locks, unlock the old image.
|
2010-08-26 10:21:34 +04:00
|
|
|
// Note that UnlockImage decrements mLockCount each time it's called.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t oldLockCount = mLockCount;
|
2015-03-25 20:59:00 +03:00
|
|
|
while (mLockCount) {
|
2010-05-15 00:47:59 +04:00
|
|
|
UnlockImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
// If we're holding animation requests, undo them.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t oldAnimationConsumers = mAnimationConsumers;
|
2010-09-08 04:33:02 +04:00
|
|
|
ClearAnimationConsumers();
|
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
GetOwner()->RemoveProxy(this, NS_OK);
|
2012-10-22 20:44:53 +04:00
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
mBehaviour->SetOwner(aNewOwner);
|
2018-02-07 15:27:27 +03:00
|
|
|
MOZ_ASSERT(!GetValidator(), "New owner cannot be validating!");
|
2012-10-22 20:44:53 +04:00
|
|
|
|
|
|
|
// If we were locked, apply the locks here
|
2015-03-25 20:59:00 +03:00
|
|
|
for (uint32_t i = 0; i < oldLockCount; i++) {
|
2012-10-22 20:44:53 +04:00
|
|
|
LockImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2011-01-26 21:52:42 +03: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 20:59:00 +03:00
|
|
|
for (uint32_t i = 0; i < oldAnimationConsumers; i++) {
|
2011-01-26 21:52:42 +03:00
|
|
|
IncrementAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2011-01-26 21:52:42 +03:00
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
AddToOwner(nullptr);
|
2018-02-07 15:27:27 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgRequestProxy::MarkValidating()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(GetValidator());
|
|
|
|
mValidating = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgRequestProxy::ClearValidating()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mValidating);
|
|
|
|
MOZ_ASSERT(!GetValidator());
|
|
|
|
mValidating = false;
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2015-10-30 02:37:42 +03:00
|
|
|
// If we'd previously requested a synchronous decode, request a decode on the
|
|
|
|
// new image.
|
|
|
|
if (mDecodeRequested) {
|
2018-02-07 15:27:27 +03:00
|
|
|
mDecodeRequested = false;
|
2016-11-26 10:56:26 +03:00
|
|
|
StartDecoding(imgIContainer::FLAG_NONE);
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
bool
|
|
|
|
imgRequestProxy::IsOnEventTarget() const
|
|
|
|
{
|
|
|
|
// Ensure we are in some main thread context because the scheduler group
|
|
|
|
// methods are only safe to call on the main thread.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mTabGroup) {
|
|
|
|
MOZ_ASSERT(mEventTarget);
|
|
|
|
return mTabGroup->IsSafeToRun();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mListener) {
|
|
|
|
// If we have no scheduler group but we do have a listener, then we know
|
|
|
|
// that the listener requires unlabelled dispatch.
|
|
|
|
MOZ_ASSERT(mEventTarget);
|
|
|
|
return mozilla::SchedulerGroup::IsSafeToRunUnlabeled();
|
|
|
|
}
|
|
|
|
|
|
|
|
// No listener means it is always safe, as there is nothing to do.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIEventTarget>
|
|
|
|
imgRequestProxy::GetEventTarget() const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEventTarget> target(mEventTarget);
|
|
|
|
return target.forget();
|
|
|
|
}
|
|
|
|
|
2017-08-15 14:14:51 +03:00
|
|
|
nsresult
|
|
|
|
imgRequestProxy::DispatchWithTargetIfAvailable(already_AddRefed<nsIRunnable> aEvent)
|
|
|
|
{
|
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::DispatchWithTargetIfAvailable");
|
|
|
|
|
|
|
|
// This method should only be used when it is *expected* that we are
|
|
|
|
// dispatching an event (e.g. we want to handle an event asynchronously)
|
|
|
|
// rather we need to (e.g. we are in the wrong scheduler group context).
|
|
|
|
// As such, we do not set mHadDispatch for telemetry purposes.
|
|
|
|
if (mEventTarget) {
|
|
|
|
mEventTarget->Dispatch(Move(aEvent), NS_DISPATCH_NORMAL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_DispatchToMainThread(Move(aEvent));
|
|
|
|
}
|
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
void
|
2017-08-15 14:14:51 +03:00
|
|
|
imgRequestProxy::DispatchWithTarget(already_AddRefed<nsIRunnable> aEvent)
|
2017-07-19 21:15:11 +03:00
|
|
|
{
|
2017-08-15 14:14:51 +03:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::DispatchWithTarget");
|
2017-07-19 21:15:11 +03:00
|
|
|
|
2017-07-20 14:53:53 +03:00
|
|
|
MOZ_ASSERT(mListener || mTabGroup);
|
2017-07-19 21:15:11 +03:00
|
|
|
MOZ_ASSERT(mEventTarget);
|
|
|
|
|
2017-07-19 21:15:12 +03:00
|
|
|
mHadDispatch = true;
|
2017-07-19 21:15:11 +03:00
|
|
|
mEventTarget->Dispatch(Move(aEvent), NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgRequestProxy::AddToOwner(nsIDocument* aLoadingDocument)
|
|
|
|
{
|
|
|
|
// An imgRequestProxy can be initialized with neither a listener nor a
|
|
|
|
// document. The caller could follow up later by cloning the canonical
|
|
|
|
// imgRequestProxy with the actual listener. This is possible because
|
|
|
|
// imgLoader::LoadImage does not require a valid listener to be provided.
|
|
|
|
//
|
|
|
|
// Without a listener, we don't need to set our scheduler group, because
|
|
|
|
// we have nothing to signal. However if we were told what document this
|
|
|
|
// is for, it is likely that future listeners will belong to the same
|
|
|
|
// scheduler group.
|
|
|
|
//
|
|
|
|
// With a listener, we always need to update our scheduler group. A null
|
|
|
|
// scheduler group is valid with or without a document, but that means
|
|
|
|
// we will use the most generic event target possible on dispatch.
|
|
|
|
if (aLoadingDocument) {
|
2018-02-28 21:34:51 +03:00
|
|
|
RefPtr<mozilla::dom::DocGroup> docGroup = aLoadingDocument->GetDocGroup();
|
2017-07-19 21:15:11 +03:00
|
|
|
if (docGroup) {
|
|
|
|
mTabGroup = docGroup->GetTabGroup();
|
|
|
|
MOZ_ASSERT(mTabGroup);
|
|
|
|
|
2018-02-08 23:54:00 +03:00
|
|
|
mEventTarget = docGroup->EventTargetFor(mozilla::TaskCategory::Other);
|
2017-07-19 21:15:11 +03:00
|
|
|
MOZ_ASSERT(mEventTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mListener && !mEventTarget) {
|
|
|
|
mEventTarget = do_GetMainThread();
|
|
|
|
}
|
|
|
|
|
2018-02-07 15:27:27 +03:00
|
|
|
imgRequest* owner = GetOwner();
|
|
|
|
if (!owner) {
|
2017-07-19 21:15:11 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-07 15:27:27 +03:00
|
|
|
owner->AddProxy(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgRequestProxy::RemoveFromOwner(nsresult aStatus)
|
|
|
|
{
|
|
|
|
imgRequest* owner = GetOwner();
|
|
|
|
if (owner) {
|
|
|
|
if (mValidating) {
|
|
|
|
imgCacheValidator* validator = owner->GetValidator();
|
|
|
|
MOZ_ASSERT(validator);
|
|
|
|
validator->RemoveProxy(this);
|
|
|
|
mValidating = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
owner->RemoveProxy(this, aStatus);
|
|
|
|
}
|
2017-07-19 21:15:11 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
void
|
|
|
|
imgRequestProxy::AddToLoadGroup()
|
2003-05-14 09:42:06 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mIsInLoadGroup, "Whaa, we're already in the loadgroup!");
|
2017-11-01 13:59:10 +03:00
|
|
|
MOZ_ASSERT(!mForceDispatchLoadGroup);
|
2003-05-14 09:42:06 +04:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
/* While in theory there could be a dispatch outstanding to remove this
|
|
|
|
request from the load group, in practice we only add to the load group
|
|
|
|
(when previously not in a load group) at initialization. */
|
2003-05-14 09:42:06 +04:00
|
|
|
if (!mIsInLoadGroup && mLoadGroup) {
|
2017-11-01 13:59:10 +03:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::AddToLoadGroup");
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadGroup->AddRequest(this, nullptr);
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsInLoadGroup = true;
|
2003-05-14 09:42:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
void
|
2017-11-01 13:59:10 +03:00
|
|
|
imgRequestProxy::RemoveFromLoadGroup()
|
2003-05-14 09:42:06 +04:00
|
|
|
{
|
2017-11-01 13:59:10 +03:00
|
|
|
if (!mIsInLoadGroup || !mLoadGroup) {
|
2003-05-14 09:42:06 +04:00
|
|
|
return;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2003-05-14 09:42:06 +04:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
/* Sometimes we may not be able to remove ourselves from the load group in
|
|
|
|
the current context. This is because our listeners are not re-entrant (e.g.
|
|
|
|
we are in the middle of CancelAndForgetObserver or SyncClone). */
|
|
|
|
if (mForceDispatchLoadGroup) {
|
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::RemoveFromLoadGroup -- dispatch");
|
|
|
|
|
|
|
|
/* We take away the load group from the request temporarily; this prevents
|
|
|
|
additional dispatches via RemoveFromLoadGroup occurring, as well as
|
|
|
|
MoveToBackgroundInLoadGroup from removing and readding. This is safe
|
|
|
|
because we know that once we get here, blocking the load group at all is
|
|
|
|
unnecessary. */
|
|
|
|
mIsInLoadGroup = false;
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = Move(mLoadGroup);
|
|
|
|
RefPtr<imgRequestProxy> self(this);
|
|
|
|
DispatchWithTargetIfAvailable(NS_NewRunnableFunction(
|
|
|
|
"imgRequestProxy::RemoveFromLoadGroup",
|
|
|
|
[self, loadGroup]() -> void {
|
|
|
|
loadGroup->RemoveRequest(self, nullptr, NS_OK);
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::RemoveFromLoadGroup");
|
|
|
|
|
2003-05-14 09:42:06 +04: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
|
2017-11-01 13:59:10 +03:00
|
|
|
least until we exit this function. */
|
2003-05-14 09:42:06 +04:00
|
|
|
nsCOMPtr<imgIRequest> kungFuDeathGrip(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadGroup->RemoveRequest(this, nullptr, NS_OK);
|
2017-11-01 13:59:10 +03:00
|
|
|
mLoadGroup = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsInLoadGroup = false;
|
2017-11-01 13:59:10 +03:00
|
|
|
}
|
2003-05-14 09:42:06 +04:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
void
|
|
|
|
imgRequestProxy::MoveToBackgroundInLoadGroup()
|
|
|
|
{
|
|
|
|
/* Even if we are still in the load group, we may have taken away the load
|
|
|
|
group reference itself because we are in the process of leaving the group.
|
|
|
|
In that case, there is no need to background the request. */
|
|
|
|
if (!mLoadGroup) {
|
|
|
|
return;
|
2005-10-04 02:27:20 +04:00
|
|
|
}
|
2003-05-14 09:42:06 +04:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
/* There is no need to dispatch if we only need to add ourselves to the load
|
|
|
|
group without removal. It is the removal which causes the problematic
|
|
|
|
callbacks (see RemoveFromLoadGroup). */
|
|
|
|
if (mIsInLoadGroup && mForceDispatchLoadGroup) {
|
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::MoveToBackgroundInLoadGroup -- dispatch");
|
|
|
|
|
|
|
|
RefPtr<imgRequestProxy> self(this);
|
|
|
|
DispatchWithTargetIfAvailable(NS_NewRunnableFunction(
|
|
|
|
"imgRequestProxy::MoveToBackgroundInLoadGroup",
|
|
|
|
[self]() -> void {
|
|
|
|
self->MoveToBackgroundInLoadGroup();
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::MoveToBackgroundInLoadGroup");
|
|
|
|
nsCOMPtr<imgIRequest> kungFuDeathGrip(this);
|
|
|
|
if (mIsInLoadGroup) {
|
|
|
|
mLoadGroup->RemoveRequest(this, nullptr, NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
mLoadFlags |= nsIRequest::LOAD_BACKGROUND;
|
|
|
|
mLoadGroup->AddRequest(this, nullptr);
|
|
|
|
}
|
2001-05-08 08:01:28 +04:00
|
|
|
|
2001-03-06 07:46:20 +03:00
|
|
|
/** nsIRequest / imgIRequest methods **/
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetName(nsACString& aName)
|
2001-03-06 07:46:20 +03:00
|
|
|
{
|
2002-03-21 01:50:33 +03:00
|
|
|
aName.Truncate();
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
if (mURI) {
|
2010-05-11 07:27:41 +04:00
|
|
|
mURI->GetSpec(aName);
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
return NS_OK;
|
2001-03-06 07:46:20 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::IsPending(bool* _retval)
|
2001-03-06 07:46:20 +03:00
|
|
|
{
|
2006-11-10 01:47:43 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-03-06 07:46:20 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetStatus(nsresult* aStatus)
|
2001-03-06 07:46:20 +03:00
|
|
|
{
|
2009-01-30 22:13:52 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-03-06 07:46:20 +03:00
|
|
|
}
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::Cancel(nsresult status)
|
2001-02-21 01:43:56 +03:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (mCanceled) {
|
2001-02-22 05:06:24 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2001-02-22 05:06:24 +03:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE(gImgLog, "imgRequestProxy::Cancel");
|
2001-02-23 11:36:51 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mCanceled = true;
|
2001-03-25 15:57:25 +04:00
|
|
|
|
2008-12-20 01:35:50 +03:00
|
|
|
nsCOMPtr<nsIRunnable> ev = new imgCancelRunnable(this, status);
|
2017-08-15 14:14:51 +03:00
|
|
|
return DispatchWithTargetIfAvailable(ev.forget());
|
2008-12-20 01:35:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgRequestProxy::DoCancel(nsresult status)
|
|
|
|
{
|
2018-02-07 15:27:27 +03:00
|
|
|
RemoveFromOwner(status);
|
2017-11-01 13:59:10 +03:00
|
|
|
RemoveFromLoadGroup();
|
2008-03-19 22:07:59 +03:00
|
|
|
NullOutListener();
|
2008-12-20 01:35:50 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::CancelAndForgetObserver(nsresult aStatus)
|
2008-12-20 01:35:50 +03:00
|
|
|
{
|
2011-10-15 00:15:56 +04: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 20:59:00 +03:00
|
|
|
if (mCanceled && !mListener) {
|
2008-12-20 01:35:50 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2008-12-20 01:35:50 +03:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE(gImgLog, "imgRequestProxy::CancelAndForgetObserver");
|
2008-12-20 01:35:50 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mCanceled = true;
|
2017-11-07 14:42:47 +03:00
|
|
|
mForceDispatchLoadGroup = true;
|
2018-02-07 15:27:27 +03:00
|
|
|
RemoveFromOwner(aStatus);
|
2017-11-01 13:59:10 +03:00
|
|
|
RemoveFromLoadGroup();
|
|
|
|
mForceDispatchLoadGroup = false;
|
2010-03-08 22:34:52 +03:00
|
|
|
|
2008-12-20 01:35:50 +03:00
|
|
|
NullOutListener();
|
2006-06-01 22:35:21 +04:00
|
|
|
|
2001-04-13 09:37:29 +04:00
|
|
|
return NS_OK;
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2012-10-05 00:02:15 +04:00
|
|
|
NS_IMETHODIMP
|
2016-11-26 10:56:26 +03:00
|
|
|
imgRequestProxy::StartDecoding(uint32_t aFlags)
|
2012-10-05 00:02:15 +04:00
|
|
|
{
|
2018-02-07 15:27:28 +03:00
|
|
|
// Flag this, so we know to request after validation if pending.
|
|
|
|
if (IsValidating()) {
|
|
|
|
mDecodeRequested = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-10-05 00:02:15 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-24 05:37:45 +03:00
|
|
|
if (image) {
|
2016-11-26 10:56:26 +03:00
|
|
|
return image->StartDecoding(aFlags);
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GetOwner()) {
|
2015-10-30 02:37:42 +03:00
|
|
|
GetOwner()->StartDecoding();
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-10-05 00:02:15 +04:00
|
|
|
}
|
|
|
|
|
2016-12-23 10:07:45 +03:00
|
|
|
bool
|
|
|
|
imgRequestProxy::StartDecodingWithResult(uint32_t aFlags)
|
|
|
|
{
|
2018-02-07 15:27:28 +03:00
|
|
|
// Flag this, so we know to request after validation if pending.
|
|
|
|
if (IsValidating()) {
|
|
|
|
mDecodeRequested = true;
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-23 10:07:45 +03:00
|
|
|
|
|
|
|
RefPtr<Image> image = GetImage();
|
|
|
|
if (image) {
|
|
|
|
return image->StartDecodingWithResult(aFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetOwner()) {
|
|
|
|
GetOwner()->StartDecoding();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::LockImage()
|
|
|
|
{
|
2010-08-26 10:21:34 +04:00
|
|
|
mLockCount++;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
if (image) {
|
2013-09-28 22:28:44 +04:00
|
|
|
return image->LockImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-08-26 10:21:34 +04:00
|
|
|
return NS_OK;
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::UnlockImage()
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "calling unlock but no locks!");
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2010-08-26 10:21:34 +04:00
|
|
|
mLockCount--;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
if (image) {
|
2013-09-28 22:28:44 +04:00
|
|
|
return image->UnlockImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-08-26 10:21:34 +04:00
|
|
|
return NS_OK;
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
2012-03-10 10:29:28 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::RequestDiscard()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
if (image) {
|
2013-09-28 22:28:44 +04:00
|
|
|
return image->RequestDiscard();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2012-03-10 10:29:28 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::IncrementAnimationConsumers()
|
|
|
|
{
|
|
|
|
mAnimationConsumers++;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
if (image) {
|
2013-09-28 22:28:44 +04:00
|
|
|
image->IncrementAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-09-08 04:33:02 +04: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 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
if (image) {
|
2013-09-28 22:28:44 +04:00
|
|
|
image->DecrementAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-09-08 04:33:02 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgRequestProxy::ClearAnimationConsumers()
|
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
while (mAnimationConsumers > 0) {
|
2010-09-08 04:33:02 +04:00
|
|
|
DecrementAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-09-08 04:33:02 +04:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::Suspend()
|
2001-03-06 07:46:20 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::Resume()
|
2001-03-06 07:46:20 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetLoadGroup(nsILoadGroup** loadGroup)
|
2001-04-10 10:01:08 +04:00
|
|
|
{
|
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
|
|
|
NS_IF_ADDREF(*loadGroup = mLoadGroup.get());
|
|
|
|
return NS_OK;
|
2001-04-10 10:01:08 +04:00
|
|
|
}
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::SetLoadGroup(nsILoadGroup* loadGroup)
|
2001-04-10 10:01:08 +04:00
|
|
|
{
|
2017-11-01 13:59:09 +03:00
|
|
|
if (loadGroup != mLoadGroup) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Switching load groups is unsupported!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
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
|
|
|
return NS_OK;
|
2001-04-10 10:01:08 +04:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetLoadFlags(nsLoadFlags* flags)
|
2001-04-10 10:01:08 +04:00
|
|
|
{
|
2001-07-17 05:14:40 +04: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 06:42:56 +04:00
|
|
|
return NS_OK;
|
2001-04-10 10:01:08 +04:00
|
|
|
}
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::SetLoadFlags(nsLoadFlags flags)
|
2001-04-10 10:01:08 +04:00
|
|
|
{
|
2001-07-17 05:14:40 +04:00
|
|
|
mLoadFlags = flags;
|
|
|
|
return NS_OK;
|
2001-04-10 10:01:08 +04:00
|
|
|
}
|
|
|
|
|
2001-03-06 07:46:20 +03:00
|
|
|
/** imgIRequest methods **/
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImage(imgIContainer** aImage)
|
2001-02-21 01:43:56 +03:00
|
|
|
{
|
2013-09-28 22:28:44 +04:00
|
|
|
NS_ENSURE_TRUE(aImage, NS_ERROR_NULL_POINTER);
|
2010-08-24 02:44:07 +04: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 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2013-09-28 22:28:44 +04:00
|
|
|
nsCOMPtr<imgIContainer> imageToReturn;
|
2015-03-24 05:37:45 +03:00
|
|
|
if (image) {
|
2013-09-28 22:28:44 +04:00
|
|
|
imageToReturn = do_QueryInterface(image);
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
|
|
|
if (!imageToReturn && GetOwner()) {
|
|
|
|
imageToReturn = GetOwner()->GetImage();
|
|
|
|
}
|
|
|
|
if (!imageToReturn) {
|
2001-03-25 15:57:25 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
2001-03-25 15:57:25 +04:00
|
|
|
|
2013-09-28 22:28:44 +04:00
|
|
|
imageToReturn.swap(*aImage);
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2001-10-12 10:43:52 +04:00
|
|
|
return NS_OK;
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImageStatus(uint32_t* aStatus)
|
2001-02-21 01:43:56 +03:00
|
|
|
{
|
2018-02-07 15:27:28 +03:00
|
|
|
if (IsValidating()) {
|
|
|
|
// We are currently validating the image, and so our status could revert if
|
|
|
|
// we discard the cache. We should also be deferring notifications, such
|
|
|
|
// that the caller will be notified when validation completes. Rather than
|
|
|
|
// risk misleading the caller, return nothing.
|
|
|
|
*aStatus = imgIRequest::STATUS_NONE;
|
|
|
|
} else {
|
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
|
|
|
*aStatus = progressTracker->GetImageStatus();
|
|
|
|
}
|
2001-03-25 15:57:25 +04:00
|
|
|
|
2001-10-12 10:43:52 +04:00
|
|
|
return NS_OK;
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImageErrorCode(nsresult* aStatus)
|
2014-07-19 05:47:11 +04:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!GetOwner()) {
|
2014-07-19 05:47:11 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2014-07-19 05:47:11 +04:00
|
|
|
|
|
|
|
*aStatus = GetOwner()->GetImageErrorCode();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetURI(nsIURI** aURI)
|
2013-09-28 22:28:42 +04: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 20:59:00 +03:00
|
|
|
nsresult
|
2017-11-13 11:31:24 +03:00
|
|
|
imgRequestProxy::GetFinalURI(nsIURI** aURI)
|
2014-11-11 01:06:24 +03:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!GetOwner()) {
|
2014-11-11 01:06:24 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2014-11-11 01:06:24 +03:00
|
|
|
|
2017-11-13 11:31:24 +03:00
|
|
|
return GetOwner()->GetFinalURI(aURI);
|
2014-11-11 01:06:24 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
nsresult
|
|
|
|
imgRequestProxy::GetURI(ImageURL** aURI)
|
2001-02-22 05:06:24 +03:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!mURI) {
|
2001-03-25 15:57:25 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2001-03-25 15:57:25 +04:00
|
|
|
|
2010-05-11 07:27:41 +04:00
|
|
|
NS_ADDREF(*aURI = mURI);
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-02-22 05:06:24 +03:00
|
|
|
}
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetNotificationObserver(imgINotificationObserver** aObserver)
|
2001-03-23 02:16:52 +03:00
|
|
|
{
|
2012-10-12 20:11:22 +04:00
|
|
|
*aObserver = mListener;
|
|
|
|
NS_IF_ADDREF(*aObserver);
|
2001-03-23 02:16:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetMimeType(char** aMimeType)
|
2001-10-12 11:59:21 +04:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!GetOwner()) {
|
2001-10-12 11:59:21 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2001-10-12 11:59:21 +04:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
const char* type = GetOwner()->GetMimeType();
|
|
|
|
if (!type) {
|
2001-10-12 11:59:21 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2001-10-12 11:59:21 +04:00
|
|
|
|
2009-03-29 15:46:12 +04:00
|
|
|
*aMimeType = NS_strdup(type);
|
2001-10-12 11:59:21 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
imgRequestProxy* imgRequestProxy::NewClonedProxy()
|
2012-10-12 20:11:22 +04:00
|
|
|
{
|
|
|
|
return new imgRequestProxy();
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::Clone(imgINotificationObserver* aObserver,
|
|
|
|
imgIRequest** aClone)
|
2012-10-12 16:43:01 +04:00
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
imgRequestProxy* proxy;
|
2017-07-19 21:15:11 +03:00
|
|
|
result = PerformClone(aObserver, nullptr, /* aSyncNotify */ true, &proxy);
|
2012-10-12 16:43:01 +04:00
|
|
|
*aClone = proxy;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
nsresult imgRequestProxy::SyncClone(imgINotificationObserver* aObserver,
|
|
|
|
nsIDocument* aLoadingDocument,
|
|
|
|
imgRequestProxy** aClone)
|
|
|
|
{
|
|
|
|
return PerformClone(aObserver, aLoadingDocument,
|
|
|
|
/* aSyncNotify */ true, aClone);
|
|
|
|
}
|
|
|
|
|
2012-10-12 16:43:01 +04:00
|
|
|
nsresult imgRequestProxy::Clone(imgINotificationObserver* aObserver,
|
2017-07-19 21:15:11 +03:00
|
|
|
nsIDocument* aLoadingDocument,
|
2012-10-12 16:43:01 +04:00
|
|
|
imgRequestProxy** aClone)
|
2012-10-12 20:11:22 +04:00
|
|
|
{
|
2017-07-19 21:15:11 +03:00
|
|
|
return PerformClone(aObserver, aLoadingDocument,
|
|
|
|
/* aSyncNotify */ false, aClone);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
nsresult
|
|
|
|
imgRequestProxy::PerformClone(imgINotificationObserver* aObserver,
|
2017-07-19 21:15:11 +03:00
|
|
|
nsIDocument* aLoadingDocument,
|
2017-07-19 21:15:11 +03:00
|
|
|
bool aSyncNotify,
|
2015-03-25 20:59:00 +03:00
|
|
|
imgRequestProxy** aClone)
|
2004-03-09 06:57:51 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aClone, "Null out param");
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE(gImgLog, "imgRequestProxy::Clone");
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aClone = nullptr;
|
2017-07-19 21:15:11 +03:00
|
|
|
RefPtr<imgRequestProxy> clone = NewClonedProxy();
|
2004-03-09 06:57:51 +03:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
if (aLoadingDocument) {
|
|
|
|
loadGroup = aLoadingDocument->GetDocumentLoadGroup();
|
|
|
|
}
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
// It is important to call |SetLoadFlags()| before calling |Init()| because
|
|
|
|
// |Init()| adds the request to the loadgroup.
|
2006-06-01 22:35:21 +04: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 06:57:51 +03:00
|
|
|
clone->SetLoadFlags(mLoadFlags);
|
2017-11-01 13:59:10 +03:00
|
|
|
nsresult rv = clone->Init(mBehaviour->GetOwner(), loadGroup,
|
2017-07-19 21:15:11 +03:00
|
|
|
aLoadingDocument, mURI, aObserver);
|
2015-03-25 20:59:00 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2004-03-09 06:57:51 +03:00
|
|
|
return rv;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2004-03-09 06:57:51 +03:00
|
|
|
|
2010-05-11 07:27:41 +04: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-15 00:47:59 +04:00
|
|
|
NS_ADDREF(*aClone = clone);
|
2004-09-21 02:46:22 +04:00
|
|
|
|
2018-02-07 15:27:27 +03:00
|
|
|
imgCacheValidator* validator = GetValidator();
|
|
|
|
if (validator) {
|
2017-07-19 21:15:11 +03:00
|
|
|
// Note that if we have a validator, we don't want to issue notifications at
|
2017-11-01 13:59:10 +03:00
|
|
|
// here because we want to defer until that completes. AddProxy will add us
|
|
|
|
// to the load group; we cannot avoid that in this case, because we don't
|
|
|
|
// know when the validation will complete, and if it will cause us to
|
|
|
|
// discard our cached state anyways. We are probably already blocked by the
|
|
|
|
// original LoadImage(WithChannel) request in any event.
|
2018-02-07 15:27:27 +03:00
|
|
|
clone->MarkValidating();
|
|
|
|
validator->AddProxy(clone);
|
2017-07-19 21:15:11 +03:00
|
|
|
} else {
|
2017-11-01 13:59:10 +03:00
|
|
|
// We only want to add the request to the load group of the owning document
|
|
|
|
// if it is still in progress. Some callers cannot handle a supurious load
|
|
|
|
// group removal (e.g. print preview) so we must be careful. On the other
|
|
|
|
// hand, if after cloning, the original request proxy is cancelled /
|
|
|
|
// destroyed, we need to ensure that any clones still block the load group
|
|
|
|
// if it is incomplete.
|
|
|
|
bool addToLoadGroup = mIsInLoadGroup;
|
|
|
|
if (!addToLoadGroup) {
|
|
|
|
RefPtr<ProgressTracker> tracker = clone->GetProgressTracker();
|
|
|
|
addToLoadGroup = tracker && !(tracker->GetProgress() & FLAG_LOAD_COMPLETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addToLoadGroup) {
|
|
|
|
clone->AddToLoadGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSyncNotify) {
|
|
|
|
// 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. Note that
|
|
|
|
// if we have a validator, we won't issue notifications anyways because
|
|
|
|
// they are deferred, so there is no point in requesting.
|
|
|
|
clone->mForceDispatchLoadGroup = true;
|
|
|
|
clone->SyncNotifyListener();
|
|
|
|
clone->mForceDispatchLoadGroup = false;
|
|
|
|
} else {
|
|
|
|
// Without a validator, we can request asynchronous notifications
|
|
|
|
// immediately. If there was a validator, this would override the deferral
|
|
|
|
// and that would be incorrect.
|
|
|
|
clone->NotifyListener();
|
|
|
|
}
|
2017-07-19 21:15:11 +03:00
|
|
|
}
|
2004-03-09 06:57:51 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-23 02:16:52 +03:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImagePrincipal(nsIPrincipal** aPrincipal)
|
2007-11-09 05:55:41 +03:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!GetOwner()) {
|
2007-11-09 05:55:41 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2007-11-09 05:55:41 +03:00
|
|
|
|
2016-08-10 11:12:30 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = GetOwner()->GetPrincipal();
|
|
|
|
principal.forget(aPrincipal);
|
2010-05-11 07:27:41 +04:00
|
|
|
return NS_OK;
|
2007-11-09 05:55:41 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetMultipart(bool* aMultipart)
|
2012-05-19 23:32:37 +04:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!GetOwner()) {
|
2012-05-19 23:32:37 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2012-05-19 23:32:37 +04:00
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
*aMultipart = GetOwner()->GetMultipart();
|
2012-05-19 23:32:37 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetCORSMode(int32_t* aCorsMode)
|
2011-07-14 22:47:34 +04:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!GetOwner()) {
|
2011-07-14 22:47:34 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2011-07-14 22:47:34 +04:00
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
*aCorsMode = GetOwner()->GetCORSMode();
|
2011-07-14 22:47:34 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-22 14:52:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::BoostPriority(uint32_t aCategory)
|
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(GetOwner() && !mCanceled);
|
|
|
|
GetOwner()->BoostPriority(aCategory);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-21 23:58:01 +03:00
|
|
|
/** nsISupportsPriority methods **/
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetPriority(int32_t* priority)
|
2005-02-21 23:58:01 +03:00
|
|
|
{
|
2012-10-19 23:39:38 +04:00
|
|
|
NS_ENSURE_STATE(GetOwner());
|
|
|
|
*priority = GetOwner()->Priority();
|
2005-02-21 23:58:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::SetPriority(int32_t priority)
|
2005-02-21 23:58:01 +03:00
|
|
|
{
|
2012-10-19 23:39:38 +04:00
|
|
|
NS_ENSURE_STATE(GetOwner() && !mCanceled);
|
|
|
|
GetOwner()->AdjustPriority(this, priority - GetOwner()->Priority());
|
2005-02-21 23:58:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::AdjustPriority(int32_t priority)
|
2005-02-21 23:58:01 +03:00
|
|
|
{
|
2013-02-16 05:00:03 +04: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 23:39:38 +04:00
|
|
|
GetOwner()->AdjustPriority(this, priority);
|
2005-02-21 23:58:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-02 00:53:59 +04:00
|
|
|
/** nsISecurityInfoProvider methods **/
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetSecurityInfo(nsISupports** _retval)
|
2008-09-02 00:53:59 +04:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (GetOwner()) {
|
2012-10-19 23:39:38 +04:00
|
|
|
return GetOwner()->GetSecurityInfo(_retval);
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2008-09-02 00:53:59 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
2008-09-02 00:53:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetHasTransferredData(bool* hasData)
|
2009-02-16 17:11:30 +03:00
|
|
|
{
|
2012-10-19 23:39:38 +04:00
|
|
|
if (GetOwner()) {
|
|
|
|
*hasData = GetOwner()->HasTransferredData();
|
2009-02-16 17:11:30 +03:00
|
|
|
} else {
|
|
|
|
// The safe thing to do is to claim we have data
|
2011-10-17 18:59:28 +04:00
|
|
|
*hasData = true;
|
2009-02-16 17:11:30 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:35:20 +03: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 19:09:02 +03:00
|
|
|
}
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:35:20 +03:00
|
|
|
void
|
2015-04-21 18:04:57 +03:00
|
|
|
imgRequestProxy::Notify(int32_t aType, const mozilla::gfx::IntRect* aRect)
|
2009-09-13 02:44:18 +04:00
|
|
|
{
|
2015-01-07 12:35:20 +03:00
|
|
|
MOZ_ASSERT(aType != imgINotificationObserver::LOAD_COMPLETE,
|
|
|
|
"Should call OnLoadComplete");
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::Notify", "type",
|
2015-01-07 12:35:20 +03:00
|
|
|
NotificationTypeToString(aType));
|
2013-02-25 04:59:22 +04:00
|
|
|
|
2015-01-07 12:35:20 +03:00
|
|
|
if (!mListener || mCanceled) {
|
|
|
|
return;
|
2013-02-25 04:59:22 +04:00
|
|
|
}
|
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
if (!IsOnEventTarget()) {
|
|
|
|
RefPtr<imgRequestProxy> self(this);
|
|
|
|
if (aRect) {
|
|
|
|
const mozilla::gfx::IntRect rect = *aRect;
|
2017-08-15 14:14:51 +03:00
|
|
|
DispatchWithTarget(NS_NewRunnableFunction("imgRequestProxy::Notify",
|
2017-07-19 21:15:11 +03:00
|
|
|
[self, rect, aType]() -> void {
|
|
|
|
self->Notify(aType, &rect);
|
|
|
|
}));
|
|
|
|
} else {
|
2017-08-15 14:14:51 +03:00
|
|
|
DispatchWithTarget(NS_NewRunnableFunction("imgRequestProxy::Notify",
|
2017-07-19 21:15:11 +03:00
|
|
|
[self, aType]() -> void {
|
|
|
|
self->Notify(aType, nullptr);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:35:20 +03:00
|
|
|
// Make sure the listener stays alive while we notify.
|
|
|
|
nsCOMPtr<imgINotificationObserver> listener(mListener);
|
2014-11-17 22:16:45 +03:00
|
|
|
|
2016-07-18 19:44:45 +03:00
|
|
|
listener->Notify(this, aType, aRect);
|
2011-11-10 01:39:15 +04:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:35:20 +03:00
|
|
|
void
|
|
|
|
imgRequestProxy::OnLoadComplete(bool aLastPart)
|
2001-03-06 07:46:20 +03:00
|
|
|
{
|
2015-11-16 20:21:00 +03:00
|
|
|
if (MOZ_LOG_TEST(gImgLog, LogLevel::Debug)) {
|
2015-05-11 23:42:30 +03:00
|
|
|
nsAutoCString name;
|
|
|
|
GetName(name);
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnLoadComplete",
|
2015-05-11 23:42:30 +03:00
|
|
|
"name", name.get());
|
|
|
|
}
|
|
|
|
|
2008-03-21 09:13:11 +03: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.
|
2017-07-19 21:15:11 +03:00
|
|
|
RefPtr<imgRequestProxy> self(this);
|
|
|
|
|
|
|
|
if (!IsOnEventTarget()) {
|
2017-08-15 14:14:51 +03:00
|
|
|
DispatchWithTarget(NS_NewRunnableFunction("imgRequestProxy::OnLoadComplete",
|
2017-07-19 21:15:11 +03:00
|
|
|
[self, aLastPart]() -> void {
|
|
|
|
self->OnLoadComplete(aLastPart);
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
2001-04-09 04:45:06 +04:00
|
|
|
|
2013-02-13 23:57:16 +04:00
|
|
|
if (mListener && !mCanceled) {
|
2006-06-01 22:35:21 +04:00
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
2016-07-18 19:44:45 +03:00
|
|
|
nsCOMPtr<imgINotificationObserver> listener(mListener);
|
|
|
|
listener->Notify(this, imgINotificationObserver::LOAD_COMPLETE, nullptr);
|
2005-10-04 02:27:20 +04:00
|
|
|
}
|
|
|
|
|
2006-06-01 22:35:21 +04: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-04 02:27:20 +04: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-18 01:29:56 +03:00
|
|
|
if (aLastPart || (mLoadFlags & nsIRequest::LOAD_BACKGROUND) == 0) {
|
2017-11-01 13:59:10 +03:00
|
|
|
if (aLastPart) {
|
|
|
|
RemoveFromLoadGroup();
|
|
|
|
} else {
|
|
|
|
// More data is coming, so change the request to be a background request
|
|
|
|
// and put it back in the loadgroup.
|
|
|
|
MoveToBackgroundInLoadGroup();
|
2005-10-04 02:27:20 +04:00
|
|
|
}
|
|
|
|
}
|
2008-03-19 22:07:59 +03:00
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
if (mListenerIsStrongRef && aLastPart) {
|
2008-03-19 22:07:59 +03: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 20:11:22 +04:00
|
|
|
imgINotificationObserver* obs = mListener;
|
2011-10-17 18:59:28 +04:00
|
|
|
mListenerIsStrongRef = false;
|
2008-03-19 22:07:59 +03:00
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
2001-03-06 07:46:20 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
void
|
|
|
|
imgRequestProxy::NullOutListener()
|
2008-03-19 22:07:59 +03:00
|
|
|
{
|
2010-09-08 04:33:02 +04:00
|
|
|
// If we have animation consumers, then they don't matter anymore
|
2015-03-25 20:59:00 +03:00
|
|
|
if (mListener) {
|
2010-09-08 04:33:02 +04:00
|
|
|
ClearAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2008-03-19 22:07:59 +03:00
|
|
|
if (mListenerIsStrongRef) {
|
|
|
|
// Releasing could do weird reentery stuff, so just play it super-safe
|
2012-10-12 20:11:22 +04:00
|
|
|
nsCOMPtr<imgINotificationObserver> obs;
|
2008-03-19 22:07:59 +03:00
|
|
|
obs.swap(mListener);
|
2011-10-17 18:59:28 +04:00
|
|
|
mListenerIsStrongRef = false;
|
2008-03-19 22:07:59 +03:00
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
mListener = nullptr;
|
2008-03-19 22:07:59 +03:00
|
|
|
}
|
2017-07-19 21:15:11 +03:00
|
|
|
|
|
|
|
// Note that we don't free the event target. We actually need that to ensure
|
|
|
|
// we get removed from the ProgressTracker properly. No harm in keeping it
|
|
|
|
// however.
|
|
|
|
mTabGroup = nullptr;
|
2008-03-19 22:07:59 +03:00
|
|
|
}
|
2009-12-11 07:02:13 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetStaticRequest(imgIRequest** aReturn)
|
2012-10-12 16:43:01 +04:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
imgRequestProxy* proxy;
|
2017-07-19 21:15:11 +03:00
|
|
|
nsresult result = GetStaticRequest(nullptr, &proxy);
|
2012-10-12 16:43:01 +04:00
|
|
|
*aReturn = proxy;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-07-19 21:15:11 +03:00
|
|
|
imgRequestProxy::GetStaticRequest(nsIDocument* aLoadingDocument,
|
|
|
|
imgRequestProxy** aReturn)
|
2009-12-11 07:02:13 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aReturn = nullptr;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool animated;
|
2012-10-12 20:11:21 +04:00
|
|
|
if (!image || (NS_SUCCEEDED(image->GetAnimated(&animated)) && !animated)) {
|
2010-05-11 07:27:41 +04: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 07:02:13 +03:00
|
|
|
}
|
|
|
|
|
2013-03-11 05:43:38 +04: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-15 00:47:59 +04:00
|
|
|
|
2013-03-11 05:43:38 +04:00
|
|
|
// We are animated. We need to create a frozen version of this image.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> frozenImage = ImageOps::Freeze(image);
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2010-05-15 00:47:59 +04:00
|
|
|
// Create a static imgRequestProxy with our new extracted frame.
|
2012-10-12 20:11:20 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> currentPrincipal;
|
|
|
|
GetImagePrincipal(getter_AddRefs(currentPrincipal));
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy> req = new imgRequestProxyStatic(frozenImage,
|
2013-03-11 05:43:38 +04:00
|
|
|
currentPrincipal);
|
2017-07-19 21:15:11 +03:00
|
|
|
req->Init(nullptr, nullptr, aLoadingDocument, mURI, nullptr);
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
NS_ADDREF(*aReturn = req);
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
void
|
|
|
|
imgRequestProxy::NotifyListener()
|
2010-05-11 07:27:41 +04:00
|
|
|
{
|
2010-07-29 01:52:14 +04: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 07:27:41 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2012-10-19 23:39:38 +04:00
|
|
|
if (GetOwner()) {
|
2010-07-29 01:52:14 +04:00
|
|
|
// Send the notifications to our listener asynchronously.
|
2014-11-15 07:10:47 +03:00
|
|
|
progressTracker->Notify(this);
|
2010-07-29 01:52:14 +04: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-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(HasImage(),
|
|
|
|
"if we have no imgRequest, we should have an Image");
|
2014-11-15 07:10:47 +03:00
|
|
|
progressTracker->NotifyCurrentState(this);
|
2010-07-29 01:52:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
void
|
|
|
|
imgRequestProxy::SyncNotifyListener()
|
2010-07-29 01:52:14 +04: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 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 07:10:47 +03:00
|
|
|
progressTracker->SyncNotify(this);
|
2010-08-24 02:44:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-12 20:11:21 +04:00
|
|
|
imgRequestProxy::SetHasImage()
|
2010-08-24 02:44:07 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 07:10:47 +03:00
|
|
|
MOZ_ASSERT(progressTracker);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = progressTracker->GetImage();
|
2013-09-28 22:28:44 +04:00
|
|
|
MOZ_ASSERT(image);
|
2010-08-24 02:44:07 +04:00
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
// Force any private status related to the owner to reflect
|
|
|
|
// the presence of an image;
|
|
|
|
mBehaviour->SetOwner(mBehaviour->GetOwner());
|
2010-08-24 02:44:07 +04:00
|
|
|
|
2010-08-26 10:21:34 +04:00
|
|
|
// Apply any locks we have
|
2015-03-25 20:59:00 +03:00
|
|
|
for (uint32_t i = 0; i < mLockCount; ++i) {
|
2012-10-12 20:11:21 +04:00
|
|
|
image->LockImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-09-08 04:33:02 +04:00
|
|
|
|
|
|
|
// Apply any animation consumers we have
|
2015-03-25 20:59:00 +03:00
|
|
|
for (uint32_t i = 0; i < mAnimationConsumers; i++) {
|
2012-10-12 20:11:21 +04:00
|
|
|
image->IncrementAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-08-24 02:44:07 +04:00
|
|
|
}
|
|
|
|
|
2014-11-15 07:10:47 +03:00
|
|
|
already_AddRefed<ProgressTracker>
|
|
|
|
imgRequestProxy::GetProgressTracker() const
|
2010-08-24 02:44:07 +04:00
|
|
|
{
|
2014-11-15 07:10:47 +03:00
|
|
|
return mBehaviour->GetProgressTracker();
|
2012-10-12 20:11:21 +04:00
|
|
|
}
|
|
|
|
|
2013-09-28 22:28:44 +04:00
|
|
|
already_AddRefed<mozilla::image::Image>
|
2012-10-12 20:11:21 +04:00
|
|
|
imgRequestProxy::GetImage() const
|
|
|
|
{
|
2012-10-19 23:39:38 +04:00
|
|
|
return mBehaviour->GetImage();
|
|
|
|
}
|
|
|
|
|
2013-09-28 22:28:44 +04:00
|
|
|
bool
|
|
|
|
RequestBehaviour::HasImage() const
|
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!mOwnerHasImage) {
|
2013-09-28 22:28:44 +04:00
|
|
|
return false;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 07:10:47 +03:00
|
|
|
return progressTracker ? progressTracker->HasImage() : false;
|
2013-09-28 22:28:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
imgRequestProxy::HasImage() const
|
|
|
|
{
|
|
|
|
return mBehaviour->HasImage();
|
|
|
|
}
|
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
imgRequest*
|
|
|
|
imgRequestProxy::GetOwner() const
|
|
|
|
{
|
|
|
|
return mBehaviour->GetOwner();
|
2012-10-12 05:34:23 +04:00
|
|
|
}
|
2012-10-12 20:11:20 +04:00
|
|
|
|
2018-02-07 15:27:27 +03:00
|
|
|
imgCacheValidator*
|
|
|
|
imgRequestProxy::GetValidator() const
|
|
|
|
{
|
|
|
|
imgRequest* owner = GetOwner();
|
|
|
|
if (!owner) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return owner->GetValidator();
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:20 +04:00
|
|
|
////////////////// imgRequestProxyStatic methods
|
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
class StaticBehaviour : public ProxyBehaviour
|
2012-10-12 20:11:20 +04:00
|
|
|
{
|
2012-10-19 23:39:38 +04:00
|
|
|
public:
|
2014-09-02 20:20:24 +04:00
|
|
|
explicit StaticBehaviour(mozilla::image::Image* aImage) : mImage(aImage) {}
|
2012-10-12 20:11:20 +04:00
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
already_AddRefed<mozilla::image::Image>
|
2015-03-21 19:28:04 +03:00
|
|
|
GetImage() const override {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::image::Image> image = mImage;
|
2013-09-28 22:28:44 +04:00
|
|
|
return image.forget();
|
|
|
|
}
|
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
bool HasImage() const override {
|
2012-10-19 23:39:38 +04:00
|
|
|
return mImage;
|
|
|
|
}
|
2012-10-12 20:11:20 +04:00
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker()
|
2015-03-25 20:59:00 +03:00
|
|
|
const override {
|
2014-11-15 07:10:47 +03:00
|
|
|
return mImage->GetProgressTracker();
|
2012-10-19 23:39:38 +04:00
|
|
|
}
|
2012-10-12 20:11:21 +04:00
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
imgRequest* GetOwner() const override {
|
2012-10-19 23:39:38 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
void SetOwner(imgRequest* aOwner) override {
|
2015-03-25 20:59:00 +03:00
|
|
|
MOZ_ASSERT(!aOwner,
|
|
|
|
"We shouldn't be giving static requests a non-null owner.");
|
2012-10-19 23:39:38 +04: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 08:24:48 +03:00
|
|
|
RefPtr<mozilla::image::Image> mImage;
|
2012-10-19 23:39:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
imgRequestProxyStatic::imgRequestProxyStatic(mozilla::image::Image* aImage,
|
|
|
|
nsIPrincipal* aPrincipal)
|
|
|
|
: mPrincipal(aPrincipal)
|
2012-10-12 20:11:21 +04:00
|
|
|
{
|
2015-10-17 13:53:28 +03:00
|
|
|
mBehaviour = mozilla::MakeUnique<StaticBehaviour>(aImage);
|
2012-10-12 20:11:21 +04:00
|
|
|
}
|
2012-10-12 20:11:21 +04:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxyStatic::GetImagePrincipal(nsIPrincipal** aPrincipal)
|
2012-10-12 20:11:21 +04:00
|
|
|
{
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!mPrincipal) {
|
2012-10-19 23:39:38 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2012-10-19 23:39:38 +04:00
|
|
|
|
|
|
|
NS_ADDREF(*aPrincipal = mPrincipal);
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-10-12 20:11:21 +04:00
|
|
|
}
|
2012-10-12 20:11:22 +04:00
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
imgRequestProxy* imgRequestProxyStatic::NewClonedProxy()
|
2012-10-12 20:11:22 +04:00
|
|
|
{
|
2017-07-19 21:15:11 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> currentPrincipal;
|
|
|
|
GetImagePrincipal(getter_AddRefs(currentPrincipal));
|
|
|
|
RefPtr<mozilla::image::Image> image = GetImage();
|
|
|
|
return new imgRequestProxyStatic(image, currentPrincipal);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|