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"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.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"
|
(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"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheetInlines.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"
|
2018-04-20 23:55:51 +03:00
|
|
|
#include "nsDocElementCreatedNotificationRunner.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"
|
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"
|
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-07-02 11:23:10 +04:00
|
|
|
#include "nsNodeUtils.h"
|
2007-01-31 00:21:06 +03:00
|
|
|
#include "nsIScriptGlobalObject.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"
|
2018-03-13 23:24:01 +03:00
|
|
|
#include "mozilla/dom/DocumentType.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"
|
2017-05-08 09:24:22 +03:00
|
|
|
#include "mozilla/dom/ScriptLoader.h"
|
2018-02-06 00:00:04 +03:00
|
|
|
#include "mozilla/dom/txMozillaXSLTProcessor.h"
|
2018-03-29 13:16:23 +03:00
|
|
|
#include "mozilla/LoadInfo.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?
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult NS_NewXMLContentSink(nsIXMLContentSink** aResult, Document* aDoc,
|
2003-04-03 22:57:33 +04:00
|
|
|
nsIURI* aURI, nsISupports* aContainer,
|
2002-03-27 09:19:14 +03:00
|
|
|
nsIChannel* aChannel) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(nullptr != aResult, "null ptr");
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr == aResult) {
|
1998-11-12 01:06:16 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<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()
|
2018-06-15 16:51:24 +03:00
|
|
|
: mState(eXMLContentSinkState_InProlog),
|
|
|
|
mTextLength(0),
|
2016-10-25 09:18:03 +03:00
|
|
|
mNotifyLevel(0),
|
|
|
|
mPrettyPrintXML(true),
|
|
|
|
mPrettyPrintHasSpecialRoot(0),
|
|
|
|
mPrettyPrintHasFactoredElements(0),
|
|
|
|
mPrettyPrinting(0),
|
|
|
|
mPreventScriptExecution(0) {
|
|
|
|
PodArrayZero(mText);
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXMLContentSink::~nsXMLContentSink() {}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult nsXMLContentSink::Init(Document* aDoc, nsIURI* aURI,
|
2003-04-03 22:57:33 +04:00
|
|
|
nsISupports* aContainer, nsIChannel* aChannel) {
|
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
|
|
|
}
|
|
|
|
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXMLContentSink)
|
2008-02-09 01:07:51 +03:00
|
|
|
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);
|
|
|
|
}
|
2017-11-03 18:58:59 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentChildren)
|
2008-02-09 01:07:51 +03:00
|
|
|
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) { 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) {
|
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
|
|
|
}
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
bool nsXMLContentSink::CanStillPrettyPrint() {
|
|
|
|
return mPrettyPrintXML &&
|
|
|
|
(!mPrettyPrintHasFactoredElements || mPrettyPrintHasSpecialRoot);
|
|
|
|
}
|
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
nsresult nsXMLContentSink::MaybePrettyPrint() {
|
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
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<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
|
|
|
}
|
|
|
|
|
2018-03-19 22:15:40 +03:00
|
|
|
static void CheckXSLTParamPI(ProcessingInstruction* aPi,
|
2006-05-19 14:29:43 +04:00
|
|
|
nsIDocumentTransformer* aProcessor,
|
2018-02-20 22:55:23 +03:00
|
|
|
nsINode* aSource) {
|
2006-05-19 14:29:43 +04:00
|
|
|
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);
|
|
|
|
if (!prefix.IsEmpty() && 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()) {
|
2018-02-20 22:55:23 +03:00
|
|
|
aProcessor->AddXSLTParam(name, namespaceAttr, select, value, aSource);
|
2006-05-19 14:29:43 +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
|
2011-09-29 10:19:26 +04:00
|
|
|
nsXMLContentSink::DidBuildModel(bool aTerminated) {
|
2012-07-27 17:35:09 +04:00
|
|
|
if (!mParser) {
|
|
|
|
// If mParser is null, this parse has already been terminated and must
|
2019-01-02 16:05:23 +03:00
|
|
|
// not been terminated again. However, Document may still think that
|
2012-07-27 17:35:09 +04:00
|
|
|
// 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
|
|
|
|
2018-02-20 22:55:23 +03:00
|
|
|
ErrorResult rv;
|
|
|
|
RefPtr<DocumentFragment> source = mDocument->CreateDocumentFragment();
|
|
|
|
for (nsIContent* child : mDocumentChildren) {
|
|
|
|
// XPath data model doesn't have DocumentType nodes.
|
|
|
|
if (child->NodeType() != nsINode::DOCUMENT_TYPE_NODE) {
|
|
|
|
source->AppendChild(*child, rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return rv.StealNSResult();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-20 22:55:23 +03:00
|
|
|
}
|
|
|
|
|
2006-05-19 14:29:43 +04:00
|
|
|
// Check for xslt-param and xslt-param-namespace PIs
|
2018-02-20 22:55:23 +03:00
|
|
|
for (nsIContent* child : mDocumentChildren) {
|
2018-03-22 00:39:04 +03:00
|
|
|
if (auto pi = ProcessingInstruction::FromNode(child)) {
|
2018-02-20 22:55:23 +03:00
|
|
|
CheckXSLTParamPI(pi, mXSLTProcessor, source);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-20 22:55:23 +03:00
|
|
|
mXSLTProcessor->SetSourceContentModel(source);
|
2003-03-26 04:10:14 +03:00
|
|
|
// 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;
|
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
|
2018-10-14 19:12:23 +03:00
|
|
|
if (mDocument->CSSLoader()->HasPendingLoads()) {
|
|
|
|
mDocument->CSSLoader()->AddObserver(this);
|
2007-05-31 05:42:48 +04:00
|
|
|
// 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
|
|
|
|
2018-02-05 19:08:09 +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
|
2019-01-02 16:05:23 +03:00
|
|
|
nsXMLContentSink::OnDocumentCreated(Document* 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);
|
|
|
|
|
2019-05-28 02:03:03 +03:00
|
|
|
aResultDocument->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
|
2019-01-02 16:05:23 +03:00
|
|
|
nsXMLContentSink::OnTransformDone(nsresult aResult, Document* aResultDocument) {
|
2017-11-03 18:58:59 +03:00
|
|
|
MOZ_ASSERT(aResultDocument,
|
|
|
|
"Don't notify about transform end without a document.");
|
|
|
|
|
|
|
|
mDocumentChildren.Clear();
|
2000-09-17 00:53:08 +04:00
|
|
|
|
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.
|
2017-11-03 18:58:59 +03:00
|
|
|
aResultDocument->SetMayStartLayout(false);
|
|
|
|
// We have an error document.
|
2018-01-31 23:18:09 +03:00
|
|
|
contentViewer->SetDocument(aResultDocument);
|
2002-06-20 16:04:22 +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
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> originalDocument = mDocument;
|
2018-02-05 19:08:09 +03:00
|
|
|
bool blockingOnload = mIsBlockingOnload;
|
|
|
|
if (!mRunsToCompletion) {
|
|
|
|
// This BlockOnload call corresponds to the UnblockOnload call in
|
|
|
|
// nsContentSink::DropParserAndPerfHint.
|
|
|
|
aResultDocument->BlockOnload();
|
|
|
|
mIsBlockingOnload = true;
|
|
|
|
}
|
2017-11-03 18:58:59 +03:00
|
|
|
// Transform succeeded, or it failed and we have an error document to display.
|
|
|
|
mDocument = aResultDocument;
|
2019-05-28 02:03:03 +03:00
|
|
|
aResultDocument->SetDocWriteDisabled(false);
|
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) {
|
2018-01-23 16:30:18 +03:00
|
|
|
NS_ASSERTION(mDocument->ComputeIndexOf(rootElement) != -1,
|
2010-04-30 17:12:05 +04:00
|
|
|
"rootElement not in doc?");
|
2018-05-15 16:56:38 +03:00
|
|
|
mDocument->BeginUpdate();
|
2017-07-27 16:49:52 +03:00
|
|
|
nsNodeUtils::ContentInserted(mDocument, rootElement);
|
2018-05-15 16:56:38 +03:00
|
|
|
mDocument->EndUpdate();
|
2003-10-11 04:27:45 +04:00
|
|
|
}
|
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();
|
2018-02-05 19:08:09 +03:00
|
|
|
if (blockingOnload) {
|
|
|
|
// This UnblockOnload call corresponds to the BlockOnload call in
|
|
|
|
// nsContentSink::WillBuildModelImpl.
|
|
|
|
originalDocument->UnblockOnload(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
DropParserAndPerfHint();
|
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
|
2016-09-26 15:03:25 +03:00
|
|
|
nsXMLContentSink::StyleSheetLoaded(StyleSheet* aSheet, bool aWasDeferred,
|
2007-05-31 05:42:48 +04:00
|
|
|
nsresult aStatus) {
|
|
|
|
if (!mPrettyPrinting) {
|
2018-04-24 20:17:33 +03:00
|
|
|
return nsContentSink::StyleSheetLoaded(aSheet, aWasDeferred, aStatus);
|
2007-05-31 05:42:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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) { return WillInterruptImpl(); }
|
|
|
|
|
(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) { return WillResumeImpl(); }
|
|
|
|
|
1998-12-11 20:02:37 +03:00
|
|
|
NS_IMETHODIMP
|
2012-01-20 15:16:27 +04:00
|
|
|
nsXMLContentSink::SetParser(nsParserBase* aParser) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aParser, "Should have a parser here!");
|
1998-12-11 20:02:37 +03:00
|
|
|
mParser = aParser;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-20 05:23:46 +03:00
|
|
|
static bool FindIsAttrValue(const char16_t** aAtts, const char16_t** aResult) {
|
|
|
|
RefPtr<nsAtom> prefix, localName;
|
|
|
|
for (; *aAtts; aAtts += 2) {
|
|
|
|
int32_t nameSpaceID;
|
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
|
|
|
if (nameSpaceID == kNameSpaceID_None && localName == nsGkAtoms::is) {
|
|
|
|
*aResult = aAtts[1];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult nsXMLContentSink::CreateElement(
|
|
|
|
const char16_t** aAtts, uint32_t aAttsCount,
|
2018-07-05 09:21:04 +03:00
|
|
|
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
|
2011-09-29 10:19:26 +04:00
|
|
|
uint32_t aColumnNumber, nsIContent** aResult, bool* aAppendContent,
|
2010-10-25 16:17:38 +04:00
|
|
|
FromParser aFromParser) {
|
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
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
|
|
|
|
RefPtr<Element> content;
|
2018-05-20 05:23:46 +03:00
|
|
|
|
|
|
|
const char16_t* is = nullptr;
|
|
|
|
if ((aNodeInfo->NamespaceEquals(kNameSpaceID_XHTML) ||
|
|
|
|
aNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) &&
|
|
|
|
FindIsAttrValue(aAtts, &is)) {
|
|
|
|
const nsDependentString isStr(is);
|
|
|
|
rv = NS_NewElement(getter_AddRefs(content), ni.forget(), aFromParser,
|
|
|
|
&isStr);
|
|
|
|
} else {
|
|
|
|
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)) {
|
2006-11-04 08:45:02 +03:00
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(content);
|
2017-01-11 19:29:13 +03:00
|
|
|
if (sele) {
|
|
|
|
sele->SetScriptLineNumber(aLineNumber);
|
2018-07-05 09:21:04 +03:00
|
|
|
sele->SetScriptColumnNumber(aColumnNumber);
|
2017-01-11 19:29:13 +03:00
|
|
|
sele->SetCreatorParser(GetParser());
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled,
|
|
|
|
"Node didn't QI to script, but SVG wasn't disabled.");
|
|
|
|
}
|
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()->HasElementCreator(
|
2004-06-25 16:26:02 +04:00
|
|
|
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);
|
2018-07-05 09:21:04 +03:00
|
|
|
ssle->SetColumnNumber(aFromParser ? aColumnNumber : 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;
|
|
|
|
}
|
|
|
|
|
2006-11-04 08:45:02 +03:00
|
|
|
nsresult 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).
|
2019-09-06 23:27:09 +03:00
|
|
|
if (nsIContent::RequiresDoneAddingChildren(nodeInfo->NamespaceID(),
|
|
|
|
nodeInfo->NameAtom())) {
|
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)) {
|
2011-11-16 11:50:18 +04:00
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(aContent);
|
2017-01-11 19:29:13 +03:00
|
|
|
if (!sele) {
|
|
|
|
MOZ_ASSERT(nsNameSpaceManager::GetInstance()->mSVGDisabled,
|
|
|
|
"Node didn't QI to script, but SVG wasn't disabled.");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
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()) {
|
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);
|
2018-04-24 13:50:35 +03:00
|
|
|
auto updateOrError =
|
|
|
|
ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this);
|
|
|
|
if (updateOrError.isErr()) {
|
|
|
|
rv = updateOrError.unwrapErr();
|
|
|
|
} else if (updateOrError.unwrap().ShouldBlock() && !mRunsToCompletion) {
|
2007-04-21 02:59:18 +04:00
|
|
|
++mPendingSheetCount;
|
2016-05-21 06:13:18 +03:00
|
|
|
mScriptLoader->AddParserBlockingScriptExecutionBlocker();
|
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;
|
|
|
|
|
2017-11-03 18:58:59 +03:00
|
|
|
if (mState == eXMLContentSinkState_InProlog) {
|
|
|
|
NS_ASSERTION(mDocument, "Fragments have no prolog");
|
|
|
|
mDocumentChildren.AppendElement(aContent);
|
|
|
|
} else if (mState == eXMLContentSinkState_InEpilog) {
|
|
|
|
NS_ASSERTION(mDocument, "Fragments have no epilog");
|
|
|
|
if (mXSLTProcessor) {
|
|
|
|
mDocumentChildren.AppendElement(aContent);
|
|
|
|
} else {
|
|
|
|
mDocument->AppendChildTo(aContent, false);
|
|
|
|
}
|
|
|
|
} 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) {
|
2018-02-06 00:00:04 +03:00
|
|
|
nsCOMPtr<nsIDocumentTransformer> processor = new txMozillaXSLTProcessor();
|
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
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
nsresult nsXMLContentSink::ProcessStyleLinkFromHeader(
|
|
|
|
const nsAString& aHref, bool aAlternate, const nsAString& aTitle,
|
|
|
|
const nsAString& aType, const nsAString& aMedia,
|
|
|
|
const nsAString& aReferrerPolicy) {
|
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;
|
2012-01-20 15:16:27 +04:00
|
|
|
if (mParser) 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
|
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
bool wasXSLT;
|
2017-12-22 00:43:24 +03:00
|
|
|
nsresult rv = MaybeProcessXSLTLink(nullptr, aHref, aAlternate, aType, aType,
|
2017-12-22 00:43:24 +03:00
|
|
|
aMedia, aReferrerPolicy, &wasXSLT);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (wasXSLT) {
|
|
|
|
// We're done here.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-05-19 06:59:15 +04:00
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
// Otherwise fall through to nsContentSink to handle CSS Link headers.
|
2017-12-22 00:43:24 +03:00
|
|
|
return nsContentSink::ProcessStyleLinkFromHeader(
|
|
|
|
aHref, aAlternate, aTitle, aType, aMedia, aReferrerPolicy);
|
2017-12-22 00:43:24 +03:00
|
|
|
}
|
2004-10-24 21:25:58 +04:00
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
nsresult nsXMLContentSink::MaybeProcessXSLTLink(
|
|
|
|
ProcessingInstruction* aProcessingInstruction, const nsAString& aHref,
|
|
|
|
bool aAlternate, const nsAString& aTitle, const nsAString& aType,
|
|
|
|
const nsAString& aMedia, const nsAString& aReferrerPolicy, bool* aWasXSLT) {
|
2017-12-22 00:43:24 +03:00
|
|
|
bool wasXSLT = aType.LowerCaseEqualsLiteral(TEXT_XSL) ||
|
|
|
|
aType.LowerCaseEqualsLiteral(APPLICATION_XSLT_XML) ||
|
|
|
|
aType.LowerCaseEqualsLiteral(TEXT_XML) ||
|
|
|
|
aType.LowerCaseEqualsLiteral(APPLICATION_XML);
|
|
|
|
|
|
|
|
if (aWasXSLT) {
|
|
|
|
*aWasXSLT = wasXSLT;
|
|
|
|
}
|
2004-10-24 21:25:58 +04:00
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
if (!wasXSLT) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-10-24 21:25:58 +04:00
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
if (aAlternate) {
|
|
|
|
// don't load alternate XSLT
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// LoadXSLStyleSheet needs a mDocShell.
|
|
|
|
if (!mDocShell) {
|
|
|
|
return NS_OK;
|
2002-12-03 12:20:43 +03:00
|
|
|
}
|
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
nsCOMPtr<nsIURI> url;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(url), aHref, nullptr,
|
|
|
|
mDocument->GetDocBaseURI());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-10-05 11:29:50 +04:00
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
// Do security check
|
|
|
|
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
|
|
|
|
rv = secMan->CheckLoadURIWithPrincipal(
|
|
|
|
mDocument->NodePrincipal(), url, nsIScriptSecurityManager::ALLOW_CHROME);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
|
|
|
|
2018-03-29 13:16:23 +03:00
|
|
|
nsCOMPtr<nsILoadInfo> secCheckLoadInfo =
|
|
|
|
new net::LoadInfo(mDocument->NodePrincipal(), // loading principal
|
|
|
|
mDocument->NodePrincipal(), // triggering principal
|
|
|
|
aProcessingInstruction,
|
|
|
|
nsILoadInfo::SEC_ONLY_FOR_EXPLICIT_CONTENTSEC_CHECK,
|
|
|
|
nsIContentPolicy::TYPE_XSLT);
|
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
// Do content policy check
|
|
|
|
int16_t decision = nsIContentPolicy::ACCEPT;
|
2018-03-29 13:16:23 +03:00
|
|
|
rv = NS_CheckContentLoadPolicy(url, secCheckLoadInfo,
|
2017-12-22 00:43:24 +03:00
|
|
|
NS_ConvertUTF16toUTF8(aType), &decision,
|
|
|
|
nsContentUtils::GetContentPolicy());
|
2015-05-03 22:32:33 +03:00
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (NS_CP_REJECTED(decision)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LoadXSLStyleSheet(url);
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
2017-06-18 14:37:50 +03:00
|
|
|
void nsXMLContentSink::SetDocumentCharset(NotNull<const Encoding*> aEncoding) {
|
2002-01-09 04:37:50 +03:00
|
|
|
if (mDocument) {
|
2017-06-18 14:37:50 +03:00
|
|
|
mDocument->SetDocumentCharacterSet(aEncoding);
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
1998-11-16 09:16:17 +03:00
|
|
|
|
2018-12-26 05:32:55 +03:00
|
|
|
nsISupports* nsXMLContentSink::GetTarget() { return ToSupports(mDocument); }
|
2004-11-02 22:52:32 +03:00
|
|
|
|
2009-04-16 02:34:50 +04:00
|
|
|
bool nsXMLContentSink::IsScriptExecuting() { return IsScriptExecutingImpl(); }
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult nsXMLContentSink::FlushText(bool aReleaseTextNode) {
|
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-10-12 20:07:51 +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;
|
2015-09-25 22:46:13 +03:00
|
|
|
}
|
2015-10-12 20:07:51 +03:00
|
|
|
|
|
|
|
mTextLength = 0;
|
2008-10-16 01:29:35 +04:00
|
|
|
} else {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<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() {
|
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
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
StackNode* 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
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
nsresult nsXMLContentSink::PushContent(nsIContent* aContent) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(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
|
|
|
}
|
|
|
|
|
|
|
|
void nsXMLContentSink::PopContent() {
|
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
|
|
|
|
2008-04-18 02:30:51 +04:00
|
|
|
bool 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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void nsXMLContentSink::MaybeStartLayout(bool aIgnorePendingSheets) {
|
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
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
bool nsXMLContentSink::SetDocElement(int32_t aNameSpaceID, nsAtom* aTagName,
|
2004-10-01 02:27:45 +04:00
|
|
|
nsIContent* aContent) {
|
|
|
|
if (mDocElement) return false;
|
|
|
|
|
2017-11-03 18:58:59 +03:00
|
|
|
mDocElement = aContent;
|
|
|
|
|
|
|
|
if (mXSLTProcessor) {
|
|
|
|
mDocumentChildren.AppendElement(aContent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDocumentChildren.IsEmpty()) {
|
|
|
|
for (nsIContent* child : mDocumentChildren) {
|
|
|
|
mDocument->AppendChildTo(child, false);
|
|
|
|
}
|
|
|
|
mDocumentChildren.Clear();
|
|
|
|
}
|
|
|
|
|
2004-10-01 02:27:45 +04:00
|
|
|
// check for root elements that needs special handling for
|
|
|
|
// prettyprinting
|
|
|
|
if ((aNameSpaceID == kNameSpaceID_XBL && aTagName == nsGkAtoms::bindings) ||
|
|
|
|
(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
|
|
|
}
|
|
|
|
|
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,
|
2018-07-05 09:21:04 +03:00
|
|
|
uint32_t aAttsCount, uint32_t aLineNumber,
|
|
|
|
uint32_t aColumnNumber) {
|
2014-05-30 11:36:53 +04:00
|
|
|
return HandleStartElement(aName, aAtts, aAttsCount, aLineNumber,
|
2018-07-05 09:21:04 +03:00
|
|
|
aColumnNumber, true);
|
2007-06-11 14:15:17 +04:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult nsXMLContentSink::HandleStartElement(
|
|
|
|
const char16_t* aName, const char16_t** aAtts, uint32_t aAttsCount,
|
2018-07-05 09:21:04 +03:00
|
|
|
uint32_t aLineNumber, uint32_t aColumnNumber, bool aInterruptable) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aAttsCount % 2 == 0, "incorrect aAttsCount");
|
2003-10-30 05:17:50 +03:00
|
|
|
// 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
|
2016-06-28 20:47:22 +03:00
|
|
|
MOZ_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;
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> prefix, localName;
|
2004-12-15 18:37:23 +03:00
|
|
|
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
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2011-06-14 11:56:49 +04:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID,
|
2018-01-30 07:10:53 +03:00
|
|
|
nsINode::ELEMENT_NODE);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2002-12-03 02:24:57 +03:00
|
|
|
result = CreateElement(aAtts, aAttsCount, nodeInfo, aLineNumber,
|
2018-07-05 09:21:04 +03:00
|
|
|
aColumnNumber, getter_AddRefs(content), &appendContent,
|
2010-10-25 16:17:38 +04:00
|
|
|
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
|
2017-12-05 20:05:51 +03:00
|
|
|
result = AddAttributes(aAtts, content->AsElement());
|
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).
|
2019-09-06 23:27:09 +03:00
|
|
|
if (nsIContent::RequiresDoneCreatingElement(nodeInfo->NamespaceID(),
|
|
|
|
nodeInfo->NameAtom())) {
|
|
|
|
content->DoneCreatingElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nodeInfo->NamespaceID() == kNameSpaceID_XHTML &&
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
|
2017-11-03 18:58:59 +03:00
|
|
|
if (!mXSLTProcessor) {
|
|
|
|
if (content == mDocElement) {
|
2018-04-20 23:55:51 +03:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new nsDocElementCreatedNotificationRunner(mDocument));
|
2017-11-28 23:55:36 +03:00
|
|
|
|
2017-11-03 18:58:59 +03:00
|
|
|
if (aInterruptable && NS_SUCCEEDED(result) && mParser &&
|
|
|
|
!mParser->IsParserEnabled()) {
|
|
|
|
return NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
|
|
|
} else if (!mCurrentHead) {
|
|
|
|
// This isn't the root and we're not inside an XHTML <head>.
|
|
|
|
// Might need to start layout
|
|
|
|
MaybeStartLayout(false);
|
2017-03-16 00:04:37 +03:00
|
|
|
}
|
2010-08-28 09:54:57 +04:00
|
|
|
}
|
|
|
|
|
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) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return HandleEndElement(aName, true);
|
2007-06-11 14:15:17 +04:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult 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.
|
2016-06-28 20:47:22 +03:00
|
|
|
MOZ_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
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> 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) ||
|
2016-06-28 17:24:48 +03:00
|
|
|
(debugNameSpaceID == kNameSpaceID_MathML &&
|
|
|
|
content->NodeInfo()->NamespaceID() == kNameSpaceID_disabled_MathML &&
|
|
|
|
content->NodeInfo()->Equals(debugTagAtom)) ||
|
2016-12-01 10:41:22 +03:00
|
|
|
(debugNameSpaceID == kNameSpaceID_SVG &&
|
|
|
|
content->NodeInfo()->NamespaceID() == kNameSpaceID_disabled_SVG &&
|
|
|
|
content->NodeInfo()->Equals(debugTagAtom)) ||
|
2014-06-05 02:21:23 +04:00
|
|
|
isTemplateElement,
|
|
|
|
"Wrong element being closed");
|
2015-05-03 22:32:33 +03:00
|
|
|
#endif
|
2001-07-04 23:35:23 +04:00
|
|
|
|
2017-10-09 21:49:19 +03:00
|
|
|
// Make sure to notify on our kids before we call out to any other code that
|
|
|
|
// might reenter us and call FlushTags, in a state in which we've already
|
|
|
|
// popped "content" from the stack but haven't notified on its kids yet.
|
|
|
|
int32_t stackLen = mContentStack.Length();
|
|
|
|
if (mNotifyLevel >= stackLen) {
|
|
|
|
if (numFlushed < content->GetChildCount()) {
|
|
|
|
NotifyAppend(content, numFlushed);
|
|
|
|
}
|
|
|
|
mNotifyLevel = stackLen - 1;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-01-26 02:14:03 +03:00
|
|
|
mDocument->TriggerInitialDocumentTranslation();
|
|
|
|
|
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
|
|
|
|
2007-02-28 20:28:17 +03:00
|
|
|
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);
|
2017-07-26 11:13:35 +03:00
|
|
|
if (NS_FAILED(content->OwnerDoc()->Dispatch(TaskCategory::Other,
|
2017-01-30 22:57:49 +03:00
|
|
|
event.forget()))) {
|
2010-07-19 02:07:54 +04:00
|
|
|
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
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Comment> comment = new Comment(mNodeInfoManager);
|
2013-04-04 16:02:22 +04:00
|
|
|
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, uint32_t aLength) {
|
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
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CDATASection> cdata = new CDATASection(mNodeInfoManager);
|
2013-04-04 16:01:11 +04:00
|
|
|
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) {
|
2002-08-13 22:41:16 +04:00
|
|
|
FlushText();
|
|
|
|
|
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
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> name = NS_Atomize(aName);
|
2003-11-19 04:20:56 +03:00
|
|
|
NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2000-06-17 05:49:19 +04:00
|
|
|
// Create a new doctype node
|
2018-03-13 23:24:01 +03:00
|
|
|
RefPtr<DocumentType> docType = NS_NewDOMDocumentType(
|
|
|
|
mNodeInfoManager, name, aPublicId, aSystemId, aSubset);
|
2000-06-17 05:49:19 +04:00
|
|
|
|
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
|
|
|
|
2018-03-13 23:24:01 +03:00
|
|
|
mDocumentChildren.AppendElement(docType);
|
2007-01-31 00:21:06 +03:00
|
|
|
DidAddContent();
|
2017-11-03 18:58:59 +03:00
|
|
|
return DidProcessATokenImpl();
|
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, uint32_t aLength) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return HandleCharacterData(aData, aLength, true);
|
2007-06-11 14:15:17 +04:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult nsXMLContentSink::HandleCharacterData(const char16_t* aData,
|
|
|
|
uint32_t aLength,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aInterruptable) {
|
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) {
|
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);
|
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
RefPtr<ProcessingInstruction> node =
|
2013-04-04 16:01:11 +04:00
|
|
|
NS_NewXMLProcessingInstruction(mNodeInfoManager, target, data);
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle =
|
|
|
|
do_QueryInterface(ToSupports(node));
|
2006-03-17 17:38:57 +03:00
|
|
|
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);
|
2018-04-24 13:50:35 +03:00
|
|
|
auto updateOrError =
|
|
|
|
ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this);
|
|
|
|
if (updateOrError.isErr()) {
|
|
|
|
return updateOrError.unwrapErr();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto update = updateOrError.unwrap();
|
|
|
|
if (update.WillNotify()) {
|
2007-04-21 02:59:18 +04:00
|
|
|
// Successfully started a stylesheet load
|
2018-04-24 13:50:35 +03:00
|
|
|
if (update.ShouldBlock() && !mRunsToCompletion) {
|
2007-04-21 02:59:18 +04:00
|
|
|
++mPendingSheetCount;
|
2016-05-21 06:13:18 +03:00
|
|
|
mScriptLoader->AddParserBlockingScriptExecutionBlocker();
|
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
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
// Check whether this is a CSS stylesheet PI. Make sure the type
|
|
|
|
// handling here matches
|
|
|
|
// XMLStylesheetProcessingInstruction::GetStyleSheetInfo.
|
2006-03-17 17:38:57 +03:00
|
|
|
nsAutoString type;
|
2012-02-27 15:57:48 +04:00
|
|
|
nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::type, type);
|
2017-12-22 00:43:24 +03:00
|
|
|
nsAutoString mimeType, notUsed;
|
|
|
|
nsContentUtils::SplitMimeType(type, mimeType, notUsed);
|
2006-03-17 17:38:57 +03:00
|
|
|
|
|
|
|
if (mState != eXMLContentSinkState_InProlog ||
|
|
|
|
!target.EqualsLiteral("xml-stylesheet") || mimeType.IsEmpty() ||
|
2017-12-22 00:43:24 +03:00
|
|
|
mimeType.LowerCaseEqualsLiteral("text/css")) {
|
|
|
|
// Either not a useful stylesheet PI, or a CSS stylesheet PI that
|
|
|
|
// got handled above by the "ssle" bits. We're done here.
|
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
|
|
|
|
2017-12-22 00:43:24 +03:00
|
|
|
// If it's not a CSS stylesheet PI...
|
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
|
|
|
|
2017-08-15 07:05:00 +03:00
|
|
|
// <?xml-stylesheet?> processing instructions don't have a referrerpolicy
|
|
|
|
// pseudo-attribute, so we pass in an empty string
|
2017-12-22 00:43:24 +03:00
|
|
|
rv = MaybeProcessXSLTLink(node, href, isAlternate, title, type, media,
|
|
|
|
EmptyString());
|
2007-01-31 00:21:06 +03:00
|
|
|
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 */
|
|
|
|
bool 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) {
|
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, bool* _retval) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(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
|
|
|
|
2016-08-29 23:30:36 +03:00
|
|
|
// Clear the current content
|
2017-11-03 18:58:59 +03:00
|
|
|
mDocumentChildren.Clear();
|
2018-01-30 07:10:50 +03:00
|
|
|
while (mDocument->GetLastChild()) {
|
|
|
|
mDocument->GetLastChild()->Remove();
|
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;
|
|
|
|
|
2016-08-29 23:30:36 +03:00
|
|
|
// return leaving the document empty if we're asked to not add a <parsererror>
|
|
|
|
// root node
|
|
|
|
if (mDocument->SuppressParserErrorElement()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare to set <parsererror> as the document root
|
2016-07-21 08:03:25 +03:00
|
|
|
rv = HandleProcessingInstruction(
|
|
|
|
u"xml-stylesheet",
|
|
|
|
u"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, 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, 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
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult nsXMLContentSink::AddAttributes(const char16_t** aAtts,
|
2017-12-05 20:05:51 +03:00
|
|
|
Element* aContent) {
|
2002-01-09 04:37:50 +03:00
|
|
|
// Add tag attributes to the content attributes
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> 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
|
|
|
|
|
2015-05-03 22:32:33 +03:00
|
|
|
nsresult nsXMLContentSink::AddText(const char16_t* aText, int32_t aLength) {
|
2015-10-12 20:07:51 +03:00
|
|
|
// Copy data from string into our buffer; flush buffer when it fills up.
|
2015-09-25 22:46:13 +03:00
|
|
|
int32_t offset = 0;
|
|
|
|
while (0 != aLength) {
|
2015-10-12 20:07:51 +03:00
|
|
|
int32_t amount = NS_ACCUMULATION_BUFFER_SIZE - mTextLength;
|
2015-09-25 22:46:13 +03:00
|
|
|
if (0 == amount) {
|
2015-10-12 20:07:51 +03:00
|
|
|
nsresult rv = FlushText(false);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2015-09-25 22:46:13 +03:00
|
|
|
}
|
2015-10-12 20:07:51 +03:00
|
|
|
MOZ_ASSERT(mTextLength == 0);
|
|
|
|
amount = NS_ACCUMULATION_BUFFER_SIZE;
|
2015-09-25 22:46:13 +03:00
|
|
|
}
|
2015-10-12 20:07:51 +03:00
|
|
|
|
2015-09-25 22:46:13 +03:00
|
|
|
if (amount > aLength) {
|
|
|
|
amount = aLength;
|
2007-06-11 13:15:23 +04:00
|
|
|
}
|
2015-09-25 22:46:13 +03:00
|
|
|
memcpy(&mText[mTextLength], &aText[offset], sizeof(char16_t) * amount);
|
|
|
|
mTextLength += amount;
|
|
|
|
offset += amount;
|
|
|
|
aLength -= amount;
|
1999-05-14 00:27:47 +04:00
|
|
|
}
|
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
|
|
|
|
2019-01-26 02:14:03 +03:00
|
|
|
void nsXMLContentSink::InitialDocumentTranslationCompleted() {
|
|
|
|
StartLayout(false);
|
|
|
|
}
|
|
|
|
|
2017-01-05 10:31:56 +03:00
|
|
|
void nsXMLContentSink::FlushPendingNotifications(FlushType aType) {
|
2007-01-31 00:21:06 +03:00
|
|
|
// 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).
|
2017-01-05 10:31:56 +03:00
|
|
|
if (aType >= FlushType::ContentAndNotify) {
|
2009-05-17 18:22:55 +04:00
|
|
|
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
|
|
|
}
|
2017-07-04 06:36:24 +03:00
|
|
|
if (aType >= FlushType::EnsurePresShellInitAndFrames) {
|
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;
|
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
|
2018-05-15 16:56:38 +03:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, 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-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;
|
|
|
|
}
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
bool 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 ||
|
2017-07-29 02:44:39 +03:00
|
|
|
aNodeInfo->NameAtom() == nsGkAtoms::object)) ||
|
2011-06-02 15:11:33 +04:00
|
|
|
(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() {
|
2017-06-12 22:34:10 +03:00
|
|
|
nsCOMPtr<nsIRunnable> ev = NewRunnableMethod(
|
|
|
|
"nsXMLContentSink::ContinueInterruptedParsingIfEnabled", this,
|
|
|
|
&nsXMLContentSink::ContinueInterruptedParsingIfEnabled);
|
2012-01-20 15:16:27 +04:00
|
|
|
|
2018-02-20 17:52:32 +03:00
|
|
|
mDocument->Dispatch(mozilla::TaskCategory::Other, ev.forget());
|
2012-01-20 15:16:27 +04:00
|
|
|
}
|
|
|
|
|
2012-01-20 15:16:27 +04:00
|
|
|
nsIParser* nsXMLContentSink::GetParser() {
|
|
|
|
return static_cast<nsIParser*>(mParser.get());
|
|
|
|
}
|