2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-12-06 01:33:15 +00:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2001-09-25 01:32:19 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-02-17 09:53:29 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
2001-02-17 09:53:29 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +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.
|
2001-02-17 09:53:29 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-02-17 09:53:29 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-02-17 09:53:29 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-08-07 02:55:54 +00:00
|
|
|
#include "nsContentDLF.h"
|
2001-11-06 01:24:39 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2001-02-17 09:53:29 +00:00
|
|
|
#include "nsIComponentManager.h"
|
2002-01-29 21:22:13 +00:00
|
|
|
#include "nsIComponentRegistrar.h"
|
2001-08-07 02:55:54 +00:00
|
|
|
#include "nsICategoryManager.h"
|
2001-02-17 09:53:29 +00:00
|
|
|
#include "nsIDocumentLoaderFactory.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsICSSStyleSheet.h"
|
2001-11-06 01:24:39 +00:00
|
|
|
#include "nsNodeInfo.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
2001-02-17 09:53:29 +00:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsContentCID.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsICSSLoader.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
2002-09-03 22:10:08 +00:00
|
|
|
#include "nsIViewSourceChannel.h"
|
2008-10-30 05:20:08 +00:00
|
|
|
#ifdef MOZ_MEDIA
|
|
|
|
#include "nsHTMLMediaElement.h"
|
|
|
|
#endif
|
2001-02-17 09:53:29 +00:00
|
|
|
|
2002-03-23 13:21:33 +00:00
|
|
|
#include "imgILoader.h"
|
2007-06-07 07:13:04 +00:00
|
|
|
#include "nsIParser.h"
|
2002-03-08 18:58:57 +00:00
|
|
|
|
2003-03-22 03:20:23 +00:00
|
|
|
// plugins
|
|
|
|
#include "nsIPluginManager.h"
|
|
|
|
#include "nsIPluginHost.h"
|
|
|
|
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
|
|
|
|
static NS_DEFINE_CID(kPluginDocumentCID, NS_PLUGINDOCUMENT_CID);
|
|
|
|
|
2001-02-17 09:53:29 +00:00
|
|
|
// Factory code for creating variations on html documents
|
|
|
|
|
|
|
|
#undef NOISY_REGISTRY
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID);
|
|
|
|
static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
|
2001-12-12 07:59:31 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
static NS_DEFINE_IID(kSVGDocumentCID, NS_SVGDOCUMENT_CID);
|
|
|
|
#endif
|
2008-10-30 05:20:08 +00:00
|
|
|
#ifdef MOZ_MEDIA
|
|
|
|
static NS_DEFINE_IID(kVideoDocumentCID, NS_VIDEODOCUMENT_CID);
|
|
|
|
#endif
|
2001-02-17 09:53:29 +00:00
|
|
|
static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID);
|
|
|
|
static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID);
|
|
|
|
|
2003-03-05 15:08:41 +00:00
|
|
|
nsresult
|
|
|
|
NS_NewDocumentViewer(nsIDocumentViewer** aResult);
|
2001-02-17 09:53:29 +00:00
|
|
|
|
2005-08-31 17:33:54 +00:00
|
|
|
// XXXbz if you change the MIME types here, be sure to update
|
|
|
|
// nsIParser.h and DetermineParseMode in nsParser.cpp accordingly.
|
2001-11-07 06:24:10 +00:00
|
|
|
static const char* const gHTMLTypes[] = {
|
2001-02-17 09:53:29 +00:00
|
|
|
"text/html",
|
|
|
|
"text/plain",
|
|
|
|
"text/css",
|
2001-08-07 02:55:54 +00:00
|
|
|
"text/javascript",
|
2005-06-22 00:50:32 +00:00
|
|
|
"text/ecmascript",
|
|
|
|
"application/javascript",
|
|
|
|
"application/ecmascript",
|
2001-08-07 02:55:54 +00:00
|
|
|
"application/x-javascript",
|
2003-07-30 23:57:39 +00:00
|
|
|
#ifdef MOZ_VIEW_SOURCE
|
2002-09-03 22:10:08 +00:00
|
|
|
"application/x-view-source", //XXX I wish I could just use nsMimeTypes.h here
|
2003-07-30 23:57:39 +00:00
|
|
|
#endif
|
2003-04-19 00:28:09 +00:00
|
|
|
"application/xhtml+xml",
|
2001-02-17 09:53:29 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2001-11-07 06:24:10 +00:00
|
|
|
static const char* const gXMLTypes[] = {
|
2001-02-17 09:53:29 +00:00
|
|
|
"text/xml",
|
|
|
|
"application/xml",
|
2007-03-07 04:23:27 +00:00
|
|
|
"application/rdf+xml",
|
|
|
|
"text/rdf",
|
2001-02-17 09:53:29 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2001-12-12 07:59:31 +00:00
|
|
|
#ifdef MOZ_SVG
|
2005-09-05 20:41:57 +00:00
|
|
|
static const char* const gSVGTypes[] = {
|
2001-12-12 07:59:31 +00:00
|
|
|
"image/svg+xml",
|
|
|
|
0
|
|
|
|
};
|
2005-02-21 18:11:18 +00:00
|
|
|
|
2006-09-11 15:26:19 +00:00
|
|
|
PRBool NS_SVGEnabled();
|
2001-12-12 07:59:31 +00:00
|
|
|
#endif
|
2001-02-17 09:53:29 +00:00
|
|
|
|
2007-03-07 04:23:27 +00:00
|
|
|
static const char* const gXULTypes[] = {
|
2001-03-25 16:49:38 +00:00
|
|
|
"application/vnd.mozilla.xul+xml",
|
|
|
|
"mozilla.application/cached-xul",
|
2001-02-17 09:53:29 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aResult, "null OUT ptr");
|
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsContentDLF* it = new nsContentDLF();
|
|
|
|
if (!it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-12-11 14:24:49 +00:00
|
|
|
|
|
|
|
return CallQueryInterface(it, aResult);
|
2001-02-17 09:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsContentDLF::nsContentDLF()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContentDLF::~nsContentDLF()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-07-15 16:12:22 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsContentDLF,
|
|
|
|
nsIDocumentLoaderFactory)
|
2001-02-17 09:53:29 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-08-07 02:55:54 +00:00
|
|
|
nsContentDLF::CreateInstance(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
const char* aContentType,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
2001-02-17 09:53:29 +00:00
|
|
|
{
|
2009-01-16 04:02:20 +00:00
|
|
|
// Declare "type" here. This is because although the variable itself only
|
|
|
|
// needs limited scope, we need to use the raw string memory -- as returned
|
|
|
|
// by "type.get()" farther down in the function.
|
|
|
|
nsCAutoString type;
|
|
|
|
|
2002-09-03 22:10:08 +00:00
|
|
|
// Are we viewing source?
|
2003-07-30 23:57:39 +00:00
|
|
|
#ifdef MOZ_VIEW_SOURCE
|
2002-09-03 22:10:08 +00:00
|
|
|
nsCOMPtr<nsIViewSourceChannel> viewSourceChannel = do_QueryInterface(aChannel);
|
|
|
|
if (viewSourceChannel)
|
|
|
|
{
|
|
|
|
aCommand = "view-source";
|
2001-08-07 02:55:54 +00:00
|
|
|
|
2002-09-03 22:10:08 +00:00
|
|
|
// The parser freaks out when it sees the content-type that a
|
|
|
|
// view-source channel normally returns. Get the actual content
|
|
|
|
// type of the data. If it's known, use it; otherwise use
|
|
|
|
// text/plain.
|
|
|
|
viewSourceChannel->GetOriginalContentType(type);
|
|
|
|
PRBool knownType = PR_FALSE;
|
2002-09-19 14:25:53 +00:00
|
|
|
PRInt32 typeIndex;
|
|
|
|
for (typeIndex = 0; gHTMLTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gHTMLTypes[typeIndex]) &&
|
2004-04-30 13:23:43 +00:00
|
|
|
!type.EqualsLiteral("application/x-view-source")) {
|
2002-09-03 22:10:08 +00:00
|
|
|
knownType = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2001-08-07 02:55:54 +00:00
|
|
|
|
2002-09-19 14:25:53 +00:00
|
|
|
for (typeIndex = 0; gXMLTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gXMLTypes[typeIndex])) {
|
2002-09-03 22:10:08 +00:00
|
|
|
knownType = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2001-08-07 02:55:54 +00:00
|
|
|
|
2002-09-03 22:10:08 +00:00
|
|
|
#ifdef MOZ_SVG
|
2006-09-11 15:26:19 +00:00
|
|
|
if (NS_SVGEnabled()) {
|
2005-02-21 18:11:18 +00:00
|
|
|
for (typeIndex = 0; gSVGTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gSVGTypes[typeIndex])) {
|
|
|
|
knownType = PR_TRUE;
|
|
|
|
}
|
2002-09-03 22:10:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // MOZ_SVG
|
2002-09-19 14:25:53 +00:00
|
|
|
|
2007-03-07 04:23:27 +00:00
|
|
|
for (typeIndex = 0; gXULTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gXULTypes[typeIndex])) {
|
2002-09-03 22:10:08 +00:00
|
|
|
knownType = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2001-08-07 02:55:54 +00:00
|
|
|
|
2002-09-03 22:10:08 +00:00
|
|
|
if (knownType) {
|
|
|
|
viewSourceChannel->SetContentType(type);
|
2009-01-16 04:02:20 +00:00
|
|
|
} else if (IsImageContentType(type.get())) {
|
|
|
|
// If it's an image, we want to display it the same way we normally would.
|
|
|
|
// Also note the lifetime of "type" allows us to safely use "get()" here.
|
|
|
|
aContentType = type.get();
|
2002-09-03 22:10:08 +00:00
|
|
|
} else {
|
|
|
|
viewSourceChannel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
|
|
|
|
}
|
|
|
|
} else if (0 == PL_strcmp("application/x-view-source", aContentType)) {
|
|
|
|
aChannel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
|
|
|
|
aContentType = "text/plain";
|
2001-02-17 09:53:29 +00:00
|
|
|
}
|
2003-07-30 23:57:39 +00:00
|
|
|
#endif
|
2001-02-17 09:53:29 +00:00
|
|
|
// Try html
|
|
|
|
int typeIndex=0;
|
|
|
|
while(gHTMLTypes[typeIndex]) {
|
2002-09-03 22:10:08 +00:00
|
|
|
if (0 == PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) {
|
2001-02-17 09:53:29 +00:00
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kHTMLDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try XML
|
|
|
|
typeIndex = 0;
|
|
|
|
while(gXMLTypes[typeIndex]) {
|
|
|
|
if (0== PL_strcmp(gXMLTypes[typeIndex++], aContentType)) {
|
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kXMLDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-12 07:59:31 +00:00
|
|
|
#ifdef MOZ_SVG
|
2006-09-11 15:26:19 +00:00
|
|
|
if (NS_SVGEnabled()) {
|
2005-02-21 18:11:18 +00:00
|
|
|
// Try SVG
|
|
|
|
typeIndex = 0;
|
|
|
|
while(gSVGTypes[typeIndex]) {
|
|
|
|
if (!PL_strcmp(gSVGTypes[typeIndex++], aContentType)) {
|
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kSVGDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-07 04:23:27 +00:00
|
|
|
// Try XUL
|
2001-02-17 09:53:29 +00:00
|
|
|
typeIndex = 0;
|
2007-03-07 04:23:27 +00:00
|
|
|
while (gXULTypes[typeIndex]) {
|
|
|
|
if (0 == PL_strcmp(gXULTypes[typeIndex++], aContentType)) {
|
|
|
|
return CreateXULDocument(aCommand,
|
2001-02-17 09:53:29 +00:00
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContentType, aContainer,
|
|
|
|
aExtraInfo, aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-30 05:20:08 +00:00
|
|
|
#ifdef MOZ_MEDIA
|
2008-12-17 02:11:07 +00:00
|
|
|
const char** supportedCodecs;
|
|
|
|
const char** maybeSupportedCodecs;
|
|
|
|
if (nsHTMLMediaElement::CanHandleMediaType(aContentType,
|
|
|
|
&supportedCodecs, &maybeSupportedCodecs)) {
|
2008-10-30 05:20:08 +00:00
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kVideoDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-02-17 09:53:29 +00:00
|
|
|
// Try image types
|
2009-01-16 04:02:20 +00:00
|
|
|
if (IsImageContentType(aContentType)) {
|
2002-03-08 18:58:57 +00:00
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kImageDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
2001-02-17 09:53:29 +00:00
|
|
|
}
|
|
|
|
|
2003-03-22 03:20:23 +00:00
|
|
|
nsCOMPtr<nsIPluginHost> ph (do_GetService(kPluginManagerCID));
|
|
|
|
if(ph && NS_SUCCEEDED(ph->IsPluginEnabledForType(aContentType))) {
|
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kPluginDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
|
2001-02-17 09:53:29 +00:00
|
|
|
// If we get here, then we weren't able to create anything. Sorry!
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentDLF::CreateInstanceForDocument(nsISupports* aContainer,
|
2001-08-07 02:55:54 +00:00
|
|
|
nsIDocument* aDocument,
|
|
|
|
const char *aCommand,
|
|
|
|
nsIContentViewer** aDocViewerResult)
|
2001-02-17 09:53:29 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv;
|
|
|
|
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
2001-08-07 04:11:09 +00:00
|
|
|
|
2001-02-17 09:53:29 +00:00
|
|
|
// Bind the document to the Content Viewer
|
2007-07-08 07:08:04 +00:00
|
|
|
nsIContentViewer* cv = static_cast<nsIContentViewer*>(docv.get());
|
2001-08-07 04:11:09 +00:00
|
|
|
rv = cv->LoadStart(aDocument);
|
|
|
|
NS_ADDREF(*aDocViewerResult = cv);
|
2001-02-17 09:53:29 +00:00
|
|
|
} while (PR_FALSE);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-11-06 01:24:39 +00:00
|
|
|
NS_IMETHODIMP
|
2006-11-22 18:27:54 +00:00
|
|
|
nsContentDLF::CreateBlankDocument(nsILoadGroup *aLoadGroup,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
nsIDocument **aDocument)
|
2001-11-06 01:24:39 +00:00
|
|
|
{
|
|
|
|
*aDocument = nsnull;
|
|
|
|
|
2001-11-16 02:08:09 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// create a new blank HTML document
|
2001-11-06 01:24:39 +00:00
|
|
|
nsCOMPtr<nsIDocument> blankDoc(do_CreateInstance(kHTMLDocumentCID));
|
|
|
|
|
2001-11-16 02:08:09 +00:00
|
|
|
if (blankDoc) {
|
|
|
|
// initialize
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2002-03-06 07:48:55 +00:00
|
|
|
NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:blank"));
|
2003-10-22 06:09:48 +00:00
|
|
|
if (uri) {
|
2006-11-22 18:27:54 +00:00
|
|
|
blankDoc->ResetToURI(uri, aLoadGroup, aPrincipal);
|
2003-10-22 06:09:48 +00:00
|
|
|
rv = NS_OK;
|
|
|
|
}
|
2001-11-16 02:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// add some simple content structure
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
2004-06-25 12:26:02 +00:00
|
|
|
nsNodeInfoManager *nim = blankDoc->NodeInfoManager();
|
2001-11-16 02:08:09 +00:00
|
|
|
|
2004-06-25 12:26:02 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> htmlNodeInfo;
|
2001-11-16 02:08:09 +00:00
|
|
|
|
2004-06-25 12:26:02 +00:00
|
|
|
// generate an html html element
|
2008-09-12 22:32:18 +00:00
|
|
|
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::html, 0, kNameSpaceID_None);
|
2005-01-12 19:45:38 +00:00
|
|
|
nsCOMPtr<nsIContent> htmlElement = NS_NewHTMLHtmlElement(htmlNodeInfo);
|
2001-11-16 02:08:09 +00:00
|
|
|
|
2004-06-25 12:26:02 +00:00
|
|
|
// generate an html head element
|
2008-09-12 22:32:18 +00:00
|
|
|
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::head, 0, kNameSpaceID_None);
|
2005-01-12 19:45:38 +00:00
|
|
|
nsCOMPtr<nsIContent> headElement = NS_NewHTMLHeadElement(htmlNodeInfo);
|
2001-11-16 02:08:09 +00:00
|
|
|
|
2004-06-25 12:26:02 +00:00
|
|
|
// generate an html body element
|
2008-09-12 22:32:18 +00:00
|
|
|
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::body, 0, kNameSpaceID_None);
|
2005-01-12 19:45:38 +00:00
|
|
|
nsCOMPtr<nsIContent> bodyElement = NS_NewHTMLBodyElement(htmlNodeInfo);
|
2001-11-16 02:08:09 +00:00
|
|
|
|
2004-06-25 12:26:02 +00:00
|
|
|
// blat in the structure
|
|
|
|
if (htmlElement && headElement && bodyElement) {
|
2006-01-19 03:34:18 +00:00
|
|
|
NS_ASSERTION(blankDoc->GetChildCount() == 0,
|
|
|
|
"Shouldn't have children");
|
|
|
|
rv = blankDoc->AppendChildTo(htmlElement, PR_FALSE);
|
2005-04-15 01:30:14 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2005-04-18 22:58:35 +00:00
|
|
|
rv = htmlElement->AppendChildTo(headElement, PR_FALSE);
|
2005-04-15 01:30:14 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// XXXbz Why not notifying here?
|
2005-04-18 22:58:35 +00:00
|
|
|
htmlElement->AppendChildTo(bodyElement, PR_FALSE);
|
2005-04-15 01:30:14 +00:00
|
|
|
}
|
2005-04-05 23:54:35 +00:00
|
|
|
}
|
2001-11-16 02:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add a nice bow
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-06-07 07:13:04 +00:00
|
|
|
blankDoc->SetDocumentCharacterSetSource(kCharsetFromDocTypeDefault);
|
|
|
|
blankDoc->SetDocumentCharacterSet(NS_LITERAL_CSTRING("UTF-8"));
|
|
|
|
|
2001-11-06 01:24:39 +00:00
|
|
|
*aDocument = blankDoc;
|
|
|
|
NS_ADDREF(*aDocument);
|
|
|
|
}
|
2001-11-16 02:08:09 +00:00
|
|
|
return rv;
|
2001-11-06 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-17 09:53:29 +00:00
|
|
|
nsresult
|
|
|
|
nsContentDLF::CreateDocument(const char* aCommand,
|
2001-08-07 02:55:54 +00:00
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
const nsCID& aDocumentCID,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
2001-02-17 09:53:29 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = aChannel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
#ifdef NOISY_CREATE_DOC
|
|
|
|
if (nsnull != aURL) {
|
|
|
|
nsAutoString tmp;
|
|
|
|
aURL->ToString(tmp);
|
2006-02-03 14:18:39 +00:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), stdout);
|
2001-02-17 09:53:29 +00:00
|
|
|
printf(": creating document\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv;
|
|
|
|
do {
|
|
|
|
// Create the document
|
2002-12-11 14:24:49 +00:00
|
|
|
doc = do_CreateInstance(aDocumentCID, &rv);
|
2001-02-17 09:53:29 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Create the document viewer XXX: could reuse document viewer here!
|
|
|
|
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
doc->SetContainer(aContainer);
|
|
|
|
|
2001-02-17 09:53:29 +00:00
|
|
|
// Initialize the document to begin loading the data. An
|
|
|
|
// nsIStreamListener connected to the parser is returned in
|
|
|
|
// aDocListener.
|
|
|
|
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Bind the document to the Content Viewer
|
2001-05-25 08:49:03 +00:00
|
|
|
rv = docv->LoadStart(doc);
|
2001-02-17 09:53:29 +00:00
|
|
|
*aDocViewer = docv;
|
|
|
|
NS_IF_ADDREF(*aDocViewer);
|
|
|
|
} while (PR_FALSE);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2007-03-07 04:23:27 +00:00
|
|
|
nsContentDLF::CreateXULDocument(const char* aCommand,
|
2001-08-07 02:55:54 +00:00
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
const char* aContentType,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
2001-02-17 09:53:29 +00:00
|
|
|
{
|
2005-12-06 01:33:15 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_CreateInstance(kXULDocumentCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-02-17 09:53:29 +00:00
|
|
|
nsCOMPtr<nsIDocumentViewer> docv;
|
2005-12-06 01:33:15 +00:00
|
|
|
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-02-17 09:53:29 +00:00
|
|
|
nsCOMPtr<nsIURI> aURL;
|
|
|
|
rv = aChannel->GetURI(getter_AddRefs(aURL));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the document to begin loading the data...
|
|
|
|
*
|
|
|
|
* An nsIStreamListener connected to the parser is returned in
|
|
|
|
* aDocListener.
|
|
|
|
*/
|
2002-04-17 04:17:16 +00:00
|
|
|
|
|
|
|
doc->SetContainer(aContainer);
|
|
|
|
|
2001-02-17 09:53:29 +00:00
|
|
|
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
/*
|
|
|
|
* Bind the document to the Content Viewer...
|
|
|
|
*/
|
2001-05-25 08:49:03 +00:00
|
|
|
rv = docv->LoadStart(doc);
|
2001-02-17 09:53:29 +00:00
|
|
|
*aDocViewer = docv;
|
|
|
|
NS_IF_ADDREF(*aDocViewer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
static nsresult
|
2003-02-27 13:51:55 +00:00
|
|
|
RegisterTypes(nsICategoryManager* aCatMgr,
|
2005-03-01 05:17:25 +00:00
|
|
|
const char* const* aTypes,
|
|
|
|
PRBool aPersist = PR_TRUE)
|
2001-02-17 09:53:29 +00:00
|
|
|
{
|
2001-08-07 02:55:54 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
while (*aTypes) {
|
2001-11-07 06:24:10 +00:00
|
|
|
const char* contentType = *aTypes++;
|
2001-08-07 02:55:54 +00:00
|
|
|
#ifdef NOISY_REGISTRY
|
|
|
|
printf("Register %s => %s\n", contractid, aPath);
|
|
|
|
#endif
|
2003-02-27 13:51:55 +00:00
|
|
|
// add the MIME types layout can handle to the handlers category.
|
2001-08-07 02:55:54 +00:00
|
|
|
// this allows users of layout's viewers (the docshell for example)
|
|
|
|
// to query the types of viewers layout can create.
|
|
|
|
rv = aCatMgr->AddCategoryEntry("Gecko-Content-Viewers", contentType,
|
2003-02-27 13:51:55 +00:00
|
|
|
"@mozilla.org/content/document-loader-factory;1",
|
2005-03-01 05:17:25 +00:00
|
|
|
aPersist, PR_TRUE, nsnull);
|
2001-08-07 02:55:54 +00:00
|
|
|
if (NS_FAILED(rv)) break;
|
|
|
|
}
|
|
|
|
return rv;
|
2001-02-17 09:53:29 +00:00
|
|
|
}
|
|
|
|
|
2003-02-27 13:51:55 +00:00
|
|
|
static nsresult UnregisterTypes(nsICategoryManager* aCatMgr,
|
|
|
|
const char* const* aTypes)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
while (*aTypes) {
|
|
|
|
const char* contentType = *aTypes++;
|
|
|
|
rv = aCatMgr->DeleteCategoryEntry("Gecko-Content-Viewers", contentType, PR_TRUE);
|
|
|
|
if (NS_FAILED(rv)) break;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-02-21 18:11:18 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentDLF::RegisterSVG()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2005-03-01 05:17:25 +00:00
|
|
|
return RegisterTypes(catmgr, gSVGTypes, PR_FALSE);
|
2005-02-21 18:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentDLF::UnregisterSVG()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return UnregisterTypes(catmgr, gSVGTypes);
|
|
|
|
}
|
|
|
|
#endif
|
2003-02-27 13:51:55 +00:00
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentDLF::RegisterDocumentFactories(nsIComponentManager* aCompMgr,
|
|
|
|
nsIFile* aPath,
|
|
|
|
const char *aLocation,
|
|
|
|
const char *aType,
|
|
|
|
const nsModuleComponentInfo* aInfo)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2001-03-08 02:41:16 +00:00
|
|
|
|
2001-08-07 02:55:54 +00:00
|
|
|
nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
do {
|
2003-02-27 13:51:55 +00:00
|
|
|
rv = RegisterTypes(catmgr, gHTMLTypes);
|
2001-08-07 02:55:54 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
2003-02-27 13:51:55 +00:00
|
|
|
rv = RegisterTypes(catmgr, gXMLTypes);
|
2001-08-07 02:55:54 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
2007-03-07 04:23:27 +00:00
|
|
|
rv = RegisterTypes(catmgr, gXULTypes);
|
2001-08-07 02:55:54 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
} while (PR_FALSE);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentDLF::UnregisterDocumentFactories(nsIComponentManager* aCompMgr,
|
|
|
|
nsIFile* aPath,
|
|
|
|
const char* aRegistryLocation,
|
|
|
|
const nsModuleComponentInfo* aInfo)
|
2001-02-17 09:53:29 +00:00
|
|
|
{
|
2001-12-19 00:12:41 +00:00
|
|
|
nsresult rv;
|
2003-02-27 13:51:55 +00:00
|
|
|
nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
do {
|
|
|
|
rv = UnregisterTypes(catmgr, gHTMLTypes);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
rv = UnregisterTypes(catmgr, gXMLTypes);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
rv = UnregisterTypes(catmgr, gSVGTypes);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
#endif
|
2007-03-07 04:23:27 +00:00
|
|
|
rv = UnregisterTypes(catmgr, gXULTypes);
|
2003-02-27 13:51:55 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
} while (PR_FALSE);
|
2001-12-19 00:12:41 +00:00
|
|
|
|
2003-02-27 13:51:55 +00:00
|
|
|
return rv;
|
2001-02-17 09:53:29 +00:00
|
|
|
}
|
2009-01-16 04:02:20 +00:00
|
|
|
|
|
|
|
PRBool nsContentDLF::IsImageContentType(const char* aContentType) {
|
|
|
|
nsCOMPtr<imgILoader> loader(do_GetService("@mozilla.org/image/loader;1"));
|
|
|
|
PRBool isDecoderAvailable = PR_FALSE;
|
|
|
|
loader->SupportImageWithMimeType(aContentType, &isDecoderAvailable);
|
|
|
|
return isDecoderAvailable;
|
|
|
|
}
|
|
|
|
|