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 02:33:29 +04:00
|
|
|
#ifdef XP_MAC
|
1998-07-30 01:06:19 +04:00
|
|
|
#include "nsIDocumentLoader.h"
|
1998-07-22 04:26:23 +04:00
|
|
|
#define NS_IMPL_IDS
|
1998-07-30 02:33:29 +04:00
|
|
|
#else
|
|
|
|
#define NS_IMPL_IDS
|
|
|
|
#include "nsIDocumentLoader.h"
|
|
|
|
#endif
|
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 "nsIPostToServer.h"
|
|
|
|
#include "nsIFactory.h"
|
1998-07-19 01:50:29 +04:00
|
|
|
#include "nsIContentViewerContainer.h"
|
1998-08-14 00:08:19 +04:00
|
|
|
#include "nsIRefreshUrl.h"
|
|
|
|
#include "nsITimer.h"
|
1998-08-12 08:56:40 +04:00
|
|
|
#include "nsIDocumentLoaderObserver.h"
|
|
|
|
#include "nsVoidArray.h"
|
1998-08-19 03:25:17 +04:00
|
|
|
#include "nsIHttpUrl.h"
|
1998-09-16 04:40:20 +04:00
|
|
|
#include "nsILoadAttribs.h"
|
1998-10-02 01:48:12 +04:00
|
|
|
#include "nsIURLGroup.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsINetService.h"
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
// XXX: Only needed for dummy factory...
|
|
|
|
#include "nsIDocument.h"
|
1998-07-19 01:50:29 +04:00
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsICSSParser.h"
|
1998-09-17 05:53:52 +04:00
|
|
|
#include "nsLayoutCID.h"
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
/* Forward declarations.... */
|
|
|
|
class nsDocLoaderImpl;
|
|
|
|
|
|
|
|
|
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... */
|
|
|
|
NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
|
|
|
|
NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID);
|
|
|
|
NS_DEFINE_IID(kIDocumentLoaderFactoryIID, NS_IDOCUMENTLOADERFACTORY_IID);
|
|
|
|
NS_DEFINE_IID(kDocumentBindInfoIID, NS_DOCUMENTBINDINFO_IID);
|
1998-10-02 01:48:12 +04:00
|
|
|
NS_DEFINE_IID(kIURLGroupIID, NS_IURLGROUP_IID);
|
|
|
|
NS_DEFINE_IID(kRefreshURLIID, NS_IREFRESHURL_IID);
|
|
|
|
NS_DEFINE_IID(kHTTPURLIID, NS_IHTTPURL_IID);
|
|
|
|
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
|
|
|
NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
|
|
|
NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
|
|
|
|
|
|
|
|
/* Define CIDs... */
|
|
|
|
NS_DEFINE_IID(kCHTMLDocumentCID, NS_HTMLDOCUMENT_CID);
|
1998-11-12 01:07:03 +03:00
|
|
|
NS_DEFINE_IID(kCXMLDocumentCID, NS_XMLDOCUMENT_CID);
|
1998-10-02 01:48:12 +04:00
|
|
|
NS_DEFINE_IID(kCImageDocumentCID, NS_IMAGEDOCUMENT_CID);
|
|
|
|
NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
|
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...
|
|
|
|
*/
|
1998-08-14 00:08:19 +04:00
|
|
|
class nsDocumentBindInfo : public nsIStreamListener,
|
1998-11-03 13:09:42 +03:00
|
|
|
public nsIRefreshUrl
|
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
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
nsresult Bind(const nsString& aURLSpec,
|
1998-08-20 03:01:52 +04:00
|
|
|
nsIPostData* aPostData,
|
1998-10-10 08:33:29 +04:00
|
|
|
nsIStreamListener* aListener);
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
nsresult Bind(nsIURL* aURL, nsIStreamListener* aListener);
|
1998-08-20 03:01:52 +04:00
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
nsresult Stop(void);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
/* nsIStreamListener interface methods... */
|
1998-07-16 02:38:01 +04:00
|
|
|
NS_IMETHOD GetBindInfo(nsIURL* aURL);
|
1998-07-24 14:02:50 +04:00
|
|
|
NS_IMETHOD OnProgress(nsIURL* aURL, PRInt32 aProgress, PRInt32 aProgressMax);
|
|
|
|
NS_IMETHOD OnStatus(nsIURL* aURL, const nsString& aMsg);
|
1998-07-16 02:38:01 +04:00
|
|
|
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
|
|
|
|
NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aStream, PRInt32 aLength);
|
|
|
|
NS_IMETHOD OnStopBinding(nsIURL* aURL, PRInt32 aStatus, const nsString& aMsg);
|
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... */
|
|
|
|
NS_IMETHOD RefreshURL(nsIURL* 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;
|
|
|
|
nsIURL* m_Url;
|
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-22 15:23:32 +04:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* nsDocFactoryImpl implementation...
|
|
|
|
****************************************************************************/
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
class nsDocFactoryImpl : public nsIDocumentLoaderFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDocFactoryImpl();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD CreateInstance(nsIURL* aURL,
|
|
|
|
const char* aContentType,
|
1998-07-17 10:32:39 +04:00
|
|
|
const char* aCommand,
|
1998-07-19 01:50:29 +04:00
|
|
|
nsIContentViewerContainer* aContainer,
|
1998-07-01 15:29:20 +04:00
|
|
|
nsIStreamListener** aDocListener,
|
1998-07-17 10:32:39 +04:00
|
|
|
nsIContentViewer** aDocViewer);
|
1998-07-19 01:50:29 +04:00
|
|
|
|
|
|
|
nsresult InitUAStyleSheet();
|
1998-07-27 22:05:34 +04:00
|
|
|
|
1998-11-12 01:07:03 +03:00
|
|
|
nsresult CreateDefaultDocument(nsIURL* aURL,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer);
|
|
|
|
|
|
|
|
nsresult CreateXMLDocument(nsIURL* aURL,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer);
|
|
|
|
|
1998-07-27 22:05:34 +04:00
|
|
|
nsresult CreateImageDocument(nsIURL* aURL,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer);
|
1998-09-10 03:51:43 +04:00
|
|
|
|
|
|
|
nsresult CreatePluginDocument(nsIURL* aURL,
|
|
|
|
const char* aCommand,
|
|
|
|
const char* aContentType,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer);
|
1998-07-01 15:29:20 +04:00
|
|
|
};
|
|
|
|
|
1998-07-19 01:50:29 +04:00
|
|
|
static nsIStyleSheet* gUAStyleSheet;
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
nsDocFactoryImpl::nsDocFactoryImpl()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of ISupports methods...
|
|
|
|
*/
|
|
|
|
NS_IMPL_ISUPPORTS(nsDocFactoryImpl,kIDocumentLoaderFactoryIID);
|
|
|
|
|
1998-11-12 01:07:03 +03:00
|
|
|
static char* gValidTypes[] = {"text/html","application/rtf",0};
|
|
|
|
static char* gXMLTypes[] = {"text/xml", "application/xml", 0};
|
1998-07-10 09:35:23 +04:00
|
|
|
|
1998-11-21 02:33:46 +03:00
|
|
|
static char* gImageTypes[] = {"image/gif", "image/jpeg", "image/png", 0 };
|
1998-07-27 22:05:34 +04:00
|
|
|
|
1998-09-10 03:51:43 +04:00
|
|
|
static char* gPluginTypes[] = {
|
|
|
|
"video/quicktime",
|
|
|
|
"video/msvideo",
|
|
|
|
"video/x-msvideo",
|
|
|
|
"application/vnd.netfpx",
|
|
|
|
"image/vnd.fpx",
|
|
|
|
"model/vrml",
|
|
|
|
"x-world/x-vrml",
|
|
|
|
"audio/midi",
|
|
|
|
"audio/x-midi",
|
|
|
|
"audio/wav",
|
1998-11-13 07:36:46 +03:00
|
|
|
"audio/x-wav",
|
1998-09-10 03:51:43 +04:00
|
|
|
"audio/aiff",
|
|
|
|
"audio/x-aiff",
|
|
|
|
"audio/basic",
|
1998-09-28 02:46:41 +04:00
|
|
|
"application/x-shockwave-flash",
|
|
|
|
"text/plain",
|
1998-09-10 03:51:43 +04:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocFactoryImpl::CreateInstance(nsIURL* aURL,
|
|
|
|
const char* aContentType,
|
|
|
|
const char *aCommand,
|
1998-07-19 01:50:29 +04:00
|
|
|
nsIContentViewerContainer* aContainer,
|
1998-07-01 15:29:20 +04:00
|
|
|
nsIStreamListener** aDocListener,
|
1998-07-17 10:32:39 +04:00
|
|
|
nsIContentViewer** aDocViewer)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
1998-07-17 21:54:46 +04:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-11-13 07:36:46 +03:00
|
|
|
if(0==PL_strcmp(gXMLTypes[0],aContentType))
|
|
|
|
if(0==PL_strcmp(aCommand,"view-source"))
|
|
|
|
aContentType=gValidTypes[0];
|
|
|
|
|
1998-07-10 09:35:23 +04:00
|
|
|
int typeIndex=0;
|
|
|
|
while(gValidTypes[typeIndex]) {
|
|
|
|
if (0== PL_strcmp(gValidTypes[typeIndex++], aContentType)) {
|
1998-11-12 01:07:03 +03:00
|
|
|
return CreateDefaultDocument(aURL, aCommand,
|
|
|
|
aContainer,
|
|
|
|
aDocListener,
|
|
|
|
aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try XML
|
|
|
|
typeIndex = 0;
|
|
|
|
while(gValidTypes[typeIndex]) {
|
|
|
|
if (0== PL_strcmp(gXMLTypes[typeIndex++], aContentType)) {
|
|
|
|
return CreateXMLDocument(aURL, aCommand,
|
|
|
|
aContainer,
|
|
|
|
aDocListener,
|
|
|
|
aDocViewer);
|
1998-07-10 09:35:23 +04:00
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
1998-07-27 22:05:34 +04:00
|
|
|
|
1998-09-10 03:51:43 +04:00
|
|
|
// Try image types
|
1998-07-27 22:05:34 +04:00
|
|
|
typeIndex = 0;
|
|
|
|
while(gImageTypes[typeIndex]) {
|
|
|
|
if (0== PL_strcmp(gImageTypes[typeIndex++], aContentType)) {
|
|
|
|
return CreateImageDocument(aURL, aCommand,
|
|
|
|
aContainer,
|
|
|
|
aDocListener,
|
|
|
|
aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
1998-09-10 03:51:43 +04:00
|
|
|
|
|
|
|
// Try plugin types
|
|
|
|
typeIndex = 0;
|
|
|
|
while(gPluginTypes[typeIndex]) {
|
|
|
|
if (0== PL_strcmp(gPluginTypes[typeIndex++], aContentType)) {
|
|
|
|
return CreatePluginDocument(aURL, aCommand, aContentType,
|
|
|
|
aContainer,
|
|
|
|
aDocListener,
|
|
|
|
aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-11-12 01:07:03 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDocFactoryImpl::CreateDefaultDocument(nsIURL* aURL,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
nsIDocument* doc = nsnull;
|
|
|
|
nsIDocumentViewer* docv = nsnull;
|
|
|
|
|
1998-07-19 01:50:29 +04:00
|
|
|
// Load the UA style sheet if we haven't already done that
|
|
|
|
if (nsnull == gUAStyleSheet) {
|
|
|
|
InitUAStyleSheet();
|
|
|
|
}
|
|
|
|
|
1998-07-03 10:16:02 +04:00
|
|
|
/*
|
|
|
|
* Create the HTML document...
|
|
|
|
*/
|
1998-09-17 05:53:52 +04:00
|
|
|
rv = nsRepository::CreateInstance(kCHTMLDocumentCID,
|
|
|
|
nsnull,
|
|
|
|
kIDocumentIID,
|
|
|
|
(void **)&doc);
|
1998-07-03 10:16:02 +04:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
goto done;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-07-03 10:16:02 +04:00
|
|
|
/*
|
|
|
|
* Create the HTML Content Viewer...
|
|
|
|
*/
|
1998-07-19 01:50:29 +04:00
|
|
|
rv = NS_NewDocumentViewer(docv);
|
1998-07-03 10:16:02 +04:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
goto done;
|
|
|
|
}
|
1998-07-19 01:50:29 +04:00
|
|
|
docv->SetUAStyleSheet(gUAStyleSheet);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-07-03 10:16:02 +04:00
|
|
|
/*
|
|
|
|
* Initialize the document to begin loading the data...
|
|
|
|
*
|
|
|
|
* An nsIStreamListener connected to the parser is returned in
|
|
|
|
* aDocListener.
|
|
|
|
*/
|
1998-11-11 14:55:32 +03:00
|
|
|
rv = doc->StartDocumentLoad(aURL, aContainer, aDocListener, aCommand);
|
1998-07-27 22:05:34 +04:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
NS_IF_RELEASE(docv);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bind the document to the Content Viewer...
|
|
|
|
*/
|
|
|
|
rv = docv->BindToDocument(doc, aCommand);
|
|
|
|
*aDocViewer = docv;
|
|
|
|
|
|
|
|
done:
|
|
|
|
NS_IF_RELEASE(doc);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-11-12 01:07:03 +03:00
|
|
|
nsresult
|
|
|
|
nsDocFactoryImpl::CreateXMLDocument(nsIURL* aURL,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
nsIDocument* doc = nsnull;
|
|
|
|
nsIDocumentViewer* docv = nsnull;
|
|
|
|
|
|
|
|
// Load the UA style sheet if we haven't already done that
|
|
|
|
if (nsnull == gUAStyleSheet) {
|
|
|
|
InitUAStyleSheet();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the image document...
|
|
|
|
*/
|
|
|
|
rv = nsRepository::CreateInstance(kCXMLDocumentCID,
|
|
|
|
nsnull,
|
|
|
|
kIDocumentIID,
|
|
|
|
(void **)&doc);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the image content viewer...
|
|
|
|
*/
|
|
|
|
rv = NS_NewDocumentViewer(docv);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
docv->SetUAStyleSheet(gUAStyleSheet);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the document to begin loading the data...
|
|
|
|
*
|
|
|
|
* An nsIStreamListener connected to the parser is returned in
|
|
|
|
* aDocListener.
|
|
|
|
*/
|
|
|
|
rv = doc->StartDocumentLoad(aURL, aContainer, aDocListener, aCommand);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
NS_IF_RELEASE(docv);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bind the document to the Content Viewer...
|
|
|
|
*/
|
|
|
|
rv = docv->BindToDocument(doc, aCommand);
|
|
|
|
*aDocViewer = docv;
|
|
|
|
|
|
|
|
done:
|
|
|
|
NS_IF_RELEASE(doc);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-07-27 22:05:34 +04:00
|
|
|
nsresult
|
|
|
|
nsDocFactoryImpl::CreateImageDocument(nsIURL* aURL,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
nsIDocument* doc = nsnull;
|
|
|
|
nsIDocumentViewer* docv = nsnull;
|
|
|
|
|
|
|
|
// Load the UA style sheet if we haven't already done that
|
|
|
|
if (nsnull == gUAStyleSheet) {
|
|
|
|
InitUAStyleSheet();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the image document...
|
|
|
|
*/
|
1998-09-17 05:53:52 +04:00
|
|
|
rv = nsRepository::CreateInstance(kCImageDocumentCID,
|
|
|
|
nsnull,
|
|
|
|
kIDocumentIID,
|
|
|
|
(void **)&doc);
|
1998-07-27 22:05:34 +04:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the image content viewer...
|
|
|
|
*/
|
|
|
|
rv = NS_NewDocumentViewer(docv);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
docv->SetUAStyleSheet(gUAStyleSheet);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the document to begin loading the data...
|
|
|
|
*
|
|
|
|
* An nsIStreamListener connected to the parser is returned in
|
|
|
|
* aDocListener.
|
|
|
|
*/
|
1998-11-11 14:55:32 +03:00
|
|
|
rv = doc->StartDocumentLoad(aURL, aContainer, aDocListener,aCommand);
|
1998-07-03 10:16:02 +04:00
|
|
|
if (NS_OK != rv) {
|
1998-07-19 01:50:29 +04:00
|
|
|
NS_IF_RELEASE(docv);
|
1998-07-03 10:16:02 +04:00
|
|
|
goto done;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-07-03 10:16:02 +04:00
|
|
|
/*
|
|
|
|
* Bind the document to the Content Viewer...
|
|
|
|
*/
|
1998-07-19 01:50:29 +04:00
|
|
|
rv = docv->BindToDocument(doc, aCommand);
|
|
|
|
*aDocViewer = docv;
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
done:
|
1998-07-03 10:16:02 +04:00
|
|
|
NS_IF_RELEASE(doc);
|
1998-07-01 15:29:20 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-09-10 03:51:43 +04:00
|
|
|
extern nsresult
|
|
|
|
NS_NewPluginContentViewer(const char* aCommand,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDocFactoryImpl::CreatePluginDocument(nsIURL* aURL,
|
|
|
|
const char* aCommand,
|
|
|
|
const char* aContentType,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Create the plugin content viewer and stream listener...
|
|
|
|
*/
|
|
|
|
nsresult rv = NS_NewPluginContentViewer(aCommand,
|
|
|
|
aDocListener,
|
|
|
|
aDocViewer);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-07-19 01:50:29 +04:00
|
|
|
#define UA_CSS_URL "resource:/res/ua.css"
|
|
|
|
|
|
|
|
nsresult nsDocFactoryImpl::InitUAStyleSheet()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == gUAStyleSheet) { // snarf one
|
|
|
|
nsIURL* uaURL;
|
1998-08-05 08:23:21 +04:00
|
|
|
rv = NS_NewURL(&uaURL, nsnull, nsString(UA_CSS_URL)); // XXX this bites, fix it
|
1998-07-19 01:50:29 +04:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Get an input stream from the url
|
|
|
|
PRInt32 ec;
|
|
|
|
nsIInputStream* in = uaURL->Open(&ec);
|
|
|
|
if (nsnull != in) {
|
|
|
|
// Translate the input using the argument character set id into unicode
|
|
|
|
nsIUnicharInputStream* uin;
|
|
|
|
rv = NS_NewConverterStream(&uin, nsnull, in);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Create parser and set it up to process the input file
|
|
|
|
nsICSSParser* css;
|
|
|
|
rv = NS_NewCSSParser(&css);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Parse the input and produce a style set
|
|
|
|
// XXX note: we are ignoring rv until the error code stuff in the
|
|
|
|
// input routines is converted to use nsresult's
|
|
|
|
css->Parse(uin, uaURL, gUAStyleSheet);
|
|
|
|
NS_RELEASE(css);
|
|
|
|
}
|
|
|
|
NS_RELEASE(uin);
|
|
|
|
}
|
|
|
|
NS_RELEASE(in);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// printf("open of %s failed: error=%x\n", UA_CSS_URL, ec);
|
|
|
|
rv = NS_ERROR_ILLEGAL_VALUE; // XXX need a better error code here
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(uaURL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
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
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
class nsDocLoaderImpl : public nsIDocumentLoader,
|
|
|
|
public nsIURLGroup
|
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
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
// nsIDocumentLoader interface
|
1998-10-09 09:49:34 +04:00
|
|
|
NS_IMETHOD LoadDocument(const nsString& aURLSpec,
|
|
|
|
const char *aCommand,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIPostData* aPostData = nsnull,
|
|
|
|
nsISupports* aExtraInfo = nsnull,
|
|
|
|
nsIStreamObserver* anObserver = nsnull,
|
1998-10-10 08:33:29 +04:00
|
|
|
nsURLReloadType aType = nsURLReload,
|
1998-10-09 09:49:34 +04: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);
|
|
|
|
NS_IMETHOD SetDocumentFactory(nsIDocumentLoaderFactory* aFactory);
|
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);
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
// nsIURLGroup interface...
|
|
|
|
NS_IMETHOD CreateURL(nsIURL** aInstancePtrResult,
|
|
|
|
nsIURL* aBaseURL,
|
|
|
|
const nsString& aSpec,
|
|
|
|
nsISupports* aContainer);
|
|
|
|
|
|
|
|
NS_IMETHOD OpenStream(nsIURL *aUrl,
|
|
|
|
nsIStreamListener *aConsumer);
|
|
|
|
|
|
|
|
NS_IMETHOD GetDefaultLoadAttributes(nsILoadAttribs*& aLoadAttribs);
|
|
|
|
NS_IMETHOD SetDefaultLoadAttributes(nsILoadAttribs* aLoadAttribs);
|
|
|
|
|
|
|
|
NS_IMETHOD AddChildGroup(nsIURLGroup* aGroup);
|
|
|
|
NS_IMETHOD RemoveChildGroup(nsIURLGroup* aGroup);
|
|
|
|
|
|
|
|
// Implementation specific methods...
|
1998-10-10 08:33:29 +04:00
|
|
|
void LoadURLComplete(nsIURL* aURL, nsISupports* aLoader, PRInt32 aStatus);
|
1998-10-02 01:48:12 +04:00
|
|
|
void SetParent(nsDocLoaderImpl* aParent);
|
1998-09-12 23:30:49 +04:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsDocLoaderImpl();
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
private:
|
|
|
|
static PRBool StopBindInfoEnumerator (nsISupports* aElement, void* aData);
|
1998-10-02 01:48:12 +04:00
|
|
|
static PRBool StopDocLoaderEnumerator(void* aElement, void* aData);
|
|
|
|
static PRBool IsBusyEnumerator(void* aElement, void* aData);
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
public:
|
|
|
|
nsIDocumentLoaderFactory* m_DocFactory;
|
|
|
|
|
|
|
|
protected:
|
1998-10-09 09:49:34 +04:00
|
|
|
nsISupportsArray* m_LoadingDocsList;
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-09 09:49:34 +04:00
|
|
|
nsVoidArray mChildGroupList;
|
|
|
|
nsVoidArray mDocObservers;
|
|
|
|
nsILoadAttribs* m_LoadAttrib;
|
|
|
|
nsIStreamObserver* mStreamObserver;
|
1998-09-16 04:40:20 +04:00
|
|
|
|
1998-10-09 09:49:34 +04:00
|
|
|
nsDocLoaderImpl* mParent;
|
1998-10-10 08:33:29 +04:00
|
|
|
/*
|
|
|
|
* The following counts are for the current document loader only. They
|
|
|
|
* do not take into account URLs being loaded by child document loaders.
|
|
|
|
*/
|
|
|
|
PRInt32 mForegroundURLs;
|
|
|
|
PRInt32 mTotalURLs;
|
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) {
|
|
|
|
gDocLoaderLog = PR_NewLogModule("DocLoader");
|
|
|
|
}
|
|
|
|
#endif /* DEBUG || FORCE_PR_LOG */
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-10 08:33:29 +04:00
|
|
|
mParent = nsnull;
|
1998-10-09 09:49:34 +04:00
|
|
|
mStreamObserver = nsnull;
|
1998-10-10 08:33:29 +04:00
|
|
|
mForegroundURLs = 0;
|
|
|
|
mTotalURLs = 0;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
NS_NewISupportsArray(&m_LoadingDocsList);
|
|
|
|
NS_NewLoadAttribs(&m_LoadAttrib);
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
m_DocFactory = new nsDocFactoryImpl();
|
|
|
|
NS_ADDREF(m_DocFactory);
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader - DocLoader [%p] created.\n", this));
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsDocLoaderImpl::~nsDocLoaderImpl()
|
|
|
|
{
|
1998-10-02 01:48:12 +04:00
|
|
|
Stop();
|
|
|
|
if (nsnull != mParent) {
|
|
|
|
mParent->RemoveChildGroup(this);
|
|
|
|
NS_RELEASE(mParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(m_LoadingDocsList);
|
|
|
|
NS_IF_RELEASE(m_DocFactory);
|
|
|
|
NS_IF_RELEASE(m_LoadAttrib);
|
1998-10-09 09:49:34 +04:00
|
|
|
NS_IF_RELEASE(mStreamObserver);
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader - DocLoader [%p] deleted.\n", this));
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
NS_PRECONDITION((0 == mChildGroupList.Count()), "Document loader has children...");
|
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)
|
|
|
|
{
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDocumentLoaderIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDocumentLoader*)this;
|
1998-09-12 23:30:49 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-07-22 15:23:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-10-02 01:48:12 +04:00
|
|
|
if (aIID.Equals(kIURLGroupIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIURLGroup*)this;
|
1998-09-12 23:30:49 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-07-22 15:23:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::CreateDocumentLoader(nsIDocumentLoader** anInstance)
|
|
|
|
{
|
1998-10-02 01:48:12 +04:00
|
|
|
nsDocLoaderImpl* newLoader = nsnull;
|
|
|
|
nsresult rv = NS_OK;
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-02 01:48:12 +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
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
NS_NEWXPCOM(newLoader, nsDocLoaderImpl);
|
|
|
|
if (nsnull == newLoader) {
|
|
|
|
*anInstance = nsnull;
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
rv = newLoader->QueryInterface(kIDocumentLoaderIID, (void**)anInstance);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
AddChildGroup(newLoader);
|
1998-09-12 23:30:49 +04:00
|
|
|
newLoader->SetParent(this);
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
|
|
|
|
done:
|
1998-10-02 01:48:12 +04:00
|
|
|
return rv;
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::SetDocumentFactory(nsIDocumentLoaderFactory* aFactory)
|
|
|
|
{
|
1998-10-02 01:48:12 +04:00
|
|
|
NS_IF_RELEASE(m_DocFactory);
|
|
|
|
m_DocFactory = aFactory;
|
|
|
|
NS_IF_ADDREF(m_DocFactory);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
return NS_OK;
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
1998-10-09 09:49:34 +04:00
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
NS_IMETHODIMP
|
1998-10-09 09:49:34 +04:00
|
|
|
nsDocLoaderImpl::LoadDocument(const nsString& aURLSpec,
|
|
|
|
const char* aCommand,
|
|
|
|
nsIContentViewerContainer* aContainer,
|
|
|
|
nsIPostData* aPostData,
|
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamObserver* anObserver,
|
1998-10-10 08:33:29 +04:00
|
|
|
nsURLReloadType aType,
|
1998-10-09 09:49:34 +04:00
|
|
|
const PRUint32 aLocalIP)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
1998-10-09 09:49:34 +04:00
|
|
|
nsresult rv;
|
1998-10-10 08:33:29 +04:00
|
|
|
nsURLLoadType loadType;
|
1998-10-09 09:49:34 +04:00
|
|
|
nsDocumentBindInfo* loader = nsnull;
|
1998-09-16 04:40:20 +04:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
loader->Init(this, // DocLoader
|
|
|
|
aCommand, // Command
|
|
|
|
aContainer, // Viewer Container
|
|
|
|
aExtraInfo, // Extra Info
|
|
|
|
anObserver); // Observer
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-10-09 09:49:34 +04:00
|
|
|
/* The DocumentBindInfo reference is only held by the Array... */
|
|
|
|
m_LoadingDocsList->AppendElement((nsIStreamListener *)loader);
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-10 08:33:29 +04:00
|
|
|
/* Initialize the URL counters... */
|
|
|
|
NS_PRECONDITION(((mTotalURLs == 0) && (mForegroundURLs == 0)), "DocuemntLoader is busy...");
|
|
|
|
rv = m_LoadAttrib->GetLoadType(&loadType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
loadType = nsURLLoadNormal;
|
|
|
|
}
|
|
|
|
if (nsURLLoadBackground != loadType) {
|
|
|
|
mForegroundURLs = 1;
|
|
|
|
}
|
|
|
|
mTotalURLs = 1;
|
|
|
|
|
|
|
|
m_LoadAttrib->SetReloadType(aType);
|
1998-10-09 09:49:34 +04:00
|
|
|
// If we've got special loading instructions, mind them.
|
1998-10-10 08:33:29 +04:00
|
|
|
if ((aType == nsURLReloadBypassProxy) ||
|
|
|
|
(aType == nsURLReloadBypassCacheAndProxy)) {
|
1998-10-09 09:49:34 +04:00
|
|
|
m_LoadAttrib->SetBypassProxy(PR_TRUE);
|
|
|
|
}
|
|
|
|
if ( aLocalIP ) {
|
|
|
|
m_LoadAttrib->SetLocalIP(aLocalIP);
|
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-09 09:49:34 +04:00
|
|
|
NS_IF_RELEASE(mStreamObserver);
|
|
|
|
mStreamObserver = anObserver;
|
|
|
|
NS_IF_ADDREF(mStreamObserver);
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-10 08:33:29 +04:00
|
|
|
rv = loader->Bind(aURLSpec, aPostData, nsnull);
|
1998-07-22 15:23:32 +04:00
|
|
|
|
|
|
|
done:
|
1998-10-09 09:49:34 +04:00
|
|
|
return rv;
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
|
|
|
|
1998-10-09 09:49:34 +04:00
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::Stop(void)
|
|
|
|
{
|
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;
|
|
|
|
|
1998-10-30 10:10:10 +03:00
|
|
|
/*
|
|
|
|
* Release the Stream Observer...
|
|
|
|
* It will be set on the next LoadDocument(...)
|
|
|
|
*/
|
|
|
|
NS_IF_RELEASE(mStreamObserver);
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::IsBusy(PRBool& aResult)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
(void*)aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not hold refs to the objects in the observer lists. Observers
|
|
|
|
* are expected to remove themselves upon their destruction if they
|
|
|
|
* have not removed themselves previously
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::AddObserver(nsIDocumentLoaderObserver* aObserver)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::CreateURL(nsIURL** aInstancePtrResult,
|
|
|
|
nsIURL* aBaseURL,
|
|
|
|
const nsString& aURLSpec,
|
|
|
|
nsISupports* aContainer)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIURL* url = nsnull;
|
|
|
|
|
|
|
|
/* Check for initial error conditions... */
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
|
|
|
rv = NS_NewURL(&url, aBaseURL, aURLSpec, aContainer, this);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1998-10-10 08:33:29 +04:00
|
|
|
nsILoadAttribs* loadAttributes;
|
|
|
|
|
|
|
|
loadAttributes = url->GetLoadAttribs();
|
|
|
|
if (nsnull != loadAttributes) {
|
|
|
|
loadAttributes->Clone(m_LoadAttrib);
|
|
|
|
NS_RELEASE(loadAttributes);
|
|
|
|
}
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
|
|
|
*aInstancePtrResult = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::OpenStream(nsIURL *aUrl, nsIStreamListener *aConsumer)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsDocumentBindInfo* loader = nsnull;
|
1998-10-10 08:33:29 +04:00
|
|
|
nsURLLoadType loadType = nsURLLoadNormal;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
NS_NEWXPCOM(loader, nsDocumentBindInfo);
|
|
|
|
if (nsnull == loader) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
1998-10-09 09:49:34 +04:00
|
|
|
loader->Init(this, // DocLoader
|
|
|
|
nsnull, // Command
|
|
|
|
nsnull, // Viewer Container
|
|
|
|
nsnull, // Extra Info
|
|
|
|
mStreamObserver); // Observer
|
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;
|
|
|
|
|
|
|
|
loadAttributes = aUrl->GetLoadAttribs();
|
|
|
|
if (nsnull != loadAttributes) {
|
|
|
|
rv = loadAttributes->GetLoadType(&loadType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
loadType = nsURLLoadNormal;
|
|
|
|
}
|
|
|
|
NS_RELEASE(loadAttributes);
|
|
|
|
}
|
|
|
|
if (nsURLLoadBackground != loadType) {
|
|
|
|
mForegroundURLs += 1;
|
|
|
|
}
|
|
|
|
mTotalURLs += 1;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
rv = loader->Bind(aUrl, aConsumer);
|
|
|
|
done:
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::GetDefaultLoadAttributes(nsILoadAttribs*& aLoadAttribs)
|
|
|
|
{
|
|
|
|
aLoadAttribs = m_LoadAttrib;
|
|
|
|
NS_IF_ADDREF(m_LoadAttrib);
|
|
|
|
|
|
|
|
return NS_OK;;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::SetDefaultLoadAttributes(nsILoadAttribs* aLoadAttribs)
|
|
|
|
{
|
|
|
|
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++) {
|
|
|
|
nsIURLGroup* child = (nsIURLGroup*)mChildGroupList.ElementAt(index);
|
|
|
|
child->SetDefaultLoadAttributes(m_LoadAttrib);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::AddChildGroup(nsIURLGroup* aGroup)
|
|
|
|
{
|
|
|
|
mChildGroupList.AppendElement(aGroup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocLoaderImpl::RemoveChildGroup(nsIURLGroup* aGroup)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (PR_FALSE == mChildGroupList.RemoveElement(aGroup)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
|
|
|
|
|
1998-10-10 08:33:29 +04:00
|
|
|
void nsDocLoaderImpl::LoadURLComplete(nsIURL* aURL, nsISupports* aBindInfo, PRInt32 aStatus)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
1998-10-02 01:48:12 +04:00
|
|
|
PRBool rv;
|
1998-10-10 09:54:58 +04:00
|
|
|
PRBool bIsForegroundURL = PR_FALSE;
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-10-10 08:33:29 +04:00
|
|
|
/*
|
|
|
|
* If the entry is not found in the list, then it must have been cancelled
|
|
|
|
* via Stop(...). So ignore just it...
|
|
|
|
*/
|
1998-10-02 01:48:12 +04:00
|
|
|
rv = m_LoadingDocsList->RemoveElement(aBindInfo);
|
1998-10-10 08:33:29 +04:00
|
|
|
if (PR_FALSE != rv) {
|
|
|
|
nsILoadAttribs* loadAttributes;
|
|
|
|
nsURLLoadType loadType = nsURLLoadNormal;
|
|
|
|
|
|
|
|
loadAttributes = aURL->GetLoadAttribs();
|
|
|
|
if (nsnull != loadAttributes) {
|
|
|
|
rv = loadAttributes->GetLoadType(&loadType);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
loadType = nsURLLoadNormal;
|
|
|
|
}
|
|
|
|
NS_RELEASE(loadAttributes);
|
|
|
|
}
|
|
|
|
if (nsURLLoadBackground != loadType) {
|
|
|
|
mForegroundURLs -= 1;
|
1998-10-10 09:54:58 +04:00
|
|
|
bIsForegroundURL = PR_TRUE;
|
1998-10-10 08:33:29 +04:00
|
|
|
}
|
|
|
|
mTotalURLs -= 1;
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-10 08:33:29 +04:00
|
|
|
NS_ASSERTION((mTotalURLs >= mForegroundURLs), "Foreground URL count is wrong.");
|
1998-08-12 08:56:40 +04:00
|
|
|
|
1998-10-10 08:33:29 +04:00
|
|
|
/*
|
|
|
|
* If this was the last URL for the entire document (including any sub
|
|
|
|
* documents) then fire an OnConnectionsComplete(...) notification.
|
1998-10-10 09:54:58 +04:00
|
|
|
*
|
|
|
|
* If the URL was a background URL, then ignore it...
|
1998-10-10 08:33:29 +04:00
|
|
|
*/
|
1998-10-10 09:54:58 +04:00
|
|
|
if (PR_FALSE != bIsForegroundURL) {
|
|
|
|
PRBool bIsBusy;
|
|
|
|
|
|
|
|
IsBusy(bIsBusy);
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1998-10-10 09:54:58 +04:00
|
|
|
if (! bIsBusy) {
|
|
|
|
PRInt32 count = mDocObservers.Count();
|
|
|
|
PRInt32 index;
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1998-10-10 09:54:58 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader [%p] - OnConnectionsComplete(...) called.\n", this));
|
1998-08-12 08:56:40 +04:00
|
|
|
|
1998-10-10 09:54:58 +04:00
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsIDocumentLoaderObserver* observer = (nsIDocumentLoaderObserver*)mDocObservers.ElementAt(index);
|
|
|
|
observer->OnConnectionsComplete();
|
|
|
|
}
|
1998-10-10 08:33:29 +04:00
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
1998-10-10 08:33:29 +04:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
|
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);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
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);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
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;
|
|
|
|
PRBool& result = (PRBool&)aData;
|
|
|
|
|
|
|
|
rv = ((nsISupports*)aElement)->QueryInterface(kIDocumentLoaderIID, (void**)&docLoader);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
docLoader->IsBusy(result);
|
|
|
|
NS_RELEASE(docLoader);
|
1998-08-12 08:56:40 +04:00
|
|
|
}
|
1998-10-02 01:48:12 +04:00
|
|
|
|
|
|
|
return !result;
|
1998-08-12 08:56:40 +04:00
|
|
|
}
|
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;
|
|
|
|
m_Url = nsnull;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
m_Url = nsnull;
|
|
|
|
m_NextStream = nsnull;
|
|
|
|
m_Command = (nsnull != aCommand) ? PL_strdup(aCommand) : nsnull;
|
1998-08-14 00:08:19 +04:00
|
|
|
m_ExtraInfo = aExtraInfo;
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
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-07-25 01:03:33 +04: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);
|
|
|
|
NS_IF_RELEASE(m_Url);
|
|
|
|
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;
|
|
|
|
}
|
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;
|
|
|
|
}
|
1998-07-22 04:26:23 +04:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
nsresult nsDocumentBindInfo::Bind(const nsString& aURLSpec,
|
1998-07-22 15:23:32 +04:00
|
|
|
nsIPostData* aPostData,
|
1998-10-10 08:33:29 +04:00
|
|
|
nsIStreamListener* aListener)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1998-10-02 01:48:12 +04:00
|
|
|
nsIURL* url = nsnull;
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-08-19 03:25:17 +04:00
|
|
|
/* If this nsDocumentBindInfo was created with a container pointer.
|
|
|
|
* extract the nsISupports iface from it and create the url with
|
|
|
|
* the nsISupports pointer so the backend can have access to the front
|
|
|
|
* end nsIContentViewerContainer for refreshing urls.
|
|
|
|
*/
|
1998-10-02 01:48:12 +04:00
|
|
|
rv = m_DocLoader->CreateURL(&url, nsnull, aURLSpec, m_Container);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Store any POST data into the URL */
|
|
|
|
if (nsnull != aPostData) {
|
|
|
|
static NS_DEFINE_IID(kPostToServerIID, NS_IPOSTTOSERVER_IID);
|
|
|
|
nsIPostToServer* pts;
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
rv = url->QueryInterface(kPostToServerIID, (void **)&pts);
|
1998-07-01 15:29:20 +04:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
const char* data = aPostData->GetData();
|
|
|
|
|
|
|
|
if (aPostData->IsFile()) {
|
|
|
|
pts->SendDataFromFile(data);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pts->SendData(data, aPostData->GetDataLength());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
rv = Bind(url, aListener);
|
|
|
|
NS_RELEASE(url);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult nsDocumentBindInfo::Bind(nsIURL* aURL, nsIStreamListener* aListener)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsINetService *inet = nsnull;
|
|
|
|
|
|
|
|
m_Url = aURL;
|
|
|
|
NS_ADDREF(m_Url);
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
/* Set up the stream listener (if provided)... */
|
|
|
|
if (nsnull != aListener) {
|
|
|
|
m_NextStream = aListener;
|
|
|
|
NS_ADDREF(m_NextStream);
|
|
|
|
}
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
/* Start the URL binding process... */
|
1998-10-02 01:48:12 +04:00
|
|
|
rv = nsServiceManager::GetService(kNetServiceCID,
|
|
|
|
kINetServiceIID,
|
|
|
|
(nsISupports **)&inet);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
rv = inet->OpenStream(m_Url, this);
|
1998-10-17 02:30:57 +04:00
|
|
|
nsServiceManager::ReleaseService(kNetServiceCID, inet);
|
1998-10-02 01:48:12 +04:00
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
nsresult nsDocumentBindInfo::Stop(void)
|
|
|
|
{
|
1998-10-17 02:30:57 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsINetService* inet;
|
1998-07-22 15:23:32 +04:00
|
|
|
|
1998-10-17 02:30:57 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader - Stop(...) called for %s.\n", m_Url->GetSpec()));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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... */
|
|
|
|
rv = nsServiceManager::GetService(kNetServiceCID,
|
|
|
|
kINetServiceIID,
|
|
|
|
(nsISupports **)&inet);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = inet->InterruptStream(m_Url);
|
|
|
|
nsServiceManager::ReleaseService(kNetServiceCID, inet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1998-07-22 15:23:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-16 02:38:01 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::GetBindInfo(nsIURL* aURL)
|
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-07-16 02:38:01 +04:00
|
|
|
rv = m_NextStream->GetBindInfo(aURL);
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-16 02:38:01 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::OnProgress(nsIURL* aURL, PRInt32 aProgress,
|
1998-07-24 14:02:50 +04:00
|
|
|
PRInt32 aProgressMax)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader - OnProgress(...) called for %s. Progress: %d. ProgressMax: %d\n",
|
|
|
|
aURL->GetSpec(), aProgress, aProgressMax));
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
/* Pass the notification out to the next stream listener... */
|
|
|
|
if (nsnull != m_NextStream) {
|
1998-07-24 14:02:50 +04:00
|
|
|
rv = m_NextStream->OnProgress(aURL, aProgress, aProgressMax);
|
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? */
|
1998-07-24 14:02:50 +04:00
|
|
|
(void) m_Observer->OnProgress(aURL, aProgress, aProgressMax);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD nsDocumentBindInfo::OnStatus(nsIURL* aURL, const nsString& aMsg)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
/* Pass the notification out to the next stream listener... */
|
|
|
|
if (nsnull != m_NextStream) {
|
|
|
|
rv = m_NextStream->OnStatus(aURL, aMsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pass the notification out to the Observer... */
|
|
|
|
if (nsnull != m_Observer) {
|
|
|
|
/* XXX: Should we ignore the return value? */
|
|
|
|
(void) m_Observer->OnStatus(aURL, aMsg);
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-16 02:38:01 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::OnStartBinding(nsIURL* aURL, const char *aContentType)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1998-07-17 10:32:39 +04:00
|
|
|
nsIContentViewer* viewer = nsnull;
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader - OnStartBinding(...) called for %s. Content-type is %s\n",
|
|
|
|
aURL->GetSpec(), aContentType));
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that the content type is available, create a document (and viewer)
|
|
|
|
* of the appropriate type...
|
|
|
|
*/
|
|
|
|
if (m_DocLoader->m_DocFactory) {
|
|
|
|
rv = m_DocLoader->m_DocFactory->CreateInstance(m_Url,
|
|
|
|
aContentType,
|
|
|
|
m_Command,
|
|
|
|
m_Container,
|
|
|
|
&m_NextStream,
|
|
|
|
&viewer);
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-07-17 10:32:39 +04:00
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
if (NS_OK != rv) {
|
1998-11-04 11:49:05 +03:00
|
|
|
printf("DocLoaderFactory: Unable to create ContentViewer for content-type: %s\n", aContentType);
|
1998-07-22 15:23:32 +04:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give the document container the new viewer...
|
|
|
|
*/
|
|
|
|
viewer->SetContainer(m_Container);
|
|
|
|
|
|
|
|
rv = m_Container->Embed(viewer, m_Command, m_ExtraInfo);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
goto done;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass the OnStartBinding(...) notification out to the document
|
|
|
|
* IStreamListener.
|
|
|
|
*/
|
|
|
|
if (nsnull != m_NextStream) {
|
1998-07-16 02:38:01 +04:00
|
|
|
rv = m_NextStream->OnStartBinding(aURL, aContentType);
|
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? */
|
1998-07-16 02:38:01 +04:00
|
|
|
(void) m_Observer->OnStartBinding(aURL, aContentType);
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
1998-07-03 10:16:02 +04:00
|
|
|
NS_IF_RELEASE(viewer);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-16 02:38:01 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::OnDataAvailable(nsIURL* aURL,
|
|
|
|
nsIInputStream *aStream, PRInt32 aLength)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader - OnDataAvailable(...) called for %s. Bytes available: %d.\n",
|
|
|
|
aURL->GetSpec(), aLength));
|
|
|
|
|
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);
|
|
|
|
rv = listener->OnDataAvailable(aURL, aStream, aLength);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-16 02:38:01 +04:00
|
|
|
NS_METHOD nsDocumentBindInfo::OnStopBinding(nsIURL* aURL, PRInt32 aStatus,
|
|
|
|
const nsString& aMsg)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1998-10-02 01:48:12 +04:00
|
|
|
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
|
|
|
|
("DocLoader - OnStopBinding(...) called for %s. Status: %d.\n",
|
|
|
|
aURL->GetSpec(), aStatus));
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
if (nsnull != m_NextStream) {
|
1998-07-16 02:38:01 +04:00
|
|
|
rv = m_NextStream->OnStopBinding(aURL, aStatus, aMsg);
|
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? */
|
1998-07-16 02:38:01 +04:00
|
|
|
(void) m_Observer->OnStopBinding(aURL, aStatus, aMsg);
|
1998-07-01 15:29:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The stream is complete... Tell the DocumentLoader to release us...
|
|
|
|
*/
|
1998-10-10 08:33:29 +04:00
|
|
|
m_DocLoader->LoadURLComplete(aURL, (nsIStreamListener *)this, aStatus);
|
1998-11-05 08:39:16 +03:00
|
|
|
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
|
|
|
|
nsDocumentBindInfo::RefreshURL(nsIURL* aURL, PRInt32 millis, PRBool repeat)
|
|
|
|
{
|
1998-08-19 03:25:17 +04:00
|
|
|
if (nsnull != m_Container) {
|
|
|
|
nsresult rv;
|
|
|
|
nsIRefreshUrl* refresher = nsnull;
|
|
|
|
|
|
|
|
/* Delegate the actual refresh call up-to the container. */
|
|
|
|
rv = m_Container->QueryInterface(kRefreshURLIID, (void**)&refresher);
|
|
|
|
|
|
|
|
if (rv != NS_OK) {
|
|
|
|
PR_FALSE;
|
|
|
|
}
|
|
|
|
rv = refresher->RefreshURL(aURL, millis, repeat);
|
|
|
|
NS_RELEASE(refresher);
|
|
|
|
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) {
|
|
|
|
nsresult rv;
|
|
|
|
nsIRefreshUrl* refresher = nsnull;
|
|
|
|
|
|
|
|
/* Delegate the actual cancel call up-to the container. */
|
|
|
|
rv = m_Container->QueryInterface(kRefreshURLIID, (void**)&refresher);
|
|
|
|
|
|
|
|
if (rv != NS_OK) {
|
|
|
|
PR_FALSE;
|
|
|
|
}
|
|
|
|
rv = refresher->CancelRefreshURLTimers();
|
|
|
|
NS_RELEASE(refresher);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
/*******************************************
|
1998-07-04 03:14:21 +04:00
|
|
|
* nsDocLoaderFactory
|
|
|
|
*******************************************/
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
|
|
|
static NS_DEFINE_IID(kCDocumentLoader, NS_DOCUMENTLOADER_CID);
|
|
|
|
|
|
|
|
class nsDocumentLoaderFactory : public nsIFactory
|
1998-07-19 05:18:15 +04:00
|
|
|
{
|
|
|
|
public:
|
1998-07-01 15:29:20 +04:00
|
|
|
nsDocumentLoaderFactory();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1998-07-19 05:18:15 +04:00
|
|
|
// nsIFactory methods
|
|
|
|
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-07-19 05:18:15 +04:00
|
|
|
NS_IMETHOD LockFactory(PRBool aLock);
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
|
|
|
|
protected:
|
1998-07-19 05:18:15 +04:00
|
|
|
virtual ~nsDocumentLoaderFactory();
|
|
|
|
};
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
nsDocumentLoaderFactory::nsDocumentLoaderFactory()
|
1998-07-19 05:18:15 +04:00
|
|
|
{
|
1998-07-01 15:29:20 +04:00
|
|
|
NS_INIT_REFCNT();
|
1998-07-19 05:18:15 +04:00
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-07-19 05:18:15 +04:00
|
|
|
nsDocumentLoaderFactory::~nsDocumentLoaderFactory()
|
|
|
|
{
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of ISupports methods...
|
|
|
|
*/
|
|
|
|
NS_IMPL_ISUPPORTS(nsDocumentLoaderFactory,kIFactoryIID);
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-19 05:18:15 +04:00
|
|
|
nsDocumentLoaderFactory::CreateInstance(nsISupports* aOuter,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void** aResult)
|
|
|
|
{
|
1998-07-01 15:29:20 +04:00
|
|
|
nsresult rv;
|
1998-07-22 15:23:32 +04:00
|
|
|
nsIDocumentLoader* inst;
|
|
|
|
static nsDocLoaderImpl* gGlobalDocLoader = nsnull;
|
|
|
|
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-07-19 05:18:15 +04:00
|
|
|
if (nsnull == aResult) {
|
1998-07-01 15:29:20 +04:00
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
goto done;
|
1998-07-19 05:18:15 +04:00
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
*aResult = nsnull;
|
|
|
|
|
|
|
|
if (nsnull != aOuter) {
|
|
|
|
rv = NS_ERROR_NO_AGGREGATION;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1998-07-22 15:23:32 +04:00
|
|
|
if (nsnull == gGlobalDocLoader) {
|
1998-09-12 23:30:49 +04:00
|
|
|
NS_NEWXPCOM(gGlobalDocLoader, nsDocLoaderImpl);
|
1998-07-22 15:23:32 +04:00
|
|
|
if (nsnull == gGlobalDocLoader) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(gGlobalDocLoader); // RefCount = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = gGlobalDocLoader->CreateDocumentLoader(&inst);
|
|
|
|
if (NS_OK != rv) {
|
1998-07-01 15:29:20 +04:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
goto done;
|
1998-07-19 05:18:15 +04:00
|
|
|
}
|
1998-07-22 15:23:32 +04:00
|
|
|
*aResult = inst;
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
done:
|
|
|
|
return rv;
|
1998-07-19 05:18:15 +04:00
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-07-19 05:18:15 +04:00
|
|
|
nsDocumentLoaderFactory::LockFactory(PRBool aLock)
|
|
|
|
{
|
|
|
|
// Not implemented in simplest case.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-01 15:29:20 +04:00
|
|
|
|
1998-07-19 05:18:15 +04:00
|
|
|
extern "C" NS_WEB nsresult
|
|
|
|
NS_NewDocumentLoaderFactory(nsIFactory** aFactory)
|
1998-07-01 15:29:20 +04:00
|
|
|
{
|
|
|
|
if (nsnull == aFactory) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1998-09-12 23:30:49 +04:00
|
|
|
nsDocumentLoaderFactory* it;
|
|
|
|
NS_NEWXPCOM(it, nsDocumentLoaderFactory);
|
|
|
|
*aFactory = it;
|
1998-07-01 15:29:20 +04:00
|
|
|
if (nsnull == *aFactory) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(*aFactory);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|