2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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/
|
|
|
|
*
|
|
|
|
* 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 the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* 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"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsContentDLF.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIComponentRegistrar.h"
|
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsIDocumentLoaderFactory.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsNodeInfo.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
2010-08-19 16:12:46 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsContentCID.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIViewSourceChannel.h"
|
2008-10-29 22:20:08 -07:00
|
|
|
#ifdef MOZ_MEDIA
|
|
|
|
#include "nsHTMLMediaElement.h"
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "imgILoader.h"
|
2007-06-07 00:13:04 -07:00
|
|
|
#include "nsIParser.h"
|
2009-11-20 15:12:42 -08:00
|
|
|
#include "nsMimeTypes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-19 16:22:19 -07:00
|
|
|
#include "mozilla/FunctionTimer.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// plugins
|
|
|
|
#include "nsIPluginHost.h"
|
|
|
|
static NS_DEFINE_CID(kPluginDocumentCID, NS_PLUGINDOCUMENT_CID);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
static NS_DEFINE_IID(kSVGDocumentCID, NS_SVGDOCUMENT_CID);
|
2008-10-29 22:20:08 -07:00
|
|
|
#ifdef MOZ_MEDIA
|
|
|
|
static NS_DEFINE_IID(kVideoDocumentCID, NS_VIDEODOCUMENT_CID);
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID);
|
|
|
|
static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDocumentViewer(nsIDocumentViewer** aResult);
|
|
|
|
|
|
|
|
// XXXbz if you change the MIME types here, be sure to update
|
|
|
|
// nsIParser.h and DetermineParseMode in nsParser.cpp accordingly.
|
|
|
|
static const char* const gHTMLTypes[] = {
|
2009-11-20 15:12:42 -08:00
|
|
|
TEXT_HTML,
|
|
|
|
TEXT_PLAIN,
|
|
|
|
TEXT_CSS,
|
|
|
|
TEXT_JAVASCRIPT,
|
|
|
|
TEXT_ECMASCRIPT,
|
|
|
|
APPLICATION_JAVASCRIPT,
|
|
|
|
APPLICATION_ECMASCRIPT,
|
|
|
|
APPLICATION_XJAVASCRIPT,
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef MOZ_VIEW_SOURCE
|
2009-11-20 15:12:42 -08:00
|
|
|
VIEWSOURCE_CONTENT_TYPE,
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2009-11-20 15:12:42 -08:00
|
|
|
APPLICATION_XHTML_XML,
|
2007-03-22 10:30:00 -07:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* const gXMLTypes[] = {
|
2009-11-20 15:12:42 -08:00
|
|
|
TEXT_XML,
|
|
|
|
APPLICATION_XML,
|
2009-11-29 14:18:53 -08:00
|
|
|
#ifdef MOZ_MATHML
|
|
|
|
APPLICATION_MATHML_XML,
|
|
|
|
#endif
|
2009-11-20 15:12:42 -08:00
|
|
|
APPLICATION_RDF_XML,
|
|
|
|
TEXT_RDF,
|
2007-03-22 10:30:00 -07:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* const gSVGTypes[] = {
|
2009-11-20 15:12:42 -08:00
|
|
|
IMAGE_SVG_XML,
|
2007-03-22 10:30:00 -07:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* const gXULTypes[] = {
|
2009-11-20 15:12:42 -08:00
|
|
|
TEXT_XUL,
|
|
|
|
APPLICATION_CACHED_XUL,
|
2007-03-22 10:30:00 -07: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(it, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContentDLF::nsContentDLF()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContentDLF::~nsContentDLF()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsContentDLF,
|
|
|
|
nsIDocumentLoaderFactory)
|
|
|
|
|
2010-08-19 16:12:46 -07:00
|
|
|
PRBool
|
|
|
|
MayUseXULXBL(nsIChannel* aChannel)
|
|
|
|
{
|
|
|
|
nsIScriptSecurityManager *securityManager =
|
|
|
|
nsContentUtils::GetSecurityManager();
|
|
|
|
if (!securityManager) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
securityManager->GetChannelPrincipal(aChannel, getter_AddRefs(principal));
|
|
|
|
NS_ENSURE_TRUE(principal, PR_FALSE);
|
|
|
|
|
2010-11-23 00:50:55 -08:00
|
|
|
return nsContentUtils::AllowXULXBLForPrincipal(principal);
|
2010-08-19 16:12:46 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentDLF::CreateInstance(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
const char* aContentType,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
{
|
2010-05-19 16:22:19 -07:00
|
|
|
#ifdef NS_FUNCTION_TIMER
|
|
|
|
nsCAutoString channelURL__("N/A");
|
|
|
|
nsCOMPtr<nsIURI> url__;
|
|
|
|
if (aChannel && NS_SUCCEEDED(aChannel->GetURI(getter_AddRefs(url__)))) {
|
|
|
|
url__->GetSpec(channelURL__);
|
|
|
|
}
|
|
|
|
NS_TIME_FUNCTION_FMT("%s (line %d) (url: %s)", MOZ_FUNCTION_NAME,
|
|
|
|
__LINE__, channelURL__.get());
|
|
|
|
#endif
|
|
|
|
|
2009-01-15 20:02:20 -08: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;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Are we viewing source?
|
|
|
|
#ifdef MOZ_VIEW_SOURCE
|
|
|
|
nsCOMPtr<nsIViewSourceChannel> viewSourceChannel = do_QueryInterface(aChannel);
|
|
|
|
if (viewSourceChannel)
|
|
|
|
{
|
|
|
|
aCommand = "view-source";
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
PRInt32 typeIndex;
|
|
|
|
for (typeIndex = 0; gHTMLTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gHTMLTypes[typeIndex]) &&
|
2009-11-20 15:12:42 -08:00
|
|
|
!type.EqualsLiteral(VIEWSOURCE_CONTENT_TYPE)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
knownType = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (typeIndex = 0; gXMLTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gXMLTypes[typeIndex])) {
|
|
|
|
knownType = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-08 13:25:06 -08:00
|
|
|
for (typeIndex = 0; gSVGTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gSVGTypes[typeIndex])) {
|
|
|
|
knownType = PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (typeIndex = 0; gXULTypes[typeIndex] && !knownType; ++typeIndex) {
|
|
|
|
if (type.Equals(gXULTypes[typeIndex])) {
|
|
|
|
knownType = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (knownType) {
|
|
|
|
viewSourceChannel->SetContentType(type);
|
2009-01-15 20:02:20 -08: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();
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2009-11-20 15:12:42 -08:00
|
|
|
viewSourceChannel->SetContentType(NS_LITERAL_CSTRING(TEXT_PLAIN));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-11-20 15:12:42 -08:00
|
|
|
} else if (0 == PL_strcmp(VIEWSOURCE_CONTENT_TYPE, aContentType)) {
|
|
|
|
aChannel->SetContentType(NS_LITERAL_CSTRING(TEXT_PLAIN));
|
|
|
|
aContentType = TEXT_PLAIN;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Try html
|
|
|
|
int typeIndex=0;
|
|
|
|
while(gHTMLTypes[typeIndex]) {
|
|
|
|
if (0 == PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) {
|
|
|
|
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-08 13:25:06 -08:00
|
|
|
// Try SVG
|
|
|
|
typeIndex = 0;
|
|
|
|
while(gSVGTypes[typeIndex]) {
|
|
|
|
if (!PL_strcmp(gSVGTypes[typeIndex++], aContentType)) {
|
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kSVGDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try XUL
|
|
|
|
typeIndex = 0;
|
|
|
|
while (gXULTypes[typeIndex]) {
|
2010-08-19 16:12:46 -07:00
|
|
|
if (0 == PL_strcmp(gXULTypes[typeIndex++], aContentType) &&
|
|
|
|
MayUseXULXBL(aChannel)) {
|
|
|
|
return CreateXULDocument(aCommand,
|
2007-03-22 10:30:00 -07:00
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContentType, aContainer,
|
|
|
|
aExtraInfo, aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-29 22:20:08 -07:00
|
|
|
#ifdef MOZ_MEDIA
|
2009-05-24 17:42:19 -07:00
|
|
|
if (nsHTMLMediaElement::ShouldHandleMediaType(aContentType)) {
|
2008-10-29 22:20:08 -07:00
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kVideoDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Try image types
|
2009-01-15 20:02:20 -08:00
|
|
|
if (IsImageContentType(aContentType)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kImageDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
|
2009-06-25 14:06:54 -07:00
|
|
|
nsCOMPtr<nsIPluginHost> ph (do_GetService(MOZ_PLUGIN_HOST_CONTRACTID));
|
2007-03-22 10:30:00 -07:00
|
|
|
if(ph && NS_SUCCEEDED(ph->IsPluginEnabledForType(aContentType))) {
|
|
|
|
return CreateDocument(aCommand,
|
|
|
|
aChannel, aLoadGroup,
|
|
|
|
aContainer, kPluginDocumentCID,
|
|
|
|
aDocListener, aDocViewer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here, then we weren't able to create anything. Sorry!
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentDLF::CreateInstanceForDocument(nsISupports* aContainer,
|
|
|
|
nsIDocument* aDocument,
|
|
|
|
const char *aCommand,
|
|
|
|
nsIContentViewer** aDocViewerResult)
|
|
|
|
{
|
2010-05-19 16:22:19 -07:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv;
|
|
|
|
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Bind the document to the Content Viewer
|
2007-07-08 00:08:04 -07:00
|
|
|
nsIContentViewer* cv = static_cast<nsIContentViewer*>(docv.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = cv->LoadStart(aDocument);
|
|
|
|
NS_ADDREF(*aDocViewerResult = cv);
|
|
|
|
} while (PR_FALSE);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContentDLF::CreateBlankDocument(nsILoadGroup *aLoadGroup,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
nsIDocument **aDocument)
|
|
|
|
{
|
2010-05-19 16:22:19 -07:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*aDocument = nsnull;
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// create a new blank HTML document
|
|
|
|
nsCOMPtr<nsIDocument> blankDoc(do_CreateInstance(kHTMLDocumentCID));
|
|
|
|
|
|
|
|
if (blankDoc) {
|
|
|
|
// initialize
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:blank"));
|
|
|
|
if (uri) {
|
|
|
|
blankDoc->ResetToURI(uri, aLoadGroup, aPrincipal);
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add some simple content structure
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsNodeInfoManager *nim = blankDoc->NodeInfoManager();
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> htmlNodeInfo;
|
|
|
|
|
|
|
|
// generate an html html element
|
2009-06-09 00:41:19 -07:00
|
|
|
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::html, 0, kNameSpaceID_XHTML);
|
2010-07-23 02:49:57 -07:00
|
|
|
nsCOMPtr<nsIContent> htmlElement =
|
|
|
|
NS_NewHTMLHtmlElement(htmlNodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// generate an html head element
|
2009-06-09 00:41:19 -07:00
|
|
|
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::head, 0, kNameSpaceID_XHTML);
|
2010-07-23 02:49:57 -07:00
|
|
|
nsCOMPtr<nsIContent> headElement =
|
|
|
|
NS_NewHTMLHeadElement(htmlNodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
// generate an html body elemment
|
2009-06-09 00:41:19 -07:00
|
|
|
htmlNodeInfo = nim->GetNodeInfo(nsGkAtoms::body, 0, kNameSpaceID_XHTML);
|
2010-07-23 02:49:57 -07:00
|
|
|
nsCOMPtr<nsIContent> bodyElement =
|
|
|
|
NS_NewHTMLBodyElement(htmlNodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// blat in the structure
|
|
|
|
if (htmlElement && headElement && bodyElement) {
|
|
|
|
NS_ASSERTION(blankDoc->GetChildCount() == 0,
|
|
|
|
"Shouldn't have children");
|
|
|
|
rv = blankDoc->AppendChildTo(htmlElement, PR_FALSE);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = htmlElement->AppendChildTo(headElement, PR_FALSE);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// XXXbz Why not notifying here?
|
|
|
|
htmlElement->AppendChildTo(bodyElement, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add a nice bow
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-06-07 00:13:04 -07:00
|
|
|
blankDoc->SetDocumentCharacterSetSource(kCharsetFromDocTypeDefault);
|
|
|
|
blankDoc->SetDocumentCharacterSet(NS_LITERAL_CSTRING("UTF-8"));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*aDocument = blankDoc;
|
|
|
|
NS_ADDREF(*aDocument);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsContentDLF::CreateDocument(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
const nsCID& aDocumentCID,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
{
|
2010-05-19 16:22:19 -07:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
2007-03-22 10:30:00 -07: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);
|
|
|
|
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), stdout);
|
|
|
|
printf(": creating document\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv;
|
|
|
|
do {
|
|
|
|
// Create the document
|
|
|
|
doc = do_CreateInstance(aDocumentCID, &rv);
|
|
|
|
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;
|
|
|
|
|
|
|
|
doc->SetContainer(aContainer);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
rv = docv->LoadStart(doc);
|
|
|
|
*aDocViewer = docv;
|
|
|
|
NS_IF_ADDREF(*aDocViewer);
|
|
|
|
} while (PR_FALSE);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsContentDLF::CreateXULDocument(const char* aCommand,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
const char* aContentType,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsISupports* aExtraInfo,
|
|
|
|
nsIStreamListener** aDocListener,
|
|
|
|
nsIContentViewer** aDocViewer)
|
|
|
|
{
|
2010-05-19 16:22:19 -07:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_CreateInstance(kXULDocumentCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docv;
|
|
|
|
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
doc->SetContainer(aContainer);
|
|
|
|
|
|
|
|
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
/*
|
|
|
|
* Bind the document to the Content Viewer...
|
|
|
|
*/
|
|
|
|
rv = docv->LoadStart(doc);
|
|
|
|
*aDocViewer = docv;
|
|
|
|
NS_IF_ADDREF(*aDocViewer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-01-15 20:02:20 -08: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;
|
|
|
|
}
|