1999-05-05 20:42:51 +00:00
|
|
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-05-05 20:42:51 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-05-05 20:42:51 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 03:40:37 +00:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-05-05 20:42:51 +00:00
|
|
|
*/
|
1999-09-30 21:14:14 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsLayoutModule.h"
|
1999-05-05 20:42:51 +00:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIDocumentLoader.h"
|
2000-01-29 06:08:52 +00:00
|
|
|
#include "nsIDocumentLoaderFactory.h"
|
1999-05-05 20:42:51 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsICSSStyleSheet.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsLayoutCID.h"
|
|
|
|
#include "prprf.h"
|
2000-03-21 10:34:56 +00:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsICSSLoader.h"
|
1999-05-05 20:42:51 +00:00
|
|
|
|
|
|
|
#include "nsRDFCID.h"
|
|
|
|
#include "nsIRDFResource.h"
|
1999-07-16 07:54:18 +00:00
|
|
|
#include "nsIXULContentSink.h"
|
1999-05-05 20:42:51 +00:00
|
|
|
#include "nsIStreamLoadableDocument.h"
|
|
|
|
#include "nsIDocStreamLoaderFactory.h"
|
|
|
|
|
2000-03-21 10:34:56 +00:00
|
|
|
// URL for the "user agent" style sheet
|
|
|
|
#define UA_CSS_URL "resource:/res/ua.css"
|
|
|
|
|
1999-05-05 20:42:51 +00:00
|
|
|
// Factory code for creating variations on html documents
|
|
|
|
|
|
|
|
#undef NOISY_REGISTRY
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIDocumentLoaderFactoryIID, NS_IDOCUMENTLOADERFACTORY_IID);
|
|
|
|
static NS_DEFINE_IID(kIDocStreamLoaderFactoryIID, NS_IDOCSTREAMLOADERFACTORY_IID);
|
|
|
|
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID);
|
|
|
|
static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
|
|
|
|
static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID);
|
|
|
|
static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID);
|
|
|
|
|
|
|
|
extern nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult);
|
|
|
|
|
|
|
|
static char* gHTMLTypes[] = {
|
|
|
|
"text/html",
|
2000-02-11 12:10:38 +00:00
|
|
|
"text/plain",
|
|
|
|
"text/rtf",
|
|
|
|
"text/cpp",
|
1999-05-05 20:42:51 +00:00
|
|
|
0
|
|
|
|
};
|
2000-02-11 12:10:38 +00:00
|
|
|
|
1999-05-05 20:42:51 +00:00
|
|
|
static char* gXMLTypes[] = {
|
|
|
|
"text/xml",
|
|
|
|
"application/xml",
|
1999-10-18 00:46:33 +00:00
|
|
|
"text/css",
|
1999-05-05 20:42:51 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2000-02-11 12:10:38 +00:00
|
|
|
|
1999-05-05 20:42:51 +00:00
|
|
|
static char* gRDFTypes[] = {
|
|
|
|
"text/rdf",
|
|
|
|
"text/xul",
|
2000-01-11 21:12:52 +00:00
|
|
|
"text/cached-xul",
|
1999-05-05 20:42:51 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static char* gImageTypes[] = {
|
|
|
|
"image/gif",
|
|
|
|
"image/jpeg",
|
|
|
|
"image/png",
|
1999-11-29 22:14:32 +00:00
|
|
|
"image/x-png",
|
1999-06-28 21:49:53 +00:00
|
|
|
"image/x-art",
|
1999-07-08 01:32:11 +00:00
|
|
|
"image/x-jg",
|
1999-05-05 20:42:51 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
// XXX temporary
|
|
|
|
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",
|
|
|
|
"audio/x-wav",
|
|
|
|
"audio/aiff",
|
|
|
|
"audio/x-aiff",
|
|
|
|
"audio/basic",
|
|
|
|
"application/x-shockwave-flash",
|
|
|
|
"application/pdf",
|
|
|
|
"application/npapi-test",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
extern nsresult
|
|
|
|
NS_NewPluginContentViewer(const char* aCommand,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer);
|
|
|
|
|
|
|
|
class nsLayoutDLF : public nsIDocumentLoaderFactory,
|
|
|
|
public nsIDocStreamLoaderFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsLayoutDLF();
|
2000-03-21 10:34:56 +00:00
|
|
|
~nsLayoutDLF();
|
1999-05-05 20:42:51 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// for nsIDocumentLoaderFactory
|
1999-07-16 11:14:36 +00:00
|
|
|
NS_IMETHOD CreateInstance(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
1999-07-20 08:46:33 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
1999-05-05 20:42:51 +00:00
|
|
|
const char* aContentType,
|
1999-11-15 07:29:23 +00:00
|
|
|
nsISupports* aContainer,
|
1999-05-05 20:42:51 +00:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer);
|
|
|
|
|
1999-11-15 07:29:23 +00:00
|
|
|
NS_IMETHOD CreateInstanceForDocument(nsISupports* aContainer,
|
1999-05-17 23:52:01 +00:00
|
|
|
nsIDocument* aDocument,
|
|
|
|
const char *aCommand,
|
|
|
|
nsIContentViewer** aDocViewerResult);
|
|
|
|
|
1999-05-05 20:42:51 +00:00
|
|
|
// for nsIDocStreamLoaderFactory
|
|
|
|
NS_METHOD CreateInstance(nsIInputStream& aInputStream,
|
|
|
|
const char* aContentType,
|
|
|
|
const char* aCommand,
|
1999-11-15 07:29:23 +00:00
|
|
|
nsISupports* aContainer,
|
1999-05-05 20:42:51 +00:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIContentViewer** aDocViewer);
|
|
|
|
|
|
|
|
nsresult InitUAStyleSheet();
|
|
|
|
|
1999-07-16 11:14:36 +00:00
|
|
|
nsresult CreateDocument(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
1999-07-20 08:46:33 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
1999-11-15 07:29:23 +00:00
|
|
|
nsISupports* aContainer,
|
1999-05-05 20:42:51 +00:00
|
|
|
const nsCID& aDocumentCID,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer);
|
|
|
|
|
1999-07-16 11:14:36 +00:00
|
|
|
nsresult CreateRDFDocument(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
1999-07-20 08:46:33 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
1999-07-16 11:14:36 +00:00
|
|
|
const char* aContentType,
|
1999-11-15 07:29:23 +00:00
|
|
|
nsISupports* aContainer,
|
1999-05-05 20:42:51 +00:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer);
|
|
|
|
|
|
|
|
nsresult CreateXULDocumentFromStream(nsIInputStream& aXULStream,
|
|
|
|
const char* aCommand,
|
1999-11-15 07:29:23 +00:00
|
|
|
nsISupports* aContainer,
|
1999-05-05 20:42:51 +00:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIContentViewer** aDocViewer);
|
|
|
|
|
|
|
|
nsresult CreateRDFDocument(nsISupports*,
|
|
|
|
nsCOMPtr<nsIDocument>*,
|
|
|
|
nsCOMPtr<nsIDocumentViewer>*);
|
2000-03-21 10:34:56 +00:00
|
|
|
|
|
|
|
static nsICSSStyleSheet* GetUAStyleSheet() {
|
2000-03-21 12:14:29 +00:00
|
|
|
return nsLayoutModule::gUAStyleSheet;
|
2000-03-21 10:34:56 +00:00
|
|
|
}
|
1999-05-05 20:42:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewLayoutDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aResult, "null OUT ptr");
|
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsLayoutDLF* it = new nsLayoutDLF();
|
|
|
|
if (!it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return it->QueryInterface(kIDocumentLoaderFactoryIID, (void**)aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLayoutDLF::nsLayoutDLF()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
2000-03-21 10:34:56 +00:00
|
|
|
nsLayoutDLF::~nsLayoutDLF()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-05-05 20:42:51 +00:00
|
|
|
NS_IMPL_ADDREF(nsLayoutDLF)
|
|
|
|
NS_IMPL_RELEASE(nsLayoutDLF)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLayoutDLF::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
if (NULL == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
if (aIID.Equals(kIDocumentLoaderFactoryIID)) {
|
|
|
|
nsIDocumentLoaderFactory *tmp = this;
|
|
|
|
*aInstancePtrResult = (void*) tmp;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDocStreamLoaderFactoryIID)) {
|
|
|
|
nsIDocStreamLoaderFactory *tmp = this;
|
|
|
|
*aInstancePtrResult = (void*) tmp;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
nsIDocumentLoaderFactory *tmp = this;
|
|
|
|
nsISupports *tmp2 = tmp;
|
|
|
|
*aInstancePtrResult = (void*) tmp2;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-07-16 11:14:36 +00:00
|
|
|
nsLayoutDLF::CreateInstance(const char *aCommand,
|
|
|
|
nsIChannel* aChannel,
|
1999-07-20 08:46:33 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
1999-05-05 20:42:51 +00:00
|
|
|
const char* aContentType,
|
1999-11-15 07:29:23 +00:00
|
|
|
nsISupports* aContainer,
|
1999-05-05 20:42:51 +00:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
{
|
2000-03-21 10:34:56 +00:00
|
|
|
nsresult rv = NS_OK;
|
2000-03-21 12:14:29 +00:00
|
|
|
if (!GetUAStyleSheet()) {
|
2000-03-21 10:34:56 +00:00
|
|
|
// Load the UA style sheet
|
|
|
|
nsCOMPtr<nsIURI> uaURL;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uaURL), UA_CSS_URL);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsICSSLoader> cssLoader;
|
|
|
|
rv = NS_NewCSSLoader(getter_AddRefs(cssLoader));
|
|
|
|
if (cssLoader) {
|
|
|
|
PRBool complete;
|
2000-03-21 12:14:29 +00:00
|
|
|
rv = cssLoader->LoadAgentSheet(uaURL, nsLayoutModule::gUAStyleSheet, complete,
|
2000-03-21 10:34:56 +00:00
|
|
|
nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("*** open of %s failed: error=%x\n", UA_CSS_URL, rv);
|
|
|
|
#endif
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1999-05-05 20:42:51 +00:00
|
|
|
|
1999-06-29 06:46:03 +00:00
|
|
|
if(0==PL_strcmp(aCommand,"view-source")) {
|
2000-02-11 12:10:38 +00:00
|
|
|
if(0==PL_strcmp(aContentType,gHTMLTypes[1])) {
|
|
|
|
aContentType=gHTMLTypes[0];
|
|
|
|
}
|
|
|
|
else if(0==PL_strcmp(aContentType,gHTMLTypes[2])) {
|
|
|
|
aContentType=gHTMLTypes[0];
|
|
|
|
}
|
|
|
|
else aContentType=gXMLTypes[0];
|
1999-06-29 06:46:03 +00:00
|
|
|
}
|
1999-05-05 20:42:51 +00:00
|
|
|
|
|
|
|
// Try html
|
|
|
|
int typeIndex=0;
|
|
|
|
while(gHTMLTypes[typeIndex]) {
|
|
|
|
if (0== PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) {
|
1999-07-16 11:14:36 +00:00
|
|
|
return CreateDocument(aCommand,
|
1999-07-20 08:46:33 +00:00
|
|
|
aChannel, aLoadGroup,
|
1999-07-16 11:14:36 +00:00
|
|
|
aContainer, kHTMLDocumentCID,
|
1999-05-05 20:42:51 +00:00
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try XML
|
|
|
|
typeIndex = 0;
|
|
|
|
while(gXMLTypes[typeIndex]) {
|
|
|
|
if (0== PL_strcmp(gXMLTypes[typeIndex++], aContentType)) {
|
1999-07-16 11:14:36 +00:00
|
|
|
return CreateDocument(aCommand,
|
1999-07-20 08:46:33 +00:00
|
|
|
aChannel, aLoadGroup,
|
1999-07-16 11:14:36 +00:00
|
|
|
aContainer, kXMLDocumentCID,
|
1999-05-05 20:42:51 +00:00
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try RDF
|
|
|
|
typeIndex = 0;
|
|
|
|
while (gRDFTypes[typeIndex]) {
|
|
|
|
if (0 == PL_strcmp(gRDFTypes[typeIndex++], aContentType)) {
|
1999-07-16 11:14:36 +00:00
|
|
|
return CreateRDFDocument(aCommand,
|
1999-07-20 08:46:33 +00:00
|
|
|
aChannel, aLoadGroup,
|
1999-07-16 11:14:36 +00:00
|
|
|
aContentType, aContainer,
|
1999-05-05 20:42:51 +00:00
|
|
|
aExtraInfo, aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try image types
|
|
|
|
typeIndex = 0;
|
|
|
|
while(gImageTypes[typeIndex]) {
|
|
|
|
if (0== PL_strcmp(gImageTypes[typeIndex++], aContentType)) {
|
1999-07-16 11:14:36 +00:00
|
|
|
return CreateDocument(aCommand,
|
1999-07-20 08:46:33 +00:00
|
|
|
aChannel, aLoadGroup,
|
1999-07-16 11:14:36 +00:00
|
|
|
aContainer, kImageDocumentCID,
|
1999-05-05 20:42:51 +00:00
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try plugin types
|
|
|
|
typeIndex = 0;
|
|
|
|
while(gPluginTypes[typeIndex]) {
|
|
|
|
if (0== PL_strcmp(gPluginTypes[typeIndex++], aContentType)) {
|
|
|
|
return NS_NewPluginContentViewer(aCommand, aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-05-17 23:52:01 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-15 07:29:23 +00:00
|
|
|
nsLayoutDLF::CreateInstanceForDocument(nsISupports* aContainer,
|
1999-05-17 23:52:01 +00:00
|
|
|
nsIDocument* aDocument,
|
|
|
|
const char *aCommand,
|
|
|
|
nsIContentViewer** aDocViewerResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv;
|
|
|
|
// Create the document viewer
|
|
|
|
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
2000-03-21 10:34:56 +00:00
|
|
|
docv->SetUAStyleSheet(nsLayoutDLF::GetUAStyleSheet());
|
1999-05-17 23:52:01 +00:00
|
|
|
|
|
|
|
// Bind the document to the Content Viewer
|
|
|
|
rv = docv->BindToDocument(aDocument, aCommand);
|
|
|
|
*aDocViewerResult = docv;
|
|
|
|
NS_IF_ADDREF(*aDocViewerResult);
|
|
|
|
} while (PR_FALSE);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-05-05 20:42:51 +00:00
|
|
|
nsresult
|
1999-07-16 11:14:36 +00:00
|
|
|
nsLayoutDLF::CreateDocument(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
1999-07-20 08:46:33 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
1999-11-15 07:29:23 +00:00
|
|
|
nsISupports* aContainer,
|
1999-05-05 20:42:51 +00:00
|
|
|
const nsCID& aDocumentCID,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
1999-07-16 11:14:36 +00:00
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = aChannel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-05-05 20:42:51 +00:00
|
|
|
#ifdef NOISY_CREATE_DOC
|
|
|
|
if (nsnull != aURL) {
|
|
|
|
nsAutoString tmp;
|
|
|
|
aURL->ToString(tmp);
|
|
|
|
fputs(tmp, stdout);
|
|
|
|
printf(": creating document\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv;
|
|
|
|
do {
|
|
|
|
// Create the document
|
|
|
|
rv = nsComponentManager::CreateInstance(aDocumentCID, nsnull,
|
|
|
|
kIDocumentIID,
|
|
|
|
getter_AddRefs(doc));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
1999-11-19 07:32:20 +00:00
|
|
|
// Create the document viewer XXX: could reuse document viewer here!
|
1999-05-05 20:42:51 +00:00
|
|
|
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
2000-03-21 10:34:56 +00:00
|
|
|
docv->SetUAStyleSheet(nsLayoutDLF::GetUAStyleSheet());
|
1999-05-05 20:42:51 +00:00
|
|
|
|
|
|
|
// Initialize the document to begin loading the data. An
|
|
|
|
// nsIStreamListener connected to the parser is returned in
|
|
|
|
// aDocListener.
|
1999-11-15 22:17:54 +00:00
|
|
|
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener);
|
1999-05-05 20:42:51 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Bind the document to the Content Viewer
|
|
|
|
rv = docv->BindToDocument(doc, aCommand);
|
|
|
|
*aDocViewer = docv;
|
|
|
|
NS_IF_ADDREF(*aDocViewer);
|
|
|
|
} while (PR_FALSE);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLayoutDLF::CreateInstance(nsIInputStream& aInputStream,
|
|
|
|
const char* aContentType,
|
|
|
|
const char* aCommand,
|
1999-11-15 07:29:23 +00:00
|
|
|
nsISupports* aContainer,
|
1999-05-05 20:42:51 +00:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
|
|
|
|
{
|
|
|
|
nsresult status = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Try RDF
|
|
|
|
int typeIndex = 0;
|
|
|
|
while (gRDFTypes[typeIndex]) {
|
|
|
|
if (0 == PL_strcmp(gRDFTypes[typeIndex++], aContentType)) {
|
|
|
|
return CreateXULDocumentFromStream(aInputStream,
|
|
|
|
aCommand,
|
|
|
|
aContainer,
|
|
|
|
aExtraInfo,
|
|
|
|
aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ...common work for |CreateRDFDocument| and |CreateXULDocumentFromStream|
|
|
|
|
nsresult
|
|
|
|
nsLayoutDLF::CreateRDFDocument(nsISupports* aExtraInfo,
|
|
|
|
nsCOMPtr<nsIDocument>* doc,
|
|
|
|
nsCOMPtr<nsIDocumentViewer>* docv)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
1999-10-29 01:19:20 +00:00
|
|
|
// Create the XUL document
|
|
|
|
rv = nsComponentManager::CreateInstance(kXULDocumentCID, nsnull,
|
|
|
|
kIDocumentIID,
|
|
|
|
getter_AddRefs(*doc));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-05-05 20:42:51 +00:00
|
|
|
|
1999-10-29 01:19:20 +00:00
|
|
|
// Create the image content viewer...
|
|
|
|
rv = NS_NewDocumentViewer(getter_AddRefs(*docv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-05-05 20:42:51 +00:00
|
|
|
|
1999-10-29 01:19:20 +00:00
|
|
|
// Load the UA style sheet if we haven't already done that
|
2000-03-21 10:34:56 +00:00
|
|
|
(*docv)->SetUAStyleSheet(nsLayoutDLF::GetUAStyleSheet());
|
1999-10-29 01:19:20 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-05-05 20:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ...note, this RDF document _may_ be XUL :-)
|
|
|
|
nsresult
|
1999-07-16 11:14:36 +00:00
|
|
|
nsLayoutDLF::CreateRDFDocument(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
1999-07-20 08:46:33 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
1999-07-16 11:14:36 +00:00
|
|
|
const char* aContentType,
|
1999-11-15 07:29:23 +00:00
|
|
|
nsISupports* aContainer,
|
1999-05-05 20:42:51 +00:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv;
|
|
|
|
nsresult rv = CreateRDFDocument(aExtraInfo, &doc, &docv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-07-16 11:14:36 +00:00
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = aChannel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-05-05 20:42:51 +00:00
|
|
|
/*
|
|
|
|
* Initialize the document to begin loading the data...
|
|
|
|
*
|
|
|
|
* An nsIStreamListener connected to the parser is returned in
|
|
|
|
* aDocListener.
|
|
|
|
*/
|
1999-11-15 22:17:54 +00:00
|
|
|
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener);
|
1999-05-05 20:42:51 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
/*
|
|
|
|
* Bind the document to the Content Viewer...
|
|
|
|
*/
|
|
|
|
rv = docv->BindToDocument(doc, aCommand);
|
|
|
|
*aDocViewer = docv;
|
|
|
|
NS_IF_ADDREF(*aDocViewer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLayoutDLF::CreateXULDocumentFromStream(nsIInputStream& aXULStream,
|
|
|
|
const char* aCommand,
|
1999-11-15 07:29:23 +00:00
|
|
|
nsISupports* aContainer,
|
1999-05-05 20:42:51 +00:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
{
|
|
|
|
nsresult status = NS_OK;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv;
|
|
|
|
if ( NS_FAILED(status = CreateRDFDocument(aExtraInfo, &doc, &docv)) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ( NS_FAILED(status = docv->BindToDocument(doc, aCommand)) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
*aDocViewer = docv;
|
|
|
|
NS_IF_ADDREF(*aDocViewer);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStreamLoadableDocument> loader = do_QueryInterface(doc, &status);
|
|
|
|
if ( NS_FAILED(status) )
|
|
|
|
break;
|
|
|
|
|
1999-11-15 22:17:54 +00:00
|
|
|
status = loader->LoadFromStream(aXULStream, aContainer, aCommand);
|
1999-05-05 20:42:51 +00:00
|
|
|
}
|
|
|
|
while (0);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kDocumentFactoryImplCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID);
|
|
|
|
|
|
|
|
static nsresult
|
1999-09-30 21:14:14 +00:00
|
|
|
RegisterTypes(nsIComponentManager* aCompMgr,
|
|
|
|
const char* aCommand,
|
2000-01-24 21:28:28 +00:00
|
|
|
nsIFile* aPath,
|
1999-09-30 21:14:14 +00:00
|
|
|
char** aTypes)
|
1999-05-05 20:42:51 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
while (*aTypes) {
|
|
|
|
char progid[500];
|
|
|
|
char* contentType = *aTypes++;
|
|
|
|
PR_snprintf(progid, sizeof(progid),
|
1999-05-06 19:26:13 +00:00
|
|
|
NS_DOCUMENT_LOADER_FACTORY_PROGID_PREFIX "%s/%s",
|
|
|
|
aCommand, contentType);
|
1999-05-05 20:42:51 +00:00
|
|
|
#ifdef NOISY_REGISTRY
|
|
|
|
printf("Register %s => %s\n", progid, aPath);
|
|
|
|
#endif
|
1999-09-30 21:14:14 +00:00
|
|
|
rv = aCompMgr->RegisterComponentSpec(kDocumentFactoryImplCID, "Layout",
|
|
|
|
progid, aPath, PR_TRUE, PR_TRUE);
|
1999-05-05 20:42:51 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-09-30 21:14:14 +00:00
|
|
|
nsLayoutModule::RegisterDocumentFactories(nsIComponentManager* aCompMgr,
|
2000-01-24 21:28:28 +00:00
|
|
|
nsIFile* aPath)
|
1999-05-05 20:42:51 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
do {
|
1999-09-30 21:14:14 +00:00
|
|
|
rv = RegisterTypes(aCompMgr, "view", aPath, gHTMLTypes);
|
1999-05-05 20:42:51 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
1999-09-30 21:14:14 +00:00
|
|
|
rv = RegisterTypes(aCompMgr, "view-source", aPath, gHTMLTypes);
|
1999-05-05 20:42:51 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
1999-09-30 21:14:14 +00:00
|
|
|
rv = RegisterTypes(aCompMgr, "view", aPath, gXMLTypes);
|
1999-05-05 20:42:51 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
1999-09-30 21:14:14 +00:00
|
|
|
rv = RegisterTypes(aCompMgr, "view-source", aPath, gXMLTypes);
|
1999-05-05 20:42:51 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
1999-09-30 21:14:14 +00:00
|
|
|
rv = RegisterTypes(aCompMgr, "view", aPath, gImageTypes);
|
1999-05-06 19:26:13 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
1999-09-30 21:14:14 +00:00
|
|
|
rv = RegisterTypes(aCompMgr, "view", aPath, gPluginTypes);
|
1999-05-06 19:26:13 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
1999-09-30 21:14:14 +00:00
|
|
|
rv = RegisterTypes(aCompMgr, "view", aPath, gRDFTypes);
|
1999-05-06 19:26:13 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
1999-09-30 21:14:14 +00:00
|
|
|
rv = RegisterTypes(aCompMgr, "view-source", aPath, gRDFTypes);
|
1999-05-05 20:42:51 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
} while (PR_FALSE);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-30 21:14:14 +00:00
|
|
|
void
|
|
|
|
nsLayoutModule::UnregisterDocumentFactories(nsIComponentManager* aCompMgr,
|
2000-01-24 21:28:28 +00:00
|
|
|
nsIFile* aPath)
|
1999-05-05 20:42:51 +00:00
|
|
|
{
|
1999-09-30 21:14:14 +00:00
|
|
|
aCompMgr->UnregisterComponentSpec(kDocumentFactoryImplCID, aPath);
|
1999-05-05 20:42:51 +00:00
|
|
|
}
|