2001-02-20 22:43:56 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* 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.
|
|
|
|
*
|
2001-02-20 22:43:56 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
2004-04-18 22:01:16 +00:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
2001-02-20 22:43:56 +00:00
|
|
|
* Contributor(s):
|
2006-03-14 06:24:02 +00:00
|
|
|
* Stuart Parmenter <stuart@mozilla.com>
|
2004-04-18 22:01:16 +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
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2001-02-20 23:27:48 +00:00
|
|
|
#include "imgRequestProxy.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2005-10-03 22:27:20 +00:00
|
|
|
#include "nsIMultiPartChannel.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
|
|
|
|
#include "nsString.h"
|
2001-10-12 06:43:52 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2002-03-06 07:48:55 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2003-05-14 05:42:06 +00:00
|
|
|
#include "ImageErrors.h"
|
2001-02-23 10:57:00 +00:00
|
|
|
#include "ImageLogging.h"
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
#include "nspr.h"
|
|
|
|
|
2001-05-08 04:01:28 +00:00
|
|
|
|
2008-08-18 14:08:14 +00:00
|
|
|
NS_IMPL_ISUPPORTS3(imgRequestProxy, imgIRequest, nsIRequest,
|
|
|
|
nsISupportsPriority)
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2001-02-22 02:06:24 +00:00
|
|
|
imgRequestProxy::imgRequestProxy() :
|
2001-10-12 19:30:28 +00:00
|
|
|
mOwner(nsnull),
|
2003-03-17 16:09:02 +00:00
|
|
|
mListener(nsnull),
|
2001-07-17 01:14:40 +00:00
|
|
|
mLoadFlags(nsIRequest::LOAD_NORMAL),
|
2001-05-08 04:01:28 +00:00
|
|
|
mCanceled(PR_FALSE),
|
2008-03-19 19:07:59 +00:00
|
|
|
mIsInLoadGroup(PR_FALSE),
|
|
|
|
mListenerIsStrongRef(PR_FALSE)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
|
|
|
/* member initializers and constructor code */
|
2001-05-08 04:01:28 +00:00
|
|
|
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-02-20 23:27:48 +00:00
|
|
|
imgRequestProxy::~imgRequestProxy()
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
|
|
|
/* destructor code */
|
2003-03-17 16:09:02 +00:00
|
|
|
NS_PRECONDITION(!mListener, "Someone forgot to properly cancel this request!");
|
2006-06-01 18:35:21 +00:00
|
|
|
// Explicitly set mListener to null to ensure that the RemoveProxy
|
|
|
|
// call below can't send |this| to an arbitrary listener while |this|
|
2008-03-19 19:07:59 +00:00
|
|
|
// is being destroyed. This is all belt-and-suspenders in view of the
|
|
|
|
// above assert.
|
|
|
|
NullOutListener();
|
2001-03-06 04:46:20 +00:00
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
if (mOwner) {
|
|
|
|
if (!mCanceled) {
|
|
|
|
mCanceled = PR_TRUE;
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
/* Call RemoveProxy with a successful status. This will keep the
|
|
|
|
channel, if still downloading data, from being canceled if 'this' is
|
|
|
|
the last observer. This allows the image to continue to download and
|
|
|
|
be cached even if no one is using it currently.
|
2006-06-01 18:35:21 +00:00
|
|
|
|
|
|
|
Passing false to aNotify means that we will still get
|
|
|
|
OnStopRequest, if needed.
|
2001-10-12 06:43:52 +00:00
|
|
|
*/
|
2002-01-15 05:23:33 +00:00
|
|
|
mOwner->RemoveProxy(this, NS_OK, PR_FALSE);
|
2001-10-12 06:43:52 +00:00
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-02-26 05:51:32 +00:00
|
|
|
nsresult imgRequestProxy::Init(imgRequest *request, nsILoadGroup *aLoadGroup, imgIDecoderObserver *aObserver)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2007-09-22 19:40:57 +00:00
|
|
|
NS_PRECONDITION(!mOwner && !mListener, "imgRequestProxy is already initialized");
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
NS_PRECONDITION(request, "no request");
|
|
|
|
if (!request)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2001-04-09 00:45:06 +00:00
|
|
|
LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequestProxy::Init", "request", request);
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
mOwner = request;
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
mListener = aObserver;
|
2008-03-19 19:07:59 +00:00
|
|
|
// Make sure to addref mListener before the AddProxy call below, since
|
|
|
|
// that call might well want to release it if the imgRequest has
|
|
|
|
// already seen OnStopRequest.
|
|
|
|
if (mListener) {
|
|
|
|
mListenerIsStrongRef = PR_TRUE;
|
|
|
|
NS_ADDREF(mListener);
|
|
|
|
}
|
2003-05-14 05:42:06 +00:00
|
|
|
mLoadGroup = aLoadGroup;
|
2001-03-06 04:46:20 +00:00
|
|
|
|
2007-09-22 19:40:57 +00:00
|
|
|
// Note: AddProxy won't send all the On* notifications immediatly
|
|
|
|
request->AddProxy(this);
|
2002-01-15 05:23:33 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult imgRequestProxy::ChangeOwner(imgRequest *aNewOwner)
|
|
|
|
{
|
|
|
|
if (mCanceled)
|
|
|
|
return NS_OK;
|
|
|
|
|
2006-06-01 18:35:21 +00:00
|
|
|
// Passing false to aNotify means that mListener will still get
|
|
|
|
// OnStopRequest, if needed.
|
2003-05-14 05:42:06 +00:00
|
|
|
mOwner->RemoveProxy(this, NS_IMAGELIB_CHANGING_OWNER, PR_FALSE);
|
2002-01-15 05:23:33 +00:00
|
|
|
|
|
|
|
mOwner = aNewOwner;
|
|
|
|
|
2007-09-22 19:40:57 +00:00
|
|
|
mOwner->AddProxy(this);
|
2002-01-15 05:23:33 +00:00
|
|
|
|
2001-02-20 22:43:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-05-14 05:42:06 +00:00
|
|
|
void imgRequestProxy::AddToLoadGroup()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mIsInLoadGroup, "Whaa, we're already in the loadgroup!");
|
|
|
|
|
|
|
|
if (!mIsInLoadGroup && mLoadGroup) {
|
|
|
|
mLoadGroup->AddRequest(this, nsnull);
|
|
|
|
mIsInLoadGroup = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-03 22:27:20 +00:00
|
|
|
void imgRequestProxy::RemoveFromLoadGroup(PRBool releaseLoadGroup)
|
2003-05-14 05:42:06 +00:00
|
|
|
{
|
|
|
|
if (!mIsInLoadGroup)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* calling RemoveFromLoadGroup may cause the document to finish
|
|
|
|
loading, which could result in our death. We need to make sure
|
|
|
|
that we stay alive long enough to fight another battle... at
|
|
|
|
least until we exit this function.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<imgIRequest> kungFuDeathGrip(this);
|
|
|
|
|
|
|
|
mLoadGroup->RemoveRequest(this, NS_OK, nsnull);
|
|
|
|
mIsInLoadGroup = PR_FALSE;
|
|
|
|
|
2005-10-03 22:27:20 +00:00
|
|
|
if (releaseLoadGroup) {
|
|
|
|
// We're done with the loadgroup, release it.
|
|
|
|
mLoadGroup = nsnull;
|
|
|
|
}
|
2003-05-14 05:42:06 +00:00
|
|
|
}
|
|
|
|
|
2001-05-08 04:01:28 +00:00
|
|
|
|
2001-03-06 04:46:20 +00:00
|
|
|
/** nsIRequest / imgIRequest methods **/
|
|
|
|
|
|
|
|
/* readonly attribute wstring name; */
|
2002-03-20 22:50:33 +00:00
|
|
|
NS_IMETHODIMP imgRequestProxy::GetName(nsACString &aName)
|
2001-03-06 04:46:20 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
aName.Truncate();
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
if (mOwner) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
mOwner->GetURI(getter_AddRefs(uri));
|
2002-03-06 07:48:55 +00:00
|
|
|
if (uri)
|
2002-03-20 22:50:33 +00:00
|
|
|
uri->GetSpec(aName);
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
}
|
2002-03-20 22:50:33 +00:00
|
|
|
return NS_OK;
|
2001-03-06 04:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean isPending (); */
|
|
|
|
NS_IMETHODIMP imgRequestProxy::IsPending(PRBool *_retval)
|
|
|
|
{
|
2006-11-09 22:47:43 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-03-06 04:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute nsresult status; */
|
|
|
|
NS_IMETHODIMP imgRequestProxy::GetStatus(nsresult *aStatus)
|
|
|
|
{
|
2006-11-09 22:47:43 +00:00
|
|
|
if (!mOwner)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*aStatus = mOwner->GetNetworkStatus();
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-03-06 04:46:20 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
|
|
|
|
/* void cancel (in nsresult status); */
|
2001-02-20 23:27:48 +00:00
|
|
|
NS_IMETHODIMP imgRequestProxy::Cancel(nsresult status)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2001-10-07 17:45:00 +00:00
|
|
|
if (mCanceled || !mOwner)
|
2001-02-22 02:06:24 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-02-26 04:22:47 +00:00
|
|
|
LOG_SCOPE(gImgLog, "imgRequestProxy::Cancel");
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2001-02-22 02:06:24 +00:00
|
|
|
mCanceled = PR_TRUE;
|
2001-03-25 11:57:25 +00:00
|
|
|
|
2006-06-01 18:35:21 +00:00
|
|
|
// Passing false to aNotify means that mListener will still get
|
|
|
|
// OnStopRequest, if needed.
|
2002-01-15 05:23:33 +00:00
|
|
|
mOwner->RemoveProxy(this, status, PR_FALSE);
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2008-03-19 19:07:59 +00:00
|
|
|
NullOutListener();
|
2006-06-01 18:35:21 +00:00
|
|
|
|
2001-04-13 05:37:29 +00:00
|
|
|
return NS_OK;
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-03-06 04:46:20 +00:00
|
|
|
/* void suspend (); */
|
|
|
|
NS_IMETHODIMP imgRequestProxy::Suspend()
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void resume (); */
|
|
|
|
NS_IMETHODIMP imgRequestProxy::Resume()
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2001-04-10 06:01:08 +00:00
|
|
|
/* attribute nsILoadGroup loadGroup */
|
|
|
|
NS_IMETHODIMP imgRequestProxy::GetLoadGroup(nsILoadGroup **loadGroup)
|
|
|
|
{
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
NS_IF_ADDREF(*loadGroup = mLoadGroup.get());
|
|
|
|
return NS_OK;
|
2001-04-10 06:01:08 +00:00
|
|
|
}
|
|
|
|
NS_IMETHODIMP imgRequestProxy::SetLoadGroup(nsILoadGroup *loadGroup)
|
|
|
|
{
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
mLoadGroup = loadGroup;
|
|
|
|
return NS_OK;
|
2001-04-10 06:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute nsLoadFlags loadFlags */
|
|
|
|
NS_IMETHODIMP imgRequestProxy::GetLoadFlags(nsLoadFlags *flags)
|
|
|
|
{
|
2001-07-17 01:14:40 +00:00
|
|
|
*flags = mLoadFlags;
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
return NS_OK;
|
2001-04-10 06:01:08 +00:00
|
|
|
}
|
|
|
|
NS_IMETHODIMP imgRequestProxy::SetLoadFlags(nsLoadFlags flags)
|
|
|
|
{
|
2001-07-17 01:14:40 +00:00
|
|
|
mLoadFlags = flags;
|
|
|
|
return NS_OK;
|
2001-04-10 06:01:08 +00:00
|
|
|
}
|
|
|
|
|
2001-03-06 04:46:20 +00:00
|
|
|
/** imgIRequest methods **/
|
|
|
|
|
2001-04-10 01:51:36 +00:00
|
|
|
/* attribute imgIContainer image; */
|
2001-03-10 01:11:54 +00:00
|
|
|
NS_IMETHODIMP imgRequestProxy::GetImage(imgIContainer * *aImage)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2001-03-25 11:57:25 +00:00
|
|
|
if (!mOwner)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
mOwner->GetImage(aImage);
|
|
|
|
return NS_OK;
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute unsigned long imageStatus; */
|
2001-02-20 23:27:48 +00:00
|
|
|
NS_IMETHODIMP imgRequestProxy::GetImageStatus(PRUint32 *aStatus)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2001-03-25 11:57:25 +00:00
|
|
|
if (!mOwner) {
|
|
|
|
*aStatus = imgIRequest::STATUS_ERROR;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
*aStatus = mOwner->GetImageStatus();
|
|
|
|
return NS_OK;
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-02-22 02:06:24 +00:00
|
|
|
/* readonly attribute nsIURI URI; */
|
|
|
|
NS_IMETHODIMP imgRequestProxy::GetURI(nsIURI **aURI)
|
|
|
|
{
|
2001-03-25 11:57:25 +00:00
|
|
|
if (!mOwner)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-02-22 02:06:24 +00:00
|
|
|
return mOwner->GetURI(aURI);
|
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2001-03-22 23:16:52 +00:00
|
|
|
/* readonly attribute imgIDecoderObserver decoderObserver; */
|
|
|
|
NS_IMETHODIMP imgRequestProxy::GetDecoderObserver(imgIDecoderObserver **aDecoderObserver)
|
|
|
|
{
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
*aDecoderObserver = mListener;
|
2001-03-22 23:16:52 +00:00
|
|
|
NS_IF_ADDREF(*aDecoderObserver);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-12 07:59:21 +00:00
|
|
|
/* readonly attribute string mimeType; */
|
|
|
|
NS_IMETHODIMP imgRequestProxy::GetMimeType(char **aMimeType)
|
|
|
|
{
|
|
|
|
if (!mOwner)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
const char *type = mOwner->GetMimeType();
|
|
|
|
if (!type)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*aMimeType = nsCRT::strdup(type);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-03-09 03:57:51 +00:00
|
|
|
NS_IMETHODIMP imgRequestProxy::Clone(imgIDecoderObserver* aObserver,
|
|
|
|
imgIRequest** aClone)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aClone, "Null out param");
|
|
|
|
*aClone = nsnull;
|
|
|
|
imgRequestProxy* clone = new imgRequestProxy();
|
|
|
|
if (!clone) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(clone);
|
|
|
|
|
|
|
|
// It is important to call |SetLoadFlags()| before calling |Init()| because
|
|
|
|
// |Init()| adds the request to the loadgroup.
|
2006-06-01 18:35:21 +00:00
|
|
|
// When a request is added to a loadgroup, its load flags are merged
|
|
|
|
// with the load flags of the loadgroup.
|
|
|
|
// XXXldb That's not true anymore. Stuff from imgLoader adds the
|
|
|
|
// request to the loadgroup.
|
2004-03-09 03:57:51 +00:00
|
|
|
clone->SetLoadFlags(mLoadFlags);
|
|
|
|
nsresult rv = clone->Init(mOwner, mLoadGroup, aObserver);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(clone);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2004-09-20 22:46:22 +00:00
|
|
|
// Assign to *aClone before calling NotifyProxyListener so that if
|
|
|
|
// the caller expects to only be notified for requests it's already
|
|
|
|
// holding pointers to it won't be surprised.
|
|
|
|
*aClone = clone;
|
|
|
|
|
2004-03-09 03:57:51 +00:00
|
|
|
// Send the notifications to the clone's observer
|
|
|
|
mOwner->NotifyProxyListener(clone);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-22 23:16:52 +00:00
|
|
|
|
2007-11-09 02:55:41 +00:00
|
|
|
/* readonly attribute nsIPrincipal imagePrincipal; */
|
|
|
|
NS_IMETHODIMP imgRequestProxy::GetImagePrincipal(nsIPrincipal **aPrincipal)
|
|
|
|
{
|
|
|
|
if (!mOwner)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return mOwner->GetPrincipal(aPrincipal);
|
|
|
|
}
|
|
|
|
|
2005-02-21 20:58:01 +00:00
|
|
|
/** nsISupportsPriority methods **/
|
|
|
|
|
|
|
|
NS_IMETHODIMP imgRequestProxy::GetPriority(PRInt32 *priority)
|
|
|
|
{
|
|
|
|
NS_ENSURE_STATE(mOwner);
|
|
|
|
*priority = mOwner->Priority();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP imgRequestProxy::SetPriority(PRInt32 priority)
|
|
|
|
{
|
2005-03-04 02:48:58 +00:00
|
|
|
NS_ENSURE_STATE(mOwner && !mCanceled);
|
2005-02-21 22:21:21 +00:00
|
|
|
mOwner->AdjustPriority(this, priority - mOwner->Priority());
|
2005-02-21 20:58:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-21 22:21:21 +00:00
|
|
|
NS_IMETHODIMP imgRequestProxy::AdjustPriority(PRInt32 priority)
|
2005-02-21 20:58:01 +00:00
|
|
|
{
|
2005-03-04 02:48:58 +00:00
|
|
|
NS_ENSURE_STATE(mOwner && !mCanceled);
|
2005-02-21 22:21:21 +00:00
|
|
|
mOwner->AdjustPriority(this, priority);
|
2005-02-21 20:58:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-10 01:11:54 +00:00
|
|
|
/** imgIContainerObserver methods **/
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2004-11-15 04:16:07 +00:00
|
|
|
void imgRequestProxy::FrameChanged(imgIContainer *container, gfxIImageFrame *newframe, nsIntRect * dirtyRect)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2001-05-08 04:01:28 +00:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::FrameChanged");
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2003-03-17 16:09:02 +00:00
|
|
|
if (mListener) {
|
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
|
|
|
nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener);
|
2003-02-26 05:51:32 +00:00
|
|
|
mListener->FrameChanged(container, newframe, dirtyRect);
|
2003-03-17 16:09:02 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-02-20 23:45:51 +00:00
|
|
|
/** imgIDecoderObserver methods **/
|
2001-02-20 22:43:56 +00:00
|
|
|
|
2001-10-12 07:59:21 +00:00
|
|
|
void imgRequestProxy::OnStartDecode()
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2001-05-08 04:01:28 +00:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::OnStartDecode");
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2003-03-17 16:09:02 +00:00
|
|
|
if (mListener) {
|
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
|
|
|
nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener);
|
2003-02-26 05:51:32 +00:00
|
|
|
mListener->OnStartDecode(this);
|
2003-03-17 16:09:02 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-10-12 07:59:21 +00:00
|
|
|
void imgRequestProxy::OnStartContainer(imgIContainer *image)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2001-05-08 04:01:28 +00:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::OnStartContainer");
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2003-03-17 16:09:02 +00:00
|
|
|
if (mListener) {
|
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
|
|
|
nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener);
|
2003-02-26 05:51:32 +00:00
|
|
|
mListener->OnStartContainer(this, image);
|
2003-03-17 16:09:02 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-10-12 07:59:21 +00:00
|
|
|
void imgRequestProxy::OnStartFrame(gfxIImageFrame *frame)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2001-05-08 04:01:28 +00:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::OnStartFrame");
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2003-03-17 16:09:02 +00:00
|
|
|
if (mListener) {
|
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
|
|
|
nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener);
|
2003-02-26 05:51:32 +00:00
|
|
|
mListener->OnStartFrame(this, frame);
|
2003-03-17 16:09:02 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2004-11-15 04:16:07 +00:00
|
|
|
void imgRequestProxy::OnDataAvailable(gfxIImageFrame *frame, const nsIntRect * rect)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2001-05-08 04:01:28 +00:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::OnDataAvailable");
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2003-03-17 16:09:02 +00:00
|
|
|
if (mListener) {
|
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
|
|
|
nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener);
|
2003-02-26 05:51:32 +00:00
|
|
|
mListener->OnDataAvailable(this, frame, rect);
|
2003-03-17 16:09:02 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-10-12 07:59:21 +00:00
|
|
|
void imgRequestProxy::OnStopFrame(gfxIImageFrame *frame)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2001-05-08 04:01:28 +00:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::OnStopFrame");
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2003-03-17 16:09:02 +00:00
|
|
|
if (mListener) {
|
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
|
|
|
nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener);
|
2003-02-26 05:51:32 +00:00
|
|
|
mListener->OnStopFrame(this, frame);
|
2003-03-17 16:09:02 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-10-12 07:59:21 +00:00
|
|
|
void imgRequestProxy::OnStopContainer(imgIContainer *image)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2001-05-08 04:01:28 +00:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::OnStopContainer");
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2003-03-17 16:09:02 +00:00
|
|
|
if (mListener) {
|
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
|
|
|
nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener);
|
2003-02-26 05:51:32 +00:00
|
|
|
mListener->OnStopContainer(this, image);
|
2003-03-17 16:09:02 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-10-12 07:59:21 +00:00
|
|
|
void imgRequestProxy::OnStopDecode(nsresult status, const PRUnichar *statusArg)
|
2001-02-20 22:43:56 +00:00
|
|
|
{
|
2001-05-08 04:01:28 +00:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::OnStopDecode");
|
2001-02-23 08:36:51 +00:00
|
|
|
|
2003-03-17 16:09:02 +00:00
|
|
|
if (mListener) {
|
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
|
|
|
nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener);
|
2003-02-26 05:51:32 +00:00
|
|
|
mListener->OnStopDecode(this, status, statusArg);
|
2003-03-17 16:09:02 +00:00
|
|
|
}
|
2001-02-20 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2001-03-06 04:46:20 +00:00
|
|
|
|
|
|
|
|
2001-10-12 06:43:52 +00:00
|
|
|
void imgRequestProxy::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
|
2001-03-06 04:46:20 +00:00
|
|
|
{
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
#ifdef PR_LOGGING
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString name;
|
|
|
|
GetName(name);
|
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnStartRequest", "name", name.get());
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
#endif
|
2006-06-01 18:35:21 +00:00
|
|
|
|
|
|
|
if (mListener) {
|
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
|
|
|
nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener);
|
|
|
|
mListener->OnStartRequest(this);
|
|
|
|
}
|
2001-03-06 04:46:20 +00:00
|
|
|
}
|
|
|
|
|
2006-06-01 18:35:21 +00:00
|
|
|
void imgRequestProxy::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
|
|
|
|
nsresult statusCode, PRBool lastPart)
|
2001-03-06 04:46:20 +00:00
|
|
|
{
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
#ifdef PR_LOGGING
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString name;
|
|
|
|
GetName(name);
|
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnStopRequest", "name", name.get());
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 02:42:56 +00:00
|
|
|
#endif
|
2008-03-21 06:13:11 +00:00
|
|
|
// There's all sorts of stuff here that could kill us (the OnStopRequest call
|
|
|
|
// on the listener, the removal from the loadgroup, the release of the
|
|
|
|
// listener, etc). Don't let them do it.
|
|
|
|
nsCOMPtr<imgIRequest> kungFuDeathGrip(this);
|
2001-04-09 00:45:06 +00:00
|
|
|
|
2006-06-01 18:35:21 +00:00
|
|
|
if (mListener) {
|
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
|
|
|
nsCOMPtr<imgIDecoderObserver> kungFuDeathGrip(mListener);
|
|
|
|
mListener->OnStopRequest(this, lastPart);
|
2005-10-03 22:27:20 +00:00
|
|
|
}
|
|
|
|
|
2006-06-01 18:35:21 +00:00
|
|
|
// If we're expecting more data from a multipart channel, re-add ourself
|
|
|
|
// to the loadgroup so that the document doesn't lose track of the load.
|
2005-10-03 22:27:20 +00:00
|
|
|
// If the request is already a background request and there's more data
|
|
|
|
// coming, we can just leave the request in the loadgroup as-is.
|
|
|
|
if (lastPart || (mLoadFlags & nsIRequest::LOAD_BACKGROUND) == 0) {
|
|
|
|
RemoveFromLoadGroup(lastPart);
|
|
|
|
// More data is coming, so change the request to be a background request
|
|
|
|
// and put it back in the loadgroup.
|
|
|
|
if (!lastPart) {
|
|
|
|
mLoadFlags |= nsIRequest::LOAD_BACKGROUND;
|
|
|
|
AddToLoadGroup();
|
|
|
|
}
|
|
|
|
}
|
2008-03-19 19:07:59 +00:00
|
|
|
|
|
|
|
if (mListenerIsStrongRef) {
|
|
|
|
NS_PRECONDITION(mListener, "How did that happen?");
|
|
|
|
// Drop our strong ref to the listener now that we're done with
|
|
|
|
// everything. Note that this can cancel us and other fun things
|
|
|
|
// like that. Don't add anything in this method after this point.
|
|
|
|
imgIDecoderObserver* obs = mListener;
|
|
|
|
mListenerIsStrongRef = PR_FALSE;
|
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
2001-03-06 04:46:20 +00:00
|
|
|
}
|
|
|
|
|
2008-03-19 19:07:59 +00:00
|
|
|
void imgRequestProxy::NullOutListener()
|
|
|
|
{
|
|
|
|
if (mListenerIsStrongRef) {
|
|
|
|
// Releasing could do weird reentery stuff, so just play it super-safe
|
|
|
|
nsCOMPtr<imgIDecoderObserver> obs;
|
|
|
|
obs.swap(mListener);
|
|
|
|
mListenerIsStrongRef = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
mListener = nsnull;
|
|
|
|
}
|
|
|
|
}
|