2002-04-17 07:48:37 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-07-01 15:29:20 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1998-07-01 15:29:20 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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 15:29:20 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-01-29 07:41:04 +03:00
|
|
|
|
1999-12-29 10:32:59 +03:00
|
|
|
#include "nspr.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
|
2000-01-29 07:41:04 +03:00
|
|
|
#include "nsDocLoader.h"
|
|
|
|
#include "nsCURILoader.h"
|
|
|
|
#include "nsNetUtil.h"
|
2001-05-12 01:05:08 +04:00
|
|
|
#include "nsIHttpChannel.h"
|
2000-01-29 07:41:04 +03:00
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
#include "nsIServiceManager.h"
|
1999-09-05 23:54:28 +04:00
|
|
|
#include "nsXPIDLString.h"
|
1999-09-17 11:56:03 +04:00
|
|
|
|
2000-01-29 07:41:04 +03:00
|
|
|
#include "nsIURL.h"
|
1999-05-06 23:31:59 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-05-26 05:38:36 +04:00
|
|
|
#include "nsCom.h"
|
2001-02-01 00:02:08 +03:00
|
|
|
#include "nsWeakPtr.h"
|
1998-07-01 15:29:20 +04:00
|
|
|
|
2000-12-15 02:26:35 +03:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
// XXX ick ick ick
|
1999-12-29 10:32:59 +03:00
|
|
|
#include "nsIContentViewerContainer.h"
|
1998-07-01 15:29:20 +04:00
|
|
|
#include "nsIDocument.h"
|
1999-05-06 07:54:40 +04:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIPresContext.h"
|
2000-07-25 09:45:56 +04:00
|
|
|
#include "nsIStringBundle.h"
|
2001-05-12 01:05:08 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-01-12 22:41:06 +03:00
|
|
|
|
2000-07-25 09:45:56 +04:00
|
|
|
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
#if defined(PR_LOGGING)
|
1999-11-22 08:46:03 +03:00
|
|
|
//
|
|
|
|
// Log module for nsIDocumentLoader logging...
|
|
|
|
//
|
|
|
|
// To enable logging (see prlog.h for full details):
|
|
|
|
//
|
2000-10-29 02:17:53 +04:00
|
|
|
// set NSPR_LOG_MODULES=DocLoader:5
|
1999-11-22 08:46:03 +03: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-29 02:17:53 +04:00
|
|
|
PRLogModuleInfo* gDocLoaderLog = nsnull;
|
|
|
|
#endif /* PR_LOGGING */
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
#if defined(DEBUG)
|
2002-03-21 01:50:33 +03:00
|
|
|
void GetURIStringFromRequest(nsIRequest* request, nsACString &name)
|
2000-06-19 09:54:37 +04:00
|
|
|
{
|
2002-03-21 01:50:33 +03:00
|
|
|
if (request)
|
|
|
|
request->GetName(name);
|
|
|
|
else
|
|
|
|
name = NS_LITERAL_CSTRING("???");
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
/* Define IIDs... */
|
1999-05-06 23:31:59 +04:00
|
|
|
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
2000-07-19 03:37:53 +04:00
|
|
|
static NS_DEFINE_IID(kIContentViewerContainerIID, NS_ICONTENTVIEWERCONTAINER_IID);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
struct nsRequestInfo {
|
|
|
|
nsRequestInfo(nsIRequest *key) : mKey(key),
|
2000-06-19 09:54:37 +04:00
|
|
|
mCurrentProgress(0),
|
|
|
|
mMaxProgress(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void* mKey;
|
|
|
|
PRInt32 mCurrentProgress;
|
|
|
|
PRInt32 mMaxProgress;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-09-12 23:30:49 +04:00
|
|
|
nsDocLoaderImpl::nsDocLoaderImpl()
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
2000-04-23 03:16:31 +04:00
|
|
|
NS_INIT_REFCNT();
|
1998-07-01 15:29:20 +04:00
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
if (nsnull == gDocLoaderLog) {
|
|
|
|
gDocLoaderLog = PR_NewLogModule("DocLoader");
|
|
|
|
}
|
|
|
|
#endif /* PR_LOGGING */
|
|
|
|
|
2000-04-23 03:16:31 +04:00
|
|
|
mContainer = nsnull;
|
|
|
|
mParent = nsnull;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
2000-04-23 03:16:31 +04:00
|
|
|
mIsLoadingDocument = PR_FALSE;
|
|
|
|
ClearInternalProgress();
|
2000-04-03 06:26:05 +04:00
|
|
|
|
2000-04-23 03:16:31 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: created.\n", this));
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
nsresult
|
2000-01-29 07:41:04 +03:00
|
|
|
nsDocLoaderImpl::SetDocLoaderParent(nsDocLoaderImpl *aParent)
|
|
|
|
{
|
|
|
|
mParent = aParent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDocLoaderImpl::Init()
|
1999-06-28 14:35:57 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), this);
|
1999-06-28 14:35:57 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-17 11:56:03 +04:00
|
|
|
|
1999-07-31 10:33:50 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-09-21 00:57:21 +04:00
|
|
|
("DocLoader:%p: load group %x.\n", this, mLoadGroup.get()));
|
1999-08-27 02:45:55 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(mChildList));
|
2001-02-01 00:02:08 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_NewISupportsArray(getter_AddRefs(mListenerList));
|
1999-06-28 14:35:57 +04:00
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
2000-03-24 08:45:31 +03:00
|
|
|
NS_IMETHODIMP nsDocLoaderImpl::ClearParentDocLoader()
|
|
|
|
{
|
|
|
|
SetDocLoaderParent(nsnull);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
nsDocLoaderImpl::~nsDocLoaderImpl()
|
|
|
|
{
|
1999-09-22 01:10:22 +04: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]
|
|
|
|
*/
|
2000-06-20 09:14:42 +04:00
|
|
|
ClearWeakReferences();
|
1999-09-22 01:10:22 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
Destroy();
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: deleted.\n", this));
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
PRUint32 count=0;
|
|
|
|
mChildList->Count(&count);
|
2000-03-24 08:45:31 +03: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
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
for (PRUint32 i=0; i<count; i++)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocumentLoader> loader;
|
|
|
|
loader = getter_AddRefs(NS_STATIC_CAST(nsIDocumentLoader*, mChildList->ElementAt(i)));
|
|
|
|
|
|
|
|
if (loader)
|
|
|
|
loader->ClearParentDocLoader();
|
|
|
|
}
|
|
|
|
mChildList->Clear();
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
1999-09-17 08:26:02 +04:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
/*
|
|
|
|
* Implementation of ISupports methods...
|
|
|
|
*/
|
2000-05-05 01:34:50 +04:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsDocLoaderImpl)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsDocLoaderImpl)
|
1998-07-22 15:23:32 +04:00
|
|
|
|
2000-01-29 07:41:04 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDocLoaderImpl)
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRequestObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
|
2000-01-29 07:41:04 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocumentLoader)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2000-04-03 06:26:05 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebProgress)
|
2000-04-23 03:16:31 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIProgressEventSink)
|
2000-05-07 06:01:10 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
2001-05-12 01:05:08 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIHttpEventSink)
|
2000-09-15 02:56:56 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISecurityEventSink)
|
2000-01-29 07:41:04 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
1998-07-22 15:23:32 +04:00
|
|
|
|
2000-05-07 06:01:10 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of nsIInterfaceRequestor methods...
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP nsDocLoaderImpl::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::CreateDocumentLoader(nsIDocumentLoader** anInstance)
|
|
|
|
{
|
|
|
|
|
2000-01-29 07:41:04 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsDocLoaderImpl * newLoader = new nsDocLoaderImpl();
|
|
|
|
NS_ENSURE_TRUE(newLoader, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
NS_ADDREF(newLoader);
|
|
|
|
newLoader->Init();
|
1999-06-28 14:35:57 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
// Initialize now that we have a reference
|
2000-01-29 07:41:04 +03:00
|
|
|
rv = newLoader->SetDocLoaderParent(this);
|
1999-11-22 08:46:03 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
//
|
|
|
|
// XXX this method incorrectly returns a bool
|
|
|
|
//
|
|
|
|
rv = mChildList->AppendElement((nsIDocumentLoader*)newLoader)
|
|
|
|
? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
2000-01-29 07:41:04 +03:00
|
|
|
|
|
|
|
rv = newLoader->QueryInterface(NS_GET_IID(nsIDocumentLoader), (void **) anInstance);
|
|
|
|
NS_RELEASE(newLoader);
|
1998-10-09 09:49:34 +04:00
|
|
|
return rv;
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
|
|
|
|
1999-03-12 08:20:29 +03:00
|
|
|
NS_IMETHODIMP
|
1999-11-22 08:46:03 +03:00
|
|
|
nsDocLoaderImpl::Stop(void)
|
1999-03-12 08:20:29 +03:00
|
|
|
{
|
1999-11-22 08:46:03 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRUint32 count, i;
|
1999-03-12 08:20:29 +03:00
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-11-22 08:46:03 +03:00
|
|
|
("DocLoader:%p: Stop() called\n", this));
|
1999-03-12 08:20:29 +03:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
rv = mChildList->Count(&count);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-12 08:20:29 +03:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
for (i=0; i<count; i++) {
|
|
|
|
nsIDocumentLoader* loader;
|
1999-03-12 08:20:29 +03:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
loader = NS_STATIC_CAST(nsIDocumentLoader*, mChildList->ElementAt(i));
|
|
|
|
|
|
|
|
if (loader) {
|
|
|
|
(void) loader->Stop();
|
|
|
|
NS_RELEASE(loader);
|
|
|
|
}
|
|
|
|
}
|
1998-10-09 09:49:34 +04:00
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
rv = mLoadGroup->Cancel(NS_BINDING_ABORTED);
|
1998-10-10 08:33:29 +04:00
|
|
|
|
1999-07-01 23:30:20 +04:00
|
|
|
return rv;
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
NS_IMETHODIMP
|
2000-01-29 07:41:04 +03:00
|
|
|
nsDocLoaderImpl::IsBusy(PRBool * aResult)
|
1998-10-02 01:48:12 +04:00
|
|
|
{
|
1999-11-22 08:46:03 +03: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...
|
|
|
|
//
|
2000-01-29 07:41:04 +03:00
|
|
|
*aResult = PR_FALSE;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
/* Is this document loader busy? */
|
1999-09-17 11:56:03 +04:00
|
|
|
if (mIsLoadingDocument) {
|
2000-01-29 07:41:04 +03:00
|
|
|
rv = mLoadGroup->IsPending(aResult);
|
1999-11-22 08:46:03 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
/* Otherwise, check its child document loaders... */
|
2000-01-29 07:41:04 +03:00
|
|
|
if (!*aResult) {
|
1999-11-22 08:46:03 +03:00
|
|
|
PRUint32 count, i;
|
|
|
|
|
|
|
|
rv = mChildList->Count(&count);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
for (i=0; i<count; i++) {
|
|
|
|
nsIDocumentLoader* loader;
|
|
|
|
|
|
|
|
loader = NS_STATIC_CAST(nsIDocumentLoader*, mChildList->ElementAt(i));
|
|
|
|
|
|
|
|
if (loader) {
|
|
|
|
(void) loader->IsBusy(aResult);
|
|
|
|
NS_RELEASE(loader);
|
|
|
|
|
2000-01-29 07:41:04 +03:00
|
|
|
if (*aResult) break;
|
1999-11-22 08:46:03 +03:00
|
|
|
}
|
|
|
|
}
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-14 09:44:23 +03:00
|
|
|
NS_IMETHODIMP
|
1999-11-15 10:29:23 +03:00
|
|
|
nsDocLoaderImpl::SetContainer(nsISupports* aContainer)
|
1999-01-14 09:44:23 +03:00
|
|
|
{
|
1999-09-17 11:56:03 +04:00
|
|
|
// This is a weak reference...
|
1999-01-14 09:44:23 +03:00
|
|
|
mContainer = aContainer;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-15 10:29:23 +03:00
|
|
|
nsDocLoaderImpl::GetContainer(nsISupports** aResult)
|
1999-01-14 09:44:23 +03:00
|
|
|
{
|
1999-11-15 10:29:23 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
1999-01-14 09:44:23 +03:00
|
|
|
|
1999-11-15 10:29:23 +03:00
|
|
|
*aResult = mContainer;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-01-14 09:44:23 +03:00
|
|
|
}
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-10-27 08:44:42 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::GetLoadGroup(nsILoadGroup** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
|
|
|
*aResult = mLoadGroup;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-05-06 05:58:48 +04:00
|
|
|
NS_IMETHODIMP
|
2000-03-23 03:53:53 +03:00
|
|
|
nsDocLoaderImpl::GetContentViewerContainer(nsISupports* aDocumentID,
|
1999-05-06 05:58:48 +04:00
|
|
|
nsIContentViewerContainer** aResult)
|
|
|
|
{
|
2000-03-23 03:53:53 +03:00
|
|
|
nsISupports* base = aDocumentID;
|
1999-05-06 07:54:40 +04:00
|
|
|
nsIDocument* doc;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = base->QueryInterface(kIDocumentIID, (void**)&doc);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-06-20 07:27:48 +04:00
|
|
|
nsCOMPtr<nsIPresShell> pres;
|
|
|
|
doc->GetShellAt(0, getter_AddRefs(pres));
|
1999-05-06 07:54:40 +04:00
|
|
|
if (nsnull != pres) {
|
|
|
|
nsIPresContext* presContext;
|
|
|
|
rv = pres->GetPresContext(&presContext);
|
|
|
|
if (NS_SUCCEEDED(rv) && nsnull != presContext) {
|
|
|
|
nsISupports* supp;
|
|
|
|
rv = presContext->GetContainer(&supp);
|
|
|
|
if (NS_SUCCEEDED(rv) && nsnull != supp) {
|
|
|
|
rv = supp->QueryInterface(kIContentViewerContainerIID, (void**)aResult);
|
|
|
|
NS_RELEASE(supp);
|
|
|
|
}
|
|
|
|
NS_RELEASE(presContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
return rv;
|
1999-05-06 05:58:48 +04:00
|
|
|
}
|
|
|
|
|
1999-09-10 03:53:55 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::Destroy()
|
|
|
|
{
|
2000-04-23 03:16:31 +04:00
|
|
|
Stop();
|
1999-09-17 11:56:03 +04:00
|
|
|
|
2000-04-23 03:16:31 +04:00
|
|
|
// Remove the document loader from the parent list of loaders...
|
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
mParent->RemoveChildGroup(this);
|
|
|
|
mParent = nsnull;
|
|
|
|
}
|
1998-10-02 01:48:12 +04:00
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
ClearRequestInfoList();
|
2000-06-20 09:14:42 +04:00
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
mDocumentRequest = 0;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
2000-04-23 03:16:31 +04:00
|
|
|
mLoadGroup->SetGroupObserver(nsnull);
|
1999-10-19 23:42:55 +04:00
|
|
|
|
2000-04-23 03:16:31 +04:00
|
|
|
return NS_OK;
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsDocLoaderImpl::OnStartRequest(nsIRequest *request, nsISupports *aCtxt)
|
1999-07-16 15:14:36 +04:00
|
|
|
{
|
2001-04-28 01:05:52 +04:00
|
|
|
// called each time a request is added to the group.
|
2001-04-13 06:32:02 +04:00
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
2001-04-28 01:05:52 +04:00
|
|
|
if (PR_LOG_TEST(gDocLoaderLog, PR_LOG_DEBUG)) {
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCAutoString name;
|
|
|
|
request->GetName(name);
|
2001-04-28 01:05:52 +04: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-21 01:50:33 +03:00
|
|
|
this, request, name.get(),
|
2001-04-28 01:05:52 +04:00
|
|
|
(mIsLoadingDocument ? "true" : "false"),
|
|
|
|
count));
|
|
|
|
}
|
|
|
|
#endif /* PR_LOGGING */
|
2001-05-30 02:10:50 +04:00
|
|
|
PRBool bJustStartedLoading = PR_FALSE;
|
|
|
|
|
2001-04-28 01:05:52 +04:00
|
|
|
PRUint32 loadFlags = 0;
|
|
|
|
request->GetLoadFlags(&loadFlags);
|
2001-04-13 06:32:02 +04:00
|
|
|
|
2001-04-28 01:05:52 +04:00
|
|
|
if (!mIsLoadingDocument && (loadFlags & nsIChannel::LOAD_DOCUMENT_URI)) {
|
2001-05-30 02:10:50 +04:00
|
|
|
bJustStartedLoading = PR_TRUE;
|
2001-04-28 01:05:52 +04:00
|
|
|
mIsLoadingDocument = PR_TRUE;
|
|
|
|
ClearInternalProgress(); // only clear our progress if we are starting a new load....
|
|
|
|
}
|
2000-01-15 09:12:54 +03:00
|
|
|
|
2001-04-28 01:05:52 +04: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-27 02:45:55 +04:00
|
|
|
//
|
2001-04-28 01:05:52 +04:00
|
|
|
// Create a new nsRequestInfo for the request that is starting to
|
|
|
|
// load...
|
1999-08-27 02:45:55 +04:00
|
|
|
//
|
2001-04-28 01:05:52 +04:00
|
|
|
AddRequestInfo(request);
|
|
|
|
|
|
|
|
if (loadFlags & nsIChannel::LOAD_DOCUMENT_URI) {
|
|
|
|
//
|
|
|
|
// Make sure that hte 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
|
|
|
|
//
|
2001-05-30 02:10:50 +04:00
|
|
|
if (bJustStartedLoading) {
|
2001-04-28 01:05:52 +04: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...
|
|
|
|
ClearRequestInfoList();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!mIsLoadingDocument || mDocumentRequest,
|
|
|
|
"mDocumentRequest MUST be set for the duration of a page load!");
|
|
|
|
|
|
|
|
doStartURLLoad(request);
|
2001-04-19 23:51:29 +04:00
|
|
|
|
2000-04-23 03:16:31 +04:00
|
|
|
return NS_OK;
|
1999-07-16 15:14:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-03-29 04:12:49 +04:00
|
|
|
nsDocLoaderImpl::OnStopRequest(nsIRequest *aRequest,
|
1999-11-22 08:46:03 +03:00
|
|
|
nsISupports *aCtxt,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsresult aStatus)
|
1999-07-16 15:14:36 +04:00
|
|
|
{
|
1999-11-22 08:46:03 +03:00
|
|
|
nsresult rv = NS_OK;
|
1999-08-27 02:45:55 +04:00
|
|
|
|
2001-04-13 06:32:02 +04:00
|
|
|
#ifdef PR_LOGGING
|
2001-04-28 01:05:52 +04:00
|
|
|
if (PR_LOG_TEST(gDocLoaderLog, PR_LOG_DEBUG)) {
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCAutoString name;
|
|
|
|
aRequest->GetName(name);
|
2001-04-28 01:05:52 +04: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-21 01:50:33 +03:00
|
|
|
this, aRequest, name.get(),
|
2001-04-28 01:05:52 +04:00
|
|
|
aStatus, (mIsLoadingDocument ? "true" : "false"),
|
|
|
|
count));
|
|
|
|
}
|
2001-04-13 06:32:02 +04:00
|
|
|
#endif
|
2001-04-28 01:05:52 +04:00
|
|
|
|
1999-09-23 02:58:29 +04:00
|
|
|
//
|
|
|
|
// Only fire the OnEndDocumentLoad(...) if the document loader
|
|
|
|
// has initiated a load...
|
|
|
|
//
|
|
|
|
if (mIsLoadingDocument) {
|
1999-11-22 08:46:03 +03:00
|
|
|
PRUint32 count;
|
1999-09-23 02:58:29 +04:00
|
|
|
|
2000-06-19 09:54:37 +04: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)
|
|
|
|
//
|
2001-03-29 04:12:49 +04:00
|
|
|
nsRequestInfo *info;
|
|
|
|
info = GetRequestInfo(aRequest);
|
2000-06-19 09:54:37 +04:00
|
|
|
if (info) {
|
|
|
|
PRInt32 oldMax = info->mMaxProgress;
|
|
|
|
|
|
|
|
info->mMaxProgress = info->mCurrentProgress;
|
|
|
|
//
|
2001-03-29 04:12:49 +04:00
|
|
|
// If a request whose content-length was previously unknown has just
|
2000-06-19 09:54:37 +04:00
|
|
|
// finished loading, then use this new data to try to calculate a
|
|
|
|
// mMaxSelfProgress...
|
|
|
|
//
|
|
|
|
if ((oldMax < 0) && (mMaxSelfProgress < 0)) {
|
|
|
|
CalculateMaxProgress(&mMaxSelfProgress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-24 04:08:15 +04:00
|
|
|
//
|
|
|
|
// Fire the OnStateChange(...) notification for stop request
|
|
|
|
//
|
2001-03-29 04:12:49 +04:00
|
|
|
doStopURLLoad(aRequest, aStatus);
|
2000-08-24 04:08:15 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
rv = mLoadGroup->GetActiveCount(&count);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-09-23 02:58:29 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
//
|
1999-11-22 08:46:03 +03:00
|
|
|
// The load group for this DocumentLoader is idle...
|
1999-08-27 02:45:55 +04:00
|
|
|
//
|
2000-08-24 04:08:15 +04:00
|
|
|
if (0 == count) {
|
2001-04-28 01:05:52 +04:00
|
|
|
DocLoaderIsEmpty();
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
1999-09-23 02:58:29 +04:00
|
|
|
}
|
2000-06-19 09:54:37 +04:00
|
|
|
else {
|
2001-03-29 04:12:49 +04:00
|
|
|
doStopURLLoad(aRequest, aStatus);
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
2000-04-23 03:16:31 +04:00
|
|
|
|
1999-09-23 02:58:29 +04:00
|
|
|
return NS_OK;
|
1999-07-16 15:14:36 +04:00
|
|
|
}
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
|
|
|
|
nsresult nsDocLoaderImpl::RemoveChildGroup(nsDocLoaderImpl* aLoader)
|
1998-10-02 01:48:12 +04:00
|
|
|
{
|
1999-11-22 08:46:03 +03:00
|
|
|
nsresult rv = NS_OK;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mChildList->RemoveElement((nsIDocumentLoader*)aLoader);
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-11-01 11:04:49 +03:00
|
|
|
NS_IMETHODIMP nsDocLoaderImpl::GetDocumentChannel(nsIChannel ** aChannel)
|
|
|
|
{
|
2001-02-21 23:38:08 +03:00
|
|
|
nsCOMPtr<nsIChannel> ourChannel = do_QueryInterface(mDocumentRequest);
|
|
|
|
|
|
|
|
*aChannel = ourChannel.get();
|
2000-11-01 11:04:49 +03:00
|
|
|
NS_IF_ADDREF(*aChannel);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
|
2001-04-28 01:05:52 +04:00
|
|
|
void nsDocLoaderImpl::DocLoaderIsEmpty()
|
1999-11-22 08:46:03 +03:00
|
|
|
{
|
|
|
|
if (mIsLoadingDocument) {
|
|
|
|
PRBool busy = PR_FALSE;
|
1999-12-15 05:18:52 +03: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 08:46:03 +03:00
|
|
|
|
2000-01-29 07:41:04 +03:00
|
|
|
IsBusy(&busy);
|
1999-11-22 08:46:03 +03:00
|
|
|
if (!busy) {
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Is now idle...\n", this));
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
nsCOMPtr<nsIRequest> docRequest = mDocumentRequest;
|
1999-11-22 08:46:03 +03:00
|
|
|
|
2001-04-28 01:05:52 +04:00
|
|
|
NS_ASSERTION(mDocumentRequest, "No Document Request!");
|
|
|
|
mDocumentRequest = 0;
|
1999-11-22 08:46:03 +03:00
|
|
|
mIsLoadingDocument = PR_FALSE;
|
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
// Update the progress status state - the document is done
|
2000-08-25 22:39:46 +04:00
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_STOP;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2000-10-26 10:34:20 +04:00
|
|
|
|
|
|
|
nsresult loadGroupStatus = NS_OK;
|
|
|
|
mLoadGroup->GetStatus(&loadGroupStatus);
|
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
//
|
|
|
|
// New code to break the circular reference between
|
|
|
|
// the load group and the docloader...
|
|
|
|
//
|
2001-02-21 23:38:08 +03:00
|
|
|
mLoadGroup->SetDefaultLoadRequest(nsnull);
|
2000-06-19 09:54:37 +04:00
|
|
|
|
1999-11-22 08:46:03 +03: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 23:38:08 +03:00
|
|
|
doStopDocumentLoad(docRequest, loadGroupStatus);
|
1999-11-22 08:46:03 +03:00
|
|
|
|
|
|
|
if (mParent) {
|
2001-04-28 01:05:52 +04:00
|
|
|
mParent->DocLoaderIsEmpty();
|
1999-11-22 08:46:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
void nsDocLoaderImpl::doStartDocumentLoad(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
GetURIStringFromRequest(mDocumentRequest, buffer);
|
2000-06-19 09:54:37 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange for start document load (...)."
|
|
|
|
"\tURI: %s \n",
|
2002-03-21 01:50:33 +03:00
|
|
|
this, buffer.get()));
|
2000-06-19 09:54:37 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
// Fire an OnStatus(...) notification STATE_START. This indicates
|
2001-02-21 23:38:08 +03:00
|
|
|
// that the document represented by mDocumentRequest has started to
|
2000-06-19 09:54:37 +04:00
|
|
|
// load...
|
|
|
|
FireOnStateChange(this,
|
2001-02-21 23:38:08 +03:00
|
|
|
mDocumentRequest,
|
2000-08-25 22:39:46 +04:00
|
|
|
nsIWebProgressListener::STATE_START |
|
|
|
|
nsIWebProgressListener::STATE_IS_DOCUMENT |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST |
|
|
|
|
nsIWebProgressListener::STATE_IS_NETWORK,
|
2000-06-19 09:54:37 +04:00
|
|
|
NS_OK);
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
void nsDocLoaderImpl::doStartURLLoad(nsIRequest *request)
|
2000-06-19 09:54:37 +04:00
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
GetURIStringFromRequest(request, buffer);
|
2000-06-19 09:54:37 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange start url load (...)."
|
|
|
|
"\tURI: %s\n",
|
2002-03-21 01:50:33 +03:00
|
|
|
this, buffer.get()));
|
2000-06-19 09:54:37 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
FireOnStateChange(this,
|
2001-02-21 23:38:08 +03:00
|
|
|
request,
|
2000-08-25 22:39:46 +04:00
|
|
|
nsIWebProgressListener::STATE_START |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST,
|
2000-06-19 09:54:37 +04:00
|
|
|
NS_OK);
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
void nsDocLoaderImpl::doStopURLLoad(nsIRequest *request, nsresult aStatus)
|
2000-06-19 09:54:37 +04:00
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
GetURIStringFromRequest(request, buffer);
|
2000-06-19 09:54:37 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange for end url load (...)."
|
|
|
|
"\tURI: %s status=%x\n",
|
2002-03-21 01:50:33 +03:00
|
|
|
this, buffer.get(), aStatus));
|
2000-06-19 09:54:37 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
FireOnStateChange(this,
|
2001-02-21 23:38:08 +03:00
|
|
|
request,
|
2000-08-25 22:39:46 +04:00
|
|
|
nsIWebProgressListener::STATE_STOP |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST,
|
2000-06-19 09:54:37 +04:00
|
|
|
aStatus);
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
void nsDocLoaderImpl::doStopDocumentLoad(nsIRequest *request,
|
2000-06-19 09:54:37 +04:00
|
|
|
nsresult aStatus)
|
|
|
|
{
|
|
|
|
#if defined(DEBUG)
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
GetURIStringFromRequest(request, buffer);
|
2000-06-19 09:54:37 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStateChange for end document load (...)."
|
|
|
|
"\tURI: %s Status=%x\n",
|
2002-03-21 01:50:33 +03:00
|
|
|
this, buffer.get(), aStatus));
|
2000-06-19 09:54:37 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fire an OnStatusChange(...) notification indicating the the
|
|
|
|
// current document has finished loading...
|
|
|
|
//
|
|
|
|
FireOnStateChange(this,
|
2001-02-21 23:38:08 +03:00
|
|
|
request,
|
2000-08-25 22:39:46 +04:00
|
|
|
nsIWebProgressListener::STATE_STOP |
|
2000-12-23 09:07:38 +03:00
|
|
|
nsIWebProgressListener::STATE_IS_DOCUMENT,
|
|
|
|
aStatus);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fire a final OnStatusChange(...) notification indicating the the
|
|
|
|
// current document has finished loading...
|
|
|
|
//
|
|
|
|
FireOnStateChange(this,
|
2001-02-21 23:38:08 +03:00
|
|
|
request,
|
2000-12-23 09:07:38 +03:00
|
|
|
nsIWebProgressListener::STATE_STOP |
|
|
|
|
nsIWebProgressListener::STATE_IS_WINDOW |
|
2000-08-25 22:39:46 +04:00
|
|
|
nsIWebProgressListener::STATE_IS_NETWORK,
|
2000-06-19 09:54:37 +04:00
|
|
|
aStatus);
|
|
|
|
}
|
|
|
|
|
2000-04-03 06:26:05 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// The following section contains support for nsIWebProgress and related stuff
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2000-04-23 03:16:31 +04:00
|
|
|
// get web progress returns our web progress listener or if
|
|
|
|
// we don't have one, it will look up the doc loader hierarchy
|
|
|
|
// to see if one of our parent doc loaders has one.
|
|
|
|
nsresult nsDocLoaderImpl::GetParentWebProgressListener(nsDocLoaderImpl * aDocLoader, nsIWebProgressListener ** aWebProgress)
|
|
|
|
{
|
2000-06-19 09:54:37 +04:00
|
|
|
// if we got here, there is no web progress to return
|
|
|
|
*aWebProgress = nsnull;
|
2000-04-23 03:16:31 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::AddProgressListener(nsIWebProgressListener *aListener)
|
2000-04-03 06:26:05 +04:00
|
|
|
{
|
2000-06-19 09:54:37 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2001-02-01 00:02:08 +03:00
|
|
|
nsWeakPtr listener = getter_AddRefs(NS_GetWeakReference(aListener));
|
|
|
|
if (!listener) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
if (mListenerList->IndexOf(listener) == -1) {
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
// XXX this method incorrectly returns a bool
|
2001-02-01 00:02:08 +03:00
|
|
|
rv = mListenerList->AppendElement(listener) ? NS_OK : NS_ERROR_FAILURE;
|
2000-06-19 09:54:37 +04:00
|
|
|
} else {
|
|
|
|
// The listener is already in the list...
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return rv;
|
2000-04-03 06:26:05 +04:00
|
|
|
}
|
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::RemoveProgressListener(nsIWebProgressListener *aListener)
|
2000-04-03 06:26:05 +04:00
|
|
|
{
|
2001-02-01 00:02:08 +03:00
|
|
|
nsWeakPtr listener = getter_AddRefs(NS_GetWeakReference(aListener));
|
|
|
|
if (!listener) return NS_ERROR_INVALID_ARG;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
// XXX this method incorrectly returns a bool
|
2001-02-01 00:02:08 +03:00
|
|
|
return mListenerList->RemoveElement(listener) ? NS_OK : NS_ERROR_FAILURE;
|
2000-04-03 06:26:05 +04:00
|
|
|
}
|
|
|
|
|
2000-12-15 02:26:35 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::GetDOMWindow(nsIDOMWindow **aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
*aResult = nsnull;
|
|
|
|
//
|
|
|
|
// The DOM Window is available from the associated container (ie DocShell)
|
|
|
|
// if one is available...
|
|
|
|
//
|
|
|
|
if (mContainer) {
|
|
|
|
nsCOMPtr<nsIDOMWindow> window(do_GetInterface(mContainer, &rv));
|
|
|
|
|
|
|
|
*aResult = window;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
2001-05-07 22:14:28 +04:00
|
|
|
} else {
|
2002-04-17 07:48:37 +04:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2000-12-15 02:26:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
nsresult nsDocLoaderImpl::GetProgressStatusFlags(PRInt32 *aProgressStateFlags)
|
2000-04-03 06:26:05 +04:00
|
|
|
{
|
2000-06-19 09:54:37 +04:00
|
|
|
*aProgressStateFlags = mProgressStateFlags;
|
2000-04-03 06:26:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
nsresult nsDocLoaderImpl::GetCurSelfProgress(PRInt32 *aCurSelfProgress)
|
2000-04-03 06:26:05 +04:00
|
|
|
{
|
2000-04-23 03:16:31 +04:00
|
|
|
*aCurSelfProgress = mCurrentSelfProgress;
|
|
|
|
return NS_OK;
|
2000-04-03 06:26:05 +04:00
|
|
|
}
|
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
nsresult nsDocLoaderImpl::GetMaxSelfProgress(PRInt32 *aMaxSelfProgress)
|
2000-04-03 06:26:05 +04:00
|
|
|
{
|
2000-04-23 03:16:31 +04:00
|
|
|
*aMaxSelfProgress = mMaxSelfProgress;
|
|
|
|
return NS_OK;
|
2000-04-03 06:26:05 +04:00
|
|
|
}
|
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
nsresult nsDocLoaderImpl::GetCurTotalProgress(PRInt32 *aCurTotalProgress)
|
2000-04-03 06:26:05 +04:00
|
|
|
{
|
2000-06-19 09:54:37 +04:00
|
|
|
*aCurTotalProgress = mCurrentTotalProgress;
|
2000-04-23 03:16:31 +04:00
|
|
|
return NS_OK;
|
2000-04-03 06:26:05 +04:00
|
|
|
}
|
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
nsresult nsDocLoaderImpl::GetMaxTotalProgress(PRInt32 *aMaxTotalProgress)
|
2000-04-03 06:26:05 +04:00
|
|
|
{
|
2000-04-23 03:16:31 +04:00
|
|
|
PRUint32 count = 0;
|
|
|
|
nsresult rv = NS_OK;
|
2000-06-19 09:54:37 +04:00
|
|
|
PRInt32 invididualProgress, newMaxTotal;
|
|
|
|
|
|
|
|
newMaxTotal = 0;
|
2000-04-23 03:16:31 +04:00
|
|
|
|
|
|
|
rv = mChildList->Count(&count);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress;
|
|
|
|
nsCOMPtr<nsISupports> docloader;
|
|
|
|
for (PRUint32 i=0; i<count; i++)
|
|
|
|
{
|
|
|
|
invididualProgress = 0;
|
|
|
|
docloader = getter_AddRefs(mChildList->ElementAt(i));
|
|
|
|
if (docloader)
|
|
|
|
{
|
2000-08-25 22:39:46 +04:00
|
|
|
// Cast is safe since all children are nsDocLoaderImpl too
|
|
|
|
((nsDocLoaderImpl *) docloader.get())->GetMaxTotalProgress(&invididualProgress);
|
2000-04-23 03:16:31 +04:00
|
|
|
}
|
2000-04-25 05:45:37 +04:00
|
|
|
if (invididualProgress < 0) // if one of the elements doesn't know it's size
|
|
|
|
// then none of them do
|
|
|
|
{
|
2000-06-19 09:54:37 +04:00
|
|
|
newMaxTotal = -1;
|
2000-04-25 05:45:37 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
2000-06-19 09:54:37 +04:00
|
|
|
newMaxTotal += invididualProgress;
|
2000-04-23 03:16:31 +04:00
|
|
|
}
|
2000-06-19 09:54:37 +04:00
|
|
|
if (mMaxSelfProgress >= 0 && newMaxTotal >= 0) {
|
|
|
|
*aMaxTotalProgress = newMaxTotal + mMaxSelfProgress;
|
|
|
|
} else {
|
|
|
|
*aMaxTotalProgress = -1;
|
|
|
|
}
|
2000-04-23 03:16:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// The following section contains support for nsIEventProgressSink which is used to
|
2001-03-29 04:12:49 +04:00
|
|
|
// pass progress and status between the actual request and the doc loader. The doc loader
|
2000-04-23 03:16:31 +04:00
|
|
|
// then turns around and makes the right web progress calls based on this information.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
NS_IMETHODIMP nsDocLoaderImpl::OnProgress(nsIRequest *aRequest, nsISupports* ctxt,
|
2000-04-23 03:16:31 +04:00
|
|
|
PRUint32 aProgress, PRUint32 aProgressMax)
|
|
|
|
{
|
2001-03-29 04:12:49 +04:00
|
|
|
nsRequestInfo *info;
|
2000-06-19 09:54:37 +04:00
|
|
|
PRInt32 progressDelta = 0;
|
|
|
|
|
|
|
|
//
|
2001-03-29 04:12:49 +04:00
|
|
|
// Update the RequsetInfo entry with the new progress data
|
2000-06-19 09:54:37 +04:00
|
|
|
//
|
2001-03-29 04:12:49 +04:00
|
|
|
info = GetRequestInfo(aRequest);
|
2000-06-19 09:54:37 +04:00
|
|
|
if (info) {
|
|
|
|
if ((0 == info->mCurrentProgress) && (0 == info->mMaxProgress)) {
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
if (aProgressMax != (PRUint32)-1) {
|
|
|
|
mMaxSelfProgress += aProgressMax;
|
|
|
|
info->mMaxProgress = aProgressMax;
|
|
|
|
} else {
|
|
|
|
mMaxSelfProgress = -1;
|
|
|
|
info->mMaxProgress = -1;
|
|
|
|
}
|
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
// Send a STATE_TRANSFERRING notification for the request.
|
2000-06-19 09:54:37 +04:00
|
|
|
PRInt32 flags;
|
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
flags = nsIWebProgressListener::STATE_TRANSFERRING |
|
|
|
|
nsIWebProgressListener::STATE_IS_REQUEST;
|
2000-06-19 09:54:37 +04:00
|
|
|
//
|
2000-08-25 22:39:46 +04:00
|
|
|
// Move the WebProgress into the STATE_TRANSFERRING state if necessary...
|
2000-06-19 09:54:37 +04:00
|
|
|
//
|
2000-08-25 22:39:46 +04:00
|
|
|
if (mProgressStateFlags & nsIWebProgressListener::STATE_START) {
|
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_TRANSFERRING;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
// Send STATE_TRANSFERRING for the document too...
|
|
|
|
flags |= nsIWebProgressListener::STATE_IS_DOCUMENT;
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
FireOnStateChange(this, aRequest, flags, NS_OK);
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the current progress count...
|
|
|
|
progressDelta = aProgress - info->mCurrentProgress;
|
|
|
|
mCurrentSelfProgress += progressDelta;
|
|
|
|
|
|
|
|
info->mCurrentProgress = aProgress;
|
|
|
|
}
|
|
|
|
//
|
2001-03-29 04:12:49 +04:00
|
|
|
// The request is not part of the load group, so ignore its progress
|
2000-06-19 09:54:37 +04:00
|
|
|
// information...
|
|
|
|
//
|
|
|
|
else {
|
|
|
|
#if defined(DEBUG)
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
GetURIStringFromRequest(aRequest, buffer);
|
2000-06-19 09:54:37 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
2001-03-29 04:12:49 +04:00
|
|
|
("DocLoader:%p OOPS - No Request Info for: %s\n",
|
2002-03-21 01:50:33 +03:00
|
|
|
this, buffer.get()));
|
2000-06-19 09:54:37 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-04-23 03:16:31 +04:00
|
|
|
}
|
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
//
|
|
|
|
// Fire progress notifications out to any registered nsIWebProgressListeners
|
|
|
|
//
|
2001-03-29 04:12:49 +04:00
|
|
|
FireOnProgressChange(this, aRequest, aProgress, aProgressMax, progressDelta,
|
2000-06-19 09:54:37 +04:00
|
|
|
mCurrentTotalProgress, mMaxTotalProgress);
|
2000-04-25 05:45:37 +04:00
|
|
|
|
2000-04-23 03:16:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsDocLoaderImpl::OnStatus(nsIRequest* aRequest, nsISupports* ctxt,
|
2000-07-25 09:45:56 +04:00
|
|
|
nsresult aStatus, const PRUnichar* aStatusArg)
|
2000-04-23 03:16:31 +04:00
|
|
|
{
|
2000-07-25 09:45:56 +04:00
|
|
|
//
|
|
|
|
// Fire progress notifications out to any registered nsIWebProgressListeners
|
|
|
|
//
|
|
|
|
if (aStatus) {
|
|
|
|
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 23:38:08 +03:00
|
|
|
FireOnStatusChange(this, aRequest, aStatus, msg);
|
2000-07-25 09:45:56 +04:00
|
|
|
}
|
2000-04-23 03:16:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDocLoaderImpl::ClearInternalProgress()
|
|
|
|
{
|
2001-03-29 04:12:49 +04:00
|
|
|
ClearRequestInfoList();
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
mCurrentSelfProgress = mMaxSelfProgress = 0;
|
|
|
|
mCurrentTotalProgress = mMaxTotalProgress = 0;
|
|
|
|
|
2000-08-25 22:39:46 +04:00
|
|
|
mProgressStateFlags = nsIWebProgressListener::STATE_STOP;
|
2000-04-03 06:26:05 +04:00
|
|
|
}
|
2000-04-25 05:45:37 +04:00
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
void nsDocLoaderImpl::FireOnProgressChange(nsDocLoaderImpl *aLoadInitiator,
|
2001-02-21 23:38:08 +03:00
|
|
|
nsIRequest *request,
|
2000-06-19 09:54:37 +04:00
|
|
|
PRInt32 aProgress,
|
|
|
|
PRInt32 aProgressMax,
|
|
|
|
PRInt32 aProgressDelta,
|
|
|
|
PRInt32 aTotalProgress,
|
|
|
|
PRInt32 aMaxTotalProgress)
|
2000-04-25 05:45:37 +04:00
|
|
|
{
|
2001-02-01 00:02:08 +03:00
|
|
|
PRUint32 count;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
if (mIsLoadingDocument) {
|
|
|
|
mCurrentTotalProgress += aProgressDelta;
|
|
|
|
GetMaxTotalProgress(&mMaxTotalProgress);
|
|
|
|
|
|
|
|
aTotalProgress = mCurrentTotalProgress;
|
|
|
|
aMaxTotalProgress = mMaxTotalProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
GetURIStringFromRequest(request, buffer);
|
2000-06-19 09:54:37 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Progress (%s): curSelf: %d maxSelf: %d curTotal: %d maxTotal %d\n",
|
2002-03-21 01:50:33 +03:00
|
|
|
this, buffer.get(), aProgress, aProgressMax, aTotalProgress, aMaxTotalProgress));
|
2000-06-19 09:54:37 +04: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
|
|
|
|
*/
|
2001-02-01 00:02:08 +03:00
|
|
|
(void)mListenerList->Count(&count);
|
2000-06-19 09:54:37 +04:00
|
|
|
while (count > 0) {
|
2001-02-01 00:02:08 +03:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
nsresult rv = mListenerList->GetElementAt(--count, getter_AddRefs(supports));
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
nsWeakPtr weakPtr = do_QueryInterface(supports);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
listener = do_QueryReferent(weakPtr);
|
|
|
|
if (!listener) {
|
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerList->RemoveElementAt(count);
|
|
|
|
continue;
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
listener->OnProgressChange(aLoadInitiator,request,
|
2000-06-19 09:54:37 +04:00
|
|
|
aProgress, aProgressMax,
|
|
|
|
aTotalProgress, aMaxTotalProgress);
|
|
|
|
}
|
|
|
|
|
2001-02-01 00:02:08 +03:00
|
|
|
mListenerList->Compact();
|
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
2001-02-21 23:38:08 +03:00
|
|
|
mParent->FireOnProgressChange(aLoadInitiator, request,
|
2000-06-19 09:54:37 +04:00
|
|
|
aProgress, aProgressMax,
|
|
|
|
aProgressDelta,
|
|
|
|
aTotalProgress, aMaxTotalProgress);
|
|
|
|
}
|
2000-04-25 05:45:37 +04:00
|
|
|
}
|
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
void nsDocLoaderImpl::FireOnStateChange(nsIWebProgress *aProgress,
|
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRInt32 aStateFlags,
|
|
|
|
nsresult aStatus)
|
|
|
|
{
|
2001-02-01 00:02:08 +03:00
|
|
|
PRUint32 count;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
//
|
2000-08-25 22:39:46 +04:00
|
|
|
// Remove the STATE_IS_NETWORK bit if necessary.
|
2000-06-19 09:54:37 +04: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 22:39:46 +04:00
|
|
|
(aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) &&
|
2000-06-19 09:54:37 +04:00
|
|
|
(this != aProgress)) {
|
2000-08-25 22:39:46 +04:00
|
|
|
aStateFlags &= ~nsIWebProgressListener::STATE_IS_NETWORK;
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
GetURIStringFromRequest(aRequest, buffer);
|
2000-06-19 09:54:37 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Status (%s): code: %x\n",
|
2002-03-21 01:50:33 +03:00
|
|
|
this, buffer.get(), aStateFlags));
|
2000-06-19 09:54:37 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2001-04-28 01:05:52 +04:00
|
|
|
NS_ASSERTION(aRequest, "Firing OnStateChange(...) notification with a NULL request!");
|
2000-06-19 09:54:37 +04: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
|
|
|
|
*/
|
2001-02-01 00:02:08 +03:00
|
|
|
(void)mListenerList->Count(&count);
|
2000-06-19 09:54:37 +04:00
|
|
|
while (count > 0) {
|
2001-02-01 00:02:08 +03:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
nsresult rv = mListenerList->GetElementAt(--count, getter_AddRefs(supports));
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
nsWeakPtr weakPtr = do_QueryInterface(supports);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
listener = do_QueryReferent(weakPtr);
|
|
|
|
if (!listener) {
|
|
|
|
// the listener went away, gracefully pull it out of the list.
|
|
|
|
mListenerList->RemoveElementAt(count);
|
|
|
|
continue;
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
listener->OnStateChange(aProgress, aRequest, aStateFlags, aStatus);
|
|
|
|
}
|
|
|
|
|
2001-02-01 00:02:08 +03:00
|
|
|
mListenerList->Compact();
|
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
|
|
|
mParent->FireOnStateChange(aProgress, aRequest, aStateFlags, aStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-15 02:56:56 +04:00
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
NS_IMETHODIMP
|
2000-07-25 09:45:56 +04:00
|
|
|
nsDocLoaderImpl::FireOnLocationChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
nsIURI *aUri)
|
|
|
|
{
|
2001-02-01 00:02:08 +03:00
|
|
|
PRUint32 count;
|
2000-07-25 09:45:56 +04:00
|
|
|
|
2001-02-01 00:02:08 +03:00
|
|
|
(void)mListenerList->Count(&count);
|
2000-07-25 09:45:56 +04:00
|
|
|
while (count > 0) {
|
2001-02-01 00:02:08 +03:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
nsresult rv = mListenerList->GetElementAt(--count, getter_AddRefs(supports));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsWeakPtr weakPtr = do_QueryInterface(supports);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
listener = do_QueryReferent(weakPtr);
|
|
|
|
if (!listener) {
|
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerList->RemoveElementAt(count);
|
|
|
|
continue;
|
2000-07-25 09:45:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
listener->OnLocationChange(aWebProgress, aRequest, aUri);
|
|
|
|
}
|
|
|
|
|
2001-02-01 00:02:08 +03:00
|
|
|
mListenerList->Compact();
|
2001-05-19 01:46:59 +04:00
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
|
|
|
mParent->FireOnLocationChange(aWebProgress, aRequest, aUri);
|
|
|
|
}
|
2001-02-01 00:02:08 +03:00
|
|
|
|
2000-07-25 09:45:56 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::FireOnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar* aMessage)
|
2000-06-19 09:54:37 +04:00
|
|
|
{
|
2001-02-01 00:02:08 +03:00
|
|
|
PRUint32 count;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2001-02-01 00:02:08 +03:00
|
|
|
(void)mListenerList->Count(&count);
|
2000-06-19 09:54:37 +04:00
|
|
|
while (count > 0) {
|
2001-02-01 00:02:08 +03:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
nsresult rv = mListenerList->GetElementAt(--count, getter_AddRefs(supports));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsWeakPtr weakPtr = do_QueryInterface(supports);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
listener = do_QueryReferent(weakPtr);
|
|
|
|
if (!listener) {
|
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerList->RemoveElementAt(count);
|
|
|
|
continue;
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
|
|
|
|
2000-07-25 09:45:56 +04:00
|
|
|
listener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
2001-02-01 00:02:08 +03:00
|
|
|
mListenerList->Compact();
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
nsresult nsDocLoaderImpl::AddRequestInfo(nsIRequest *aRequest)
|
2000-06-19 09:54:37 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2001-03-29 04:12:49 +04:00
|
|
|
nsRequestInfo *info;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
info = new nsRequestInfo(aRequest);
|
|
|
|
if (info) {
|
|
|
|
// XXX this method incorrectly returns a bool
|
|
|
|
rv = mRequestInfoList.AppendElement(info) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
nsRequestInfo * nsDocLoaderImpl::GetRequestInfo(nsIRequest *aRequest)
|
2000-06-19 09:54:37 +04:00
|
|
|
{
|
2001-03-29 04:12:49 +04:00
|
|
|
nsRequestInfo *info;
|
2000-06-19 09:54:37 +04:00
|
|
|
PRInt32 i, count;
|
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
count = mRequestInfoList.Count();
|
2000-06-19 09:54:37 +04:00
|
|
|
for(i=0; i<count; i++) {
|
2001-03-29 04:12:49 +04:00
|
|
|
info = (nsRequestInfo *)mRequestInfoList.ElementAt(i);
|
|
|
|
if (aRequest == info->mKey) {
|
2000-06-19 09:54:37 +04:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
nsresult nsDocLoaderImpl::ClearRequestInfoList(void)
|
2000-06-19 09:54:37 +04:00
|
|
|
{
|
2001-03-29 04:12:49 +04:00
|
|
|
nsRequestInfo *info;
|
2000-06-19 09:54:37 +04:00
|
|
|
PRInt32 i, count;
|
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
count = mRequestInfoList.Count();
|
2000-06-19 09:54:37 +04:00
|
|
|
for(i=0; i<count; i++) {
|
2001-03-29 04:12:49 +04:00
|
|
|
info = (nsRequestInfo *)mRequestInfoList.ElementAt(i);
|
2000-06-19 09:54:37 +04:00
|
|
|
delete info;
|
|
|
|
}
|
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
mRequestInfoList.Clear();
|
|
|
|
mRequestInfoList.Compact();
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDocLoaderImpl::CalculateMaxProgress(PRInt32 *aMax)
|
|
|
|
{
|
|
|
|
PRInt32 i, count;
|
|
|
|
PRInt32 current=0, max=0;
|
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
count = mRequestInfoList.Count();
|
2000-06-19 09:54:37 +04:00
|
|
|
for(i=0; i<count; i++) {
|
2001-03-29 04:12:49 +04:00
|
|
|
nsRequestInfo *info;
|
2000-06-19 09:54:37 +04:00
|
|
|
|
2001-03-29 04:12:49 +04:00
|
|
|
info = (nsRequestInfo *)mRequestInfoList.ElementAt(i);
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
current += info->mCurrentProgress;
|
|
|
|
if (max >= 0) {
|
|
|
|
if (info->mMaxProgress < info->mCurrentProgress) {
|
|
|
|
max = -1;
|
|
|
|
} else {
|
|
|
|
max += info->mMaxProgress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aMax = max;
|
|
|
|
}
|
|
|
|
|
2001-05-12 01:05:08 +04:00
|
|
|
NS_IMETHODIMP nsDocLoaderImpl::OnRedirect(nsIHttpChannel *aOldChannel, nsIChannel *aNewChannel)
|
2000-08-25 05:32:40 +04:00
|
|
|
{
|
2001-04-28 01:05:52 +04:00
|
|
|
if (aOldChannel)
|
|
|
|
{
|
2001-05-12 01:05:08 +04: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;
|
|
|
|
|
|
|
|
// verify that this is a legal redirect
|
2001-07-25 11:54:28 +04:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager =
|
|
|
|
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
2001-05-12 01:05:08 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = securityManager->CheckLoadURI(oldURI, newURI,
|
|
|
|
nsIScriptSecurityManager::DISALLOW_FROM_MAIL);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-04-28 01:05:52 +04: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 05:32:40 +04:00
|
|
|
}
|
|
|
|
|
2000-09-15 02:56:56 +04:00
|
|
|
NS_IMETHODIMP nsDocLoaderImpl::OnSecurityChange(nsISupports * aContext,
|
|
|
|
PRInt32 state)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Fire progress notifications out to any registered nsIWebProgressListeners.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRequest> request = do_QueryInterface(aContext);
|
|
|
|
nsIWebProgress* webProgress = NS_STATIC_CAST(nsIWebProgress*, this);
|
|
|
|
|
2001-02-01 00:02:08 +03:00
|
|
|
PRUint32 count;
|
|
|
|
(void)mListenerList->Count(&count);
|
2000-09-15 02:56:56 +04:00
|
|
|
|
2001-02-01 00:02:08 +03:00
|
|
|
while (count > 0) {
|
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
nsresult rv = mListenerList->GetElementAt(--count, getter_AddRefs(supports));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsWeakPtr weakPtr = do_QueryInterface(supports);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebProgressListener> listener;
|
|
|
|
listener = do_QueryReferent(weakPtr);
|
|
|
|
if (!listener) {
|
|
|
|
// the listener went away. gracefully pull it out of the list.
|
|
|
|
mListenerList->RemoveElementAt(count);
|
|
|
|
continue;
|
2000-09-15 02:56:56 +04:00
|
|
|
}
|
|
|
|
listener->OnSecurityChange(webProgress, request, state);
|
|
|
|
}
|
|
|
|
|
2001-02-01 00:02:08 +03:00
|
|
|
mListenerList->Compact();
|
|
|
|
|
2000-09-15 02:56:56 +04:00
|
|
|
// Pass the notification up to the parent...
|
|
|
|
if (mParent) {
|
|
|
|
mParent->OnSecurityChange(aContext, state);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-19 09:54:37 +04:00
|
|
|
#if 0
|
|
|
|
void nsDocLoaderImpl::DumpChannelInfo()
|
|
|
|
{
|
|
|
|
nsChannelInfo *info;
|
|
|
|
PRInt32 i, count;
|
|
|
|
PRInt32 current=0, max=0;
|
|
|
|
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("==== DocLoader=%x\n", this);
|
2000-06-19 09:54:37 +04:00
|
|
|
|
|
|
|
count = mChannelInfoList.Count();
|
|
|
|
for(i=0; i<count; i++) {
|
|
|
|
info = (nsChannelInfo *)mChannelInfoList.ElementAt(i);
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCAutoString buffer;
|
2000-06-19 09:54:37 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (info->mURI) {
|
2002-03-21 01:50:33 +03:00
|
|
|
rv = info->mURI->GetSpec(buffer);
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" [%d] current=%d max=%d [%s]\n", i,
|
2000-06-19 09:54:37 +04:00
|
|
|
info->mCurrentProgress,
|
2002-03-21 01:50:33 +03:00
|
|
|
info->mMaxProgress, buffer.get());
|
2000-06-19 09:54:37 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
current += info->mCurrentProgress;
|
|
|
|
if (max >= 0) {
|
|
|
|
if (info->mMaxProgress < info->mCurrentProgress) {
|
|
|
|
max = -1;
|
|
|
|
} else {
|
|
|
|
max += info->mMaxProgress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("\nCurrent=%d Total=%d\n====\n", current, max);
|
2000-06-19 09:54:37 +04:00
|
|
|
}
|
2000-06-19 17:03:52 +04:00
|
|
|
#endif /* 0 */
|
|
|
|
|