2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nspr.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
#include "nsDocLoader.h"
|
|
|
|
#include "nsCURILoader.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "nsIWebProgressListener2.h"
|
|
|
|
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsWeakPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
|
|
|
|
#include "nsITransport.h"
|
|
|
|
#include "nsISocketTransport.h"
|
|
|
|
|
2009-02-15 10:14:19 -08:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
2010-07-18 19:30:56 -07:00
|
|
|
#include "nsPresContext.h"
|
2010-08-04 19:15:55 -07:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
2009-02-15 10:14:19 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static NS_DEFINE_CID(kThisImplCID, NS_THIS_DOCLOADER_IMPL_CID);
|
|
|
|
|
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
//
|
|
|
|
// Log module for nsIDocumentLoader logging...
|
|
|
|
//
|
|
|
|
// To enable logging (see prlog.h for full details):
|
|
|
|
//
|
|
|
|
// set NSPR_LOG_MODULES=DocLoader:5
|
|
|
|
// set NSPR_LOG_FILE=nspr.log
|
|
|
|
//
|
|
|
|
// this enables PR_LOG_DEBUG level information and places all output in
|
|
|
|
// the file nspr.log
|
|
|
|
//
|
2012-07-30 07:20:58 -07:00
|
|
|
PRLogModuleInfo* gDocLoaderLog = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* PR_LOGGING */
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
void GetURIStringFromRequest(nsIRequest* request, nsACString &name)
|
|
|
|
{
|
|
|
|
if (request)
|
|
|
|
request->GetName(name);
|
|
|
|
else
|
|
|
|
name.AssignLiteral("???");
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2012-10-31 10:23:17 -07:00
|
|
|
|
2012-11-08 00:20:25 -08:00
|
|
|
|
2012-10-19 09:24:12 -07:00
|
|
|
bool
|
|
|
|
nsDocLoader::RequestInfoHashInitEntry(PLDHashTable* table,
|
|
|
|
PLDHashEntryHdr* entry,
|
|
|
|
const void* key)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Initialize the entry with placement new
|
|
|
|
new (entry) nsRequestInfo(key);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-19 09:24:12 -07:00
|
|
|
void
|
|
|
|
nsDocLoader::RequestInfoHashClearEntry(PLDHashTable* table,
|
|
|
|
PLDHashEntryHdr* entry)
|
2009-07-28 10:46:04 -07:00
|
|
|
{
|
|
|
|
nsRequestInfo* info = static_cast<nsRequestInfo *>(entry);
|
|
|
|
info->~nsRequestInfo();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-04-26 10:12:10 -07:00
|
|
|
struct nsListenerInfo {
|
|
|
|
nsListenerInfo(nsIWeakReference *aListener, unsigned long aNotifyMask)
|
|
|
|
: mWeakListener(aListener),
|
|
|
|
mNotifyMask(aNotifyMask)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Weak pointer for the nsIWebProgressListener...
|
|
|
|
nsWeakPtr mWeakListener;
|
|
|
|
|
|
|
|
// Mask indicating which notifications the listener wants to receive.
|
|
|
|
unsigned long mNotifyMask;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-04-26 10:12:10 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDocLoader::nsDocLoader()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mParent(nullptr),
|
2014-04-26 10:12:10 -07:00
|
|
|
mListenerInfoList(8),
|
2011-03-31 17:15:27 -07:00
|
|
|
mCurrentSelfProgress(0),
|
|
|
|
mMaxSelfProgress(0),
|
|
|
|
mCurrentTotalProgress(0),
|
|
|
|
mMaxTotalProgress(0),
|
|
|
|
mCompletedTotalProgress(0),
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsLoadingDocument(false),
|
|
|
|
mIsRestoringDocument(false),
|
|
|
|
mDontFlushLayout(false),
|
|
|
|
mIsFlushingLayout(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#if defined(PR_LOGGING)
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr == gDocLoaderLog) {
|
2007-03-22 10:30:00 -07:00
|
|
|
gDocLoaderLog = PR_NewLogModule("DocLoader");
|
|
|
|
}
|
|
|
|
#endif /* PR_LOGGING */
|
|
|
|
|
2013-11-18 18:58:27 -08:00
|
|
|
static const PLDHashTableOps hash_table_ops =
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
PL_DHashMatchEntryStub,
|
|
|
|
PL_DHashMoveEntryStub,
|
2009-07-28 10:46:04 -07:00
|
|
|
RequestInfoHashClearEntry,
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
RequestInfoHashInitEntry
|
|
|
|
};
|
|
|
|
|
2014-02-27 10:04:09 -08:00
|
|
|
PL_DHashTableInit(&mRequestInfoHash, &hash_table_ops, nullptr,
|
|
|
|
sizeof(nsRequestInfo), 16);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
ClearInternalProgress();
|
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: created.\n", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDocLoader::SetDocLoaderParent(nsDocLoader *aParent)
|
|
|
|
{
|
|
|
|
mParent = aParent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDocLoader::Init()
|
|
|
|
{
|
|
|
|
if (!mRequestInfoHash.ops) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), this);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: load group %x.\n", this, mLoadGroup.get()));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDocLoader::~nsDocLoader()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
|ClearWeakReferences()| here is intended to prevent people holding weak references
|
|
|
|
from re-entering this destructor since |QueryReferent()| will |AddRef()| me, and the
|
|
|
|
subsequent |Release()| will try to destroy me. At this point there should be only
|
|
|
|
weak references remaining (otherwise, we wouldn't be getting destroyed).
|
|
|
|
|
|
|
|
An alternative would be incrementing our refcount (consider it a compressed flag
|
|
|
|
saying "Don't re-destroy."). I haven't yet decided which is better. [scc]
|
|
|
|
*/
|
|
|
|
// XXXbz now that NS_IMPL_RELEASE stabilizes by setting refcount to 1, is
|
|
|
|
// this needed?
|
|
|
|
ClearWeakReferences();
|
|
|
|
|
|
|
|
Destroy();
|
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: deleted.\n", this));
|
|
|
|
|
|
|
|
if (mRequestInfoHash.ops) {
|
|
|
|
PL_DHashTableFinish(&mRequestInfoHash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of ISupports methods...
|
|
|
|
*/
|
2013-04-02 09:41:41 -07:00
|
|
|
NS_IMPL_ADDREF(nsDocLoader)
|
|
|
|
NS_IMPL_RELEASE(nsDocLoader)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDocLoader)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRequestObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocumentLoader)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebProgress)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIProgressEventSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIChannelEventSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISecurityEventSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsPriority)
|
|
|
|
if (aIID.Equals(kThisImplCID))
|
2007-07-08 00:08:04 -07:00
|
|
|
foundInterface = static_cast<nsIDocumentLoader *>(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of nsIInterfaceRequestor methods...
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP nsDocLoader::GetInterface(const nsIID& aIID, void** aSink)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aSink);
|
|
|
|
|
|
|
|
if(aIID.Equals(NS_GET_IID(nsILoadGroup))) {
|
|
|
|
*aSink = mLoadGroup;
|
|
|
|
NS_IF_ADDREF((nsISupports*)*aSink);
|
|
|
|
rv = NS_OK;
|
|
|
|
} else {
|
|
|
|
rv = QueryInterface(aIID, aSink);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsDocLoader>
|
|
|
|
nsDocLoader::GetAsDocLoader(nsISupports* aSupports)
|
|
|
|
{
|
2013-04-22 04:15:59 -07:00
|
|
|
nsRefPtr<nsDocLoader> ret = do_QueryObject(aSupports);
|
|
|
|
return ret.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
nsDocLoader::AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocumentLoader> docLoaderService =
|
|
|
|
do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsRefPtr<nsDocLoader> rootDocLoader = GetAsDocLoader(docLoaderService);
|
|
|
|
NS_ENSURE_TRUE(rootDocLoader, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
return rootDocLoader->AddChildLoader(aDocLoader);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoader::Stop(void)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Stop() called\n", this));
|
|
|
|
|
2013-02-20 13:33:44 -08:00
|
|
|
NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mChildList, nsDocLoader, Stop, ());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mLoadGroup)
|
|
|
|
rv = mLoadGroup->Cancel(NS_BINDING_ABORTED);
|
|
|
|
|
2010-04-10 11:03:40 -07:00
|
|
|
// Don't report that we're flushing layout so IsBusy returns false after a
|
|
|
|
// Stop call.
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsFlushingLayout = false;
|
2010-04-10 11:03:40 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Clear out mChildrenInOnload. We want to make sure to fire our
|
|
|
|
// onload at this point, and there's no issue with mChildrenInOnload
|
|
|
|
// after this, since mDocumentRequest will be null after the
|
|
|
|
// DocLoaderIsEmpty() call.
|
|
|
|
mChildrenInOnload.Clear();
|
|
|
|
|
|
|
|
// Make sure to call DocLoaderIsEmpty now so that we reset mDocumentRequest,
|
|
|
|
// etc, as needed. We could be getting into here from a subframe onload, in
|
|
|
|
// which case the call to DocLoaderIsEmpty() is coming but hasn't quite
|
|
|
|
// happened yet, Canceling the loadgroup did nothing (because it was already
|
|
|
|
// empty), and we're about to start a new load (which is what triggered this
|
|
|
|
// Stop() call).
|
|
|
|
|
|
|
|
// XXXbz If the child frame loadgroups were requests in mLoadgroup, I suspect
|
|
|
|
// we wouldn't need the call here....
|
|
|
|
|
|
|
|
NS_ASSERTION(!IsBusy(), "Shouldn't be busy here");
|
2011-10-17 07:59:28 -07:00
|
|
|
DocLoaderIsEmpty(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDocLoader::IsBusy()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
//
|
|
|
|
// A document loader is busy if either:
|
|
|
|
//
|
|
|
|
// 1. One of its children is in the middle of an onload handler. Note that
|
|
|
|
// the handler may have already removed this child from mChildList!
|
|
|
|
// 2. It is currently loading a document and either has parts of it still
|
|
|
|
// loading, or has a busy child docloader.
|
2009-02-15 10:14:19 -08:00
|
|
|
// 3. It's currently flushing layout in DocLoaderIsEmpty().
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
|
2009-02-15 10:14:19 -08:00
|
|
|
if (mChildrenInOnload.Count() || mIsFlushingLayout) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Is this document loader busy? */
|
|
|
|
if (!mIsLoadingDocument) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool busy;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = mLoadGroup->IsPending(&busy);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (busy) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check its child document loaders... */
|
2013-02-12 22:23:14 -08:00
|
|
|
uint32_t count = mChildList.Length();
|
|
|
|
for (uint32_t i=0; i < count; i++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDocumentLoader* loader = ChildAt(i);
|
|
|
|
|
|
|
|
// This is a safe cast, because we only put nsDocLoader objects into the
|
|
|
|
// array
|
2007-07-08 00:08:04 -07:00
|
|
|
if (loader && static_cast<nsDocLoader*>(loader)->IsBusy())
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoader::GetContainer(nsISupports** aResult)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
NS_ADDREF(*aResult = static_cast<nsIDocumentLoader*>(this));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoader::GetLoadGroup(nsILoadGroup** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr == aResult) {
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
|
|
|
*aResult = mLoadGroup;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDocLoader::Destroy()
|
|
|
|
{
|
|
|
|
Stop();
|
|
|
|
|
|
|
|
// Remove the document loader from the parent list of loaders...
|
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
mParent->RemoveChildLoader(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release all the information about network requests...
|
|
|
|
ClearRequestInfoHash();
|
|
|
|
|
2014-04-26 10:12:10 -07:00
|
|
|
// Release all the information about registered listeners...
|
|
|
|
int32_t count = mListenerInfoList.Count();
|
|
|
|
for(int32_t i = 0; i < count; i++) {
|
|
|
|
nsListenerInfo *info =
|
|
|
|
static_cast<nsListenerInfo*>(mListenerInfoList.ElementAt(i));
|
|
|
|
|
|
|
|
delete info;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mListenerInfoList.Clear();
|
|
|
|
mListenerInfoList.Compact();
|
|
|
|
|
|
|
|
mDocumentRequest = 0;
|
|
|
|
|
|
|
|
if (mLoadGroup)
|
2012-07-30 07:20:58 -07:00
|
|
|
mLoadGroup->SetGroupObserver(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
DestroyChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDocLoader::DestroyChildren()
|
|
|
|
{
|
2013-02-12 22:23:14 -08:00
|
|
|
uint32_t count = mChildList.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
// if the doc loader still has children...we need to enumerate the
|
|
|
|
// children and make them null out their back ptr to the parent doc
|
|
|
|
// loader
|
2013-02-12 22:23:14 -08:00
|
|
|
for (uint32_t i=0; i < count; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIDocumentLoader* loader = ChildAt(i);
|
|
|
|
|
|
|
|
if (loader) {
|
|
|
|
// This is a safe cast, as we only put nsDocLoader objects into the
|
|
|
|
// array
|
2012-07-30 07:20:58 -07:00
|
|
|
static_cast<nsDocLoader*>(loader)->SetDocLoaderParent(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mChildList.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoader::OnStartRequest(nsIRequest *request, nsISupports *aCtxt)
|
|
|
|
{
|
|
|
|
// called each time a request is added to the group.
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gDocLoaderLog, PR_LOG_DEBUG)) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString name;
|
2007-03-22 10:30:00 -07:00
|
|
|
request->GetName(name);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mLoadGroup)
|
|
|
|
mLoadGroup->GetActiveCount(&count);
|
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: OnStartRequest[%p](%s) mIsLoadingDocument=%s, %u active URLs",
|
|
|
|
this, request, name.get(),
|
|
|
|
(mIsLoadingDocument ? "true" : "false"),
|
|
|
|
count));
|
|
|
|
}
|
|
|
|
#endif /* PR_LOGGING */
|
2011-09-28 23:19:26 -07:00
|
|
|
bool bJustStartedLoading = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsLoadFlags loadFlags = 0;
|
|
|
|
request->GetLoadFlags(&loadFlags);
|
|
|
|
|
|
|
|
if (!mIsLoadingDocument && (loadFlags & nsIChannel::LOAD_DOCUMENT_URI)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
bJustStartedLoading = true;
|
|
|
|
mIsLoadingDocument = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
ClearInternalProgress(); // only clear our progress if we are starting a new load....
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2009-04-08 01:45:32 -07:00
|
|
|
// Create a new nsRequestInfo for the request that is starting to
|
|
|
|
// load...
|
|
|
|
//
|
|
|
|
AddRequestInfo(request);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Only fire a doStartDocumentLoad(...) if the document loader
|
2007-03-22 10:30:00 -07:00
|
|
|
// has initiated a load... Otherwise, this notification has
|
|
|
|
// resulted from a request being added to the load group.
|
|
|
|
//
|
|
|
|
if (mIsLoadingDocument) {
|
|
|
|
if (loadFlags & nsIChannel::LOAD_DOCUMENT_URI) {
|
|
|
|
//
|
|
|
|
// Make sure that the document channel is null at this point...
|
|
|
|
// (unless its been redirected)
|
|
|
|
//
|
|
|
|
NS_ASSERTION((loadFlags & nsIChannel::LOAD_REPLACE) ||
|
|
|
|
!(mDocumentRequest.get()),
|
|
|
|
"Overwriting an existing document channel!");
|
|
|
|
|
|
|
|
// This request is associated with the entire document...
|
|
|
|
mDocumentRequest = request;
|
|
|
|
mLoadGroup->SetDefaultLoadRequest(request);
|
|
|
|
|
|
|
|
// Only fire the start document load notification for the first
|
|
|
|
// document URI... Do not fire it again for redirections
|
|
|
|
//
|
|
|
|
if (bJustStartedLoading) {
|
|
|
|
// Update the progress status state
|
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_START;
|
|
|
|
|
|
|
|
// Fire the start document load notification
|
|
|
|
doStartDocumentLoad();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!mIsLoadingDocument || mDocumentRequest,
|
|
|
|
"mDocumentRequest MUST be set for the duration of a page load!");
|
|
|
|
|
|
|
|
doStartURLLoad(request);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoader::OnStopRequest(nsIRequest *aRequest,
|
2009-04-08 01:45:32 -07:00
|
|
|
nsISupports *aCtxt,
|
|
|
|
nsresult aStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(gDocLoaderLog, PR_LOG_DEBUG)) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString name;
|
2007-03-22 10:30:00 -07:00
|
|
|
aRequest->GetName(name);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mLoadGroup)
|
|
|
|
mLoadGroup->GetActiveCount(&count);
|
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: OnStopRequest[%p](%s) status=%x mIsLoadingDocument=%s, %u active URLs",
|
|
|
|
this, aRequest, name.get(),
|
|
|
|
aStatus, (mIsLoadingDocument ? "true" : "false"),
|
|
|
|
count));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool bFireTransferring = false;
|
2009-04-08 01:45:32 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2009-04-08 01:45:32 -07:00
|
|
|
// Set the Maximum progress to the same value as the current progress.
|
|
|
|
// Since the URI has finished loading, all the data is there. Also,
|
|
|
|
// this will allow a more accurate estimation of the max progress (in case
|
|
|
|
// the old value was unknown ie. -1)
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2009-04-08 01:45:32 -07:00
|
|
|
nsRequestInfo *info = GetRequestInfo(aRequest);
|
|
|
|
if (info) {
|
2011-09-06 19:57:46 -07:00
|
|
|
// Null out mLastStatus now so we don't find it when looking for
|
|
|
|
// status from now on. This destroys the nsStatusInfo and hence
|
|
|
|
// removes it from our list.
|
2012-07-30 07:20:58 -07:00
|
|
|
info->mLastStatus = nullptr;
|
2009-07-28 09:13:48 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t oldMax = info->mMaxProgress;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-08 01:45:32 -07:00
|
|
|
info->mMaxProgress = info->mCurrentProgress;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2009-04-08 01:45:32 -07:00
|
|
|
// If a request whose content-length was previously unknown has just
|
|
|
|
// finished loading, then use this new data to try to calculate a
|
|
|
|
// mMaxSelfProgress...
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2012-08-22 08:56:38 -07:00
|
|
|
if ((oldMax < int64_t(0)) && (mMaxSelfProgress < int64_t(0))) {
|
2009-04-08 01:45:32 -07:00
|
|
|
mMaxSelfProgress = CalculateMaxProgress();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-08 01:45:32 -07:00
|
|
|
// As we know the total progress of this request now, save it to be part
|
|
|
|
// of CalculateMaxProgress() result. We need to remove the info from the
|
|
|
|
// hash, see bug 480713.
|
|
|
|
mCompletedTotalProgress += info->mMaxProgress;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Determine whether a STATE_TRANSFERRING notification should be
|
|
|
|
// 'synthesized'.
|
|
|
|
//
|
|
|
|
// If nsRequestInfo::mMaxProgress (as stored in oldMax) and
|
|
|
|
// nsRequestInfo::mCurrentProgress are both 0, then the
|
|
|
|
// STATE_TRANSFERRING notification has not been fired yet...
|
|
|
|
//
|
2012-10-25 16:25:59 -07:00
|
|
|
if ((oldMax == 0) && (info->mCurrentProgress == 0)) {
|
2009-04-08 01:45:32 -07:00
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-08 01:45:32 -07:00
|
|
|
// Only fire a TRANSFERRING notification if the request is also a
|
|
|
|
// channel -- data transfer requires a nsIChannel!
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2009-04-08 01:45:32 -07:00
|
|
|
if (channel) {
|
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
bFireTransferring = true;
|
2009-04-08 01:45:32 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2009-04-08 01:45:32 -07:00
|
|
|
// If the request failed (for any reason other than being
|
|
|
|
// redirected or retargeted), the TRANSFERRING notification can
|
|
|
|
// still be fired if a HTTP connection was established to a server.
|
|
|
|
//
|
|
|
|
else if (aStatus != NS_BINDING_REDIRECTED &&
|
|
|
|
aStatus != NS_BINDING_RETARGETED) {
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2009-04-08 01:45:32 -07:00
|
|
|
// Only if the load has been targeted (see bug 268483)...
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t lf;
|
2009-04-08 01:45:32 -07:00
|
|
|
channel->GetLoadFlags(&lf);
|
|
|
|
if (lf & nsIChannel::LOAD_TARGETED) {
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest));
|
|
|
|
if (httpChannel) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t responseCode;
|
2009-04-08 01:45:32 -07:00
|
|
|
rv = httpChannel->GetResponseStatus(&responseCode);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
//
|
|
|
|
// A valid server status indicates that a connection was
|
|
|
|
// established to the server... So, fire the notification
|
|
|
|
// even though a failure occurred later...
|
|
|
|
//
|
2011-10-17 07:59:28 -07:00
|
|
|
bFireTransferring = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-08 01:45:32 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-08 01:45:32 -07:00
|
|
|
if (bFireTransferring) {
|
|
|
|
// Send a STATE_TRANSFERRING notification for the request.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t flags;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-08 01:45:32 -07:00
|
|
|
flags = nsIWebProgressListener::STATE_TRANSFERRING |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST;
|
|
|
|
//
|
|
|
|
// Move the WebProgress into the STATE_TRANSFERRING state if necessary...
|
|
|
|
//
|
|
|
|
if (mProgressStateFlags & nsIWebProgressListener::STATE_START) {
|
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_TRANSFERRING;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-08 01:45:32 -07:00
|
|
|
// Send STATE_TRANSFERRING for the document too...
|
|
|
|
flags |= nsIWebProgressListener::STATE_IS_DOCUMENT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-04-08 01:45:32 -07:00
|
|
|
FireOnStateChange(this, aRequest, flags, NS_OK);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-04-08 01:45:32 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// Fire the OnStateChange(...) notification for stop request
|
|
|
|
//
|
|
|
|
doStopURLLoad(aRequest, aStatus);
|
|
|
|
|
|
|
|
// Clear this request out of the hash to avoid bypass of FireOnStateChange
|
|
|
|
// when address of the request is reused.
|
|
|
|
RemoveRequestInfo(aRequest);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Only fire the DocLoaderIsEmpty(...) if the document loader has initiated a
|
|
|
|
// load. This will handle removing the request from our hashtable as needed.
|
|
|
|
//
|
|
|
|
if (mIsLoadingDocument) {
|
2011-10-17 07:59:28 -07:00
|
|
|
DocLoaderIsEmpty(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult nsDocLoader::RemoveChildLoader(nsDocLoader* aChild)
|
|
|
|
{
|
|
|
|
nsresult rv = mChildList.RemoveElement(aChild) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
aChild->SetDocLoaderParent(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsDocLoader::AddChildLoader(nsDocLoader* aChild)
|
|
|
|
{
|
|
|
|
nsresult rv = mChildList.AppendElement(aChild) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aChild->SetDocLoaderParent(this);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocLoader::GetDocumentChannel(nsIChannel ** aChannel)
|
|
|
|
{
|
|
|
|
if (!mDocumentRequest) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aChannel = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(mDocumentRequest, aChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void nsDocLoader::DocLoaderIsEmpty(bool aFlushLayout)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mIsLoadingDocument) {
|
|
|
|
/* In the unimagineably rude circumstance that onload event handlers
|
|
|
|
triggered by this function actually kill the window ... ok, it's
|
|
|
|
not unimagineable; it's happened ... this deathgrip keeps this object
|
|
|
|
alive long enough to survive this function call. */
|
|
|
|
nsCOMPtr<nsIDocumentLoader> kungFuDeathGrip(this);
|
|
|
|
|
2009-02-15 10:14:19 -08:00
|
|
|
// Don't flush layout if we're still busy.
|
|
|
|
if (IsBusy()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!mIsFlushingLayout, "Someone screwed up");
|
|
|
|
|
2010-07-18 19:30:56 -07:00
|
|
|
// The load group for this DocumentLoader is idle. Flush if we need to.
|
2010-04-10 11:03:40 -07:00
|
|
|
if (aFlushLayout && !mDontFlushLayout) {
|
2009-02-15 10:14:19 -08:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_GetInterface(GetAsSupports(this));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
|
|
|
if (doc) {
|
2010-07-18 19:30:56 -07:00
|
|
|
// We start loads from style resolution, so we need to flush out style
|
|
|
|
// no matter what. If we have user fonts, we also need to flush layout,
|
|
|
|
// since the reflow is what starts font loads.
|
|
|
|
mozFlushType flushType = Flush_Style;
|
|
|
|
nsIPresShell* shell = doc->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
// Be safe in case this presshell is in teardown now
|
|
|
|
nsPresContext* presContext = shell->GetPresContext();
|
|
|
|
if (presContext && presContext->GetUserFontSet()) {
|
|
|
|
flushType = Flush_Layout;
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mDontFlushLayout = mIsFlushingLayout = true;
|
2010-07-18 19:30:56 -07:00
|
|
|
doc->FlushPendingNotifications(flushType);
|
2011-10-17 07:59:28 -07:00
|
|
|
mDontFlushLayout = mIsFlushingLayout = false;
|
2009-02-15 10:14:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// And now check whether we're really busy; that might have changed with
|
|
|
|
// the layout flush.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!IsBusy()) {
|
2009-04-08 01:45:32 -07:00
|
|
|
// Clear out our request info hash, now that our load really is done and
|
|
|
|
// we don't need it anymore to CalculateMaxProgress().
|
|
|
|
ClearInternalProgress();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Is now idle...\n", this));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRequest> docRequest = mDocumentRequest;
|
|
|
|
|
|
|
|
NS_ASSERTION(mDocumentRequest, "No Document Request!");
|
|
|
|
mDocumentRequest = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsLoadingDocument = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Update the progress status state - the document is done
|
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_STOP;
|
|
|
|
|
|
|
|
|
|
|
|
nsresult loadGroupStatus = NS_OK;
|
|
|
|
mLoadGroup->GetStatus(&loadGroupStatus);
|
|
|
|
|
|
|
|
//
|
|
|
|
// New code to break the circular reference between
|
|
|
|
// the load group and the docloader...
|
|
|
|
//
|
2012-07-30 07:20:58 -07:00
|
|
|
mLoadGroup->SetDefaultLoadRequest(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Take a ref to our parent now so that we can call DocLoaderIsEmpty() on
|
|
|
|
// it even if our onload handler removes us from the docloader tree.
|
|
|
|
nsRefPtr<nsDocLoader> parent = mParent;
|
|
|
|
|
|
|
|
// Note that if calling ChildEnteringOnload() on the parent returns false
|
|
|
|
// then calling our onload handler is not safe. That can only happen on
|
|
|
|
// OOM, so that's ok.
|
|
|
|
if (!parent || parent->ChildEnteringOnload(this)) {
|
|
|
|
// Do nothing with our state after firing the
|
|
|
|
// OnEndDocumentLoad(...). The document loader may be loading a *new*
|
|
|
|
// document - if LoadDocument() was called from a handler!
|
|
|
|
//
|
|
|
|
doStopDocumentLoad(docRequest, loadGroupStatus);
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
parent->ChildDoneWithOnload(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDocLoader::doStartDocumentLoad(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buffer;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
GetURIStringFromRequest(mDocumentRequest, buffer);
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange for start document load (...)."
|
|
|
|
"\tURI: %s \n",
|
|
|
|
this, buffer.get()));
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
// Fire an OnStatus(...) notification STATE_START. This indicates
|
|
|
|
// that the document represented by mDocumentRequest has started to
|
|
|
|
// load...
|
|
|
|
FireOnStateChange(this,
|
|
|
|
mDocumentRequest,
|
|
|
|
nsIWebProgressListener::STATE_START |
|
|
|
|
nsIWebProgressListener::STATE_IS_DOCUMENT |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST |
|
|
|
|
nsIWebProgressListener::STATE_IS_WINDOW |
|
|
|
|
nsIWebProgressListener::STATE_IS_NETWORK,
|
|
|
|
NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDocLoader::doStartURLLoad(nsIRequest *request)
|
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buffer;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
GetURIStringFromRequest(request, buffer);
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange start url load (...)."
|
|
|
|
"\tURI: %s\n",
|
|
|
|
this, buffer.get()));
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
FireOnStateChange(this,
|
|
|
|
request,
|
|
|
|
nsIWebProgressListener::STATE_START |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST,
|
|
|
|
NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDocLoader::doStopURLLoad(nsIRequest *request, nsresult aStatus)
|
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buffer;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
GetURIStringFromRequest(request, buffer);
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange for end url load (...)."
|
|
|
|
"\tURI: %s status=%x\n",
|
|
|
|
this, buffer.get(), aStatus));
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
FireOnStateChange(this,
|
|
|
|
request,
|
|
|
|
nsIWebProgressListener::STATE_STOP |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST,
|
|
|
|
aStatus);
|
2009-07-28 09:13:48 -07:00
|
|
|
|
2011-09-06 19:57:46 -07:00
|
|
|
// Fire a status change message for the most recent unfinished
|
|
|
|
// request to make sure that the displayed status is not outdated.
|
2012-10-19 09:24:12 -07:00
|
|
|
if (!mStatusInfoList.isEmpty()) {
|
|
|
|
nsStatusInfo* statusInfo = mStatusInfoList.getFirst();
|
2011-09-06 19:57:46 -07:00
|
|
|
FireOnStatusChange(this, statusInfo->mRequest,
|
|
|
|
statusInfo->mStatusCode,
|
|
|
|
statusInfo->mStatusMessage.get());
|
2009-07-28 09:13:48 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDocLoader::doStopDocumentLoad(nsIRequest *request,
|
|
|
|
nsresult aStatus)
|
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buffer;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
GetURIStringFromRequest(request, buffer);
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange for end document load (...)."
|
|
|
|
"\tURI: %s Status=%x\n",
|
|
|
|
this, buffer.get(), aStatus));
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2011-09-08 20:19:45 -07:00
|
|
|
// Firing STATE_STOP|STATE_IS_DOCUMENT will fire onload handlers.
|
|
|
|
// Grab our parent chain before doing that so we can still dispatch
|
|
|
|
// STATE_STOP|STATE_IS_WINDW_STATE_IS_NETWORK to them all, even if
|
|
|
|
// the onload handlers rearrange the docshell tree.
|
|
|
|
WebProgressList list;
|
|
|
|
GatherAncestorWebProgresses(list);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// Fire an OnStateChange(...) notification indicating the the
|
|
|
|
// current document has finished loading...
|
|
|
|
//
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t flags = nsIWebProgressListener::STATE_STOP |
|
2011-09-08 20:19:45 -07:00
|
|
|
nsIWebProgressListener::STATE_IS_DOCUMENT;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < list.Length(); ++i) {
|
2011-09-08 20:19:45 -07:00
|
|
|
list[i]->DoFireOnStateChange(this, request, flags, aStatus);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// Fire a final OnStateChange(...) notification indicating the the
|
|
|
|
// current document has finished loading...
|
|
|
|
//
|
2011-09-08 20:19:45 -07:00
|
|
|
flags = nsIWebProgressListener::STATE_STOP |
|
|
|
|
nsIWebProgressListener::STATE_IS_WINDOW |
|
|
|
|
nsIWebProgressListener::STATE_IS_NETWORK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < list.Length(); ++i) {
|
2011-09-08 20:19:45 -07:00
|
|
|
list[i]->DoFireOnStateChange(this, request, flags, aStatus);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// The following section contains support for nsIWebProgress and related stuff
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoader::AddProgressListener(nsIWebProgressListener *aListener,
|
2014-04-26 10:12:10 -07:00
|
|
|
uint32_t aNotifyMask)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-04-26 10:12:10 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsListenerInfo* info = GetListenerInfo(aListener);
|
|
|
|
if (info) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// The listener is already registered!
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWeakPtr listener = do_GetWeakReference(aListener);
|
|
|
|
if (!listener) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2014-04-26 10:12:10 -07:00
|
|
|
info = new nsListenerInfo(listener, aNotifyMask);
|
|
|
|
if (!info) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mListenerInfoList.AppendElement(info) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoader::RemoveProgressListener(nsIWebProgressListener *aListener)
|
|
|
|
{
|
2014-04-26 10:12:10 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsListenerInfo* info = GetListenerInfo(aListener);
|
|
|
|
if (info) {
|
|
|
|
rv = mListenerInfoList.RemoveElement(info) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
delete info;
|
|
|
|
} else {
|
|
|
|
// The listener is not registered!
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoader::GetDOMWindow(nsIDOMWindow **aResult)
|
|
|
|
{
|
|
|
|
return CallGetInterface(this, aResult);
|
|
|
|
}
|
|
|
|
|
2013-04-24 22:26:13 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoader::GetDOMWindowID(uint64_t *aResult)
|
|
|
|
{
|
|
|
|
*aResult = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> window;
|
|
|
|
nsresult rv = GetDOMWindow(getter_AddRefs(window));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> piwindow = do_QueryInterface(window);
|
|
|
|
NS_ENSURE_STATE(piwindow);
|
|
|
|
|
|
|
|
MOZ_ASSERT(piwindow->IsOuterWindow());
|
|
|
|
*aResult = piwindow->WindowID();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoader::GetIsTopLevel(bool *aResult)
|
|
|
|
{
|
|
|
|
*aResult = false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> window;
|
2013-04-29 15:52:57 -07:00
|
|
|
GetDOMWindow(getter_AddRefs(window));
|
|
|
|
if (window) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> piwindow = do_QueryInterface(window);
|
|
|
|
NS_ENSURE_STATE(piwindow);
|
2013-04-24 22:26:13 -07:00
|
|
|
|
2013-04-29 15:52:57 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> topWindow;
|
|
|
|
nsresult rv = piwindow->GetTop(getter_AddRefs(topWindow));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-04-24 22:26:13 -07:00
|
|
|
|
2013-04-29 15:52:57 -07:00
|
|
|
*aResult = piwindow == topWindow;
|
|
|
|
}
|
2013-04-24 22:26:13 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDocLoader::GetIsLoadingDocument(bool *aIsLoadingDocument)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aIsLoadingDocument = mIsLoadingDocument;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-29 08:03:41 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoader::GetLoadType(uint32_t *aLoadType)
|
|
|
|
{
|
|
|
|
*aLoadType = 0;
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t nsDocLoader::GetMaxTotalProgress()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t newMaxTotal = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-12 22:23:14 -08:00
|
|
|
uint32_t count = mChildList.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIWebProgress> webProgress;
|
2013-02-12 22:23:14 -08:00
|
|
|
for (uint32_t i=0; i < count; i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t individualProgress = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDocumentLoader* docloader = ChildAt(i);
|
|
|
|
if (docloader)
|
|
|
|
{
|
|
|
|
// Cast is safe since all children are nsDocLoader too
|
|
|
|
individualProgress = ((nsDocLoader *) docloader)->GetMaxTotalProgress();
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
if (individualProgress < int64_t(0)) // if one of the elements doesn't know it's size
|
2007-03-22 10:30:00 -07:00
|
|
|
// then none of them do
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
newMaxTotal = int64_t(-1);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newMaxTotal += individualProgress;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t progress = -1;
|
|
|
|
if (mMaxSelfProgress >= int64_t(0) && newMaxTotal >= int64_t(0))
|
2007-03-22 10:30:00 -07:00
|
|
|
progress = newMaxTotal + mMaxSelfProgress;
|
|
|
|
|
|
|
|
return progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// The following section contains support for nsIProgressEventSink which is used to
|
|
|
|
// pass progress and status between the actual request and the doc loader. The doc loader
|
|
|
|
// then turns around and makes the right web progress calls based on this information.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocLoader::OnProgress(nsIRequest *aRequest, nsISupports* ctxt,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t aProgress, uint64_t aProgressMax)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsRequestInfo *info;
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t progressDelta = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// Update the RequestInfo entry with the new progress data
|
|
|
|
//
|
|
|
|
info = GetRequestInfo(aRequest);
|
|
|
|
if (info) {
|
|
|
|
// suppress sending STATE_TRANSFERRING if this is upload progress (see bug 240053)
|
2012-08-22 08:56:38 -07:00
|
|
|
if (!info->mUploading && (int64_t(0) == info->mCurrentProgress) && (int64_t(0) == info->mMaxProgress)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// If we receive an OnProgress event from a toplevel channel that the URI Loader
|
|
|
|
// has not yet targeted, then we must suppress the event. This is necessary to
|
|
|
|
// ensure that webprogresslisteners do not get confused when the channel is
|
|
|
|
// finally targeted. See bug 257308.
|
|
|
|
//
|
|
|
|
nsLoadFlags lf = 0;
|
|
|
|
aRequest->GetLoadFlags(&lf);
|
|
|
|
if ((lf & nsIChannel::LOAD_DOCUMENT_URI) && !(lf & nsIChannel::LOAD_TARGETED)) {
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p Ignoring OnProgress while load is not targeted\n", this));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This is the first progress notification for the entry. If
|
|
|
|
// (aMaxProgress > 0) then the content-length of the data is known,
|
|
|
|
// so update mMaxSelfProgress... Otherwise, set it to -1 to indicate
|
|
|
|
// that the content-length is no longer known.
|
|
|
|
//
|
2012-09-28 12:55:23 -07:00
|
|
|
if (uint64_t(aProgressMax) != UINT64_MAX) {
|
2012-08-22 08:56:38 -07:00
|
|
|
mMaxSelfProgress += int64_t(aProgressMax);
|
|
|
|
info->mMaxProgress = int64_t(aProgressMax);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
mMaxSelfProgress = int64_t(-1);
|
|
|
|
info->mMaxProgress = int64_t(-1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send a STATE_TRANSFERRING notification for the request.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t flags;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
flags = nsIWebProgressListener::STATE_TRANSFERRING |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST;
|
|
|
|
//
|
|
|
|
// Move the WebProgress into the STATE_TRANSFERRING state if necessary...
|
|
|
|
//
|
|
|
|
if (mProgressStateFlags & nsIWebProgressListener::STATE_START) {
|
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_TRANSFERRING;
|
|
|
|
|
|
|
|
// Send STATE_TRANSFERRING for the document too...
|
|
|
|
flags |= nsIWebProgressListener::STATE_IS_DOCUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
FireOnStateChange(this, aRequest, flags, NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the current progress count...
|
2012-08-22 08:56:38 -07:00
|
|
|
progressDelta = int64_t(aProgress) - info->mCurrentProgress;
|
2007-03-22 10:30:00 -07:00
|
|
|
mCurrentSelfProgress += progressDelta;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
info->mCurrentProgress = int64_t(aProgress);
|
2009-04-08 01:45:32 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// The request is not part of the load group, so ignore its progress
|
|
|
|
// information...
|
|
|
|
//
|
|
|
|
else {
|
|
|
|
#if defined(DEBUG)
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buffer;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
GetURIStringFromRequest(aRequest, buffer);
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p OOPS - No Request Info for: %s\n",
|
|
|
|
this, buffer.get()));
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fire progress notifications out to any registered nsIWebProgressListeners
|
|
|
|
//
|
|
|
|
FireOnProgressChange(this, aRequest, aProgress, aProgressMax, progressDelta,
|
|
|
|
mCurrentTotalProgress, mMaxTotalProgress);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocLoader::OnStatus(nsIRequest* aRequest, nsISupports* ctxt,
|
2014-01-04 07:02:17 -08:00
|
|
|
nsresult aStatus, const char16_t* aStatusArg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// Fire progress notifications out to any registered nsIWebProgressListeners
|
|
|
|
//
|
2012-08-14 02:10:42 -07:00
|
|
|
if (aStatus != NS_OK) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Remember the current status for this request
|
|
|
|
nsRequestInfo *info;
|
|
|
|
info = GetRequestInfo(aRequest);
|
|
|
|
if (info) {
|
2012-08-07 08:11:35 -07:00
|
|
|
bool uploading = (aStatus == NS_NET_STATUS_WRITING ||
|
|
|
|
aStatus == NS_NET_STATUS_SENDING_TO);
|
2007-03-22 10:30:00 -07:00
|
|
|
// If switching from uploading to downloading (or vice versa), then we
|
|
|
|
// need to reset our progress counts. This is designed with HTTP form
|
|
|
|
// submission in mind, where an upload is performed followed by download
|
|
|
|
// of possibly several documents.
|
|
|
|
if (info->mUploading != uploading) {
|
2012-10-25 16:25:59 -07:00
|
|
|
mCurrentSelfProgress = mMaxSelfProgress = 0;
|
|
|
|
mCurrentTotalProgress = mMaxTotalProgress = 0;
|
|
|
|
mCompletedTotalProgress = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
info->mUploading = uploading;
|
2012-10-25 16:25:59 -07:00
|
|
|
info->mCurrentProgress = 0;
|
|
|
|
info->mMaxProgress = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-05-14 02:24:41 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundleService> sbs =
|
|
|
|
mozilla::services::GetStringBundleService();
|
|
|
|
if (!sbs)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXPIDLString msg;
|
2010-05-14 02:24:41 -07:00
|
|
|
nsresult rv = sbs->FormatStatusMessage(aStatus, aStatusArg,
|
|
|
|
getter_Copies(msg));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2009-07-28 09:13:48 -07:00
|
|
|
|
|
|
|
// Keep around the message. In case a request finishes, we need to make sure
|
|
|
|
// to send the status message of another request to our user to that we
|
|
|
|
// don't display, for example, "Transferring" messages for requests that are
|
|
|
|
// already done.
|
|
|
|
if (info) {
|
2011-09-06 19:57:46 -07:00
|
|
|
if (!info->mLastStatus) {
|
|
|
|
info->mLastStatus = new nsStatusInfo(aRequest);
|
|
|
|
} else {
|
|
|
|
// We're going to move it to the front of the list, so remove
|
|
|
|
// it from wherever it is now.
|
2012-10-19 09:24:12 -07:00
|
|
|
info->mLastStatus->remove();
|
2011-09-06 19:57:46 -07:00
|
|
|
}
|
|
|
|
info->mLastStatus->mStatusMessage = msg;
|
|
|
|
info->mLastStatus->mStatusCode = aStatus;
|
|
|
|
// Put the info at the front of the list
|
2012-10-19 09:24:12 -07:00
|
|
|
mStatusInfoList.insertFront(info->mLastStatus);
|
2009-07-28 09:13:48 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
FireOnStatusChange(this, aRequest, aStatus, msg);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDocLoader::ClearInternalProgress()
|
|
|
|
{
|
|
|
|
ClearRequestInfoHash();
|
|
|
|
|
2012-10-25 16:25:59 -07:00
|
|
|
mCurrentSelfProgress = mMaxSelfProgress = 0;
|
|
|
|
mCurrentTotalProgress = mMaxTotalProgress = 0;
|
|
|
|
mCompletedTotalProgress = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nsDocLoader::FireOnProgressChange(nsDocLoader *aLoadInitiator,
|
|
|
|
nsIRequest *request,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aProgress,
|
|
|
|
int64_t aProgressMax,
|
|
|
|
int64_t aProgressDelta,
|
|
|
|
int64_t aTotalProgress,
|
|
|
|
int64_t aMaxTotalProgress)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mIsLoadingDocument) {
|
|
|
|
mCurrentTotalProgress += aProgressDelta;
|
|
|
|
mMaxTotalProgress = GetMaxTotalProgress();
|
|
|
|
|
|
|
|
aTotalProgress = mCurrentTotalProgress;
|
|
|
|
aMaxTotalProgress = mMaxTotalProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buffer;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
GetURIStringFromRequest(request, buffer);
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Progress (%s): curSelf: %d maxSelf: %d curTotal: %d maxTotal %d\n",
|
|
|
|
this, buffer.get(), aProgress, aProgressMax, aTotalProgress, aMaxTotalProgress));
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2014-04-26 10:12:10 -07:00
|
|
|
/*
|
|
|
|
* First notify any listeners of the new progress info...
|
|
|
|
*
|
|
|
|
* Operate the elements from back to front so that if items get
|
|
|
|
* get removed from the list it won't affect our iteration
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
int32_t count = mListenerInfoList.Count();
|
|
|
|
|
|
|
|
while (--count >= 0) {
|
|
|
|
nsListenerInfo *info;
|
|
|
|
|
|
|
|
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
|
|
|
|
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_PROGRESS)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener = do_QueryReferent(info->mWeakListener);
|
|
|
|
if (!listener) {
|
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerInfoList.RemoveElementAt(count);
|
|
|
|
delete info;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX truncates 64-bit to 32-bit
|
|
|
|
listener->OnProgressChange(aLoadInitiator,request,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t(aProgress), int32_t(aProgressMax),
|
|
|
|
int32_t(aTotalProgress), int32_t(aMaxTotalProgress));
|
2014-04-26 10:12:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mListenerInfoList.Compact();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
|
|
|
mParent->FireOnProgressChange(aLoadInitiator, request,
|
|
|
|
aProgress, aProgressMax,
|
|
|
|
aProgressDelta,
|
|
|
|
aTotalProgress, aMaxTotalProgress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-08 20:19:45 -07:00
|
|
|
void nsDocLoader::GatherAncestorWebProgresses(WebProgressList& aList)
|
|
|
|
{
|
|
|
|
for (nsDocLoader* loader = this; loader; loader = loader->mParent) {
|
|
|
|
aList.AppendElement(loader);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void nsDocLoader::FireOnStateChange(nsIWebProgress *aProgress,
|
|
|
|
nsIRequest *aRequest,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aStateFlags,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult aStatus)
|
2011-09-08 20:19:45 -07:00
|
|
|
{
|
|
|
|
WebProgressList list;
|
|
|
|
GatherAncestorWebProgresses(list);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < list.Length(); ++i) {
|
2011-09-08 20:19:45 -07:00
|
|
|
list[i]->DoFireOnStateChange(aProgress, aRequest, aStateFlags, aStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDocLoader::DoFireOnStateChange(nsIWebProgress * const aProgress,
|
|
|
|
nsIRequest * const aRequest,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t &aStateFlags,
|
2011-09-08 20:19:45 -07:00
|
|
|
const nsresult aStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// Remove the STATE_IS_NETWORK bit if necessary.
|
|
|
|
//
|
|
|
|
// The rule is to remove this bit, if the notification has been passed
|
|
|
|
// up from a child WebProgress, and the current WebProgress is already
|
|
|
|
// active...
|
|
|
|
//
|
|
|
|
if (mIsLoadingDocument &&
|
|
|
|
(aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) &&
|
|
|
|
(this != aProgress)) {
|
|
|
|
aStateFlags &= ~nsIWebProgressListener::STATE_IS_NETWORK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the STATE_RESTORING bit if necessary.
|
|
|
|
if (mIsRestoringDocument)
|
|
|
|
aStateFlags |= nsIWebProgressListener::STATE_RESTORING;
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buffer;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
GetURIStringFromRequest(aRequest, buffer);
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Status (%s): code: %x\n",
|
|
|
|
this, buffer.get(), aStateFlags));
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
NS_ASSERTION(aRequest, "Firing OnStateChange(...) notification with a NULL request!");
|
|
|
|
|
2014-04-26 10:12:10 -07:00
|
|
|
/*
|
|
|
|
* First notify any listeners of the new state info...
|
|
|
|
*
|
|
|
|
* Operate the elements from back to front so that if items get
|
|
|
|
* get removed from the list it won't affect our iteration
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
int32_t count = mListenerInfoList.Count();
|
|
|
|
int32_t notifyMask = (aStateFlags >> 16) & nsIWebProgress::NOTIFY_STATE_ALL;
|
|
|
|
|
|
|
|
while (--count >= 0) {
|
|
|
|
nsListenerInfo *info;
|
|
|
|
|
|
|
|
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
|
|
|
|
if (!info || !(info->mNotifyMask & notifyMask)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener = do_QueryReferent(info->mWeakListener);
|
|
|
|
if (!listener) {
|
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerInfoList.RemoveElementAt(count);
|
|
|
|
delete info;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
listener->OnStateChange(aProgress, aRequest, aStateFlags, aStatus);
|
2014-04-26 10:12:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mListenerInfoList.Compact();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDocLoader::FireOnLocationChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
2011-11-10 06:01:11 -08:00
|
|
|
nsIURI *aUri,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-04-26 10:12:10 -07:00
|
|
|
/*
|
|
|
|
* First notify any listeners of the new state info...
|
|
|
|
*
|
|
|
|
* Operate the elements from back to front so that if items get
|
|
|
|
* get removed from the list it won't affect our iteration
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
int32_t count = mListenerInfoList.Count();
|
|
|
|
|
|
|
|
while (--count >= 0) {
|
|
|
|
nsListenerInfo *info;
|
|
|
|
|
|
|
|
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
|
|
|
|
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_LOCATION)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener = do_QueryReferent(info->mWeakListener);
|
|
|
|
if (!listener) {
|
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerInfoList.RemoveElementAt(count);
|
|
|
|
delete info;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-07-31 11:59:17 -07:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG, ("DocLoader [%p] calling %p->OnLocationChange", this, listener.get()));
|
2011-11-10 06:01:11 -08:00
|
|
|
listener->OnLocationChange(aWebProgress, aRequest, aUri, aFlags);
|
2014-04-26 10:12:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mListenerInfoList.Compact();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
2011-11-10 06:01:11 -08:00
|
|
|
mParent->FireOnLocationChange(aWebProgress, aRequest, aUri, aFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDocLoader::FireOnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
nsresult aStatus,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aMessage)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-04-26 10:12:10 -07:00
|
|
|
/*
|
|
|
|
* First notify any listeners of the new state info...
|
|
|
|
*
|
|
|
|
* Operate the elements from back to front so that if items get
|
|
|
|
* get removed from the list it won't affect our iteration
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
int32_t count = mListenerInfoList.Count();
|
|
|
|
|
|
|
|
while (--count >= 0) {
|
|
|
|
nsListenerInfo *info;
|
|
|
|
|
|
|
|
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
|
|
|
|
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_STATUS)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener = do_QueryReferent(info->mWeakListener);
|
|
|
|
if (!listener) {
|
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerInfoList.RemoveElementAt(count);
|
|
|
|
delete info;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
listener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
|
2014-04-26 10:12:10 -07:00
|
|
|
}
|
|
|
|
mListenerInfoList.Compact();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
|
|
|
mParent->FireOnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDocLoader::RefreshAttempted(nsIWebProgress* aWebProgress,
|
|
|
|
nsIURI *aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aDelay,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aSameURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Returns true if the refresh may proceed,
|
|
|
|
* false if the refresh should be blocked.
|
2014-04-26 10:12:10 -07:00
|
|
|
*
|
|
|
|
* First notify any listeners of the refresh attempt...
|
|
|
|
*
|
|
|
|
* Iterate the elements from back to front so that if items
|
|
|
|
* get removed from the list it won't affect our iteration
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool allowRefresh = true;
|
2014-04-26 10:12:10 -07:00
|
|
|
int32_t count = mListenerInfoList.Count();
|
|
|
|
|
|
|
|
while (--count >= 0) {
|
|
|
|
nsListenerInfo *info;
|
|
|
|
|
|
|
|
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
|
|
|
|
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_REFRESH)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener =
|
|
|
|
do_QueryReferent(info->mWeakListener);
|
|
|
|
if (!listener) {
|
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerInfoList.RemoveElementAt(count);
|
|
|
|
delete info;
|
|
|
|
continue;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWebProgressListener2> listener2 =
|
2014-04-26 10:12:10 -07:00
|
|
|
do_QueryReferent(info->mWeakListener);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!listener2)
|
|
|
|
continue;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool listenerAllowedRefresh;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult listenerRV = listener2->OnRefreshAttempted(
|
|
|
|
aWebProgress, aURI, aDelay, aSameURI, &listenerAllowedRefresh);
|
|
|
|
if (NS_FAILED(listenerRV))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
allowRefresh = allowRefresh && listenerAllowedRefresh;
|
2014-04-26 10:12:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mListenerInfoList.Compact();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
|
|
|
allowRefresh = allowRefresh &&
|
|
|
|
mParent->RefreshAttempted(aWebProgress, aURI, aDelay, aSameURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return allowRefresh;
|
|
|
|
}
|
|
|
|
|
2014-04-26 10:12:10 -07:00
|
|
|
nsListenerInfo *
|
|
|
|
nsDocLoader::GetListenerInfo(nsIWebProgressListener *aListener)
|
|
|
|
{
|
|
|
|
int32_t i, count;
|
|
|
|
nsListenerInfo *info;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> listener1 = do_QueryInterface(aListener);
|
|
|
|
count = mListenerInfoList.Count();
|
|
|
|
for (i=0; i<count; i++) {
|
|
|
|
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(i));
|
|
|
|
|
|
|
|
NS_ASSERTION(info, "There should NEVER be a null listener in the list");
|
|
|
|
if (info) {
|
|
|
|
nsCOMPtr<nsISupports> listener2 = do_QueryReferent(info->mWeakListener);
|
|
|
|
if (listener1 == listener2)
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult nsDocLoader::AddRequestInfo(nsIRequest *aRequest)
|
|
|
|
{
|
|
|
|
if (!PL_DHashTableOperate(&mRequestInfoHash, aRequest, PL_DHASH_ADD)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-04-08 01:45:32 -07:00
|
|
|
void nsDocLoader::RemoveRequestInfo(nsIRequest *aRequest)
|
|
|
|
{
|
|
|
|
PL_DHashTableOperate(&mRequestInfoHash, aRequest, PL_DHASH_REMOVE);
|
|
|
|
}
|
|
|
|
|
2012-10-19 09:24:12 -07:00
|
|
|
nsDocLoader::nsRequestInfo* nsDocLoader::GetRequestInfo(nsIRequest* aRequest)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-19 09:24:12 -07:00
|
|
|
nsRequestInfo* info =
|
|
|
|
static_cast<nsRequestInfo*>
|
2007-07-08 00:08:04 -07:00
|
|
|
(PL_DHashTableOperate(&mRequestInfoHash, aRequest,
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHASH_LOOKUP));
|
|
|
|
|
|
|
|
if (PL_DHASH_ENTRY_IS_FREE(info)) {
|
|
|
|
// Nothing found in the hash, return null.
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return what we found in the hash...
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PLDHashTable enumeration callback that just removes every entry
|
|
|
|
// from the hash.
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashOperator
|
2012-08-22 08:56:38 -07:00
|
|
|
RemoveInfoCallback(PLDHashTable *table, PLDHashEntryHdr *hdr, uint32_t number,
|
2007-03-22 10:30:00 -07:00
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDocLoader::ClearRequestInfoHash(void)
|
|
|
|
{
|
|
|
|
if (!mRequestInfoHash.ops || !mRequestInfoHash.entryCount) {
|
|
|
|
// No hash, or the hash is empty, nothing to do here then...
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
PL_DHashTableEnumerate(&mRequestInfoHash, RemoveInfoCallback, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// PLDHashTable enumeration callback that calculates the max progress.
|
2012-10-19 09:24:12 -07:00
|
|
|
PLDHashOperator
|
|
|
|
nsDocLoader::CalcMaxProgressCallback(PLDHashTable* table, PLDHashEntryHdr* hdr,
|
|
|
|
uint32_t number, void* arg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-19 09:24:12 -07:00
|
|
|
const nsRequestInfo* info = static_cast<const nsRequestInfo*>(hdr);
|
|
|
|
int64_t* max = static_cast<int64_t* >(arg);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (info->mMaxProgress < info->mCurrentProgress) {
|
2012-08-22 08:56:38 -07:00
|
|
|
*max = int64_t(-1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
*max += info->mMaxProgress;
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t nsDocLoader::CalculateMaxProgress()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t max = mCompletedTotalProgress;
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashTableEnumerate(&mRequestInfoHash, CalcMaxProgressCallback, &max);
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
2010-08-04 19:15:55 -07:00
|
|
|
NS_IMETHODIMP nsDocLoader::AsyncOnChannelRedirect(nsIChannel *aOldChannel,
|
|
|
|
nsIChannel *aNewChannel,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags,
|
2010-08-04 19:15:55 -07:00
|
|
|
nsIAsyncVerifyRedirectCallback *cb)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aOldChannel)
|
|
|
|
{
|
|
|
|
nsLoadFlags loadFlags = 0;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t stateFlags = nsIWebProgressListener::STATE_REDIRECTING |
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST;
|
|
|
|
|
|
|
|
aOldChannel->GetLoadFlags(&loadFlags);
|
|
|
|
// If the document channel is being redirected, then indicate that the
|
|
|
|
// document is being redirected in the notification...
|
|
|
|
if (loadFlags & nsIChannel::LOAD_DOCUMENT_URI)
|
|
|
|
{
|
|
|
|
stateFlags |= nsIWebProgressListener::STATE_IS_DOCUMENT;
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
nsCOMPtr<nsIRequest> request(do_QueryInterface(aOldChannel));
|
|
|
|
NS_ASSERTION(request == mDocumentRequest, "Wrong Document Channel");
|
|
|
|
#endif /* DEBUG */
|
|
|
|
}
|
|
|
|
|
2010-09-30 16:55:11 -07:00
|
|
|
OnRedirectStateChange(aOldChannel, aNewChannel, aFlags, stateFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
FireOnStateChange(this, aOldChannel, stateFlags, NS_OK);
|
|
|
|
}
|
|
|
|
|
2010-08-04 19:15:55 -07:00
|
|
|
cb->OnRedirectVerifyCallback(NS_OK);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of nsISecurityEventSink method...
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocLoader::OnSecurityChange(nsISupports * aContext,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// Fire progress notifications out to any registered nsIWebProgressListeners.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRequest> request = do_QueryInterface(aContext);
|
2007-07-08 00:08:04 -07:00
|
|
|
nsIWebProgress* webProgress = static_cast<nsIWebProgress*>(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-04-26 10:12:10 -07:00
|
|
|
/*
|
|
|
|
* First notify any listeners of the new state info...
|
|
|
|
*
|
|
|
|
* Operate the elements from back to front so that if items get
|
|
|
|
* get removed from the list it won't affect our iteration
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
int32_t count = mListenerInfoList.Count();
|
|
|
|
|
|
|
|
while (--count >= 0) {
|
|
|
|
nsListenerInfo *info;
|
|
|
|
|
|
|
|
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
|
|
|
|
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_SECURITY)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener = do_QueryReferent(info->mWeakListener);
|
|
|
|
if (!listener) {
|
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerInfoList.RemoveElementAt(count);
|
|
|
|
delete info;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
listener->OnSecurityChange(webProgress, request, aState);
|
2014-04-26 10:12:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mListenerInfoList.Compact();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
|
|
|
mParent->OnSecurityChange(aContext, aState);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of nsISupportsPriority methods...
|
|
|
|
*
|
|
|
|
* The priority of the DocLoader _is_ the priority of its LoadGroup.
|
|
|
|
*
|
|
|
|
* XXX(darin): Once we start storing loadgroups in loadgroups, this code will
|
|
|
|
* go away.
|
|
|
|
*/
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsDocLoader::GetPriority(int32_t *aPriority)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mLoadGroup);
|
|
|
|
if (p)
|
|
|
|
return p->GetPriority(aPriority);
|
|
|
|
|
|
|
|
*aPriority = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsDocLoader::SetPriority(int32_t aPriority)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: SetPriority(%d) called\n", this, aPriority));
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mLoadGroup);
|
|
|
|
if (p)
|
|
|
|
p->SetPriority(aPriority);
|
|
|
|
|
2013-02-20 13:33:44 -08:00
|
|
|
NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mChildList, nsDocLoader,
|
|
|
|
SetPriority, (aPriority));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsDocLoader::AdjustPriority(int32_t aDelta)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: AdjustPriority(%d) called\n", this, aDelta));
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mLoadGroup);
|
|
|
|
if (p)
|
|
|
|
p->AdjustPriority(aDelta);
|
|
|
|
|
2013-02-20 13:33:44 -08:00
|
|
|
NS_OBSERVER_ARRAY_NOTIFY_XPCOM_OBSERVERS(mChildList, nsDocLoader,
|
|
|
|
AdjustPriority, (aDelta));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
void nsDocLoader::DumpChannelInfo()
|
|
|
|
{
|
|
|
|
nsChannelInfo *info;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t i, count;
|
|
|
|
int32_t current=0, max=0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
printf("==== DocLoader=%x\n", this);
|
|
|
|
|
|
|
|
count = mChannelInfoList.Count();
|
|
|
|
for(i=0; i<count; i++) {
|
|
|
|
info = (nsChannelInfo *)mChannelInfoList.ElementAt(i);
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buffer;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (info->mURI) {
|
|
|
|
rv = info->mURI->GetSpec(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(" [%d] current=%d max=%d [%s]\n", i,
|
|
|
|
info->mCurrentProgress,
|
|
|
|
info->mMaxProgress, buffer.get());
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
current += info->mCurrentProgress;
|
|
|
|
if (max >= 0) {
|
|
|
|
if (info->mMaxProgress < info->mCurrentProgress) {
|
|
|
|
max = -1;
|
|
|
|
} else {
|
|
|
|
max += info->mMaxProgress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\nCurrent=%d Total=%d\n====\n", current, max);
|
|
|
|
}
|
|
|
|
#endif /* 0 */
|