2003-03-19 01:08:22 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2004-05-13 18:34:18 +00:00
|
|
|
// vim: ft=cpp tw=78 sw=2 et ts=2
|
2003-03-19 01:08:22 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
2005-12-31 16:02:07 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
2003-03-19 01:08:22 +00:00
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2005-12-31 16:02:07 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2003-03-19 01:08:22 +00:00
|
|
|
* Boris Zbarsky <bzbarsky@mit.edu>.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2003
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2005-09-21 19:14:30 +00:00
|
|
|
* Christian Biesinger <cbiesinger@web.de>
|
2010-07-31 17:54:59 +00:00
|
|
|
* Bobby Holley <bobbyholley@gmail.com>
|
2003-03-19 01:08:22 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2005-12-31 16:02:07 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2003-03-19 01:08:22 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2005-12-31 16:02:07 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2003-03-19 01:08:22 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2006-03-31 08:00:42 +00: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 01:08:22 +00:00
|
|
|
#include "nsImageLoadingContent.h"
|
2006-06-01 18:35:21 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2003-03-19 01:08:22 +00:00
|
|
|
#include "nsContentErrors.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2004-11-24 22:48:45 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2003-03-19 01:08:22 +00:00
|
|
|
#include "nsContentPolicyUtils.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsILoadGroup.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgILoader.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2003-03-19 01:08:22 +00:00
|
|
|
#include "nsNetUtil.h"
|
2010-02-25 02:45:43 +00:00
|
|
|
#include "nsPLDOMEvent.h"
|
2003-03-19 01:08:22 +00:00
|
|
|
|
2003-03-19 05:38:33 +00:00
|
|
|
#include "nsIPresShell.h"
|
2005-09-18 18:05:40 +00:00
|
|
|
#include "nsIEventStateManager.h"
|
2003-03-19 05:38:33 +00:00
|
|
|
#include "nsGUIEvent.h"
|
2003-03-19 01:08:22 +00:00
|
|
|
|
2003-04-02 03:27:20 +00:00
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
|
2003-04-16 01:53:48 +00:00
|
|
|
#include "nsIFrame.h"
|
2004-05-13 18:34:18 +00:00
|
|
|
#include "nsIDOMNode.h"
|
2003-04-16 01:53:48 +00:00
|
|
|
|
2004-03-09 03:57:51 +00:00
|
|
|
#include "nsContentUtils.h"
|
2005-03-02 04:05:12 +00:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
2006-03-07 17:08:51 +00:00
|
|
|
#include "nsEventDispatcher.h"
|
2006-06-01 18:35:21 +00:00
|
|
|
#include "nsDOMClassInfo.h"
|
2010-08-13 13:36:13 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
#include "nsSVGEffects.h"
|
|
|
|
#endif
|
2004-03-09 03:57:51 +00:00
|
|
|
|
2008-04-11 17:29:06 +00:00
|
|
|
#include "mozAutoDocUpdate.h"
|
|
|
|
|
2004-06-05 17:57:00 +00: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString spec;
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
printf("spec='%s'\n", spec.get());
|
|
|
|
}
|
|
|
|
#endif /* DEBUG_chb */
|
|
|
|
|
2004-05-13 18:34:18 +00:00
|
|
|
|
2003-03-19 01:08:22 +00:00
|
|
|
nsImageLoadingContent::nsImageLoadingContent()
|
|
|
|
: mObserverList(nsnull),
|
2005-03-02 04:05:12 +00:00
|
|
|
mImageBlockingStatus(nsIContentPolicy::ACCEPT),
|
2005-09-18 18:05:40 +00:00
|
|
|
mLoadingEnabled(PR_TRUE),
|
2009-09-12 22:44:18 +00:00
|
|
|
mIsImageStateForced(PR_FALSE),
|
2005-10-17 00:50:39 +00:00
|
|
|
mLoading(PR_FALSE),
|
2005-09-18 18:05:40 +00:00
|
|
|
// mBroken starts out true, since an image without a URI is broken....
|
|
|
|
mBroken(PR_TRUE),
|
|
|
|
mUserDisabled(PR_FALSE),
|
2009-06-26 07:25:17 +00:00
|
|
|
mSuppressed(PR_FALSE),
|
2010-07-31 17:54:59 +00:00
|
|
|
mBlockingOnload(PR_FALSE),
|
|
|
|
mStateChangerDepth(0)
|
2003-03-19 01:08:22 +00:00
|
|
|
{
|
2005-09-21 19:14:30 +00:00
|
|
|
if (!nsContentUtils::GetImgLoader()) {
|
2003-05-02 19:21:00 +00:00
|
|
|
mLoadingEnabled = PR_FALSE;
|
2005-09-21 19:14:30 +00:00
|
|
|
}
|
2003-03-19 01:08:22 +00:00
|
|
|
}
|
|
|
|
|
2006-06-01 18:35:21 +00:00
|
|
|
void
|
|
|
|
nsImageLoadingContent::DestroyImageLoadingContent()
|
2003-03-19 01:08:22 +00:00
|
|
|
{
|
|
|
|
// Cancel our requests so they won't hold stale refs to us
|
2010-07-31 17:54:59 +00:00
|
|
|
ClearCurrentRequest(NS_BINDING_ABORTED);
|
|
|
|
ClearPendingRequest(NS_BINDING_ABORTED);
|
2006-06-01 18:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsImageLoadingContent::~nsImageLoadingContent()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mCurrentRequest && !mPendingRequest,
|
|
|
|
"DestroyImageLoadingContent not called");
|
2003-03-19 01:08:22 +00:00
|
|
|
NS_ASSERTION(!mObserverList.mObserver && !mObserverList.mNext,
|
|
|
|
"Observers still registered?");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Macro to call some func on each observer. This handles observers
|
|
|
|
// removing themselves.
|
|
|
|
#define LOOP_OVER_OBSERVERS(func_) \
|
|
|
|
PR_BEGIN_MACRO \
|
2003-07-23 23:09:33 +00:00
|
|
|
for (ImageObserver* observer = &mObserverList, *next; observer; \
|
|
|
|
observer = next) { \
|
|
|
|
next = observer->mNext; \
|
2003-03-19 01:08:22 +00:00
|
|
|
if (observer->mObserver) { \
|
|
|
|
observer->mObserver->func_; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* imgIContainerObserver impl
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::FrameChanged(imgIContainer* aContainer,
|
2010-08-14 04:09:48 +00:00
|
|
|
const nsIntRect* aDirtyRect)
|
2003-03-19 01:08:22 +00:00
|
|
|
{
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
LOOP_OVER_OBSERVERS(FrameChanged(aContainer, aDirtyRect));
|
2003-03-19 01:08:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* imgIDecoderObserver impl
|
|
|
|
*/
|
2006-06-01 18:35:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::OnStartRequest(imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
LOOP_OVER_OBSERVERS(OnStartRequest(aRequest));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 01:08:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::OnStartDecode(imgIRequest* aRequest)
|
|
|
|
{
|
2010-07-01 17:42:58 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Onload blocking. This only applies for the current request.
|
2009-09-12 22:44:18 +00:00
|
|
|
if (aRequest == mCurrentRequest) {
|
2010-07-01 17:42:58 +00:00
|
|
|
|
|
|
|
// Determine whether this is a background request (this can be the case
|
|
|
|
// with multipart/x-mixed-replace images, for example).
|
|
|
|
PRUint32 loadFlags;
|
|
|
|
rv = aRequest->GetLoadFlags(&loadFlags);
|
|
|
|
PRBool background =
|
|
|
|
(NS_SUCCEEDED(rv) && (loadFlags & nsIRequest::LOAD_BACKGROUND));
|
|
|
|
|
|
|
|
// Block onload for non-background requests
|
|
|
|
if (!background) {
|
|
|
|
NS_ABORT_IF_FALSE(!mBlockingOnload, "Shouldn't already be blocking");
|
|
|
|
SetBlockingOnload(PR_TRUE);
|
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
}
|
|
|
|
|
2003-03-19 01:08:22 +00:00
|
|
|
LOOP_OVER_OBSERVERS(OnStartDecode(aRequest));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::OnStartContainer(imgIRequest* aRequest,
|
|
|
|
imgIContainer* aContainer)
|
|
|
|
{
|
|
|
|
LOOP_OVER_OBSERVERS(OnStartContainer(aRequest, aContainer));
|
2005-10-17 00:50:39 +00:00
|
|
|
|
|
|
|
// Have to check for state changes here, since we might have been in
|
|
|
|
// the LOADING state before.
|
|
|
|
UpdateImageState(PR_TRUE);
|
2003-03-19 01:08:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::OnStartFrame(imgIRequest* aRequest,
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
PRUint32 aFrame)
|
2003-03-19 01:08:22 +00:00
|
|
|
{
|
|
|
|
LOOP_OVER_OBSERVERS(OnStartFrame(aRequest, aFrame));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::OnDataAvailable(imgIRequest* aRequest,
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
PRBool aCurrentFrame,
|
2009-01-15 03:27:09 +00:00
|
|
|
const nsIntRect* aRect)
|
2003-03-19 01:08:22 +00:00
|
|
|
{
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
LOOP_OVER_OBSERVERS(OnDataAvailable(aRequest, aCurrentFrame, aRect));
|
2003-03-19 01:08:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::OnStopFrame(imgIRequest* aRequest,
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
PRUint32 aFrame)
|
2003-03-19 01:08:22 +00:00
|
|
|
{
|
2009-09-12 22:44:18 +00:00
|
|
|
// If we're blocking a load, one frame is enough
|
|
|
|
if (aRequest == mCurrentRequest)
|
|
|
|
SetBlockingOnload(PR_FALSE);
|
|
|
|
|
2003-03-19 01:08:22 +00:00
|
|
|
LOOP_OVER_OBSERVERS(OnStopFrame(aRequest, aFrame));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::OnStopContainer(imgIRequest* aRequest,
|
|
|
|
imgIContainer* aContainer)
|
|
|
|
{
|
2009-09-12 22:44:18 +00:00
|
|
|
// This is really hacky. We need to handle the case where we start decoding,
|
|
|
|
// block onload, but then hit an error before we get to our first frame. In
|
|
|
|
// theory we would just hook in at OnStopDecode, but OnStopDecode is broken
|
|
|
|
// until we fix bug 505385. OnStopContainer is actually going away at that
|
|
|
|
// point. So for now we take advantage of the fact that OnStopContainer is
|
|
|
|
// always fired in the decoders at the same time as OnStopDecode.
|
|
|
|
if (aRequest == mCurrentRequest)
|
|
|
|
SetBlockingOnload(PR_FALSE);
|
|
|
|
|
2003-03-19 01:08:22 +00:00
|
|
|
LOOP_OVER_OBSERVERS(OnStopContainer(aRequest, aContainer));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
// Warning - This isn't actually fired when decode is complete. Rather, it's
|
|
|
|
// fired when load is complete. See bug 505385, and in the mean time use
|
|
|
|
// OnStopContainer.
|
2003-03-19 01:08:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::OnStopDecode(imgIRequest* aRequest,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar* aStatusArg)
|
|
|
|
{
|
2009-09-12 22:44:18 +00:00
|
|
|
// We should definitely have a request here
|
|
|
|
NS_ABORT_IF_FALSE(aRequest, "no request?");
|
|
|
|
|
2003-03-19 01:08:22 +00:00
|
|
|
NS_PRECONDITION(aRequest == mCurrentRequest || aRequest == mPendingRequest,
|
|
|
|
"Unknown request");
|
|
|
|
LOOP_OVER_OBSERVERS(OnStopDecode(aRequest, aStatus, aStatusArg));
|
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
// XXXbholley - When we fix bug 505385, everything here should go in
|
|
|
|
// OnStopRequest.
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
// Our state may change. Watch it.
|
|
|
|
AutoStateChanger changer(this, PR_TRUE);
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
// If the pending request is loaded, switch to it.
|
|
|
|
if (aRequest == mPendingRequest) {
|
|
|
|
PrepareCurrentRequest() = mPendingRequest;
|
2003-03-19 01:08:22 +00:00
|
|
|
mPendingRequest = nsnull;
|
|
|
|
}
|
2010-07-31 17:54:59 +00:00
|
|
|
NS_ABORT_IF_FALSE(aRequest == mCurrentRequest,
|
|
|
|
"One way or another, we should be current by now");
|
2003-03-19 01:08:22 +00:00
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
// We just loaded all the data we're going to get. If we haven't done an
|
|
|
|
// initial paint, we want to make sure the image starts decoding for 2
|
|
|
|
// reasons:
|
|
|
|
//
|
|
|
|
// 1) This image is sitting idle but might need to be decoded as soon as we
|
|
|
|
// start painting, in which case we've wasted time.
|
|
|
|
//
|
|
|
|
// 2) We want to block onload until all visible images are decoded. We do this
|
|
|
|
// by blocking onload until all in progress decodes get at least one frame
|
|
|
|
// decoded. However, if all the data comes in while painting is suppressed
|
|
|
|
// (ie, before the initial paint delay is finished), we fire onload without
|
|
|
|
// doing a paint first. This means that decode-on-draw images don't start
|
|
|
|
// decoding, so we can't wait for them to finish. See bug 512435.
|
|
|
|
|
|
|
|
// We can only do this if we have a presshell
|
2009-09-16 19:01:18 +00:00
|
|
|
nsIDocument* doc = GetOurDocument();
|
2010-06-25 13:59:57 +00:00
|
|
|
nsIPresShell* shell = doc ? doc->GetShell() : nsnull;
|
2009-09-12 22:44:18 +00:00
|
|
|
if (shell) {
|
|
|
|
|
|
|
|
// We need to figure out whether to kick off decoding
|
|
|
|
PRBool doRequestDecode = PR_FALSE;
|
|
|
|
|
|
|
|
// If we haven't got the initial reflow yet, IsPaintingSuppressed actually
|
|
|
|
// returns false
|
|
|
|
if (!shell->DidInitialReflow())
|
|
|
|
doRequestDecode = PR_TRUE;
|
|
|
|
|
|
|
|
// Figure out if painting is suppressed. Note that it's possible for painting
|
|
|
|
// to be suppressed for reasons other than the initial paint delay (for
|
|
|
|
// example - being in the bfcache), but we probably aren't loading images in
|
|
|
|
// those situations.
|
2010-03-31 12:43:49 +00:00
|
|
|
if (shell->IsPaintingSuppressed())
|
2009-09-12 22:44:18 +00:00
|
|
|
doRequestDecode = PR_TRUE;
|
|
|
|
|
|
|
|
// If we're requesting a decode, do it
|
|
|
|
if (doRequestDecode)
|
2010-07-31 17:54:59 +00:00
|
|
|
mCurrentRequest->RequestDecode();
|
2009-09-12 22:44:18 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
// Fire the appropriate DOM event.
|
2003-03-19 01:08:22 +00:00
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
|
|
|
FireEvent(NS_LITERAL_STRING("load"));
|
|
|
|
} else {
|
|
|
|
FireEvent(NS_LITERAL_STRING("error"));
|
|
|
|
}
|
|
|
|
|
2010-08-13 13:36:13 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
nsCOMPtr<nsINode> thisNode = do_QueryInterface(this);
|
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(thisNode->AsElement());
|
|
|
|
#endif
|
|
|
|
|
2003-03-19 01:08:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-01 18:35:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::OnStopRequest(imgIRequest* aRequest, PRBool aLastPart)
|
|
|
|
{
|
|
|
|
LOOP_OVER_OBSERVERS(OnStopRequest(aRequest, aLastPart));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::OnDiscard(imgIRequest *aRequest)
|
|
|
|
{
|
|
|
|
LOOP_OVER_OBSERVERS(OnDiscard(aRequest));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 01:08:22 +00:00
|
|
|
/*
|
2003-04-02 03:27:20 +00:00
|
|
|
* nsIImageLoadingContent impl
|
2003-03-19 01:08:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::GetLoadingEnabled(PRBool *aLoadingEnabled)
|
|
|
|
{
|
|
|
|
*aLoadingEnabled = mLoadingEnabled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::SetLoadingEnabled(PRBool aLoadingEnabled)
|
|
|
|
{
|
2005-09-21 19:14:30 +00:00
|
|
|
if (nsContentUtils::GetImgLoader()) {
|
2003-05-02 19:21:00 +00:00
|
|
|
mLoadingEnabled = aLoadingEnabled;
|
2005-09-21 19:14:30 +00:00
|
|
|
}
|
2003-03-19 01:08:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-03-02 04:05:12 +00:00
|
|
|
nsImageLoadingContent::GetImageBlockingStatus(PRInt16* aStatus)
|
2003-03-19 01:08:22 +00:00
|
|
|
{
|
2005-03-02 04:05:12 +00:00
|
|
|
NS_PRECONDITION(aStatus, "Null out param");
|
|
|
|
*aStatus = mImageBlockingStatus;
|
2003-03-19 01:08:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-07-24 17:30:52 +00:00
|
|
|
|
2003-03-19 01:08:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::AddObserver(imgIDecoderObserver* aObserver)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aObserver);
|
|
|
|
|
|
|
|
if (!mObserverList.mObserver) {
|
|
|
|
mObserverList.mObserver = aObserver;
|
|
|
|
// Don't touch the linking of the list!
|
|
|
|
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);
|
|
|
|
if (! observer->mNext) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::RemoveObserver(imgIDecoderObserver* aObserver)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aObserver);
|
|
|
|
|
|
|
|
if (mObserverList.mObserver == aObserver) {
|
|
|
|
mObserverList.mObserver = nsnull;
|
|
|
|
// 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;
|
|
|
|
oldObserver->mNext = nsnull; // so we don't destroy them all
|
|
|
|
delete oldObserver;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
2010-05-23 19:26:15 +00:00
|
|
|
NS_WARNING("Asked to remove nonexistent observer");
|
2003-03-19 01:08:22 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-03-19 04:13:37 +00:00
|
|
|
nsImageLoadingContent::GetRequest(PRInt32 aRequestType,
|
2003-03-19 01:08:22 +00:00
|
|
|
imgIRequest** aRequest)
|
|
|
|
{
|
|
|
|
switch(aRequestType) {
|
|
|
|
case CURRENT_REQUEST:
|
|
|
|
*aRequest = mCurrentRequest;
|
|
|
|
break;
|
|
|
|
case PENDING_REQUEST:
|
|
|
|
*aRequest = mPendingRequest;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unknown request type");
|
|
|
|
*aRequest = nsnull;
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aRequest);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::GetRequestType(imgIRequest* aRequest,
|
|
|
|
PRInt32* aRequestType)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aRequestType, "Null out param");
|
|
|
|
|
|
|
|
if (aRequest == mCurrentRequest) {
|
|
|
|
*aRequestType = CURRENT_REQUEST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRequest == mPendingRequest) {
|
|
|
|
*aRequestType = PENDING_REQUEST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aRequestType = UNKNOWN_REQUEST;
|
|
|
|
NS_ERROR("Unknown request");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2004-06-05 17:57:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::GetCurrentURI(nsIURI** aURI)
|
|
|
|
{
|
2005-09-21 19:14:30 +00:00
|
|
|
if (mCurrentRequest) {
|
2004-06-05 17:57:00 +00:00
|
|
|
return mCurrentRequest->GetURI(aURI);
|
2005-09-21 19:14:30 +00:00
|
|
|
}
|
2004-06-05 17:57:00 +00:00
|
|
|
|
2006-05-31 15:58:43 +00:00
|
|
|
if (!mCurrentURI) {
|
|
|
|
*aURI = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_EnsureSafeToReturn(mCurrentURI, aURI);
|
2004-06-05 17:57:00 +00:00
|
|
|
}
|
|
|
|
|
2003-04-02 03:27:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageLoadingContent::LoadImageWithChannel(nsIChannel* aChannel,
|
|
|
|
nsIStreamListener** aListener)
|
|
|
|
{
|
2005-09-21 19:14:30 +00:00
|
|
|
if (!nsContentUtils::GetImgLoader()) {
|
2003-05-02 19:21:00 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2005-09-21 19:14:30 +00:00
|
|
|
}
|
2003-05-02 19:21:00 +00:00
|
|
|
|
2003-07-28 21:09:56 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetOurDocument();
|
|
|
|
if (!doc) {
|
|
|
|
// Don't bother
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-08-19 14:55:07 +00:00
|
|
|
|
2010-07-31 17:54:59 +00: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 03:27:20 +00:00
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
// Our state might change. Watch it.
|
|
|
|
AutoStateChanger changer(this, PR_TRUE);
|
2003-04-02 03:27:20 +00:00
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
// Do the load.
|
2010-08-04 00:40:29 +00:00
|
|
|
nsCOMPtr<imgIRequest>& req = PrepareNextRequest();
|
2005-09-18 18:05:40 +00:00
|
|
|
nsresult rv = nsContentUtils::GetImgLoader()->
|
2010-07-31 17:54:59 +00:00
|
|
|
LoadImageWithChannel(aChannel, this, doc, aListener,
|
2010-08-04 00:40:29 +00:00
|
|
|
getter_AddRefs(req));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
TrackImage(req);
|
|
|
|
} else {
|
2010-07-31 17:54:59 +00: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)
|
|
|
|
aChannel->GetURI(getter_AddRefs(mCurrentURI));
|
|
|
|
FireEvent(NS_LITERAL_STRING("error"));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;;
|
2003-04-02 03:27:20 +00:00
|
|
|
}
|
|
|
|
|
2006-09-07 22:51:57 +00:00
|
|
|
NS_IMETHODIMP nsImageLoadingContent::ForceReload()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
|
|
|
GetCurrentURI(getter_AddRefs(currentURI));
|
|
|
|
if (!currentURI) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LoadImage(currentURI, PR_TRUE, PR_TRUE, nsnull, nsIRequest::VALIDATE_ALWAYS);
|
|
|
|
}
|
|
|
|
|
2003-03-19 01:08:22 +00:00
|
|
|
/*
|
|
|
|
* Non-interface methods
|
|
|
|
*/
|
2005-09-18 18:05:40 +00:00
|
|
|
|
2010-08-27 01:30:03 +00:00
|
|
|
void
|
|
|
|
nsImageLoadingContent::NotifyOwnerDocumentChanged(nsIDocument *aOldDoc)
|
|
|
|
{
|
|
|
|
// If we had a document before, unregister ourselves with it.
|
|
|
|
if (aOldDoc) {
|
|
|
|
if (mCurrentRequest)
|
|
|
|
aOldDoc->RemoveImage(mCurrentRequest);
|
|
|
|
if (mPendingRequest)
|
|
|
|
aOldDoc->RemoveImage(mPendingRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re-track the images
|
2010-09-01 01:26:41 +00:00
|
|
|
TrackImage(mCurrentRequest);
|
|
|
|
TrackImage(mPendingRequest);
|
2010-08-27 01:30:03 +00:00
|
|
|
}
|
|
|
|
|
2003-03-19 01:08:22 +00:00
|
|
|
nsresult
|
2006-01-01 11:25:43 +00:00
|
|
|
nsImageLoadingContent::LoadImage(const nsAString& aNewURI,
|
|
|
|
PRBool aForce,
|
|
|
|
PRBool aNotify)
|
2003-03-19 01:08:22 +00:00
|
|
|
{
|
2003-07-03 02:45:34 +00:00
|
|
|
// First, get a document (needed for security checks and the like)
|
2005-09-21 19:14:30 +00:00
|
|
|
nsIDocument* doc = GetOurDocument();
|
2003-04-15 01:09:09 +00:00
|
|
|
if (!doc) {
|
|
|
|
// No reason to bother, I think...
|
2003-07-28 21:09:56 +00:00
|
|
|
return NS_OK;
|
2003-04-15 01:09:09 +00:00
|
|
|
}
|
2003-03-19 01:08:22 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> imageURI;
|
2005-09-21 19:14:30 +00:00
|
|
|
nsresult rv = StringToURI(aNewURI, doc, getter_AddRefs(imageURI));
|
2003-03-19 01:08:22 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-09-21 19:14:30 +00:00
|
|
|
// XXXbiesi fire onerror if that failed?
|
|
|
|
|
2008-08-08 01:09:20 +00:00
|
|
|
PRBool equal;
|
|
|
|
|
|
|
|
if (aNewURI.IsEmpty() &&
|
|
|
|
doc->GetDocumentURI() &&
|
2008-08-08 15:40:19 +00:00
|
|
|
NS_SUCCEEDED(doc->GetDocumentURI()->Equals(imageURI, &equal)) &&
|
2008-08-08 01:09:20 +00:00
|
|
|
equal) {
|
|
|
|
|
|
|
|
// Loading an embedded img from the same URI as the document URI will not work
|
|
|
|
// as a resource cannot recursively embed itself. Attempting to do so generally
|
|
|
|
// results in having to pre-emptively close down an in-flight HTTP transaction
|
|
|
|
// and then incurring the significant cost of establishing a new TCP channel.
|
|
|
|
// This is generally triggered from <img src="">
|
|
|
|
// In light of that, just skip loading it..
|
2008-12-12 19:41:11 +00:00
|
|
|
// Do make sure to drop our existing image, if any
|
|
|
|
CancelImageRequests(aNotify);
|
2008-08-08 01:09:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-31 15:58:43 +00:00
|
|
|
NS_TryToSetImmutable(imageURI);
|
|
|
|
|
2006-01-01 11:25:43 +00:00
|
|
|
return LoadImage(imageURI, aForce, aNotify, doc);
|
2005-09-21 19:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-01-01 11:25:43 +00:00
|
|
|
nsImageLoadingContent::LoadImage(nsIURI* aNewURI,
|
|
|
|
PRBool aForce,
|
|
|
|
PRBool aNotify,
|
2006-09-07 22:51:57 +00:00
|
|
|
nsIDocument* aDocument,
|
|
|
|
nsLoadFlags aLoadFlags)
|
2005-09-21 19:14:30 +00:00
|
|
|
{
|
|
|
|
if (!mLoadingEnabled) {
|
2009-11-20 04:39:11 +00:00
|
|
|
// XXX Why fire an error here? seems like the callers to SetLoadingEnabled
|
|
|
|
// don't want/need it.
|
2006-06-01 18:35:21 +00:00
|
|
|
FireEvent(NS_LITERAL_STRING("error"));
|
2005-09-21 19:14:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!aDocument || aDocument == GetOurDocument(),
|
|
|
|
"Bogus document passed in");
|
|
|
|
// First, get a document (needed for security checks and the like)
|
|
|
|
if (!aDocument) {
|
|
|
|
aDocument = GetOurDocument();
|
|
|
|
if (!aDocument) {
|
|
|
|
// No reason to bother, I think...
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-31 17:54:59 +00: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 16:37:27 +00:00
|
|
|
if (!aForce && NS_CP_ACCEPTED(mImageBlockingStatus)) {
|
2005-04-06 02:55:02 +00:00
|
|
|
nsCOMPtr<nsIURI> currentURI;
|
|
|
|
GetCurrentURI(getter_AddRefs(currentURI));
|
|
|
|
PRBool equal;
|
|
|
|
if (currentURI &&
|
2005-09-21 19:14:30 +00:00
|
|
|
NS_SUCCEEDED(currentURI->Equals(aNewURI, &equal)) &&
|
2005-04-06 02:55:02 +00:00
|
|
|
equal) {
|
|
|
|
// Nothing to do here.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
// From this point on, our image state could change. Watch it.
|
2005-09-18 18:05:40 +00:00
|
|
|
AutoStateChanger changer(this, aNotify);
|
|
|
|
|
2010-07-31 17:54:59 +00: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 18:45:39 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
|
2010-07-31 17:54:59 +00:00
|
|
|
NS_ABORT_IF_FALSE(thisContent &&
|
|
|
|
thisContent->NodePrincipal() == aDocument->NodePrincipal(),
|
|
|
|
"Principal mismatch?");
|
2007-07-03 18:45:39 +00:00
|
|
|
#endif
|
2010-07-31 17:54:59 +00:00
|
|
|
|
|
|
|
// Are we blocked?
|
|
|
|
PRInt16 cpDecision = nsIContentPolicy::REJECT_REQUEST;
|
|
|
|
nsContentUtils::CanLoadImage(aNewURI, this, aDocument,
|
|
|
|
aDocument->NodePrincipal(), &cpDecision);
|
|
|
|
if (!NS_CP_ACCEPTED(cpDecision)) {
|
2005-08-17 23:01:09 +00:00
|
|
|
FireEvent(NS_LITERAL_STRING("error"));
|
2010-07-31 17:54:59 +00:00
|
|
|
SetBlockedRequest(aNewURI, cpDecision);
|
2003-03-19 01:08:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
// Not blocked. Do the load.
|
2010-08-04 00:40:29 +00:00
|
|
|
nsCOMPtr<imgIRequest>& req = PrepareNextRequest();
|
2010-07-31 17:54:59 +00:00
|
|
|
nsresult rv;
|
2005-09-21 19:14:30 +00:00
|
|
|
rv = nsContentUtils::LoadImage(aNewURI, aDocument,
|
2007-07-03 18:45:39 +00:00
|
|
|
aDocument->NodePrincipal(),
|
2005-09-21 19:14:30 +00:00
|
|
|
aDocument->GetDocumentURI(),
|
2006-09-07 22:51:57 +00:00
|
|
|
this, aLoadFlags,
|
2010-08-04 00:40:29 +00:00
|
|
|
getter_AddRefs(req));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
TrackImage(req);
|
|
|
|
} else {
|
2010-07-31 17:54:59 +00: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;
|
2005-08-17 23:01:09 +00:00
|
|
|
FireEvent(NS_LITERAL_STRING("error"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-09-18 18:05:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-26 07:25:17 +00:00
|
|
|
nsresult
|
2010-10-20 11:26:32 +00:00
|
|
|
nsImageLoadingContent::ForceImageState(PRBool aForce, nsEventStates::InternalType aState)
|
2009-06-26 07:25:17 +00:00
|
|
|
{
|
|
|
|
mIsImageStateForced = aForce;
|
2010-10-20 11:26:32 +00:00
|
|
|
mForcedImageState = nsEventStates(aState);
|
2009-06-26 07:25:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-20 11:26:32 +00:00
|
|
|
nsEventStates
|
2005-09-18 18:05:40 +00:00
|
|
|
nsImageLoadingContent::ImageState() const
|
|
|
|
{
|
2010-10-20 11:26:32 +00:00
|
|
|
if (mIsImageStateForced) {
|
|
|
|
return mForcedImageState;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStates states;
|
|
|
|
|
|
|
|
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 18:05:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageLoadingContent::UpdateImageState(PRBool aNotify)
|
|
|
|
{
|
2010-07-31 17:54:59 +00:00
|
|
|
if (mStateChangerDepth > 0) {
|
|
|
|
// Ignore this call; we'll update our state when the outermost state
|
|
|
|
// changer is destroyed. Need this to work around the fact that some libpr0n
|
|
|
|
// 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-18 21:06:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-09-18 18:05:40 +00:00
|
|
|
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
|
|
|
|
if (!thisContent) {
|
|
|
|
return;
|
2003-04-16 01:53:48 +00:00
|
|
|
}
|
|
|
|
|
2010-10-20 11:26:32 +00:00
|
|
|
nsEventStates oldState = ImageState();
|
2005-09-18 18:05:40 +00:00
|
|
|
|
2005-10-17 00:50:39 +00:00
|
|
|
mLoading = mBroken = mUserDisabled = mSuppressed = PR_FALSE;
|
2005-09-18 18:05:40 +00: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) {
|
|
|
|
mSuppressed = PR_TRUE;
|
|
|
|
} else if (mImageBlockingStatus == nsIContentPolicy::REJECT_TYPE) {
|
|
|
|
mUserDisabled = PR_TRUE;
|
|
|
|
} else if (!mCurrentRequest) {
|
|
|
|
// No current request means error, since we weren't disabled or suppressed
|
|
|
|
mBroken = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
PRUint32 currentLoadStatus;
|
|
|
|
nsresult rv = mCurrentRequest->GetImageStatus(¤tLoadStatus);
|
|
|
|
if (NS_FAILED(rv) || (currentLoadStatus & imgIRequest::STATUS_ERROR)) {
|
|
|
|
mBroken = PR_TRUE;
|
2005-10-17 00:50:39 +00:00
|
|
|
} else if (!(currentLoadStatus & imgIRequest::STATUS_SIZE_AVAILABLE)) {
|
|
|
|
mLoading = PR_TRUE;
|
2005-09-18 18:05:40 +00:00
|
|
|
}
|
2003-04-16 01:53:48 +00:00
|
|
|
}
|
|
|
|
|
2005-09-18 18:05:40 +00:00
|
|
|
if (aNotify) {
|
|
|
|
nsIDocument* doc = thisContent->GetCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
NS_ASSERTION(thisContent->IsInDoc(), "Something is confused");
|
2010-10-20 11:26:32 +00:00
|
|
|
nsEventStates changedBits = oldState ^ ImageState();
|
|
|
|
if (!changedBits.IsEmpty()) {
|
2005-10-29 12:54:24 +00:00
|
|
|
mozAutoDocUpdate upd(doc, UPDATE_CONTENT_STATE, PR_TRUE);
|
2005-09-18 18:05:40 +00:00
|
|
|
doc->ContentStatesChanged(thisContent, nsnull, changedBits);
|
2003-04-16 01:53:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-19 01:08:22 +00:00
|
|
|
}
|
|
|
|
|
2005-08-19 14:55:07 +00:00
|
|
|
void
|
2005-09-18 18:05:40 +00:00
|
|
|
nsImageLoadingContent::CancelImageRequests(PRBool aNotify)
|
2005-08-19 14:55:07 +00:00
|
|
|
{
|
2008-12-12 19:41:11 +00:00
|
|
|
AutoStateChanger changer(this, aNotify);
|
2010-07-31 17:54:59 +00:00
|
|
|
ClearPendingRequest(NS_BINDING_ABORTED);
|
|
|
|
ClearCurrentRequest(NS_BINDING_ABORTED);
|
2003-03-19 01:08:22 +00:00
|
|
|
}
|
|
|
|
|
2005-09-20 02:05:48 +00:00
|
|
|
nsresult
|
|
|
|
nsImageLoadingContent::UseAsPrimaryRequest(imgIRequest* aRequest,
|
|
|
|
PRBool aNotify)
|
|
|
|
{
|
2010-07-31 17:54:59 +00:00
|
|
|
// Our state will change. Watch it.
|
2005-09-20 02:05:48 +00:00
|
|
|
AutoStateChanger changer(this, aNotify);
|
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
// Get rid if our existing images
|
|
|
|
ClearPendingRequest(NS_BINDING_ABORTED);
|
|
|
|
ClearCurrentRequest(NS_BINDING_ABORTED);
|
|
|
|
|
|
|
|
// Clone the request we were given.
|
2010-08-04 00:40:29 +00:00
|
|
|
nsCOMPtr<imgIRequest>& req = PrepareNextRequest();;
|
|
|
|
nsresult rv = aRequest->Clone(this, getter_AddRefs(req));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
TrackImage(req);
|
|
|
|
else
|
|
|
|
return rv;
|
2005-09-20 02:05:48 +00:00
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
return NS_OK;
|
2005-09-20 02:05:48 +00:00
|
|
|
}
|
|
|
|
|
2003-07-28 21:09:56 +00:00
|
|
|
nsIDocument*
|
|
|
|
nsImageLoadingContent::GetOurDocument()
|
2003-03-19 01:08:22 +00:00
|
|
|
{
|
2003-07-28 21:09:56 +00:00
|
|
|
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
|
|
|
|
NS_ENSURE_TRUE(thisContent, nsnull);
|
2003-03-19 01:08:22 +00:00
|
|
|
|
2004-10-11 16:29:42 +00:00
|
|
|
return thisContent->GetOwnerDoc();
|
2003-03-19 01:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2005-04-06 02:55:02 +00:00
|
|
|
nsImageLoadingContent::StringToURI(const nsAString& aSpec,
|
2003-03-19 01:08:22 +00:00
|
|
|
nsIDocument* aDocument,
|
|
|
|
nsIURI** aURI)
|
|
|
|
{
|
2003-04-15 01:09:09 +00:00
|
|
|
NS_PRECONDITION(aDocument, "Must have a document");
|
2003-03-19 01:08:22 +00:00
|
|
|
NS_PRECONDITION(aURI, "Null out param");
|
|
|
|
|
|
|
|
// (1) Get the base URI
|
2003-07-03 02:45:34 +00:00
|
|
|
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
|
|
|
|
NS_ASSERTION(thisContent, "An image loading content must be an nsIContent");
|
2004-01-09 23:54:21 +00:00
|
|
|
nsCOMPtr<nsIURI> baseURL = thisContent->GetBaseURI();
|
2003-03-19 01:08:22 +00:00
|
|
|
|
|
|
|
// (2) Get the charset
|
2005-09-21 19:14:30 +00:00
|
|
|
const nsAFlatCString &charset = aDocument->GetDocumentCharacterSet();
|
2003-03-19 01:08:22 +00:00
|
|
|
|
|
|
|
// (3) Construct the silly thing
|
|
|
|
return NS_NewURI(aURI,
|
|
|
|
aSpec,
|
2005-09-21 19:14:30 +00:00
|
|
|
charset.IsEmpty() ? nsnull : charset.get(),
|
2003-05-02 19:21:00 +00:00
|
|
|
baseURL,
|
2005-09-11 10:08:43 +00:00
|
|
|
nsContentUtils::GetIOService());
|
2003-03-19 01:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageLoadingContent::FireEvent(const nsAString& aEventType)
|
|
|
|
{
|
|
|
|
// 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-09 20:42:49 +00:00
|
|
|
|
2010-02-25 02:45:43 +00:00
|
|
|
nsCOMPtr<nsINode> thisNode = do_QueryInterface(this);
|
2003-03-19 01:08:22 +00:00
|
|
|
|
2010-02-25 02:45:43 +00:00
|
|
|
nsRefPtr<nsPLDOMEvent> event =
|
|
|
|
new nsLoadBlockingPLDOMEvent(thisNode, aEventType, PR_FALSE, PR_FALSE);
|
|
|
|
event->PostDOMEvent();
|
2005-05-13 19:54:28 +00:00
|
|
|
|
2010-02-25 02:45:43 +00:00
|
|
|
return NS_OK;
|
2003-03-19 01:08:22 +00:00
|
|
|
}
|
2006-06-01 18:35:21 +00:00
|
|
|
|
2010-07-31 17:54:59 +00:00
|
|
|
nsCOMPtr<imgIRequest>&
|
|
|
|
nsImageLoadingContent::PrepareNextRequest()
|
|
|
|
{
|
|
|
|
// 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))
|
|
|
|
return PrepareCurrentRequest();
|
|
|
|
|
|
|
|
// Otherwise, make it pending.
|
|
|
|
return PreparePendingRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageLoadingContent::SetBlockedRequest(nsIURI* aURI, PRInt16 aContentDecision)
|
|
|
|
{
|
|
|
|
// Sanity
|
|
|
|
NS_ABORT_IF_FALSE(!NS_CP_ACCEPTED(aContentDecision), "Blocked but not?");
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
ClearPendingRequest(NS_ERROR_IMAGE_BLOCKED);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
ClearCurrentRequest(NS_ERROR_IMAGE_BLOCKED);
|
|
|
|
|
|
|
|
// We still want to remember what URI we were despite not having an actual
|
|
|
|
// request.
|
|
|
|
mCurrentURI = aURI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<imgIRequest>&
|
|
|
|
nsImageLoadingContent::PrepareCurrentRequest()
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
ClearCurrentRequest(NS_ERROR_IMAGE_SRC_CHANGED);
|
|
|
|
|
|
|
|
// Return a reference.
|
|
|
|
return mCurrentRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<imgIRequest>&
|
|
|
|
nsImageLoadingContent::PreparePendingRequest()
|
|
|
|
{
|
|
|
|
// Get rid of anything that was there previously.
|
|
|
|
ClearPendingRequest(NS_ERROR_IMAGE_SRC_CHANGED);
|
|
|
|
|
|
|
|
// Return a reference.
|
|
|
|
return mPendingRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageLoadingContent::ClearCurrentRequest(nsresult aReason)
|
|
|
|
{
|
|
|
|
if (!mCurrentRequest) {
|
|
|
|
// Even if we didn't have a current request, we might have been keeping
|
|
|
|
// a URI as a placeholder for a failed load. Clear that now.
|
|
|
|
mCurrentURI = nsnull;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(!mCurrentURI,
|
|
|
|
"Shouldn't have both mCurrentRequest and mCurrentURI!");
|
|
|
|
|
|
|
|
// Clean up the request.
|
2010-08-04 00:40:29 +00:00
|
|
|
UntrackImage(mCurrentRequest);
|
2010-07-31 17:54:59 +00:00
|
|
|
mCurrentRequest->CancelAndForgetObserver(aReason);
|
|
|
|
mCurrentRequest = nsnull;
|
|
|
|
|
|
|
|
// We only block onload during the decoding of "current" images. This one is
|
|
|
|
// going away, so we should unblock unconditionally here.
|
|
|
|
SetBlockingOnload(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageLoadingContent::ClearPendingRequest(nsresult aReason)
|
|
|
|
{
|
|
|
|
if (!mPendingRequest)
|
|
|
|
return;
|
2010-08-04 00:40:29 +00:00
|
|
|
UntrackImage(mPendingRequest);
|
2010-07-31 17:54:59 +00:00
|
|
|
mPendingRequest->CancelAndForgetObserver(aReason);
|
|
|
|
mPendingRequest = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsImageLoadingContent::HaveSize(imgIRequest *aImage)
|
|
|
|
{
|
|
|
|
// Handle the null case
|
|
|
|
if (!aImage)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Query the image
|
|
|
|
PRUint32 status;
|
|
|
|
nsresult rv = aImage->GetImageStatus(&status);
|
|
|
|
return (NS_SUCCEEDED(rv) && (status & imgIRequest::STATUS_SIZE_AVAILABLE));
|
|
|
|
}
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
void
|
|
|
|
nsImageLoadingContent::SetBlockingOnload(PRBool aBlocking)
|
|
|
|
{
|
|
|
|
// If we're already in the desired state, we have nothing to do
|
|
|
|
if (mBlockingOnload == aBlocking)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Get the document
|
|
|
|
nsIDocument* doc = GetOurDocument();
|
|
|
|
|
|
|
|
if (doc) {
|
|
|
|
// Take the appropriate action
|
|
|
|
if (aBlocking)
|
|
|
|
doc->BlockOnload();
|
|
|
|
else
|
|
|
|
doc->UnblockOnload(PR_FALSE);
|
|
|
|
|
|
|
|
// Update our state
|
|
|
|
mBlockingOnload = aBlocking;
|
|
|
|
}
|
|
|
|
}
|
2009-12-11 04:02:13 +00:00
|
|
|
|
2010-08-04 00:40:29 +00:00
|
|
|
nsresult
|
|
|
|
nsImageLoadingContent::TrackImage(imgIRequest* aImage)
|
|
|
|
{
|
2010-09-01 01:26:41 +00:00
|
|
|
if (!aImage)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-08-04 00:40:29 +00:00
|
|
|
nsIDocument* doc = GetOurDocument();
|
|
|
|
if (doc)
|
|
|
|
return doc->AddImage(aImage);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageLoadingContent::UntrackImage(imgIRequest* aImage)
|
|
|
|
{
|
2010-09-01 01:26:41 +00:00
|
|
|
if (!aImage)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-08-04 00:40:29 +00:00
|
|
|
// If GetOurDocument() returns null here, we've outlived our document.
|
|
|
|
// That's fine, because the document empties out the tracker and unlocks
|
|
|
|
// all locked images on destruction.
|
|
|
|
nsIDocument* doc = GetOurDocument();
|
|
|
|
if (doc)
|
|
|
|
return doc->RemoveImage(aImage);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-11 04:02:13 +00:00
|
|
|
void
|
|
|
|
nsImageLoadingContent::CreateStaticImageClone(nsImageLoadingContent* aDest) const
|
|
|
|
{
|
|
|
|
aDest->mCurrentRequest = nsContentUtils::GetStaticRequest(mCurrentRequest);
|
2010-09-01 01:26:41 +00:00
|
|
|
aDest->TrackImage(aDest->mCurrentRequest);
|
2009-12-11 04:02:13 +00:00
|
|
|
aDest->mForcedImageState = mForcedImageState;
|
|
|
|
aDest->mImageBlockingStatus = mImageBlockingStatus;
|
|
|
|
aDest->mLoadingEnabled = mLoadingEnabled;
|
2010-07-31 17:54:59 +00:00
|
|
|
aDest->mStateChangerDepth = mStateChangerDepth;
|
2009-12-11 04:02:13 +00:00
|
|
|
aDest->mIsImageStateForced = mIsImageStateForced;
|
|
|
|
aDest->mLoading = mLoading;
|
|
|
|
aDest->mBroken = mBroken;
|
|
|
|
aDest->mUserDisabled = mUserDisabled;
|
|
|
|
aDest->mSuppressed = mSuppressed;
|
|
|
|
}
|
|
|
|
|