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
|
|
|
*/
|
1998-07-30 01:06:19 +04:00
|
|
|
#include "nsIDocumentLoader.h"
|
1999-08-27 02:45:55 +04:00
|
|
|
#include "nsIWebShell.h"
|
1998-07-01 15:29:20 +04:00
|
|
|
#include "prmem.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIFactory.h"
|
1998-07-19 01:50:29 +04:00
|
|
|
#include "nsIContentViewerContainer.h"
|
1999-05-06 23:31:59 +04:00
|
|
|
#include "nsIContentViewer.h"
|
1998-08-14 00:08:19 +04:00
|
|
|
#include "nsITimer.h"
|
1998-08-12 08:56:40 +04:00
|
|
|
#include "nsIDocumentLoaderObserver.h"
|
|
|
|
#include "nsVoidArray.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
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#include "nsILoadGroup.h"
|
1999-11-22 08:46:03 +03:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#include "nsNeckoUtil.h"
|
1999-06-23 07:29:44 +04:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIChannel.h"
|
1999-08-04 19:06:51 +04:00
|
|
|
#include "nsIHTTPChannel.h"
|
|
|
|
#include "nsHTTPEnums.h"
|
1999-11-22 08:46:03 +03:00
|
|
|
#include "nsIDNSService.h"
|
1999-06-28 14:35:57 +04:00
|
|
|
#include "nsIProgressEventSink.h"
|
1999-09-17 11:56:03 +04:00
|
|
|
|
1999-05-26 05:38:36 +04:00
|
|
|
#include "nsIGenericFactory.h"
|
1999-05-06 23:31:59 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-05-26 05:38:36 +04:00
|
|
|
#include "nsCom.h"
|
1999-06-28 14:35:57 +04:00
|
|
|
#include "prlog.h"
|
|
|
|
#include "prprf.h"
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-09-10 03:53:55 +04:00
|
|
|
#include "nsWeakReference.h"
|
|
|
|
|
1999-08-29 18:31:08 +04:00
|
|
|
#include "nsIStreamConverterService.h"
|
|
|
|
#include "nsIStreamConverter.h"
|
|
|
|
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
|
|
|
|
|
1999-07-17 05:58:38 +04:00
|
|
|
#include <iostream.h>
|
|
|
|
|
1999-11-18 10:07:33 +03:00
|
|
|
#include "nsIPref.h"
|
|
|
|
#include "nsIURIContentListener.h"
|
|
|
|
#include "nsIURILoader.h"
|
|
|
|
#include "nsCURILoader.h"
|
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
// XXX ick ick ick
|
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(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDocumentLoaderFactoryIID, NS_IDOCUMENTLOADERFACTORY_IID);
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
1999-09-17 11:56:03 +04:00
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
static NS_DEFINE_IID(kIContentViewerContainerIID, NS_ICONTENT_VIEWER_CONTAINER_IID);
|
1999-05-26 05:38:36 +04:00
|
|
|
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
/* Forward declarations.... */
|
|
|
|
class nsDocLoaderImpl;
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
|
|
|
|
class nsChannelListener : public nsIStreamListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsChannelListener();
|
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
nsresult Init(nsIStreamListener *aListener);
|
1999-08-27 02:45:55 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
1999-09-16 05:16:22 +04:00
|
|
|
NS_DECL_NSISTREAMOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
1999-08-27 02:45:55 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsChannelListener();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStreamListener> mNextListener;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
/*
|
|
|
|
* The nsDocumentBindInfo contains the state required when a single document
|
|
|
|
* is being loaded... Each instance remains alive until its target URL has
|
|
|
|
* been loaded (or aborted).
|
|
|
|
*
|
|
|
|
* The Document Loader maintains a list of nsDocumentBindInfo instances which
|
|
|
|
* represents the set of documents actively being loaded...
|
|
|
|
*/
|
1999-06-28 14:35:57 +04:00
|
|
|
class nsDocumentBindInfo : public nsIStreamListener
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
public:
|
1998-09-15 04:17:53 +04:00
|
|
|
nsDocumentBindInfo();
|
|
|
|
|
|
|
|
nsresult Init(nsDocLoaderImpl* aDocLoader,
|
|
|
|
const char *aCommand,
|
1999-11-15 10:29:23 +03:00
|
|
|
nsISupports* aContainer,
|
1999-10-05 08:04:16 +04:00
|
|
|
nsISupports* aExtraInfo);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
nsresult Bind(nsIURI *aURL,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsIInputStream *postDataStream,
|
|
|
|
const PRUnichar* aReferrer=nsnull);
|
1999-08-27 02:45:55 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
// nsIStreamObserver methods:
|
1999-08-22 17:26:18 +04:00
|
|
|
NS_DECL_NSISTREAMOBSERVER
|
1999-09-17 11:56:03 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
// nsIStreamListener methods:
|
1999-08-22 17:26:18 +04:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
1999-06-28 14:35:57 +04:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsDocumentBindInfo();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
char* m_Command;
|
1999-11-15 10:29:23 +03:00
|
|
|
nsCOMPtr<nsISupports> m_Container;
|
|
|
|
nsCOMPtr<nsISupports> m_ExtraInfo;
|
|
|
|
nsCOMPtr<nsIStreamListener> m_NextStream;
|
1998-07-01 15:29:20 +04:00
|
|
|
nsDocLoaderImpl* m_DocLoader;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* nsDocLoaderImpl implementation...
|
|
|
|
****************************************************************************/
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
class nsDocLoaderImpl : public nsIDocumentLoader,
|
|
|
|
public nsIStreamObserver,
|
1999-09-10 03:53:55 +04:00
|
|
|
public nsILoadGroupListenerFactory,
|
|
|
|
public nsSupportsWeakReference
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
1998-09-12 23:30:49 +04:00
|
|
|
nsDocLoaderImpl();
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
nsresult Init(nsDocLoaderImpl* aParent);
|
1999-06-28 14:35:57 +04:00
|
|
|
|
1999-05-26 05:38:36 +04:00
|
|
|
// for nsIGenericFactory:
|
|
|
|
static NS_IMETHODIMP Create(nsISupports *aOuter, const nsIID &aIID, void **aResult);
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1999-11-18 10:07:33 +03:00
|
|
|
NS_IMETHOD LoadOpenedDocument(nsIChannel * aOpenedChannel,
|
|
|
|
const char * aCommand,
|
|
|
|
nsIContentViewerContainer *aContainer,
|
|
|
|
nsIInputStream * aPostDataStream,
|
|
|
|
nsIURI * aReffererUrl,
|
|
|
|
nsIStreamListener ** aContentHandler);
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
// nsIDocumentLoader interface
|
1999-09-08 07:58:57 +04:00
|
|
|
NS_IMETHOD LoadDocument(nsIURI * aUri,
|
1998-10-09 09:49:34 +04:00
|
|
|
const char *aCommand,
|
1999-11-15 10:29:23 +03:00
|
|
|
nsISupports* aContainer,
|
1999-08-04 00:51:41 +04:00
|
|
|
nsIInputStream* aPostDataStream = nsnull,
|
1998-10-09 09:49:34 +04:00
|
|
|
nsISupports* aExtraInfo = nsnull,
|
1999-07-01 23:30:20 +04:00
|
|
|
nsLoadFlags aType = nsIChannel::LOAD_NORMAL,
|
1999-09-17 08:26:02 +04:00
|
|
|
const PRUint32 aLocalIP = 0,
|
|
|
|
const PRUnichar* aReferrer = nsnull);
|
1998-07-22 15:23:32 +04:00
|
|
|
|
|
|
|
NS_IMETHOD Stop(void);
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
NS_IMETHOD IsBusy(PRBool& aResult);
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
NS_IMETHOD CreateDocumentLoader(nsIDocumentLoader** anInstance);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-08-12 08:56:40 +04:00
|
|
|
NS_IMETHOD AddObserver(nsIDocumentLoaderObserver *aObserver);
|
|
|
|
NS_IMETHOD RemoveObserver(nsIDocumentLoaderObserver *aObserver);
|
|
|
|
|
1999-11-15 10:29:23 +03:00
|
|
|
NS_IMETHOD SetContainer(nsISupports* aContainer);
|
|
|
|
NS_IMETHOD GetContainer(nsISupports** aResult);
|
1999-11-22 08:46:03 +03:00
|
|
|
|
|
|
|
// XXX: this method is evil and should be removed.
|
1999-05-06 05:58:48 +04:00
|
|
|
NS_IMETHOD GetContentViewerContainer(PRUint32 aDocumentID,
|
|
|
|
nsIContentViewerContainer** aResult);
|
1999-11-22 08:46:03 +03:00
|
|
|
|
1999-10-27 08:44:42 +04:00
|
|
|
NS_IMETHOD GetLoadGroup(nsILoadGroup** aResult);
|
|
|
|
|
1999-09-10 03:53:55 +04:00
|
|
|
NS_IMETHOD Destroy();
|
1999-01-14 09:44:23 +03:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
// nsILoadGroupListenerFactory methods...
|
|
|
|
NS_IMETHOD CreateLoadGroupListener(nsIStreamListener *aListener,
|
|
|
|
nsIStreamListener **aResult);
|
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
// nsIStreamObserver methods: (for observing the load group)
|
|
|
|
NS_DECL_NSISTREAMOBSERVER
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
// Implementation specific methods...
|
1999-11-22 08:46:03 +03:00
|
|
|
nsresult CreateContentViewer(const char *aCommand,
|
|
|
|
nsIChannel* channel,
|
|
|
|
const char* aContentType,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsDocLoaderImpl();
|
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
nsresult RemoveChildGroup(nsDocLoaderImpl *aLoader);
|
1999-11-22 08:46:03 +03:00
|
|
|
void DocLoaderIsEmpty(nsresult aStatus);
|
1999-09-17 11:56:03 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void FireOnStartDocumentLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-11-22 08:46:03 +03:00
|
|
|
nsIURI* aURL);
|
1999-10-07 01:43:21 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void 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-08-27 02:45:55 +04:00
|
|
|
void FireOnStartURLLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-06-28 14:35:57 +04:00
|
|
|
nsIChannel* channel,
|
1999-03-29 13:21:01 +04:00
|
|
|
nsIContentViewer* aViewer);
|
1999-10-07 01:43:21 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void FireOnEndURLLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-08-05 05:28:30 +04:00
|
|
|
nsIChannel* channel, nsresult aStatus);
|
1999-04-30 04:10:27 +04:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
protected:
|
1999-04-30 13:04:36 +04:00
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
// IMPORTANT: The ownership implicit in the following member
|
|
|
|
// variables has been explicitly checked and set using nsCOMPtr
|
|
|
|
// for owning pointers and raw COM interface pointers for weak
|
|
|
|
// (ie, non owning) references. If you add any members to this
|
1999-04-30 13:04:36 +04:00
|
|
|
// class, please make the ownership explicit (pinkerton, scc).
|
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
nsCOMPtr<nsIChannel> mDocumentChannel; // [OWNER] ???compare with document
|
1999-07-16 15:14:36 +04:00
|
|
|
nsVoidArray mDocObservers;
|
1999-11-22 08:46:03 +03:00
|
|
|
nsISupports* mContainer; // [WEAK] it owns me!
|
|
|
|
|
|
|
|
nsDocLoaderImpl* mParent; // [WEAK]
|
|
|
|
|
|
|
|
nsCString mCommand;
|
1999-07-16 15:14:36 +04:00
|
|
|
|
1998-12-29 07:45:00 +03:00
|
|
|
/*
|
|
|
|
* This flag indicates that the loader is loading a document. It is set
|
|
|
|
* from the call to LoadDocument(...) until the OnConnectionsComplete(...)
|
|
|
|
* notification is fired...
|
|
|
|
*/
|
1999-01-14 09:44:23 +03:00
|
|
|
PRBool mIsLoadingDocument;
|
1999-06-28 14:35:57 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
1999-09-17 11:56:03 +04:00
|
|
|
nsCOMPtr<nsISupportsArray> mChildList;
|
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
|
1999-11-22 08:46:03 +03:00
|
|
|
nsDocLoaderImpl::Init(nsDocLoaderImpl *aParent)
|
1999-06-28 14:35:57 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
rv = NS_NewLoadGroup(nsnull, 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-09-17 11:56:03 +04:00
|
|
|
rv = mLoadGroup->SetGroupListenerFactory(this);
|
1999-08-27 02:45:55 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(mChildList));
|
1999-11-22 08:46:03 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
mParent = aParent;
|
|
|
|
return NS_OK;
|
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);
|
|
|
|
|
1999-09-17 08:26:02 +04:00
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
1999-05-06 23:31:59 +04:00
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDocumentLoaderIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDocumentLoader*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-27 02:45:55 +04:00
|
|
|
if (aIID.Equals(nsCOMTypeInfo<nsILoadGroupListenerFactory>::GetIID())) {
|
|
|
|
*aInstancePtr = (void*)(nsILoadGroupListenerFactory*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
if (aIID.Equals(kIStreamObserverIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIStreamObserver*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-10 03:53:55 +04:00
|
|
|
if (aIID.Equals(nsCOMTypeInfo<nsISupportsWeakReference>::GetIID())) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsISupportsWeakReference*,this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-06 23:31:59 +04:00
|
|
|
return NS_NOINTERFACE;
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::CreateDocumentLoader(nsIDocumentLoader** anInstance)
|
|
|
|
{
|
1999-11-22 08:46:03 +03:00
|
|
|
nsDocLoaderImpl* newLoader = nsnull;
|
|
|
|
nsresult rv = NS_OK;
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
/* Check for initial error conditions... */
|
|
|
|
if (nsnull == anInstance) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
*anInstance = nsnull;
|
|
|
|
NS_NEWXPCOM(newLoader, nsDocLoaderImpl);
|
|
|
|
if (nsnull == newLoader) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// The QI causes the new document laoder to get AddRefed... So now
|
|
|
|
// its refcount is 1.
|
|
|
|
//
|
|
|
|
rv = newLoader->QueryInterface(kIDocumentLoaderIID, (void**)anInstance);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete newLoader;
|
|
|
|
return rv;
|
|
|
|
}
|
1999-06-28 14:35:57 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
// Initialize now that we have a reference
|
|
|
|
rv = newLoader->Init(this);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
//
|
|
|
|
// XXX this method incorrectly returns a bool
|
|
|
|
//
|
|
|
|
rv = mChildList->AppendElement((nsIDocumentLoader*)newLoader)
|
|
|
|
? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
// Delete the new document loader if any error occurs during initialization
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(*anInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
nsresult
|
1999-07-16 15:14:36 +04:00
|
|
|
nsDocLoaderImpl::CreateContentViewer(const char *aCommand,
|
|
|
|
nsIChannel* channel,
|
1999-05-06 23:31:59 +04:00
|
|
|
const char* aContentType,
|
1999-11-15 10:29:23 +03:00
|
|
|
nsISupports* aContainer,
|
1999-05-06 23:31:59 +04:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListenerResult,
|
|
|
|
nsIContentViewer** aDocViewerResult)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
1999-05-06 23:31:59 +04:00
|
|
|
// Lookup class-id for the command plus content-type combination
|
|
|
|
nsCID cid;
|
|
|
|
char id[500];
|
|
|
|
PR_snprintf(id, sizeof(id),
|
|
|
|
NS_DOCUMENT_LOADER_FACTORY_PROGID_PREFIX "%s/%s",
|
|
|
|
aCommand ? aCommand : "view",/* XXX bug! shouldn't b needed!*/
|
|
|
|
aContentType);
|
|
|
|
nsresult rv = nsComponentManager::ProgIDToCLSID(id, &cid);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
// Create an instance of the document-loader-factory object
|
|
|
|
nsIDocumentLoaderFactory* factory;
|
|
|
|
rv = nsComponentManager::CreateInstance(cid, (nsISupports *)nsnull,
|
|
|
|
kIDocumentLoaderFactoryIID,
|
|
|
|
(void **)&factory);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
// Now create an instance of the content viewer
|
1999-07-16 15:14:36 +04:00
|
|
|
rv = factory->CreateInstance(aCommand,
|
1999-07-20 12:46:33 +04:00
|
|
|
channel, mLoadGroup,
|
1999-07-16 15:14:36 +04:00
|
|
|
aContentType,
|
1999-11-15 10:47:01 +03:00
|
|
|
aContainer,
|
1999-05-06 23:31:59 +04:00
|
|
|
aExtraInfo, aDocListenerResult,
|
|
|
|
aDocViewerResult);
|
|
|
|
NS_RELEASE(factory);
|
|
|
|
return rv;
|
1999-04-23 20:48:30 +04:00
|
|
|
}
|
|
|
|
|
1999-11-18 10:07:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::LoadOpenedDocument(nsIChannel * aOpenedChannel,
|
|
|
|
const char * aCommand,
|
|
|
|
nsIContentViewerContainer *aContainer,
|
|
|
|
nsIInputStream * aPostDataStream,
|
|
|
|
nsIURI * aReffererUrl,
|
|
|
|
nsIStreamListener ** aContentHandler)
|
|
|
|
{
|
|
|
|
// mscott - there's a big flaw here...we'll proably need to reset the
|
|
|
|
// loadgroupon the channel to theloadgroup associated with the content
|
|
|
|
// viewer container since that's the new guy whose actually going to be
|
|
|
|
// receiving the content
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsDocumentBindInfo* loader = nsnull;
|
|
|
|
if (!aOpenedChannel)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
NS_NEWXPCOM(loader, nsDocumentBindInfo);
|
|
|
|
if (nsnull == loader)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(loader);
|
|
|
|
loader->Init(this, // DocLoader
|
|
|
|
aCommand, // Command
|
|
|
|
aContainer, // Viewer Container
|
|
|
|
/* aExtraInfo */ nsnull); // Extra Info
|
|
|
|
|
|
|
|
loader->QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aContentHandler);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the flag indicating that the document loader is in the process of
|
|
|
|
* loading a document. This flag will remain set until the
|
|
|
|
* OnConnectionsComplete(...) notification is fired for the loader...
|
|
|
|
*/
|
|
|
|
mIsLoadingDocument = PR_TRUE;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kURILoaderCID, NS_URI_LOADER_CID);
|
|
|
|
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
|
|
|
|
|
|
|
// start up prefs
|
|
|
|
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
NS_IMETHODIMP
|
1999-09-08 07:58:57 +04:00
|
|
|
nsDocLoaderImpl::LoadDocument(nsIURI * aUri,
|
1998-10-09 09:49:34 +04:00
|
|
|
const char* aCommand,
|
1999-11-15 10:29:23 +03:00
|
|
|
nsISupports* aContainer,
|
1999-08-04 00:51:41 +04:00
|
|
|
nsIInputStream* aPostDataStream,
|
1998-10-09 09:49:34 +04:00
|
|
|
nsISupports* aExtraInfo,
|
1999-07-01 23:30:20 +04:00
|
|
|
nsLoadFlags aType,
|
1999-09-17 08:26:02 +04:00
|
|
|
const PRUint32 aLocalIP,
|
|
|
|
const PRUnichar* aReferrer)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
1999-09-08 07:58:57 +04:00
|
|
|
nsresult rv = NS_OK;
|
1999-11-18 10:07:33 +03:00
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
|
|
|
PRBool useURILoader = PR_FALSE;
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
prefs->GetBoolPref("browser.uriloader", &useURILoader);
|
|
|
|
|
1999-11-23 10:14:45 +03:00
|
|
|
nsXPIDLCString aUrlScheme;
|
|
|
|
if (aUri)
|
|
|
|
aUri->GetScheme(getter_Copies(aUrlScheme));
|
|
|
|
|
|
|
|
// temporary hack alert! whether uri loading is turned on or off,
|
|
|
|
// I want mailto urls to properly get sent to the uri loader because
|
|
|
|
// it works so well...=)
|
|
|
|
// so for now, if the protocol scheme is mailto, for useURILoader to true
|
|
|
|
if (nsCRT::strcasecmp(aUrlScheme, "mailto") == 0)
|
|
|
|
useURILoader = PR_TRUE;
|
|
|
|
|
1999-11-18 10:07:33 +03:00
|
|
|
// right now, uri dispatching is only hooked up to work with imap, mailbox and
|
|
|
|
// news urls...so as a hack....check the protocol scheme and only call the
|
|
|
|
// dispatching code for those schemes which work with uri dispatching...
|
|
|
|
if (useURILoader && aUri)
|
1999-11-23 10:14:45 +03:00
|
|
|
{
|
|
|
|
if (nsCRT::strcasecmp(aUrlScheme, "imap") == 0
|
|
|
|
|| nsCRT::strcasecmp(aUrlScheme, "news") == 0
|
|
|
|
|| nsCRT::strcasecmp(aUrlScheme, "mailbox") == 0
|
|
|
|
|| nsCRT::strcasecmp(aUrlScheme, "mailboxMessage") ==0
|
|
|
|
|| nsCRT::strcasecmp(aUrlScheme, "mailto") == 0
|
|
|
|
|| nsCRT::strcasecmp(aUrlScheme, "http") == 0)
|
1999-11-18 10:07:33 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> aOpenContext = do_QueryInterface(mLoadGroup);
|
|
|
|
|
|
|
|
// let's try uri dispatching...
|
|
|
|
NS_WITH_SERVICE(nsIURILoader, pURILoader, kURILoaderCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
1999-11-30 00:01:15 +03:00
|
|
|
// temporary hack for post data...eventually this snippet of code
|
|
|
|
// should be moved into the layout call when callers go through the
|
|
|
|
// uri loader directly!
|
|
|
|
|
|
|
|
if (aPostDataStream)
|
|
|
|
{
|
|
|
|
// query for private post data stream interface
|
|
|
|
nsCOMPtr<nsPIURILoaderWithPostData> postLoader = do_QueryInterface(pURILoader, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = postLoader->OpenURIWithPostData(aUri, nsnull /* window target */,
|
|
|
|
aContainer,
|
|
|
|
nsnull /* referring uri */,
|
|
|
|
aPostDataStream,
|
|
|
|
mLoadGroup,
|
|
|
|
getter_AddRefs(aOpenContext));
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = pURILoader->OpenURI(aUri, nsnull /* window target */,
|
|
|
|
aContainer,
|
|
|
|
nsnull /* refferring URI */,
|
|
|
|
mLoadGroup,
|
|
|
|
getter_AddRefs(aOpenContext));
|
1999-11-18 10:07:33 +03:00
|
|
|
if (aOpenContext)
|
|
|
|
mLoadGroup = do_QueryInterface(aOpenContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} // end try uri loader code
|
|
|
|
|
1998-10-09 09:49:34 +04:00
|
|
|
nsDocumentBindInfo* loader = nsnull;
|
1999-09-08 07:58:57 +04:00
|
|
|
if (!aUri)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1998-09-16 04:40:20 +04:00
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
#if defined(DEBUG)
|
1999-09-08 07:58:57 +04:00
|
|
|
nsXPIDLCString urlSpec;
|
|
|
|
aUri->GetSpec(getter_Copies(urlSpec));
|
1999-01-15 13:10:46 +03:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-04-30 04:10:27 +04:00
|
|
|
("DocLoader:%p: LoadDocument(...) called for %s.",
|
1999-09-08 07:58:57 +04:00
|
|
|
this, (const char *) urlSpec));
|
1999-01-15 13:10:46 +03:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
1998-10-09 09:49:34 +04:00
|
|
|
/* Check for initial error conditions... */
|
|
|
|
if (nsnull == aContainer) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
goto done;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
// Save the command associated with this load...
|
|
|
|
mCommand = aCommand;
|
|
|
|
|
1998-10-09 09:49:34 +04:00
|
|
|
NS_NEWXPCOM(loader, nsDocumentBindInfo);
|
|
|
|
if (nsnull == loader) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
NS_ADDREF(loader);
|
1998-10-09 09:49:34 +04:00
|
|
|
loader->Init(this, // DocLoader
|
|
|
|
aCommand, // Command
|
|
|
|
aContainer, // Viewer Container
|
1999-10-05 08:04:16 +04:00
|
|
|
aExtraInfo); // Extra Info
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-12-29 07:45:00 +03:00
|
|
|
/*
|
|
|
|
* Set the flag indicating that the document loader is in the process of
|
|
|
|
* loading a document. This flag will remain set until the
|
|
|
|
* OnConnectionsComplete(...) notification is fired for the loader...
|
|
|
|
*/
|
|
|
|
mIsLoadingDocument = PR_TRUE;
|
1998-10-10 08:33:29 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
rv = loader->Bind(aUri, mLoadGroup, aPostDataStream, aReferrer);
|
1998-07-22 15:23:32 +04:00
|
|
|
|
|
|
|
done:
|
1999-07-16 15:14:36 +04:00
|
|
|
NS_RELEASE(loader);
|
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
|
|
|
|
nsDocLoaderImpl::IsBusy(PRBool& aResult)
|
|
|
|
{
|
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...
|
|
|
|
//
|
1998-10-02 01:48:12 +04:00
|
|
|
aResult = PR_FALSE;
|
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
/* Is this document loader busy? */
|
1999-09-17 11:56:03 +04:00
|
|
|
if (mIsLoadingDocument) {
|
1999-11-22 08:46:03 +03:00
|
|
|
rv = mLoadGroup->IsPending(&aResult);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
/* Otherwise, check its child document loaders... */
|
1999-11-22 08:46:03 +03:00
|
|
|
if (!aResult) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (aResult) break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
FireOnStartDocumentLoad(this, uri);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
|
|
|
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mContainer));
|
|
|
|
NS_ENSURE_TRUE(webShell, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
webShell->GetContentViewer(getter_AddRefs(viewer));
|
|
|
|
|
|
|
|
FireOnStartURLLoad(this, aChannel, viewer);
|
|
|
|
}
|
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-08-27 02:45:55 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::CreateLoadGroupListener(nsIStreamListener *aListener,
|
|
|
|
nsIStreamListener **aResult)
|
|
|
|
{
|
|
|
|
nsChannelListener *newListener;
|
|
|
|
|
|
|
|
NS_NEWXPCOM(newListener, nsChannelListener);
|
|
|
|
if (nsnull == newListener) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(newListener);
|
1999-11-22 08:46:03 +03:00
|
|
|
newListener->Init(aListener);
|
1999-08-27 02:45:55 +04:00
|
|
|
|
|
|
|
*aResult = newListener;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-17 11:56:03 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
void nsDocLoaderImpl::DocLoaderIsEmpty(nsresult aStatus)
|
|
|
|
{
|
|
|
|
if (mIsLoadingDocument) {
|
|
|
|
PRBool busy = PR_FALSE;
|
|
|
|
|
|
|
|
IsBusy(busy);
|
|
|
|
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
|
|
|
|
|
|
|
observer->OnEndDocumentLoad(aLoadInitiator, aDocChannel, aStatus, observer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-11-22 08:46:03 +03:00
|
|
|
nsIChannel* aChannel,
|
1999-03-29 13:21:01 +04:00
|
|
|
nsIContentViewer* aViewer)
|
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(...)"
|
|
|
|
"\tURI: %s Viewer: %x\n",
|
|
|
|
this, buffer, aViewer));
|
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
observer->OnStartURLLoad(aLoadInitiator, aChannel, aViewer);
|
1999-01-14 09:44:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally notify the parent...
|
|
|
|
*/
|
1999-09-17 11:56:03 +04:00
|
|
|
if (mParent) {
|
1999-11-22 08:46:03 +03:00
|
|
|
mParent->FireOnStartURLLoad(aLoadInitiator, aChannel, aViewer);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* nsDocumentBindInfo implementation...
|
|
|
|
****************************************************************************/
|
|
|
|
|
1998-09-15 04:17:53 +04:00
|
|
|
nsDocumentBindInfo::nsDocumentBindInfo()
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
1998-09-15 04:17:53 +04:00
|
|
|
m_Command = nsnull;
|
|
|
|
m_DocLoader = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDocumentBindInfo::Init(nsDocLoaderImpl* aDocLoader,
|
|
|
|
const char *aCommand,
|
1999-11-15 10:29:23 +03:00
|
|
|
nsISupports* aContainer,
|
1999-10-05 08:04:16 +04:00
|
|
|
nsISupports* aExtraInfo)
|
1998-09-15 04:17:53 +04:00
|
|
|
{
|
1998-07-01 15:29:20 +04:00
|
|
|
m_Command = (nsnull != aCommand) ? PL_strdup(aCommand) : nsnull;
|
|
|
|
|
|
|
|
m_DocLoader = aDocLoader;
|
|
|
|
NS_ADDREF(m_DocLoader);
|
|
|
|
|
1999-11-15 10:29:23 +03:00
|
|
|
m_Container = aContainer; // This does an addref
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-11-15 10:29:23 +03:00
|
|
|
m_ExtraInfo = aExtraInfo; // This does an addref
|
1998-09-15 04:17:53 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDocumentBindInfo::~nsDocumentBindInfo()
|
|
|
|
{
|
|
|
|
if (m_Command) {
|
|
|
|
PR_Free(m_Command);
|
|
|
|
}
|
|
|
|
m_Command = nsnull;
|
|
|
|
|
|
|
|
NS_RELEASE (m_DocLoader);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of ISupports methods...
|
|
|
|
*/
|
1998-07-22 04:26:23 +04:00
|
|
|
NS_IMPL_ADDREF(nsDocumentBindInfo);
|
|
|
|
NS_IMPL_RELEASE(nsDocumentBindInfo);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-07-22 04:26:23 +04:00
|
|
|
nsresult
|
|
|
|
nsDocumentBindInfo::QueryInterface(const nsIID& aIID,
|
|
|
|
void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aInstancePtrResult = NULL;
|
|
|
|
|
|
|
|
if (aIID.Equals(kIStreamObserverIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIStreamObserver*)this);
|
1998-09-12 23:30:49 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-07-22 04:26:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIStreamListenerIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIStreamListener*)this);
|
1998-09-12 23:30:49 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-07-22 04:26:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-18 05:19:13 +03:00
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsISupports*) this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-22 04:26:23 +04:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-09-17 11:56:03 +04:00
|
|
|
nsresult nsDocumentBindInfo::Bind(nsIURI* aURL,
|
|
|
|
nsILoadGroup *aLoadGroup,
|
|
|
|
nsIInputStream *postDataStream,
|
|
|
|
const PRUnichar* aReferrer)
|
1998-10-02 01:48:12 +04:00
|
|
|
{
|
1999-03-29 13:21:01 +04:00
|
|
|
nsresult rv = NS_OK;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
// XXXbe this knows that m_Container implements nsIWebShell
|
1999-11-18 10:36:41 +03:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> capabilities = do_QueryInterface(m_Container);
|
1999-07-16 15:14:36 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
1999-11-17 11:14:52 +03:00
|
|
|
rv = NS_OpenURI(getter_AddRefs(channel), aURL, aLoadGroup, capabilities);
|
1999-07-16 15:14:36 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-09-17 08:26:02 +04:00
|
|
|
if (postDataStream || aReferrer)
|
1999-08-04 19:06:51 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTTPChannel> httpChannel(do_QueryInterface(channel));
|
|
|
|
if (httpChannel)
|
|
|
|
{
|
1999-09-17 08:26:02 +04:00
|
|
|
if (postDataStream) {
|
|
|
|
httpChannel->SetRequestMethod(HM_POST);
|
|
|
|
httpChannel->SetPostDataStream(postDataStream);
|
|
|
|
}
|
|
|
|
if (aReferrer) {
|
|
|
|
// Referer - misspelled, but per the HTTP spec
|
|
|
|
nsCAutoString str = aReferrer;
|
|
|
|
nsCOMPtr<nsIAtom> key = NS_NewAtom("referer");
|
|
|
|
httpChannel->SetRequestHeader(key, str.GetBuffer());
|
|
|
|
}
|
1999-08-04 19:06:51 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-31 10:33:50 +04:00
|
|
|
|
1999-07-20 12:46:33 +04:00
|
|
|
rv = channel->AsyncRead(0, -1, nsnull, this);
|
1999-03-29 13:21:01 +04:00
|
|
|
|
|
|
|
return rv;
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
NS_IMETHODIMP
|
1999-07-07 12:08:40 +04:00
|
|
|
nsDocumentBindInfo::OnStartRequest(nsIChannel* channel, nsISupports *ctxt)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1998-07-17 10:32:39 +04:00
|
|
|
nsIContentViewer* viewer = nsnull;
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-06-30 01:48:35 +04:00
|
|
|
char* aContentType = nsnull;
|
1999-07-03 09:49:12 +04:00
|
|
|
rv = channel->GetContentType(&aContentType);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-06-28 14:35:57 +04:00
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
#if defined(DEBUG)
|
1999-06-28 14:35:57 +04:00
|
|
|
char* spec;
|
1998-12-16 08:40:20 +03:00
|
|
|
(void)aURL->GetSpec(&spec);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-07-01 23:30:20 +04:00
|
|
|
("DocumentBindInfo:%p OnStartRequest(...) called for %s. Content-type is %s\n",
|
1999-04-30 04:10:27 +04:00
|
|
|
this, spec, aContentType));
|
1999-06-28 14:35:57 +04:00
|
|
|
nsCRT::free(spec);
|
1999-03-29 13:21:01 +04:00
|
|
|
#endif /* DEBUG */
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
if (nsnull == m_NextStream) {
|
|
|
|
/*
|
1999-05-06 23:31:59 +04:00
|
|
|
* Now that the content type is available, create a document
|
|
|
|
* (and viewer) of the appropriate type...
|
1998-07-22 15:23:32 +04:00
|
|
|
*/
|
1999-05-06 23:31:59 +04:00
|
|
|
if (m_DocLoader) {
|
1999-08-29 18:31:08 +04:00
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
rv = m_DocLoader->CreateContentViewer(m_Command,
|
|
|
|
channel,
|
1999-05-06 23:31:59 +04:00
|
|
|
aContentType,
|
|
|
|
m_Container,
|
|
|
|
m_ExtraInfo,
|
1999-11-15 10:29:23 +03:00
|
|
|
getter_AddRefs(m_NextStream),
|
1999-05-06 23:31:59 +04:00
|
|
|
&viewer);
|
1998-07-22 15:23:32 +04:00
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-07-17 10:32:39 +04:00
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-05-06 23:31:59 +04:00
|
|
|
printf("DocLoaderFactory: Unable to create ContentViewer for command=%s, content-type=%s\n", m_Command ? m_Command : "(null)", aContentType);
|
1999-11-15 10:29:23 +03:00
|
|
|
nsCOMPtr<nsIContentViewerContainer>
|
|
|
|
cvContainer(do_QueryInterface(m_Container));
|
|
|
|
if ( cvContainer ) {
|
1999-04-08 08:21:15 +04:00
|
|
|
// Give content container a chance to do something with this URL.
|
1999-11-15 10:29:23 +03:00
|
|
|
rv = cvContainer->HandleUnknownContentType( (nsIDocumentLoader*) m_DocLoader, channel, aContentType, m_Command );
|
1999-04-08 08:21:15 +04:00
|
|
|
}
|
|
|
|
// Stop the binding.
|
|
|
|
// This crashes on Unix/Mac... Stop();
|
1998-07-22 15:23:32 +04:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give the document container the new viewer...
|
|
|
|
*/
|
1999-11-15 10:29:23 +03:00
|
|
|
nsCOMPtr<nsIContentViewerContainer>
|
|
|
|
cvContainer(do_QueryInterface(m_Container));
|
|
|
|
if (cvContainer) {
|
1999-03-12 08:20:29 +03:00
|
|
|
viewer->SetContainer(m_Container);
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-11-15 10:29:23 +03:00
|
|
|
rv = cvContainer->Embed(viewer, m_Command, m_ExtraInfo);
|
1999-03-29 13:21:01 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-03-12 08:20:29 +03:00
|
|
|
goto done;
|
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-07-01 23:30:20 +04:00
|
|
|
* Pass the OnStartRequest(...) notification out to the document
|
1998-07-01 15:29:20 +04:00
|
|
|
* IStreamListener.
|
|
|
|
*/
|
|
|
|
if (nsnull != m_NextStream) {
|
1999-07-07 12:08:40 +04:00
|
|
|
rv = m_NextStream->OnStartRequest(channel, ctxt);
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
done:
|
1998-07-03 10:16:02 +04:00
|
|
|
NS_IF_RELEASE(viewer);
|
1999-07-16 15:14:36 +04:00
|
|
|
nsCRT::free(aContentType);
|
1998-07-01 15:29:20 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-07 12:08:40 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::OnDataAvailable(nsIChannel* channel, nsISupports *ctxt,
|
1999-06-29 00:43:28 +04:00
|
|
|
nsIInputStream *aStream,
|
1999-06-28 14:35:57 +04:00
|
|
|
PRUint32 sourceOffset,
|
|
|
|
PRUint32 aLength)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
1999-09-17 11:56:03 +04:00
|
|
|
nsresult rv;
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
#if defined(DEBUG)
|
1999-06-28 14:35:57 +04:00
|
|
|
char* spec;
|
1998-12-16 08:40:20 +03:00
|
|
|
(void)aURL->GetSpec(&spec);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-04-30 04:10:27 +04:00
|
|
|
("DocumentBindInfo:%p: OnDataAvailable(...) called for %s. Bytes available: %d.\n",
|
|
|
|
this, spec, aLength));
|
1999-06-28 14:35:57 +04:00
|
|
|
nsCRT::free(spec);
|
1999-03-29 13:21:01 +04:00
|
|
|
#endif /* DEBUG */
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
if (nsnull != m_NextStream) {
|
1998-11-10 10:06:02 +03:00
|
|
|
/*
|
|
|
|
* Bump the refcount in case the stream gets destroyed while the data
|
|
|
|
* is being processed... If Stop(...) is called the stream could be
|
|
|
|
* freed prematurely :-(
|
|
|
|
*
|
|
|
|
* Currently this can happen if javascript loads a new URL
|
|
|
|
* (via nsIWebShell::LoadURL) during the parse phase...
|
|
|
|
*/
|
1999-11-15 10:29:23 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> listener(m_NextStream);
|
1998-11-10 10:06:02 +03:00
|
|
|
|
1999-07-07 12:08:40 +04:00
|
|
|
rv = listener->OnDataAvailable(channel, ctxt, aStream, sourceOffset, aLength);
|
1998-11-22 12:28:44 +03:00
|
|
|
} else {
|
|
|
|
rv = NS_BINDING_FAILED;
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-07 12:08:40 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
|
|
|
|
nsresult aStatus, const PRUnichar *aMsg)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
1999-09-17 11:56:03 +04:00
|
|
|
nsresult rv;
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
#if defined(DEBUG)
|
1999-06-28 14:35:57 +04:00
|
|
|
char* spec;
|
1998-12-16 08:40:20 +03:00
|
|
|
(void)aURL->GetSpec(&spec);
|
1998-10-02 01:48:12 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-07-01 23:30:20 +04:00
|
|
|
("DocumentBindInfo:%p: OnStopRequest(...) called for %s. Status: %d.\n",
|
1999-04-30 04:10:27 +04:00
|
|
|
this, spec, aStatus));
|
1999-06-28 14:35:57 +04:00
|
|
|
nsCRT::free(spec);
|
1999-07-30 08:20:34 +04:00
|
|
|
#endif // DEBUG
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
if (NS_FAILED(aStatus)) {
|
1999-07-30 08:20:34 +04:00
|
|
|
char *url;
|
1999-09-17 11:56:03 +04:00
|
|
|
aURL->GetSpec(&url);
|
1999-07-30 08:20:34 +04:00
|
|
|
|
|
|
|
if (aStatus == NS_ERROR_UNKNOWN_HOST)
|
|
|
|
printf("Error: Unknown host: %s\n", url);
|
|
|
|
else if (aStatus == NS_ERROR_MALFORMED_URI)
|
|
|
|
printf("Error: Malformed URI: %s\n", url);
|
1999-08-07 01:54:25 +04:00
|
|
|
else if (NS_FAILED(aStatus))
|
1999-07-30 08:20:34 +04:00
|
|
|
printf("Error: Can't load: %s (%x)\n", url, aStatus);
|
|
|
|
nsCRT::free(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != m_NextStream) {
|
|
|
|
rv = m_NextStream->OnStopRequest(channel, ctxt, aStatus, aMsg);
|
|
|
|
}
|
|
|
|
|
1999-11-15 10:29:23 +03:00
|
|
|
m_NextStream = nsnull; // Release our stream we are holding
|
1999-07-30 08:20:34 +04:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
|
|
|
|
|
1999-10-06 12:26:01 +04:00
|
|
|
NS_IMPL_ISUPPORTS2(nsChannelListener, nsIStreamObserver, nsIStreamListener);
|
1999-08-27 02:45:55 +04:00
|
|
|
|
|
|
|
nsChannelListener::nsChannelListener()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
nsresult nsChannelListener::Init(nsIStreamListener *aListener)
|
1999-08-27 02:45:55 +04:00
|
|
|
{
|
|
|
|
mNextListener = aListener;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsChannelListener::~nsChannelListener()
|
|
|
|
{
|
|
|
|
mNextListener = null_nsCOMPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChannelListener::OnStartRequest(nsIChannel *aChannel, nsISupports *aContext)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-08-29 18:31:08 +04:00
|
|
|
///////////////////////////////
|
|
|
|
// STREAM CONVERTERS
|
|
|
|
///////////////////////////////
|
1999-09-05 23:54:28 +04:00
|
|
|
|
1999-11-22 08:46:03 +03:00
|
|
|
nsXPIDLCString contentType;
|
|
|
|
rv = aChannel->GetContentType(getter_Copies(contentType));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-11-18 10:07:33 +03:00
|
|
|
// if we are using the uri loader, it handles the stream converter work for us!
|
1999-08-29 18:31:08 +04:00
|
|
|
|
1999-11-18 10:07:33 +03:00
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
|
|
|
PRBool useURILoader = PR_FALSE;
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
prefs->GetBoolPref("browser.uriloader", &useURILoader);
|
1999-09-05 23:54:28 +04:00
|
|
|
|
1999-11-18 10:07:33 +03:00
|
|
|
if (!useURILoader)
|
1999-09-05 23:54:28 +04:00
|
|
|
{
|
1999-11-18 10:07:33 +03:00
|
|
|
PRBool conversionRequired = PR_FALSE;
|
|
|
|
nsAutoString from, to;
|
1999-08-29 18:31:08 +04:00
|
|
|
|
1999-11-18 10:07:33 +03:00
|
|
|
// Let's shanghai this channelListener's mNextListener if we want to convert the stream.
|
|
|
|
if (!nsCRT::strcasecmp(contentType, "message/rfc822"))
|
|
|
|
{
|
|
|
|
from = "message/rfc822";
|
|
|
|
to = "text/xul";
|
|
|
|
conversionRequired = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (!nsCRT::strcasecmp(contentType, "multipart/x-mixed-replace"))
|
|
|
|
{
|
|
|
|
from = "multipart/x-mixed-replace";
|
|
|
|
to = "text/html";
|
|
|
|
conversionRequired = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conversionRequired)
|
|
|
|
{
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIStreamConverterService, StreamConvService, kStreamConverterServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// The following call binds this channelListener's mNextListener (typically
|
|
|
|
// the nsDocumentBindInfo) to the underlying stream converter, and returns
|
|
|
|
// the underlying stream converter which we then set to be this channelListener's
|
|
|
|
// mNextListener. This effectively nestles the stream converter down right
|
|
|
|
// in between the raw stream and the final listener.
|
|
|
|
nsIStreamListener *converterListener = nsnull;
|
|
|
|
rv = StreamConvService->AsyncConvertData(from.GetUnicode(), to.GetUnicode(), mNextListener, aChannel,
|
|
|
|
&converterListener);
|
|
|
|
mNextListener = converterListener;
|
|
|
|
NS_IF_RELEASE(converterListener);
|
|
|
|
}
|
|
|
|
}
|
1999-08-29 18:31:08 +04:00
|
|
|
//////////////////////////////
|
|
|
|
// END STREAM CONVERTERS
|
|
|
|
//////////////////////////////
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
// Pass the notification to the next listener...
|
1999-11-22 08:46:03 +03:00
|
|
|
return mNextListener->OnStartRequest(aChannel, aContext);
|
1999-08-27 02:45:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChannelListener::OnStopRequest(nsIChannel *aChannel, nsISupports *aContext,
|
|
|
|
nsresult aStatus, const PRUnichar *aMsg)
|
|
|
|
{
|
1999-11-22 08:46:03 +03:00
|
|
|
return mNextListener->OnStopRequest(aChannel, aContext, aStatus, aMsg);
|
1999-08-27 02:45:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChannelListener::OnDataAvailable(nsIChannel *aChannel, nsISupports *aContext,
|
|
|
|
nsIInputStream *aInStream, PRUint32 aOffset,
|
|
|
|
PRUint32 aCount)
|
|
|
|
{
|
|
|
|
return mNextListener->OnDataAvailable(aChannel, aContext, aInStream,
|
|
|
|
aOffset, aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
/*******************************************
|
1999-01-17 14:48:58 +03:00
|
|
|
* nsDocLoaderServiceFactory
|
1998-07-04 03:14:21 +04:00
|
|
|
*******************************************/
|
1999-01-17 14:48:58 +03:00
|
|
|
static nsDocLoaderImpl* gServiceInstance = nsnull;
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-05-26 05:38:36 +04:00
|
|
|
nsDocLoaderImpl::Create(nsISupports *aOuter, const nsIID &aIID, void **aResult)
|
1998-07-19 05:18:15 +04:00
|
|
|
{
|
1999-01-17 14:48:58 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsDocLoaderImpl* inst;
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-01-17 14:48:58 +03:00
|
|
|
// Parameter validation...
|
|
|
|
if (NULL == aResult) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
// Do not support aggregatable components...
|
|
|
|
*aResult = NULL;
|
|
|
|
if (NULL != aOuter) {
|
|
|
|
rv = NS_ERROR_NO_AGGREGATION;
|
|
|
|
goto done;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-01-17 14:48:58 +03:00
|
|
|
if (NULL == gServiceInstance) {
|
|
|
|
// Create a new instance of the component...
|
|
|
|
NS_NEWXPCOM(gServiceInstance, nsDocLoaderImpl);
|
|
|
|
if (NULL == gServiceInstance) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto done;
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
1999-01-17 14:48:58 +03:00
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-01-17 14:48:58 +03:00
|
|
|
// If the QI fails, the component will be destroyed...
|
|
|
|
//
|
|
|
|
// Use a local copy so the NS_RELEASE() will not null the global
|
|
|
|
// pointer...
|
|
|
|
inst = gServiceInstance;
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-01-17 14:48:58 +03:00
|
|
|
NS_ADDREF(inst);
|
|
|
|
rv = inst->QueryInterface(aIID, aResult);
|
1999-09-10 03:53:55 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-11-22 08:46:03 +03:00
|
|
|
rv = inst->Init(nsnull);
|
1999-09-10 03:53:55 +04:00
|
|
|
}
|
1999-01-17 14:48:58 +03:00
|
|
|
NS_RELEASE(inst);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
done:
|
1999-01-17 14:48:58 +03:00
|
|
|
return rv;
|
1998-07-19 05:18:15 +04:00
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-03-08 12:44:16 +03:00
|
|
|
// Entry point to create nsDocLoaderService factory instances...
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-01-17 14:48:58 +03:00
|
|
|
nsresult NS_NewDocLoaderServiceFactory(nsIFactory** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1999-05-26 05:38:36 +04:00
|
|
|
nsIGenericFactory* factory;
|
|
|
|
rv = nsComponentManager::CreateInstance(kGenericFactoryCID, nsnull,
|
|
|
|
nsIGenericFactory::GetIID(),
|
|
|
|
(void**)&factory);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = factory->SetConstructor(nsDocLoaderImpl::Create);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(factory);
|
|
|
|
return rv;
|
1999-01-17 14:48:58 +03:00
|
|
|
}
|
1999-05-26 05:38:36 +04:00
|
|
|
|
|
|
|
*aResult = factory;
|
1999-01-17 14:48:58 +03:00
|
|
|
return rv;
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
|