2002-04-17 03:48:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-09-28 20:14:13 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 16:52:41 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-07-01 11:29:20 +00:00
|
|
|
*
|
2004-04-17 16:52:41 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-07-01 11:29:20 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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.
|
1998-07-01 11:29:20 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-17 16:52:41 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:43:54 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 16:52:41 +00:00
|
|
|
* either of 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"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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
|
2004-04-17 16:52:41 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 16:52:41 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-01-29 04:41:04 +00:00
|
|
|
|
1999-12-29 07:32:59 +00:00
|
|
|
#include "nspr.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
|
2000-01-29 04:41:04 +00:00
|
|
|
#include "nsDocLoader.h"
|
|
|
|
#include "nsCURILoader.h"
|
|
|
|
#include "nsNetUtil.h"
|
2001-05-11 21:05:08 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
2000-01-29 04:41:04 +00:00
|
|
|
|
1998-10-01 21:48:12 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-09-05 19:54:28 +00:00
|
|
|
#include "nsXPIDLString.h"
|
1999-09-17 07:56:03 +00:00
|
|
|
|
2000-01-29 04:41:04 +00:00
|
|
|
#include "nsIURL.h"
|
1999-05-06 19:31:59 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2003-11-29 18:56:10 +00:00
|
|
|
#include "nscore.h"
|
2001-01-31 21:02:08 +00:00
|
|
|
#include "nsWeakPtr.h"
|
2004-12-08 17:32:06 +00:00
|
|
|
#include "nsAutoPtr.h"
|
1998-07-01 11:29:20 +00:00
|
|
|
|
2000-12-14 23:26:35 +00:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
|
1999-05-06 03:54:40 +00:00
|
|
|
#include "nsIPresShell.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2000-07-25 05:45:56 +00:00
|
|
|
#include "nsIStringBundle.h"
|
2001-05-11 21:05:08 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
|
2004-04-10 20:03:03 +00:00
|
|
|
#include "nsITransport.h"
|
|
|
|
#include "nsISocketTransport.h"
|
|
|
|
|
2000-07-25 05:45:56 +00:00
|
|
|
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
2004-12-08 17:32:06 +00:00
|
|
|
static NS_DEFINE_CID(kThisImplCID, NS_THIS_DOCLOADER_IMPL_CID);
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
#if defined(PR_LOGGING)
|
1999-11-22 05:46:03 +00:00
|
|
|
//
|
|
|
|
// Log module for nsIDocumentLoader logging...
|
|
|
|
//
|
|
|
|
// To enable logging (see prlog.h for full details):
|
|
|
|
//
|
2000-10-28 22:17:53 +00:00
|
|
|
// set NSPR_LOG_MODULES=DocLoader:5
|
1999-11-22 05:46:03 +00:00
|
|
|
// set NSPR_LOG_FILE=nspr.log
|
|
|
|
//
|
|
|
|
// this enables PR_LOG_DEBUG level information and places all output in
|
|
|
|
// the file nspr.log
|
|
|
|
//
|
2000-10-28 22:17:53 +00:00
|
|
|
PRLogModuleInfo* gDocLoaderLog = nsnull;
|
|
|
|
#endif /* PR_LOGGING */
|
|
|
|
|
1998-07-22 11:23:32 +00:00
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
#if defined(DEBUG)
|
2002-03-20 22:50:33 +00:00
|
|
|
void GetURIStringFromRequest(nsIRequest* request, nsACString &name)
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
if (request)
|
|
|
|
request->GetName(name);
|
|
|
|
else
|
2004-06-17 00:13:25 +00:00
|
|
|
name.AssignLiteral("???");
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
struct nsRequestInfo : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
nsRequestInfo(const void *key)
|
2004-04-10 20:03:03 +00:00
|
|
|
: mKey(key), mCurrentProgress(0), mMaxProgress(0), mUploading(PR_FALSE)
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
const void* mKey; // Must be first for the pldhash stubs to work
|
2005-01-09 20:43:35 +00:00
|
|
|
nsInt64 mCurrentProgress;
|
|
|
|
nsInt64 mMaxProgress;
|
2004-04-10 20:03:03 +00:00
|
|
|
PRBool mUploading;
|
2000-06-19 05:54:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-08-05 20:09:21 +00:00
|
|
|
PR_STATIC_CALLBACK(PRBool)
|
2002-07-09 00:54:41 +00:00
|
|
|
RequestInfoHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
// Initialize the entry with placement new
|
|
|
|
new (entry) nsRequestInfo(key);
|
2003-08-05 20:09:21 +00:00
|
|
|
return PR_TRUE;
|
2002-07-09 00:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-16 20:57:37 +00: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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::nsDocLoader()
|
2002-07-09 00:54:41 +00:00
|
|
|
: mListenerInfoList(8)
|
1998-07-01 11:29:20 +00:00
|
|
|
{
|
2000-10-28 22:17:53 +00:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
if (nsnull == gDocLoaderLog) {
|
|
|
|
gDocLoaderLog = PR_NewLogModule("DocLoader");
|
|
|
|
}
|
|
|
|
#endif /* PR_LOGGING */
|
|
|
|
|
2000-04-22 23:16:31 +00:00
|
|
|
mParent = nsnull;
|
1998-10-01 21:48:12 +00:00
|
|
|
|
2000-04-22 23:16:31 +00:00
|
|
|
mIsLoadingDocument = PR_FALSE;
|
2005-06-15 23:52:46 +00:00
|
|
|
mIsRestoringDocument = PR_FALSE;
|
2002-07-09 00:54:41 +00:00
|
|
|
|
|
|
|
static PLDHashTableOps hash_table_ops =
|
|
|
|
{
|
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashGetKeyStub,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
PL_DHashMatchEntryStub,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
PL_DHashClearEntryStub,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
RequestInfoHashInitEntry
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!PL_DHashTableInit(&mRequestInfoHash, &hash_table_ops, nsnull,
|
|
|
|
sizeof(nsRequestInfo), 16)) {
|
|
|
|
mRequestInfoHash.ops = nsnull;
|
|
|
|
}
|
|
|
|
|
2000-04-22 23:16:31 +00:00
|
|
|
ClearInternalProgress();
|
2000-04-03 02:26:05 +00:00
|
|
|
|
2000-04-22 23:16:31 +00:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: created.\n", this));
|
1998-07-01 11:29:20 +00:00
|
|
|
}
|
|
|
|
|
1999-06-28 10:35:57 +00:00
|
|
|
nsresult
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::SetDocLoaderParent(nsDocLoader *aParent)
|
2000-01-29 04:41:04 +00:00
|
|
|
{
|
|
|
|
mParent = aParent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::Init()
|
1999-06-28 10:35:57 +00:00
|
|
|
{
|
2002-07-09 00:54:41 +00:00
|
|
|
if (!mRequestInfoHash.ops) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-06-28 10:35:57 +00:00
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
nsresult rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), this);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-17 07:56:03 +00:00
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: load group %x.\n", this, mLoadGroup.get()));
|
1999-08-26 22:45:55 +00:00
|
|
|
|
2002-12-11 00:15:19 +00:00
|
|
|
return NS_OK;
|
1999-06-28 10:35:57 +00:00
|
|
|
}
|
1998-07-01 11:29:20 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::~nsDocLoader()
|
1998-07-01 11:29:20 +00:00
|
|
|
{
|
1999-09-21 21:10:22 +00:00
|
|
|
/*
|
|
|
|
|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]
|
|
|
|
*/
|
2004-12-08 17:32:06 +00:00
|
|
|
// XXXbz now that NS_IMPL_RELEASE stabilizes by setting refcount to 1, is
|
|
|
|
// this needed?
|
2000-06-20 05:14:42 +00:00
|
|
|
ClearWeakReferences();
|
1999-09-21 21:10:22 +00:00
|
|
|
|
1999-09-17 07:56:03 +00:00
|
|
|
Destroy();
|
1998-10-01 21:48:12 +00:00
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-09-17 07:56:03 +00:00
|
|
|
("DocLoader:%p: deleted.\n", this));
|
1998-10-01 21:48:12 +00:00
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
if (mRequestInfoHash.ops) {
|
|
|
|
PL_DHashTableFinish(&mRequestInfoHash);
|
|
|
|
}
|
1998-07-01 11:29:20 +00:00
|
|
|
}
|
|
|
|
|
1999-09-17 04:26:02 +00:00
|
|
|
|
1998-07-01 11:29:20 +00:00
|
|
|
/*
|
|
|
|
* Implementation of ISupports methods...
|
|
|
|
*/
|
2004-12-08 17:32:06 +00:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsDocLoader)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsDocLoader)
|
1998-07-22 11:23:32 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDocLoader)
|
2001-04-10 06:01:08 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRequestObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
|
2000-01-29 04:41:04 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocumentLoader)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2000-04-03 02:26:05 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebProgress)
|
2000-04-22 23:16:31 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIProgressEventSink)
|
2000-05-07 02:01:10 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
2005-03-07 19:46:06 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIChannelEventSink)
|
2000-09-14 22:56:56 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISecurityEventSink)
|
2005-02-21 20:58:01 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsPriority)
|
2004-12-08 17:32:06 +00:00
|
|
|
if (aIID.Equals(kThisImplCID))
|
|
|
|
foundInterface = NS_STATIC_CAST(nsIDocumentLoader *, this);
|
|
|
|
else
|
2000-01-29 04:41:04 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
1998-07-22 11:23:32 +00:00
|
|
|
|
2000-05-07 02:01:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of nsIInterfaceRequestor methods...
|
|
|
|
*/
|
2004-12-08 17:32:06 +00:00
|
|
|
NS_IMETHODIMP nsDocLoader::GetInterface(const nsIID& aIID, void** aSink)
|
2000-05-07 02:01:10 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsDocLoader>
|
|
|
|
nsDocLoader::GetAsDocLoader(nsISupports* aSupports)
|
1998-07-22 11:23:32 +00:00
|
|
|
{
|
2004-12-08 17:32:06 +00:00
|
|
|
if (!aSupports) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2000-01-29 04:41:04 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader* ptr;
|
|
|
|
CallQueryInterface(aSupports, &ptr);
|
|
|
|
return ptr;
|
|
|
|
}
|
1999-06-28 10:35:57 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
nsDocLoader::AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocumentLoader> docLoaderService =
|
|
|
|
do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-12-11 00:15:19 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
nsRefPtr<nsDocLoader> rootDocLoader = GetAsDocLoader(docLoaderService);
|
|
|
|
NS_ENSURE_TRUE(rootDocLoader, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
return rootDocLoader->AddChildLoader(aDocLoader);
|
1998-07-22 11:23:32 +00:00
|
|
|
}
|
|
|
|
|
1999-03-12 05:20:29 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::Stop(void)
|
1999-03-12 05:20:29 +00:00
|
|
|
{
|
1999-11-22 05:46:03 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-12-11 00:15:19 +00:00
|
|
|
PRInt32 count, i;
|
1999-03-12 05:20:29 +00:00
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-11-22 05:46:03 +00:00
|
|
|
("DocLoader:%p: Stop() called\n", this));
|
1999-03-12 05:20:29 +00:00
|
|
|
|
2002-12-11 00:15:19 +00:00
|
|
|
count = mChildList.Count();
|
1999-03-12 05:20:29 +00:00
|
|
|
|
2002-12-11 00:15:19 +00:00
|
|
|
nsCOMPtr<nsIDocumentLoader> loader;
|
|
|
|
for (i=0; i < count; i++) {
|
2004-12-08 17:32:06 +00:00
|
|
|
loader = ChildAt(i);
|
1999-11-22 05:46:03 +00:00
|
|
|
|
|
|
|
if (loader) {
|
|
|
|
(void) loader->Stop();
|
|
|
|
}
|
|
|
|
}
|
1998-10-09 05:49:34 +00:00
|
|
|
|
2003-03-01 20:39:44 +00:00
|
|
|
if (mLoadGroup)
|
|
|
|
rv = mLoadGroup->Cancel(NS_BINDING_ABORTED);
|
1998-10-10 04:33:29 +00:00
|
|
|
|
2005-07-13 16:43:30 +00:00
|
|
|
// 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....
|
|
|
|
DocLoaderIsEmpty();
|
|
|
|
|
1999-07-01 19:30:20 +00:00
|
|
|
return rv;
|
1998-10-01 21:48:12 +00:00
|
|
|
}
|
1998-07-22 11:23:32 +00:00
|
|
|
|
|
|
|
|
2004-09-28 20:48:58 +00:00
|
|
|
PRBool
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::IsBusy()
|
1998-10-01 21:48:12 +00:00
|
|
|
{
|
1999-11-22 05:46:03 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
//
|
|
|
|
// A document loader is busy if either:
|
|
|
|
//
|
|
|
|
// 1. It is currently loading a document (ie. one or more URIs)
|
|
|
|
// 2. One of it's child document loaders is busy...
|
|
|
|
//
|
1998-10-01 21:48:12 +00:00
|
|
|
|
1999-11-22 05:46:03 +00:00
|
|
|
/* Is this document loader busy? */
|
1999-09-17 07:56:03 +00:00
|
|
|
if (mIsLoadingDocument) {
|
2004-09-28 20:48:58 +00:00
|
|
|
PRBool busy;
|
|
|
|
rv = mLoadGroup->IsPending(&busy);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
|
|
|
if (busy)
|
|
|
|
return PR_TRUE;
|
1999-11-22 05:46:03 +00:00
|
|
|
}
|
|
|
|
|
1998-10-01 21:48:12 +00:00
|
|
|
/* Otherwise, check its child document loaders... */
|
2004-09-28 20:48:58 +00:00
|
|
|
PRInt32 count, i;
|
1999-11-22 05:46:03 +00:00
|
|
|
|
2004-09-28 20:48:58 +00:00
|
|
|
count = mChildList.Count();
|
1999-11-22 05:46:03 +00:00
|
|
|
|
2004-09-28 20:48:58 +00:00
|
|
|
for (i=0; i < count; i++) {
|
2004-12-08 17:32:06 +00:00
|
|
|
nsIDocumentLoader* loader = ChildAt(i);
|
1999-11-22 05:46:03 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
// This is a safe cast, because we only put nsDocLoader objects into the
|
2004-09-28 20:48:58 +00:00
|
|
|
// array
|
2004-12-08 17:32:06 +00:00
|
|
|
if (loader && NS_STATIC_CAST(nsDocLoader*, loader)->IsBusy())
|
2004-09-28 20:48:58 +00:00
|
|
|
return PR_TRUE;
|
1998-10-01 21:48:12 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 20:48:58 +00:00
|
|
|
return PR_FALSE;
|
1998-10-01 21:48:12 +00:00
|
|
|
}
|
|
|
|
|
1999-01-14 06:44:23 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::GetContainer(nsISupports** aResult)
|
1999-01-14 06:44:23 +00:00
|
|
|
{
|
2004-12-08 17:32:06 +00:00
|
|
|
NS_ADDREF(*aResult = NS_STATIC_CAST(nsIDocumentLoader*, this));
|
1999-11-15 07:29:23 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-01-14 06:44:23 +00:00
|
|
|
}
|
1998-10-01 21:48:12 +00:00
|
|
|
|
1999-10-27 04:44:42 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::GetLoadGroup(nsILoadGroup** aResult)
|
1999-10-27 04:44:42 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
|
|
|
*aResult = mLoadGroup;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
void
|
|
|
|
nsDocLoader::Destroy()
|
1999-09-09 23:53:55 +00:00
|
|
|
{
|
2000-04-22 23:16:31 +00:00
|
|
|
Stop();
|
1999-09-17 07:56:03 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
// Remove the document loader from the parent list of loaders...
|
2000-04-22 23:16:31 +00:00
|
|
|
if (mParent)
|
|
|
|
{
|
2004-12-08 17:32:06 +00:00
|
|
|
mParent->RemoveChildLoader(this);
|
2000-04-22 23:16:31 +00:00
|
|
|
}
|
1998-10-01 21:48:12 +00:00
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
// Release all the information about network requests...
|
2002-07-09 00:54:41 +00:00
|
|
|
ClearRequestInfoHash();
|
2000-06-20 05:14:42 +00:00
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
// Release all the information about registered listeners...
|
2004-12-08 17:32:06 +00:00
|
|
|
PRInt32 count = mListenerInfoList.Count();
|
|
|
|
for(PRInt32 i = 0; i < count; i++) {
|
2002-07-09 00:54:41 +00:00
|
|
|
nsListenerInfo *info =
|
|
|
|
NS_STATIC_CAST(nsListenerInfo*, mListenerInfoList.ElementAt(i));
|
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
delete info;
|
|
|
|
}
|
|
|
|
|
|
|
|
mListenerInfoList.Clear();
|
|
|
|
mListenerInfoList.Compact();
|
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
mDocumentRequest = 0;
|
1998-10-01 21:48:12 +00:00
|
|
|
|
2003-03-01 20:39:44 +00:00
|
|
|
if (mLoadGroup)
|
|
|
|
mLoadGroup->SetGroupObserver(nsnull);
|
1999-10-19 19:42:55 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
DestroyChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDocLoader::DestroyChildren()
|
|
|
|
{
|
|
|
|
PRInt32 i, count;
|
|
|
|
|
|
|
|
count = mChildList.Count();
|
|
|
|
// 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
|
|
|
|
for (i=0; i < count; i++)
|
|
|
|
{
|
|
|
|
nsIDocumentLoader* loader = ChildAt(i);
|
|
|
|
|
|
|
|
if (loader) {
|
|
|
|
// This is a safe cast, as we only put nsDocLoader objects into the
|
|
|
|
// array
|
|
|
|
NS_STATIC_CAST(nsDocLoader*, loader)->SetDocLoaderParent(nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mChildList.Clear();
|
1998-10-01 21:48:12 +00:00
|
|
|
}
|
|
|
|
|
1999-07-16 11:14:36 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::OnStartRequest(nsIRequest *request, nsISupports *aCtxt)
|
1999-07-16 11:14:36 +00:00
|
|
|
{
|
2001-04-27 21:05:52 +00:00
|
|
|
// called each time a request is added to the group.
|
2001-04-13 02:32:02 +00:00
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
2001-04-27 21:05:52 +00:00
|
|
|
if (PR_LOG_TEST(gDocLoaderLog, PR_LOG_DEBUG)) {
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString name;
|
|
|
|
request->GetName(name);
|
2001-04-27 21:05:52 +00:00
|
|
|
|
|
|
|
PRUint32 count = 0;
|
|
|
|
if (mLoadGroup)
|
|
|
|
mLoadGroup->GetActiveCount(&count);
|
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: OnStartRequest[%p](%s) mIsLoadingDocument=%s, %u active URLs",
|
2002-03-20 22:50:33 +00:00
|
|
|
this, request, name.get(),
|
2001-04-27 21:05:52 +00:00
|
|
|
(mIsLoadingDocument ? "true" : "false"),
|
|
|
|
count));
|
|
|
|
}
|
|
|
|
#endif /* PR_LOGGING */
|
2001-05-29 22:10:50 +00:00
|
|
|
PRBool bJustStartedLoading = PR_FALSE;
|
|
|
|
|
2004-09-17 20:33:25 +00:00
|
|
|
nsLoadFlags loadFlags = 0;
|
2001-04-27 21:05:52 +00:00
|
|
|
request->GetLoadFlags(&loadFlags);
|
2001-04-13 02:32:02 +00:00
|
|
|
|
2001-04-27 21:05:52 +00:00
|
|
|
if (!mIsLoadingDocument && (loadFlags & nsIChannel::LOAD_DOCUMENT_URI)) {
|
2001-05-29 22:10:50 +00:00
|
|
|
bJustStartedLoading = PR_TRUE;
|
2001-04-27 21:05:52 +00:00
|
|
|
mIsLoadingDocument = PR_TRUE;
|
|
|
|
ClearInternalProgress(); // only clear our progress if we are starting a new load....
|
|
|
|
}
|
2000-01-15 06:12:54 +00:00
|
|
|
|
2001-04-27 21:05:52 +00:00
|
|
|
//
|
|
|
|
// Only fire an OnStartDocumentLoad(...) if the document loader
|
|
|
|
// has initiated a load... Otherwise, this notification has
|
|
|
|
// resulted from a request being added to the load group.
|
|
|
|
//
|
|
|
|
if (mIsLoadingDocument) {
|
1999-08-26 22:45:55 +00:00
|
|
|
//
|
2001-04-27 21:05:52 +00:00
|
|
|
// Create a new nsRequestInfo for the request that is starting to
|
|
|
|
// load...
|
1999-08-26 22:45:55 +00:00
|
|
|
//
|
2001-04-27 21:05:52 +00:00
|
|
|
AddRequestInfo(request);
|
|
|
|
|
|
|
|
if (loadFlags & nsIChannel::LOAD_DOCUMENT_URI) {
|
|
|
|
//
|
2003-06-11 06:17:53 +00:00
|
|
|
// Make sure that the document channel is null at this point...
|
2001-04-27 21:05:52 +00:00
|
|
|
// (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
|
|
|
|
//
|
2001-05-29 22:10:50 +00:00
|
|
|
if (bJustStartedLoading) {
|
2001-04-27 21:05:52 +00:00
|
|
|
// Update the progress status state
|
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_START;
|
|
|
|
|
|
|
|
// Fire the start document load notification
|
|
|
|
doStartDocumentLoad();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The DocLoader is not busy, so clear out any cached information...
|
2002-07-09 00:54:41 +00:00
|
|
|
ClearRequestInfoHash();
|
2001-04-27 21:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!mIsLoadingDocument || mDocumentRequest,
|
|
|
|
"mDocumentRequest MUST be set for the duration of a page load!");
|
|
|
|
|
|
|
|
doStartURLLoad(request);
|
2001-04-19 19:51:29 +00:00
|
|
|
|
2000-04-22 23:16:31 +00:00
|
|
|
return NS_OK;
|
1999-07-16 11:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::OnStopRequest(nsIRequest *aRequest,
|
1999-11-22 05:46:03 +00:00
|
|
|
nsISupports *aCtxt,
|
2001-04-10 06:01:08 +00:00
|
|
|
nsresult aStatus)
|
1999-07-16 11:14:36 +00:00
|
|
|
{
|
1999-11-22 05:46:03 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-08-26 22:45:55 +00:00
|
|
|
|
2001-04-13 02:32:02 +00:00
|
|
|
#ifdef PR_LOGGING
|
2001-04-27 21:05:52 +00:00
|
|
|
if (PR_LOG_TEST(gDocLoaderLog, PR_LOG_DEBUG)) {
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString name;
|
|
|
|
aRequest->GetName(name);
|
2001-04-27 21:05:52 +00:00
|
|
|
|
|
|
|
PRUint32 count = 0;
|
|
|
|
if (mLoadGroup)
|
|
|
|
mLoadGroup->GetActiveCount(&count);
|
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: OnStopRequest[%p](%s) status=%x mIsLoadingDocument=%s, %u active URLs",
|
2002-03-20 22:50:33 +00:00
|
|
|
this, aRequest, name.get(),
|
2001-04-27 21:05:52 +00:00
|
|
|
aStatus, (mIsLoadingDocument ? "true" : "false"),
|
|
|
|
count));
|
|
|
|
}
|
2001-04-13 02:32:02 +00:00
|
|
|
#endif
|
2001-04-27 21:05:52 +00:00
|
|
|
|
1999-09-22 22:58:29 +00:00
|
|
|
//
|
|
|
|
// Only fire the OnEndDocumentLoad(...) if the document loader
|
|
|
|
// has initiated a load...
|
|
|
|
//
|
|
|
|
if (mIsLoadingDocument) {
|
1999-11-22 05:46:03 +00:00
|
|
|
PRUint32 count;
|
2002-06-20 21:16:46 +00:00
|
|
|
PRBool bFireTransferring = PR_FALSE;
|
1999-09-22 22:58:29 +00:00
|
|
|
|
2000-06-19 05:54:37 +00: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)
|
|
|
|
//
|
2005-01-09 20:43:35 +00:00
|
|
|
nsRequestInfo *info = GetRequestInfo(aRequest);
|
2000-06-19 05:54:37 +00:00
|
|
|
if (info) {
|
2005-01-09 20:43:35 +00:00
|
|
|
nsInt64 oldMax = info->mMaxProgress;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
|
|
|
info->mMaxProgress = info->mCurrentProgress;
|
|
|
|
//
|
2001-03-29 00:12:49 +00:00
|
|
|
// If a request whose content-length was previously unknown has just
|
2000-06-19 05:54:37 +00:00
|
|
|
// finished loading, then use this new data to try to calculate a
|
|
|
|
// mMaxSelfProgress...
|
|
|
|
//
|
2005-01-09 20:43:35 +00:00
|
|
|
if ((oldMax < nsInt64(0)) && (mMaxSelfProgress < nsInt64(0))) {
|
2004-09-28 20:48:58 +00:00
|
|
|
mMaxSelfProgress = CalculateMaxProgress();
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
2002-06-20 21:16:46 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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...
|
|
|
|
//
|
2005-01-09 20:43:35 +00:00
|
|
|
if ((oldMax == LL_ZERO) && (info->mCurrentProgress == LL_ZERO)) {
|
2002-06-20 21:16:46 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
|
|
|
|
|
|
|
// Only fire a TRANSFERRING notification if the request is also a
|
|
|
|
// channel -- data transfer requires a nsIChannel!
|
|
|
|
//
|
|
|
|
if (channel) {
|
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
|
|
|
bFireTransferring = PR_TRUE;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// If the request failed (for any reason other than being
|
2004-09-09 06:54:52 +00:00
|
|
|
// redirected or retargeted), the TRANSFERRING notification can
|
|
|
|
// still be fired if a HTTP connection was established to a server.
|
2002-06-20 21:16:46 +00:00
|
|
|
//
|
2004-09-09 06:54:52 +00:00
|
|
|
else if (aStatus != NS_BINDING_REDIRECTED &&
|
|
|
|
aStatus != NS_BINDING_RETARGETED) {
|
2004-12-30 18:13:45 +00:00
|
|
|
//
|
|
|
|
// Only if the load has been targeted (see bug 268483)...
|
|
|
|
//
|
|
|
|
PRUint32 lf;
|
|
|
|
channel->GetLoadFlags(&lf);
|
|
|
|
if (lf & nsIChannel::LOAD_TARGETED) {
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest));
|
|
|
|
if (httpChannel) {
|
|
|
|
PRUint32 responseCode;
|
|
|
|
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...
|
|
|
|
//
|
|
|
|
bFireTransferring = PR_TRUE;
|
|
|
|
}
|
2002-06-20 21:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bFireTransferring) {
|
|
|
|
// Send a STATE_TRANSFERRING notification for the request.
|
|
|
|
PRInt32 flags;
|
|
|
|
|
|
|
|
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);
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2000-08-24 00:08:15 +00:00
|
|
|
//
|
|
|
|
// Fire the OnStateChange(...) notification for stop request
|
|
|
|
//
|
2001-03-29 00:12:49 +00:00
|
|
|
doStopURLLoad(aRequest, aStatus);
|
2000-08-24 00:08:15 +00:00
|
|
|
|
1999-11-22 05:46:03 +00:00
|
|
|
rv = mLoadGroup->GetActiveCount(&count);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-22 22:58:29 +00:00
|
|
|
|
1999-08-26 22:45:55 +00:00
|
|
|
//
|
1999-11-22 05:46:03 +00:00
|
|
|
// The load group for this DocumentLoader is idle...
|
1999-08-26 22:45:55 +00:00
|
|
|
//
|
2000-08-24 00:08:15 +00:00
|
|
|
if (0 == count) {
|
2001-04-27 21:05:52 +00:00
|
|
|
DocLoaderIsEmpty();
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
1999-09-22 22:58:29 +00:00
|
|
|
}
|
2000-06-19 05:54:37 +00:00
|
|
|
else {
|
2001-03-29 00:12:49 +00:00
|
|
|
doStopURLLoad(aRequest, aStatus);
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
2000-04-22 23:16:31 +00:00
|
|
|
|
1999-09-22 22:58:29 +00:00
|
|
|
return NS_OK;
|
1999-07-16 11:14:36 +00:00
|
|
|
}
|
1998-10-01 21:48:12 +00:00
|
|
|
|
1999-09-17 07:56:03 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
nsresult nsDocLoader::RemoveChildLoader(nsDocLoader* aChild)
|
1998-10-01 21:48:12 +00:00
|
|
|
{
|
2004-12-08 17:32:06 +00:00
|
|
|
nsresult rv = mChildList.RemoveElement(aChild) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aChild->SetDocLoaderParent(nsnull);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
1998-10-01 21:48:12 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
nsresult nsDocLoader::AddChildLoader(nsDocLoader* aChild)
|
|
|
|
{
|
|
|
|
nsresult rv = mChildList.AppendElement(aChild) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
1999-09-17 07:56:03 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-12-08 17:32:06 +00:00
|
|
|
aChild->SetDocLoaderParent(this);
|
1998-10-01 21:48:12 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
NS_IMETHODIMP nsDocLoader::GetDocumentChannel(nsIChannel ** aChannel)
|
2000-11-01 08:04:49 +00:00
|
|
|
{
|
2002-12-11 00:15:19 +00:00
|
|
|
if (!mDocumentRequest) {
|
|
|
|
*aChannel = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(mDocumentRequest, aChannel);
|
2000-11-01 08:04:49 +00:00
|
|
|
}
|
|
|
|
|
1998-07-22 11:23:32 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
void nsDocLoader::DocLoaderIsEmpty()
|
1999-11-22 05:46:03 +00:00
|
|
|
{
|
|
|
|
if (mIsLoadingDocument) {
|
1999-12-15 02:18:52 +00:00
|
|
|
/* 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);
|
1999-11-22 05:46:03 +00:00
|
|
|
|
2004-09-28 20:48:58 +00:00
|
|
|
if (!IsBusy()) {
|
1999-11-22 05:46:03 +00:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Is now idle...\n", this));
|
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
nsCOMPtr<nsIRequest> docRequest = mDocumentRequest;
|
1999-11-22 05:46:03 +00:00
|
|
|
|
2001-04-27 21:05:52 +00:00
|
|
|
NS_ASSERTION(mDocumentRequest, "No Document Request!");
|
|
|
|
mDocumentRequest = 0;
|
1999-11-22 05:46:03 +00:00
|
|
|
mIsLoadingDocument = PR_FALSE;
|
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
// Update the progress status state - the document is done
|
2000-08-25 18:39:46 +00:00
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_STOP;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2000-10-26 06:34:20 +00:00
|
|
|
|
|
|
|
nsresult loadGroupStatus = NS_OK;
|
|
|
|
mLoadGroup->GetStatus(&loadGroupStatus);
|
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
//
|
|
|
|
// New code to break the circular reference between
|
|
|
|
// the load group and the docloader...
|
|
|
|
//
|
2001-02-21 20:38:08 +00:00
|
|
|
mLoadGroup->SetDefaultLoadRequest(nsnull);
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2005-11-04 23:40:22 +00: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;
|
|
|
|
|
1999-11-22 05:46:03 +00:00
|
|
|
//
|
|
|
|
// Do nothing after firing the OnEndDocumentLoad(...). The document
|
|
|
|
// loader may be loading a *new* document - if LoadDocument()
|
|
|
|
// was called from a handler!
|
|
|
|
//
|
2001-02-21 20:38:08 +00:00
|
|
|
doStopDocumentLoad(docRequest, loadGroupStatus);
|
1999-11-22 05:46:03 +00:00
|
|
|
|
2005-11-04 23:40:22 +00:00
|
|
|
if (parent) {
|
|
|
|
parent->DocLoaderIsEmpty();
|
1999-11-22 05:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
void nsDocLoader::doStartDocumentLoad(void)
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
GetURIStringFromRequest(mDocumentRequest, buffer);
|
2000-06-19 05:54:37 +00:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange for start document load (...)."
|
|
|
|
"\tURI: %s \n",
|
2002-03-20 22:50:33 +00:00
|
|
|
this, buffer.get()));
|
2000-06-19 05:54:37 +00:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2000-08-25 18:39:46 +00:00
|
|
|
// Fire an OnStatus(...) notification STATE_START. This indicates
|
2001-02-21 20:38:08 +00:00
|
|
|
// that the document represented by mDocumentRequest has started to
|
2000-06-19 05:54:37 +00:00
|
|
|
// load...
|
|
|
|
FireOnStateChange(this,
|
2001-02-21 20:38:08 +00:00
|
|
|
mDocumentRequest,
|
2000-08-25 18:39:46 +00:00
|
|
|
nsIWebProgressListener::STATE_START |
|
|
|
|
nsIWebProgressListener::STATE_IS_DOCUMENT |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST |
|
2004-10-01 04:52:26 +00:00
|
|
|
nsIWebProgressListener::STATE_IS_WINDOW |
|
2000-08-25 18:39:46 +00:00
|
|
|
nsIWebProgressListener::STATE_IS_NETWORK,
|
2000-06-19 05:54:37 +00:00
|
|
|
NS_OK);
|
|
|
|
}
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
void nsDocLoader::doStartURLLoad(nsIRequest *request)
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
GetURIStringFromRequest(request, buffer);
|
2000-06-19 05:54:37 +00:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange start url load (...)."
|
|
|
|
"\tURI: %s\n",
|
2002-03-20 22:50:33 +00:00
|
|
|
this, buffer.get()));
|
2000-06-19 05:54:37 +00:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
FireOnStateChange(this,
|
2001-02-21 20:38:08 +00:00
|
|
|
request,
|
2000-08-25 18:39:46 +00:00
|
|
|
nsIWebProgressListener::STATE_START |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST,
|
2000-06-19 05:54:37 +00:00
|
|
|
NS_OK);
|
|
|
|
}
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
void nsDocLoader::doStopURLLoad(nsIRequest *request, nsresult aStatus)
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
GetURIStringFromRequest(request, buffer);
|
2000-06-19 05:54:37 +00:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange for end url load (...)."
|
|
|
|
"\tURI: %s status=%x\n",
|
2002-03-20 22:50:33 +00:00
|
|
|
this, buffer.get(), aStatus));
|
2000-06-19 05:54:37 +00:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
FireOnStateChange(this,
|
2001-02-21 20:38:08 +00:00
|
|
|
request,
|
2000-08-25 18:39:46 +00:00
|
|
|
nsIWebProgressListener::STATE_STOP |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST,
|
2000-06-19 05:54:37 +00:00
|
|
|
aStatus);
|
|
|
|
}
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
void nsDocLoader::doStopDocumentLoad(nsIRequest *request,
|
2000-06-19 05:54:37 +00:00
|
|
|
nsresult aStatus)
|
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
GetURIStringFromRequest(request, buffer);
|
2000-06-19 05:54:37 +00:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange for end document load (...)."
|
|
|
|
"\tURI: %s Status=%x\n",
|
2002-03-20 22:50:33 +00:00
|
|
|
this, buffer.get(), aStatus));
|
2000-06-19 05:54:37 +00:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
//
|
2002-05-16 20:57:37 +00:00
|
|
|
// Fire an OnStateChange(...) notification indicating the the
|
2000-06-19 05:54:37 +00:00
|
|
|
// current document has finished loading...
|
|
|
|
//
|
|
|
|
FireOnStateChange(this,
|
2001-02-21 20:38:08 +00:00
|
|
|
request,
|
2000-08-25 18:39:46 +00:00
|
|
|
nsIWebProgressListener::STATE_STOP |
|
2000-12-23 06:07:38 +00:00
|
|
|
nsIWebProgressListener::STATE_IS_DOCUMENT,
|
|
|
|
aStatus);
|
|
|
|
|
|
|
|
//
|
2002-05-16 20:57:37 +00:00
|
|
|
// Fire a final OnStateChange(...) notification indicating the the
|
2000-12-23 06:07:38 +00:00
|
|
|
// current document has finished loading...
|
|
|
|
//
|
|
|
|
FireOnStateChange(this,
|
2001-02-21 20:38:08 +00:00
|
|
|
request,
|
2000-12-23 06:07:38 +00:00
|
|
|
nsIWebProgressListener::STATE_STOP |
|
|
|
|
nsIWebProgressListener::STATE_IS_WINDOW |
|
2000-08-25 18:39:46 +00:00
|
|
|
nsIWebProgressListener::STATE_IS_NETWORK,
|
2000-06-19 05:54:37 +00:00
|
|
|
aStatus);
|
|
|
|
}
|
|
|
|
|
2000-04-03 02:26:05 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// The following section contains support for nsIWebProgress and related stuff
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::AddProgressListener(nsIWebProgressListener *aListener,
|
2002-05-16 20:57:37 +00:00
|
|
|
PRUint32 aNotifyMask)
|
2000-04-03 02:26:05 +00:00
|
|
|
{
|
2000-06-19 05:54:37 +00:00
|
|
|
nsresult rv;
|
2001-01-31 21:02:08 +00:00
|
|
|
|
2004-10-25 15:55:33 +00:00
|
|
|
nsListenerInfo* info = GetListenerInfo(aListener);
|
2002-05-16 20:57:37 +00:00
|
|
|
if (info) {
|
|
|
|
// The listener is already registered!
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2004-10-25 15:55:33 +00:00
|
|
|
nsWeakPtr listener = do_GetWeakReference(aListener);
|
|
|
|
if (!listener) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
info = new nsListenerInfo(listener, aNotifyMask);
|
|
|
|
if (!info) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
2002-05-16 20:57:37 +00:00
|
|
|
|
|
|
|
rv = mListenerInfoList.AppendElement(info) ? NS_OK : NS_ERROR_FAILURE;
|
2000-06-19 05:54:37 +00:00
|
|
|
return rv;
|
2000-04-03 02:26:05 +00:00
|
|
|
}
|
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::RemoveProgressListener(nsIWebProgressListener *aListener)
|
2000-04-03 02:26:05 +00:00
|
|
|
{
|
2002-05-16 20:57:37 +00:00
|
|
|
nsresult rv;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2004-10-25 15:55:33 +00:00
|
|
|
nsListenerInfo* info = GetListenerInfo(aListener);
|
2002-05-16 20:57:37 +00:00
|
|
|
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;
|
2000-04-03 02:26:05 +00:00
|
|
|
}
|
|
|
|
|
2000-12-14 23:26:35 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::GetDOMWindow(nsIDOMWindow **aResult)
|
2000-12-14 23:26:35 +00:00
|
|
|
{
|
2004-12-08 17:32:06 +00:00
|
|
|
return CallGetInterface(this, aResult);
|
2000-12-14 23:26:35 +00:00
|
|
|
}
|
|
|
|
|
2002-07-02 02:17:15 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::GetIsLoadingDocument(PRBool *aIsLoadingDocument)
|
2002-07-02 02:17:15 +00:00
|
|
|
{
|
|
|
|
*aIsLoadingDocument = mIsLoadingDocument;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-09 20:43:35 +00:00
|
|
|
PRInt64 nsDocLoader::GetMaxTotalProgress()
|
2000-04-03 02:26:05 +00:00
|
|
|
{
|
2005-01-09 20:43:35 +00:00
|
|
|
nsInt64 newMaxTotal = 0;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2005-01-09 20:43:35 +00:00
|
|
|
PRInt32 count = mChildList.Count();
|
2000-04-22 23:16:31 +00:00
|
|
|
nsCOMPtr<nsIWebProgress> webProgress;
|
2002-12-11 00:15:19 +00:00
|
|
|
for (PRInt32 i=0; i < count; i++)
|
2000-04-22 23:16:31 +00:00
|
|
|
{
|
2005-01-09 20:43:35 +00:00
|
|
|
nsInt64 individualProgress = 0;
|
|
|
|
nsIDocumentLoader* docloader = ChildAt(i);
|
2000-04-22 23:16:31 +00:00
|
|
|
if (docloader)
|
|
|
|
{
|
2004-12-08 17:32:06 +00:00
|
|
|
// Cast is safe since all children are nsDocLoader too
|
2005-01-09 20:43:35 +00:00
|
|
|
individualProgress = ((nsDocLoader *) docloader)->GetMaxTotalProgress();
|
2000-04-22 23:16:31 +00:00
|
|
|
}
|
2005-01-09 20:43:35 +00:00
|
|
|
if (individualProgress < nsInt64(0)) // if one of the elements doesn't know it's size
|
|
|
|
// then none of them do
|
2000-04-25 01:45:37 +00:00
|
|
|
{
|
2005-01-09 20:43:35 +00:00
|
|
|
newMaxTotal = nsInt64(-1);
|
2000-04-25 01:45:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
2004-09-28 20:48:58 +00:00
|
|
|
newMaxTotal += individualProgress;
|
2000-04-22 23:16:31 +00:00
|
|
|
}
|
2004-09-28 20:48:58 +00:00
|
|
|
|
2005-01-09 20:43:35 +00:00
|
|
|
nsInt64 progress = -1;
|
|
|
|
if (mMaxSelfProgress >= nsInt64(0) && newMaxTotal >= nsInt64(0))
|
2004-09-28 20:48:58 +00:00
|
|
|
progress = newMaxTotal + mMaxSelfProgress;
|
|
|
|
|
|
|
|
return progress;
|
2000-04-22 23:16:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
2005-01-09 20:43:35 +00:00
|
|
|
// The following section contains support for nsIProgressEventSink which is used to
|
2001-03-29 00:12:49 +00:00
|
|
|
// pass progress and status between the actual request and the doc loader. The doc loader
|
2000-04-22 23:16:31 +00:00
|
|
|
// then turns around and makes the right web progress calls based on this information.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
NS_IMETHODIMP nsDocLoader::OnProgress(nsIRequest *aRequest, nsISupports* ctxt,
|
2005-01-09 20:43:35 +00:00
|
|
|
PRUint64 aProgress, PRUint64 aProgressMax)
|
2000-04-22 23:16:31 +00:00
|
|
|
{
|
2001-03-29 00:12:49 +00:00
|
|
|
nsRequestInfo *info;
|
2005-01-09 20:43:35 +00:00
|
|
|
nsInt64 progressDelta = 0;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
|
|
|
//
|
2002-06-20 21:16:46 +00:00
|
|
|
// Update the RequestInfo entry with the new progress data
|
2000-06-19 05:54:37 +00:00
|
|
|
//
|
2001-03-29 00:12:49 +00:00
|
|
|
info = GetRequestInfo(aRequest);
|
2000-06-19 05:54:37 +00:00
|
|
|
if (info) {
|
2004-04-10 20:03:03 +00:00
|
|
|
// suppress sending STATE_TRANSFERRING if this is upload progress (see bug 240053)
|
2005-01-09 20:43:35 +00:00
|
|
|
if (!info->mUploading && (nsInt64(0) == info->mCurrentProgress) && (nsInt64(0) == info->mMaxProgress)) {
|
2004-09-17 20:33:25 +00: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;
|
|
|
|
}
|
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
2005-01-09 20:43:35 +00:00
|
|
|
if (nsUint64(aProgressMax) != LL_MAXUINT) {
|
|
|
|
mMaxSelfProgress += PRInt64(aProgressMax);
|
|
|
|
info->mMaxProgress = PRInt64(aProgressMax);
|
2000-06-19 05:54:37 +00:00
|
|
|
} else {
|
2005-01-09 20:43:35 +00:00
|
|
|
mMaxSelfProgress = nsInt64(-1);
|
|
|
|
info->mMaxProgress = nsInt64(-1);
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2000-08-25 18:39:46 +00:00
|
|
|
// Send a STATE_TRANSFERRING notification for the request.
|
2000-06-19 05:54:37 +00:00
|
|
|
PRInt32 flags;
|
|
|
|
|
2000-08-25 18:39:46 +00:00
|
|
|
flags = nsIWebProgressListener::STATE_TRANSFERRING |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST;
|
2000-06-19 05:54:37 +00:00
|
|
|
//
|
2000-08-25 18:39:46 +00:00
|
|
|
// Move the WebProgress into the STATE_TRANSFERRING state if necessary...
|
2000-06-19 05:54:37 +00:00
|
|
|
//
|
2000-08-25 18:39:46 +00:00
|
|
|
if (mProgressStateFlags & nsIWebProgressListener::STATE_START) {
|
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_TRANSFERRING;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2000-08-25 18:39:46 +00:00
|
|
|
// Send STATE_TRANSFERRING for the document too...
|
|
|
|
flags |= nsIWebProgressListener::STATE_IS_DOCUMENT;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2001-03-29 00:12:49 +00:00
|
|
|
FireOnStateChange(this, aRequest, flags, NS_OK);
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the current progress count...
|
2005-01-09 20:43:35 +00:00
|
|
|
progressDelta = nsInt64(PRInt64(aProgress)) - info->mCurrentProgress;
|
2000-06-19 05:54:37 +00:00
|
|
|
mCurrentSelfProgress += progressDelta;
|
|
|
|
|
2005-01-09 20:43:35 +00:00
|
|
|
info->mCurrentProgress = PRInt64(aProgress);
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
//
|
2001-03-29 00:12:49 +00:00
|
|
|
// The request is not part of the load group, so ignore its progress
|
2000-06-19 05:54:37 +00:00
|
|
|
// information...
|
|
|
|
//
|
|
|
|
else {
|
|
|
|
#if defined(DEBUG)
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2001-03-29 00:12:49 +00:00
|
|
|
GetURIStringFromRequest(aRequest, buffer);
|
2000-06-19 05:54:37 +00:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
2001-03-29 00:12:49 +00:00
|
|
|
("DocLoader:%p OOPS - No Request Info for: %s\n",
|
2002-03-20 22:50:33 +00:00
|
|
|
this, buffer.get()));
|
2000-06-19 05:54:37 +00:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-04-22 23:16:31 +00:00
|
|
|
}
|
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
//
|
|
|
|
// Fire progress notifications out to any registered nsIWebProgressListeners
|
|
|
|
//
|
2001-03-29 00:12:49 +00:00
|
|
|
FireOnProgressChange(this, aRequest, aProgress, aProgressMax, progressDelta,
|
2000-06-19 05:54:37 +00:00
|
|
|
mCurrentTotalProgress, mMaxTotalProgress);
|
2000-04-25 01:45:37 +00:00
|
|
|
|
2000-04-22 23:16:31 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
NS_IMETHODIMP nsDocLoader::OnStatus(nsIRequest* aRequest, nsISupports* ctxt,
|
2000-07-25 05:45:56 +00:00
|
|
|
nsresult aStatus, const PRUnichar* aStatusArg)
|
2000-04-22 23:16:31 +00:00
|
|
|
{
|
2000-07-25 05:45:56 +00:00
|
|
|
//
|
|
|
|
// Fire progress notifications out to any registered nsIWebProgressListeners
|
|
|
|
//
|
|
|
|
if (aStatus) {
|
2004-04-10 20:03:03 +00:00
|
|
|
// Remember the current status for this request
|
|
|
|
nsRequestInfo *info;
|
|
|
|
info = GetRequestInfo(aRequest);
|
|
|
|
if (info) {
|
|
|
|
PRBool uploading = (aStatus == nsITransport::STATUS_WRITING ||
|
|
|
|
aStatus == nsISocketTransport::STATUS_SENDING_TO);
|
|
|
|
// 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) {
|
2005-01-09 20:43:35 +00:00
|
|
|
mCurrentSelfProgress = mMaxSelfProgress = LL_ZERO;
|
|
|
|
mCurrentTotalProgress = mMaxTotalProgress = LL_ZERO;
|
2004-04-10 20:03:03 +00:00
|
|
|
info->mUploading = uploading;
|
2005-01-09 20:43:35 +00:00
|
|
|
info->mCurrentProgress = LL_ZERO;
|
|
|
|
info->mMaxProgress = LL_ZERO;
|
2004-04-10 20:03:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-25 05:45:56 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIStringBundleService> sbs = do_GetService(kStringBundleServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsXPIDLString msg;
|
|
|
|
rv = sbs->FormatStatusMessage(aStatus, aStatusArg, getter_Copies(msg));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-02-21 20:38:08 +00:00
|
|
|
FireOnStatusChange(this, aRequest, aStatus, msg);
|
2000-07-25 05:45:56 +00:00
|
|
|
}
|
2000-04-22 23:16:31 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
void nsDocLoader::ClearInternalProgress()
|
2000-04-22 23:16:31 +00:00
|
|
|
{
|
2002-07-09 00:54:41 +00:00
|
|
|
ClearRequestInfoHash();
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2005-01-09 20:43:35 +00:00
|
|
|
mCurrentSelfProgress = mMaxSelfProgress = LL_ZERO;
|
|
|
|
mCurrentTotalProgress = mMaxTotalProgress = LL_ZERO;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2000-08-25 18:39:46 +00:00
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_STOP;
|
2000-04-03 02:26:05 +00:00
|
|
|
}
|
2000-04-25 01:45:37 +00:00
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
void nsDocLoader::FireOnProgressChange(nsDocLoader *aLoadInitiator,
|
|
|
|
nsIRequest *request,
|
2005-01-09 20:43:35 +00:00
|
|
|
PRInt64 aProgress,
|
|
|
|
PRInt64 aProgressMax,
|
|
|
|
PRInt64 aProgressDelta,
|
|
|
|
PRInt64 aTotalProgress,
|
|
|
|
PRInt64 aMaxTotalProgress)
|
2000-04-25 01:45:37 +00:00
|
|
|
{
|
2000-06-19 05:54:37 +00:00
|
|
|
if (mIsLoadingDocument) {
|
|
|
|
mCurrentTotalProgress += aProgressDelta;
|
2004-09-28 20:48:58 +00:00
|
|
|
mMaxTotalProgress = GetMaxTotalProgress();
|
2000-06-19 05:54:37 +00:00
|
|
|
|
|
|
|
aTotalProgress = mCurrentTotalProgress;
|
|
|
|
aMaxTotalProgress = mMaxTotalProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
GetURIStringFromRequest(request, buffer);
|
2000-06-19 05:54:37 +00:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Progress (%s): curSelf: %d maxSelf: %d curTotal: %d maxTotal %d\n",
|
2002-03-20 22:50:33 +00:00
|
|
|
this, buffer.get(), aProgress, aProgressMax, aTotalProgress, aMaxTotalProgress));
|
2000-06-19 05:54:37 +00:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2002-05-16 20:57:37 +00:00
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
PRInt32 count = mListenerInfoList.Count();
|
|
|
|
|
|
|
|
while (--count >= 0) {
|
|
|
|
nsListenerInfo *info;
|
|
|
|
|
2004-03-03 15:46:05 +00:00
|
|
|
info = NS_STATIC_CAST(nsListenerInfo*,mListenerInfoList.SafeElementAt(count));
|
2002-05-21 21:30:58 +00:00
|
|
|
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_PROGRESS)) {
|
2002-05-16 20:57:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener = do_QueryReferent(info->mWeakListener);
|
2001-01-31 21:02:08 +00:00
|
|
|
if (!listener) {
|
2002-05-16 20:57:37 +00:00
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerInfoList.RemoveElementAt(count);
|
|
|
|
delete info;
|
|
|
|
continue;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2005-01-09 20:43:35 +00:00
|
|
|
// XXX truncates 64-bit to 32-bit
|
2001-02-21 20:38:08 +00:00
|
|
|
listener->OnProgressChange(aLoadInitiator,request,
|
2005-01-09 20:43:35 +00:00
|
|
|
PRInt32(aProgress), PRInt32(aProgressMax),
|
|
|
|
PRInt32(aTotalProgress), PRInt32(aMaxTotalProgress));
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
mListenerInfoList.Compact();
|
2001-01-31 21:02:08 +00:00
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
2001-02-21 20:38:08 +00:00
|
|
|
mParent->FireOnProgressChange(aLoadInitiator, request,
|
2000-06-19 05:54:37 +00:00
|
|
|
aProgress, aProgressMax,
|
|
|
|
aProgressDelta,
|
|
|
|
aTotalProgress, aMaxTotalProgress);
|
|
|
|
}
|
2000-04-25 01:45:37 +00:00
|
|
|
}
|
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
void nsDocLoader::FireOnStateChange(nsIWebProgress *aProgress,
|
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRInt32 aStateFlags,
|
|
|
|
nsresult aStatus)
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
|
|
|
//
|
2000-08-25 18:39:46 +00:00
|
|
|
// Remove the STATE_IS_NETWORK bit if necessary.
|
2000-06-19 05:54:37 +00:00
|
|
|
//
|
|
|
|
// 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 &&
|
2000-08-25 18:39:46 +00:00
|
|
|
(aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) &&
|
2000-06-19 05:54:37 +00:00
|
|
|
(this != aProgress)) {
|
2000-08-25 18:39:46 +00:00
|
|
|
aStateFlags &= ~nsIWebProgressListener::STATE_IS_NETWORK;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2005-06-15 23:52:46 +00:00
|
|
|
// Add the STATE_RESTORING bit if necessary.
|
|
|
|
if (mIsRestoringDocument)
|
|
|
|
aStateFlags |= nsIWebProgressListener::STATE_RESTORING;
|
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
#if defined(DEBUG)
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
GetURIStringFromRequest(aRequest, buffer);
|
2000-06-19 05:54:37 +00:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Status (%s): code: %x\n",
|
2002-03-20 22:50:33 +00:00
|
|
|
this, buffer.get(), aStateFlags));
|
2000-06-19 05:54:37 +00:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2001-04-27 21:05:52 +00:00
|
|
|
NS_ASSERTION(aRequest, "Firing OnStateChange(...) notification with a NULL request!");
|
2000-06-19 05:54:37 +00: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
|
|
|
|
*/
|
2002-05-16 20:57:37 +00:00
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
PRInt32 count = mListenerInfoList.Count();
|
|
|
|
|
|
|
|
while (--count >= 0) {
|
|
|
|
nsListenerInfo *info;
|
|
|
|
|
2004-03-03 15:46:05 +00:00
|
|
|
info = NS_STATIC_CAST(nsListenerInfo*,mListenerInfoList.SafeElementAt(count));
|
2002-05-21 21:30:58 +00:00
|
|
|
if (!info || !(info->mNotifyMask & (aStateFlags >>16))) {
|
2002-05-16 20:57:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener = do_QueryReferent(info->mWeakListener);
|
2001-01-31 21:02:08 +00:00
|
|
|
if (!listener) {
|
2002-05-16 20:57:37 +00:00
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerInfoList.RemoveElementAt(count);
|
|
|
|
delete info;
|
|
|
|
continue;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
listener->OnStateChange(aProgress, aRequest, aStateFlags, aStatus);
|
|
|
|
}
|
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
mListenerInfoList.Compact();
|
2001-01-31 21:02:08 +00:00
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
|
|
|
mParent->FireOnStateChange(aProgress, aRequest, aStateFlags, aStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 22:56:56 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
void
|
|
|
|
nsDocLoader::FireOnLocationChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
nsIURI *aUri)
|
2000-07-25 05:45:56 +00:00
|
|
|
{
|
2002-05-16 20:57:37 +00: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;
|
|
|
|
PRInt32 count = mListenerInfoList.Count();
|
2000-07-25 05:45:56 +00:00
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
while (--count >= 0) {
|
|
|
|
nsListenerInfo *info;
|
2001-01-31 21:02:08 +00:00
|
|
|
|
2004-03-03 15:46:05 +00:00
|
|
|
info = NS_STATIC_CAST(nsListenerInfo*,mListenerInfoList.SafeElementAt(count));
|
2002-05-21 21:30:58 +00:00
|
|
|
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_LOCATION)) {
|
2002-05-16 20:57:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener = do_QueryReferent(info->mWeakListener);
|
2001-01-31 21:02:08 +00:00
|
|
|
if (!listener) {
|
2002-05-16 20:57:37 +00:00
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerInfoList.RemoveElementAt(count);
|
|
|
|
delete info;
|
|
|
|
continue;
|
2000-07-25 05:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
listener->OnLocationChange(aWebProgress, aRequest, aUri);
|
|
|
|
}
|
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
mListenerInfoList.Compact();
|
|
|
|
|
2001-05-18 21:46:59 +00:00
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
|
|
|
mParent->FireOnLocationChange(aWebProgress, aRequest, aUri);
|
|
|
|
}
|
2000-07-25 05:45:56 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 20:48:58 +00:00
|
|
|
void
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::FireOnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar* aMessage)
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
2002-05-16 20:57:37 +00: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;
|
|
|
|
PRInt32 count = mListenerInfoList.Count();
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
while (--count >= 0) {
|
|
|
|
nsListenerInfo *info;
|
|
|
|
|
2004-03-03 15:46:05 +00:00
|
|
|
info = NS_STATIC_CAST(nsListenerInfo*,mListenerInfoList.SafeElementAt(count));
|
2002-05-21 21:30:58 +00:00
|
|
|
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_STATUS)) {
|
2002-05-16 20:57:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-01-31 21:02:08 +00:00
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
listener = do_QueryReferent(info->mWeakListener);
|
2001-01-31 21:02:08 +00:00
|
|
|
if (!listener) {
|
2002-05-16 20:57:37 +00:00
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerInfoList.RemoveElementAt(count);
|
|
|
|
delete info;
|
|
|
|
continue;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2000-07-25 05:45:56 +00:00
|
|
|
listener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
2002-05-16 20:57:37 +00:00
|
|
|
mListenerInfoList.Compact();
|
|
|
|
|
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
|
|
|
mParent->FireOnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
|
|
|
|
}
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
nsListenerInfo *
|
2004-12-08 17:32:06 +00:00
|
|
|
nsDocLoader::GetListenerInfo(nsIWebProgressListener *aListener)
|
2002-05-16 20:57:37 +00:00
|
|
|
{
|
|
|
|
PRInt32 i, count;
|
|
|
|
nsListenerInfo *info;
|
|
|
|
|
2004-10-25 15:55:33 +00:00
|
|
|
nsCOMPtr<nsISupports> listener1 = do_QueryInterface(aListener);
|
2002-05-16 20:57:37 +00:00
|
|
|
count = mListenerInfoList.Count();
|
|
|
|
for (i=0; i<count; i++) {
|
2004-03-03 15:46:05 +00:00
|
|
|
info = NS_STATIC_CAST(nsListenerInfo* ,mListenerInfoList.SafeElementAt(i));
|
2002-05-21 21:30:58 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(info, "There should NEVER be a null listener in the list");
|
2004-10-25 15:55:33 +00:00
|
|
|
if (info) {
|
|
|
|
nsCOMPtr<nsISupports> listener2 = do_QueryReferent(info->mWeakListener);
|
|
|
|
if (listener1 == listener2)
|
|
|
|
return info;
|
2002-05-16 20:57:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
nsresult nsDocLoader::AddRequestInfo(nsIRequest *aRequest)
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
2002-07-09 00:54:41 +00:00
|
|
|
if (!PL_DHashTableOperate(&mRequestInfoHash, aRequest, PL_DHASH_ADD)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
2002-07-09 00:54:41 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
nsRequestInfo * nsDocLoader::GetRequestInfo(nsIRequest *aRequest)
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
2002-07-09 00:54:41 +00:00
|
|
|
nsRequestInfo *info =
|
|
|
|
NS_STATIC_CAST(nsRequestInfo *,
|
|
|
|
PL_DHashTableOperate(&mRequestInfoHash, aRequest,
|
|
|
|
PL_DHASH_LOOKUP));
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
if (PL_DHASH_ENTRY_IS_FREE(info)) {
|
|
|
|
// Nothing found in the hash, return null.
|
|
|
|
|
|
|
|
return nsnull;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
// Return what we found in the hash...
|
|
|
|
|
|
|
|
return info;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
// PLDHashTable enumeration callback that just removes every entry
|
|
|
|
// from the hash.
|
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator)
|
|
|
|
RemoveInfoCallback(PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number,
|
|
|
|
void *arg)
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
2002-07-09 00:54:41 +00:00
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
void nsDocLoader::ClearRequestInfoHash(void)
|
2002-07-09 00:54:41 +00:00
|
|
|
{
|
|
|
|
if (!mRequestInfoHash.ops || !mRequestInfoHash.entryCount) {
|
|
|
|
// No hash, or the hash is empty, nothing to do here then...
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
PL_DHashTableEnumerate(&mRequestInfoHash, RemoveInfoCallback, nsnull);
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
// PLDHashTable enumeration callback that calculates the max progress.
|
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator)
|
|
|
|
CalcMaxProgressCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
|
|
|
PRUint32 number, void *arg)
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
2002-07-09 00:54:41 +00:00
|
|
|
const nsRequestInfo *info = NS_STATIC_CAST(const nsRequestInfo *, hdr);
|
2005-01-09 20:43:35 +00:00
|
|
|
nsInt64 *max = NS_STATIC_CAST(nsInt64 *, arg);
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
if (info->mMaxProgress < info->mCurrentProgress) {
|
2005-01-09 20:43:35 +00:00
|
|
|
*max = nsInt64(-1);
|
2000-06-19 05:54:37 +00:00
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
return PL_DHASH_STOP;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2002-07-09 00:54:41 +00:00
|
|
|
*max += info->mMaxProgress;
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2005-01-09 20:43:35 +00:00
|
|
|
PRInt64 nsDocLoader::CalculateMaxProgress()
|
2002-07-09 00:54:41 +00:00
|
|
|
{
|
2005-01-09 20:43:35 +00:00
|
|
|
nsInt64 max = 0;
|
2004-09-28 20:48:58 +00:00
|
|
|
PL_DHashTableEnumerate(&mRequestInfoHash, CalcMaxProgressCallback, &max);
|
|
|
|
return max;
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2005-03-07 19:46:06 +00:00
|
|
|
NS_IMETHODIMP nsDocLoader::OnChannelRedirect(nsIChannel *aOldChannel,
|
|
|
|
nsIChannel *aNewChannel,
|
|
|
|
PRUint32 aFlags)
|
2000-08-25 01:32:40 +00:00
|
|
|
{
|
2001-04-27 21:05:52 +00:00
|
|
|
if (aOldChannel)
|
|
|
|
{
|
2001-05-11 21:05:08 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> oldURI, newURI;
|
|
|
|
|
|
|
|
rv = aOldChannel->GetOriginalURI(getter_AddRefs(oldURI));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = aNewChannel->GetURI(getter_AddRefs(newURI));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-04-27 21:05:52 +00:00
|
|
|
nsLoadFlags loadFlags = 0;
|
|
|
|
PRInt32 stateFlags = nsIWebProgressListener::STATE_REDIRECTING |
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
|
|
|
|
FireOnStateChange(this, aOldChannel, stateFlags, NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-08-25 01:32:40 +00:00
|
|
|
}
|
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
/*
|
|
|
|
* Implementation of nsISecurityEventSink method...
|
|
|
|
*/
|
|
|
|
|
2004-12-08 17:32:06 +00:00
|
|
|
NS_IMETHODIMP nsDocLoader::OnSecurityChange(nsISupports * aContext,
|
|
|
|
PRUint32 aState)
|
2000-09-14 22:56:56 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// Fire progress notifications out to any registered nsIWebProgressListeners.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRequest> request = do_QueryInterface(aContext);
|
|
|
|
nsIWebProgress* webProgress = NS_STATIC_CAST(nsIWebProgress*, this);
|
|
|
|
|
2002-05-16 20:57:37 +00: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;
|
|
|
|
PRInt32 count = mListenerInfoList.Count();
|
2000-09-14 22:56:56 +00:00
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
while (--count >= 0) {
|
|
|
|
nsListenerInfo *info;
|
2001-01-31 21:02:08 +00:00
|
|
|
|
2004-03-03 15:46:05 +00:00
|
|
|
info = NS_STATIC_CAST(nsListenerInfo*,mListenerInfoList.SafeElementAt(count));
|
2002-05-21 21:30:58 +00:00
|
|
|
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_SECURITY)) {
|
2002-05-16 20:57:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener = do_QueryReferent(info->mWeakListener);
|
2001-01-31 21:02:08 +00:00
|
|
|
if (!listener) {
|
2002-05-16 20:57:37 +00:00
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerInfoList.RemoveElementAt(count);
|
|
|
|
delete info;
|
|
|
|
continue;
|
2000-09-14 22:56:56 +00:00
|
|
|
}
|
2002-05-16 20:57:37 +00:00
|
|
|
|
|
|
|
listener->OnSecurityChange(webProgress, request, aState);
|
2000-09-14 22:56:56 +00:00
|
|
|
}
|
|
|
|
|
2002-05-16 20:57:37 +00:00
|
|
|
mListenerInfoList.Compact();
|
2001-01-31 21:02:08 +00:00
|
|
|
|
2000-09-14 22:56:56 +00:00
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
2002-05-16 20:57:37 +00:00
|
|
|
mParent->OnSecurityChange(aContext, aState);
|
2000-09-14 22:56:56 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-21 20:58:01 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocLoader::GetPriority(PRInt32 *aPriority)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mLoadGroup);
|
|
|
|
if (p)
|
|
|
|
return p->GetPriority(aPriority);
|
|
|
|
|
|
|
|
*aPriority = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDocLoader::SetPriority(PRInt32 aPriority)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
PRInt32 count = mChildList.Count();
|
|
|
|
|
|
|
|
nsDocLoader *loader;
|
|
|
|
for (PRInt32 i=0; i < count; i++) {
|
|
|
|
loader = NS_STATIC_CAST(nsDocLoader*, ChildAt(i));
|
|
|
|
if (loader) {
|
|
|
|
loader->SetPriority(aPriority);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-21 22:21:21 +00:00
|
|
|
NS_IMETHODIMP nsDocLoader::AdjustPriority(PRInt32 aDelta)
|
2005-02-21 20:58:01 +00:00
|
|
|
{
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
2005-02-21 22:21:21 +00:00
|
|
|
("DocLoader:%p: AdjustPriority(%d) called\n", this, aDelta));
|
2005-02-21 20:58:01 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mLoadGroup);
|
|
|
|
if (p)
|
2005-02-21 22:21:21 +00:00
|
|
|
p->AdjustPriority(aDelta);
|
2005-02-21 20:58:01 +00:00
|
|
|
|
|
|
|
PRInt32 count = mChildList.Count();
|
|
|
|
|
|
|
|
nsDocLoader *loader;
|
|
|
|
for (PRInt32 i=0; i < count; i++) {
|
|
|
|
loader = NS_STATIC_CAST(nsDocLoader*, ChildAt(i));
|
|
|
|
if (loader) {
|
2005-02-21 22:21:21 +00:00
|
|
|
loader->AdjustPriority(aDelta);
|
2005-02-21 20:58:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-09-14 22:56:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-19 05:54:37 +00:00
|
|
|
#if 0
|
2004-12-08 17:32:06 +00:00
|
|
|
void nsDocLoader::DumpChannelInfo()
|
2000-06-19 05:54:37 +00:00
|
|
|
{
|
|
|
|
nsChannelInfo *info;
|
|
|
|
PRInt32 i, count;
|
|
|
|
PRInt32 current=0, max=0;
|
|
|
|
|
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("==== DocLoader=%x\n", this);
|
2000-06-19 05:54:37 +00:00
|
|
|
|
|
|
|
count = mChannelInfoList.Count();
|
|
|
|
for(i=0; i<count; i++) {
|
|
|
|
info = (nsChannelInfo *)mChannelInfoList.ElementAt(i);
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 05:54:37 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (info->mURI) {
|
2002-03-20 22:50:33 +00:00
|
|
|
rv = info->mURI->GetSpec(buffer);
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
printf(" [%d] current=%d max=%d [%s]\n", i,
|
2000-06-19 05:54:37 +00:00
|
|
|
info->mCurrentProgress,
|
2002-03-20 22:50:33 +00:00
|
|
|
info->mMaxProgress, buffer.get());
|
2000-06-19 05:54:37 +00:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
current += info->mCurrentProgress;
|
|
|
|
if (max >= 0) {
|
|
|
|
if (info->mMaxProgress < info->mCurrentProgress) {
|
|
|
|
max = -1;
|
|
|
|
} else {
|
|
|
|
max += info->mMaxProgress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("\nCurrent=%d Total=%d\n====\n", current, max);
|
2000-06-19 05:54:37 +00:00
|
|
|
}
|
2000-06-19 13:03:52 +00:00
|
|
|
#endif /* 0 */
|
|
|
|
|