fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
git-svn-id: svn://10.0.0.236/trunk@92152 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -36,8 +36,6 @@
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
#include "DummyChannel.h"
|
||||
|
||||
#include "nspr.h"
|
||||
|
||||
#include "ImageLogging.h"
|
||||
@@ -55,44 +53,44 @@ imgRequestProxy::~imgRequestProxy()
|
||||
{
|
||||
/* destructor code */
|
||||
|
||||
// XXX pav
|
||||
// it isn't the job of the request proxy to cancel itself.
|
||||
// if your object goes away and you want to cancel the load, then do it yourself.
|
||||
if (!mCanceled) {
|
||||
mCanceled = PR_TRUE;
|
||||
|
||||
// cancel here for now until i make this work right like the above comment
|
||||
Cancel(NS_ERROR_FAILURE);
|
||||
/* set mListener to null so that we don't forward any callbacks that RemoveObserver might generate */
|
||||
mListener = nsnull;
|
||||
|
||||
/* Call RemoveObserver 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.
|
||||
*/
|
||||
NS_REINTERPRET_CAST(imgRequest*, mOwner.get())->RemoveProxy(this, NS_OK);
|
||||
|
||||
mOwner = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult imgRequestProxy::Init(imgRequest *request, nsILoadGroup *aLoadGroup, imgIDecoderObserver *aObserver, nsISupports *cx)
|
||||
{
|
||||
PR_ASSERT(request);
|
||||
NS_PRECONDITION(aLoadGroup, "no loadgroup");
|
||||
if (!aLoadGroup)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(request, "no request");
|
||||
if (!request)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequestProxy::Init", "request", request);
|
||||
|
||||
mOwner = NS_STATIC_CAST(imgIRequest*, request);
|
||||
|
||||
mObserver = aObserver;
|
||||
// XXX we should save off the thread we are getting called on here so that we can proxy all calls to mDecoder to it.
|
||||
|
||||
mListener = aObserver;
|
||||
mContext = cx;
|
||||
|
||||
// XXX we should only create a channel, etc if the image isn't finished loading already.
|
||||
aLoadGroup->AddRequest(this, cx);
|
||||
mLoadGroup = aLoadGroup;
|
||||
|
||||
nsISupports *inst = nsnull;
|
||||
inst = new DummyChannel(this, aLoadGroup);
|
||||
NS_ADDREF(inst);
|
||||
nsresult res = inst->QueryInterface(NS_GET_IID(nsIChannel), getter_AddRefs(mDummyChannel));
|
||||
NS_RELEASE(inst);
|
||||
|
||||
nsCOMPtr<nsILoadGroup> loadGroup;
|
||||
mDummyChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
||||
if (loadGroup) {
|
||||
loadGroup->AddRequest(mDummyChannel, cx);
|
||||
}
|
||||
|
||||
request->AddObserver(this);
|
||||
request->AddProxy(this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -102,7 +100,23 @@ nsresult imgRequestProxy::Init(imgRequest *request, nsILoadGroup *aLoadGroup, im
|
||||
/* readonly attribute wstring name; */
|
||||
NS_IMETHODIMP imgRequestProxy::GetName(PRUnichar * *aName)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
nsAutoString name(NS_LITERAL_STRING("imgRequestProxy["));
|
||||
if (mOwner) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
mOwner->GetURI(getter_AddRefs(uri));
|
||||
if (uri) {
|
||||
nsXPIDLCString spec;
|
||||
uri->GetSpec(getter_Copies(spec));
|
||||
if (spec)
|
||||
name.Append(NS_ConvertUTF8toUCS2(spec));
|
||||
}
|
||||
} else {
|
||||
name.Append(NS_LITERAL_STRING("(null)"));
|
||||
}
|
||||
name.Append(PRUnichar(']'));
|
||||
|
||||
*aName = nsCRT::strdup(name.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* boolean isPending (); */
|
||||
@@ -127,12 +141,12 @@ NS_IMETHODIMP imgRequestProxy::Cancel(nsresult status)
|
||||
|
||||
mCanceled = PR_TRUE;
|
||||
|
||||
NS_ASSERTION(mOwner, "canceling request proxy twice");
|
||||
|
||||
nsresult rv = NS_REINTERPRET_CAST(imgRequest*, mOwner.get())->RemoveObserver(this, status);
|
||||
nsresult rv = NS_REINTERPRET_CAST(imgRequest*, mOwner.get())->RemoveProxy(this, status);
|
||||
|
||||
mOwner = nsnull;
|
||||
|
||||
mListener = nsnull;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -151,20 +165,20 @@ NS_IMETHODIMP imgRequestProxy::Resume()
|
||||
/* attribute nsILoadGroup loadGroup */
|
||||
NS_IMETHODIMP imgRequestProxy::GetLoadGroup(nsILoadGroup **loadGroup)
|
||||
{
|
||||
*loadGroup = nsnull;
|
||||
return NS_OK;
|
||||
NS_IF_ADDREF(*loadGroup = mLoadGroup.get());
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP imgRequestProxy::SetLoadGroup(nsILoadGroup *loadGroup)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("imgRequestProxy::SetLoadGroup");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
mLoadGroup = loadGroup;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute nsLoadFlags loadFlags */
|
||||
NS_IMETHODIMP imgRequestProxy::GetLoadFlags(nsLoadFlags *flags)
|
||||
{
|
||||
*flags = nsIRequest::LOAD_NORMAL;
|
||||
return NS_OK;
|
||||
*flags = nsIRequest::LOAD_NORMAL;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP imgRequestProxy::SetLoadFlags(nsLoadFlags flags)
|
||||
{
|
||||
@@ -210,7 +224,7 @@ NS_IMETHODIMP imgRequestProxy::GetURI(nsIURI **aURI)
|
||||
/* readonly attribute imgIDecoderObserver decoderObserver; */
|
||||
NS_IMETHODIMP imgRequestProxy::GetDecoderObserver(imgIDecoderObserver **aDecoderObserver)
|
||||
{
|
||||
*aDecoderObserver = mObserver;
|
||||
*aDecoderObserver = mListener;
|
||||
NS_IF_ADDREF(*aDecoderObserver);
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -224,8 +238,8 @@ NS_IMETHODIMP imgRequestProxy::FrameChanged(imgIContainer *container, nsISupport
|
||||
PR_LOG(gImgLog, PR_LOG_DEBUG,
|
||||
("[this=%p] imgRequestProxy::FrameChanged\n", this));
|
||||
|
||||
if (mObserver)
|
||||
mObserver->FrameChanged(container, mContext, newframe, dirtyRect);
|
||||
if (mListener)
|
||||
mListener->FrameChanged(container, mContext, newframe, dirtyRect);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -238,8 +252,8 @@ NS_IMETHODIMP imgRequestProxy::OnStartDecode(imgIRequest *request, nsISupports *
|
||||
PR_LOG(gImgLog, PR_LOG_DEBUG,
|
||||
("[this=%p] imgRequestProxy::OnStartDecode\n", this));
|
||||
|
||||
if (mObserver)
|
||||
mObserver->OnStartDecode(this, mContext);
|
||||
if (mListener)
|
||||
mListener->OnStartDecode(this, mContext);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -250,8 +264,8 @@ NS_IMETHODIMP imgRequestProxy::OnStartContainer(imgIRequest *request, nsISupport
|
||||
PR_LOG(gImgLog, PR_LOG_DEBUG,
|
||||
("[this=%p] imgRequestProxy::OnStartContainer\n", this));
|
||||
|
||||
if (mObserver)
|
||||
mObserver->OnStartContainer(this, mContext, image);
|
||||
if (mListener)
|
||||
mListener->OnStartContainer(this, mContext, image);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -262,8 +276,8 @@ NS_IMETHODIMP imgRequestProxy::OnStartFrame(imgIRequest *request, nsISupports *c
|
||||
PR_LOG(gImgLog, PR_LOG_DEBUG,
|
||||
("[this=%p] imgRequestProxy::OnStartFrame\n", this));
|
||||
|
||||
if (mObserver)
|
||||
mObserver->OnStartFrame(this, mContext, frame);
|
||||
if (mListener)
|
||||
mListener->OnStartFrame(this, mContext, frame);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -274,8 +288,8 @@ NS_IMETHODIMP imgRequestProxy::OnDataAvailable(imgIRequest *request, nsISupports
|
||||
PR_LOG(gImgLog, PR_LOG_DEBUG,
|
||||
("[this=%p] imgRequestProxy::OnDataAvailable\n", this));
|
||||
|
||||
if (mObserver)
|
||||
mObserver->OnDataAvailable(this, mContext, frame, rect);
|
||||
if (mListener)
|
||||
mListener->OnDataAvailable(this, mContext, frame, rect);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -286,8 +300,8 @@ NS_IMETHODIMP imgRequestProxy::OnStopFrame(imgIRequest *request, nsISupports *cx
|
||||
PR_LOG(gImgLog, PR_LOG_DEBUG,
|
||||
("[this=%p] imgRequestProxy::OnStopFrame\n", this));
|
||||
|
||||
if (mObserver)
|
||||
mObserver->OnStopFrame(this, mContext, frame);
|
||||
if (mListener)
|
||||
mListener->OnStopFrame(this, mContext, frame);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -298,8 +312,8 @@ NS_IMETHODIMP imgRequestProxy::OnStopContainer(imgIRequest *request, nsISupports
|
||||
PR_LOG(gImgLog, PR_LOG_DEBUG,
|
||||
("[this=%p] imgRequestProxy::OnStopContainer\n", this));
|
||||
|
||||
if (mObserver)
|
||||
mObserver->OnStopContainer(this, mContext, image);
|
||||
if (mListener)
|
||||
mListener->OnStopContainer(this, mContext, image);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -310,8 +324,8 @@ NS_IMETHODIMP imgRequestProxy::OnStopDecode(imgIRequest *request, nsISupports *c
|
||||
PR_LOG(gImgLog, PR_LOG_DEBUG,
|
||||
("[this=%p] imgRequestProxy::OnStopDecode\n", this));
|
||||
|
||||
if (mObserver)
|
||||
mObserver->OnStopDecode(this, mContext, status, statusArg);
|
||||
if (mListener)
|
||||
mListener->OnStopDecode(this, mContext, status, statusArg);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -323,22 +337,38 @@ NS_IMETHODIMP imgRequestProxy::OnStopDecode(imgIRequest *request, nsISupports *c
|
||||
/* void onStartRequest (in nsIRequest request, in nsISupports ctxt); */
|
||||
NS_IMETHODIMP imgRequestProxy::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
|
||||
{
|
||||
#ifdef PR_LOGGING
|
||||
if (PR_LOG_TEST(gImgLog, PR_LOG_DEBUG)) {
|
||||
nsXPIDLString name;
|
||||
GetName(getter_Copies(name));
|
||||
PR_LOG(gImgLog, PR_LOG_DEBUG,
|
||||
("[this=%p] imgRequestProxy::OnStartRequest(%s)",
|
||||
this, NS_ConvertUCS2toUTF8(name).get()));
|
||||
}
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void onStopRequest (in nsIRequest request, in nsISupports ctxt, in nsresult statusCode, in wstring statusText); */
|
||||
NS_IMETHODIMP imgRequestProxy::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult statusCode)
|
||||
{
|
||||
if (!mDummyChannel)
|
||||
/* it is ok to get multiple OnStopRequest messages */
|
||||
if (!mLoadGroup)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsILoadGroup> loadGroup;
|
||||
mDummyChannel->GetLoadGroup(getter_AddRefs(loadGroup));
|
||||
if (loadGroup) {
|
||||
loadGroup->RemoveRequest(mDummyChannel, mContext, statusCode);
|
||||
#ifdef PR_LOGGING
|
||||
if (PR_LOG_TEST(gImgLog, PR_LOG_DEBUG)) {
|
||||
nsXPIDLString name;
|
||||
GetName(getter_Copies(name));
|
||||
PR_LOG(gImgLog, PR_LOG_DEBUG,
|
||||
("[this=%p] imgRequestProxy::OnStopRequest(%s)",
|
||||
this, NS_ConvertUCS2toUTF8(name).get()));
|
||||
}
|
||||
mDummyChannel = nsnull;
|
||||
#endif
|
||||
|
||||
mLoadGroup->RemoveRequest(this, mContext, statusCode);
|
||||
mLoadGroup = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user