2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-12-06 04:33:15 +03:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-02-17 12:53:29 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2001-08-07 06:55:54 +04:00
|
|
|
#include "nsContentDLF.h"
|
2013-11-15 11:12:43 +04:00
|
|
|
#include "nsDocShell.h"
|
2001-11-06 04:24:39 +03:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2001-02-17 12:53:29 +03:00
|
|
|
#include "nsIComponentManager.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsIComponentRegistrar.h"
|
2011-10-15 11:33:26 +04:00
|
|
|
#include "nsIContentViewer.h"
|
2001-08-07 06:55:54 +04:00
|
|
|
#include "nsICategoryManager.h"
|
2001-02-17 12:53:29 +03:00
|
|
|
#include "nsIDocumentLoaderFactory.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIURL.h"
|
2001-11-06 04:24:39 +03:00
|
|
|
#include "nsNodeInfo.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
2010-08-20 03:12:46 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2001-02-17 12:53:29 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsContentCID.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsNetUtil.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2002-09-04 02:10:08 +04:00
|
|
|
#include "nsIViewSourceChannel.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-10-04 00:17:40 +04:00
|
|
|
#include "imgLoader.h"
|
2012-03-22 18:42:42 +04:00
|
|
|
#include "nsCharsetSource.h"
|
2009-11-21 02:12:42 +03:00
|
|
|
#include "nsMimeTypes.h"
|
2012-11-22 07:10:41 +04:00
|
|
|
#include "DecoderTraits.h"
|
2002-03-08 21:58:57 +03:00
|
|
|
|
2010-05-20 03:22:19 +04:00
|
|
|
|
2003-03-22 06:20:23 +03:00
|
|
|
// plugins
|
|
|
|
#include "nsIPluginHost.h"
|
2011-05-21 17:28:54 +04:00
|
|
|
#include "nsPluginHost.h"
|
2003-03-22 06:20:23 +03:00
|
|
|
static NS_DEFINE_CID(kPluginDocumentCID, NS_PLUGINDOCUMENT_CID);
|
|
|
|
|
2001-02-17 12:53:29 +03: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 10:59:31 +03:00
|
|
|
static NS_DEFINE_IID(kSVGDocumentCID, NS_SVGDOCUMENT_CID);
|
2008-10-30 08:20:08 +03:00
|
|
|
static NS_DEFINE_IID(kVideoDocumentCID, NS_VIDEODOCUMENT_CID);
|
2001-02-17 12:53:29 +03:00
|
|
|
static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID);
|
|
|
|
static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID);
|
|
|
|
|
2014-02-09 12:04:40 +04:00
|
|
|
already_AddRefed<nsIContentViewer> NS_NewContentViewer();
|
2001-02-17 12:53:29 +03:00
|
|
|
|
2005-08-31 21:33:54 +04:00
|
|
|
// XXXbz if you change the MIME types here, be sure to update
|
2011-11-01 19:27:36 +04:00
|
|
|
// nsIParser.h and DetermineParseMode in nsParser.cpp and
|
|
|
|
// nsHTMLDocument::StartDocumentLoad accordingly.
|
2001-11-07 09:24:10 +03:00
|
|
|
static const char* const gHTMLTypes[] = {
|
2009-11-21 02:12:42 +03:00
|
|
|
TEXT_HTML,
|
|
|
|
TEXT_PLAIN,
|
2012-07-14 10:13:20 +04:00
|
|
|
TEXT_CACHE_MANIFEST,
|
2009-11-21 02:12:42 +03:00
|
|
|
TEXT_CSS,
|
|
|
|
TEXT_JAVASCRIPT,
|
|
|
|
TEXT_ECMASCRIPT,
|
|
|
|
APPLICATION_JAVASCRIPT,
|
|
|
|
APPLICATION_ECMASCRIPT,
|
|
|
|
APPLICATION_XJAVASCRIPT,
|
2011-08-08 22:32:07 +04:00
|
|
|
APPLICATION_JSON,
|
2009-11-21 02:12:42 +03:00
|
|
|
VIEWSOURCE_CONTENT_TYPE,
|
|
|
|
APPLICATION_XHTML_XML,
|
2001-02-17 12:53:29 +03:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2001-11-07 09:24:10 +03:00
|
|
|
static const char* const gXMLTypes[] = {
|
2009-11-21 02:12:42 +03:00
|
|
|
TEXT_XML,
|
|
|
|
APPLICATION_XML,
|
2009-11-30 01:18:53 +03:00
|
|
|
APPLICATION_MATHML_XML,
|
2009-11-21 02:12:42 +03:00
|
|
|
APPLICATION_RDF_XML,
|
|
|
|
TEXT_RDF,
|
2001-02-17 12:53:29 +03:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2005-09-06 00:41:57 +04:00
|
|
|
static const char* const gSVGTypes[] = {
|
2009-11-21 02:12:42 +03:00
|
|
|
IMAGE_SVG_XML,
|
2001-12-12 10:59:31 +03:00
|
|
|
0
|
|
|
|
};
|
2005-02-21 21:11:18 +03:00
|
|
|
|
2007-03-07 07:23:27 +03:00
|
|
|
static const char* const gXULTypes[] = {
|
2009-11-21 02:12:42 +03:00
|
|
|
TEXT_XUL,
|
|
|
|
APPLICATION_CACHED_XUL,
|
2001-02-17 12:53:29 +03: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 17:24:49 +03:00
|
|
|
|
|
|
|
return CallQueryInterface(it, aResult);
|
2001-02-17 12:53:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsContentDLF::nsContentDLF()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContentDLF::~nsContentDLF()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsContentDLF,
|
|
|
|
nsIDocumentLoaderFactory)
|
2001-02-17 12:53:29 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-08-20 03:12:46 +04:00
|
|
|
MayUseXULXBL(nsIChannel* aChannel)
|
|
|
|
{
|
|
|
|
nsIScriptSecurityManager *securityManager =
|
|
|
|
nsContentUtils::GetSecurityManager();
|
|
|
|
if (!securityManager) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-08-20 03:12:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
securityManager->GetChannelPrincipal(aChannel, getter_AddRefs(principal));
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(principal, false);
|
2010-08-20 03:12:46 +04:00
|
|
|
|
2010-11-23 11:50:55 +03:00
|
|
|
return nsContentUtils::AllowXULXBLForPrincipal(principal);
|
2010-08-20 03:12:46 +04:00
|
|
|
}
|
|
|
|
|
2001-02-17 12:53:29 +03:00
|
|
|
NS_IMETHODIMP
|
2001-08-07 06:55:54 +04:00
|
|
|
nsContentDLF::CreateInstance(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
const char* aContentType,
|
2013-11-15 11:12:43 +04:00
|
|
|
nsIDocShell* aContainer,
|
2001-08-07 06:55:54 +04:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
2001-02-17 12:53:29 +03:00
|
|
|
{
|
2009-01-16 07:02:20 +03: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.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString type;
|
2009-01-16 07:02:20 +03:00
|
|
|
|
2002-09-04 02:10:08 +04:00
|
|
|
// Are we viewing source?
|
|
|
|
nsCOMPtr<nsIViewSourceChannel> viewSourceChannel = do_QueryInterface(aChannel);
|
|
|
|
if (viewSourceChannel)
|
|
|
|
{
|
|
|
|
aCommand = "view-source";
|
2001-08-07 06:55:54 +04:00
|
|
|
|
2002-09-04 02:10:08 +04: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);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool knownType = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t typeIndex;
|
2002-09-19 18:25:53 +04:00
|
|
|
for (typeIndex = 0; gHTMLTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gHTMLTypes[typeIndex]) &&
|
2009-11-21 02:12:42 +03:00
|
|
|
!type.EqualsLiteral(VIEWSOURCE_CONTENT_TYPE)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
knownType = true;
|
2002-09-04 02:10:08 +04:00
|
|
|
}
|
|
|
|
}
|
2001-08-07 06:55:54 +04:00
|
|
|
|
2002-09-19 18:25:53 +04:00
|
|
|
for (typeIndex = 0; gXMLTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gXMLTypes[typeIndex])) {
|
2011-10-17 18:59:28 +04:00
|
|
|
knownType = true;
|
2002-09-04 02:10:08 +04:00
|
|
|
}
|
|
|
|
}
|
2001-08-07 06:55:54 +04:00
|
|
|
|
2010-12-09 00:25:06 +03:00
|
|
|
for (typeIndex = 0; gSVGTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gSVGTypes[typeIndex])) {
|
2011-10-17 18:59:28 +04:00
|
|
|
knownType = true;
|
2002-09-04 02:10:08 +04:00
|
|
|
}
|
|
|
|
}
|
2002-09-19 18:25:53 +04:00
|
|
|
|
2007-03-07 07:23:27 +03:00
|
|
|
for (typeIndex = 0; gXULTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gXULTypes[typeIndex])) {
|
2011-10-17 18:59:28 +04:00
|
|
|
knownType = true;
|
2002-09-04 02:10:08 +04:00
|
|
|
}
|
|
|
|
}
|
2001-08-07 06:55:54 +04:00
|
|
|
|
2002-09-04 02:10:08 +04:00
|
|
|
if (knownType) {
|
|
|
|
viewSourceChannel->SetContentType(type);
|
2009-01-16 07:02:20 +03: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-04 02:10:08 +04:00
|
|
|
} else {
|
2009-11-21 02:12:42 +03:00
|
|
|
viewSourceChannel->SetContentType(NS_LITERAL_CSTRING(TEXT_PLAIN));
|
2002-09-04 02:10:08 +04:00
|
|
|
}
|
2009-11-21 02:12:42 +03:00
|
|
|
} else if (0 == PL_strcmp(VIEWSOURCE_CONTENT_TYPE, aContentType)) {
|
|
|
|
aChannel->SetContentType(NS_LITERAL_CSTRING(TEXT_PLAIN));
|
|
|
|
aContentType = TEXT_PLAIN;
|
2001-02-17 12:53:29 +03:00
|
|
|
}
|
|
|
|
// Try html
|
|
|
|
int typeIndex=0;
|
|
|
|
while(gHTMLTypes[typeIndex]) {
|
2002-09-04 02:10:08 +04:00
|
|
|
if (0 == PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) {
|
2001-02-17 12:53:29 +03: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-09 00:25:06 +03: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 10:59:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 07:23:27 +03:00
|
|
|
// Try XUL
|
2001-02-17 12:53:29 +03:00
|
|
|
typeIndex = 0;
|
2007-03-07 07:23:27 +03:00
|
|
|
while (gXULTypes[typeIndex]) {
|
2011-01-14 18:33:57 +03:00
|
|
|
if (0 == PL_strcmp(gXULTypes[typeIndex++], aContentType)) {
|
|
|
|
if (!MayUseXULXBL(aChannel)) {
|
|
|
|
return NS_ERROR_REMOTE_XUL;
|
|
|
|
}
|
|
|
|
|
2010-08-20 03:12:46 +04:00
|
|
|
return CreateXULDocument(aCommand,
|
2001-02-17 12:53:29 +03:00
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContentType, aContainer,
|
|
|
|
aExtraInfo, aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-22 07:10:41 +04:00
|
|
|
if (mozilla::DecoderTraits::ShouldHandleMediaType(aContentType)) {
|
2008-10-30 08:20:08 +03:00
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kVideoDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
|
2001-02-17 12:53:29 +03:00
|
|
|
// Try image types
|
2009-01-16 07:02:20 +03:00
|
|
|
if (IsImageContentType(aContentType)) {
|
2002-03-08 21:58:57 +03:00
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kImageDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
2001-02-17 12:53:29 +03:00
|
|
|
}
|
|
|
|
|
2011-05-21 17:28:54 +04:00
|
|
|
nsCOMPtr<nsIPluginHost> pluginHostCOM(do_GetService(MOZ_PLUGIN_HOST_CONTRACTID));
|
|
|
|
nsPluginHost *pluginHost = static_cast<nsPluginHost*>(pluginHostCOM.get());
|
|
|
|
if(pluginHost &&
|
2013-06-11 18:58:43 +04:00
|
|
|
pluginHost->PluginExistsForType(aContentType)) {
|
2003-03-22 06:20:23 +03:00
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kPluginDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
|
2001-02-17 12:53:29 +03: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 06:55:54 +04:00
|
|
|
nsIDocument* aDocument,
|
|
|
|
const char *aCommand,
|
2011-10-15 11:33:26 +04:00
|
|
|
nsIContentViewer** aContentViewer)
|
2001-02-17 12:53:29 +03:00
|
|
|
{
|
2014-02-09 12:04:40 +04:00
|
|
|
MOZ_ASSERT(aDocument);
|
|
|
|
|
2014-02-09 12:04:40 +04:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer = NS_NewContentViewer();
|
2001-02-17 12:53:29 +03:00
|
|
|
|
2011-10-15 11:33:26 +04:00
|
|
|
// Bind the document to the Content Viewer
|
2014-02-09 12:04:40 +04:00
|
|
|
contentViewer->LoadStart(aDocument);
|
2011-10-15 11:33:26 +04:00
|
|
|
contentViewer.forget(aContentViewer);
|
2014-02-09 12:04:40 +04:00
|
|
|
return NS_OK;
|
2001-02-17 12:53:29 +03:00
|
|
|
}
|
|
|
|
|
2001-11-06 04:24:39 +03:00
|
|
|
NS_IMETHODIMP
|
2006-11-22 21:27:54 +03:00
|
|
|
nsContentDLF::CreateBlankDocument(nsILoadGroup *aLoadGroup,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
nsIDocument **aDocument)
|
2001-11-06 04:24:39 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aDocument = nullptr;
|
2001-11-06 04:24:39 +03:00
|
|
|
|
2001-11-16 05:08:09 +03:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// create a new blank HTML document
|
2001-11-06 04:24:39 +03:00
|
|
|
nsCOMPtr<nsIDocument> blankDoc(do_CreateInstance(kHTMLDocumentCID));
|
|
|
|
|
2001-11-16 05:08:09 +03:00
|
|
|
if (blankDoc) {
|
|
|
|
// initialize
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2002-03-06 10:48:55 +03:00
|
|
|
NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:blank"));
|
2003-10-22 10:09:48 +04:00
|
|
|
if (uri) {
|
2006-11-22 21:27:54 +03:00
|
|
|
blankDoc->ResetToURI(uri, aLoadGroup, aPrincipal);
|
2003-10-22 10:09:48 +04:00
|
|
|
rv = NS_OK;
|
|
|
|
}
|
2001-11-16 05:08:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// add some simple content structure
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
nsNodeInfoManager *nim = blankDoc->NodeInfoManager();
|
2001-11-16 05:08:09 +03:00
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
nsCOMPtr<nsINodeInfo> htmlNodeInfo;
|
2001-11-16 05:08:09 +03:00
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
// generate an html html element
|
2011-06-14 11:56:49 +04:00
|
|
|
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::html, 0, kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2010-07-23 13:49:57 +04:00
|
|
|
nsCOMPtr<nsIContent> htmlElement =
|
|
|
|
NS_NewHTMLHtmlElement(htmlNodeInfo.forget());
|
2001-11-16 05:08:09 +03:00
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
// generate an html head element
|
2011-06-14 11:56:49 +04:00
|
|
|
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::head, 0, kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2010-07-23 13:49:57 +04:00
|
|
|
nsCOMPtr<nsIContent> headElement =
|
|
|
|
NS_NewHTMLHeadElement(htmlNodeInfo.forget());
|
2001-11-16 05:08:09 +03:00
|
|
|
|
2010-07-23 13:49:57 +04:00
|
|
|
// generate an html body elemment
|
2011-06-14 11:56:49 +04:00
|
|
|
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::body, 0, kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2010-07-23 13:49:57 +04:00
|
|
|
nsCOMPtr<nsIContent> bodyElement =
|
|
|
|
NS_NewHTMLBodyElement(htmlNodeInfo.forget());
|
2001-11-16 05:08:09 +03:00
|
|
|
|
2004-06-25 16:26:02 +04:00
|
|
|
// blat in the structure
|
|
|
|
if (htmlElement && headElement && bodyElement) {
|
2006-01-19 06:34:18 +03:00
|
|
|
NS_ASSERTION(blankDoc->GetChildCount() == 0,
|
|
|
|
"Shouldn't have children");
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = blankDoc->AppendChildTo(htmlElement, false);
|
2005-04-15 05:30:14 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = htmlElement->AppendChildTo(headElement, false);
|
2005-04-15 05:30:14 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// XXXbz Why not notifying here?
|
2011-10-17 18:59:28 +04:00
|
|
|
htmlElement->AppendChildTo(bodyElement, false);
|
2005-04-15 05:30:14 +04:00
|
|
|
}
|
2005-04-06 03:54:35 +04:00
|
|
|
}
|
2001-11-16 05:08:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add a nice bow
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-06-07 11:13:04 +04:00
|
|
|
blankDoc->SetDocumentCharacterSetSource(kCharsetFromDocTypeDefault);
|
|
|
|
blankDoc->SetDocumentCharacterSet(NS_LITERAL_CSTRING("UTF-8"));
|
|
|
|
|
2001-11-06 04:24:39 +03:00
|
|
|
*aDocument = blankDoc;
|
|
|
|
NS_ADDREF(*aDocument);
|
|
|
|
}
|
2001-11-16 05:08:09 +03:00
|
|
|
return rv;
|
2001-11-06 04:24:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-17 12:53:29 +03:00
|
|
|
nsresult
|
|
|
|
nsContentDLF::CreateDocument(const char* aCommand,
|
2001-08-07 06:55:54 +04:00
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
2013-11-15 11:12:43 +04:00
|
|
|
nsIDocShell* aContainer,
|
2001-08-07 06:55:54 +04:00
|
|
|
const nsCID& aDocumentCID,
|
|
|
|
nsIStreamListener** aDocListener,
|
2011-10-15 11:33:26 +04:00
|
|
|
nsIContentViewer** aContentViewer)
|
2001-02-17 12:53:29 +03: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
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != aURL) {
|
2001-02-17 12:53:29 +03:00
|
|
|
nsAutoString tmp;
|
|
|
|
aURL->ToString(tmp);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), stdout);
|
2001-02-17 12:53:29 +03:00
|
|
|
printf(": creating document\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-15 11:33:26 +04:00
|
|
|
// Create the document
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_CreateInstance(aDocumentCID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Create the content viewer XXX: could reuse content viewer here!
|
2014-02-09 12:04:40 +04:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer = NS_NewContentViewer();
|
2011-10-15 11:33:26 +04:00
|
|
|
|
2013-11-15 11:12:43 +04:00
|
|
|
doc->SetContainer(static_cast<nsDocShell*>(aContainer));
|
2011-10-15 11:33:26 +04: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, true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-02-17 12:53:29 +03:00
|
|
|
|
2011-10-15 11:33:26 +04:00
|
|
|
// Bind the document to the Content Viewer
|
2014-02-09 12:04:40 +04:00
|
|
|
contentViewer->LoadStart(doc);
|
2011-10-15 11:33:26 +04:00
|
|
|
contentViewer.forget(aContentViewer);
|
2014-02-09 12:04:40 +04:00
|
|
|
return NS_OK;
|
2001-02-17 12:53:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2007-03-07 07:23:27 +03:00
|
|
|
nsContentDLF::CreateXULDocument(const char* aCommand,
|
2001-08-07 06:55:54 +04:00
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
const char* aContentType,
|
2013-11-15 11:12:43 +04:00
|
|
|
nsIDocShell* aContainer,
|
2001-08-07 06:55:54 +04:00
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
2011-10-15 11:33:26 +04:00
|
|
|
nsIContentViewer** aContentViewer)
|
2001-02-17 12:53:29 +03:00
|
|
|
{
|
2005-12-06 04:33:15 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_CreateInstance(kXULDocumentCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2014-02-09 12:04:40 +04:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer = NS_NewContentViewer();
|
2005-12-06 04:33:15 +03:00
|
|
|
|
2001-02-17 12:53:29 +03: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 08:17:16 +04:00
|
|
|
|
2013-11-15 11:12:43 +04:00
|
|
|
doc->SetContainer(static_cast<nsDocShell*>(aContainer));
|
2002-04-17 08:17:16 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, true);
|
2011-10-15 11:33:26 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bind the document to the Content Viewer...
|
|
|
|
*/
|
2014-02-09 12:04:40 +04:00
|
|
|
contentViewer->LoadStart(doc);
|
2011-10-15 11:33:26 +04:00
|
|
|
contentViewer.forget(aContentViewer);
|
2014-02-09 12:04:40 +04:00
|
|
|
return NS_OK;
|
2001-02-17 12:53:29 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsContentDLF::IsImageContentType(const char* aContentType) {
|
2012-10-04 00:17:47 +04:00
|
|
|
return imgLoader::SupportImageWithMimeType(aContentType);
|
2009-01-16 07:02:20 +03:00
|
|
|
}
|