1998-07-19 01:50:29 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
1998-07-01 15:29:20 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03: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
|
|
|
*
|
1999-11-06 06:43:54 +03: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.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 06:43:54 +03:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-07-01 15:29:20 +04:00
|
|
|
*/
|
2000-01-29 07:41:04 +03:00
|
|
|
|
1999-12-29 10:32:59 +03:00
|
|
|
#include "nspr.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
|
1998-08-12 08:56:40 +04:00
|
|
|
#include "nsIDocumentLoaderObserver.h"
|
2000-01-29 07:41:04 +03:00
|
|
|
#include "nsDocLoader.h"
|
|
|
|
#include "nsCURILoader.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
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"
|
|
|
|
#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"
|
1998-07-01 15:29:20 +04:00
|
|
|
|
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"
|
1999-01-12 22:41:06 +03:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
//
|
|
|
|
// Log module for nsIDocumentLoader logging...
|
|
|
|
//
|
|
|
|
// To enable logging (see prlog.h for full details):
|
|
|
|
//
|
|
|
|
// set NSPR_LOG_MODULES=DocLoader:5
|
|
|
|
// set NSPR_LOG_FILE=nspr.log
|
|
|
|
//
|
|
|
|
// this enables PR_LOG_DEBUG level information and places all output in
|
|
|
|
// the file nspr.log
|
|
|
|
//
|
1998-10-02 01:48:12 +04:00
|
|
|
PRLogModuleInfo* gDocLoaderLog = nsnull;
|
1999-11-22 08:46:03 +03:00
|
|
|
#endif /* PR_LOGGING */
|
1998-07-22 15:23:32 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* Define IIDs... */
|
1999-05-06 23:31:59 +04:00
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
2000-01-29 07:41:04 +03:00
|
|
|
static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID);
|
1999-05-06 23:31:59 +04:00
|
|
|
static NS_DEFINE_IID(kIContentViewerContainerIID, NS_ICONTENT_VIEWER_CONTAINER_IID);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
|
1998-09-12 23:30:49 +04:00
|
|
|
nsDocLoaderImpl::nsDocLoaderImpl()
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
#if defined(PR_LOGGING)
|
1998-10-02 01:48:12 +04:00
|
|
|
if (nsnull == gDocLoaderLog) {
|
1999-05-06 23:31:59 +04:00
|
|
|
gDocLoaderLog = PR_NewLogModule("DocLoader");
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
1999-11-22 08:46:03 +03:00
|
|
|
#endif /* PR_LOGGING */
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
mContainer = nsnull;
|
|
|
|
mParent = nsnull;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1998-12-29 07:45:00 +03:00
|
|
|
mIsLoadingDocument = PR_FALSE;
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-04-30 04:10:27 +04:00
|
|
|
("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;
|
|
|
|
|
1999-11-30 07:50:42 +03:00
|
|
|
rv = NS_NewLoadGroup(this, getter_AddRefs(mLoadGroup));
|
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-12-28 12:16:15 +03:00
|
|
|
/// rv = mLoadGroup->SetGroupListenerFactory(this);
|
|
|
|
/// if (NS_FAILED(rv)) return rv;
|
1999-08-27 02:45:55 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(mChildList));
|
2000-01-29 07:41:04 +03:00
|
|
|
|
|
|
|
return rv;
|
1999-06-28 14:35:57 +04:00
|
|
|
}
|
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]
|
|
|
|
*/
|
|
|
|
ClearWeakReferences();
|
|
|
|
|
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
|
|
|
#ifdef DEBUG
|
|
|
|
PRUint32 count=0;
|
|
|
|
mChildList->Count(&count);
|
|
|
|
NS_PRECONDITION((0 == count), "Document loader has children...");
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
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...
|
|
|
|
*/
|
1998-07-22 15:23:32 +04:00
|
|
|
NS_IMPL_ADDREF(nsDocLoaderImpl);
|
|
|
|
NS_IMPL_RELEASE(nsDocLoaderImpl);
|
|
|
|
|
2000-01-29 07:41:04 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDocLoaderImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStreamObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocumentLoader)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_END
|
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
|
|
|
|
1999-07-01 23:30:20 +04:00
|
|
|
rv = mLoadGroup->Cancel();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not hold refs to the objects in the observer lists. Observers
|
|
|
|
* are expected to remove themselves upon their destruction if they
|
|
|
|
* have not removed themselves previously
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::AddObserver(nsIDocumentLoaderObserver* aObserver)
|
|
|
|
{
|
1999-11-22 08:46:03 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
1998-10-09 09:49:34 +04:00
|
|
|
if (mDocObservers.IndexOf(aObserver) == -1) {
|
1999-11-22 08:46:03 +03:00
|
|
|
//
|
|
|
|
// XXX this method incorrectly returns a bool
|
|
|
|
//
|
|
|
|
rv = mDocObservers.AppendElement(aObserver) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
} else {
|
|
|
|
// The observer is already in the list...
|
|
|
|
rv = NS_ERROR_FAILURE;
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
1999-11-22 08:46:03 +03:00
|
|
|
return rv;
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::RemoveObserver(nsIDocumentLoaderObserver* aObserver)
|
|
|
|
{
|
1998-10-09 09:49:34 +04:00
|
|
|
if (PR_TRUE == mDocObservers.RemoveElement(aObserver)) {
|
1998-07-22 15:23:32 +04:00
|
|
|
return NS_OK;
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
nsDocLoaderImpl::GetContentViewerContainer(PRUint32 aDocumentID,
|
|
|
|
nsIContentViewerContainer** aResult)
|
|
|
|
{
|
1999-05-06 07:54:40 +04:00
|
|
|
nsISupports* base = (nsISupports*) aDocumentID;
|
|
|
|
nsIDocument* doc;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = base->QueryInterface(kIDocumentIID, (void**)&doc);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsIPresShell* pres;
|
|
|
|
pres = doc->GetShellAt(0);
|
|
|
|
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(pres);
|
|
|
|
}
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
Stop();
|
1999-09-17 11:56:03 +04:00
|
|
|
|
|
|
|
// Remove the document loader from the parent list of loaders...
|
|
|
|
if (mParent) {
|
1999-09-17 08:26:02 +04:00
|
|
|
mParent->RemoveChildGroup(this);
|
1999-11-22 08:46:03 +03:00
|
|
|
mParent = nsnull;
|
1999-09-17 08:26:02 +04:00
|
|
|
}
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
mDocumentChannel = null_nsCOMPtr();
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
// Clear factory pointer (which is the docloader)
|
|
|
|
(void)mLoadGroup->SetGroupListenerFactory(nsnull);
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-10-19 23:42:55 +04:00
|
|
|
mLoadGroup->SetGroupObserver(nsnull);
|
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
return NS_OK;
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
NS_IMETHODIMP
|
1999-11-22 08:46:03 +03:00
|
|
|
nsDocLoaderImpl::OnStartRequest(nsIChannel *aChannel, nsISupports *aCtxt)
|
1999-07-16 15:14:36 +04:00
|
|
|
{
|
1999-11-22 08:46:03 +03:00
|
|
|
// called each time a channel is added to the group.
|
1999-07-16 15:14:36 +04:00
|
|
|
nsresult rv;
|
1999-08-27 02:45:55 +04:00
|
|
|
|
2000-01-15 09:12:54 +03:00
|
|
|
if (!mIsLoadingDocument) {
|
|
|
|
PRUint32 loadAttribs = 0;
|
|
|
|
|
|
|
|
aChannel->GetLoadAttributes(&loadAttribs);
|
|
|
|
if (loadAttribs & nsIChannel::LOAD_DOCUMENT_URI) {
|
|
|
|
mIsLoadingDocument = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
//
|
|
|
|
// Only fire an OnStartDocumentLoad(...) if the document loader
|
|
|
|
// has initiated a load... Otherwise, this notification has
|
|
|
|
// resulted from a channel being added to the load group.
|
|
|
|
//
|
|
|
|
if (mIsLoadingDocument) {
|
1999-11-22 08:46:03 +03:00
|
|
|
PRUint32 count;
|
|
|
|
|
|
|
|
rv = mLoadGroup->GetActiveCount(&count);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (1 == count) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
rv = aChannel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// This channel is associated with the entire document...
|
|
|
|
mDocumentChannel = aChannel;
|
1999-12-18 08:16:18 +03:00
|
|
|
mLoadGroup->SetDefaultLoadChannel(mDocumentChannel);
|
1999-11-22 08:46:03 +03:00
|
|
|
FireOnStartDocumentLoad(this, uri);
|
|
|
|
}
|
|
|
|
else {
|
1999-12-29 10:32:59 +03:00
|
|
|
FireOnStartURLLoad(this, aChannel);
|
1999-11-22 08:46:03 +03:00
|
|
|
}
|
1999-08-27 02:45:55 +04:00
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-22 08:46:03 +03:00
|
|
|
nsDocLoaderImpl::OnStopRequest(nsIChannel *aChannel,
|
|
|
|
nsISupports *aCtxt,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar *aMsg)
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
//
|
1999-11-22 08:46:03 +03:00
|
|
|
if (0 == count) {
|
|
|
|
DocLoaderIsEmpty(aStatus);
|
|
|
|
} else {
|
|
|
|
FireOnEndURLLoad(this, aChannel, aStatus);
|
|
|
|
}
|
1999-09-23 02:58:29 +04:00
|
|
|
}
|
1999-09-21 09:36:49 +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;
|
|
|
|
}
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
void nsDocLoaderImpl::DocLoaderIsEmpty(nsresult aStatus)
|
|
|
|
{
|
1999-12-18 08:16:18 +03:00
|
|
|
if (mParent) {
|
|
|
|
mParent->DocLoaderIsEmpty(aStatus);
|
|
|
|
//
|
|
|
|
// New code to break the circular reference between
|
|
|
|
// the load group and the docloader...
|
|
|
|
//
|
|
|
|
mLoadGroup->SetDefaultLoadChannel(nsnull);
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> docChannel(mDocumentChannel);
|
|
|
|
|
|
|
|
mDocumentChannel = null_nsCOMPtr();
|
|
|
|
mIsLoadingDocument = PR_FALSE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Do nothing after firing the OnEndDocumentLoad(...). The document
|
|
|
|
// loader may be loading a *new* document - if LoadDocument()
|
|
|
|
// was called from a handler!
|
|
|
|
//
|
|
|
|
FireOnEndDocumentLoad(this, docChannel, aStatus);
|
|
|
|
|
|
|
|
if (mParent) {
|
|
|
|
mParent->DocLoaderIsEmpty(aStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void nsDocLoaderImpl::FireOnStartDocumentLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-11-22 08:46:03 +03:00
|
|
|
nsIURI* aURL)
|
1999-03-29 13:21:01 +04:00
|
|
|
{
|
1999-11-22 08:46:03 +03:00
|
|
|
PRInt32 count;
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
#if defined(DEBUG)
|
|
|
|
char *buffer;
|
|
|
|
|
|
|
|
aURL->GetSpec(&buffer);
|
1999-11-22 08:46:03 +03:00
|
|
|
if (aLoadInitiator == this) {
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStartDocumentLoad(...).\tURI: %s\n",
|
|
|
|
this, buffer));
|
|
|
|
} else {
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: -- Propagating OnStartDocumentLoad(...)."
|
|
|
|
"DocLoader:%p URI:%s\n",
|
|
|
|
this, aLoadInitiator, buffer));
|
|
|
|
}
|
1999-08-27 02:45:55 +04:00
|
|
|
nsCRT::free(buffer);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
/*
|
1999-11-22 08:46:03 +03:00
|
|
|
* First notify any observers that the document load has begun...
|
|
|
|
*
|
|
|
|
* Operate the elements from back to front so that if items get
|
|
|
|
* get removed from the list it won't affect our iteration
|
1999-03-29 13:21:01 +04:00
|
|
|
*/
|
1999-11-22 08:46:03 +03:00
|
|
|
count = mDocObservers.Count();
|
|
|
|
while (count > 0) {
|
|
|
|
nsIDocumentLoaderObserver *observer;
|
|
|
|
|
|
|
|
observer = NS_STATIC_CAST(nsIDocumentLoaderObserver*, mDocObservers.ElementAt(--count));
|
|
|
|
|
|
|
|
NS_ASSERTION(observer, "NULL observer found in list.");
|
|
|
|
if (! observer) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
observer->OnStartDocumentLoad(aLoadInitiator, aURL, mCommand);
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally notify the parent...
|
|
|
|
*/
|
1999-09-17 11:56:03 +04:00
|
|
|
if (mParent) {
|
1999-11-22 08:46:03 +03:00
|
|
|
mParent->FireOnStartDocumentLoad(aLoadInitiator, aURL);
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void nsDocLoaderImpl::FireOnEndDocumentLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-09-23 02:58:29 +04:00
|
|
|
nsIChannel *aDocChannel,
|
1999-08-05 05:28:30 +04:00
|
|
|
nsresult aStatus)
|
1999-06-15 02:12:19 +04:00
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
{
|
1999-07-31 10:33:50 +04:00
|
|
|
#if defined(DEBUG)
|
1999-11-22 08:46:03 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (aDocChannel)
|
|
|
|
rv = aDocChannel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
char* buffer = nsnull;
|
|
|
|
if (uri)
|
|
|
|
rv = uri->GetSpec(&buffer);
|
|
|
|
if (NS_SUCCEEDED(rv) && buffer != nsnull) {
|
|
|
|
if (aLoadInitiator == this) {
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnEndDocumentLoad(...)"
|
|
|
|
"\tURI: %s Status: %x\n",
|
|
|
|
this, buffer, aStatus));
|
|
|
|
} else {
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: -- Propagating OnEndDocumentLoad(...)."
|
|
|
|
"DocLoader:%p URI:%s\n",
|
|
|
|
this, aLoadInitiator, buffer));
|
1999-07-31 10:33:50 +04:00
|
|
|
}
|
1999-11-22 08:46:03 +03:00
|
|
|
nsCRT::free(buffer);
|
|
|
|
}
|
1999-07-31 10:33:50 +04:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
/*
|
|
|
|
* First notify any observers that the document load has finished...
|
|
|
|
*
|
|
|
|
* Operate the elements from back to front so that if items get
|
|
|
|
* get removed from the list it won't affect our iteration
|
|
|
|
*/
|
|
|
|
PRInt32 count;
|
|
|
|
|
|
|
|
count = mDocObservers.Count();
|
|
|
|
while (count > 0) {
|
|
|
|
nsIDocumentLoaderObserver *observer;
|
|
|
|
|
|
|
|
observer = NS_STATIC_CAST(nsIDocumentLoaderObserver*, mDocObservers.ElementAt(--count));
|
|
|
|
|
|
|
|
NS_ASSERTION(observer, "NULL observer found in list.");
|
|
|
|
if (! observer) {
|
|
|
|
continue;
|
1999-08-27 02:45:55 +04:00
|
|
|
}
|
1999-11-22 08:46:03 +03:00
|
|
|
|
1999-12-29 10:32:59 +03:00
|
|
|
observer->OnEndDocumentLoad(aLoadInitiator, aDocChannel, aStatus);
|
1999-11-22 08:46:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Next notify the parent...
|
|
|
|
*/
|
|
|
|
if (mParent) {
|
|
|
|
mParent->FireOnEndDocumentLoad(aLoadInitiator, aDocChannel, aStatus);
|
|
|
|
}
|
1999-04-30 04:10:27 +04:00
|
|
|
}
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void nsDocLoaderImpl::FireOnStartURLLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-12-29 10:32:59 +03:00
|
|
|
nsIChannel* aChannel)
|
1999-01-14 09:44:23 +03:00
|
|
|
{
|
1999-11-22 08:46:03 +03:00
|
|
|
#if defined(DEBUG)
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (aChannel)
|
|
|
|
rv = aChannel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
char* buffer = nsnull;
|
|
|
|
if (uri)
|
|
|
|
rv = uri->GetSpec(&buffer);
|
|
|
|
if (NS_SUCCEEDED(rv) && buffer != nsnull) {
|
|
|
|
if (aLoadInitiator == this) {
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnStartURLLoad(...)"
|
1999-12-29 10:32:59 +03:00
|
|
|
"\tURI: %s\n",
|
|
|
|
this, buffer));
|
1999-11-22 08:46:03 +03:00
|
|
|
} else {
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: -- Propagating OnStartURLLoad(...)."
|
|
|
|
"DocLoader:%p URI:%s\n",
|
|
|
|
this, aLoadInitiator, buffer));
|
|
|
|
}
|
|
|
|
nsCRT::free(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
PRInt32 count;
|
1999-01-14 09:44:23 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First notify any observers that the URL load has begun...
|
1999-11-22 08:46:03 +03:00
|
|
|
*
|
|
|
|
* Operate the elements from back to front so that if items get
|
|
|
|
* get removed from the list it won't affect our iteration
|
1999-01-14 09:44:23 +03:00
|
|
|
*/
|
1999-11-22 08:46:03 +03:00
|
|
|
count = mDocObservers.Count();
|
|
|
|
while (count > 0) {
|
|
|
|
nsIDocumentLoaderObserver *observer;
|
|
|
|
|
|
|
|
observer = NS_STATIC_CAST(nsIDocumentLoaderObserver*, mDocObservers.ElementAt(--count));
|
|
|
|
|
|
|
|
NS_ASSERTION(observer, "NULL observer found in list.");
|
|
|
|
if (! observer) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-12-29 10:32:59 +03:00
|
|
|
observer->OnStartURLLoad(aLoadInitiator, aChannel);
|
1999-01-14 09:44:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally notify the parent...
|
|
|
|
*/
|
1999-09-17 11:56:03 +04:00
|
|
|
if (mParent) {
|
1999-12-29 10:32:59 +03:00
|
|
|
mParent->FireOnStartURLLoad(aLoadInitiator, aChannel);
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void nsDocLoaderImpl::FireOnEndURLLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-11-22 08:46:03 +03:00
|
|
|
nsIChannel* aChannel, nsresult aStatus)
|
1999-03-29 13:21:01 +04:00
|
|
|
{
|
1999-11-22 08:46:03 +03:00
|
|
|
#if defined(DEBUG)
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (aChannel)
|
|
|
|
rv = aChannel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
char* buffer = nsnull;
|
|
|
|
if (uri)
|
|
|
|
rv = uri->GetSpec(&buffer);
|
|
|
|
if (NS_SUCCEEDED(rv) && buffer != nsnull) {
|
|
|
|
if (aLoadInitiator == this) {
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: ++ Firing OnEndURLLoad(...)"
|
|
|
|
"\tURI: %s Status: %x\n",
|
|
|
|
this, buffer, aStatus));
|
|
|
|
} else {
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: -- Propagating OnEndURLLoad(...)."
|
|
|
|
"DocLoader:%p URI:%s\n",
|
|
|
|
this, aLoadInitiator, buffer));
|
|
|
|
}
|
|
|
|
nsCRT::free(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
PRInt32 count;
|
1999-03-29 13:21:01 +04:00
|
|
|
|
|
|
|
/*
|
1999-11-22 08:46:03 +03:00
|
|
|
* First notify any observers that the URL load has completed...
|
|
|
|
*
|
|
|
|
* Operate the elements from back to front so that if items get
|
|
|
|
* get removed from the list it won't affect our iteration
|
1999-03-29 13:21:01 +04:00
|
|
|
*/
|
1999-11-22 08:46:03 +03:00
|
|
|
count = mDocObservers.Count();
|
|
|
|
while (count > 0) {
|
|
|
|
nsIDocumentLoaderObserver *observer;
|
|
|
|
|
|
|
|
observer = NS_STATIC_CAST(nsIDocumentLoaderObserver*, mDocObservers.ElementAt(--count));
|
|
|
|
|
|
|
|
NS_ASSERTION(observer, "NULL observer found in list.");
|
|
|
|
if (! observer) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
observer->OnEndURLLoad(aLoadInitiator, aChannel, aStatus);
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally notify the parent...
|
|
|
|
*/
|
1999-09-17 11:56:03 +04:00
|
|
|
if (mParent) {
|
1999-11-22 08:46:03 +03:00
|
|
|
mParent->FireOnEndURLLoad(aLoadInitiator, aChannel, aStatus);
|
1999-01-14 09:44:23 +03:00
|
|
|
}
|
|
|
|
}
|