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
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
|
|
|
* Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
*/
|
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-06-18 21:34:08 +04:00
|
|
|
#ifndef NECKO
|
1999-06-28 14:35:57 +04:00
|
|
|
#include "nsIHttpURL.h"
|
|
|
|
#include "nsIRefreshUrl.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIURLGroup.h"
|
|
|
|
#include "nsILoadAttribs.h"
|
1998-10-02 01:48:12 +04:00
|
|
|
#include "nsINetService.h"
|
1999-08-04 00:51:41 +04:00
|
|
|
//#include "nsIPostToServer.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#else
|
1999-07-16 15:14:36 +04:00
|
|
|
#include "nsIIOService.h"
|
1999-06-28 14:35:57 +04:00
|
|
|
#include "nsILoadGroup.h"
|
1999-07-20 12:46:33 +04:00
|
|
|
//#include "nsILoadGroupObserver.h"
|
1999-06-28 14:35:57 +04:00
|
|
|
#include "nsNeckoUtil.h"
|
1999-06-23 07:29:44 +04:00
|
|
|
#include "nsIURL.h"
|
1999-07-30 08:20:34 +04:00
|
|
|
#include "nsIDNSService.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-06-28 14:35:57 +04:00
|
|
|
#include "nsIProgressEventSink.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#endif // NECKO
|
1999-05-26 05:38:36 +04:00
|
|
|
#include "nsIGenericFactory.h"
|
1999-04-23 20:48:30 +04:00
|
|
|
#include "nsIStreamLoadableDocument.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-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-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
|
|
|
|
1998-11-23 20:18:08 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
#undef NOISY_CREATE_DOC
|
|
|
|
#else
|
|
|
|
#undef NOISY_CREATE_DOC
|
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
#if defined(DEBUG) || defined(FORCE_PR_LOG)
|
|
|
|
PRLogModuleInfo* gDocLoaderLog = nsnull;
|
|
|
|
#endif /* DEBUG || FORCE_PR_LOG */
|
|
|
|
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
/* Private IIDs... */
|
|
|
|
/* eb001fa0-214f-11d2-bec0-00805f8a66dc */
|
|
|
|
#define NS_DOCUMENTBINDINFO_IID \
|
|
|
|
{ 0xeb001fa0, 0x214f, 0x11d2, \
|
|
|
|
{0xbe, 0xc0, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
|
|
|
|
|
|
|
|
|
|
|
|
/* 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(kDocumentBindInfoIID, NS_DOCUMENTBINDINFO_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-06-18 21:34:08 +04:00
|
|
|
#ifndef NECKO
|
1999-06-28 14:35:57 +04:00
|
|
|
static NS_DEFINE_IID(kHTTPURLIID, NS_IHTTPURL_IID);
|
|
|
|
static NS_DEFINE_IID(kRefreshURLIID, NS_IREFRESHURL_IID);
|
|
|
|
static NS_DEFINE_IID(kILoadGroupIID, NS_ILOADGROUP_IID);
|
1999-05-06 23:31:59 +04:00
|
|
|
static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
|
1999-06-28 14:35:57 +04:00
|
|
|
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
|
1999-07-16 15:14:36 +04:00
|
|
|
#else
|
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
1999-06-18 21:34:08 +04:00
|
|
|
#endif // NECKO
|
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
|
|
|
|
|
|
|
#ifdef NECKO
|
|
|
|
class nsChannelListener : public nsIStreamListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsChannelListener();
|
|
|
|
|
|
|
|
nsresult Init(nsDocLoaderImpl *aDocLoader, nsIStreamListener *aListener);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIStreamListener methods:
|
|
|
|
NS_IMETHOD OnStartRequest(nsIChannel* channel, nsISupports *ctxt);
|
|
|
|
NS_IMETHOD OnStopRequest(nsIChannel* channel, nsISupports *ctxt, nsresult status,
|
|
|
|
const PRUnichar *errorMsg);
|
|
|
|
|
|
|
|
NS_IMETHOD OnDataAvailable(nsIChannel* channel, nsISupports *ctxt, nsIInputStream *inStr,
|
|
|
|
PRUint32 sourceOffset, PRUint32 count);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsChannelListener();
|
|
|
|
|
|
|
|
nsDocLoaderImpl *mDocLoader;
|
|
|
|
nsCOMPtr<nsIStreamListener> mNextListener;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // NECKO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
, public nsIProgressEventSink
|
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,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamObserver* anObserver);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1999-08-04 19:06:51 +04:00
|
|
|
nsresult Bind(nsIURI* aURL, nsIStreamListener* aListener, nsIInputStream *postDataStream = nsnull);
|
1998-08-20 03:01:52 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
nsresult Bind(nsIStreamListener *aListener);
|
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
// nsIStreamObserver methods:
|
1999-08-22 17:26:18 +04:00
|
|
|
NS_DECL_NSISTREAMOBSERVER
|
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
|
|
|
|
|
|
|
// nsIProgressEventSink methods:
|
1999-08-22 17:26:18 +04:00
|
|
|
NS_DECL_NSIPROGRESSEVENTSINK
|
1999-09-08 07:58:57 +04:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-08-21 02:28:52 +04:00
|
|
|
nsresult GetStatus(void) { return mStatus; }
|
|
|
|
|
1998-08-14 00:08:19 +04:00
|
|
|
/* nsIRefreshURL interface methods... */
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_IMETHOD RefreshURL(nsIURI* aURL, PRInt32 millis, PRBool repeat);
|
1998-08-19 03:25:17 +04:00
|
|
|
NS_IMETHOD CancelRefreshURLTimers(void);
|
1998-08-14 00:08:19 +04:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsDocumentBindInfo();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
char* m_Command;
|
1998-07-19 01:50:29 +04:00
|
|
|
nsIContentViewerContainer* m_Container;
|
1998-07-01 15:29:20 +04:00
|
|
|
nsISupports* m_ExtraInfo;
|
|
|
|
nsIStreamObserver* m_Observer;
|
|
|
|
nsIStreamListener* m_NextStream;
|
|
|
|
nsDocLoaderImpl* m_DocLoader;
|
1998-07-25 01:03:33 +04:00
|
|
|
nsresult mStatus;
|
1998-07-01 15:29:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
public nsILoadGroupListenerFactory
|
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-06-28 14:35:57 +04:00
|
|
|
nsresult Init();
|
|
|
|
|
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
|
|
|
|
|
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,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
1999-08-04 00:51:41 +04:00
|
|
|
nsIInputStream* aPostDataStream = nsnull,
|
1998-10-09 09:49:34 +04:00
|
|
|
nsISupports* aExtraInfo = nsnull,
|
|
|
|
nsIStreamObserver* anObserver = nsnull,
|
1999-07-01 23:30:20 +04:00
|
|
|
nsLoadFlags aType = nsIChannel::LOAD_NORMAL,
|
1998-10-09 09:49:34 +04:00
|
|
|
const PRUint32 aLocalIP = 0);
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-09-08 07:58:57 +04:00
|
|
|
NS_IMETHOD LoadSubDocument(nsIURI * aUri,
|
1999-03-12 08:20:29 +03:00
|
|
|
nsISupports* aExtraInfo = nsnull,
|
1999-07-01 23:30:20 +04:00
|
|
|
nsLoadFlags aType = nsIChannel::LOAD_NORMAL,
|
1999-03-12 08:20:29 +03:00
|
|
|
const PRUint32 aLocalIP = 0);
|
|
|
|
|
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-01-14 09:44:23 +03:00
|
|
|
NS_IMETHOD SetContainer(nsIContentViewerContainer* aContainer);
|
|
|
|
NS_IMETHOD GetContainer(nsIContentViewerContainer** aResult);
|
1999-05-06 05:58:48 +04:00
|
|
|
NS_IMETHOD GetContentViewerContainer(PRUint32 aDocumentID,
|
|
|
|
nsIContentViewerContainer** aResult);
|
1999-01-14 09:44:23 +03:00
|
|
|
|
1999-06-25 06:31:51 +04:00
|
|
|
// nsILoadGroup interface...
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_IMETHOD CreateURL(nsIURI** aInstancePtrResult,
|
|
|
|
nsIURI* aBaseURL,
|
1998-10-02 01:48:12 +04:00
|
|
|
const nsString& aSpec,
|
|
|
|
nsISupports* aContainer);
|
|
|
|
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_IMETHOD OpenStream(nsIURI *aUrl,
|
1998-10-02 01:48:12 +04:00
|
|
|
nsIStreamListener *aConsumer);
|
|
|
|
|
1999-07-01 23:30:20 +04:00
|
|
|
NS_IMETHOD GetDefaultLoadAttributes(nsLoadFlags *aLoadAttribs);
|
|
|
|
NS_IMETHOD SetDefaultLoadAttributes(nsLoadFlags aLoadAttribs);
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-06-25 06:31:51 +04:00
|
|
|
NS_IMETHOD AddChildGroup(nsILoadGroup* aGroup);
|
|
|
|
NS_IMETHOD RemoveChildGroup(nsILoadGroup* aGroup);
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
// nsILoadGroupListenerFactory methods...
|
|
|
|
NS_IMETHOD CreateLoadGroupListener(nsIStreamListener *aListener,
|
|
|
|
nsIStreamListener **aResult);
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
// Implementation specific methods...
|
1999-08-27 02:45:55 +04:00
|
|
|
void FireOnStartDocumentLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* aURL,
|
1999-05-06 10:52:05 +04:00
|
|
|
const char* aCommand);
|
1999-08-27 02:45:55 +04:00
|
|
|
void FireOnEndDocumentLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-08-05 05:28:30 +04:00
|
|
|
nsresult aStatus);
|
1999-06-15 02:12:19 +04:00
|
|
|
|
1999-05-06 10:52:05 +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-08-27 02:45:55 +04:00
|
|
|
void FireOnProgressURLLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-06-28 14:35:57 +04:00
|
|
|
nsIChannel* channel,
|
|
|
|
PRUint32 aProgress,
|
1999-03-29 13:21:01 +04:00
|
|
|
PRUint32 aProgressMax);
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void FireOnStatusURLLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-06-28 14:35:57 +04:00
|
|
|
nsIChannel* channel,
|
|
|
|
nsString& aMsg);
|
1999-03-29 13:21:01 +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
|
|
|
|
1999-07-20 12:46:33 +04:00
|
|
|
nsresult LoadURLComplete(nsIChannel* channel, nsISupports* ctxt,
|
1999-08-05 05:28:30 +04:00
|
|
|
nsISupports* aLoader, nsresult aStatus,
|
1999-07-20 12:46:33 +04:00
|
|
|
const PRUnichar* aMsg);
|
1998-10-02 01:48:12 +04:00
|
|
|
void SetParent(nsDocLoaderImpl* aParent);
|
1999-07-31 10:33:50 +04:00
|
|
|
void SetDocumentChannel(nsIChannel* channel);
|
1999-06-28 14:35:57 +04:00
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
// nsIStreamObserver methods: (for observing the load group)
|
|
|
|
NS_IMETHOD OnStartRequest(nsIChannel *channel, nsISupports *ctxt);
|
|
|
|
NS_IMETHOD OnStopRequest(nsIChannel *channel, nsISupports *ctxt,
|
|
|
|
nsresult status, const PRUnichar *errorMsg);
|
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
nsILoadGroup* GetLoadGroup() { return mLoadGroup; }
|
1999-04-30 04:10:27 +04:00
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
nsresult CreateContentViewer(const char *aCommand,
|
|
|
|
nsIChannel* channel,
|
1999-05-06 23:31:59 +04:00
|
|
|
const char* aContentType,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer);
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsDocLoaderImpl();
|
|
|
|
|
|
|
|
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-07-31 10:33:50 +04:00
|
|
|
nsIChannel* mDocumentChannel; // [OWNER] ???compare with document
|
1999-07-16 15:14:36 +04:00
|
|
|
nsVoidArray mDocObservers;
|
|
|
|
nsCOMPtr<nsIStreamObserver> mStreamObserver; // ??? unclear what to do here
|
|
|
|
nsIContentViewerContainer* mContainer; // [WEAK] it owns me!
|
|
|
|
|
|
|
|
nsDocLoaderImpl* mParent; // [OWNER] but upside down ownership model
|
|
|
|
// needs to be fixed***
|
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;
|
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();
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
#if defined(DEBUG) || defined(FORCE_PR_LOG)
|
|
|
|
if (nsnull == gDocLoaderLog) {
|
1999-05-06 23:31:59 +04:00
|
|
|
gDocLoaderLog = PR_NewLogModule("DocLoader");
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
#endif /* DEBUG || FORCE_PR_LOG */
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-07-31 10:33:50 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
mDocumentChannel = nsnull;
|
|
|
|
#else
|
1999-03-29 13:21:01 +04:00
|
|
|
mDocumentUrl = nsnull;
|
1999-07-16 15:14:36 +04:00
|
|
|
mForegroundURLs = 0;
|
|
|
|
mTotalURLs = 0;
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-10-10 08:33:29 +04:00
|
|
|
mParent = nsnull;
|
1999-01-14 09:44:23 +03:00
|
|
|
mContainer = nsnull;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1998-12-29 07:45:00 +03:00
|
|
|
mIsLoadingDocument = PR_FALSE;
|
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
// XXX I wanted to pull this initialization code out of this constructor
|
|
|
|
// because it could fail... but the web shell uses this implementation
|
|
|
|
// as a service too. Since it's a service, it really can't have any
|
|
|
|
// initialization. We're sort of screwed here.
|
|
|
|
nsresult rv = Init();
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "nsDocLoaderImpl::Init failed");
|
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
|
|
|
|
nsDocLoaderImpl::Init()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
#ifdef NECKO
|
1999-07-16 15:14:36 +04:00
|
|
|
rv = NS_NewLoadGroup(nsnull, this, nsnull, getter_AddRefs(mLoadGroup));
|
1999-06-28 14:35:57 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-07-31 10:33:50 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: load group %x.\n", this, mLoadGroup));
|
1999-08-27 02:45:55 +04:00
|
|
|
|
|
|
|
rv = mLoadGroup->SetGroupListenerFactory( (nsILoadGroupListenerFactory*)this);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-07-16 15:14:36 +04:00
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(m_LoadingDocsList));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-06-28 14:35:57 +04:00
|
|
|
rv = NS_NewLoadAttribs(getter_AddRefs(m_LoadAttrib));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
#endif
|
|
|
|
return rv;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
nsDocLoaderImpl::~nsDocLoaderImpl()
|
|
|
|
{
|
1999-05-06 23:31:59 +04:00
|
|
|
Stop();
|
|
|
|
if (nsnull != mParent) {
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
mParent->RemoveChildGroup(GetLoadGroup());
|
|
|
|
#else
|
1999-05-06 23:31:59 +04:00
|
|
|
mParent->RemoveChildGroup(this);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-05-06 23:31:59 +04:00
|
|
|
NS_RELEASE(mParent);
|
|
|
|
}
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-07-31 10:33:50 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
NS_IF_RELEASE(mDocumentChannel);
|
|
|
|
#else
|
1999-05-06 23:31:59 +04:00
|
|
|
NS_IF_RELEASE(mDocumentUrl);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: deleted.\n", this));
|
1999-07-16 15:14:36 +04:00
|
|
|
#ifndef NECKO
|
1999-05-06 23:31:59 +04:00
|
|
|
NS_PRECONDITION((0 == mChildGroupList.Count()), "Document loader has children...");
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
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);
|
|
|
|
|
|
|
|
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-06-18 21:34:08 +04:00
|
|
|
#ifndef NECKO
|
1999-06-25 06:31:51 +04:00
|
|
|
if (aIID.Equals(kILoadGroupIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsILoadGroup*)this;
|
1999-05-06 23:31:59 +04:00
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
#else
|
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-06-18 21:34:08 +04:00
|
|
|
#endif // NECKO
|
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-05-06 23:31:59 +04:00
|
|
|
nsDocLoaderImpl* newLoader = nsnull;
|
|
|
|
nsresult rv = NS_OK;
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
/* Check for initial error conditions... */
|
|
|
|
if (nsnull == anInstance) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
goto done;
|
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
NS_NEWXPCOM(newLoader, nsDocLoaderImpl);
|
|
|
|
if (nsnull == newLoader) {
|
|
|
|
*anInstance = nsnull;
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
1999-06-28 14:35:57 +04:00
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
rv = newLoader->QueryInterface(kIDocumentLoaderIID, (void**)anInstance);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
AddChildGroup(newLoader->GetLoadGroup());
|
|
|
|
#else
|
1999-05-06 23:31:59 +04:00
|
|
|
AddChildGroup(newLoader);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-05-06 23:31:59 +04:00
|
|
|
newLoader->SetParent(this);
|
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
done:
|
|
|
|
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,
|
|
|
|
#ifdef NECKO
|
|
|
|
nsIChannel* channel,
|
|
|
|
#else
|
|
|
|
nsIURI* aURL,
|
|
|
|
#endif
|
1999-05-06 23:31:59 +04:00
|
|
|
const char* aContentType,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
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,
|
|
|
|
#ifdef NECKO
|
1999-07-20 12:46:33 +04:00
|
|
|
channel, mLoadGroup,
|
1999-07-16 15:14:36 +04:00
|
|
|
#else
|
|
|
|
aURL,
|
|
|
|
#endif
|
|
|
|
aContentType,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
1999-08-04 00:51:41 +04:00
|
|
|
nsIInputStream* aPostDataStream,
|
1998-10-09 09:49:34 +04:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamObserver* anObserver,
|
1999-07-01 23:30:20 +04:00
|
|
|
nsLoadFlags aType,
|
1998-10-09 09:49:34 +04:00
|
|
|
const PRUint32 aLocalIP)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
1999-09-08 07:58:57 +04:00
|
|
|
nsresult rv = NS_OK;
|
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
|
|
|
|
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
|
|
|
|
aExtraInfo, // Extra Info
|
|
|
|
anObserver); // Observer
|
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-04-30 13:04:36 +04:00
|
|
|
mStreamObserver = dont_QueryInterface(anObserver);
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-09-08 07:58:57 +04:00
|
|
|
rv = loader->Bind(aUri, nsnull, aPostDataStream);
|
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-09-08 07:58:57 +04:00
|
|
|
nsDocLoaderImpl::LoadSubDocument(nsIURI *aUri,
|
1999-03-12 08:20:29 +03:00
|
|
|
nsISupports* aExtraInfo,
|
1999-07-01 23:30:20 +04:00
|
|
|
nsLoadFlags aType,
|
1999-03-12 08:20:29 +03:00
|
|
|
const PRUint32 aLocalIP)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsDocumentBindInfo* loader = nsnull;
|
1999-09-08 07:58:57 +04:00
|
|
|
if (!aUri)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-03-12 08:20:29 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1999-08-30 09:54:37 +04:00
|
|
|
char buffer[512];
|
1999-09-08 07:58:57 +04:00
|
|
|
nsXPIDLCString uriSpec;
|
|
|
|
rv = aUri->GetSpec(getter_Copies(uriSpec));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-12 08:20:29 +03:00
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-04-30 04:10:27 +04:00
|
|
|
("DocLoader:%p: LoadSubDocument(...) called for %s.",
|
1999-09-08 07:58:57 +04:00
|
|
|
this, (const char *) uriSpec));
|
1999-03-12 08:20:29 +03:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
NS_NEWXPCOM(loader, nsDocumentBindInfo);
|
|
|
|
if (nsnull == loader) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return rv;
|
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
NS_ADDREF(loader);
|
1999-03-12 08:20:29 +03:00
|
|
|
loader->Init(this, // DocLoader
|
|
|
|
nsnull, // Command
|
|
|
|
nsnull, // Viewer Container
|
|
|
|
aExtraInfo, // Extra Info
|
|
|
|
mStreamObserver); // Observer
|
|
|
|
|
|
|
|
|
1999-09-08 07:58:57 +04:00
|
|
|
rv = loader->Bind(aUri, nsnull, nsnull);
|
1999-07-16 15:14:36 +04:00
|
|
|
NS_RELEASE(loader);
|
1999-03-12 08:20:29 +03:00
|
|
|
return rv;
|
|
|
|
}
|
1998-10-09 09:49:34 +04:00
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::Stop(void)
|
|
|
|
{
|
1999-07-01 23:30:20 +04:00
|
|
|
nsresult rv = NS_OK;
|
1999-01-15 13:10:46 +03:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-04-30 04:10:27 +04:00
|
|
|
("DocLoader:%p: Stop() called\n", this));
|
1999-07-01 23:30:20 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
rv = mLoadGroup->Cancel();
|
|
|
|
#else
|
1998-10-02 01:48:12 +04:00
|
|
|
m_LoadingDocsList->EnumerateForwards(nsDocLoaderImpl::StopBindInfoEnumerator, nsnull);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now the only reference to each nsDocumentBindInfo instance is held by
|
|
|
|
* Netlib via the nsIStreamListener interface...
|
|
|
|
*
|
|
|
|
* When each connection is aborted, Netlib will release its reference to
|
|
|
|
* the StreamListener and the DocumentBindInfo object will be deleted...
|
|
|
|
*/
|
|
|
|
m_LoadingDocsList->Clear();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now Stop() all documents being loaded by child DocumentLoaders...
|
|
|
|
*/
|
|
|
|
mChildGroupList.EnumerateForwards(nsDocLoaderImpl::StopDocLoaderEnumerator, nsnull);
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-10 08:33:29 +04:00
|
|
|
/* Reset the URL counters... */
|
|
|
|
mForegroundURLs = 0;
|
|
|
|
mTotalURLs = 0;
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1998-10-10 08:33:29 +04:00
|
|
|
|
1998-10-30 10:10:10 +03:00
|
|
|
/*
|
|
|
|
* Release the Stream Observer...
|
|
|
|
* It will be set on the next LoadDocument(...)
|
|
|
|
*/
|
1999-04-30 13:04:36 +04:00
|
|
|
mStreamObserver = do_QueryInterface(0); // to be replaced with null_nsCOMPtr()
|
1998-10-30 10:10:10 +03: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-07-16 15:14:36 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
return mLoadGroup->IsPending(&aResult);
|
|
|
|
#else
|
1998-10-02 01:48:12 +04:00
|
|
|
aResult = PR_FALSE;
|
|
|
|
|
|
|
|
/* If this document loader is busy? */
|
1998-10-10 08:33:29 +04:00
|
|
|
if (0 != mForegroundURLs) {
|
1998-10-02 01:48:12 +04:00
|
|
|
aResult = PR_TRUE;
|
|
|
|
}
|
|
|
|
/* Otherwise, check its child document loaders... */
|
|
|
|
else {
|
|
|
|
mChildGroupList.EnumerateForwards(nsDocLoaderImpl::IsBusyEnumerator,
|
1998-12-29 07:45:00 +03:00
|
|
|
(void*)&aResult);
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
// Make sure the observer isn't already in the list
|
1998-10-09 09:49:34 +04:00
|
|
|
if (mDocObservers.IndexOf(aObserver) == -1) {
|
|
|
|
mDocObservers.AppendElement(aObserver);
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
nsDocLoaderImpl::SetContainer(nsIContentViewerContainer* aContainer)
|
|
|
|
{
|
|
|
|
mContainer = aContainer;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::GetContainer(nsIContentViewerContainer** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
|
|
|
*aResult = mContainer;
|
1999-04-30 13:04:36 +04:00
|
|
|
NS_IF_ADDREF(*aResult);
|
1999-01-14 09:44:23 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
1998-10-02 01:48:12 +04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 07:29:44 +04:00
|
|
|
nsDocLoaderImpl::CreateURL(nsIURI** aInstancePtrResult,
|
|
|
|
nsIURI* aBaseURL,
|
1998-10-02 01:48:12 +04:00
|
|
|
const nsString& aURLSpec,
|
|
|
|
nsISupports* aContainer)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* url = nsnull;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
/* Check for initial error conditions... */
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-10 01:18:47 +04:00
|
|
|
rv = NS_NewURI(&url, aURLSpec, aBaseURL);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1998-12-16 08:40:20 +03:00
|
|
|
rv = NS_NewURL(&url, aURLSpec, aBaseURL, aContainer, this);
|
1998-10-02 01:48:12 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-04-30 13:04:36 +04:00
|
|
|
nsCOMPtr<nsILoadAttribs> loadAttributes;
|
|
|
|
rv = url->GetLoadAttribs(getter_AddRefs(loadAttributes));
|
|
|
|
if (loadAttributes)
|
1998-10-10 08:33:29 +04:00
|
|
|
loadAttributes->Clone(m_LoadAttrib);
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1998-10-02 01:48:12 +04:00
|
|
|
*aInstancePtrResult = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-23 07:29:44 +04:00
|
|
|
nsDocLoaderImpl::OpenStream(nsIURI *aUrl, nsIStreamListener *aConsumer)
|
1998-10-02 01:48:12 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsDocumentBindInfo* loader = nsnull;
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
#if defined(DEBUG)
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
char* buffer;
|
|
|
|
#else
|
1999-01-15 13:10:46 +03:00
|
|
|
const char* buffer;
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-01-15 13:10:46 +03:00
|
|
|
aUrl->GetSpec(&buffer);
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-04-30 04:10:27 +04:00
|
|
|
("DocLoader:%p: OpenStream(...) called for %s.",
|
|
|
|
this, buffer));
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(buffer);
|
|
|
|
#endif
|
1999-01-15 13:10:46 +03:00
|
|
|
#endif /* DEBUG */
|
1999-06-28 18:02:28 +04:00
|
|
|
|
|
|
|
#ifndef NECKO
|
1999-06-28 14:35:57 +04:00
|
|
|
nsURLLoadType loadType;
|
1999-06-28 18:02:28 +04:00
|
|
|
#endif // NECKO
|
1999-01-15 13:10:46 +03:00
|
|
|
|
1998-10-02 01:48:12 +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
|
|
|
|
nsnull, // Command
|
1999-01-14 09:44:23 +03:00
|
|
|
mContainer, // Viewer Container
|
1998-10-09 09:49:34 +04:00
|
|
|
nsnull, // Extra Info
|
|
|
|
mStreamObserver); // Observer
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
#ifndef NECKO // done in the load group now
|
1998-10-02 01:48:12 +04:00
|
|
|
/* The DocumentBindInfo reference is only held by the Array... */
|
|
|
|
m_LoadingDocsList->AppendElement(((nsISupports*)(nsIStreamObserver*)loader));
|
1998-10-10 08:33:29 +04:00
|
|
|
|
|
|
|
/* Update the URL counters... */
|
|
|
|
nsILoadAttribs* loadAttributes;
|
|
|
|
|
1998-12-16 08:40:20 +03:00
|
|
|
rv = aUrl->GetLoadAttribs(&loadAttributes);
|
1999-06-28 14:35:57 +04:00
|
|
|
loadType = nsURLLoadNormal;
|
1999-03-29 13:21:01 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1998-10-10 08:33:29 +04:00
|
|
|
rv = loadAttributes->GetLoadType(&loadType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
loadType = nsURLLoadNormal;
|
|
|
|
}
|
|
|
|
NS_RELEASE(loadAttributes);
|
|
|
|
}
|
|
|
|
if (nsURLLoadBackground != loadType) {
|
|
|
|
mForegroundURLs += 1;
|
|
|
|
}
|
|
|
|
mTotalURLs += 1;
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
rv = loader->Bind(aUrl, aConsumer);
|
|
|
|
done:
|
1999-07-16 15:14:36 +04:00
|
|
|
NS_RELEASE(loader);
|
1998-10-02 01:48:12 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-01 23:30:20 +04:00
|
|
|
nsDocLoaderImpl::GetDefaultLoadAttributes(nsLoadFlags *aLoadAttribs)
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1998-10-02 01:48:12 +04:00
|
|
|
nsDocLoaderImpl::GetDefaultLoadAttributes(nsILoadAttribs*& aLoadAttribs)
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-10-02 01:48:12 +04:00
|
|
|
{
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-16 15:14:36 +04:00
|
|
|
return mLoadGroup->GetDefaultLoadAttributes(aLoadAttribs);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1998-10-02 01:48:12 +04:00
|
|
|
aLoadAttribs = m_LoadAttrib;
|
1999-04-30 13:04:36 +04:00
|
|
|
NS_IF_ADDREF(aLoadAttribs);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
return NS_OK;;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-01 23:30:20 +04:00
|
|
|
nsDocLoaderImpl::SetDefaultLoadAttributes(nsLoadFlags aLoadAttribs)
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1998-10-02 01:48:12 +04:00
|
|
|
nsDocLoaderImpl::SetDefaultLoadAttributes(nsILoadAttribs* aLoadAttribs)
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-10-02 01:48:12 +04:00
|
|
|
{
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-16 15:14:36 +04:00
|
|
|
return mLoadGroup->SetDefaultLoadAttributes(aLoadAttribs);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1998-10-02 01:48:12 +04:00
|
|
|
m_LoadAttrib->Clone(aLoadAttribs);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now set the default attributes for all child DocumentLoaders...
|
|
|
|
*/
|
|
|
|
PRInt32 count = mChildGroupList.Count();
|
|
|
|
PRInt32 index;
|
|
|
|
|
|
|
|
for (index = 0; index < count; index++) {
|
1999-06-25 06:31:51 +04:00
|
|
|
nsILoadGroup* child = (nsILoadGroup*)mChildGroupList.ElementAt(index);
|
1998-10-02 01:48:12 +04:00
|
|
|
child->SetDefaultLoadAttributes(m_LoadAttrib);
|
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::OnStartRequest(nsIChannel *channel, nsISupports *ctxt)
|
|
|
|
{
|
1999-07-31 10:33:50 +04:00
|
|
|
// called when the group gets its first element
|
1999-07-16 15:14:36 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) return 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) {
|
|
|
|
FireOnStartDocumentLoad(this, uri, "load"); // XXX fix command
|
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::OnStopRequest(nsIChannel *channel, nsISupports *ctxt,
|
|
|
|
nsresult status, const PRUnichar *errorMsg)
|
|
|
|
{
|
1999-08-27 02:45:55 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Is now idle...\n", this));
|
|
|
|
|
|
|
|
//
|
|
|
|
// Only fire the OnEndDocumentLoad(...) if the document loader
|
|
|
|
// has initiated a load...
|
|
|
|
//
|
|
|
|
if (mIsLoadingDocument) {
|
|
|
|
mIsLoadingDocument = PR_FALSE;
|
|
|
|
FireOnEndDocumentLoad(this, status);
|
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-25 06:31:51 +04:00
|
|
|
nsDocLoaderImpl::AddChildGroup(nsILoadGroup* aGroup)
|
1998-10-02 01:48:12 +04:00
|
|
|
{
|
1999-07-16 15:14:36 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
return mLoadGroup->AddSubGroup(aGroup);
|
|
|
|
#else
|
1998-10-02 01:48:12 +04:00
|
|
|
mChildGroupList.AppendElement(aGroup);
|
|
|
|
return NS_OK;
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-25 06:31:51 +04:00
|
|
|
nsDocLoaderImpl::RemoveChildGroup(nsILoadGroup* aGroup)
|
1998-10-02 01:48:12 +04:00
|
|
|
{
|
1999-07-16 15:14:36 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
return mLoadGroup->RemoveSubGroup(aGroup);
|
|
|
|
#else
|
1998-10-02 01:48:12 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (PR_FALSE == mChildGroupList.RemoveElement(aGroup)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return rv;
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
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);
|
|
|
|
newListener->Init(this, aListener);
|
|
|
|
|
|
|
|
*aResult = newListener;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void nsDocLoaderImpl::FireOnStartDocumentLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* aURL,
|
1999-03-29 13:21:01 +04:00
|
|
|
const char* aCommand)
|
|
|
|
{
|
|
|
|
PRInt32 count = mDocObservers.Count();
|
|
|
|
PRInt32 index;
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
#if defined(DEBUG)
|
|
|
|
#ifdef NECKO
|
|
|
|
char *buffer;
|
|
|
|
#else
|
|
|
|
const char *buffer;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
aURL->GetSpec(&buffer);
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: Firing OnStartDocumentLoad(...) called for [DocLoader:%p] %s.\n",
|
|
|
|
this, aLoadInitiator, buffer));
|
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(buffer);
|
|
|
|
#endif
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
/*
|
|
|
|
* First notify any observers that the URL load has begun...
|
|
|
|
*/
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIDocumentLoaderObserver* observer = (nsIDocumentLoaderObserver*)mDocObservers.ElementAt(index);
|
1999-05-06 10:52:05 +04:00
|
|
|
observer->OnStartDocumentLoad(aLoadInitiator, aURL, aCommand);
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally notify the parent...
|
|
|
|
*/
|
|
|
|
if (nsnull != mParent) {
|
1999-05-06 10:52:05 +04:00
|
|
|
mParent->FireOnStartDocumentLoad(aLoadInitiator, aURL, aCommand);
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void nsDocLoaderImpl::FireOnEndDocumentLoad(nsDocLoaderImpl* aLoadInitiator,
|
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)
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_OK;
|
1999-08-27 02:45:55 +04:00
|
|
|
if (aLoadInitiator->mDocumentChannel)
|
|
|
|
rv = aLoadInitiator->mDocumentChannel->GetURI(getter_AddRefs(uri));
|
1999-07-31 10:33:50 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-09-02 01:50:32 +04:00
|
|
|
char* buffer = nsnull;
|
1999-07-31 10:33:50 +04:00
|
|
|
if (uri)
|
|
|
|
rv = uri->GetSpec(&buffer);
|
1999-09-02 01:50:32 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && buffer != nsnull) {
|
1999-07-31 10:33:50 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-08-27 02:45:55 +04:00
|
|
|
("DocLoader:%p: Firing OnEndDocumentLoad(...) called for [DocLoader:%p] %s\n",
|
|
|
|
this, aLoadInitiator, buffer));
|
1999-07-31 10:33:50 +04:00
|
|
|
nsCRT::free(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
1999-04-30 04:10:27 +04:00
|
|
|
/*
|
|
|
|
* First notify any observers that the document load has finished...
|
|
|
|
*/
|
1999-08-27 02:45:55 +04:00
|
|
|
PRInt32 count = mDocObservers.Count();
|
|
|
|
PRInt32 index;
|
|
|
|
|
1999-04-30 04:10:27 +04:00
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIDocumentLoaderObserver* observer = (nsIDocumentLoaderObserver*)
|
|
|
|
mDocObservers.ElementAt(index);
|
1999-06-28 14:35:57 +04:00
|
|
|
observer->OnEndDocumentLoad(aLoadInitiator,
|
|
|
|
#ifdef NECKO
|
1999-08-27 02:45:55 +04:00
|
|
|
aLoadInitiator->mDocumentChannel,
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
|
|
|
mDocumentUrl,
|
|
|
|
#endif
|
1999-06-15 02:12:19 +04:00
|
|
|
aStatus, observer);
|
1999-04-30 04:10:27 +04:00
|
|
|
}
|
1999-08-27 02:45:55 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
/*
|
|
|
|
* Next notify the parent...
|
|
|
|
*/
|
|
|
|
if (nsnull != mParent) {
|
|
|
|
mParent->FireOnEndDocumentLoad(aLoadInitiator, aStatus);
|
|
|
|
}
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
#else // !NECKO
|
1999-04-30 04:10:27 +04:00
|
|
|
/*
|
|
|
|
* Finally notify the parent...
|
|
|
|
*/
|
|
|
|
if (nsnull != mParent) {
|
1999-07-31 10:33:50 +04:00
|
|
|
mParent->ChildDocLoaderFiredEndDocumentLoad(this, aLoadInitiator, aStatus);
|
1999-04-30 04:10:27 +04:00
|
|
|
}
|
1999-08-27 02:45:55 +04:00
|
|
|
#endif // !NECKO
|
1999-04-30 04:10:27 +04:00
|
|
|
}
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
#ifndef NECKO
|
1999-04-30 04:10:27 +04:00
|
|
|
void
|
|
|
|
nsDocLoaderImpl::ChildDocLoaderFiredEndDocumentLoad(nsDocLoaderImpl* aChild,
|
1999-05-06 10:52:05 +04:00
|
|
|
nsIDocumentLoader* aLoadInitiator,
|
1999-08-05 05:28:30 +04:00
|
|
|
nsresult aStatus)
|
1999-04-30 04:10:27 +04:00
|
|
|
{
|
|
|
|
PRBool busy;
|
|
|
|
IsBusy(busy);
|
|
|
|
if (!busy) {
|
|
|
|
// If the parent is no longer busy because a child document
|
|
|
|
// loader finished, then its time for the parent to fire its
|
|
|
|
// on-end-document-load notification.
|
1999-07-31 10:33:50 +04:00
|
|
|
FireOnEndDocumentLoad(aLoadInitiator, 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
|
|
|
#endif // !NECKO
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void nsDocLoaderImpl::FireOnStartURLLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
nsIChannel* channel,
|
|
|
|
#else
|
|
|
|
nsIURI* aURL,
|
|
|
|
const char* aContentType,
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
nsIContentViewer* aViewer)
|
1999-01-14 09:44:23 +03:00
|
|
|
{
|
|
|
|
PRInt32 count = mDocObservers.Count();
|
|
|
|
PRInt32 index;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First notify any observers that the URL load has begun...
|
|
|
|
*/
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIDocumentLoaderObserver* observer = (nsIDocumentLoaderObserver*)mDocObservers.ElementAt(index);
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-16 15:14:36 +04:00
|
|
|
observer->OnStartURLLoad(aLoadInitiator, channel, aViewer);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-05-06 10:52:05 +04:00
|
|
|
observer->OnStartURLLoad(aLoadInitiator, aURL, aContentType, aViewer);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-01-14 09:44:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally notify the parent...
|
|
|
|
*/
|
|
|
|
if (nsnull != mParent) {
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-16 15:14:36 +04:00
|
|
|
mParent->FireOnStartURLLoad(aLoadInitiator, channel, aViewer);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-05-06 10:52:05 +04:00
|
|
|
mParent->FireOnStartURLLoad(aLoadInitiator, aURL, aContentType, aViewer);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void nsDocLoaderImpl::FireOnProgressURLLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
nsIChannel* channel,
|
|
|
|
#else
|
|
|
|
nsIURI* aURL,
|
|
|
|
#endif
|
|
|
|
PRUint32 aProgress,
|
1999-03-29 13:21:01 +04:00
|
|
|
PRUint32 aProgressMax)
|
|
|
|
{
|
|
|
|
PRInt32 count = mDocObservers.Count();
|
|
|
|
PRInt32 index;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First notify any observers that there is progress information available...
|
|
|
|
*/
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIDocumentLoaderObserver* observer = (nsIDocumentLoaderObserver*)mDocObservers.ElementAt(index);
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
observer->OnProgressURLLoad(aLoadInitiator, channel, aProgress, aProgressMax);
|
|
|
|
#else
|
1999-05-06 10:52:05 +04:00
|
|
|
observer->OnProgressURLLoad(aLoadInitiator, aURL, aProgress, aProgressMax);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally notify the parent...
|
|
|
|
*/
|
|
|
|
if (nsnull != mParent) {
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
mParent->FireOnProgressURLLoad(aLoadInitiator, channel, aProgress, aProgressMax);
|
|
|
|
#else
|
1999-05-06 10:52:05 +04:00
|
|
|
mParent->FireOnProgressURLLoad(aLoadInitiator, aURL, aProgress, aProgressMax);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
void nsDocLoaderImpl::FireOnStatusURLLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
nsIChannel* channel,
|
|
|
|
#else
|
|
|
|
nsIURI* aURL,
|
|
|
|
#endif
|
|
|
|
nsString& aMsg)
|
1999-03-29 13:21:01 +04:00
|
|
|
{
|
|
|
|
PRInt32 count = mDocObservers.Count();
|
|
|
|
PRInt32 index;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First notify any observers that there is status text available...
|
|
|
|
*/
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIDocumentLoaderObserver* observer = (nsIDocumentLoaderObserver*)mDocObservers.ElementAt(index);
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
observer->OnStatusURLLoad(aLoadInitiator, channel, aMsg);
|
|
|
|
#else
|
1999-05-06 10:52:05 +04:00
|
|
|
observer->OnStatusURLLoad(aLoadInitiator, aURL, aMsg);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally notify the parent...
|
|
|
|
*/
|
|
|
|
if (nsnull != mParent) {
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
mParent->FireOnStatusURLLoad(aLoadInitiator, channel, aMsg);
|
|
|
|
#else
|
1999-05-06 10:52:05 +04:00
|
|
|
mParent->FireOnStatusURLLoad(aLoadInitiator, aURL, aMsg);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-08-27 02:45:55 +04:00
|
|
|
void nsDocLoaderImpl::FireOnEndURLLoad(nsDocLoaderImpl* aLoadInitiator,
|
1999-08-05 05:28:30 +04:00
|
|
|
nsIChannel* channel, nsresult aStatus)
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-05-06 10:52:05 +04:00
|
|
|
void nsDocLoaderImpl::FireOnEndURLLoad(nsIDocumentLoader* aLoadInitiator,
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* aURL, PRInt32 aStatus)
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
{
|
|
|
|
PRInt32 count = mDocObservers.Count();
|
|
|
|
PRInt32 index;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First notify any observers that the URL load has begun...
|
|
|
|
*/
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIDocumentLoaderObserver* observer = (nsIDocumentLoaderObserver*)mDocObservers.ElementAt(index);
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
observer->OnEndURLLoad(aLoadInitiator, channel, aStatus);
|
|
|
|
#else
|
1999-05-06 10:52:05 +04:00
|
|
|
observer->OnEndURLLoad(aLoadInitiator, aURL, aStatus);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally notify the parent...
|
|
|
|
*/
|
|
|
|
if (nsnull != mParent) {
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
mParent->FireOnEndURLLoad(aLoadInitiator, channel, aStatus);
|
|
|
|
#else
|
1999-05-06 10:52:05 +04:00
|
|
|
mParent->FireOnEndURLLoad(aLoadInitiator, aURL, aStatus);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-01-14 09:44:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-20 12:46:33 +04:00
|
|
|
nsresult nsDocLoaderImpl::LoadURLComplete(nsIChannel* channel, nsISupports* ctxt,
|
1999-08-05 05:28:30 +04:00
|
|
|
nsISupports* aBindInfo, nsresult aStatus,
|
1999-07-20 12:46:33 +04:00
|
|
|
const PRUnichar* aMsg)
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-07-20 12:46:33 +04:00
|
|
|
nsresult nsDocLoaderImpl::LoadURLComplete(nsIURI* aURL, nsISupports* aBindInfo, PRInt32 aStatus)
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
1999-04-30 04:10:27 +04:00
|
|
|
/*
|
|
|
|
* If the entry is not found in the list, then it must have been cancelled
|
|
|
|
* via Stop(...). So ignore just it...
|
|
|
|
*/
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-16 15:14:36 +04:00
|
|
|
#if defined(DEBUG)
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = channel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
char* buffer;
|
|
|
|
rv = uri->GetSpec(&buffer);
|
1999-06-28 14:35:57 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-07-16 15:14:36 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: LoadURLComplete(...) called for %s\n",
|
|
|
|
this, buffer));
|
|
|
|
nsCRT::free(buffer);
|
1999-06-28 14:35:57 +04:00
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
1999-07-20 12:46:33 +04:00
|
|
|
#else // !NECKO
|
|
|
|
PRBool isForegroundURL = PR_FALSE;
|
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
PRBool removed = m_LoadingDocsList->RemoveElement(aBindInfo);
|
|
|
|
if (removed) {
|
1999-04-30 04:10:27 +04:00
|
|
|
nsILoadAttribs* loadAttributes;
|
|
|
|
nsURLLoadType loadType = nsURLLoadNormal;
|
|
|
|
|
|
|
|
nsresult rv = aURL->GetLoadAttribs(&loadAttributes);
|
|
|
|
if (NS_SUCCEEDED(rv) && loadAttributes) {
|
|
|
|
rv = loadAttributes->GetLoadType(&loadType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
loadType = nsURLLoadNormal;
|
|
|
|
}
|
|
|
|
NS_RELEASE(loadAttributes);
|
|
|
|
}
|
|
|
|
if (nsURLLoadBackground != loadType) {
|
|
|
|
mForegroundURLs--;
|
|
|
|
isForegroundURL = PR_TRUE;
|
|
|
|
}
|
|
|
|
mTotalURLs -= 1;
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-04-30 04:10:27 +04:00
|
|
|
NS_ASSERTION(mTotalURLs >= mForegroundURLs,
|
|
|
|
"Foreground URL count is wrong.");
|
1998-08-12 08:56:40 +04:00
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
#if defined(DEBUG)
|
1999-04-30 04:10:27 +04:00
|
|
|
const char* buffer;
|
1999-01-20 01:48:05 +03:00
|
|
|
|
1999-04-30 04:10:27 +04:00
|
|
|
aURL->GetSpec(&buffer);
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: LoadURLComplete(...) called for %s; Foreground URLs: %d; Total URLs: %d\n",
|
|
|
|
this, buffer, mForegroundURLs, mTotalURLs));
|
1999-01-20 01:48:05 +03:00
|
|
|
#endif /* DEBUG */
|
1999-04-30 04:10:27 +04:00
|
|
|
}
|
1999-07-20 12:46:33 +04:00
|
|
|
#endif // !NECKO
|
1999-01-20 01:48:05 +03:00
|
|
|
|
1999-04-30 04:10:27 +04:00
|
|
|
/*
|
|
|
|
* Fire the OnEndURLLoad notification to any observers...
|
|
|
|
*/
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-08-27 02:45:55 +04:00
|
|
|
/// FireOnEndURLLoad((nsIDocumentLoader *) this, channel, aStatus);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-05-06 10:52:05 +04:00
|
|
|
FireOnEndURLLoad((nsIDocumentLoader *) this, aURL, aStatus);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-04-13 04:19:48 +04:00
|
|
|
|
1999-07-20 12:46:33 +04:00
|
|
|
#ifdef NECKO
|
1999-08-27 02:45:55 +04:00
|
|
|
/// return GetLoadGroup()->RemoveChannel(channel, ctxt, aStatus, aMsg);
|
|
|
|
return NS_OK;
|
1999-07-31 10:33:50 +04:00
|
|
|
#else // !NECKO
|
1999-04-30 04:10:27 +04:00
|
|
|
/*
|
|
|
|
* Fire the OnEndDocumentLoad notification to any observers...
|
|
|
|
*/
|
|
|
|
PRBool busy;
|
|
|
|
IsBusy(busy);
|
|
|
|
if (isForegroundURL && !busy) {
|
1999-03-29 13:21:01 +04:00
|
|
|
#if defined(DEBUG)
|
1999-04-30 04:10:27 +04:00
|
|
|
const char* buffer;
|
1999-06-28 14:35:57 +04:00
|
|
|
nsIURI* uri = mDocumentUrl;
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
uri->GetSpec(&buffer);
|
1999-04-30 04:10:27 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader:%p: OnEndDocumentLoad(...) called for %s.\n",
|
|
|
|
this, buffer));
|
1999-03-29 13:21:01 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
1999-07-31 10:33:50 +04:00
|
|
|
FireOnEndDocumentLoad((nsIDocumentLoader *) this, aStatus);
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
1999-07-20 12:46:33 +04:00
|
|
|
return NS_OK;
|
1999-07-31 10:33:50 +04:00
|
|
|
#endif // !NECKO
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
void nsDocLoaderImpl::SetParent(nsDocLoaderImpl* aParent)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mParent);
|
|
|
|
mParent = aParent;
|
|
|
|
NS_IF_ADDREF(mParent);
|
|
|
|
}
|
|
|
|
|
1999-07-31 10:33:50 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
void nsDocLoaderImpl::SetDocumentChannel(nsIChannel* channel)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mDocumentChannel);
|
|
|
|
mDocumentChannel = channel;
|
|
|
|
NS_IF_ADDREF(mDocumentChannel);
|
|
|
|
}
|
|
|
|
#else
|
1999-06-23 07:29:44 +04:00
|
|
|
void nsDocLoaderImpl::SetDocumentUrl(nsIURI* aUrl)
|
1999-03-29 13:21:01 +04:00
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mDocumentUrl);
|
|
|
|
mDocumentUrl = aUrl;
|
|
|
|
NS_IF_ADDREF(mDocumentUrl);
|
|
|
|
}
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
#ifndef NECKO
|
1998-07-22 15:23:32 +04:00
|
|
|
PRBool nsDocLoaderImpl::StopBindInfoEnumerator(nsISupports* aElement, void* aData)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsDocumentBindInfo* bindInfo;
|
|
|
|
|
|
|
|
rv = aElement->QueryInterface(kDocumentBindInfoIID, (void**)&bindInfo);
|
1999-03-29 13:21:01 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1998-07-22 15:23:32 +04:00
|
|
|
bindInfo->Stop();
|
1998-09-15 04:17:53 +04:00
|
|
|
NS_RELEASE(bindInfo);
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
PRBool nsDocLoaderImpl::StopDocLoaderEnumerator(void* aElement, void* aData)
|
1998-07-22 15:23:32 +04:00
|
|
|
{
|
1998-10-02 01:48:12 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsIDocumentLoader* docLoader;
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
rv = ((nsISupports*)aElement)->QueryInterface(kIDocumentLoaderIID, (void**)&docLoader);
|
1999-03-29 13:21:01 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1998-10-02 01:48:12 +04:00
|
|
|
docLoader->Stop();
|
|
|
|
NS_RELEASE(docLoader);
|
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
return PR_TRUE;
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
PRBool nsDocLoaderImpl::IsBusyEnumerator(void* aElement, void* aData)
|
1998-08-12 08:56:40 +04:00
|
|
|
{
|
1998-10-02 01:48:12 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsIDocumentLoader* docLoader;
|
1998-12-29 07:45:00 +03:00
|
|
|
PRBool* result = (PRBool*)aData;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
rv = ((nsISupports*)aElement)->QueryInterface(kIDocumentLoaderIID, (void**)&docLoader);
|
1999-03-29 13:21:01 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1998-12-29 07:45:00 +03:00
|
|
|
docLoader->IsBusy(*result);
|
1998-10-02 01:48:12 +04:00
|
|
|
NS_RELEASE(docLoader);
|
1998-08-12 08:56:40 +04:00
|
|
|
}
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1998-12-29 07:45:00 +03:00
|
|
|
return !(*result);
|
1998-08-12 08:56:40 +04:00
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1998-07-01 15:29:20 +04: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;
|
1999-07-16 15:14:36 +04:00
|
|
|
#ifndef NECKO
|
1998-09-15 04:17:53 +04:00
|
|
|
m_Url = nsnull;
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1998-09-15 04:17:53 +04:00
|
|
|
m_Container = nsnull;
|
|
|
|
m_ExtraInfo = nsnull;
|
|
|
|
m_Observer = nsnull;
|
|
|
|
m_NextStream = nsnull;
|
|
|
|
m_DocLoader = nsnull;
|
|
|
|
mStatus = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDocumentBindInfo::Init(nsDocLoaderImpl* aDocLoader,
|
|
|
|
const char *aCommand,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamObserver* anObserver)
|
|
|
|
{
|
1999-07-16 15:14:36 +04:00
|
|
|
#ifndef NECKO
|
1998-07-01 15:29:20 +04:00
|
|
|
m_Url = nsnull;
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
m_NextStream = nsnull;
|
|
|
|
m_Command = (nsnull != aCommand) ? PL_strdup(aCommand) : nsnull;
|
|
|
|
|
|
|
|
m_DocLoader = aDocLoader;
|
|
|
|
NS_ADDREF(m_DocLoader);
|
|
|
|
|
|
|
|
m_Container = aContainer;
|
|
|
|
NS_IF_ADDREF(m_Container);
|
|
|
|
|
|
|
|
m_Observer = anObserver;
|
|
|
|
NS_IF_ADDREF(m_Observer);
|
|
|
|
|
|
|
|
m_ExtraInfo = aExtraInfo;
|
|
|
|
NS_IF_ADDREF(m_ExtraInfo);
|
1998-09-15 04:17:53 +04:00
|
|
|
|
1998-11-26 21:06:08 +03:00
|
|
|
mStatus = NS_OK;
|
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);
|
1999-07-16 15:14:36 +04:00
|
|
|
#ifndef NECKO
|
1998-07-01 15:29:20 +04:00
|
|
|
NS_IF_RELEASE(m_Url);
|
1999-07-16 15:14:36 +04:00
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
NS_IF_RELEASE(m_NextStream);
|
|
|
|
NS_IF_RELEASE(m_Container);
|
|
|
|
NS_IF_RELEASE(m_Observer);
|
|
|
|
NS_IF_RELEASE(m_ExtraInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
if (aIID.Equals(kDocumentBindInfoIID)) {
|
|
|
|
*aInstancePtrResult = (void*) this;
|
1998-09-12 23:30:49 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-07-22 15:23:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifndef NECKO
|
1998-08-14 00:08:19 +04:00
|
|
|
if (aIID.Equals(kRefreshURLIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIRefreshUrl*)this);
|
1998-09-12 23:30:49 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-08-14 00:08:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-07-22 04:26:23 +04:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
class nsWebShellEventSinkGetter : public nsIEventSinkGetter {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsWebShellEventSinkGetter(nsIWebShell *aWebShell) {
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
mWebShell = aWebShell;
|
|
|
|
NS_IF_ADDREF(mWebShell);
|
|
|
|
}
|
|
|
|
|
1999-08-28 21:32:51 +04:00
|
|
|
virtual ~nsWebShellEventSinkGetter() {
|
1999-08-27 02:45:55 +04:00
|
|
|
NS_IF_RELEASE(mWebShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetEventSink(const char* aVerb, const nsIID& anIID, nsISupports** aSink) {
|
|
|
|
if (mWebShell) {
|
|
|
|
if (nsCRT::strcmp(aVerb, "load") == 0) {
|
|
|
|
return mWebShell->QueryInterface(anIID, (void**)aSink);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsIWebShell* mWebShell;
|
|
|
|
};
|
|
|
|
|
|
|
|
// XXXbe second arg is unnecessary given first; hidden static IID in macro... scc help!
|
|
|
|
NS_IMPL_ISUPPORTS(nsWebShellEventSinkGetter, nsCOMTypeInfo<nsIEventSinkGetter>::GetIID())
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1999-08-04 19:06:51 +04:00
|
|
|
nsresult nsDocumentBindInfo::Bind(nsIURI* aURL, nsIStreamListener* aListener, nsIInputStream *postDataStream)
|
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-04-07 01:01:04 +04:00
|
|
|
// m_DocLoader->FireOnStartDocumentLoad(aURL, m_Command);
|
1999-03-29 13:21:01 +04:00
|
|
|
|
|
|
|
/* Set up the stream listener (if provided)... */
|
|
|
|
if (nsnull != aListener) {
|
|
|
|
m_NextStream = aListener;
|
|
|
|
NS_ADDREF(m_NextStream);
|
|
|
|
}
|
|
|
|
|
1999-07-10 01:18:47 +04:00
|
|
|
nsILoadGroup* loadGroup = nsnull;
|
|
|
|
if (m_DocLoader) {
|
|
|
|
loadGroup = m_DocLoader->GetLoadGroup();
|
|
|
|
}
|
1999-07-16 15:14:36 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
// XXXbe this knows that m_Container implements nsIWebShell
|
|
|
|
nsCOMPtr<nsIWebShell> webShell = do_QueryInterface(m_Container);
|
|
|
|
nsCOMPtr<nsIEventSinkGetter> eventSinkGetter = new nsWebShellEventSinkGetter(webShell);
|
|
|
|
if (!eventSinkGetter)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
1999-08-27 02:45:55 +04:00
|
|
|
rv = NS_OpenURI(getter_AddRefs(channel), aURL, loadGroup, eventSinkGetter);
|
1999-07-16 15:14:36 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-08-04 19:06:51 +04:00
|
|
|
if (postDataStream)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTTPChannel> httpChannel(do_QueryInterface(channel));
|
|
|
|
if (httpChannel)
|
|
|
|
{
|
|
|
|
httpChannel->SetRequestMethod(HM_POST);
|
|
|
|
httpChannel->SetPostDataStream(postDataStream);
|
|
|
|
}
|
|
|
|
}
|
1999-07-31 10:33:50 +04:00
|
|
|
m_DocLoader->SetDocumentChannel(channel);
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
/// rv = loadGroup->AddChannel(channel, nsnull);
|
|
|
|
/// if (NS_FAILED(rv)) return rv;
|
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-08-27 02:45:55 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
nsresult nsDocumentBindInfo::Bind(nsIStreamListener *aListener)
|
|
|
|
{
|
|
|
|
m_NextStream = aListener;
|
|
|
|
NS_IF_ADDREF(m_NextStream);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // NECKO
|
|
|
|
|
1999-07-16 15:14:36 +04:00
|
|
|
#ifndef NECKO
|
1998-07-22 15:23:32 +04:00
|
|
|
nsresult nsDocumentBindInfo::Stop(void)
|
|
|
|
{
|
1998-10-17 02:30:57 +04:00
|
|
|
nsresult rv;
|
1999-03-29 13:21:01 +04:00
|
|
|
if (m_Url == nsnull) return NS_OK;
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
char* spec;
|
|
|
|
#else
|
1998-12-16 08:40:20 +03:00
|
|
|
const char* spec;
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-12-16 08:40:20 +03:00
|
|
|
rv = m_Url->GetSpec(&spec);
|
1999-04-30 04:10:27 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1998-12-16 08:40:20 +03:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
1999-04-30 04:10:27 +04:00
|
|
|
("DocumentBindInfo:%p: Stop(...) called for %s.\n", this, spec));
|
|
|
|
}
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(spec);
|
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
#endif /* DEBUG */
|
1998-10-17 02:30:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the IStreamListener as being aborted... If more data is pushed
|
|
|
|
* down the stream, the connection will be aborted...
|
|
|
|
*/
|
|
|
|
mStatus = NS_BINDING_ABORTED;
|
|
|
|
|
|
|
|
/* Stop the URL binding process... */
|
1999-06-18 21:34:08 +04:00
|
|
|
#ifndef NECKO
|
|
|
|
nsINetService* inet;
|
1998-10-17 02:30:57 +04:00
|
|
|
rv = nsServiceManager::GetService(kNetServiceCID,
|
|
|
|
kINetServiceIID,
|
|
|
|
(nsISupports **)&inet);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = inet->InterruptStream(m_Url);
|
|
|
|
nsServiceManager::ReleaseService(kNetServiceCID, inet);
|
|
|
|
}
|
1999-06-18 21:34:08 +04:00
|
|
|
#else
|
|
|
|
// XXX NECKO
|
|
|
|
// need to interrupt the load;
|
|
|
|
#endif // NECKO
|
1998-10-17 02:30:57 +04:00
|
|
|
|
|
|
|
return rv;
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
|
|
|
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::GetBindInfo(nsIURI* aURL, nsStreamBindingInfo* aInfo)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_PRECONDITION(nsnull !=m_NextStream, "DocLoader: No stream for document");
|
|
|
|
|
|
|
|
if (nsnull != m_NextStream) {
|
1998-12-16 08:40:20 +03:00
|
|
|
rv = m_NextStream->GetBindInfo(aURL, aInfo);
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-07 12:08:40 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::OnProgress(nsIChannel* channel, nsISupports *ctxt,
|
|
|
|
PRUint32 aProgress, PRUint32 aProgressMax)
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
|
|
|
NS_METHOD nsDocumentBindInfo::OnProgress(nsIURI* aURL, PRUint32 aProgress, PRUint32 aProgressMax)
|
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
#endif
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
#if defined(DEBUG)
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
char* spec;
|
|
|
|
#else
|
1998-12-16 08:40:20 +03:00
|
|
|
const char* spec;
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
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-04-30 04:10:27 +04:00
|
|
|
("DocumentBindInfo:%p: OnProgress(...) called for %s. Progress: %d. ProgressMax: %d\n",
|
|
|
|
this, spec, aProgress, aProgressMax));
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(spec);
|
|
|
|
#endif
|
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
|
|
|
/* Pass the notification out to the next stream listener... */
|
|
|
|
if (nsnull != m_NextStream) {
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
// rv = m_NextStream->OnProgress(channel, aProgress, aProgressMax);
|
|
|
|
NS_ASSERTION(0, "help");
|
|
|
|
#else
|
1998-07-24 14:02:50 +04:00
|
|
|
rv = m_NextStream->OnProgress(aURL, aProgress, aProgressMax);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
/* Pass the notification out to any observers... */
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-08-27 02:45:55 +04:00
|
|
|
m_DocLoader->FireOnProgressURLLoad(m_DocLoader, channel, aProgress, aProgressMax);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-08-27 02:45:55 +04:00
|
|
|
m_DocLoader->FireOnProgressURLLoad(m_DocLoader, aURL, aProgress, aProgressMax);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
/* Pass the notification out to the Observer... */
|
|
|
|
if (nsnull != m_Observer) {
|
|
|
|
/* XXX: Should we ignore the return value? */
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
// (void) m_Observer->OnProgress(channel, aProgress, aProgressMax);
|
|
|
|
NS_ASSERTION(0, "help");
|
|
|
|
#else
|
1998-07-24 14:02:50 +04:00
|
|
|
(void) m_Observer->OnProgress(aURL, aProgress, aProgressMax);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-07-24 14:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-07 12:08:40 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::OnStatus(nsIChannel* channel, nsISupports *ctxt, const PRUnichar *aMsg)
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::OnStatus(nsIURI* aURL, const PRUnichar* aMsg)
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-07-24 14:02:50 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
#endif
|
|
|
|
|
1998-07-24 14:02:50 +04:00
|
|
|
/* Pass the notification out to the next stream listener... */
|
|
|
|
if (nsnull != m_NextStream) {
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
// rv = m_NextStream->OnStatus(ctxt, aMsg);
|
|
|
|
NS_ASSERTION(0, "help");
|
|
|
|
#else
|
1998-07-24 14:02:50 +04:00
|
|
|
rv = m_NextStream->OnStatus(aURL, aMsg);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-07-24 14:02:50 +04:00
|
|
|
}
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
/* Pass the notification out to any observers... */
|
1999-03-31 23:08:53 +04:00
|
|
|
nsString msgStr(aMsg);
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-08-27 02:45:55 +04:00
|
|
|
m_DocLoader->FireOnStatusURLLoad(m_DocLoader, channel, msgStr);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-08-27 02:45:55 +04:00
|
|
|
m_DocLoader->FireOnStatusURLLoad(m_DocLoader, aURL, msgStr);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1998-07-24 14:02:50 +04:00
|
|
|
/* Pass the notification out to the Observer... */
|
|
|
|
if (nsnull != m_Observer) {
|
|
|
|
/* XXX: Should we ignore the return value? */
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
// (void) m_Observer->OnStatus(ctxt, aMsg);
|
|
|
|
NS_ASSERTION(0, "help");
|
|
|
|
#else
|
1998-07-24 14:02:50 +04:00
|
|
|
(void) m_Observer->OnStatus(aURL, aMsg);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-05-06 23:31:59 +04:00
|
|
|
NS_IMETHODIMP
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-07 12:08:40 +04:00
|
|
|
nsDocumentBindInfo::OnStartRequest(nsIChannel* channel, nsISupports *ctxt)
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-07-01 23:30:20 +04:00
|
|
|
nsDocumentBindInfo::OnStartRequest(nsIURI* aURL, const char *aContentType)
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
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
|
|
|
#ifdef NECKO
|
|
|
|
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-29 02:50:14 +04:00
|
|
|
#endif // NECKO
|
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
|
|
|
#ifdef NECKO
|
|
|
|
char* spec;
|
|
|
|
#else
|
1998-12-16 08:40:20 +03:00
|
|
|
const char* spec;
|
1999-06-29 02:50:14 +04:00
|
|
|
#endif // NECKO
|
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
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(spec);
|
1999-06-29 02:50:14 +04:00
|
|
|
#endif // NECKO
|
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 the binding has been canceled via Stop() then abort the load... */
|
|
|
|
if (NS_BINDING_ABORTED == mStatus) {
|
|
|
|
rv = NS_BINDING_ABORTED;
|
1998-07-01 15:29:20 +04:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
#ifdef NECKO
|
|
|
|
channel,
|
|
|
|
#else
|
|
|
|
m_Url,
|
|
|
|
#endif
|
1999-05-06 23:31:59 +04:00
|
|
|
aContentType,
|
|
|
|
m_Container,
|
|
|
|
m_ExtraInfo,
|
|
|
|
&m_NextStream,
|
|
|
|
&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-04-08 08:21:15 +04:00
|
|
|
if ( m_Container ) {
|
|
|
|
// Give content container a chance to do something with this URL.
|
1999-06-28 18:02:28 +04:00
|
|
|
#ifndef NECKO
|
1999-04-28 10:47:40 +04:00
|
|
|
rv = m_Container->HandleUnknownContentType( (nsIDocumentLoader*) m_DocLoader, aURL, aContentType, m_Command );
|
1999-06-28 18:02:28 +04:00
|
|
|
#else
|
|
|
|
rv = m_Container->HandleUnknownContentType( (nsIDocumentLoader*) m_DocLoader, channel, aContentType, m_Command );
|
|
|
|
#endif // NECKO
|
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-03-12 08:20:29 +03:00
|
|
|
if (m_Container) {
|
|
|
|
viewer->SetContainer(m_Container);
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1999-03-12 08:20:29 +03:00
|
|
|
rv = m_Container->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
|
|
|
}
|
1999-01-14 09:44:23 +03: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-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-07 12:08:40 +04:00
|
|
|
rv = m_NextStream->OnStartRequest(channel, ctxt);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-07-01 23:30:20 +04:00
|
|
|
rv = m_NextStream->OnStartRequest(aURL, aContentType);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
1999-01-14 09:44:23 +03:00
|
|
|
/*
|
|
|
|
* Notify the DocumentLoadObserver(s)
|
|
|
|
*/
|
|
|
|
if ((nsnull == viewer) && (nsnull != m_Container)) {
|
1999-05-06 23:31:59 +04:00
|
|
|
m_Container->GetContentViewer(&viewer);
|
1999-01-14 09:44:23 +03:00
|
|
|
}
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-08-27 02:45:55 +04:00
|
|
|
/// m_DocLoader->FireOnStartURLLoad((nsIDocumentLoader *)m_DocLoader, channel, viewer);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-05-06 10:52:05 +04:00
|
|
|
m_DocLoader->FireOnStartURLLoad((nsIDocumentLoader *)m_DocLoader, m_Url, aContentType, viewer);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-01-14 09:44:23 +03:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
/* Pass the notification out to the Observer... */
|
|
|
|
if (nsnull != m_Observer) {
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-07 12:08:40 +04:00
|
|
|
nsresult rv2 = m_Observer->OnStartRequest(channel, ctxt);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-07-01 23:30:20 +04:00
|
|
|
nsresult rv2 = m_Observer->OnStartRequest(aURL, aContentType);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1999-03-29 13:21:01 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-01-16 01:34:46 +03:00
|
|
|
rv = rv2;
|
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
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(aContentType);
|
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
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)
|
|
|
|
#else
|
|
|
|
NS_METHOD nsDocumentBindInfo::OnDataAvailable(nsIURI* aURL, nsIInputStream *aStream, PRUint32 aLength)
|
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
#endif
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
#if defined(DEBUG)
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
char* spec;
|
|
|
|
#else
|
1998-12-16 08:40:20 +03:00
|
|
|
const char* spec;
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
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
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(spec);
|
|
|
|
#endif
|
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 the binding has been canceled via Stop() then abort the load... */
|
|
|
|
if (NS_BINDING_ABORTED == mStatus) {
|
|
|
|
rv = NS_BINDING_ABORTED;
|
|
|
|
goto done;
|
|
|
|
}
|
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...
|
|
|
|
*/
|
|
|
|
nsIStreamListener* listener = m_NextStream;
|
|
|
|
|
|
|
|
NS_ADDREF(listener);
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-07 12:08:40 +04:00
|
|
|
rv = listener->OnDataAvailable(channel, ctxt, aStream, sourceOffset, aLength);
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1998-11-10 10:06:02 +03:00
|
|
|
rv = listener->OnDataAvailable(aURL, aStream, aLength);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-11-10 10:06:02 +03:00
|
|
|
NS_RELEASE(listener);
|
1998-11-22 12:28:44 +03:00
|
|
|
} else {
|
|
|
|
rv = NS_BINDING_FAILED;
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
done:
|
1998-07-01 15:29:20 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
1999-07-07 12:08:40 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
|
|
|
|
nsresult aStatus, const PRUnichar *aMsg)
|
1999-06-28 14:35:57 +04:00
|
|
|
#else
|
1999-08-05 05:28:30 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::OnStopRequest(nsIURI* aURL, PRInt32 aStatus, const PRUnichar* aMsg)
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1999-03-29 13:21:01 +04:00
|
|
|
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
#endif
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
#if defined(DEBUG)
|
1999-06-28 14:35:57 +04:00
|
|
|
#ifdef NECKO
|
|
|
|
char* spec;
|
|
|
|
#else
|
1998-12-16 08:40:20 +03:00
|
|
|
const char* spec;
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
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
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(spec);
|
|
|
|
#endif
|
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-16 15:14:36 +04:00
|
|
|
#ifdef NECKO
|
1999-07-30 08:20:34 +04:00
|
|
|
char *url;
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
aURL->GetSpec(&url);
|
|
|
|
else
|
|
|
|
url = nsCRT::strdup("");
|
|
|
|
#else
|
|
|
|
const char *url;
|
|
|
|
if (nsnull != aURL)
|
|
|
|
aURL->GetSpec(&url);
|
|
|
|
else
|
|
|
|
url = "";
|
|
|
|
#endif // NECKO
|
|
|
|
|
|
|
|
#ifdef NECKO
|
|
|
|
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);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != m_NextStream) {
|
|
|
|
#ifdef NECKO
|
|
|
|
rv = m_NextStream->OnStopRequest(channel, ctxt, aStatus, aMsg);
|
|
|
|
#else
|
|
|
|
rv = m_NextStream->OnStopRequest(aURL, aStatus, aMsg);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pass the notification out to the Observer... */
|
|
|
|
if (nsnull != m_Observer) {
|
|
|
|
/* XXX: Should we ignore the return value? */
|
|
|
|
#ifdef NECKO
|
|
|
|
(void) m_Observer->OnStopRequest(channel, ctxt, aStatus, aMsg);
|
|
|
|
#else
|
|
|
|
(void) m_Observer->OnStopRequest(aURL, aStatus, aMsg);
|
|
|
|
#endif
|
|
|
|
}
|
1999-07-21 20:41:07 +04:00
|
|
|
|
1999-07-30 08:20:34 +04:00
|
|
|
/*
|
|
|
|
* The stream is complete... Tell the DocumentLoader to release us...
|
|
|
|
*/
|
|
|
|
#ifdef NECKO
|
|
|
|
rv = m_DocLoader->LoadURLComplete(channel, ctxt, (nsIStreamListener *)this,
|
|
|
|
aStatus, aMsg);
|
|
|
|
#else
|
|
|
|
rv = m_DocLoader->LoadURLComplete(aURL, (nsIStreamListener *)this, aStatus);
|
|
|
|
#endif
|
|
|
|
NS_IF_RELEASE(m_NextStream);
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-08-14 00:08:19 +04:00
|
|
|
NS_METHOD
|
1999-06-23 07:29:44 +04:00
|
|
|
nsDocumentBindInfo::RefreshURL(nsIURI* aURL, PRInt32 millis, PRBool repeat)
|
1998-08-14 00:08:19 +04:00
|
|
|
{
|
1998-08-19 03:25:17 +04:00
|
|
|
if (nsnull != m_Container) {
|
1999-06-28 14:35:57 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
#ifdef NECKO
|
|
|
|
NS_ASSERTION(0, "help");
|
|
|
|
#else
|
1998-08-19 03:25:17 +04:00
|
|
|
nsIRefreshUrl* refresher = nsnull;
|
|
|
|
|
|
|
|
/* Delegate the actual refresh call up-to the container. */
|
|
|
|
rv = m_Container->QueryInterface(kRefreshURLIID, (void**)&refresher);
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-02-12 20:14:26 +03:00
|
|
|
return PR_FALSE;
|
1998-08-19 03:25:17 +04:00
|
|
|
}
|
|
|
|
rv = refresher->RefreshURL(aURL, millis, repeat);
|
|
|
|
NS_RELEASE(refresher);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-08-19 03:25:17 +04:00
|
|
|
return rv;
|
1998-08-14 00:08:19 +04:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-08-19 03:25:17 +04:00
|
|
|
NS_METHOD
|
|
|
|
nsDocumentBindInfo::CancelRefreshURLTimers(void)
|
|
|
|
{
|
|
|
|
if (nsnull != m_Container) {
|
1999-06-28 14:35:57 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
#ifdef NECKO
|
|
|
|
NS_ASSERTION(0, "help");
|
|
|
|
#else
|
1998-08-19 03:25:17 +04:00
|
|
|
nsIRefreshUrl* refresher = nsnull;
|
|
|
|
|
|
|
|
/* Delegate the actual cancel call up-to the container. */
|
|
|
|
rv = m_Container->QueryInterface(kRefreshURLIID, (void**)&refresher);
|
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-02-12 20:14:26 +03:00
|
|
|
return PR_FALSE;
|
1998-08-19 03:25:17 +04:00
|
|
|
}
|
|
|
|
rv = refresher->CancelRefreshURLTimers();
|
|
|
|
NS_RELEASE(refresher);
|
1999-06-28 14:35:57 +04:00
|
|
|
#endif
|
1998-08-19 03:25:17 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef NECKO
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(nsChannelListener, nsCOMTypeInfo<nsIStreamListener>::GetIID());
|
|
|
|
|
|
|
|
nsChannelListener::nsChannelListener()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
|
|
|
mDocLoader = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsChannelListener::Init(nsDocLoaderImpl *aDocLoader,
|
|
|
|
nsIStreamListener *aListener)
|
|
|
|
{
|
|
|
|
mDocLoader = aDocLoader;
|
|
|
|
NS_ADDREF(mDocLoader);
|
|
|
|
|
|
|
|
mNextListener = aListener;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsChannelListener::~nsChannelListener()
|
|
|
|
{
|
|
|
|
NS_RELEASE(mDocLoader);
|
|
|
|
mNextListener = null_nsCOMPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChannelListener::OnStartRequest(nsIChannel *aChannel, nsISupports *aContext)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIContentViewerContainer> container;
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
|
|
|
|
1999-08-29 18:31:08 +04:00
|
|
|
///////////////////////////////
|
|
|
|
// STREAM CONVERTERS
|
|
|
|
///////////////////////////////
|
1999-09-05 23:54:28 +04:00
|
|
|
|
|
|
|
nsXPIDLCString contentType;
|
|
|
|
rv = aChannel->GetContentType(getter_Copies(contentType));
|
1999-08-29 18:31:08 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-09-05 23:54:28 +04:00
|
|
|
PRBool conversionRequired = PR_FALSE;
|
|
|
|
nsAutoString from, to;
|
|
|
|
|
1999-08-29 18:31:08 +04:00
|
|
|
// Let's shanghai this channelListener's mNextListener if we want to convert the stream.
|
1999-09-05 23:54:28 +04:00
|
|
|
if (!PL_strcmp(contentType, "message/rfc822"))
|
|
|
|
{
|
|
|
|
from = "message/rfc822";
|
|
|
|
to = "text/xul";
|
|
|
|
conversionRequired = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (!PL_strcmp(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;
|
1999-08-29 18:31:08 +04:00
|
|
|
|
|
|
|
// 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;
|
1999-09-05 23:54:28 +04:00
|
|
|
rv = StreamConvService->AsyncConvertData(from.GetUnicode(), to.GetUnicode(), mNextListener, aChannel,
|
1999-08-29 18:31:08 +04:00
|
|
|
&converterListener);
|
|
|
|
mNextListener = converterListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////
|
|
|
|
// END STREAM CONVERTERS
|
|
|
|
//////////////////////////////
|
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
// Pass the notification to the next listener...
|
|
|
|
rv = mNextListener->OnStartRequest(aChannel, aContext);
|
|
|
|
|
1999-08-29 18:31:08 +04:00
|
|
|
|
1999-08-27 02:45:55 +04:00
|
|
|
//
|
|
|
|
// Notify the document loader...
|
|
|
|
mDocLoader->GetContainer(getter_AddRefs(container));
|
|
|
|
if (container) {
|
|
|
|
container->GetContentViewer(getter_AddRefs(viewer));
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocLoader->FireOnStartURLLoad(mDocLoader,
|
|
|
|
aChannel,
|
|
|
|
viewer);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChannelListener::OnStopRequest(nsIChannel *aChannel, nsISupports *aContext,
|
|
|
|
nsresult aStatus, const PRUnichar *aMsg)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = mNextListener->OnStopRequest(aChannel, aContext, aStatus, aMsg);
|
|
|
|
|
|
|
|
mDocLoader->FireOnEndURLLoad(mDocLoader,
|
|
|
|
aChannel,
|
|
|
|
aStatus);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChannelListener::OnDataAvailable(nsIChannel *aChannel, nsISupports *aContext,
|
|
|
|
nsIInputStream *aInStream, PRUint32 aOffset,
|
|
|
|
PRUint32 aCount)
|
|
|
|
{
|
|
|
|
return mNextListener->OnDataAvailable(aChannel, aContext, aInStream,
|
|
|
|
aOffset, aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // NECKO
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
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
|
|
|
|