2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2006-03-31 12:00:42 +04:00
|
|
|
/*
|
|
|
|
* A base class which implements nsIImageLoadingContent and can be
|
|
|
|
* subclassed by various content nodes that want to provide image
|
|
|
|
* loading functionality (eg <img>, <object>, etc).
|
|
|
|
*/
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
#include "nsImageLoadingContent.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2003-03-19 04:08:22 +03:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2004-11-25 01:48:45 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2003-03-19 04:08:22 +03:00
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsILoadGroup.h"
|
|
|
|
#include "imgIContainer.h"
|
2012-11-16 22:24:58 +04:00
|
|
|
#include "imgLoader.h"
|
2012-10-12 16:43:01 +04:00
|
|
|
#include "imgRequestProxy.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2003-03-19 04:08:22 +03:00
|
|
|
#include "nsNetUtil.h"
|
2012-03-20 02:22:02 +04:00
|
|
|
#include "nsImageFrame.h"
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2003-03-19 08:38:33 +03:00
|
|
|
#include "nsIPresShell.h"
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2003-04-02 07:27:20 +04:00
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
|
2003-04-16 05:53:48 +04:00
|
|
|
#include "nsIFrame.h"
|
2004-05-13 22:34:18 +04:00
|
|
|
#include "nsIDOMNode.h"
|
2003-04-16 05:53:48 +04:00
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
#include "nsContentUtils.h"
|
2011-11-10 01:39:16 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2005-03-02 07:05:12 +03:00
|
|
|
#include "nsIContentPolicy.h"
|
2010-08-13 17:36:13 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2004-03-09 06:57:51 +03:00
|
|
|
|
2015-07-13 21:25:13 +03:00
|
|
|
#include "gfxPrefs.h"
|
|
|
|
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2014-03-17 10:56:54 +04:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2016-10-13 10:04:15 +03:00
|
|
|
#include "mozilla/dom/ImageTracker.h"
|
2013-12-12 05:51:58 +04:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2015-06-06 01:25:24 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
|
2014-03-12 05:11:37 +04:00
|
|
|
#ifdef LoadImage
|
2013-12-02 14:26:11 +04:00
|
|
|
// Undefine LoadImage to prevent naming conflict with Windows.
|
|
|
|
#undef LoadImage
|
|
|
|
#endif
|
|
|
|
|
2012-03-10 20:13:51 +04:00
|
|
|
using namespace mozilla;
|
2016-10-13 10:04:15 +03:00
|
|
|
using namespace mozilla::dom;
|
2012-03-10 20:13:51 +04:00
|
|
|
|
2004-06-05 21:57:00 +04:00
|
|
|
#ifdef DEBUG_chb
|
|
|
|
static void PrintReqURL(imgIRequest* req) {
|
|
|
|
if (!req) {
|
|
|
|
printf("(null req)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
req->GetURI(getter_AddRefs(uri));
|
|
|
|
if (!uri) {
|
|
|
|
printf("(null uri)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2004-06-05 21:57:00 +04:00
|
|
|
uri->GetSpec(spec);
|
|
|
|
printf("spec='%s'\n", spec.get());
|
|
|
|
}
|
|
|
|
#endif /* DEBUG_chb */
|
|
|
|
|
2004-05-13 22:34:18 +04:00
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
nsImageLoadingContent::nsImageLoadingContent()
|
2012-08-14 02:11:50 +04:00
|
|
|
: mCurrentRequestFlags(0),
|
|
|
|
mPendingRequestFlags(0),
|
|
|
|
mObserverList(nullptr),
|
2005-03-02 07:05:12 +03:00
|
|
|
mImageBlockingStatus(nsIContentPolicy::ACCEPT),
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoadingEnabled(true),
|
|
|
|
mIsImageStateForced(false),
|
|
|
|
mLoading(false),
|
2005-09-18 22:05:40 +04:00
|
|
|
// mBroken starts out true, since an image without a URI is broken....
|
2011-10-17 18:59:28 +04:00
|
|
|
mBroken(true),
|
|
|
|
mUserDisabled(false),
|
|
|
|
mSuppressed(false),
|
|
|
|
mNewRequestsWillNeedAnimationReset(false),
|
2011-11-10 01:39:16 +04:00
|
|
|
mStateChangerDepth(0),
|
|
|
|
mCurrentRequestRegistered(false),
|
2013-02-25 04:59:21 +04:00
|
|
|
mPendingRequestRegistered(false),
|
2016-03-26 00:49:43 +03:00
|
|
|
mFrameCreateCalled(false)
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
2015-02-13 05:44:32 +03:00
|
|
|
if (!nsContentUtils::GetImgLoaderForChannel(nullptr, nullptr)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoadingEnabled = false;
|
2005-09-21 23:14:30 +04:00
|
|
|
}
|
2015-07-08 00:00:08 +03:00
|
|
|
|
|
|
|
bool isInconsistent;
|
|
|
|
mMostRecentRequestChange = TimeStamp::ProcessCreation(isInconsistent);
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
2006-06-01 22:35:21 +04:00
|
|
|
void
|
|
|
|
nsImageLoadingContent::DestroyImageLoadingContent()
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
|
|
|
// Cancel our requests so they won't hold stale refs to us
|
2013-04-09 20:50:35 +04:00
|
|
|
// NB: Don't ask to discard the images here.
|
2016-03-26 00:49:43 +03:00
|
|
|
ClearCurrentRequest(NS_BINDING_ABORTED);
|
|
|
|
ClearPendingRequest(NS_BINDING_ABORTED);
|
2006-06-01 22:35:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsImageLoadingContent::~nsImageLoadingContent()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mCurrentRequest && !mPendingRequest,
|
|
|
|
"DestroyImageLoadingContent not called");
|
2003-03-19 04:08:22 +03:00
|
|
|
NS_ASSERTION(!mObserverList.mObserver && !mObserverList.mNext,
|
|
|
|
"Observers still registered?");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-10-12 20:11:22 +04:00
|
|
|
* imgINotificationObserver impl
|
2003-03-19 04:08:22 +03:00
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2012-10-12 20:11:22 +04:00
|
|
|
nsImageLoadingContent::Notify(imgIRequest* aRequest,
|
|
|
|
int32_t aType,
|
|
|
|
const nsIntRect* aData)
|
2012-10-12 05:58:24 +04:00
|
|
|
{
|
2012-10-12 20:11:22 +04:00
|
|
|
if (aType == imgINotificationObserver::IS_ANIMATED) {
|
|
|
|
return OnImageIsAnimated(aRequest);
|
|
|
|
}
|
2011-02-01 07:50:01 +03:00
|
|
|
|
2013-02-25 04:59:22 +04:00
|
|
|
if (aType == imgINotificationObserver::UNLOCKED_DRAW) {
|
|
|
|
OnUnlockedDraw();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::LOAD_COMPLETE) {
|
2012-10-12 20:11:22 +04:00
|
|
|
// We should definitely have a request here
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aRequest, "no request?");
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
NS_PRECONDITION(aRequest == mCurrentRequest || aRequest == mPendingRequest,
|
|
|
|
"Unknown request");
|
|
|
|
}
|
2012-10-12 05:58:24 +04:00
|
|
|
|
2013-01-18 21:49:59 +04:00
|
|
|
{
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
|
|
|
|
for (ImageObserver* observer = &mObserverList, *next; observer;
|
|
|
|
observer = next) {
|
|
|
|
next = observer->mNext;
|
|
|
|
if (observer->mObserver) {
|
|
|
|
observer->mObserver->Notify(aRequest, aType, aData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-12 05:58:24 +04:00
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
|
2012-10-12 20:11:22 +04:00
|
|
|
// Have to check for state changes here, since we might have been in
|
|
|
|
// the LOADING state before.
|
|
|
|
UpdateImageState(true);
|
|
|
|
}
|
2012-10-12 05:58:24 +04:00
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::LOAD_COMPLETE) {
|
2012-10-12 20:11:22 +04:00
|
|
|
uint32_t reqStatus;
|
|
|
|
aRequest->GetImageStatus(&reqStatus);
|
2014-06-25 04:37:03 +04:00
|
|
|
/* triage STATUS_ERROR */
|
|
|
|
if (reqStatus & imgIRequest::STATUS_ERROR) {
|
|
|
|
nsresult errorCode = NS_OK;
|
|
|
|
aRequest->GetImageErrorCode(&errorCode);
|
|
|
|
|
|
|
|
/* Handle image not loading error because source was a tracking URL.
|
2014-08-08 00:35:03 +04:00
|
|
|
* We make a note of this image node by including it in a dedicated
|
|
|
|
* array of blocked tracking nodes under its parent document.
|
2014-06-25 04:37:03 +04:00
|
|
|
*/
|
|
|
|
if (errorCode == NS_ERROR_TRACKING_URI) {
|
|
|
|
nsCOMPtr<nsIContent> thisNode
|
|
|
|
= do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
|
|
|
|
|
|
|
nsIDocument *doc = GetOurOwnerDoc();
|
|
|
|
doc->AddBlockedTrackingNode(thisNode);
|
|
|
|
}
|
|
|
|
}
|
2012-10-12 20:11:22 +04:00
|
|
|
nsresult status =
|
|
|
|
reqStatus & imgIRequest::STATUS_ERROR ? NS_ERROR_FAILURE : NS_OK;
|
2014-11-18 01:29:56 +03:00
|
|
|
return OnLoadComplete(aRequest, status);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
2012-10-12 05:58:24 +04:00
|
|
|
|
2014-08-28 22:43:21 +04:00
|
|
|
if (aType == imgINotificationObserver::DECODE_COMPLETE) {
|
2015-06-03 20:42:07 +03:00
|
|
|
nsCOMPtr<imgIContainer> container;
|
|
|
|
aRequest->GetImage(getter_AddRefs(container));
|
|
|
|
if (container) {
|
|
|
|
container->PropagateUseCounters(GetOurOwnerDoc());
|
|
|
|
}
|
|
|
|
|
2013-02-15 20:48:17 +04:00
|
|
|
UpdateImageState(true);
|
|
|
|
}
|
|
|
|
|
2012-10-12 05:58:24 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
nsresult
|
2014-11-18 01:29:56 +03:00
|
|
|
nsImageLoadingContent::OnLoadComplete(imgIRequest* aRequest, nsresult aStatus)
|
2012-10-12 05:58:24 +04:00
|
|
|
{
|
2012-10-12 20:11:22 +04:00
|
|
|
uint32_t oldStatus;
|
|
|
|
aRequest->GetImageStatus(&oldStatus);
|
|
|
|
|
|
|
|
//XXXjdm This occurs when we have a pending request created, then another
|
|
|
|
// pending request replaces it before the first one is finished.
|
|
|
|
// This begs the question of what the correct behaviour is; we used
|
|
|
|
// to not have to care because we ran this code in OnStopDecode which
|
|
|
|
// wasn't called when the first request was cancelled. For now, I choose
|
|
|
|
// to punt when the given request doesn't appear to have terminated in
|
|
|
|
// an expected state.
|
|
|
|
if (!(oldStatus & (imgIRequest::STATUS_ERROR | imgIRequest::STATUS_LOAD_COMPLETE)))
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// Our state may change. Watch it.
|
2011-10-17 18:59:28 +04:00
|
|
|
AutoStateChanger changer(this, true);
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// If the pending request is loaded, switch to it.
|
|
|
|
if (aRequest == mPendingRequest) {
|
2012-03-20 02:22:02 +04:00
|
|
|
MakePendingRequestCurrent();
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aRequest == mCurrentRequest,
|
|
|
|
"One way or another, we should be current by now");
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2015-06-20 01:55:12 +03:00
|
|
|
// Fire the appropriate DOM event.
|
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
|
|
|
FireEvent(NS_LITERAL_STRING("load"));
|
2016-08-16 07:01:12 +03:00
|
|
|
|
|
|
|
// Do not fire loadend event for multipart/x-mixed-replace image streams.
|
|
|
|
bool isMultipart;
|
|
|
|
if (NS_FAILED(aRequest->GetMultipart(&isMultipart)) || !isMultipart) {
|
|
|
|
FireEvent(NS_LITERAL_STRING("loadend"));
|
|
|
|
}
|
2003-03-19 04:08:22 +03:00
|
|
|
} else {
|
2015-06-20 01:55:12 +03:00
|
|
|
FireEvent(NS_LITERAL_STRING("error"));
|
2016-08-16 07:01:12 +03:00
|
|
|
FireEvent(NS_LITERAL_STRING("loadend"));
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
2012-08-14 02:58:53 +04:00
|
|
|
nsCOMPtr<nsINode> thisNode = do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
2010-08-13 17:36:13 +04:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(thisNode->AsElement());
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-03 04:29:50 +03:00
|
|
|
static bool
|
|
|
|
ImageIsAnimated(imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
if (!aRequest) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
if (NS_SUCCEEDED(aRequest->GetImage(getter_AddRefs(image)))) {
|
|
|
|
bool isAnimated = false;
|
|
|
|
nsresult rv = image->GetAnimated(&isAnimated);
|
|
|
|
if (NS_SUCCEEDED(rv) && isAnimated) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-25 04:59:22 +04:00
|
|
|
void
|
|
|
|
nsImageLoadingContent::OnUnlockedDraw()
|
|
|
|
{
|
2016-03-26 00:49:43 +03:00
|
|
|
// It's OK for non-animated images to wait until the next frame visibility
|
2015-06-03 04:29:50 +03:00
|
|
|
// update to become locked. (And that's preferable, since in the case of
|
|
|
|
// scrolling it keeps memory usage minimal.) For animated images, though, we
|
|
|
|
// want to mark them visible right away so we can call
|
|
|
|
// IncrementAnimationConsumers() on them and they'll start animating.
|
|
|
|
if (!ImageIsAnimated(mCurrentRequest) && !ImageIsAnimated(mPendingRequest)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-26 00:49:43 +03:00
|
|
|
nsIFrame* frame = GetOurPrimaryFrame();
|
|
|
|
if (!frame) {
|
2013-02-25 04:59:22 +04:00
|
|
|
return;
|
2016-03-26 00:49:43 +03:00
|
|
|
}
|
|
|
|
|
2016-09-12 08:19:08 +03:00
|
|
|
if (frame->GetVisibility() == Visibility::APPROXIMATELY_VISIBLE) {
|
|
|
|
// This frame is already marked visible; there's nothing to do.
|
|
|
|
return;
|
2016-03-26 00:49:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext* presContext = frame->PresContext();
|
|
|
|
if (!presContext) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-25 04:59:22 +04:00
|
|
|
|
|
|
|
nsIPresShell* presShell = presContext->PresShell();
|
2016-03-26 00:49:43 +03:00
|
|
|
if (!presShell) {
|
2013-02-25 04:59:22 +04:00
|
|
|
return;
|
2016-03-26 00:49:43 +03:00
|
|
|
}
|
2013-02-25 04:59:22 +04:00
|
|
|
|
2016-09-12 08:19:08 +03:00
|
|
|
presShell->EnsureFrameInApproximatelyVisibleList(frame);
|
2013-02-25 04:59:22 +04:00
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
nsresult
|
2011-11-10 01:39:15 +04:00
|
|
|
nsImageLoadingContent::OnImageIsAnimated(imgIRequest *aRequest)
|
|
|
|
{
|
2011-11-10 01:39:16 +04:00
|
|
|
bool* requestFlag = GetRegisteredFlagForRequest(aRequest);
|
|
|
|
if (requestFlag) {
|
|
|
|
nsLayoutUtils::RegisterImageRequest(GetFramePresContext(),
|
|
|
|
aRequest, requestFlag);
|
|
|
|
}
|
|
|
|
|
2011-11-10 01:39:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
/*
|
2003-04-02 07:27:20 +04:00
|
|
|
* nsIImageLoadingContent impl
|
2003-03-19 04:08:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsImageLoadingContent::GetLoadingEnabled(bool *aLoadingEnabled)
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
|
|
|
*aLoadingEnabled = mLoadingEnabled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsImageLoadingContent::SetLoadingEnabled(bool aLoadingEnabled)
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
2015-02-13 05:44:32 +03:00
|
|
|
if (nsContentUtils::GetImgLoaderForChannel(nullptr, nullptr)) {
|
2003-05-02 23:21:00 +04:00
|
|
|
mLoadingEnabled = aLoadingEnabled;
|
2005-09-21 23:14:30 +04:00
|
|
|
}
|
2003-03-19 04:08:22 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsImageLoadingContent::GetImageBlockingStatus(int16_t* aStatus)
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
2005-03-02 07:05:12 +03:00
|
|
|
NS_PRECONDITION(aStatus, "Null out param");
|
2013-01-02 23:30:02 +04:00
|
|
|
*aStatus = ImageBlockingStatus();
|
2003-03-19 04:08:22 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-07-24 21:30:52 +04:00
|
|
|
|
2014-11-25 10:42:43 +03:00
|
|
|
static void
|
|
|
|
ReplayImageStatus(imgIRequest* aRequest, imgINotificationObserver* aObserver)
|
|
|
|
{
|
|
|
|
if (!aRequest) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t status = 0;
|
|
|
|
nsresult rv = aRequest->GetImageStatus(&status);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & imgIRequest::STATUS_SIZE_AVAILABLE) {
|
|
|
|
aObserver->Notify(aRequest, imgINotificationObserver::SIZE_AVAILABLE, nullptr);
|
|
|
|
}
|
|
|
|
if (status & imgIRequest::STATUS_FRAME_COMPLETE) {
|
|
|
|
aObserver->Notify(aRequest, imgINotificationObserver::FRAME_COMPLETE, nullptr);
|
|
|
|
}
|
|
|
|
if (status & imgIRequest::STATUS_HAS_TRANSPARENCY) {
|
|
|
|
aObserver->Notify(aRequest, imgINotificationObserver::HAS_TRANSPARENCY, nullptr);
|
|
|
|
}
|
|
|
|
if (status & imgIRequest::STATUS_IS_ANIMATED) {
|
|
|
|
aObserver->Notify(aRequest, imgINotificationObserver::IS_ANIMATED, nullptr);
|
|
|
|
}
|
|
|
|
if (status & imgIRequest::STATUS_DECODE_COMPLETE) {
|
|
|
|
aObserver->Notify(aRequest, imgINotificationObserver::DECODE_COMPLETE, nullptr);
|
|
|
|
}
|
|
|
|
if (status & imgIRequest::STATUS_LOAD_COMPLETE) {
|
|
|
|
aObserver->Notify(aRequest, imgINotificationObserver::LOAD_COMPLETE, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
NS_IMETHODIMP
|
2012-10-12 20:11:22 +04:00
|
|
|
nsImageLoadingContent::AddObserver(imgINotificationObserver* aObserver)
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aObserver);
|
|
|
|
|
|
|
|
if (!mObserverList.mObserver) {
|
|
|
|
// Don't touch the linking of the list!
|
2014-11-25 10:42:43 +03:00
|
|
|
mObserverList.mObserver = aObserver;
|
|
|
|
|
|
|
|
ReplayImageStatus(mCurrentRequest, aObserver);
|
|
|
|
ReplayImageStatus(mPendingRequest, aObserver);
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise we have to create a new entry
|
|
|
|
|
|
|
|
ImageObserver* observer = &mObserverList;
|
|
|
|
while (observer->mNext) {
|
|
|
|
observer = observer->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
observer->mNext = new ImageObserver(aObserver);
|
2014-11-25 10:42:43 +03:00
|
|
|
ReplayImageStatus(mCurrentRequest, aObserver);
|
|
|
|
ReplayImageStatus(mPendingRequest, aObserver);
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-10-12 20:11:22 +04:00
|
|
|
nsImageLoadingContent::RemoveObserver(imgINotificationObserver* aObserver)
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aObserver);
|
|
|
|
|
|
|
|
if (mObserverList.mObserver == aObserver) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mObserverList.mObserver = nullptr;
|
2003-03-19 04:08:22 +03:00
|
|
|
// Don't touch the linking of the list!
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise have to find it and splice it out
|
|
|
|
ImageObserver* observer = &mObserverList;
|
|
|
|
while (observer->mNext && observer->mNext->mObserver != aObserver) {
|
|
|
|
observer = observer->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point, we are pointing to the list element whose mNext is
|
|
|
|
// the right observer (assuming of course that mNext is not null)
|
|
|
|
if (observer->mNext) {
|
|
|
|
// splice it out
|
|
|
|
ImageObserver* oldObserver = observer->mNext;
|
|
|
|
observer->mNext = oldObserver->mNext;
|
2012-07-30 18:20:58 +04:00
|
|
|
oldObserver->mNext = nullptr; // so we don't destroy them all
|
2003-03-19 04:08:22 +03:00
|
|
|
delete oldObserver;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
2010-05-23 23:26:15 +04:00
|
|
|
NS_WARNING("Asked to remove nonexistent observer");
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-02 23:30:02 +04:00
|
|
|
already_AddRefed<imgIRequest>
|
2012-08-22 19:56:38 +04:00
|
|
|
nsImageLoadingContent::GetRequest(int32_t aRequestType,
|
2013-01-02 23:30:02 +04:00
|
|
|
ErrorResult& aError)
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
2013-01-02 23:30:02 +04:00
|
|
|
nsCOMPtr<imgIRequest> request;
|
2003-03-19 04:08:22 +03:00
|
|
|
switch(aRequestType) {
|
|
|
|
case CURRENT_REQUEST:
|
2013-01-02 23:30:02 +04:00
|
|
|
request = mCurrentRequest;
|
2003-03-19 04:08:22 +03:00
|
|
|
break;
|
|
|
|
case PENDING_REQUEST:
|
2013-01-02 23:30:02 +04:00
|
|
|
request = mPendingRequest;
|
2003-03-19 04:08:22 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unknown request type");
|
2013-01-02 23:30:02 +04:00
|
|
|
aError.Throw(NS_ERROR_UNEXPECTED);
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
2013-01-02 23:30:02 +04:00
|
|
|
|
|
|
|
return request.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::GetRequest(int32_t aRequestType,
|
|
|
|
imgIRequest** aRequest)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRequest);
|
|
|
|
|
|
|
|
ErrorResult result;
|
2014-03-15 23:00:15 +04:00
|
|
|
*aRequest = GetRequest(aRequestType, result).take();
|
2013-01-02 23:30:02 +04:00
|
|
|
|
2015-04-27 16:18:51 +03:00
|
|
|
return result.StealNSResult();
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
2015-03-19 04:29:32 +03:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
nsImageLoadingContent::CurrentRequestHasSize()
|
|
|
|
{
|
|
|
|
return HaveSize(mCurrentRequest);
|
|
|
|
}
|
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsImageLoadingContent::FrameCreated(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame, "aFrame is null");
|
|
|
|
|
2013-09-15 04:05:05 +04:00
|
|
|
mFrameCreateCalled = true;
|
|
|
|
|
|
|
|
TrackImage(mCurrentRequest);
|
|
|
|
TrackImage(mPendingRequest);
|
2013-02-25 04:59:21 +04:00
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
// We need to make sure that our image request is registered, if it should
|
|
|
|
// be registered.
|
2013-09-15 04:05:05 +04:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2011-11-10 01:39:16 +04:00
|
|
|
if (mCurrentRequest) {
|
|
|
|
nsLayoutUtils::RegisterImageRequestIfAnimated(presContext, mCurrentRequest,
|
|
|
|
&mCurrentRequestRegistered);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPendingRequest) {
|
|
|
|
nsLayoutUtils::RegisterImageRequestIfAnimated(presContext, mPendingRequest,
|
|
|
|
&mPendingRequestRegistered);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsImageLoadingContent::FrameDestroyed(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame, "aFrame is null");
|
|
|
|
|
2013-09-15 04:05:05 +04:00
|
|
|
mFrameCreateCalled = false;
|
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
// We need to make sure that our image request is deregistered.
|
2014-04-15 09:24:01 +04:00
|
|
|
nsPresContext* presContext = GetFramePresContext();
|
2011-11-10 01:39:16 +04:00
|
|
|
if (mCurrentRequest) {
|
2014-04-15 09:24:01 +04:00
|
|
|
nsLayoutUtils::DeregisterImageRequest(presContext,
|
2011-11-10 01:39:16 +04:00
|
|
|
mCurrentRequest,
|
|
|
|
&mCurrentRequestRegistered);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPendingRequest) {
|
2014-04-15 09:24:01 +04:00
|
|
|
nsLayoutUtils::DeregisterImageRequest(presContext,
|
2011-11-10 01:39:16 +04:00
|
|
|
mPendingRequest,
|
|
|
|
&mPendingRequestRegistered);
|
|
|
|
}
|
2013-02-14 00:18:08 +04:00
|
|
|
|
2013-02-25 04:59:21 +04:00
|
|
|
UntrackImage(mCurrentRequest);
|
|
|
|
UntrackImage(mPendingRequest);
|
2013-02-25 04:59:23 +04:00
|
|
|
|
2014-04-15 09:33:45 +04:00
|
|
|
nsIPresShell* presShell = presContext ? presContext->GetPresShell() : nullptr;
|
2014-04-15 09:24:01 +04:00
|
|
|
if (presShell) {
|
2016-09-12 08:19:08 +03:00
|
|
|
presShell->RemoveFrameFromApproximatelyVisibleList(aFrame);
|
2013-02-25 04:59:23 +04:00
|
|
|
}
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2014-08-20 01:49:38 +04:00
|
|
|
/* static */
|
|
|
|
nsContentPolicyType
|
|
|
|
nsImageLoadingContent::PolicyTypeForLoad(ImageLoadType aImageLoadType)
|
|
|
|
{
|
|
|
|
if (aImageLoadType == eImageLoadType_Imageset) {
|
|
|
|
return nsIContentPolicy::TYPE_IMAGESET;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aImageLoadType == eImageLoadType_Normal,
|
|
|
|
"Unknown ImageLoadType type in PolicyTypeForLoad");
|
2015-09-21 00:55:59 +03:00
|
|
|
return nsIContentPolicy::TYPE_INTERNAL_IMAGE;
|
2014-08-20 01:49:38 +04:00
|
|
|
}
|
|
|
|
|
2013-01-02 23:30:02 +04:00
|
|
|
int32_t
|
2003-03-19 04:08:22 +03:00
|
|
|
nsImageLoadingContent::GetRequestType(imgIRequest* aRequest,
|
2013-01-02 23:30:02 +04:00
|
|
|
ErrorResult& aError)
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
|
|
|
if (aRequest == mCurrentRequest) {
|
2013-01-02 23:30:02 +04:00
|
|
|
return CURRENT_REQUEST;
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aRequest == mPendingRequest) {
|
2013-01-02 23:30:02 +04:00
|
|
|
return PENDING_REQUEST;
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ERROR("Unknown request");
|
2013-01-02 23:30:02 +04:00
|
|
|
aError.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return UNKNOWN_REQUEST;
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
2004-06-05 21:57:00 +04:00
|
|
|
NS_IMETHODIMP
|
2013-01-02 23:30:02 +04:00
|
|
|
nsImageLoadingContent::GetRequestType(imgIRequest* aRequest,
|
|
|
|
int32_t* aRequestType)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aRequestType, "Null out param");
|
|
|
|
|
|
|
|
ErrorResult result;
|
|
|
|
*aRequestType = GetRequestType(aRequest, result);
|
2015-04-27 16:18:51 +03:00
|
|
|
return result.StealNSResult();
|
2013-01-02 23:30:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsImageLoadingContent::GetCurrentURI(ErrorResult& aError)
|
2004-06-05 21:57:00 +04:00
|
|
|
{
|
2013-01-02 23:30:02 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2005-09-21 23:14:30 +04:00
|
|
|
if (mCurrentRequest) {
|
2013-01-02 23:30:02 +04:00
|
|
|
mCurrentRequest->GetURI(getter_AddRefs(uri));
|
|
|
|
} else if (mCurrentURI) {
|
|
|
|
nsresult rv = NS_EnsureSafeToReturn(mCurrentURI, getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
}
|
2005-09-21 23:14:30 +04:00
|
|
|
}
|
2004-06-05 21:57:00 +04:00
|
|
|
|
2013-01-02 23:30:02 +04:00
|
|
|
return uri.forget();
|
2004-06-05 21:57:00 +04:00
|
|
|
}
|
|
|
|
|
2003-04-02 07:27:20 +04:00
|
|
|
NS_IMETHODIMP
|
2013-01-02 23:30:02 +04:00
|
|
|
nsImageLoadingContent::GetCurrentURI(nsIURI** aURI)
|
2003-04-02 07:27:20 +04:00
|
|
|
{
|
2013-01-02 23:30:02 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2011-02-01 07:50:01 +03:00
|
|
|
|
2013-01-02 23:30:02 +04:00
|
|
|
ErrorResult result;
|
2014-03-15 23:00:15 +04:00
|
|
|
*aURI = GetCurrentURI(result).take();
|
2015-04-27 16:18:51 +03:00
|
|
|
return result.StealNSResult();
|
2013-01-02 23:30:02 +04:00
|
|
|
}
|
|
|
|
|
2016-09-22 18:58:35 +03:00
|
|
|
NS_IMETHODIMP
|
2013-01-02 23:30:02 +04:00
|
|
|
nsImageLoadingContent::LoadImageWithChannel(nsIChannel* aChannel,
|
2016-09-22 18:58:35 +03:00
|
|
|
nsIStreamListener** aListener)
|
2013-01-02 23:30:02 +04:00
|
|
|
{
|
2015-02-13 05:44:32 +03:00
|
|
|
imgLoader* loader =
|
|
|
|
nsContentUtils::GetImgLoaderForChannel(aChannel, GetOurOwnerDoc());
|
|
|
|
if (!loader) {
|
2016-09-22 18:58:35 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2005-09-21 23:14:30 +04:00
|
|
|
}
|
2003-05-02 23:21:00 +04:00
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetOurOwnerDoc();
|
2003-07-29 01:09:56 +04:00
|
|
|
if (!doc) {
|
|
|
|
// Don't bother
|
2016-09-22 18:58:35 +03:00
|
|
|
*aListener = nullptr;
|
|
|
|
return NS_OK;
|
2003-07-29 01:09:56 +04:00
|
|
|
}
|
2005-08-19 18:55:07 +04:00
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// XXX what should we do with content policies here, if anything?
|
|
|
|
// Shouldn't that be done before the start of the load?
|
|
|
|
// XXX what about shouldProcess?
|
2003-04-02 07:27:20 +04:00
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// Our state might change. Watch it.
|
2011-10-17 18:59:28 +04:00
|
|
|
AutoStateChanger changer(this, true);
|
2003-04-02 07:27:20 +04:00
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// Do the load.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy>& req = PrepareNextRequest(eImageLoadType_Normal);
|
2015-02-13 05:44:32 +03:00
|
|
|
nsresult rv = loader->
|
2016-09-22 18:58:35 +03:00
|
|
|
LoadImageWithChannel(aChannel, this, doc, aListener, getter_AddRefs(req));
|
2010-08-04 04:40:29 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
TrackImage(req);
|
2012-06-14 05:12:37 +04:00
|
|
|
ResetAnimationIfNeeded();
|
2016-09-22 18:58:35 +03:00
|
|
|
return NS_OK;
|
2010-07-31 21:54:59 +04:00
|
|
|
}
|
2003-04-02 07:27:20 +04:00
|
|
|
|
2016-09-22 18:58:35 +03:00
|
|
|
MOZ_ASSERT(!req, "Shouldn't have non-null request here");
|
|
|
|
// If we don't have a current URI, we might as well store this URI so people
|
|
|
|
// know what we tried (and failed) to load.
|
|
|
|
if (!mCurrentRequest)
|
|
|
|
aChannel->GetURI(getter_AddRefs(mCurrentURI));
|
2013-01-02 23:30:02 +04:00
|
|
|
|
2016-09-22 18:58:35 +03:00
|
|
|
FireEvent(NS_LITERAL_STRING("error"));
|
|
|
|
FireEvent(NS_LITERAL_STRING("loadend"));
|
|
|
|
return rv;
|
2013-01-02 23:30:02 +04:00
|
|
|
}
|
2011-02-01 07:50:01 +03:00
|
|
|
|
2013-01-02 23:30:02 +04:00
|
|
|
void
|
2014-08-20 01:49:38 +04:00
|
|
|
nsImageLoadingContent::ForceReload(const mozilla::dom::Optional<bool>& aNotify,
|
|
|
|
mozilla::ErrorResult& aError)
|
2013-01-02 23:30:02 +04:00
|
|
|
{
|
2006-09-08 02:51:57 +04:00
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
|
|
|
GetCurrentURI(getter_AddRefs(currentURI));
|
|
|
|
if (!currentURI) {
|
2013-01-02 23:30:02 +04:00
|
|
|
aError.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return;
|
2006-09-08 02:51:57 +04:00
|
|
|
}
|
|
|
|
|
2014-08-20 01:49:38 +04:00
|
|
|
// defaults to true
|
|
|
|
bool notify = !aNotify.WasPassed() || aNotify.Value();
|
|
|
|
|
|
|
|
// We keep this flag around along with the old URI even for failed requests
|
|
|
|
// without a live request object
|
|
|
|
ImageLoadType loadType = \
|
|
|
|
(mCurrentRequestFlags & REQUEST_IS_IMAGESET) ? eImageLoadType_Imageset
|
|
|
|
: eImageLoadType_Normal;
|
2016-10-05 05:06:27 +03:00
|
|
|
nsresult rv = LoadImage(currentURI, true, notify, loadType, true, nullptr,
|
2014-08-20 01:49:38 +04:00
|
|
|
nsIRequest::VALIDATE_ALWAYS);
|
2013-01-02 23:30:02 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-20 01:49:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::ForceReload(bool aNotify /* = true */,
|
|
|
|
uint8_t aArgc)
|
2013-01-02 23:30:02 +04:00
|
|
|
{
|
2014-08-20 01:49:38 +04:00
|
|
|
mozilla::dom::Optional<bool> notify;
|
|
|
|
if (aArgc >= 1) {
|
|
|
|
notify.Construct() = aNotify;
|
|
|
|
}
|
|
|
|
|
2013-01-02 23:30:02 +04:00
|
|
|
ErrorResult result;
|
2014-08-20 01:49:38 +04:00
|
|
|
ForceReload(notify, result);
|
2015-04-27 16:18:51 +03:00
|
|
|
return result.StealNSResult();
|
2006-09-08 02:51:57 +04:00
|
|
|
}
|
|
|
|
|
2012-08-14 02:58:53 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::BlockOnload(imgIRequest* aRequest)
|
|
|
|
{
|
2013-03-13 02:13:40 +04:00
|
|
|
if (aRequest == mCurrentRequest) {
|
|
|
|
NS_ASSERTION(!(mCurrentRequestFlags & REQUEST_BLOCKS_ONLOAD),
|
|
|
|
"Double BlockOnload!?");
|
|
|
|
mCurrentRequestFlags |= REQUEST_BLOCKS_ONLOAD;
|
|
|
|
} else if (aRequest == mPendingRequest) {
|
|
|
|
NS_ASSERTION(!(mPendingRequestFlags & REQUEST_BLOCKS_ONLOAD),
|
|
|
|
"Double BlockOnload!?");
|
|
|
|
mPendingRequestFlags |= REQUEST_BLOCKS_ONLOAD;
|
|
|
|
} else {
|
2012-08-14 02:58:53 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = GetOurCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->BlockOnload();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::UnblockOnload(imgIRequest* aRequest)
|
|
|
|
{
|
2013-03-13 02:13:40 +04:00
|
|
|
if (aRequest == mCurrentRequest) {
|
|
|
|
NS_ASSERTION(mCurrentRequestFlags & REQUEST_BLOCKS_ONLOAD,
|
|
|
|
"Double UnblockOnload!?");
|
|
|
|
mCurrentRequestFlags &= ~REQUEST_BLOCKS_ONLOAD;
|
|
|
|
} else if (aRequest == mPendingRequest) {
|
|
|
|
NS_ASSERTION(mPendingRequestFlags & REQUEST_BLOCKS_ONLOAD,
|
|
|
|
"Double UnblockOnload!?");
|
|
|
|
mPendingRequestFlags &= ~REQUEST_BLOCKS_ONLOAD;
|
|
|
|
} else {
|
2012-08-14 02:58:53 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = GetOurCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->UnblockOnload(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
/*
|
|
|
|
* Non-interface methods
|
|
|
|
*/
|
2005-09-18 22:05:40 +04:00
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
nsresult
|
2006-01-01 14:25:43 +03:00
|
|
|
nsImageLoadingContent::LoadImage(const nsAString& aNewURI,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aForce,
|
2014-08-20 01:49:38 +04:00
|
|
|
bool aNotify,
|
|
|
|
ImageLoadType aImageLoadType)
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
2003-07-03 06:45:34 +04:00
|
|
|
// First, get a document (needed for security checks and the like)
|
2012-08-14 02:11:50 +04:00
|
|
|
nsIDocument* doc = GetOurOwnerDoc();
|
2003-04-15 05:09:09 +04:00
|
|
|
if (!doc) {
|
|
|
|
// No reason to bother, I think...
|
2003-07-29 01:09:56 +04:00
|
|
|
return NS_OK;
|
2003-04-15 05:09:09 +04:00
|
|
|
}
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2016-10-06 07:30:35 +03:00
|
|
|
// Pending load/error events need to be canceled in some situations. This
|
|
|
|
// is not documented in the spec, but can cause site compat problems if not
|
|
|
|
// done. See bug 1309461 and https://github.com/whatwg/html/issues/1872.
|
|
|
|
CancelPendingEvent();
|
|
|
|
|
2016-09-08 11:27:03 +03:00
|
|
|
if (aNewURI.IsEmpty()) {
|
|
|
|
// Cancel image requests and then fire only error event per spec.
|
|
|
|
CancelImageRequests(aNotify);
|
2016-10-06 07:30:35 +03:00
|
|
|
// Mark error event as cancelable only for src="" case, since only this
|
|
|
|
// error causes site compat problem (bug 1308069) for now.
|
|
|
|
FireEvent(NS_LITERAL_STRING("error"), true);
|
2016-09-08 11:27:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-10-05 05:06:27 +03:00
|
|
|
// Fire loadstart event
|
|
|
|
FireEvent(NS_LITERAL_STRING("loadstart"));
|
|
|
|
|
|
|
|
// Parse the URI string to get image URI
|
2003-03-19 04:08:22 +03:00
|
|
|
nsCOMPtr<nsIURI> imageURI;
|
2005-09-21 23:14:30 +04:00
|
|
|
nsresult rv = StringToURI(aNewURI, doc, getter_AddRefs(imageURI));
|
2017-01-09 06:50:55 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// XXXbiesi fire onerror if that failed?
|
2005-09-21 23:14:30 +04:00
|
|
|
|
2006-05-31 19:58:43 +04:00
|
|
|
NS_TryToSetImmutable(imageURI);
|
|
|
|
|
2016-10-05 05:06:27 +03:00
|
|
|
return LoadImage(imageURI, aForce, aNotify, aImageLoadType, false, doc);
|
2005-09-21 23:14:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-01-01 14:25:43 +03:00
|
|
|
nsImageLoadingContent::LoadImage(nsIURI* aNewURI,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aForce,
|
|
|
|
bool aNotify,
|
2014-08-20 01:49:38 +04:00
|
|
|
ImageLoadType aImageLoadType,
|
2016-10-05 05:06:27 +03:00
|
|
|
bool aLoadStart,
|
2006-09-08 02:51:57 +04:00
|
|
|
nsIDocument* aDocument,
|
|
|
|
nsLoadFlags aLoadFlags)
|
2005-09-21 23:14:30 +04:00
|
|
|
{
|
2016-10-06 07:30:35 +03:00
|
|
|
// Pending load/error events need to be canceled in some situations. This
|
|
|
|
// is not documented in the spec, but can cause site compat problems if not
|
|
|
|
// done. See bug 1309461 and https://github.com/whatwg/html/issues/1872.
|
|
|
|
CancelPendingEvent();
|
|
|
|
|
2016-10-05 05:06:27 +03:00
|
|
|
// Fire loadstart event if required
|
|
|
|
if (aLoadStart) {
|
|
|
|
FireEvent(NS_LITERAL_STRING("loadstart"));
|
|
|
|
}
|
|
|
|
|
2005-09-21 23:14:30 +04:00
|
|
|
if (!mLoadingEnabled) {
|
2009-11-20 07:39:11 +03:00
|
|
|
// XXX Why fire an error here? seems like the callers to SetLoadingEnabled
|
|
|
|
// don't want/need it.
|
2006-06-01 22:35:21 +04:00
|
|
|
FireEvent(NS_LITERAL_STRING("error"));
|
2016-08-16 07:01:12 +03:00
|
|
|
FireEvent(NS_LITERAL_STRING("loadend"));
|
2005-09-21 23:14:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
NS_ASSERTION(!aDocument || aDocument == GetOurOwnerDoc(),
|
2005-09-21 23:14:30 +04:00
|
|
|
"Bogus document passed in");
|
|
|
|
// First, get a document (needed for security checks and the like)
|
|
|
|
if (!aDocument) {
|
2012-08-14 02:11:50 +04:00
|
|
|
aDocument = GetOurOwnerDoc();
|
2005-09-21 23:14:30 +04:00
|
|
|
if (!aDocument) {
|
|
|
|
// No reason to bother, I think...
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// URI equality check.
|
|
|
|
//
|
|
|
|
// We skip the equality check if our current image was blocked, since in that
|
|
|
|
// case we really do want to try loading again.
|
2005-04-11 20:37:27 +04:00
|
|
|
if (!aForce && NS_CP_ACCEPTED(mImageBlockingStatus)) {
|
2005-04-06 06:55:02 +04:00
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
|
|
|
GetCurrentURI(getter_AddRefs(currentURI));
|
2011-09-29 10:19:26 +04:00
|
|
|
bool equal;
|
2005-04-06 06:55:02 +04:00
|
|
|
if (currentURI &&
|
2005-09-21 23:14:30 +04:00
|
|
|
NS_SUCCEEDED(currentURI->Equals(aNewURI, &equal)) &&
|
2005-04-06 06:55:02 +04:00
|
|
|
equal) {
|
|
|
|
// Nothing to do here.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// From this point on, our image state could change. Watch it.
|
2005-09-18 22:05:40 +04:00
|
|
|
AutoStateChanger changer(this, aNotify);
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// Sanity check.
|
|
|
|
//
|
|
|
|
// We use the principal of aDocument to avoid having to QI |this| an extra
|
|
|
|
// time. It should always be the same as the principal of this node.
|
2007-07-03 22:45:39 +04:00
|
|
|
#ifdef DEBUG
|
2012-08-14 02:58:53 +04:00
|
|
|
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(thisContent &&
|
|
|
|
thisContent->NodePrincipal() == aDocument->NodePrincipal(),
|
|
|
|
"Principal mismatch?");
|
2007-07-03 22:45:39 +04:00
|
|
|
#endif
|
2010-07-31 21:54:59 +04:00
|
|
|
|
|
|
|
// Are we blocked?
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t cpDecision = nsIContentPolicy::REJECT_REQUEST;
|
2014-08-20 01:49:38 +04:00
|
|
|
nsContentPolicyType policyType = PolicyTypeForLoad(aImageLoadType);
|
|
|
|
|
2012-08-14 02:58:53 +04:00
|
|
|
nsContentUtils::CanLoadImage(aNewURI,
|
|
|
|
static_cast<nsIImageLoadingContent*>(this),
|
|
|
|
aDocument,
|
|
|
|
aDocument->NodePrincipal(),
|
2014-08-20 01:49:38 +04:00
|
|
|
&cpDecision,
|
|
|
|
policyType);
|
2010-07-31 21:54:59 +04:00
|
|
|
if (!NS_CP_ACCEPTED(cpDecision)) {
|
2005-08-18 03:01:09 +04:00
|
|
|
FireEvent(NS_LITERAL_STRING("error"));
|
2016-08-16 07:01:12 +03:00
|
|
|
FireEvent(NS_LITERAL_STRING("loadend"));
|
2010-07-31 21:54:59 +04:00
|
|
|
SetBlockedRequest(aNewURI, cpDecision);
|
2003-03-19 04:08:22 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-14 22:47:35 +04:00
|
|
|
nsLoadFlags loadFlags = aLoadFlags;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t corsmode = GetCORSMode();
|
2012-03-10 20:13:51 +04:00
|
|
|
if (corsmode == CORS_ANONYMOUS) {
|
2011-07-14 22:47:35 +04:00
|
|
|
loadFlags |= imgILoader::LOAD_CORS_ANONYMOUS;
|
2012-03-10 20:13:51 +04:00
|
|
|
} else if (corsmode == CORS_USE_CREDENTIALS) {
|
2011-07-14 22:47:35 +04:00
|
|
|
loadFlags |= imgILoader::LOAD_CORS_USE_CREDENTIALS;
|
|
|
|
}
|
|
|
|
|
2015-06-06 01:25:24 +03:00
|
|
|
// get document wide referrer policy
|
|
|
|
// if referrer attributes are enabled in preferences, load img referrer attribute
|
2015-07-14 04:04:42 +03:00
|
|
|
// if the image does not provide a referrer attribute, ignore this
|
|
|
|
net::ReferrerPolicy referrerPolicy = aDocument->GetReferrerPolicy();
|
|
|
|
net::ReferrerPolicy imgReferrerPolicy = GetImageReferrerPolicy();
|
|
|
|
if (imgReferrerPolicy != net::RP_Unset) {
|
|
|
|
referrerPolicy = imgReferrerPolicy;
|
2015-06-06 01:25:24 +03:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// Not blocked. Do the load.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy>& req = PrepareNextRequest(aImageLoadType);
|
2013-10-16 05:35:44 +04:00
|
|
|
nsCOMPtr<nsIContent> content =
|
|
|
|
do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
2016-04-11 11:58:03 +03:00
|
|
|
nsCOMPtr<nsINode> thisNode =
|
|
|
|
do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
|
|
|
nsresult rv = nsContentUtils::LoadImage(aNewURI,
|
|
|
|
thisNode,
|
|
|
|
aDocument,
|
2015-07-14 04:04:42 +03:00
|
|
|
aDocument->NodePrincipal(),
|
|
|
|
aDocument->GetDocumentURI(),
|
|
|
|
referrerPolicy,
|
|
|
|
this, loadFlags,
|
|
|
|
content->LocalName(),
|
|
|
|
getter_AddRefs(req),
|
|
|
|
policyType);
|
2013-10-16 05:35:44 +04:00
|
|
|
|
2014-11-24 19:57:49 +03:00
|
|
|
// Tell the document to forget about the image preload, if any, for
|
|
|
|
// this URI, now that we might have another imgRequestProxy for it.
|
|
|
|
// That way if we get canceled later the image load won't continue.
|
|
|
|
aDocument->ForgetImagePreload(aNewURI);
|
|
|
|
|
2010-08-04 04:40:29 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
TrackImage(req);
|
2012-06-14 05:12:37 +04:00
|
|
|
ResetAnimationIfNeeded();
|
2012-03-20 02:22:02 +04:00
|
|
|
|
|
|
|
// Handle cases when we just ended up with a pending request but it's
|
|
|
|
// already done. In that situation we have to synchronously switch that
|
|
|
|
// request to being the current request, because websites depend on that
|
|
|
|
// behavior.
|
|
|
|
if (req == mPendingRequest) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t pendingLoadStatus;
|
2012-03-20 02:22:02 +04:00
|
|
|
rv = req->GetImageStatus(&pendingLoadStatus);
|
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
(pendingLoadStatus & imgIRequest::STATUS_LOAD_COMPLETE)) {
|
|
|
|
MakePendingRequestCurrent();
|
|
|
|
MOZ_ASSERT(mCurrentRequest,
|
|
|
|
"How could we not have a current request here?");
|
|
|
|
|
|
|
|
nsImageFrame *f = do_QueryFrame(GetOurPrimaryFrame());
|
|
|
|
if (f) {
|
|
|
|
f->NotifyNewCurrentRequest(mCurrentRequest, NS_OK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-04 04:40:29 +04:00
|
|
|
} else {
|
2013-02-14 00:18:08 +04:00
|
|
|
MOZ_ASSERT(!req, "Shouldn't have non-null request here");
|
2010-07-31 21:54:59 +04:00
|
|
|
// If we don't have a current URI, we might as well store this URI so people
|
|
|
|
// know what we tried (and failed) to load.
|
|
|
|
if (!mCurrentRequest)
|
|
|
|
mCurrentURI = aNewURI;
|
2016-08-16 07:01:12 +03:00
|
|
|
|
2005-08-18 03:01:09 +04:00
|
|
|
FireEvent(NS_LITERAL_STRING("error"));
|
2016-08-16 07:01:12 +03:00
|
|
|
FireEvent(NS_LITERAL_STRING("loadend"));
|
2005-08-18 03:01:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-26 11:25:17 +04:00
|
|
|
nsresult
|
2014-04-03 08:18:36 +04:00
|
|
|
nsImageLoadingContent::ForceImageState(bool aForce,
|
|
|
|
EventStates::InternalType aState)
|
2009-06-26 11:25:17 +04:00
|
|
|
{
|
|
|
|
mIsImageStateForced = aForce;
|
2014-04-03 08:18:36 +04:00
|
|
|
mForcedImageState = EventStates(aState);
|
2009-06-26 11:25:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-03 04:05:19 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::GetNaturalWidth(uint32_t* aNaturalWidth)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNaturalWidth);
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
if (mCurrentRequest) {
|
|
|
|
mCurrentRequest->GetImage(getter_AddRefs(image));
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t width;
|
|
|
|
if (image && NS_SUCCEEDED(image->GetWidth(&width))) {
|
|
|
|
*aNaturalWidth = width;
|
|
|
|
} else {
|
|
|
|
*aNaturalWidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::GetNaturalHeight(uint32_t* aNaturalHeight)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNaturalHeight);
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
if (mCurrentRequest) {
|
|
|
|
mCurrentRequest->GetImage(getter_AddRefs(image));
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t height;
|
|
|
|
if (image && NS_SUCCEEDED(image->GetHeight(&height))) {
|
|
|
|
*aNaturalHeight = height;
|
|
|
|
} else {
|
|
|
|
*aNaturalHeight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2005-09-18 22:05:40 +04:00
|
|
|
nsImageLoadingContent::ImageState() const
|
|
|
|
{
|
2010-10-20 15:26:32 +04:00
|
|
|
if (mIsImageStateForced) {
|
|
|
|
return mForcedImageState;
|
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates states;
|
2010-10-20 15:26:32 +04:00
|
|
|
|
|
|
|
if (mBroken) {
|
|
|
|
states |= NS_EVENT_STATE_BROKEN;
|
|
|
|
}
|
|
|
|
if (mUserDisabled) {
|
|
|
|
states |= NS_EVENT_STATE_USERDISABLED;
|
|
|
|
}
|
|
|
|
if (mSuppressed) {
|
|
|
|
states |= NS_EVENT_STATE_SUPPRESSED;
|
|
|
|
}
|
|
|
|
if (mLoading) {
|
|
|
|
states |= NS_EVENT_STATE_LOADING;
|
|
|
|
}
|
|
|
|
|
|
|
|
return states;
|
2005-09-18 22:05:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsImageLoadingContent::UpdateImageState(bool aNotify)
|
2005-09-18 22:05:40 +04:00
|
|
|
{
|
2010-07-31 21:54:59 +04:00
|
|
|
if (mStateChangerDepth > 0) {
|
2014-11-14 20:59:00 +03:00
|
|
|
// Ignore this call; we'll update our state when the outermost state changer
|
|
|
|
// is destroyed. Need this to work around the fact that some ImageLib
|
2010-07-31 21:54:59 +04:00
|
|
|
// stuff is actually sync and hence we can get OnStopDecode called while
|
|
|
|
// we're still under LoadImage, and OnStopDecode doesn't know anything about
|
|
|
|
// aNotify.
|
|
|
|
// XXX - This machinery should be removed after bug 521604.
|
2005-09-19 01:06:19 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-08-20 01:49:38 +04:00
|
|
|
|
2012-08-14 02:58:53 +04:00
|
|
|
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
2005-09-18 22:05:40 +04:00
|
|
|
if (!thisContent) {
|
|
|
|
return;
|
2003-04-16 05:53:48 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoading = mBroken = mUserDisabled = mSuppressed = false;
|
2014-08-20 01:49:38 +04:00
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
// If we were blocked by server-based content policy, we claim to be
|
|
|
|
// suppressed. If we were blocked by type-based content policy, we claim to
|
|
|
|
// be user-disabled. Otherwise, claim to be broken.
|
|
|
|
if (mImageBlockingStatus == nsIContentPolicy::REJECT_SERVER) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mSuppressed = true;
|
2005-09-18 22:05:40 +04:00
|
|
|
} else if (mImageBlockingStatus == nsIContentPolicy::REJECT_TYPE) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mUserDisabled = true;
|
2005-09-18 22:05:40 +04:00
|
|
|
} else if (!mCurrentRequest) {
|
|
|
|
// No current request means error, since we weren't disabled or suppressed
|
2011-10-17 18:59:28 +04:00
|
|
|
mBroken = true;
|
2005-09-18 22:05:40 +04:00
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t currentLoadStatus;
|
2005-09-18 22:05:40 +04:00
|
|
|
nsresult rv = mCurrentRequest->GetImageStatus(¤tLoadStatus);
|
|
|
|
if (NS_FAILED(rv) || (currentLoadStatus & imgIRequest::STATUS_ERROR)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mBroken = true;
|
2005-10-17 04:50:39 +04:00
|
|
|
} else if (!(currentLoadStatus & imgIRequest::STATUS_SIZE_AVAILABLE)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoading = true;
|
2005-09-18 22:05:40 +04:00
|
|
|
}
|
2003-04-16 05:53:48 +04:00
|
|
|
}
|
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
NS_ASSERTION(thisContent->IsElement(), "Not an element?");
|
|
|
|
thisContent->AsElement()->UpdateState(aNotify);
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
2005-08-19 18:55:07 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsImageLoadingContent::CancelImageRequests(bool aNotify)
|
2005-08-19 18:55:07 +04:00
|
|
|
{
|
2008-12-12 22:41:11 +03:00
|
|
|
AutoStateChanger changer(this, aNotify);
|
2016-03-26 00:49:43 +03:00
|
|
|
ClearPendingRequest(NS_BINDING_ABORTED, Some(OnNonvisible::DISCARD_IMAGES));
|
|
|
|
ClearCurrentRequest(NS_BINDING_ABORTED, Some(OnNonvisible::DISCARD_IMAGES));
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
2005-09-20 06:05:48 +04:00
|
|
|
nsresult
|
2012-10-12 16:43:01 +04:00
|
|
|
nsImageLoadingContent::UseAsPrimaryRequest(imgRequestProxy* aRequest,
|
2014-08-20 01:49:38 +04:00
|
|
|
bool aNotify,
|
|
|
|
ImageLoadType aImageLoadType)
|
2005-09-20 06:05:48 +04:00
|
|
|
{
|
2010-07-31 21:54:59 +04:00
|
|
|
// Our state will change. Watch it.
|
2005-09-20 06:05:48 +04:00
|
|
|
AutoStateChanger changer(this, aNotify);
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// Get rid if our existing images
|
2016-03-26 00:49:43 +03:00
|
|
|
ClearPendingRequest(NS_BINDING_ABORTED, Some(OnNonvisible::DISCARD_IMAGES));
|
|
|
|
ClearCurrentRequest(NS_BINDING_ABORTED, Some(OnNonvisible::DISCARD_IMAGES));
|
2010-07-31 21:54:59 +04:00
|
|
|
|
|
|
|
// Clone the request we were given.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy>& req = PrepareNextRequest(aImageLoadType);
|
2010-08-04 04:40:29 +04:00
|
|
|
nsresult rv = aRequest->Clone(this, getter_AddRefs(req));
|
2013-02-14 00:18:08 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2010-08-04 04:40:29 +04:00
|
|
|
TrackImage(req);
|
2013-02-14 00:18:08 +04:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(!req, "Shouldn't have non-null request here");
|
2010-08-04 04:40:29 +04:00
|
|
|
return rv;
|
2013-02-14 00:18:08 +04:00
|
|
|
}
|
2005-09-20 06:05:48 +04:00
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
return NS_OK;
|
2005-09-20 06:05:48 +04:00
|
|
|
}
|
|
|
|
|
2003-07-29 01:09:56 +04:00
|
|
|
nsIDocument*
|
2012-08-14 02:11:50 +04:00
|
|
|
nsImageLoadingContent::GetOurOwnerDoc()
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
2012-08-14 02:58:53 +04:00
|
|
|
nsCOMPtr<nsIContent> thisContent =
|
|
|
|
do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(thisContent, nullptr);
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2011-10-18 14:53:36 +04:00
|
|
|
return thisContent->OwnerDoc();
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
nsIDocument*
|
|
|
|
nsImageLoadingContent::GetOurCurrentDoc()
|
|
|
|
{
|
2012-08-14 02:58:53 +04:00
|
|
|
nsCOMPtr<nsIContent> thisContent =
|
|
|
|
do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
2012-08-14 02:11:50 +04:00
|
|
|
NS_ENSURE_TRUE(thisContent, nullptr);
|
|
|
|
|
2014-10-02 22:45:44 +04:00
|
|
|
return thisContent->GetComposedDoc();
|
2012-08-14 02:11:50 +04:00
|
|
|
}
|
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsImageLoadingContent::GetOurPrimaryFrame()
|
|
|
|
{
|
2012-08-14 02:58:53 +04:00
|
|
|
nsCOMPtr<nsIContent> thisContent =
|
|
|
|
do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
2011-11-10 01:39:16 +04:00
|
|
|
return thisContent->GetPrimaryFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext* nsImageLoadingContent::GetFramePresContext()
|
|
|
|
{
|
|
|
|
nsIFrame* frame = GetOurPrimaryFrame();
|
|
|
|
if (!frame) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return frame->PresContext();
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
nsresult
|
2005-04-06 06:55:02 +04:00
|
|
|
nsImageLoadingContent::StringToURI(const nsAString& aSpec,
|
2003-03-19 04:08:22 +03:00
|
|
|
nsIDocument* aDocument,
|
|
|
|
nsIURI** aURI)
|
|
|
|
{
|
2003-04-15 05:09:09 +04:00
|
|
|
NS_PRECONDITION(aDocument, "Must have a document");
|
2003-03-19 04:08:22 +03:00
|
|
|
NS_PRECONDITION(aURI, "Null out param");
|
|
|
|
|
|
|
|
// (1) Get the base URI
|
2012-08-14 02:58:53 +04:00
|
|
|
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
2003-07-03 06:45:34 +04:00
|
|
|
NS_ASSERTION(thisContent, "An image loading content must be an nsIContent");
|
2004-01-10 02:54:21 +03:00
|
|
|
nsCOMPtr<nsIURI> baseURL = thisContent->GetBaseURI();
|
2003-03-19 04:08:22 +03:00
|
|
|
|
|
|
|
// (2) Get the charset
|
2005-09-21 23:14:30 +04:00
|
|
|
const nsAFlatCString &charset = aDocument->GetDocumentCharacterSet();
|
2003-03-19 04:08:22 +03:00
|
|
|
|
|
|
|
// (3) Construct the silly thing
|
|
|
|
return NS_NewURI(aURI,
|
|
|
|
aSpec,
|
2012-07-30 18:20:58 +04:00
|
|
|
charset.IsEmpty() ? nullptr : charset.get(),
|
2003-05-02 23:21:00 +04:00
|
|
|
baseURL,
|
2005-09-11 14:08:43 +04:00
|
|
|
nsContentUtils::GetIOService());
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-10-06 07:30:35 +03:00
|
|
|
nsImageLoadingContent::FireEvent(const nsAString& aEventType, bool aIsCancelable)
|
2003-03-19 04:08:22 +03:00
|
|
|
{
|
2015-02-13 05:44:32 +03:00
|
|
|
if (nsContentUtils::DocumentInactiveForImageLoads(GetOurOwnerDoc())) {
|
|
|
|
// Don't bother to fire any events, especially error events.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 04:08:22 +03:00
|
|
|
// We have to fire the event asynchronously so that we won't go into infinite
|
|
|
|
// loops in cases when onLoad handlers reset the src and the new src is in
|
|
|
|
// cache.
|
2003-05-10 00:42:49 +04:00
|
|
|
|
2012-08-14 02:58:53 +04:00
|
|
|
nsCOMPtr<nsINode> thisNode = do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
2003-03-19 04:08:22 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AsyncEventDispatcher> loadBlockingAsyncDispatcher =
|
2014-03-17 10:56:54 +04:00
|
|
|
new LoadBlockingAsyncEventDispatcher(thisNode, aEventType, false, false);
|
|
|
|
loadBlockingAsyncDispatcher->PostDOMEvent();
|
|
|
|
|
2016-10-06 07:30:35 +03:00
|
|
|
if (aIsCancelable) {
|
|
|
|
mPendingEvent = loadBlockingAsyncDispatcher;
|
|
|
|
}
|
|
|
|
|
2010-02-25 05:45:43 +03:00
|
|
|
return NS_OK;
|
2003-03-19 04:08:22 +03:00
|
|
|
}
|
2006-06-01 22:35:21 +04:00
|
|
|
|
2016-10-06 07:30:35 +03:00
|
|
|
void
|
|
|
|
nsImageLoadingContent::AsyncEventRunning(AsyncEventDispatcher* aEvent)
|
|
|
|
{
|
|
|
|
if (mPendingEvent == aEvent) {
|
|
|
|
mPendingEvent = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageLoadingContent::CancelPendingEvent()
|
|
|
|
{
|
|
|
|
if (mPendingEvent) {
|
|
|
|
mPendingEvent->Cancel();
|
|
|
|
mPendingEvent = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy>&
|
2014-08-20 01:49:38 +04:00
|
|
|
nsImageLoadingContent::PrepareNextRequest(ImageLoadType aImageLoadType)
|
2010-07-31 21:54:59 +04:00
|
|
|
{
|
2015-07-08 00:00:08 +03:00
|
|
|
nsImageFrame* frame = do_QueryFrame(GetOurPrimaryFrame());
|
|
|
|
if (frame) {
|
|
|
|
// Detect JavaScript-based animations created by changing the |src|
|
|
|
|
// attribute on a timer.
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
|
|
|
TimeDuration threshold =
|
|
|
|
TimeDuration::FromMilliseconds(
|
|
|
|
gfxPrefs::ImageInferSrcAnimationThresholdMS());
|
|
|
|
|
|
|
|
// If the length of time between request changes is less than the threshold,
|
|
|
|
// then force sync decoding to eliminate flicker from the animation.
|
|
|
|
frame->SetForceSyncDecoding(now - mMostRecentRequestChange < threshold);
|
|
|
|
|
|
|
|
mMostRecentRequestChange = now;
|
|
|
|
}
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// If we don't have a usable current request, get rid of any half-baked
|
|
|
|
// request that might be sitting there and make this one current.
|
|
|
|
if (!HaveSize(mCurrentRequest))
|
2014-08-20 01:49:38 +04:00
|
|
|
return PrepareCurrentRequest(aImageLoadType);
|
2010-07-31 21:54:59 +04:00
|
|
|
|
|
|
|
// Otherwise, make it pending.
|
2014-08-20 01:49:38 +04:00
|
|
|
return PreparePendingRequest(aImageLoadType);
|
2010-07-31 21:54:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsImageLoadingContent::SetBlockedRequest(nsIURI* aURI, int16_t aContentDecision)
|
2010-07-31 21:54:59 +04:00
|
|
|
{
|
|
|
|
// Sanity
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!NS_CP_ACCEPTED(aContentDecision), "Blocked but not?");
|
2010-07-31 21:54:59 +04:00
|
|
|
|
|
|
|
// We do some slightly illogical stuff here to maintain consistency with
|
|
|
|
// old behavior that people probably depend on. Even in the case where the
|
|
|
|
// new image is blocked, the old one should really be canceled with the
|
|
|
|
// reason "image source changed". However, apparently there's some abuse
|
|
|
|
// over in nsImageFrame where the displaying of the "broken" icon for the
|
|
|
|
// next image depends on the cancel reason of the previous image. ugh.
|
2016-03-26 00:49:43 +03:00
|
|
|
// XXX(seth): So shouldn't we fix nsImageFrame?!
|
|
|
|
ClearPendingRequest(NS_ERROR_IMAGE_BLOCKED,
|
|
|
|
Some(OnNonvisible::DISCARD_IMAGES));
|
2010-07-31 21:54:59 +04:00
|
|
|
|
|
|
|
// For the blocked case, we only want to cancel the existing current request
|
|
|
|
// if size is not available. bz says the web depends on this behavior.
|
|
|
|
if (!HaveSize(mCurrentRequest)) {
|
|
|
|
|
|
|
|
mImageBlockingStatus = aContentDecision;
|
2014-08-20 01:49:38 +04:00
|
|
|
uint32_t keepFlags = mCurrentRequestFlags & REQUEST_IS_IMAGESET;
|
2016-03-26 00:49:43 +03:00
|
|
|
ClearCurrentRequest(NS_ERROR_IMAGE_BLOCKED,
|
|
|
|
Some(OnNonvisible::DISCARD_IMAGES));
|
2010-07-31 21:54:59 +04:00
|
|
|
|
2014-08-20 01:49:38 +04:00
|
|
|
// We still want to remember what URI we were and if it was an imageset,
|
|
|
|
// despite not having an actual request. These are both cleared as part of
|
|
|
|
// ClearCurrentRequest() before a new request is started.
|
2010-07-31 21:54:59 +04:00
|
|
|
mCurrentURI = aURI;
|
2014-08-20 01:49:38 +04:00
|
|
|
mCurrentRequestFlags = keepFlags;
|
2010-07-31 21:54:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy>&
|
2014-08-20 01:49:38 +04:00
|
|
|
nsImageLoadingContent::PrepareCurrentRequest(ImageLoadType aImageLoadType)
|
2010-07-31 21:54:59 +04:00
|
|
|
{
|
|
|
|
// Blocked images go through SetBlockedRequest, which is a separate path. For
|
|
|
|
// everything else, we're unblocked.
|
|
|
|
mImageBlockingStatus = nsIContentPolicy::ACCEPT;
|
|
|
|
|
|
|
|
// Get rid of anything that was there previously.
|
2015-02-06 13:51:12 +03:00
|
|
|
ClearCurrentRequest(NS_ERROR_IMAGE_SRC_CHANGED,
|
2016-03-26 00:49:43 +03:00
|
|
|
Some(OnNonvisible::DISCARD_IMAGES));
|
2010-07-31 21:54:59 +04:00
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
if (mNewRequestsWillNeedAnimationReset) {
|
|
|
|
mCurrentRequestFlags |= REQUEST_NEEDS_ANIMATION_RESET;
|
|
|
|
}
|
2011-01-26 21:52:48 +03:00
|
|
|
|
2014-08-20 01:49:38 +04:00
|
|
|
if (aImageLoadType == eImageLoadType_Imageset) {
|
|
|
|
mCurrentRequestFlags |= REQUEST_IS_IMAGESET;
|
|
|
|
}
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// Return a reference.
|
|
|
|
return mCurrentRequest;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy>&
|
2014-08-20 01:49:38 +04:00
|
|
|
nsImageLoadingContent::PreparePendingRequest(ImageLoadType aImageLoadType)
|
2010-07-31 21:54:59 +04:00
|
|
|
{
|
|
|
|
// Get rid of anything that was there previously.
|
2015-02-06 13:51:12 +03:00
|
|
|
ClearPendingRequest(NS_ERROR_IMAGE_SRC_CHANGED,
|
2016-03-26 00:49:43 +03:00
|
|
|
Some(OnNonvisible::DISCARD_IMAGES));
|
2010-07-31 21:54:59 +04:00
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
if (mNewRequestsWillNeedAnimationReset) {
|
|
|
|
mPendingRequestFlags |= REQUEST_NEEDS_ANIMATION_RESET;
|
|
|
|
}
|
2011-01-26 21:52:48 +03:00
|
|
|
|
2014-08-20 01:49:38 +04:00
|
|
|
if (aImageLoadType == eImageLoadType_Imageset) {
|
|
|
|
mPendingRequestFlags |= REQUEST_IS_IMAGESET;
|
|
|
|
}
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// Return a reference.
|
|
|
|
return mPendingRequest;
|
|
|
|
}
|
|
|
|
|
2012-06-20 21:43:06 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ImageRequestAutoLock
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit ImageRequestAutoLock(imgIRequest* aRequest)
|
2012-06-20 21:43:06 +04:00
|
|
|
: mRequest(aRequest)
|
|
|
|
{
|
|
|
|
if (mRequest) {
|
|
|
|
mRequest->LockImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~ImageRequestAutoLock()
|
|
|
|
{
|
|
|
|
if (mRequest) {
|
|
|
|
mRequest->UnlockImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<imgIRequest> mRequest;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2012-06-20 21:43:06 +04:00
|
|
|
|
2012-03-20 02:22:02 +04:00
|
|
|
void
|
|
|
|
nsImageLoadingContent::MakePendingRequestCurrent()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mPendingRequest);
|
2012-06-20 21:43:06 +04:00
|
|
|
|
|
|
|
// Lock mCurrentRequest for the duration of this method. We do this because
|
|
|
|
// PrepareCurrentRequest() might unlock mCurrentRequest. If mCurrentRequest
|
|
|
|
// and mPendingRequest are both requests for the same image, unlocking
|
|
|
|
// mCurrentRequest before we lock mPendingRequest can cause the lock count
|
|
|
|
// to go to 0 and the image to be discarded!
|
|
|
|
ImageRequestAutoLock autoLock(mCurrentRequest);
|
|
|
|
|
2014-08-20 01:49:38 +04:00
|
|
|
ImageLoadType loadType = \
|
|
|
|
(mPendingRequestFlags & REQUEST_IS_IMAGESET) ? eImageLoadType_Imageset
|
|
|
|
: eImageLoadType_Normal;
|
|
|
|
|
|
|
|
PrepareCurrentRequest(loadType) = mPendingRequest;
|
2012-07-30 18:20:58 +04:00
|
|
|
mPendingRequest = nullptr;
|
2012-08-14 02:11:50 +04:00
|
|
|
mCurrentRequestFlags = mPendingRequestFlags;
|
|
|
|
mPendingRequestFlags = 0;
|
2012-06-14 05:12:37 +04:00
|
|
|
ResetAnimationIfNeeded();
|
2012-03-20 02:22:02 +04:00
|
|
|
}
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
void
|
2013-04-09 20:50:35 +04:00
|
|
|
nsImageLoadingContent::ClearCurrentRequest(nsresult aReason,
|
2016-03-26 00:49:43 +03:00
|
|
|
const Maybe<OnNonvisible>& aNonvisibleAction)
|
2010-07-31 21:54:59 +04:00
|
|
|
{
|
|
|
|
if (!mCurrentRequest) {
|
|
|
|
// Even if we didn't have a current request, we might have been keeping
|
2014-08-20 01:49:38 +04:00
|
|
|
// a URI and flags as a placeholder for a failed load. Clear that now.
|
2012-07-30 18:20:58 +04:00
|
|
|
mCurrentURI = nullptr;
|
2014-08-20 01:49:38 +04:00
|
|
|
mCurrentRequestFlags = 0;
|
2010-07-31 21:54:59 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mCurrentURI,
|
|
|
|
"Shouldn't have both mCurrentRequest and mCurrentURI!");
|
2010-07-31 21:54:59 +04:00
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
// Deregister this image from the refresh driver so it no longer receives
|
|
|
|
// notifications.
|
|
|
|
nsLayoutUtils::DeregisterImageRequest(GetFramePresContext(), mCurrentRequest,
|
|
|
|
&mCurrentRequestRegistered);
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
// Clean up the request.
|
2015-02-06 13:51:12 +03:00
|
|
|
UntrackImage(mCurrentRequest, aNonvisibleAction);
|
2010-07-31 21:54:59 +04:00
|
|
|
mCurrentRequest->CancelAndForgetObserver(aReason);
|
2012-07-30 18:20:58 +04:00
|
|
|
mCurrentRequest = nullptr;
|
2012-08-14 02:11:50 +04:00
|
|
|
mCurrentRequestFlags = 0;
|
2010-07-31 21:54:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-09 20:50:35 +04:00
|
|
|
nsImageLoadingContent::ClearPendingRequest(nsresult aReason,
|
2016-03-26 00:49:43 +03:00
|
|
|
const Maybe<OnNonvisible>& aNonvisibleAction)
|
2010-07-31 21:54:59 +04:00
|
|
|
{
|
|
|
|
if (!mPendingRequest)
|
|
|
|
return;
|
2011-02-01 07:50:01 +03:00
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
// Deregister this image from the refresh driver so it no longer receives
|
|
|
|
// notifications.
|
|
|
|
nsLayoutUtils::DeregisterImageRequest(GetFramePresContext(), mPendingRequest,
|
|
|
|
&mPendingRequestRegistered);
|
|
|
|
|
2015-02-06 13:51:12 +03:00
|
|
|
UntrackImage(mPendingRequest, aNonvisibleAction);
|
2010-07-31 21:54:59 +04:00
|
|
|
mPendingRequest->CancelAndForgetObserver(aReason);
|
2012-07-30 18:20:58 +04:00
|
|
|
mPendingRequest = nullptr;
|
2012-08-14 02:11:50 +04:00
|
|
|
mPendingRequestFlags = 0;
|
2010-07-31 21:54:59 +04:00
|
|
|
}
|
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
bool*
|
|
|
|
nsImageLoadingContent::GetRegisteredFlagForRequest(imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
if (aRequest == mCurrentRequest) {
|
|
|
|
return &mCurrentRequestRegistered;
|
|
|
|
} else if (aRequest == mPendingRequest) {
|
|
|
|
return &mPendingRequestRegistered;
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-14 05:12:37 +04:00
|
|
|
void
|
|
|
|
nsImageLoadingContent::ResetAnimationIfNeeded()
|
|
|
|
{
|
2012-08-14 02:11:50 +04:00
|
|
|
if (mCurrentRequest &&
|
|
|
|
(mCurrentRequestFlags & REQUEST_NEEDS_ANIMATION_RESET)) {
|
2012-06-14 05:12:37 +04:00
|
|
|
nsCOMPtr<imgIContainer> container;
|
|
|
|
mCurrentRequest->GetImage(getter_AddRefs(container));
|
|
|
|
if (container)
|
|
|
|
container->ResetAnimation();
|
2012-08-14 02:11:50 +04:00
|
|
|
mCurrentRequestFlags &= ~REQUEST_NEEDS_ANIMATION_RESET;
|
2012-06-14 05:12:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-31 21:54:59 +04:00
|
|
|
bool
|
|
|
|
nsImageLoadingContent::HaveSize(imgIRequest *aImage)
|
|
|
|
{
|
|
|
|
// Handle the null case
|
|
|
|
if (!aImage)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Query the image
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t status;
|
2010-07-31 21:54:59 +04:00
|
|
|
nsresult rv = aImage->GetImageStatus(&status);
|
|
|
|
return (NS_SUCCEEDED(rv) && (status & imgIRequest::STATUS_SIZE_AVAILABLE));
|
|
|
|
}
|
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
void
|
|
|
|
nsImageLoadingContent::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
// We may be entering the document, so if our image should be tracked,
|
|
|
|
// track it.
|
|
|
|
if (!aDocument)
|
|
|
|
return;
|
|
|
|
|
2013-02-25 04:59:21 +04:00
|
|
|
TrackImage(mCurrentRequest);
|
|
|
|
TrackImage(mPendingRequest);
|
2012-10-11 20:37:05 +04:00
|
|
|
|
|
|
|
if (mCurrentRequestFlags & REQUEST_BLOCKS_ONLOAD)
|
|
|
|
aDocument->BlockOnload();
|
2012-08-14 02:11:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageLoadingContent::UnbindFromTree(bool aDeep, bool aNullParent)
|
|
|
|
{
|
|
|
|
// We may be leaving the document, so if our image is tracked, untrack it.
|
|
|
|
nsCOMPtr<nsIDocument> doc = GetOurCurrentDoc();
|
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
|
2013-02-25 04:59:21 +04:00
|
|
|
UntrackImage(mCurrentRequest);
|
|
|
|
UntrackImage(mPendingRequest);
|
2012-10-11 20:37:05 +04:00
|
|
|
|
|
|
|
if (mCurrentRequestFlags & REQUEST_BLOCKS_ONLOAD)
|
|
|
|
doc->UnblockOnload(false);
|
2012-08-14 02:11:50 +04:00
|
|
|
}
|
|
|
|
|
2016-03-26 00:49:43 +03:00
|
|
|
void
|
2016-09-12 08:19:07 +03:00
|
|
|
nsImageLoadingContent::OnVisibilityChange(Visibility aNewVisibility,
|
2016-03-26 00:49:43 +03:00
|
|
|
const Maybe<OnNonvisible>& aNonvisibleAction)
|
|
|
|
{
|
|
|
|
switch (aNewVisibility) {
|
2016-09-12 08:19:08 +03:00
|
|
|
case Visibility::APPROXIMATELY_VISIBLE:
|
2016-09-12 08:19:07 +03:00
|
|
|
TrackImage(mCurrentRequest);
|
|
|
|
TrackImage(mPendingRequest);
|
2016-03-26 00:49:43 +03:00
|
|
|
break;
|
|
|
|
|
2016-09-12 08:19:08 +03:00
|
|
|
case Visibility::APPROXIMATELY_NONVISIBLE:
|
2016-03-26 00:49:43 +03:00
|
|
|
UntrackImage(mCurrentRequest, aNonvisibleAction);
|
|
|
|
UntrackImage(mPendingRequest, aNonvisibleAction);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Visibility::UNTRACKED:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Shouldn't notify for untracked visibility");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 22:38:35 +04:00
|
|
|
void
|
2013-09-15 04:05:05 +04:00
|
|
|
nsImageLoadingContent::TrackImage(imgIRequest* aImage)
|
2010-08-04 04:40:29 +04:00
|
|
|
{
|
2010-09-01 05:26:41 +04:00
|
|
|
if (!aImage)
|
2013-05-07 22:38:35 +04:00
|
|
|
return;
|
2010-09-01 05:26:41 +04:00
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
MOZ_ASSERT(aImage == mCurrentRequest || aImage == mPendingRequest,
|
|
|
|
"Why haven't we heard of this request?");
|
|
|
|
|
|
|
|
nsIDocument* doc = GetOurCurrentDoc();
|
2016-03-26 00:49:43 +03:00
|
|
|
if (!doc) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-20 05:30:35 +03:00
|
|
|
|
2016-03-26 00:49:43 +03:00
|
|
|
// We only want to track this request if we're visible. Ordinarily we check
|
2016-09-12 08:19:08 +03:00
|
|
|
// the visible count, but that requires a frame; in cases where
|
2016-03-26 00:49:43 +03:00
|
|
|
// GetOurPrimaryFrame() cannot obtain a frame (e.g. <feImage>), we assume
|
|
|
|
// we're visible if FrameCreated() was called.
|
|
|
|
nsIFrame* frame = GetOurPrimaryFrame();
|
2016-09-12 08:19:08 +03:00
|
|
|
if ((frame && frame->GetVisibility() == Visibility::APPROXIMATELY_NONVISIBLE) ||
|
2016-03-26 00:49:43 +03:00
|
|
|
(!frame && !mFrameCreateCalled)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aImage == mCurrentRequest && !(mCurrentRequestFlags & REQUEST_IS_TRACKED)) {
|
|
|
|
mCurrentRequestFlags |= REQUEST_IS_TRACKED;
|
2016-10-13 10:04:19 +03:00
|
|
|
doc->ImageTracker()->Add(mCurrentRequest);
|
2016-03-26 00:49:43 +03:00
|
|
|
}
|
|
|
|
if (aImage == mPendingRequest && !(mPendingRequestFlags & REQUEST_IS_TRACKED)) {
|
|
|
|
mPendingRequestFlags |= REQUEST_IS_TRACKED;
|
2016-10-13 10:04:19 +03:00
|
|
|
doc->ImageTracker()->Add(mPendingRequest);
|
2013-02-14 00:18:08 +04:00
|
|
|
}
|
2010-08-04 04:40:29 +04:00
|
|
|
}
|
|
|
|
|
2013-05-07 22:38:35 +04:00
|
|
|
void
|
2015-02-06 13:51:12 +03:00
|
|
|
nsImageLoadingContent::UntrackImage(imgIRequest* aImage,
|
2016-03-26 00:49:43 +03:00
|
|
|
const Maybe<OnNonvisible>& aNonvisibleAction
|
|
|
|
/* = Nothing() */)
|
2010-08-04 04:40:29 +04:00
|
|
|
{
|
2010-09-01 05:26:41 +04:00
|
|
|
if (!aImage)
|
2013-05-07 22:38:35 +04:00
|
|
|
return;
|
2010-09-01 05:26:41 +04:00
|
|
|
|
2012-08-14 02:11:50 +04:00
|
|
|
MOZ_ASSERT(aImage == mCurrentRequest || aImage == mPendingRequest,
|
|
|
|
"Why haven't we heard of this request?");
|
|
|
|
|
2013-04-09 20:50:35 +04:00
|
|
|
// We may not be in the document. If we outlived our document that's fine,
|
|
|
|
// because the document empties out the tracker and unlocks all locked images
|
|
|
|
// on destruction. But if we were never in the document we may need to force
|
|
|
|
// discarding the image here, since this is the only chance we have.
|
2012-08-14 02:11:50 +04:00
|
|
|
nsIDocument* doc = GetOurCurrentDoc();
|
2013-04-09 20:50:35 +04:00
|
|
|
if (aImage == mCurrentRequest) {
|
|
|
|
if (doc && (mCurrentRequestFlags & REQUEST_IS_TRACKED)) {
|
2013-02-14 00:18:08 +04:00
|
|
|
mCurrentRequestFlags &= ~REQUEST_IS_TRACKED;
|
2016-10-13 10:04:19 +03:00
|
|
|
doc->ImageTracker()->Remove(
|
2016-10-13 10:04:15 +03:00
|
|
|
mCurrentRequest,
|
|
|
|
aNonvisibleAction == Some(OnNonvisible::DISCARD_IMAGES)
|
|
|
|
? ImageTracker::REQUEST_DISCARD
|
|
|
|
: 0);
|
2016-03-26 00:49:43 +03:00
|
|
|
} else if (aNonvisibleAction == Some(OnNonvisible::DISCARD_IMAGES)) {
|
2013-04-09 20:50:35 +04:00
|
|
|
// If we're not in the document we may still need to be discarded.
|
|
|
|
aImage->RequestDiscard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aImage == mPendingRequest) {
|
|
|
|
if (doc && (mPendingRequestFlags & REQUEST_IS_TRACKED)) {
|
2013-02-14 00:18:08 +04:00
|
|
|
mPendingRequestFlags &= ~REQUEST_IS_TRACKED;
|
2016-10-13 10:04:19 +03:00
|
|
|
doc->ImageTracker()->Remove(
|
2016-10-13 10:04:15 +03:00
|
|
|
mPendingRequest,
|
|
|
|
aNonvisibleAction == Some(OnNonvisible::DISCARD_IMAGES)
|
|
|
|
? ImageTracker::REQUEST_DISCARD
|
|
|
|
: 0);
|
2016-03-26 00:49:43 +03:00
|
|
|
} else if (aNonvisibleAction == Some(OnNonvisible::DISCARD_IMAGES)) {
|
2013-04-09 20:50:35 +04:00
|
|
|
// If we're not in the document we may still need to be discarded.
|
|
|
|
aImage->RequestDiscard();
|
2013-02-14 00:18:08 +04:00
|
|
|
}
|
|
|
|
}
|
2010-08-04 04:40:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
void
|
|
|
|
nsImageLoadingContent::CreateStaticImageClone(nsImageLoadingContent* aDest) const
|
|
|
|
{
|
|
|
|
aDest->mCurrentRequest = nsContentUtils::GetStaticRequest(mCurrentRequest);
|
2010-09-01 05:26:41 +04:00
|
|
|
aDest->TrackImage(aDest->mCurrentRequest);
|
2009-12-11 07:02:13 +03:00
|
|
|
aDest->mForcedImageState = mForcedImageState;
|
|
|
|
aDest->mImageBlockingStatus = mImageBlockingStatus;
|
|
|
|
aDest->mLoadingEnabled = mLoadingEnabled;
|
2010-07-31 21:54:59 +04:00
|
|
|
aDest->mStateChangerDepth = mStateChangerDepth;
|
2009-12-11 07:02:13 +03:00
|
|
|
aDest->mIsImageStateForced = mIsImageStateForced;
|
|
|
|
aDest->mLoading = mLoading;
|
|
|
|
aDest->mBroken = mBroken;
|
|
|
|
aDest->mUserDisabled = mUserDisabled;
|
|
|
|
aDest->mSuppressed = mSuppressed;
|
|
|
|
}
|
|
|
|
|
2012-03-10 20:13:51 +04:00
|
|
|
CORSMode
|
2011-07-14 22:47:35 +04:00
|
|
|
nsImageLoadingContent::GetCORSMode()
|
|
|
|
{
|
2012-03-10 20:13:51 +04:00
|
|
|
return CORS_NONE;
|
2011-07-14 22:47:35 +04:00
|
|
|
}
|
2013-02-01 15:00:41 +04:00
|
|
|
|
|
|
|
nsImageLoadingContent::ImageObserver::ImageObserver(imgINotificationObserver* aObserver)
|
|
|
|
: mObserver(aObserver)
|
|
|
|
, mNext(nullptr)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ImageObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsImageLoadingContent::ImageObserver::~ImageObserver()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ImageObserver);
|
|
|
|
NS_CONTENT_DELETE_LIST_MEMBER(ImageObserver, this, mNext);
|
|
|
|
}
|
2015-06-06 01:25:24 +03:00
|
|
|
|
|
|
|
// Only HTMLInputElement.h overrides this for <img> tags
|
|
|
|
// all other subclasses use this one, i.e. ignore referrer attributes
|
|
|
|
mozilla::net::ReferrerPolicy
|
|
|
|
nsImageLoadingContent::GetImageReferrerPolicy()
|
|
|
|
{
|
|
|
|
return mozilla::net::RP_Unset;
|
|
|
|
};
|