2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2011-05-28 11:43:53 +04:00
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1998-11-12 01:06:16 +03:00
|
|
|
#include "nsXMLContentSink.h"
|
1998-12-11 20:02:37 +03:00
|
|
|
#include "nsIParser.h"
|
1998-11-12 01:06:16 +03:00
|
|
|
#include "nsIDocument.h"
|
2000-06-17 05:49:19 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMDocumentType.h"
|
2007-02-09 03:15:14 +03:00
|
|
|
#include "nsIContent.h"
|
2004-01-10 02:54:21 +03:00
|
|
|
#include "nsIURI.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
2003-10-05 11:29:50 +04:00
|
|
|
#include "nsIDocShell.h"
|
2001-05-19 06:59:15 +04:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
1998-11-12 01:06:16 +03:00
|
|
|
#include "nsIDOMComment.h"
|
1999-04-01 00:49:25 +04:00
|
|
|
#include "nsIDOMCDATASection.h"
|
2012-12-29 05:34:02 +04:00
|
|
|
#include "DocumentType.h"
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
#include "nsHTMLParts.h"
|
1998-11-12 01:06:16 +03:00
|
|
|
#include "nsCRT.h"
|
2014-06-20 14:32:49 +04:00
|
|
|
#include "mozilla/CSSStyleSheet.h"
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Loader.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsContentUtils.h"
|
1998-11-13 02:55:47 +03:00
|
|
|
#include "nsIScriptContext.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
1999-11-16 08:07:31 +03:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-05-14 00:27:47 +04:00
|
|
|
#include "nsIContentViewer.h"
|
1998-11-12 01:06:16 +03:00
|
|
|
#include "prtime.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
1998-11-13 02:55:47 +03:00
|
|
|
#include "prmem.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsRect.h"
|
2001-05-01 03:35:09 +04:00
|
|
|
#include "nsIWebNavigation.h"
|
2001-05-17 09:54:16 +04:00
|
|
|
#include "nsIScriptElement.h"
|
2006-11-04 08:45:02 +03:00
|
|
|
#include "nsScriptLoader.h"
|
2001-05-19 06:59:15 +04:00
|
|
|
#include "nsStyleLinkElement.h"
|
2001-12-17 10:14:49 +03:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2002-03-27 09:19:14 +03:00
|
|
|
#include "nsICookieService.h"
|
|
|
|
#include "nsIPrompt.h"
|
|
|
|
#include "nsIChannel.h"
|
2002-07-02 21:58:24 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2002-10-22 09:28:36 +04:00
|
|
|
#include "nsXMLPrettyPrinter.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2004-10-24 21:25:58 +04:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2006-05-19 14:29:43 +04:00
|
|
|
#include "nsIDOMProcessingInstruction.h"
|
2006-07-02 11:23:10 +04:00
|
|
|
#include "nsNodeUtils.h"
|
2007-01-31 00:21:06 +03:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
2009-11-06 07:27:30 +03:00
|
|
|
#include "nsIHTMLDocument.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2009-11-21 02:12:42 +03:00
|
|
|
#include "nsMimeTypes.h"
|
2010-07-19 02:07:54 +04:00
|
|
|
#include "nsHtml5SVGLoadDispatcher.h"
|
2013-04-04 16:01:08 +04:00
|
|
|
#include "nsTextNode.h"
|
2013-04-04 16:01:11 +04:00
|
|
|
#include "mozilla/dom/CDATASection.h"
|
2013-04-04 16:02:22 +04:00
|
|
|
#include "mozilla/dom/Comment.h"
|
2013-12-03 18:40:11 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-06-05 02:21:23 +04:00
|
|
|
#include "mozilla/dom/HTMLTemplateElement.h"
|
2013-04-04 16:01:11 +04:00
|
|
|
#include "mozilla/dom/ProcessingInstruction.h"
|
2004-07-07 02:52:03 +04:00
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
using namespace mozilla;
|
2010-10-25 16:17:38 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
1998-11-14 03:21:19 +03:00
|
|
|
// XXX Open Issues:
|
2001-05-01 03:35:09 +04:00
|
|
|
// 1) what's not allowed - We need to figure out which HTML tags
|
1998-11-14 03:21:19 +03:00
|
|
|
// (prefixed with a HTML namespace qualifier) are explicitly not
|
|
|
|
// allowed (if any).
|
2001-05-01 03:35:09 +04:00
|
|
|
// 2) factoring code with nsHTMLContentSink - There's some amount of
|
1998-11-14 03:21:19 +03:00
|
|
|
// common code between this and the HTML content sink. This will
|
|
|
|
// increase as we support more and more HTML elements. How can code
|
|
|
|
// from the code be factored?
|
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewXMLContentSink(nsIXMLContentSink** aResult,
|
|
|
|
nsIDocument* aDoc,
|
2004-01-10 02:54:21 +03:00
|
|
|
nsIURI* aURI,
|
2003-04-03 22:57:33 +04:00
|
|
|
nsISupports* aContainer,
|
2002-03-27 09:19:14 +03:00
|
|
|
nsIChannel* aChannel)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aResult, "null ptr");
|
|
|
|
if (nullptr == aResult) {
|
1998-11-12 01:06:16 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2015-03-12 20:20:29 +03:00
|
|
|
nsRefPtr<nsXMLContentSink> it = new nsXMLContentSink();
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult rv = it->Init(aDoc, aURI, aContainer, aChannel);
|
2003-02-17 17:52:46 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-03-12 20:20:29 +03:00
|
|
|
|
|
|
|
it.forget(aResult);
|
|
|
|
return NS_OK;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXMLContentSink::nsXMLContentSink()
|
2015-09-22 23:13:16 +03:00
|
|
|
: mPrettyPrintXML(true)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXMLContentSink::~nsXMLContentSink()
|
|
|
|
{
|
2004-01-08 07:25:43 +03:00
|
|
|
if (mText) {
|
|
|
|
PR_Free(mText); // Doesn't null out, unlike PR_FREEIF
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::Init(nsIDocument* aDoc,
|
2004-01-10 02:54:21 +03:00
|
|
|
nsIURI* aURI,
|
2003-04-03 22:57:33 +04:00
|
|
|
nsISupports* aContainer,
|
2002-03-27 09:19:14 +03:00
|
|
|
nsIChannel* aChannel)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult rv = nsContentSink::Init(aDoc, aURI, aContainer, aChannel);
|
2003-10-05 11:29:50 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
aDoc->AddObserver(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsDocumentObserver = true;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2003-04-03 22:57:33 +04:00
|
|
|
if (!mDocShell) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrettyPrintXML = false;
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
mState = eXMLContentSinkState_InProlog;
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocElement = nullptr;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2003-10-05 11:29:50 +04:00
|
|
|
return NS_OK;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
2008-02-09 01:07:51 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsXMLContentSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXMLContentSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIExpatSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITransformObserver)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsContentSink)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsXMLContentSink, nsContentSink)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsXMLContentSink, nsContentSink)
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLContentSink)
|
|
|
|
|
2008-02-09 01:07:51 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLContentSink,
|
|
|
|
nsContentSink)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCurrentHead)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocElement)
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, count = tmp->mContentStack.Length(); i < count; i++) {
|
2008-02-09 01:07:51 +03:00
|
|
|
const StackNode& node = tmp->mContentStack.ElementAt(i);
|
|
|
|
cb.NoteXPCOMChild(node.mContent);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2003-10-05 11:29:50 +04:00
|
|
|
|
|
|
|
// nsIContentSink
|
2007-01-31 00:21:06 +03:00
|
|
|
NS_IMETHODIMP
|
2008-10-31 00:31:00 +03:00
|
|
|
nsXMLContentSink::WillParse(void)
|
2007-01-31 00:21:06 +03:00
|
|
|
{
|
2008-10-31 00:31:00 +03:00
|
|
|
return WillParseImpl();
|
2007-01-31 00:21:06 +03:00
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
NS_IMETHODIMP
|
2009-06-24 01:22:16 +04:00
|
|
|
nsXMLContentSink::WillBuildModel(nsDTDMode aDTDMode)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
2007-01-31 00:21:06 +03:00
|
|
|
WillBuildModelImpl();
|
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
// Notify document that the load is beginning
|
|
|
|
mDocument->BeginLoad();
|
2004-04-20 21:12:48 +04:00
|
|
|
|
|
|
|
// Check for correct load-command for maybe prettyprinting
|
|
|
|
if (mPrettyPrintXML) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString command;
|
2012-01-20 15:16:27 +04:00
|
|
|
GetParser()->GetCommand(command);
|
2004-05-23 02:15:22 +04:00
|
|
|
if (!command.EqualsLiteral("view")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrettyPrintXML = false;
|
2004-04-20 21:12:48 +04:00
|
|
|
}
|
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
|
1999-07-14 21:59:19 +04:00
|
|
|
return NS_OK;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-01-31 00:21:06 +03:00
|
|
|
nsXMLContentSink::CanStillPrettyPrint()
|
|
|
|
{
|
|
|
|
return mPrettyPrintXML &&
|
|
|
|
(!mPrettyPrintHasFactoredElements || mPrettyPrintHasSpecialRoot);
|
|
|
|
}
|
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::MaybePrettyPrint()
|
2002-09-04 10:57:25 +04:00
|
|
|
{
|
2007-01-31 00:21:06 +03:00
|
|
|
if (!CanStillPrettyPrint()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrettyPrintXML = false;
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
return NS_OK;
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
// stop observing in order to avoid crashing when replacing content
|
|
|
|
mDocument->RemoveObserver(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsDocumentObserver = false;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2004-04-20 21:12:48 +04:00
|
|
|
// Reenable the CSSLoader so that the prettyprinting stylesheets can load
|
|
|
|
if (mCSSLoader) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mCSSLoader->SetEnabled(true);
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2014-03-18 04:23:03 +04:00
|
|
|
nsRefPtr<nsXMLPrettyPrinter> printer;
|
2002-10-22 09:28:36 +04:00
|
|
|
nsresult rv = NS_NewXMLPrettyPrinter(getter_AddRefs(printer));
|
2002-10-09 11:03:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isPrettyPrinting;
|
2007-05-31 05:42:48 +04:00
|
|
|
rv = printer->PrettyPrint(mDocument, &isPrettyPrinting);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mPrettyPrinting = isPrettyPrinting;
|
|
|
|
return NS_OK;
|
2002-09-04 10:57:25 +04:00
|
|
|
}
|
|
|
|
|
2006-05-19 14:29:43 +04:00
|
|
|
static void
|
|
|
|
CheckXSLTParamPI(nsIDOMProcessingInstruction* aPi,
|
|
|
|
nsIDocumentTransformer* aProcessor,
|
|
|
|
nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
nsAutoString target, data;
|
|
|
|
aPi->GetTarget(target);
|
|
|
|
|
|
|
|
// Check for namespace declarations
|
|
|
|
if (target.EqualsLiteral("xslt-param-namespace")) {
|
|
|
|
aPi->GetData(data);
|
|
|
|
nsAutoString prefix, namespaceAttr;
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::prefix,
|
|
|
|
prefix);
|
2006-05-19 14:29:43 +04:00
|
|
|
if (!prefix.IsEmpty() &&
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::_namespace,
|
|
|
|
namespaceAttr)) {
|
2006-05-19 14:29:43 +04:00
|
|
|
aProcessor->AddXSLTParamNamespace(prefix, namespaceAttr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for actual parameters
|
|
|
|
else if (target.EqualsLiteral("xslt-param")) {
|
|
|
|
aPi->GetData(data);
|
|
|
|
nsAutoString name, namespaceAttr, select, value;
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::name,
|
|
|
|
name);
|
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::_namespace,
|
|
|
|
namespaceAttr);
|
|
|
|
if (!nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::select, select)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
select.SetIsVoid(true);
|
2006-05-19 14:29:43 +04:00
|
|
|
}
|
2012-02-27 15:57:48 +04:00
|
|
|
if (!nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::value, value)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
value.SetIsVoid(true);
|
2006-05-19 14:29:43 +04:00
|
|
|
}
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIDOMNode> doc = do_QueryInterface(aDocument);
|
|
|
|
aProcessor->AddXSLTParam(name, namespaceAttr, select, value, doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXMLContentSink::DidBuildModel(bool aTerminated)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
2012-07-27 17:35:09 +04:00
|
|
|
if (!mParser) {
|
|
|
|
// If mParser is null, this parse has already been terminated and must
|
|
|
|
// not been terminated again. However, nsDocument may still think that
|
|
|
|
// the parse has not been terminated and call back into here in the case
|
|
|
|
// where the XML parser has finished but the XSLT transform associated
|
|
|
|
// with the document has not.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-02 15:13:59 +04:00
|
|
|
DidBuildModelImpl(aTerminated);
|
2002-01-08 02:51:36 +03:00
|
|
|
|
2003-03-26 04:10:14 +03:00
|
|
|
if (mXSLTProcessor) {
|
2007-01-31 00:21:06 +03:00
|
|
|
// stop observing in order to avoid crashing when replacing content
|
|
|
|
mDocument->RemoveObserver(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsDocumentObserver = false;
|
2006-05-19 14:29:43 +04:00
|
|
|
|
|
|
|
// Check for xslt-param and xslt-param-namespace PIs
|
2011-09-27 11:54:58 +04:00
|
|
|
for (nsIContent* child = mDocument->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2006-05-19 14:51:56 +04:00
|
|
|
if (child->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION)) {
|
2006-05-19 14:29:43 +04:00
|
|
|
nsCOMPtr<nsIDOMProcessingInstruction> pi = do_QueryInterface(child);
|
|
|
|
CheckXSLTParamPI(pi, mXSLTProcessor, mDocument);
|
|
|
|
}
|
2010-04-30 17:12:06 +04:00
|
|
|
else if (child->IsElement()) {
|
2006-05-19 14:29:43 +04:00
|
|
|
// Only honor PIs in the prolog
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-15 01:32:18 +03:00
|
|
|
nsCOMPtr<nsIDOMDocument> currentDOMDoc(do_QueryInterface(mDocument));
|
2003-03-26 04:10:14 +03:00
|
|
|
mXSLTProcessor->SetSourceContentModel(currentDOMDoc);
|
|
|
|
// Since the processor now holds a reference to us we drop our reference
|
2003-01-15 01:32:18 +03:00
|
|
|
// to it to avoid owning cycles
|
2012-07-30 18:20:58 +04:00
|
|
|
mXSLTProcessor = nullptr;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
}
|
2003-01-15 01:32:18 +03:00
|
|
|
else {
|
|
|
|
// Kick off layout for non-XSLT transformed documents.
|
2002-06-20 16:04:22 +04:00
|
|
|
|
2003-10-20 23:33:46 +04:00
|
|
|
// Check if we want to prettyprint
|
|
|
|
MaybePrettyPrint();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool startLayout = true;
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2007-05-31 05:42:48 +04:00
|
|
|
if (mPrettyPrinting) {
|
|
|
|
NS_ASSERTION(!mPendingSheetCount, "Shouldn't have pending sheets here!");
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2007-05-31 05:42:48 +04:00
|
|
|
// We're pretty-printing now. See whether we should wait up on
|
|
|
|
// stylesheet loads
|
|
|
|
if (mDocument->CSSLoader()->HasPendingLoads() &&
|
|
|
|
NS_SUCCEEDED(mDocument->CSSLoader()->AddObserver(this))) {
|
|
|
|
// wait for those sheets to load
|
2011-10-17 18:59:28 +04:00
|
|
|
startLayout = false;
|
2007-05-31 05:42:48 +04:00
|
|
|
}
|
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2007-05-31 05:42:48 +04:00
|
|
|
if (startLayout) {
|
2011-10-17 18:59:28 +04:00
|
|
|
StartLayout(false);
|
2002-04-16 02:53:58 +04:00
|
|
|
|
2007-05-31 05:42:48 +04:00
|
|
|
ScrollToRef();
|
|
|
|
}
|
2002-04-16 02:53:58 +04:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
mDocument->RemoveObserver(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsDocumentObserver = false;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2000-09-02 19:34:07 +04:00
|
|
|
mDocument->EndLoad();
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
DropParserAndPerfHint();
|
1999-06-28 18:49:29 +04:00
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Landing XSLT branch. Tracking bug is 155578, fixes bugs 46633, 54659, 73492, 70369, 85408, 90157, 130161, 109918, 150916 and 170097
* New scriptable interfaces to XSLT
* Make HTML-output create real html
* cleanup the XSLTProcessor class
Patch by sicking, pike and peterv
r=sicking/pike, sr=peterv, a=asa
2002-10-22 01:35:23 +04:00
|
|
|
NS_IMETHODIMP
|
2006-10-03 06:22:22 +04:00
|
|
|
nsXMLContentSink::OnDocumentCreated(nsIDocument* aResultDocument)
|
Landing XSLT branch. Tracking bug is 155578, fixes bugs 46633, 54659, 73492, 70369, 85408, 90157, 130161, 109918, 150916 and 170097
* New scriptable interfaces to XSLT
* Make HTML-output create real html
* cleanup the XSLTProcessor class
Patch by sicking, pike and peterv
r=sicking/pike, sr=peterv, a=asa
2002-10-22 01:35:23 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aResultDocument);
|
|
|
|
|
2009-11-06 07:27:30 +03:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(aResultDocument);
|
|
|
|
if (htmlDoc) {
|
2011-10-17 18:59:28 +04:00
|
|
|
htmlDoc->SetDocWriteDisabled(true);
|
2009-11-06 07:27:30 +03:00
|
|
|
}
|
|
|
|
|
Landing XSLT branch. Tracking bug is 155578, fixes bugs 46633, 54659, 73492, 70369, 85408, 90157, 130161, 109918, 150916 and 170097
* New scriptable interfaces to XSLT
* Make HTML-output create real html
* cleanup the XSLTProcessor class
Patch by sicking, pike and peterv
r=sicking/pike, sr=peterv, a=asa
2002-10-22 01:35:23 +04:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
2003-04-03 22:57:33 +04:00
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2011-10-15 11:33:26 +04:00
|
|
|
if (contentViewer) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return contentViewer->SetDocumentInternal(aResultDocument, true);
|
Landing XSLT branch. Tracking bug is 155578, fixes bugs 46633, 54659, 73492, 70369, 85408, 90157, 130161, 109918, 150916 and 170097
* New scriptable interfaces to XSLT
* Make HTML-output create real html
* cleanup the XSLTProcessor class
Patch by sicking, pike and peterv
r=sicking/pike, sr=peterv, a=asa
2002-10-22 01:35:23 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-28 18:49:29 +04:00
|
|
|
NS_IMETHODIMP
|
2002-06-20 16:04:22 +04:00
|
|
|
nsXMLContentSink::OnTransformDone(nsresult aResult,
|
2006-10-03 06:22:22 +04:00
|
|
|
nsIDocument* aResultDocument)
|
1999-06-28 18:49:29 +04:00
|
|
|
{
|
2002-06-20 16:04:22 +04:00
|
|
|
NS_ASSERTION(NS_FAILED(aResult) || aResultDocument,
|
|
|
|
"Don't notify about transform success without a document.");
|
2000-09-17 00:53:08 +04:00
|
|
|
|
2006-10-03 06:22:22 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aResultDocument);
|
|
|
|
|
2002-06-20 16:04:22 +04:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
2003-04-03 22:57:33 +04:00
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2001-03-12 09:34:40 +03:00
|
|
|
|
2002-06-20 16:04:22 +04:00
|
|
|
if (NS_FAILED(aResult) && contentViewer) {
|
|
|
|
// Transform failed.
|
2006-10-03 06:22:22 +04:00
|
|
|
if (domDoc) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aResultDocument->SetMayStartLayout(false);
|
2002-06-20 16:04:22 +04:00
|
|
|
// We have an error document.
|
2006-10-03 06:22:22 +04:00
|
|
|
contentViewer->SetDOMDocument(domDoc);
|
2000-09-02 19:34:07 +04:00
|
|
|
}
|
2002-06-20 16:04:22 +04:00
|
|
|
else {
|
|
|
|
// We don't have an error document, display the
|
|
|
|
// untransformed source document.
|
|
|
|
nsCOMPtr<nsIDOMDocument> document = do_QueryInterface(mDocument);
|
|
|
|
contentViewer->SetDOMDocument(document);
|
|
|
|
}
|
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
|
2002-06-20 16:04:22 +04:00
|
|
|
nsCOMPtr<nsIDocument> originalDocument = mDocument;
|
|
|
|
if (NS_SUCCEEDED(aResult) || aResultDocument) {
|
|
|
|
// Transform succeeded or it failed and we have an error
|
|
|
|
// document to display.
|
2006-10-03 06:22:22 +04:00
|
|
|
mDocument = aResultDocument;
|
2009-11-06 07:27:30 +03:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
|
|
|
|
if (htmlDoc) {
|
2011-10-17 18:59:28 +04:00
|
|
|
htmlDoc->SetDocWriteDisabled(false);
|
2009-11-06 07:27:30 +03:00
|
|
|
}
|
2002-06-20 16:04:22 +04:00
|
|
|
}
|
2000-09-02 19:34:07 +04:00
|
|
|
|
2003-10-11 04:27:45 +04:00
|
|
|
// Notify document observers that all the content has been stuck
|
2015-05-03 22:32:33 +03:00
|
|
|
// into the document.
|
2003-10-11 04:27:45 +04:00
|
|
|
// XXX do we need to notify for things like PIs? Or just the
|
|
|
|
// documentElement?
|
2010-04-30 17:12:05 +04:00
|
|
|
nsIContent *rootElement = mDocument->GetRootElement();
|
|
|
|
if (rootElement) {
|
|
|
|
NS_ASSERTION(mDocument->IndexOf(rootElement) != -1,
|
|
|
|
"rootElement not in doc?");
|
2003-10-11 04:27:45 +04:00
|
|
|
mDocument->BeginUpdate(UPDATE_CONTENT_MODEL);
|
2010-04-30 17:12:05 +04:00
|
|
|
nsNodeUtils::ContentInserted(mDocument, rootElement,
|
|
|
|
mDocument->IndexOf(rootElement));
|
2003-10-11 04:27:45 +04:00
|
|
|
mDocument->EndUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
}
|
2010-08-28 09:54:57 +04:00
|
|
|
|
2002-06-20 16:04:22 +04:00
|
|
|
// Start the layout process
|
2011-10-17 18:59:28 +04:00
|
|
|
StartLayout(false);
|
2002-04-25 15:58:08 +04:00
|
|
|
|
2007-02-03 03:48:29 +03:00
|
|
|
ScrollToRef();
|
2002-04-25 15:58:08 +04:00
|
|
|
|
2002-06-20 16:04:22 +04:00
|
|
|
originalDocument->EndLoad();
|
2002-04-25 15:58:08 +04:00
|
|
|
|
2002-06-20 16:04:22 +04:00
|
|
|
return NS_OK;
|
1999-06-28 18:49:29 +04:00
|
|
|
}
|
|
|
|
|
2007-05-31 05:42:48 +04:00
|
|
|
NS_IMETHODIMP
|
2014-06-20 14:32:49 +04:00
|
|
|
nsXMLContentSink::StyleSheetLoaded(CSSStyleSheet* aSheet,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aWasAlternate,
|
2007-05-31 05:42:48 +04:00
|
|
|
nsresult aStatus)
|
|
|
|
{
|
|
|
|
if (!mPrettyPrinting) {
|
|
|
|
return nsContentSink::StyleSheetLoaded(aSheet, aWasAlternate, aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDocument->CSSLoader()->HasPendingLoads()) {
|
|
|
|
mDocument->CSSLoader()->RemoveObserver(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
StartLayout(false);
|
2007-05-31 05:42:48 +04:00
|
|
|
ScrollToRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-28 18:49:29 +04:00
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
NS_IMETHODIMP
|
1998-11-12 01:06:16 +03:00
|
|
|
nsXMLContentSink::WillInterrupt(void)
|
|
|
|
{
|
2007-01-31 00:21:06 +03:00
|
|
|
return WillInterruptImpl();
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
NS_IMETHODIMP
|
1998-11-12 01:06:16 +03:00
|
|
|
nsXMLContentSink::WillResume(void)
|
|
|
|
{
|
2007-01-31 00:21:06 +03:00
|
|
|
return WillResumeImpl();
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
1998-12-11 20:02:37 +03:00
|
|
|
NS_IMETHODIMP
|
2012-01-20 15:16:27 +04:00
|
|
|
nsXMLContentSink::SetParser(nsParserBase* aParser)
|
1998-12-11 20:02:37 +03:00
|
|
|
{
|
2007-04-27 08:05:08 +04:00
|
|
|
NS_PRECONDITION(aParser, "Should have a parser here!");
|
1998-12-11 20:02:37 +03:00
|
|
|
mParser = aParser;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXMLContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
|
2014-06-20 06:01:40 +04:00
|
|
|
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
|
2011-09-29 10:19:26 +04:00
|
|
|
nsIContent** aResult, bool* aAppendContent,
|
2010-10-25 16:17:38 +04:00
|
|
|
FromParser aFromParser)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2002-12-03 02:24:57 +03:00
|
|
|
NS_ASSERTION(aNodeInfo, "can't create element without nodeinfo");
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
*aAppendContent = true;
|
2002-09-04 10:57:25 +04:00
|
|
|
nsresult rv = NS_OK;
|
2002-12-03 02:24:57 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
|
|
|
nsRefPtr<Element> content;
|
2011-11-16 11:50:19 +04:00
|
|
|
rv = NS_NewElement(getter_AddRefs(content), ni.forget(), aFromParser);
|
2004-06-25 16:26:02 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-12-03 02:24:57 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aNodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XHTML)
|
|
|
|
|| aNodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_SVG)
|
2004-07-07 02:52:03 +04:00
|
|
|
) {
|
2006-11-04 08:45:02 +03:00
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(content);
|
|
|
|
sele->SetScriptLineNumber(aLineNumber);
|
2012-01-20 15:16:27 +04:00
|
|
|
sele->SetCreatorParser(GetParser());
|
2004-07-07 02:52:03 +04:00
|
|
|
}
|
|
|
|
|
2002-12-03 02:24:57 +03:00
|
|
|
// XHTML needs some special attention
|
2004-04-13 03:21:42 +04:00
|
|
|
if (aNodeInfo->NamespaceEquals(kNameSpaceID_XHTML)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrettyPrintHasFactoredElements = true;
|
2004-04-13 03:21:42 +04:00
|
|
|
}
|
|
|
|
else {
|
2002-12-03 02:24:57 +03:00
|
|
|
// If we care, find out if we just used a special factory.
|
|
|
|
if (!mPrettyPrintHasFactoredElements && !mPrettyPrintHasSpecialRoot &&
|
|
|
|
mPrettyPrintXML) {
|
2004-06-25 16:26:02 +04:00
|
|
|
mPrettyPrintHasFactoredElements =
|
2005-09-11 14:08:43 +04:00
|
|
|
nsContentUtils::NameSpaceManager()->
|
2004-06-25 16:26:02 +04:00
|
|
|
HasElementCreator(aNodeInfo->NamespaceID());
|
2002-12-03 02:24:57 +03:00
|
|
|
}
|
|
|
|
|
2004-04-13 03:21:42 +04:00
|
|
|
if (!aNodeInfo->NamespaceEquals(kNameSpaceID_SVG)) {
|
2013-12-03 18:40:11 +04:00
|
|
|
content.forget(aResult);
|
2002-12-03 02:24:57 +03:00
|
|
|
|
2004-04-13 03:21:42 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2002-12-03 02:24:57 +03:00
|
|
|
|
2008-08-18 06:10:28 +04:00
|
|
|
if (aNodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML) ||
|
|
|
|
aNodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_XHTML) ||
|
|
|
|
aNodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_SVG)) {
|
2004-04-13 03:21:42 +04:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(content));
|
2002-12-03 02:24:57 +03:00
|
|
|
if (ssle) {
|
2011-10-17 18:59:28 +04:00
|
|
|
ssle->InitStyleLinkElement(false);
|
2010-10-19 07:45:34 +04:00
|
|
|
if (aFromParser) {
|
2011-10-17 18:59:28 +04:00
|
|
|
ssle->SetEnableUpdates(false);
|
2010-10-19 07:45:34 +04:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (!aNodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML)) {
|
2010-10-19 07:45:34 +04:00
|
|
|
ssle->SetLineNumber(aFromParser ? aLineNumber : 0);
|
2004-09-09 21:32:35 +04:00
|
|
|
}
|
2002-12-03 02:24:57 +03:00
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
}
|
2002-09-04 10:57:25 +04:00
|
|
|
|
2013-12-03 18:40:11 +04:00
|
|
|
content.forget(aResult);
|
2004-04-13 03:21:42 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-12-03 02:24:57 +03:00
|
|
|
|
|
|
|
nsresult
|
2006-11-04 08:45:02 +03:00
|
|
|
nsXMLContentSink::CloseElement(nsIContent* aContent)
|
2002-12-03 02:24:57 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent, "missing element to close");
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
mozilla::dom::NodeInfo *nodeInfo = aContent->NodeInfo();
|
2004-04-13 03:21:42 +04:00
|
|
|
|
2004-12-02 01:41:20 +03:00
|
|
|
// Some HTML nodes need DoneAddingChildren() called to initialize
|
|
|
|
// properly (eg form state restoration).
|
|
|
|
if ((nodeInfo->NamespaceID() == kNameSpaceID_XHTML &&
|
2006-12-26 20:47:52 +03:00
|
|
|
(nodeInfo->NameAtom() == nsGkAtoms::select ||
|
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::textarea ||
|
2008-07-09 12:22:20 +04:00
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::video ||
|
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::audio ||
|
2006-12-26 20:47:52 +03:00
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::object ||
|
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::applet))
|
2008-08-18 06:10:28 +04:00
|
|
|
|| nodeInfo->NameAtom() == nsGkAtoms::title
|
2004-12-02 01:41:20 +03:00
|
|
|
) {
|
2008-04-18 02:30:51 +04:00
|
|
|
aContent->DoneAddingChildren(HaveNotifiedForCurrentContent());
|
2004-12-02 01:41:20 +03:00
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
if (IsMonolithicContainer(nodeInfo)) {
|
|
|
|
mInMonolithicContainer--;
|
|
|
|
}
|
|
|
|
|
2004-04-13 03:21:42 +04:00
|
|
|
if (!nodeInfo->NamespaceEquals(kNameSpaceID_XHTML) &&
|
|
|
|
!nodeInfo->NamespaceEquals(kNameSpaceID_SVG)) {
|
2002-12-03 02:24:57 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-11-19 04:20:56 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XHTML)
|
|
|
|
|| nodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_SVG)
|
2004-07-07 02:52:03 +04:00
|
|
|
) {
|
2011-11-16 11:50:18 +04:00
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(aContent);
|
2006-11-04 08:45:02 +03:00
|
|
|
|
2011-08-01 11:48:28 +04:00
|
|
|
if (mPreventScriptExecution) {
|
|
|
|
sele->PreventExecution();
|
2011-11-16 11:50:18 +04:00
|
|
|
return NS_OK;
|
2011-08-01 11:48:28 +04:00
|
|
|
}
|
|
|
|
|
2012-01-20 15:16:27 +04:00
|
|
|
// Always check the clock in nsContentSink right after a script
|
|
|
|
StopDeflecting();
|
|
|
|
|
2006-11-04 08:45:02 +03:00
|
|
|
// Now tell the script that it's ready to go. This may execute the script
|
2011-11-16 11:50:18 +04:00
|
|
|
// or return true, or neither if the script doesn't need executing.
|
|
|
|
bool block = sele->AttemptToExecute();
|
2006-11-04 08:45:02 +03:00
|
|
|
|
|
|
|
// If the parser got blocked, make sure to return the appropriate rv.
|
|
|
|
// I'm not sure if this is actually needed or not.
|
|
|
|
if (mParser && !mParser->IsParserEnabled()) {
|
|
|
|
// XXX The HTML sink doesn't call BlockParser here, why do we?
|
2012-01-20 15:16:27 +04:00
|
|
|
GetParser()->BlockParser();
|
2011-11-16 11:50:18 +04:00
|
|
|
block = true;
|
2006-11-04 08:45:02 +03:00
|
|
|
}
|
|
|
|
|
2011-11-16 11:50:18 +04:00
|
|
|
return block ? NS_ERROR_HTMLPARSER_BLOCK : NS_OK;
|
2002-12-03 02:24:57 +03:00
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2011-11-16 11:50:18 +04:00
|
|
|
nsresult rv = NS_OK;
|
2010-04-23 20:10:07 +04:00
|
|
|
if (nodeInfo->Equals(nsGkAtoms::meta, kNameSpaceID_XHTML) &&
|
2004-04-20 21:12:48 +04:00
|
|
|
// Need to check here to make sure this meta tag does not set
|
|
|
|
// mPrettyPrintXML to false when we have a special root!
|
|
|
|
(!mPrettyPrintXML || !mPrettyPrintHasSpecialRoot)) {
|
2002-12-03 02:24:57 +03:00
|
|
|
rv = ProcessMETATag(aContent);
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (nodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML) ||
|
|
|
|
nodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_XHTML) ||
|
|
|
|
nodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_SVG)) {
|
2002-12-03 02:24:57 +03:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aContent));
|
|
|
|
if (ssle) {
|
2011-10-17 18:59:28 +04:00
|
|
|
ssle->SetEnableUpdates(true);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool willNotify;
|
|
|
|
bool isAlternate;
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this,
|
2011-08-01 11:48:24 +04:00
|
|
|
&willNotify,
|
|
|
|
&isAlternate);
|
2012-01-20 16:03:49 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && willNotify && !isAlternate && !mRunsToCompletion) {
|
2007-04-21 02:59:18 +04:00
|
|
|
++mPendingSheetCount;
|
|
|
|
mScriptLoader->AddExecuteBlocker();
|
2002-12-03 02:24:57 +03:00
|
|
|
}
|
|
|
|
}
|
2008-11-08 02:00:26 +03:00
|
|
|
// Look for <link rel="dns-prefetch" href="hostname">
|
2011-08-29 20:26:23 +04:00
|
|
|
// and look for <link rel="next" href="hostname"> like in HTML sink
|
2008-11-08 02:00:26 +03:00
|
|
|
if (nodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML)) {
|
|
|
|
nsAutoString relVal;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::rel, relVal);
|
2011-08-29 20:26:23 +04:00
|
|
|
if (!relVal.IsEmpty()) {
|
2014-07-08 06:02:03 +04:00
|
|
|
uint32_t linkTypes =
|
|
|
|
nsStyleLinkElement::ParseLinkTypes(relVal, aContent->NodePrincipal());
|
2014-02-27 17:44:52 +04:00
|
|
|
bool hasPrefetch = linkTypes & nsStyleLinkElement::ePREFETCH;
|
|
|
|
if (hasPrefetch || (linkTypes & nsStyleLinkElement::eNEXT)) {
|
2011-08-29 20:26:23 +04:00
|
|
|
nsAutoString hrefVal;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::href, hrefVal);
|
|
|
|
if (!hrefVal.IsEmpty()) {
|
|
|
|
PrefetchHref(hrefVal, aContent, hasPrefetch);
|
|
|
|
}
|
|
|
|
}
|
2014-02-27 17:44:52 +04:00
|
|
|
if (linkTypes & nsStyleLinkElement::eDNS_PREFETCH) {
|
2011-08-29 20:26:23 +04:00
|
|
|
nsAutoString hrefVal;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::href, hrefVal);
|
|
|
|
if (!hrefVal.IsEmpty()) {
|
|
|
|
PrefetchDNS(hrefVal);
|
|
|
|
}
|
2008-11-08 02:00:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-12-03 02:24:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2015-05-03 22:32:33 +03:00
|
|
|
}
|
2002-12-03 02:24:57 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::AddContentAsLeaf(nsIContent *aContent)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
if ((eXMLContentSinkState_InProlog == mState) ||
|
|
|
|
(eXMLContentSinkState_InEpilog == mState)) {
|
2006-01-19 06:34:18 +03:00
|
|
|
NS_ASSERTION(mDocument, "Fragments have no prolog or epilog");
|
2011-10-17 18:59:28 +04:00
|
|
|
mDocument->AppendChildTo(aContent, false);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
else {
|
2003-07-03 09:34:26 +04:00
|
|
|
nsCOMPtr<nsIContent> parent = GetCurrentContent();
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
if (parent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
result = parent->AppendChildTo(aContent, false);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
// Create an XML parser and an XSL content sink and start parsing
|
2004-01-10 02:54:21 +03:00
|
|
|
// the XSL stylesheet located at the given URI.
|
2002-01-09 04:37:50 +03:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::LoadXSLStyleSheet(nsIURI* aUrl)
|
|
|
|
{
|
2008-04-18 02:22:44 +04:00
|
|
|
nsCOMPtr<nsIDocumentTransformer> processor =
|
2003-04-01 23:50:42 +04:00
|
|
|
do_CreateInstance("@mozilla.org/document-transformer;1?type=xslt");
|
2008-04-18 02:22:44 +04:00
|
|
|
if (!processor) {
|
2002-01-09 04:37:50 +03:00
|
|
|
// No XSLT processor available, continue normal document loading
|
2001-11-02 04:53:13 +03:00
|
|
|
return NS_OK;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2000-05-10 17:13:39 +04:00
|
|
|
|
2008-04-18 02:22:44 +04:00
|
|
|
processor->SetTransformObserver(this);
|
2001-02-03 04:16:20 +03:00
|
|
|
|
2014-10-08 12:29:11 +04:00
|
|
|
if (NS_SUCCEEDED(processor->LoadStyleSheet(aUrl, mDocument))) {
|
2008-04-18 02:22:44 +04:00
|
|
|
mXSLTProcessor.swap(processor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intentionally ignore errors here, we should continue loading the
|
|
|
|
// XML document whether we're able to load the XSLT stylesheet or
|
|
|
|
// not.
|
|
|
|
|
|
|
|
return NS_OK;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2003-10-05 11:29:50 +04:00
|
|
|
nsresult
|
2002-01-09 04:37:50 +03:00
|
|
|
nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
|
2005-03-30 04:36:57 +04:00
|
|
|
const nsSubstring& aHref,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aAlternate,
|
2005-03-30 04:36:57 +04:00
|
|
|
const nsSubstring& aTitle,
|
|
|
|
const nsSubstring& aType,
|
|
|
|
const nsSubstring& aMedia)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrettyPrintXML = false;
|
2001-07-04 23:35:23 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString cmd;
|
2004-07-18 01:45:37 +04:00
|
|
|
if (mParser)
|
2012-01-20 15:16:27 +04:00
|
|
|
GetParser()->GetCommand(cmd);
|
2004-06-26 18:32:11 +04:00
|
|
|
if (cmd.EqualsASCII(kLoadAsData))
|
2002-10-11 04:38:29 +04:00
|
|
|
return NS_OK; // Do not load stylesheets when loading as data
|
|
|
|
|
2003-10-05 11:29:50 +04:00
|
|
|
NS_ConvertUTF16toUTF8 type(aType);
|
2009-11-21 02:12:42 +03:00
|
|
|
if (type.EqualsIgnoreCase(TEXT_XSL) ||
|
2011-05-28 16:34:36 +04:00
|
|
|
type.EqualsIgnoreCase(APPLICATION_XSLT_XML) ||
|
2009-11-21 02:12:42 +03:00
|
|
|
type.EqualsIgnoreCase(TEXT_XML) ||
|
|
|
|
type.EqualsIgnoreCase(APPLICATION_XML)) {
|
2002-08-29 10:53:59 +04:00
|
|
|
if (aAlternate) {
|
|
|
|
// don't load alternate XSLT
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-04-03 22:57:33 +04:00
|
|
|
// LoadXSLStyleSheet needs a mDocShell.
|
|
|
|
if (!mDocShell)
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
2000-08-30 04:35:43 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
nsCOMPtr<nsIURI> url;
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = NS_NewURI(getter_AddRefs(url), aHref, nullptr,
|
2010-04-19 19:40:15 +04:00
|
|
|
mDocument->GetDocBaseURI());
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-05-19 06:59:15 +04:00
|
|
|
|
2004-10-24 21:25:58 +04:00
|
|
|
// Do security check
|
2005-10-14 13:07:29 +04:00
|
|
|
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
|
2004-04-25 20:55:27 +04:00
|
|
|
rv = secMan->
|
2008-03-04 08:39:09 +03:00
|
|
|
CheckLoadURIWithPrincipal(mDocument->NodePrincipal(), url,
|
|
|
|
nsIScriptSecurityManager::ALLOW_CHROME);
|
2002-12-03 12:20:43 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
|
|
|
|
2004-10-24 21:25:58 +04:00
|
|
|
// Do content policy check
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t decision = nsIContentPolicy::ACCEPT;
|
2013-09-12 01:11:49 +04:00
|
|
|
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_XSLT,
|
2004-10-24 21:25:58 +04:00
|
|
|
url,
|
2007-08-08 05:16:09 +04:00
|
|
|
mDocument->NodePrincipal(),
|
2004-10-24 21:25:58 +04:00
|
|
|
aElement,
|
|
|
|
type,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr,
|
2005-08-19 19:00:01 +04:00
|
|
|
&decision,
|
2007-08-08 05:16:09 +04:00
|
|
|
nsContentUtils::GetContentPolicy(),
|
|
|
|
nsContentUtils::GetSecurityManager());
|
2004-10-24 21:25:58 +04:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (NS_CP_REJECTED(decision)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-12-03 12:20:43 +03:00
|
|
|
return LoadXSLStyleSheet(url);
|
|
|
|
}
|
|
|
|
|
2003-10-05 11:29:50 +04:00
|
|
|
// Let nsContentSink deal with css.
|
|
|
|
rv = nsContentSink::ProcessStyleLink(aElement, aHref, aAlternate,
|
|
|
|
aTitle, aType, aMedia);
|
|
|
|
|
2007-04-21 02:59:18 +04:00
|
|
|
// nsContentSink::ProcessStyleLink handles the bookkeeping here wrt
|
|
|
|
// pending sheets.
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2003-10-05 11:29:50 +04:00
|
|
|
return rv;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
2015-05-03 22:32:33 +03:00
|
|
|
NS_IMETHODIMP
|
2003-06-17 20:40:34 +04:00
|
|
|
nsXMLContentSink::SetDocumentCharset(nsACString& aCharset)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
if (mDocument) {
|
2003-10-22 10:09:48 +04:00
|
|
|
mDocument->SetDocumentCharacterSet(aCharset);
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-16 09:16:17 +03:00
|
|
|
|
2004-11-02 22:52:32 +03:00
|
|
|
nsISupports *
|
|
|
|
nsXMLContentSink::GetTarget()
|
|
|
|
{
|
|
|
|
return mDocument;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-04-16 02:34:50 +04:00
|
|
|
nsXMLContentSink::IsScriptExecuting()
|
|
|
|
{
|
|
|
|
return IsScriptExecutingImpl();
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXMLContentSink::FlushText(bool aReleaseTextNode)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2008-10-16 01:29:35 +04:00
|
|
|
nsresult rv = NS_OK;
|
2003-03-26 10:41:30 +03:00
|
|
|
|
2008-10-16 01:29:35 +04:00
|
|
|
if (mTextLength != 0) {
|
|
|
|
if (mLastTextNode) {
|
2015-09-22 23:13:16 +03:00
|
|
|
bool notify = HaveNotifiedForCurrentContent();
|
|
|
|
// We could probably always increase mInNotification here since
|
|
|
|
// if AppendText doesn't notify it shouldn't trigger evil code.
|
|
|
|
// But just in case it does, we don't want to mask any notifications.
|
|
|
|
if (notify) {
|
|
|
|
++mInNotification;
|
|
|
|
}
|
|
|
|
rv = mLastTextNode->AppendText(mText, mTextLength, notify);
|
|
|
|
if (notify) {
|
|
|
|
--mInNotification;
|
2008-10-16 01:29:35 +04:00
|
|
|
}
|
2015-09-22 23:13:16 +03:00
|
|
|
|
|
|
|
mTextLength = 0;
|
2008-10-16 01:29:35 +04:00
|
|
|
} else {
|
2013-04-04 16:01:08 +04:00
|
|
|
nsRefPtr<nsTextNode> textContent = new nsTextNode(mNodeInfoManager);
|
2007-06-27 08:22:35 +04:00
|
|
|
|
2008-10-16 01:29:35 +04:00
|
|
|
mLastTextNode = textContent;
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2008-10-16 01:29:35 +04:00
|
|
|
// Set the text in the text node
|
2011-10-17 18:59:28 +04:00
|
|
|
textContent->SetText(mText, mTextLength, false);
|
2008-10-16 01:29:35 +04:00
|
|
|
mTextLength = 0;
|
|
|
|
|
|
|
|
// Add text to its parent
|
|
|
|
rv = AddContentAsLeaf(textContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aReleaseTextNode) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mLastTextNode = nullptr;
|
2008-10-16 01:29:35 +04:00
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2008-10-16 01:29:35 +04:00
|
|
|
return rv;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
nsIContent*
|
|
|
|
nsXMLContentSink::GetCurrentContent()
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
2007-01-31 00:21:06 +03:00
|
|
|
if (mContentStack.Length() == 0) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2010-10-05 05:25:44 +04:00
|
|
|
return GetCurrentStackNode()->mContent;
|
2007-01-31 00:21:06 +03:00
|
|
|
}
|
2003-07-03 09:34:26 +04:00
|
|
|
|
2010-10-05 05:25:44 +04:00
|
|
|
StackNode*
|
2007-01-31 00:21:06 +03:00
|
|
|
nsXMLContentSink::GetCurrentStackNode()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = mContentStack.Length();
|
2012-07-30 18:20:58 +04:00
|
|
|
return count != 0 ? &mContentStack[count-1] : nullptr;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
|
|
|
|
nsresult
|
2002-01-09 04:37:50 +03:00
|
|
|
nsXMLContentSink::PushContent(nsIContent *aContent)
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
{
|
2003-07-03 09:34:26 +04:00
|
|
|
NS_PRECONDITION(aContent, "Null content being pushed!");
|
2007-01-31 00:21:06 +03:00
|
|
|
StackNode *sn = mContentStack.AppendElement();
|
|
|
|
NS_ENSURE_TRUE(sn, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2014-06-05 02:21:23 +04:00
|
|
|
nsIContent* contentToPush = aContent;
|
|
|
|
|
|
|
|
// When an XML parser would append a node to a template element, it
|
|
|
|
// must instead append it to the template element's template contents.
|
2015-03-03 14:08:59 +03:00
|
|
|
if (contentToPush->IsHTMLElement(nsGkAtoms::_template)) {
|
2014-06-05 02:21:23 +04:00
|
|
|
HTMLTemplateElement* templateElement =
|
|
|
|
static_cast<HTMLTemplateElement*>(contentToPush);
|
|
|
|
contentToPush = templateElement->Content();
|
|
|
|
}
|
|
|
|
|
|
|
|
sn->mContent = contentToPush;
|
2007-01-31 00:21:06 +03:00
|
|
|
sn->mNumFlushed = 0;
|
|
|
|
return NS_OK;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
void
|
2002-01-09 04:37:50 +03:00
|
|
|
nsXMLContentSink::PopContent()
|
2007-01-31 00:21:06 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = mContentStack.Length();
|
2003-07-03 09:34:26 +04:00
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
NS_WARNING("Popping empty stack");
|
2007-01-31 00:21:06 +03:00
|
|
|
return;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
mContentStack.RemoveElementAt(count - 1);
|
|
|
|
}
|
2003-07-03 09:34:26 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-04-18 02:30:51 +04:00
|
|
|
nsXMLContentSink::HaveNotifiedForCurrentContent() const
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t stackLength = mContentStack.Length();
|
2008-04-18 02:30:51 +04:00
|
|
|
if (stackLength) {
|
|
|
|
const StackNode& stackNode = mContentStack[stackLength - 1];
|
|
|
|
nsIContent* parent = stackNode.mContent;
|
|
|
|
return stackNode.mNumFlushed == parent->GetChildCount();
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-04-18 02:30:51 +04:00
|
|
|
}
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXMLContentSink::MaybeStartLayout(bool aIgnorePendingSheets)
|
2007-01-31 00:21:06 +03:00
|
|
|
{
|
2007-04-21 02:59:18 +04:00
|
|
|
// XXXbz if aIgnorePendingSheets is true, what should we do when
|
|
|
|
// mXSLTProcessor or CanStillPrettyPrint()?
|
2007-01-31 00:21:06 +03:00
|
|
|
if (mLayoutStarted || mXSLTProcessor || CanStillPrettyPrint()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-04-21 02:59:18 +04:00
|
|
|
StartLayout(aIgnorePendingSheets);
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
2002-04-04 19:42:45 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsXMLContentSink::SetDocElement(int32_t aNameSpaceID,
|
2004-10-01 02:27:45 +04:00
|
|
|
nsIAtom* aTagName,
|
|
|
|
nsIContent *aContent)
|
|
|
|
{
|
|
|
|
if (mDocElement)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2004-10-01 02:27:45 +04:00
|
|
|
|
|
|
|
// check for root elements that needs special handling for
|
|
|
|
// prettyprinting
|
|
|
|
if ((aNameSpaceID == kNameSpaceID_XBL &&
|
2006-12-26 20:47:52 +03:00
|
|
|
aTagName == nsGkAtoms::bindings) ||
|
2004-10-01 02:27:45 +04:00
|
|
|
(aNameSpaceID == kNameSpaceID_XSLT &&
|
2006-12-26 20:47:52 +03:00
|
|
|
(aTagName == nsGkAtoms::stylesheet ||
|
|
|
|
aTagName == nsGkAtoms::transform))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrettyPrintHasSpecialRoot = true;
|
2004-10-01 02:27:45 +04:00
|
|
|
if (mPrettyPrintXML) {
|
|
|
|
// In this case, disable script execution, stylesheet
|
|
|
|
// loading, and auto XLinks since we plan to prettyprint.
|
2011-10-17 18:59:28 +04:00
|
|
|
mDocument->ScriptLoader()->SetEnabled(false);
|
2004-10-01 02:27:45 +04:00
|
|
|
if (mCSSLoader) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mCSSLoader->SetEnabled(false);
|
2004-10-01 02:27:45 +04:00
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
}
|
2004-10-01 02:27:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mDocElement = aContent;
|
2010-05-03 17:23:36 +04:00
|
|
|
nsresult rv = mDocument->AppendChildTo(mDocElement, NotifyForDocElement());
|
2005-04-06 03:54:35 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
// If we return false here, the caller will bail out because it won't
|
2005-04-06 03:54:35 +04:00
|
|
|
// find a parent content node to append to, which is fine.
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2005-04-06 03:54:35 +04:00
|
|
|
}
|
2009-02-10 09:40:40 +03:00
|
|
|
|
|
|
|
if (aTagName == nsGkAtoms::html &&
|
|
|
|
aNameSpaceID == kNameSpaceID_XHTML) {
|
|
|
|
ProcessOfflineManifest(aContent);
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2004-10-01 02:27:45 +04:00
|
|
|
}
|
|
|
|
|
2007-06-11 14:15:17 +04:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXMLContentSink::HandleStartElement(const char16_t *aName,
|
|
|
|
const char16_t **aAtts,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aAttsCount,
|
|
|
|
uint32_t aLineNumber)
|
2007-06-11 14:15:17 +04:00
|
|
|
{
|
2014-05-30 11:36:53 +04:00
|
|
|
return HandleStartElement(aName, aAtts, aAttsCount, aLineNumber,
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2007-06-11 14:15:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXMLContentSink::HandleStartElement(const char16_t *aName,
|
|
|
|
const char16_t **aAtts,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aAttsCount,
|
|
|
|
uint32_t aLineNumber,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aInterruptable)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2003-10-30 05:17:50 +03:00
|
|
|
NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount");
|
|
|
|
// Adjust aAttsCount so it's the actual number of attributes
|
|
|
|
aAttsCount /= 2;
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
nsresult result = NS_OK;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool appendContent = true;
|
2002-01-09 04:37:50 +03:00
|
|
|
nsCOMPtr<nsIContent> content;
|
2001-03-01 02:51:35 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
// XXX Hopefully the parser will flag this before we get
|
|
|
|
// here. If we're in the epilog, there should be no
|
|
|
|
// new elements
|
|
|
|
PR_ASSERT(eXMLContentSinkState_InEpilog != mState);
|
2001-03-01 02:51:35 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
FlushText();
|
2007-01-31 00:21:06 +03:00
|
|
|
DidAddContent();
|
2001-03-01 02:51:35 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
mState = eXMLContentSinkState_InDocumentElement;
|
2001-05-19 06:59:15 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nameSpaceID;
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
nsContentUtils::SplitExpatName(aName, getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-03-01 02:51:35 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (!OnOpenContainer(aAtts, aAttsCount, nameSpaceID, localName, aLineNumber)) {
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
2004-01-08 07:25:43 +03:00
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2011-06-14 11:56:49 +04:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2002-12-03 02:24:57 +03:00
|
|
|
result = CreateElement(aAtts, aAttsCount, nodeInfo, aLineNumber,
|
2010-10-25 16:17:38 +04:00
|
|
|
getter_AddRefs(content), &appendContent,
|
|
|
|
FROM_PARSER_NETWORK);
|
2002-12-03 02:24:57 +03:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2001-05-01 03:35:09 +04:00
|
|
|
|
2007-05-16 06:21:55 +04:00
|
|
|
// Have to do this before we push the new content on the stack... and have to
|
|
|
|
// do that before we set attributes, call BindToTree, etc. Ideally we'd push
|
|
|
|
// on the stack inside CreateElement (which is effectively what the HTML sink
|
|
|
|
// does), but that's hard with all the subclass overrides going on.
|
|
|
|
nsCOMPtr<nsIContent> parent = GetCurrentContent();
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2007-05-16 06:21:55 +04:00
|
|
|
result = PushContent(content);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2002-12-03 02:24:57 +03:00
|
|
|
// Set the attributes on the new content element
|
|
|
|
result = AddAttributes(aAtts, content);
|
2001-05-01 03:35:09 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
if (NS_OK == result) {
|
2015-05-03 22:32:33 +03:00
|
|
|
// Store the element
|
2004-12-15 18:37:23 +03:00
|
|
|
if (!SetDocElement(nameSpaceID, localName, content) && appendContent) {
|
2002-12-03 02:24:57 +03:00
|
|
|
NS_ENSURE_TRUE(parent, NS_ERROR_UNEXPECTED);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
parent->AppendChildTo(content, false);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2002-12-03 02:24:57 +03:00
|
|
|
}
|
2002-05-21 02:47:02 +04:00
|
|
|
|
2004-12-02 01:41:20 +03:00
|
|
|
// Some HTML nodes need DoneCreatingElement() called to initialize
|
|
|
|
// properly (eg form state restoration).
|
2007-07-11 07:42:11 +04:00
|
|
|
if (nodeInfo->NamespaceID() == kNameSpaceID_XHTML) {
|
|
|
|
if (nodeInfo->NameAtom() == nsGkAtoms::input ||
|
2011-08-08 21:31:32 +04:00
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::button ||
|
2013-04-05 02:07:00 +04:00
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::menuitem ||
|
2012-01-20 23:23:58 +04:00
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::audio ||
|
2013-04-05 02:07:00 +04:00
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::video) {
|
2007-07-11 07:42:11 +04:00
|
|
|
content->DoneCreatingElement();
|
|
|
|
} else if (nodeInfo->NameAtom() == nsGkAtoms::head && !mCurrentHead) {
|
|
|
|
mCurrentHead = content;
|
|
|
|
}
|
2004-12-02 01:41:20 +03:00
|
|
|
}
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
if (IsMonolithicContainer(nodeInfo)) {
|
|
|
|
mInMonolithicContainer++;
|
|
|
|
}
|
|
|
|
|
2007-07-11 07:42:11 +04:00
|
|
|
if (content != mDocElement && !mCurrentHead) {
|
|
|
|
// This isn't the root and we're not inside an XHTML <head>.
|
|
|
|
// Might need to start layout
|
2011-10-17 18:59:28 +04:00
|
|
|
MaybeStartLayout(false);
|
2007-07-11 07:42:11 +04:00
|
|
|
}
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2010-08-28 09:54:57 +04:00
|
|
|
if (content == mDocElement) {
|
|
|
|
NotifyDocElementCreated(mDocument);
|
|
|
|
}
|
|
|
|
|
2007-06-11 14:15:17 +04:00
|
|
|
return aInterruptable && NS_SUCCEEDED(result) ? DidProcessATokenImpl() :
|
|
|
|
result;
|
2001-05-01 03:35:09 +04:00
|
|
|
}
|
|
|
|
|
2007-06-11 14:15:17 +04:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXMLContentSink::HandleEndElement(const char16_t *aName)
|
2007-06-11 14:15:17 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return HandleEndElement(aName, true);
|
2007-06-11 14:15:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXMLContentSink::HandleEndElement(const char16_t *aName,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aInterruptable)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
// XXX Hopefully the parser will flag this before we get
|
|
|
|
// here. If we're in the prolog or epilog, there should be
|
|
|
|
// no close tags for elements.
|
|
|
|
PR_ASSERT(eXMLContentSinkState_InDocumentElement == mState);
|
1999-04-01 00:49:25 +04:00
|
|
|
|
|
|
|
FlushText();
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2010-10-05 05:25:44 +04:00
|
|
|
StackNode* sn = GetCurrentStackNode();
|
|
|
|
if (!sn) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2007-01-31 00:21:06 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
2010-10-05 05:25:44 +04:00
|
|
|
sn->mContent.swap(content);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numFlushed = sn->mNumFlushed;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
|
|
|
PopContent();
|
2002-12-03 02:24:57 +03:00
|
|
|
NS_ASSERTION(content, "failed to pop content");
|
2004-12-02 05:15:37 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Check that we're closing the right thing
|
|
|
|
nsCOMPtr<nsIAtom> debugNameSpacePrefix, debugTagAtom;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t debugNameSpaceID;
|
2004-12-15 18:37:23 +03:00
|
|
|
nsContentUtils::SplitExpatName(aName, getter_AddRefs(debugNameSpacePrefix),
|
|
|
|
getter_AddRefs(debugTagAtom),
|
|
|
|
&debugNameSpaceID);
|
2014-06-05 02:21:23 +04:00
|
|
|
// Check if we are closing a template element because template
|
|
|
|
// elements do not get pushed on the stack, the template
|
|
|
|
// element content is pushed instead.
|
|
|
|
bool isTemplateElement = debugTagAtom == nsGkAtoms::_template &&
|
|
|
|
debugNameSpaceID == kNameSpaceID_XHTML;
|
|
|
|
NS_ASSERTION(content->NodeInfo()->Equals(debugTagAtom, debugNameSpaceID) ||
|
|
|
|
isTemplateElement, "Wrong element being closed");
|
2015-05-03 22:32:33 +03:00
|
|
|
#endif
|
2001-07-04 23:35:23 +04:00
|
|
|
|
2006-11-04 08:45:02 +03:00
|
|
|
result = CloseElement(content);
|
2001-05-19 06:59:15 +04:00
|
|
|
|
2007-07-11 07:42:11 +04:00
|
|
|
if (mCurrentHead == content) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mCurrentHead = nullptr;
|
2007-07-11 07:42:11 +04:00
|
|
|
}
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2002-12-03 02:24:57 +03:00
|
|
|
if (mDocElement == content) {
|
2005-06-02 06:38:20 +04:00
|
|
|
// XXXbz for roots that don't want to be appended on open, we
|
|
|
|
// probably need to deal here.... (and stop appending them on open).
|
2002-12-03 02:24:57 +03:00
|
|
|
mState = eXMLContentSinkState_InEpilog;
|
2007-07-11 07:42:11 +04:00
|
|
|
|
|
|
|
// We might have had no occasion to start layout yet. Do so now.
|
2011-10-17 18:59:28 +04:00
|
|
|
MaybeStartLayout(false);
|
2002-12-03 02:24:57 +03:00
|
|
|
}
|
2001-07-04 23:35:23 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t stackLen = mContentStack.Length();
|
2007-02-28 20:28:17 +03:00
|
|
|
if (mNotifyLevel >= stackLen) {
|
|
|
|
if (numFlushed < content->GetChildCount()) {
|
2015-05-03 22:32:33 +03:00
|
|
|
NotifyAppend(content, numFlushed);
|
2007-02-28 20:28:17 +03:00
|
|
|
}
|
|
|
|
mNotifyLevel = stackLen - 1;
|
|
|
|
}
|
|
|
|
DidAddContent();
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsSVGElement(nsGkAtoms::svg)) {
|
2007-05-24 00:05:53 +04:00
|
|
|
FlushTags();
|
2010-07-19 02:07:54 +04:00
|
|
|
nsCOMPtr<nsIRunnable> event = new nsHtml5SVGLoadDispatcher(content);
|
|
|
|
if (NS_FAILED(NS_DispatchToMainThread(event))) {
|
|
|
|
NS_WARNING("failed to dispatch svg load dispatcher");
|
2007-01-31 00:21:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-11 14:15:17 +04:00
|
|
|
return aInterruptable && NS_SUCCEEDED(result) ? DidProcessATokenImpl() :
|
|
|
|
result;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2015-05-03 22:32:33 +03:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXMLContentSink::HandleComment(const char16_t *aName)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
FlushText();
|
2001-07-04 23:35:23 +04:00
|
|
|
|
2013-04-04 16:02:22 +04:00
|
|
|
nsRefPtr<Comment> comment = new Comment(mNodeInfoManager);
|
|
|
|
comment->SetText(nsDependentString(aName), false);
|
|
|
|
nsresult rv = AddContentAsLeaf(comment);
|
|
|
|
DidAddContent();
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
return NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
1998-12-27 11:24:04 +03:00
|
|
|
|
2015-05-03 22:32:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::HandleCDataSection(const char16_t *aData,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLength)
|
2000-06-17 05:49:19 +04:00
|
|
|
{
|
2006-04-06 10:17:51 +04:00
|
|
|
// XSLT doesn't differentiate between text and cdata and wants adjacent
|
|
|
|
// textnodes merged, so add as text.
|
|
|
|
if (mXSLTProcessor) {
|
|
|
|
return AddText(aData, aLength);
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
FlushText();
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2013-04-04 16:01:11 +04:00
|
|
|
nsRefPtr<CDATASection> cdata = new CDATASection(mNodeInfoManager);
|
|
|
|
cdata->SetText(aData, aLength, false);
|
|
|
|
nsresult rv = AddContentAsLeaf(cdata);
|
|
|
|
DidAddContent();
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
return NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
2000-06-17 05:49:19 +04:00
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
NS_IMETHODIMP
|
2015-05-03 22:32:33 +03:00
|
|
|
nsXMLContentSink::HandleDoctypeDecl(const nsAString & aSubset,
|
|
|
|
const nsAString & aName,
|
|
|
|
const nsAString & aSystemId,
|
2002-05-22 04:46:16 +04:00
|
|
|
const nsAString & aPublicId,
|
2002-03-15 12:45:31 +03:00
|
|
|
nsISupports* aCatalogData)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
2002-08-13 22:41:16 +04:00
|
|
|
FlushText();
|
|
|
|
|
2000-06-17 05:49:19 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2006-01-19 06:34:18 +03:00
|
|
|
NS_ASSERTION(mDocument, "Shouldn't get here from a document fragment");
|
2000-06-17 05:49:19 +04:00
|
|
|
|
2003-11-19 04:20:56 +03:00
|
|
|
nsCOMPtr<nsIAtom> name = do_GetAtom(aName);
|
|
|
|
NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2000-06-17 05:49:19 +04:00
|
|
|
// Create a new doctype node
|
2003-11-19 04:20:56 +03:00
|
|
|
nsCOMPtr<nsIDOMDocumentType> docType;
|
2011-09-17 17:32:32 +04:00
|
|
|
rv = NS_NewDOMDocumentType(getter_AddRefs(docType), mNodeInfoManager,
|
2011-04-14 16:04:21 +04:00
|
|
|
name, aPublicId, aSystemId, aSubset);
|
2000-06-17 05:49:19 +04:00
|
|
|
if (NS_FAILED(rv) || !docType) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-05-24 22:46:38 +04:00
|
|
|
MOZ_ASSERT(!aCatalogData, "Need to add back support for catalog style "
|
|
|
|
"sheets");
|
2002-03-15 12:45:31 +03:00
|
|
|
|
2006-01-19 06:34:18 +03:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(docType);
|
|
|
|
NS_ASSERTION(content, "doctype isn't content?");
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = mDocument->AppendChildTo(content, false);
|
2007-01-31 00:21:06 +03:00
|
|
|
DidAddContent();
|
|
|
|
return NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
2007-06-11 14:15:17 +04:00
|
|
|
NS_IMETHODIMP
|
2015-05-03 22:32:33 +03:00
|
|
|
nsXMLContentSink::HandleCharacterData(const char16_t *aData,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLength)
|
2007-06-11 14:15:17 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return HandleCharacterData(aData, aLength, true);
|
2007-06-11 14:15:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXMLContentSink::HandleCharacterData(const char16_t *aData, uint32_t aLength,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aInterruptable)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
2007-01-31 00:21:06 +03:00
|
|
|
nsresult rv = NS_OK;
|
2003-10-16 00:10:47 +04:00
|
|
|
if (aData && mState != eXMLContentSinkState_InProlog &&
|
|
|
|
mState != eXMLContentSinkState_InEpilog) {
|
2007-01-31 00:21:06 +03:00
|
|
|
rv = AddText(aData, aLength);
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
2007-06-11 14:15:17 +04:00
|
|
|
return aInterruptable && NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
NS_IMETHODIMP
|
2015-05-03 22:32:33 +03:00
|
|
|
nsXMLContentSink::HandleProcessingInstruction(const char16_t *aTarget,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *aData)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
2002-01-09 04:37:50 +03:00
|
|
|
FlushText();
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
const nsDependentString target(aTarget);
|
2002-04-25 15:58:08 +04:00
|
|
|
const nsDependentString data(aData);
|
|
|
|
|
2013-04-04 16:01:11 +04:00
|
|
|
nsCOMPtr<nsIContent> node =
|
|
|
|
NS_NewXMLProcessingInstruction(mNodeInfoManager, target, data);
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(node));
|
|
|
|
if (ssle) {
|
2011-10-17 18:59:28 +04:00
|
|
|
ssle->InitStyleLinkElement(false);
|
|
|
|
ssle->SetEnableUpdates(false);
|
|
|
|
mPrettyPrintXML = false;
|
2006-03-17 17:38:57 +03:00
|
|
|
}
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2013-04-04 16:01:11 +04:00
|
|
|
nsresult rv = AddContentAsLeaf(node);
|
2006-03-17 17:38:57 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-01-31 00:21:06 +03:00
|
|
|
DidAddContent();
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
if (ssle) {
|
2007-04-21 02:59:18 +04:00
|
|
|
// This is an xml-stylesheet processing instruction... but it might not be
|
|
|
|
// a CSS one if the type is set to something else.
|
2011-10-17 18:59:28 +04:00
|
|
|
ssle->SetEnableUpdates(true);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool willNotify;
|
|
|
|
bool isAlternate;
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this,
|
2011-08-01 11:48:24 +04:00
|
|
|
&willNotify,
|
|
|
|
&isAlternate);
|
2007-04-21 02:59:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2007-04-21 02:59:18 +04:00
|
|
|
if (willNotify) {
|
|
|
|
// Successfully started a stylesheet load
|
2012-01-20 16:03:49 +04:00
|
|
|
if (!isAlternate && !mRunsToCompletion) {
|
2007-04-21 02:59:18 +04:00
|
|
|
++mPendingSheetCount;
|
|
|
|
mScriptLoader->AddExecuteBlocker();
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2007-04-21 02:59:18 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2006-03-17 17:38:57 +03:00
|
|
|
}
|
2001-09-05 08:20:54 +04:00
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
// If it's not a CSS stylesheet PI...
|
|
|
|
nsAutoString type;
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::type, type);
|
2006-03-17 17:38:57 +03:00
|
|
|
|
|
|
|
if (mState != eXMLContentSinkState_InProlog ||
|
|
|
|
!target.EqualsLiteral("xml-stylesheet") ||
|
2007-04-21 02:59:18 +04:00
|
|
|
type.IsEmpty() ||
|
2006-03-17 17:38:57 +03:00
|
|
|
type.LowerCaseEqualsLiteral("text/css")) {
|
2007-01-31 00:21:06 +03:00
|
|
|
return DidProcessATokenImpl();
|
2006-03-17 17:38:57 +03:00
|
|
|
}
|
1999-01-12 19:37:24 +03:00
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
nsAutoString href, title, media;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isAlternate = false;
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
// If there was no href, we can't do anything with this PI
|
2008-11-29 00:21:55 +03:00
|
|
|
if (!ParsePIData(data, href, title, media, isAlternate)) {
|
2007-01-31 00:21:06 +03:00
|
|
|
return DidProcessATokenImpl();
|
2006-03-17 17:38:57 +03:00
|
|
|
}
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
rv = ProcessStyleLink(node, href, isAlternate, title, type, media);
|
|
|
|
return NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
2006-03-17 17:38:57 +03:00
|
|
|
}
|
2006-03-16 16:47:42 +03:00
|
|
|
|
2006-03-17 17:38:57 +03:00
|
|
|
/* static */
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2006-03-17 17:38:57 +03:00
|
|
|
nsXMLContentSink::ParsePIData(const nsString &aData, nsString &aHref,
|
|
|
|
nsString &aTitle, nsString &aMedia,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool &aIsAlternate)
|
2006-03-17 17:38:57 +03:00
|
|
|
{
|
|
|
|
// If there was no href, we can't do anything with this PI
|
2012-02-27 15:57:48 +04:00
|
|
|
if (!nsContentUtils::GetPseudoAttributeValue(aData, nsGkAtoms::href, aHref)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
2006-03-17 17:38:57 +03:00
|
|
|
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(aData, nsGkAtoms::title, aTitle);
|
2006-03-17 17:38:57 +03:00
|
|
|
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(aData, nsGkAtoms::media, aMedia);
|
2006-03-17 17:38:57 +03:00
|
|
|
|
|
|
|
nsAutoString alternate;
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(aData,
|
|
|
|
nsGkAtoms::alternate,
|
|
|
|
alternate);
|
2006-03-17 17:38:57 +03:00
|
|
|
|
|
|
|
aIsAlternate = alternate.EqualsLiteral("yes");
|
2008-11-29 00:21:55 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
2002-08-13 22:41:16 +04:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXMLContentSink::HandleXMLDeclaration(const char16_t *aVersion,
|
|
|
|
const char16_t *aEncoding,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aStandalone)
|
2002-08-13 22:41:16 +04:00
|
|
|
{
|
2004-12-17 12:17:35 +03:00
|
|
|
mDocument->SetXMLDeclaration(aVersion, aEncoding, aStandalone);
|
2002-08-13 22:41:16 +04:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
return DidProcessATokenImpl();
|
2002-08-13 22:41:16 +04:00
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_IMETHODIMP
|
2015-05-03 22:32:33 +03:00
|
|
|
nsXMLContentSink::ReportError(const char16_t* aErrorText,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aSourceText,
|
2006-08-25 20:34:57 +04:00
|
|
|
nsIScriptError *aError,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
2006-08-25 20:34:57 +04:00
|
|
|
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
2002-01-09 04:37:50 +03:00
|
|
|
nsresult rv = NS_OK;
|
2006-08-25 20:34:57 +04:00
|
|
|
|
|
|
|
// The expat driver should report the error. We're just cleaning up the mess.
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = true;
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrettyPrintXML = false;
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
|
2002-03-13 01:17:18 +03:00
|
|
|
mState = eXMLContentSinkState_InProlog;
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
// XXX need to stop scripts here -- hsivonen
|
|
|
|
|
|
|
|
// stop observing in order to avoid crashing when removing content
|
|
|
|
mDocument->RemoveObserver(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsDocumentObserver = false;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2002-03-13 01:17:18 +03:00
|
|
|
// Clear the current content and
|
|
|
|
// prepare to set <parsererror> as the document root
|
2004-12-04 20:51:12 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mDocument));
|
|
|
|
if (node) {
|
2002-03-13 01:17:18 +03:00
|
|
|
for (;;) {
|
|
|
|
nsCOMPtr<nsIDOMNode> child, dummy;
|
2004-12-04 20:51:12 +03:00
|
|
|
node->GetLastChild(getter_AddRefs(child));
|
2002-03-13 01:17:18 +03:00
|
|
|
if (!child)
|
|
|
|
break;
|
2004-12-04 20:51:12 +03:00
|
|
|
node->RemoveChild(child, getter_AddRefs(dummy));
|
2002-03-13 01:17:18 +03:00
|
|
|
}
|
|
|
|
}
|
2012-11-12 21:43:02 +04:00
|
|
|
mDocElement = nullptr;
|
2002-03-13 01:17:18 +03:00
|
|
|
|
2005-04-06 10:28:28 +04:00
|
|
|
// Clear any buffered-up text we have. It's enough to set the length to 0.
|
|
|
|
// The buffer itself is allocated when we're created and deleted in our
|
|
|
|
// destructor, so don't mess with it.
|
2005-04-05 07:40:36 +04:00
|
|
|
mTextLength = 0;
|
|
|
|
|
2003-03-26 04:10:14 +03:00
|
|
|
if (mXSLTProcessor) {
|
|
|
|
// Get rid of the XSLT processor.
|
|
|
|
mXSLTProcessor->CancelLoads();
|
2012-07-30 18:20:58 +04:00
|
|
|
mXSLTProcessor = nullptr;
|
2002-04-25 15:58:08 +04:00
|
|
|
}
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
// release the nodes on stack
|
|
|
|
mContentStack.Clear();
|
|
|
|
mNotifyLevel = 0;
|
|
|
|
|
2013-12-13 05:50:01 +04:00
|
|
|
rv = HandleProcessingInstruction(MOZ_UTF16("xml-stylesheet"),
|
|
|
|
MOZ_UTF16("href=\"chrome://global/locale/intl.css\" type=\"text/css\""));
|
2009-02-27 21:37:51 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* noAtts[] = { 0, 0 };
|
2000-01-21 04:32:32 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(errorNs,
|
|
|
|
"http://www.mozilla.org/newlayout/xml/parsererror.xml");
|
|
|
|
|
|
|
|
nsAutoString parsererror(errorNs);
|
2014-01-04 19:02:17 +04:00
|
|
|
parsererror.Append((char16_t)0xFFFF);
|
2004-12-15 18:37:23 +03:00
|
|
|
parsererror.AppendLiteral("parsererror");
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2014-05-30 11:36:53 +04:00
|
|
|
rv = HandleStartElement(parsererror.get(), noAtts, 0, (uint32_t)-1,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2007-06-11 14:15:17 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-01-21 03:05:36 +03:00
|
|
|
|
2012-05-30 21:43:39 +04:00
|
|
|
rv = HandleCharacterData(aErrorText, NS_strlen(aErrorText), false);
|
2015-05-03 22:32:33 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
nsAutoString sourcetext(errorNs);
|
2014-01-04 19:02:17 +04:00
|
|
|
sourcetext.Append((char16_t)0xFFFF);
|
2004-12-15 18:37:23 +03:00
|
|
|
sourcetext.AppendLiteral("sourcetext");
|
|
|
|
|
2014-05-30 11:36:53 +04:00
|
|
|
rv = HandleStartElement(sourcetext.get(), noAtts, 0, (uint32_t)-1,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2007-06-11 14:15:17 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2012-05-30 21:43:39 +04:00
|
|
|
rv = HandleCharacterData(aSourceText, NS_strlen(aSourceText), false);
|
2007-06-11 14:15:17 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = HandleEndElement(sourcetext.get(), false);
|
2015-05-03 22:32:33 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = HandleEndElement(parsererror.get(), false);
|
2007-06-11 14:15:17 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
FlushTags();
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 03:43:30 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
nsXMLContentSink::AddAttributes(const char16_t** aAtts,
|
2002-12-03 02:24:57 +03:00
|
|
|
nsIContent* aContent)
|
1998-12-18 04:36:41 +03:00
|
|
|
{
|
2002-01-09 04:37:50 +03:00
|
|
|
// Add tag attributes to the content attributes
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
2002-01-09 04:37:50 +03:00
|
|
|
while (*aAtts) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nameSpaceID;
|
2004-12-15 18:37:23 +03:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
// Add attribute to content
|
2004-12-15 18:37:23 +03:00
|
|
|
aContent->SetAttr(nameSpaceID, localName, prefix,
|
2011-10-17 18:59:28 +04:00
|
|
|
nsDependentString(aAtts[1]), false);
|
2002-01-09 04:37:50 +03:00
|
|
|
aAtts += 2;
|
|
|
|
}
|
|
|
|
|
2001-05-17 09:54:16 +04:00
|
|
|
return NS_OK;
|
1998-12-18 04:36:41 +03:00
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
#define NS_ACCUMULATION_BUFFER_SIZE 4096
|
|
|
|
|
1998-11-13 02:55:47 +03:00
|
|
|
nsresult
|
2015-05-03 22:32:33 +03:00
|
|
|
nsXMLContentSink::AddText(const char16_t* aText,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aLength)
|
1998-11-13 02:55:47 +03:00
|
|
|
{
|
2002-01-09 04:37:50 +03:00
|
|
|
// Create buffer when we first need it
|
|
|
|
if (0 == mTextSize) {
|
2014-01-04 19:02:17 +04:00
|
|
|
mText = (char16_t *) PR_MALLOC(sizeof(char16_t) * NS_ACCUMULATION_BUFFER_SIZE);
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr == mText) {
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mTextSize = NS_ACCUMULATION_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
2015-09-22 23:13:16 +03:00
|
|
|
// Copy data from string into our buffer, resizing the buffer if
|
|
|
|
// it's not big enough.
|
|
|
|
int32_t availableSpace = mTextSize - mTextLength;
|
|
|
|
if (availableSpace < aLength) {
|
|
|
|
mTextSize = mTextLength + aLength;
|
|
|
|
mText = (char16_t *) PR_REALLOC(mText, sizeof(char16_t) * mTextSize);
|
|
|
|
if (nullptr == mText) {
|
|
|
|
mTextSize = 0;
|
2007-06-11 13:15:23 +04:00
|
|
|
|
2015-09-22 23:13:16 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-06-11 13:15:23 +04:00
|
|
|
}
|
1999-05-14 00:27:47 +04:00
|
|
|
}
|
2015-09-22 23:13:16 +03:00
|
|
|
memcpy(&mText[mTextLength], aText, sizeof(char16_t) * aLength);
|
|
|
|
mTextLength += aLength;
|
2002-01-09 04:37:50 +03:00
|
|
|
|
1999-05-14 00:27:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-01-31 00:21:06 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
nsXMLContentSink::FlushPendingNotifications(mozFlushType aType)
|
|
|
|
{
|
|
|
|
// Only flush tags if we're not doing the notification ourselves
|
|
|
|
// (since we aren't reentrant)
|
|
|
|
if (!mInNotification) {
|
2009-05-17 18:22:55 +04:00
|
|
|
if (mIsDocumentObserver) {
|
|
|
|
// Only flush if we're still a document observer (so that our child
|
|
|
|
// counts should be correct).
|
|
|
|
if (aType >= Flush_ContentAndNotify) {
|
|
|
|
FlushTags();
|
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
FlushText(false);
|
2009-05-17 18:22:55 +04:00
|
|
|
}
|
2007-01-31 00:21:06 +03:00
|
|
|
}
|
2009-04-22 03:53:52 +04:00
|
|
|
if (aType >= Flush_InterruptibleLayout) {
|
2007-01-31 00:21:06 +03:00
|
|
|
// Make sure that layout has started so that the reflow flush
|
|
|
|
// will actually happen.
|
2011-10-17 18:59:28 +04:00
|
|
|
MaybeStartLayout(true);
|
2007-01-31 00:21:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NOTE!! Forked from SinkContext. Please keep in sync.
|
|
|
|
*
|
|
|
|
* Flush all elements that have been seen so far such that
|
|
|
|
* they are visible in the tree. Specifically, make sure
|
|
|
|
* that they are all added to their respective parents.
|
|
|
|
* Also, do notification at the top for all content that
|
|
|
|
* has been newly added so that the frame tree is complete.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::FlushTags()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mDeferredFlushTags = false;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool oldBeganUpdate = mBeganUpdate;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t oldUpdates = mUpdatesInNotification;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2007-05-18 03:54:35 +04:00
|
|
|
mUpdatesInNotification = 0;
|
2007-01-31 00:21:06 +03:00
|
|
|
++mInNotification;
|
2007-04-07 04:20:09 +04:00
|
|
|
{
|
|
|
|
// Scope so we call EndUpdate before we decrease mInNotification
|
2011-10-17 18:59:28 +04:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_CONTENT_MODEL, true);
|
|
|
|
mBeganUpdate = true;
|
2007-04-07 04:20:09 +04:00
|
|
|
|
|
|
|
// Don't release last text node in case we need to add to it again
|
2011-10-17 18:59:28 +04:00
|
|
|
FlushText(false);
|
2007-04-07 04:20:09 +04:00
|
|
|
|
|
|
|
// Start from the base of the stack (growing downward) and do
|
|
|
|
// a notification from the node that is closest to the root of
|
|
|
|
// tree for any content that has been added.
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t stackPos;
|
|
|
|
int32_t stackLen = mContentStack.Length();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool flushed = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount;
|
2007-04-07 04:20:09 +04:00
|
|
|
nsIContent* content;
|
|
|
|
|
|
|
|
for (stackPos = 0; stackPos < stackLen; ++stackPos) {
|
|
|
|
content = mContentStack[stackPos].mContent;
|
|
|
|
childCount = content->GetChildCount();
|
|
|
|
|
|
|
|
if (!flushed && (mContentStack[stackPos].mNumFlushed < childCount)) {
|
|
|
|
NotifyAppend(content, mContentStack[stackPos].mNumFlushed);
|
2011-10-17 18:59:28 +04:00
|
|
|
flushed = true;
|
2007-04-07 04:20:09 +04:00
|
|
|
}
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2007-04-07 04:20:09 +04:00
|
|
|
mContentStack[stackPos].mNumFlushed = childCount;
|
2007-01-31 00:21:06 +03:00
|
|
|
}
|
2007-04-07 04:20:09 +04:00
|
|
|
mNotifyLevel = stackLen - 1;
|
2007-01-31 00:21:06 +03:00
|
|
|
}
|
|
|
|
--mInNotification;
|
|
|
|
|
2007-05-18 03:54:35 +04:00
|
|
|
if (mUpdatesInNotification > 1) {
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
mUpdatesInNotification = oldUpdates;
|
2007-03-10 02:43:50 +03:00
|
|
|
mBeganUpdate = oldBeganUpdate;
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NOTE!! Forked from SinkContext. Please keep in sync.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsXMLContentSink::UpdateChildCounts()
|
|
|
|
{
|
|
|
|
// Start from the top of the stack (growing upwards) and see if any
|
|
|
|
// new content has been appended. If so, we recognize that reflows
|
|
|
|
// have been generated for it and we should make sure that no
|
|
|
|
// further reflows occur. Note that we have to include stackPos == 0
|
|
|
|
// to properly notify on kids of <html>.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t stackLen = mContentStack.Length();
|
|
|
|
int32_t stackPos = stackLen - 1;
|
2007-01-31 00:21:06 +03:00
|
|
|
while (stackPos >= 0) {
|
|
|
|
StackNode & node = mContentStack[stackPos];
|
|
|
|
node.mNumFlushed = node.mContent->GetChildCount();
|
|
|
|
|
|
|
|
stackPos--;
|
|
|
|
}
|
|
|
|
mNotifyLevel = stackLen - 1;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-06-20 06:01:40 +04:00
|
|
|
nsXMLContentSink::IsMonolithicContainer(mozilla::dom::NodeInfo* aNodeInfo)
|
2007-01-31 00:21:06 +03:00
|
|
|
{
|
|
|
|
return ((aNodeInfo->NamespaceID() == kNameSpaceID_XHTML &&
|
|
|
|
(aNodeInfo->NameAtom() == nsGkAtoms::tr ||
|
|
|
|
aNodeInfo->NameAtom() == nsGkAtoms::select ||
|
|
|
|
aNodeInfo->NameAtom() == nsGkAtoms::object ||
|
2011-06-02 15:11:33 +04:00
|
|
|
aNodeInfo->NameAtom() == nsGkAtoms::applet)) ||
|
|
|
|
(aNodeInfo->NamespaceID() == kNameSpaceID_MathML &&
|
2007-01-31 00:21:06 +03:00
|
|
|
(aNodeInfo->NameAtom() == nsGkAtoms::math))
|
|
|
|
);
|
|
|
|
}
|
2012-01-20 15:16:27 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsXMLContentSink::ContinueInterruptedParsingIfEnabled()
|
|
|
|
{
|
|
|
|
if (mParser && mParser->IsParserEnabled()) {
|
2012-01-20 15:16:27 +04:00
|
|
|
GetParser()->ContinueInterruptedParsing();
|
2012-01-20 15:16:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXMLContentSink::ContinueInterruptedParsingAsync()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> ev = NS_NewRunnableMethod(this,
|
|
|
|
&nsXMLContentSink::ContinueInterruptedParsingIfEnabled);
|
|
|
|
|
|
|
|
NS_DispatchToCurrentThread(ev);
|
|
|
|
}
|
|
|
|
|
2012-01-20 15:16:27 +04:00
|
|
|
nsIParser*
|
|
|
|
nsXMLContentSink::GetParser()
|
|
|
|
{
|
|
|
|
return static_cast<nsIParser*>(mParser.get());
|
|
|
|
}
|