2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2008-04-17 22:30:51 +00:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2001-09-25 01:32:19 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-11-11 22:06:16 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-11-11 22:06:16 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-11-11 22:06:16 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
2000-02-02 22:24:56 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2007-01-30 21:21:06 +00:00
|
|
|
* Henri Sivonen <hsivonen@iki.fi>
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2011-05-28 07:43:53 +00:00
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsXMLContentSink.h"
|
1998-12-11 17:02:37 +00:00
|
|
|
#include "nsIParser.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIDocument.h"
|
2000-06-17 01:49:19 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMDocumentType.h"
|
|
|
|
#include "nsIDOMDOMImplementation.h"
|
2007-02-09 00:15:14 +00:00
|
|
|
#include "nsIContent.h"
|
2004-01-09 23:54:21 +00:00
|
|
|
#include "nsIURI.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.h"
|
2003-10-05 07:29:50 +00:00
|
|
|
#include "nsIDocShell.h"
|
1999-12-18 02:09:29 +00:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2001-05-19 02:59:15 +00:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIDOMComment.h"
|
1999-03-31 20:49:25 +00:00
|
|
|
#include "nsIDOMCDATASection.h"
|
2000-06-17 01:49:19 +00:00
|
|
|
#include "nsDOMDocumentType.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 00:43:30 +00:00
|
|
|
#include "nsHTMLParts.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsCRT.h"
|
2010-05-11 20:41:47 +00:00
|
|
|
#include "nsCSSStyleSheet.h"
|
2010-06-28 22:49:35 +00:00
|
|
|
#include "mozilla/css/Loader.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsContentUtils.h"
|
1998-11-12 23:55:47 +00:00
|
|
|
#include "nsIScriptContext.h"
|
1998-12-11 02:53:49 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-11-16 05:07:31 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-05-13 20:27:47 +00:00
|
|
|
#include "nsIContentViewer.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "prtime.h"
|
|
|
|
#include "prlog.h"
|
1998-11-12 23:55:47 +00:00
|
|
|
#include "prmem.h"
|
2001-02-22 03:01:34 +00:00
|
|
|
#include "nsParserUtils.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsRect.h"
|
2001-05-19 02:59:15 +00:00
|
|
|
#include "nsGenericElement.h"
|
2001-04-30 23:35:09 +00:00
|
|
|
#include "nsIWebNavigation.h"
|
2001-05-17 05:54:16 +00:00
|
|
|
#include "nsIScriptElement.h"
|
2006-11-04 05:45:02 +00:00
|
|
|
#include "nsScriptLoader.h"
|
2001-05-19 02:59:15 +00:00
|
|
|
#include "nsStyleLinkElement.h"
|
2003-03-19 03:47:09 +00:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2001-12-17 07:14:49 +00:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2002-03-27 06:19:14 +00:00
|
|
|
#include "nsICookieService.h"
|
|
|
|
#include "nsIPrompt.h"
|
|
|
|
#include "nsIChannel.h"
|
2002-07-02 17:58:24 +00:00
|
|
|
#include "nsIPrincipal.h"
|
2002-10-22 05:28:36 +00:00
|
|
|
#include "nsXMLPrettyPrinter.h"
|
2004-06-25 12:26:02 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2004-10-24 17:25:58 +00:00
|
|
|
#include "nsIContentPolicy.h"
|
2010-09-15 22:54:00 +00:00
|
|
|
#include "nsIDocumentViewer.h"
|
2004-10-24 17:25:58 +00:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2006-03-22 18:36:36 +00:00
|
|
|
#include "nsContentErrors.h"
|
2006-05-19 10:29:43 +00:00
|
|
|
#include "nsIDOMProcessingInstruction.h"
|
2006-07-02 07:23:10 +00:00
|
|
|
#include "nsNodeUtils.h"
|
2007-01-30 21:21:06 +00:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
2009-11-06 04:27:30 +00:00
|
|
|
#include "nsIHTMLDocument.h"
|
2008-04-11 17:29:06 +00:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2009-11-20 23:12:42 +00:00
|
|
|
#include "nsMimeTypes.h"
|
2010-07-18 22:07:54 +00:00
|
|
|
#include "nsHtml5SVGLoadDispatcher.h"
|
2004-07-06 22:52:03 +00:00
|
|
|
|
2010-10-25 12:17:38 +00:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
1998-11-14 00:21:19 +00:00
|
|
|
// XXX Open Issues:
|
2001-04-30 23:35:09 +00:00
|
|
|
// 1) what's not allowed - We need to figure out which HTML tags
|
1998-11-14 00:21:19 +00:00
|
|
|
// (prefixed with a HTML namespace qualifier) are explicitly not
|
|
|
|
// allowed (if any).
|
2001-04-30 23:35:09 +00:00
|
|
|
// 2) factoring code with nsHTMLContentSink - There's some amount of
|
1998-11-14 00:21:19 +00:00
|
|
|
// common code between this and the HTML content sink. This will
|
|
|
|
// increase as we support more and more HTML elements. How can code
|
|
|
|
// from the code be factored?
|
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
nsresult
|
|
|
|
NS_NewXMLContentSink(nsIXMLContentSink** aResult,
|
|
|
|
nsIDocument* aDoc,
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI* aURI,
|
2003-04-03 18:57:33 +00:00
|
|
|
nsISupports* aContainer,
|
2002-03-27 06:19:14 +00:00
|
|
|
nsIChannel* aChannel)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2010-07-05 09:42:18 +00:00
|
|
|
nsXMLContentSink* it = new nsXMLContentSink();
|
1998-11-11 22:06:16 +00:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2003-01-14 22:32:18 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIXMLContentSink> kungFuDeathGrip = it;
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult rv = it->Init(aDoc, aURI, aContainer, aChannel);
|
2003-02-17 14:52:46 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
return CallQueryInterface(it, aResult);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXMLContentSink::nsXMLContentSink()
|
2007-02-02 02:12:48 +00:00
|
|
|
: mConstrainSize(PR_TRUE),
|
2009-10-25 04:33:47 +00:00
|
|
|
mPrettyPrintXML(PR_TRUE)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXMLContentSink::~nsXMLContentSink()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mDocElement);
|
2004-01-08 04:25:43 +00:00
|
|
|
if (mText) {
|
|
|
|
PR_Free(mText); // Doesn't null out, unlike PR_FREEIF
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::Init(nsIDocument* aDoc,
|
2004-01-09 23:54:21 +00:00
|
|
|
nsIURI* aURI,
|
2003-04-03 18:57:33 +00:00
|
|
|
nsISupports* aContainer,
|
2002-03-27 06:19:14 +00:00
|
|
|
nsIChannel* aChannel)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult rv = nsContentSink::Init(aDoc, aURI, aContainer, aChannel);
|
2003-10-05 07:29:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
aDoc->AddObserver(this);
|
2009-05-17 14:22:55 +00:00
|
|
|
mIsDocumentObserver = PR_TRUE;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2003-04-03 18:57:33 +00:00
|
|
|
if (!mDocShell) {
|
2002-09-04 06:57:25 +00:00
|
|
|
mPrettyPrintXML = PR_FALSE;
|
|
|
|
}
|
2003-01-14 22:32:18 +00:00
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
mState = eXMLContentSinkState_InProlog;
|
|
|
|
mDocElement = nsnull;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
return NS_OK;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 22:07:51 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsXMLContentSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXMLContentSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIExpatSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITransformObserver)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsContentSink)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsXMLContentSink, nsContentSink)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsXMLContentSink, nsContentSink)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLContentSink)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLContentSink,
|
|
|
|
nsContentSink)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentHead)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDocElement)
|
|
|
|
for (PRUint32 i = 0, count = tmp->mContentStack.Length(); i < count; i++) {
|
|
|
|
const StackNode& node = tmp->mContentStack.ElementAt(i);
|
|
|
|
cb.NoteXPCOMChild(node.mContent);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2003-10-05 07:29:50 +00:00
|
|
|
|
|
|
|
// nsIContentSink
|
2007-01-30 21:21:06 +00:00
|
|
|
NS_IMETHODIMP
|
2008-10-30 21:31:00 +00:00
|
|
|
nsXMLContentSink::WillParse(void)
|
2007-01-30 21:21:06 +00:00
|
|
|
{
|
2008-10-30 21:31:00 +00:00
|
|
|
return WillParseImpl();
|
2007-01-30 21:21:06 +00: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 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
2009-06-23 21:22:16 +00:00
|
|
|
nsXMLContentSink::WillBuildModel(nsDTDMode aDTDMode)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2007-01-30 21:21:06 +00:00
|
|
|
WillBuildModelImpl();
|
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
// Notify document that the load is beginning
|
|
|
|
mDocument->BeginLoad();
|
2004-04-20 17:12:48 +00:00
|
|
|
|
|
|
|
// Check for correct load-command for maybe prettyprinting
|
|
|
|
if (mPrettyPrintXML) {
|
2004-07-17 21:45:37 +00:00
|
|
|
nsCAutoString command;
|
2004-04-20 17:12:48 +00:00
|
|
|
mParser->GetCommand(command);
|
2004-05-22 22:15:22 +00:00
|
|
|
if (!command.EqualsLiteral("view")) {
|
2004-04-20 17:12:48 +00:00
|
|
|
mPrettyPrintXML = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-14 17:59:19 +00:00
|
|
|
return NS_OK;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
PRBool
|
|
|
|
nsXMLContentSink::CanStillPrettyPrint()
|
|
|
|
{
|
|
|
|
return mPrettyPrintXML &&
|
|
|
|
(!mPrettyPrintHasFactoredElements || mPrettyPrintHasSpecialRoot);
|
|
|
|
}
|
|
|
|
|
2002-10-09 07:03:15 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::MaybePrettyPrint()
|
2002-09-04 06:57:25 +00:00
|
|
|
{
|
2007-01-30 21:21:06 +00:00
|
|
|
if (!CanStillPrettyPrint()) {
|
2002-09-04 06:57:25 +00:00
|
|
|
mPrettyPrintXML = PR_FALSE;
|
|
|
|
|
2002-10-09 07:03:15 +00:00
|
|
|
return NS_OK;
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
// stop observing in order to avoid crashing when replacing content
|
|
|
|
mDocument->RemoveObserver(this);
|
2009-05-17 14:22:55 +00:00
|
|
|
mIsDocumentObserver = PR_FALSE;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2004-04-20 17:12:48 +00:00
|
|
|
// Reenable the CSSLoader so that the prettyprinting stylesheets can load
|
|
|
|
if (mCSSLoader) {
|
|
|
|
mCSSLoader->SetEnabled(PR_TRUE);
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
2004-04-20 17:12:48 +00:00
|
|
|
|
2002-10-22 05:28:36 +00:00
|
|
|
nsCOMPtr<nsXMLPrettyPrinter> printer;
|
|
|
|
nsresult rv = NS_NewXMLPrettyPrinter(getter_AddRefs(printer));
|
2002-10-09 07:03:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-05-31 01:42:48 +00:00
|
|
|
PRBool isPrettyPrinting;
|
|
|
|
rv = printer->PrettyPrint(mDocument, &isPrettyPrinting);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mPrettyPrinting = isPrettyPrinting;
|
|
|
|
return NS_OK;
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
|
|
|
|
2006-05-19 10:29:43 +00:00
|
|
|
static void
|
|
|
|
CheckXSLTParamPI(nsIDOMProcessingInstruction* aPi,
|
|
|
|
nsIDocumentTransformer* aProcessor,
|
|
|
|
nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
nsAutoString target, data;
|
|
|
|
aPi->GetTarget(target);
|
|
|
|
|
|
|
|
// Check for namespace declarations
|
|
|
|
if (target.EqualsLiteral("xslt-param-namespace")) {
|
|
|
|
aPi->GetData(data);
|
|
|
|
nsAutoString prefix, namespaceAttr;
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::prefix,
|
|
|
|
prefix);
|
|
|
|
if (!prefix.IsEmpty() &&
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::_namespace,
|
|
|
|
namespaceAttr)) {
|
|
|
|
aProcessor->AddXSLTParamNamespace(prefix, namespaceAttr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for actual parameters
|
|
|
|
else if (target.EqualsLiteral("xslt-param")) {
|
|
|
|
aPi->GetData(data);
|
|
|
|
nsAutoString name, namespaceAttr, select, value;
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::name,
|
|
|
|
name);
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::_namespace,
|
|
|
|
namespaceAttr);
|
|
|
|
if (!nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::select, select)) {
|
|
|
|
select.SetIsVoid(PR_TRUE);
|
|
|
|
}
|
|
|
|
if (!nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::value, value)) {
|
|
|
|
value.SetIsVoid(PR_TRUE);
|
|
|
|
}
|
|
|
|
if (!name.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIDOMNode> doc = do_QueryInterface(aDocument);
|
|
|
|
aProcessor->AddXSLTParam(name, namespaceAttr, select, value, doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
2009-10-02 11:13:59 +00:00
|
|
|
nsXMLContentSink::DidBuildModel(PRBool aTerminated)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2009-10-02 11:13:59 +00:00
|
|
|
DidBuildModelImpl(aTerminated);
|
2002-01-07 23:51:36 +00:00
|
|
|
|
2003-03-26 01:10:14 +00:00
|
|
|
if (mXSLTProcessor) {
|
2007-01-30 21:21:06 +00:00
|
|
|
// stop observing in order to avoid crashing when replacing content
|
|
|
|
mDocument->RemoveObserver(this);
|
2009-05-17 14:22:55 +00:00
|
|
|
mIsDocumentObserver = PR_FALSE;
|
2006-05-19 10:29:43 +00:00
|
|
|
|
|
|
|
// Check for xslt-param and xslt-param-namespace PIs
|
|
|
|
PRUint32 i;
|
|
|
|
nsIContent* child;
|
|
|
|
for (i = 0; (child = mDocument->GetChildAt(i)); ++i) {
|
2006-05-19 10:51:56 +00:00
|
|
|
if (child->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION)) {
|
2006-05-19 10:29:43 +00:00
|
|
|
nsCOMPtr<nsIDOMProcessingInstruction> pi = do_QueryInterface(child);
|
|
|
|
CheckXSLTParamPI(pi, mXSLTProcessor, mDocument);
|
|
|
|
}
|
2010-04-30 13:12:06 +00:00
|
|
|
else if (child->IsElement()) {
|
2006-05-19 10:29:43 +00:00
|
|
|
// Only honor PIs in the prolog
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-14 22:32:18 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> currentDOMDoc(do_QueryInterface(mDocument));
|
2003-03-26 01:10:14 +00:00
|
|
|
mXSLTProcessor->SetSourceContentModel(currentDOMDoc);
|
|
|
|
// Since the processor now holds a reference to us we drop our reference
|
2003-01-14 22:32:18 +00:00
|
|
|
// to it to avoid owning cycles
|
2003-03-26 01:10:14 +00:00
|
|
|
mXSLTProcessor = nsnull;
|
(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 00:43:30 +00:00
|
|
|
}
|
2003-01-14 22:32:18 +00:00
|
|
|
else {
|
|
|
|
// Kick off layout for non-XSLT transformed documents.
|
2007-05-30 20:43:41 +00:00
|
|
|
mDocument->ScriptLoader()->RemoveObserver(this);
|
2002-06-20 12:04:22 +00:00
|
|
|
|
2003-10-20 19:33:46 +00:00
|
|
|
// Check if we want to prettyprint
|
|
|
|
MaybePrettyPrint();
|
|
|
|
|
2007-05-31 01:42:48 +00:00
|
|
|
PRBool startLayout = PR_TRUE;
|
|
|
|
|
|
|
|
if (mPrettyPrinting) {
|
|
|
|
NS_ASSERTION(!mPendingSheetCount, "Shouldn't have pending sheets here!");
|
|
|
|
|
|
|
|
// We're pretty-printing now. See whether we should wait up on
|
|
|
|
// stylesheet loads
|
|
|
|
if (mDocument->CSSLoader()->HasPendingLoads() &&
|
|
|
|
NS_SUCCEEDED(mDocument->CSSLoader()->AddObserver(this))) {
|
|
|
|
// wait for those sheets to load
|
|
|
|
startLayout = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startLayout) {
|
|
|
|
StartLayout(PR_FALSE);
|
2002-04-15 22:53:58 +00:00
|
|
|
|
2007-05-31 01:42:48 +00:00
|
|
|
ScrollToRef();
|
|
|
|
}
|
2002-04-15 22:53:58 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
mDocument->RemoveObserver(this);
|
2009-05-17 14:22:55 +00:00
|
|
|
mIsDocumentObserver = PR_FALSE;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2000-09-02 15:34:07 +00:00
|
|
|
mDocument->EndLoad();
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
DropParserAndPerfHint();
|
1999-06-28 14:49:29 +00:00
|
|
|
|
1998-11-11 22:06:16 +00: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-21 21:35:23 +00:00
|
|
|
NS_IMETHODIMP
|
2006-10-03 02:22:22 +00:00
|
|
|
nsXMLContentSink::OnDocumentCreated(nsIDocument* aResultDocument)
|
Landing XSLT branch. Tracking bug is 155578, fixes bugs 46633, 54659, 73492, 70369, 85408, 90157, 130161, 109918, 150916 and 170097
* New scriptable interfaces to XSLT
* Make HTML-output create real html
* cleanup the XSLTProcessor class
Patch by sicking, pike and peterv
r=sicking/pike, sr=peterv, a=asa
2002-10-21 21:35:23 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aResultDocument);
|
|
|
|
|
2009-11-06 04:27:30 +00:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(aResultDocument);
|
|
|
|
if (htmlDoc) {
|
|
|
|
htmlDoc->SetDocWriteDisabled(PR_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-21 21:35:23 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
2003-04-03 18:57:33 +00:00
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2010-09-15 22:54:00 +00:00
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(contentViewer);
|
|
|
|
if (docViewer) {
|
|
|
|
return docViewer->SetDocumentInternal(aResultDocument, PR_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-21 21:35:23 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-28 14:49:29 +00:00
|
|
|
NS_IMETHODIMP
|
2002-06-20 12:04:22 +00:00
|
|
|
nsXMLContentSink::OnTransformDone(nsresult aResult,
|
2006-10-03 02:22:22 +00:00
|
|
|
nsIDocument* aResultDocument)
|
1999-06-28 14:49:29 +00:00
|
|
|
{
|
2002-06-20 12:04:22 +00:00
|
|
|
NS_ASSERTION(NS_FAILED(aResult) || aResultDocument,
|
|
|
|
"Don't notify about transform success without a document.");
|
2000-09-16 20:53:08 +00:00
|
|
|
|
2006-10-03 02:22:22 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aResultDocument);
|
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
2003-04-03 18:57:33 +00:00
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2001-03-12 06:34:40 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
if (NS_FAILED(aResult) && contentViewer) {
|
|
|
|
// Transform failed.
|
2006-10-03 02:22:22 +00:00
|
|
|
if (domDoc) {
|
2008-10-10 17:44:43 +00:00
|
|
|
aResultDocument->SetMayStartLayout(PR_FALSE);
|
2002-06-20 12:04:22 +00:00
|
|
|
// We have an error document.
|
2006-10-03 02:22:22 +00:00
|
|
|
contentViewer->SetDOMDocument(domDoc);
|
2000-09-02 15:34:07 +00:00
|
|
|
}
|
2002-06-20 12:04:22 +00:00
|
|
|
else {
|
|
|
|
// We don't have an error document, display the
|
|
|
|
// untransformed source document.
|
|
|
|
nsCOMPtr<nsIDOMDocument> document = do_QueryInterface(mDocument);
|
|
|
|
contentViewer->SetDOMDocument(document);
|
|
|
|
}
|
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
nsCOMPtr<nsIDocument> originalDocument = mDocument;
|
|
|
|
if (NS_SUCCEEDED(aResult) || aResultDocument) {
|
|
|
|
// Transform succeeded or it failed and we have an error
|
|
|
|
// document to display.
|
2006-10-03 02:22:22 +00:00
|
|
|
mDocument = aResultDocument;
|
2009-11-06 04:27:30 +00:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
|
|
|
|
if (htmlDoc) {
|
|
|
|
htmlDoc->SetDocWriteDisabled(PR_FALSE);
|
|
|
|
}
|
2002-06-20 12:04:22 +00:00
|
|
|
}
|
2000-09-02 15:34:07 +00:00
|
|
|
|
2007-05-30 20:43:41 +00:00
|
|
|
originalDocument->ScriptLoader()->RemoveObserver(this);
|
2002-06-20 12:04:22 +00:00
|
|
|
|
2003-10-11 00:27:45 +00:00
|
|
|
// Notify document observers that all the content has been stuck
|
|
|
|
// into the document.
|
|
|
|
// XXX do we need to notify for things like PIs? Or just the
|
|
|
|
// documentElement?
|
2010-04-30 13:12:05 +00:00
|
|
|
nsIContent *rootElement = mDocument->GetRootElement();
|
|
|
|
if (rootElement) {
|
|
|
|
NS_ASSERTION(mDocument->IndexOf(rootElement) != -1,
|
|
|
|
"rootElement not in doc?");
|
2003-10-11 00:27:45 +00:00
|
|
|
mDocument->BeginUpdate(UPDATE_CONTENT_MODEL);
|
2010-04-30 13:12:05 +00:00
|
|
|
nsNodeUtils::ContentInserted(mDocument, rootElement,
|
|
|
|
mDocument->IndexOf(rootElement));
|
2003-10-11 00:27:45 +00:00
|
|
|
mDocument->EndUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
}
|
2010-08-28 05:54:57 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
// Start the layout process
|
2007-04-20 22:59:18 +00:00
|
|
|
StartLayout(PR_FALSE);
|
2002-04-25 11:58:08 +00:00
|
|
|
|
2007-02-03 00:48:29 +00:00
|
|
|
ScrollToRef();
|
2002-04-25 11:58:08 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
originalDocument->EndLoad();
|
2002-04-25 11:58:08 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
return NS_OK;
|
1999-06-28 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
2007-05-31 01:42:48 +00:00
|
|
|
NS_IMETHODIMP
|
2010-05-11 20:41:47 +00:00
|
|
|
nsXMLContentSink::StyleSheetLoaded(nsCSSStyleSheet* aSheet,
|
2007-05-31 01:42:48 +00:00
|
|
|
PRBool aWasAlternate,
|
|
|
|
nsresult aStatus)
|
|
|
|
{
|
|
|
|
if (!mPrettyPrinting) {
|
|
|
|
return nsContentSink::StyleSheetLoaded(aSheet, aWasAlternate, aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDocument->CSSLoader()->HasPendingLoads()) {
|
|
|
|
mDocument->CSSLoader()->RemoveObserver(this);
|
|
|
|
StartLayout(PR_FALSE);
|
|
|
|
ScrollToRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-28 14:49:29 +00: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 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-11-11 22:06:16 +00:00
|
|
|
nsXMLContentSink::WillInterrupt(void)
|
|
|
|
{
|
2007-01-30 21:21:06 +00:00
|
|
|
return WillInterruptImpl();
|
1998-11-11 22:06:16 +00: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 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-11-11 22:06:16 +00:00
|
|
|
nsXMLContentSink::WillResume(void)
|
|
|
|
{
|
2007-01-30 21:21:06 +00:00
|
|
|
return WillResumeImpl();
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
1998-12-11 17:02:37 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::SetParser(nsIParser* aParser)
|
|
|
|
{
|
2007-04-27 04:05:08 +00:00
|
|
|
NS_PRECONDITION(aParser, "Should have a parser here!");
|
1998-12-11 17:02:37 +00:00
|
|
|
mParser = aParser;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
2002-12-02 23:24:57 +00:00
|
|
|
nsXMLContentSink::CreateElement(const PRUnichar** aAtts, PRUint32 aAttsCount,
|
|
|
|
nsINodeInfo* aNodeInfo, PRUint32 aLineNumber,
|
2008-09-25 16:58:11 +00:00
|
|
|
nsIContent** aResult, PRBool* aAppendContent,
|
2010-10-25 12:17:38 +00:00
|
|
|
FromParser aFromParser)
|
2002-01-09 01:37:50 +00:00
|
|
|
{
|
2002-12-02 23:24:57 +00:00
|
|
|
NS_ASSERTION(aNodeInfo, "can't create element without nodeinfo");
|
|
|
|
|
2004-04-12 23:21:42 +00:00
|
|
|
*aResult = nsnull;
|
2002-12-02 23:24:57 +00:00
|
|
|
*aAppendContent = PR_TRUE;
|
2002-09-04 06:57:25 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-12-02 23:24:57 +00:00
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
|
2004-04-12 23:21:42 +00:00
|
|
|
nsCOMPtr<nsIContent> content;
|
2004-06-25 12:26:02 +00:00
|
|
|
rv = NS_NewElement(getter_AddRefs(content), aNodeInfo->NamespaceID(),
|
2010-07-23 09:49:57 +00:00
|
|
|
ni.forget(), aFromParser);
|
2004-06-25 12:26:02 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-12-02 23:24:57 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aNodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XHTML)
|
|
|
|
|| aNodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_SVG)
|
2004-07-06 22:52:03 +00:00
|
|
|
) {
|
2006-11-04 05:45:02 +00:00
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(content);
|
|
|
|
sele->SetScriptLineNumber(aLineNumber);
|
2010-12-08 12:37:19 +00:00
|
|
|
sele->SetCreatorParser(mParser);
|
2004-07-06 22:52:03 +00:00
|
|
|
mConstrainSize = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
// XHTML needs some special attention
|
2004-04-12 23:21:42 +00:00
|
|
|
if (aNodeInfo->NamespaceEquals(kNameSpaceID_XHTML)) {
|
|
|
|
mPrettyPrintHasFactoredElements = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
2002-12-02 23:24:57 +00:00
|
|
|
// If we care, find out if we just used a special factory.
|
|
|
|
if (!mPrettyPrintHasFactoredElements && !mPrettyPrintHasSpecialRoot &&
|
|
|
|
mPrettyPrintXML) {
|
2004-06-25 12:26:02 +00:00
|
|
|
mPrettyPrintHasFactoredElements =
|
2005-09-11 10:08:43 +00:00
|
|
|
nsContentUtils::NameSpaceManager()->
|
2004-06-25 12:26:02 +00:00
|
|
|
HasElementCreator(aNodeInfo->NamespaceID());
|
2002-12-02 23:24:57 +00:00
|
|
|
}
|
|
|
|
|
2004-04-12 23:21:42 +00:00
|
|
|
if (!aNodeInfo->NamespaceEquals(kNameSpaceID_SVG)) {
|
|
|
|
content.swap(*aResult);
|
2002-12-02 23:24:57 +00:00
|
|
|
|
2004-04-12 23:21:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2002-12-02 23:24:57 +00:00
|
|
|
|
2008-08-18 02:10:28 +00:00
|
|
|
if (aNodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML) ||
|
|
|
|
aNodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_XHTML) ||
|
|
|
|
aNodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_SVG)) {
|
2004-04-12 23:21:42 +00:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(content));
|
2002-12-02 23:24:57 +00:00
|
|
|
if (ssle) {
|
2007-04-20 22:59:18 +00:00
|
|
|
ssle->InitStyleLinkElement(PR_FALSE);
|
2010-10-19 03:45:34 +00:00
|
|
|
if (aFromParser) {
|
|
|
|
ssle->SetEnableUpdates(PR_FALSE);
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
if (!aNodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML)) {
|
2010-10-19 03:45:34 +00:00
|
|
|
ssle->SetLineNumber(aFromParser ? aLineNumber : 0);
|
2004-09-09 17:32:35 +00:00
|
|
|
}
|
2002-12-02 23:24:57 +00:00
|
|
|
}
|
2004-04-12 23:21:42 +00:00
|
|
|
}
|
2002-09-04 06:57:25 +00:00
|
|
|
|
2004-04-12 23:21:42 +00:00
|
|
|
content.swap(*aResult);
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
|
|
|
|
nsresult
|
2006-11-04 05:45:02 +00:00
|
|
|
nsXMLContentSink::CloseElement(nsIContent* aContent)
|
2002-12-02 23:24:57 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent, "missing element to close");
|
|
|
|
|
2005-09-24 18:43:15 +00:00
|
|
|
nsINodeInfo *nodeInfo = aContent->NodeInfo();
|
2004-04-12 23:21:42 +00:00
|
|
|
|
2004-12-01 22:41:20 +00:00
|
|
|
// Some HTML nodes need DoneAddingChildren() called to initialize
|
|
|
|
// properly (eg form state restoration).
|
|
|
|
if ((nodeInfo->NamespaceID() == kNameSpaceID_XHTML &&
|
2006-12-26 17:47:52 +00:00
|
|
|
(nodeInfo->NameAtom() == nsGkAtoms::select ||
|
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::textarea ||
|
2008-07-09 08:22:20 +00:00
|
|
|
#ifdef MOZ_MEDIA
|
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::video ||
|
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::audio ||
|
|
|
|
#endif
|
2006-12-26 17:47:52 +00:00
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::object ||
|
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::applet))
|
2004-10-07 20:59:53 +00:00
|
|
|
#ifdef MOZ_XTF
|
2004-12-01 22:41:20 +00:00
|
|
|
|| nodeInfo->NamespaceID() > kNameSpaceID_LastBuiltin
|
2004-10-07 20:59:53 +00:00
|
|
|
#endif
|
2008-08-18 02:10:28 +00:00
|
|
|
|| nodeInfo->NameAtom() == nsGkAtoms::title
|
2004-12-01 22:41:20 +00:00
|
|
|
) {
|
2008-04-17 22:30:51 +00:00
|
|
|
aContent->DoneAddingChildren(HaveNotifiedForCurrentContent());
|
2004-12-01 22:41:20 +00:00
|
|
|
}
|
2004-10-07 20:59:53 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
if (IsMonolithicContainer(nodeInfo)) {
|
|
|
|
mInMonolithicContainer--;
|
|
|
|
}
|
|
|
|
|
2004-04-12 23:21:42 +00:00
|
|
|
if (!nodeInfo->NamespaceEquals(kNameSpaceID_XHTML) &&
|
|
|
|
!nodeInfo->NamespaceEquals(kNameSpaceID_SVG)) {
|
2002-12-02 23:24:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-11-19 01:20:56 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (nodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XHTML)
|
|
|
|
|| nodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_SVG)
|
2004-07-06 22:52:03 +00:00
|
|
|
) {
|
2006-11-04 05:45:02 +00:00
|
|
|
mConstrainSize = PR_TRUE;
|
|
|
|
|
2011-08-01 07:48:28 +00:00
|
|
|
if (mPreventScriptExecution) {
|
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(aContent);
|
|
|
|
NS_ASSERTION(sele, "script did QI correctly!");
|
|
|
|
sele->PreventExecution();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-11-04 05:45:02 +00:00
|
|
|
// Now tell the script that it's ready to go. This may execute the script
|
|
|
|
// or return NS_ERROR_HTMLPARSER_BLOCK. Or neither if the script doesn't
|
|
|
|
// need executing.
|
|
|
|
rv = aContent->DoneAddingChildren(PR_TRUE);
|
|
|
|
|
|
|
|
// If the act of insertion evaluated the script, we're fine.
|
|
|
|
// Else, block the parser till the script has loaded.
|
|
|
|
if (rv == NS_ERROR_HTMLPARSER_BLOCK) {
|
|
|
|
nsCOMPtr<nsIScriptElement> sele = do_QueryInterface(aContent);
|
|
|
|
mScriptElements.AppendObject(sele);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the parser got blocked, make sure to return the appropriate rv.
|
|
|
|
// I'm not sure if this is actually needed or not.
|
|
|
|
if (mParser && !mParser->IsParserEnabled()) {
|
|
|
|
// XXX The HTML sink doesn't call BlockParser here, why do we?
|
|
|
|
mParser->BlockParser();
|
|
|
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
|
|
|
|
2004-07-06 22:52:03 +00:00
|
|
|
return rv;
|
2002-12-02 23:24:57 +00:00
|
|
|
}
|
2004-07-06 22:52:03 +00:00
|
|
|
|
2010-04-23 16:10:07 +00:00
|
|
|
if (nodeInfo->Equals(nsGkAtoms::meta, kNameSpaceID_XHTML) &&
|
2004-04-20 17:12:48 +00: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-02 23:24:57 +00:00
|
|
|
rv = ProcessMETATag(aContent);
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (nodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML) ||
|
|
|
|
nodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_XHTML) ||
|
|
|
|
nodeInfo->Equals(nsGkAtoms::style, kNameSpaceID_SVG)) {
|
2002-12-02 23:24:57 +00:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aContent));
|
|
|
|
if (ssle) {
|
|
|
|
ssle->SetEnableUpdates(PR_TRUE);
|
2007-04-20 22:59:18 +00:00
|
|
|
PRBool willNotify;
|
|
|
|
PRBool isAlternate;
|
2011-08-01 07:48:24 +00:00
|
|
|
rv = ssle->UpdateStyleSheet(mFragmentMode ? nsnull : this,
|
|
|
|
&willNotify,
|
|
|
|
&isAlternate);
|
|
|
|
if (NS_SUCCEEDED(rv) && willNotify && !isAlternate && !mFragmentMode) {
|
2007-04-20 22:59:18 +00:00
|
|
|
++mPendingSheetCount;
|
|
|
|
mScriptLoader->AddExecuteBlocker();
|
2002-12-02 23:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-07 23:00:26 +00:00
|
|
|
// Look for <link rel="dns-prefetch" href="hostname">
|
|
|
|
if (nodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML)) {
|
|
|
|
nsAutoString relVal;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::rel, relVal);
|
|
|
|
if (relVal.EqualsLiteral("dns-prefetch")) {
|
|
|
|
nsAutoString hrefVal;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::href, hrefVal);
|
|
|
|
if (!hrefVal.IsEmpty()) {
|
|
|
|
PrefetchDNS(hrefVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-12-02 23:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::AddContentAsLeaf(nsIContent *aContent)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if ((eXMLContentSinkState_InProlog == mState) ||
|
|
|
|
(eXMLContentSinkState_InEpilog == mState)) {
|
2006-01-19 03:34:18 +00:00
|
|
|
NS_ASSERTION(mDocument, "Fragments have no prolog or epilog");
|
|
|
|
mDocument->AppendChildTo(aContent, PR_FALSE);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-07-03 05:34:26 +00:00
|
|
|
nsCOMPtr<nsIContent> parent = GetCurrentContent();
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (parent) {
|
2005-04-18 22:58:35 +00:00
|
|
|
result = parent->AppendChildTo(aContent, PR_FALSE);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Create an XML parser and an XSL content sink and start parsing
|
2004-01-09 23:54:21 +00:00
|
|
|
// the XSL stylesheet located at the given URI.
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::LoadXSLStyleSheet(nsIURI* aUrl)
|
|
|
|
{
|
2008-04-17 22:22:44 +00:00
|
|
|
nsCOMPtr<nsIDocumentTransformer> processor =
|
2003-04-01 19:50:42 +00:00
|
|
|
do_CreateInstance("@mozilla.org/document-transformer;1?type=xslt");
|
2008-04-17 22:22:44 +00:00
|
|
|
if (!processor) {
|
2002-01-09 01:37:50 +00:00
|
|
|
// No XSLT processor available, continue normal document loading
|
2001-11-02 01:53:13 +00:00
|
|
|
return NS_OK;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2008-04-17 22:22:44 +00:00
|
|
|
processor->Init(mDocument->NodePrincipal());
|
|
|
|
processor->SetTransformObserver(this);
|
2001-02-03 01:16:20 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup();
|
|
|
|
if (!loadGroup) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2002-09-27 04:22:13 +00:00
|
|
|
}
|
|
|
|
|
2008-04-17 22:22:44 +00:00
|
|
|
if (NS_SUCCEEDED(processor->LoadStyleSheet(aUrl, loadGroup))) {
|
|
|
|
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 01:37:50 +00:00
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
nsresult
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
|
2005-03-30 00:36:57 +00:00
|
|
|
const nsSubstring& aHref,
|
2002-01-09 01:37:50 +00:00
|
|
|
PRBool aAlternate,
|
2005-03-30 00:36:57 +00:00
|
|
|
const nsSubstring& aTitle,
|
|
|
|
const nsSubstring& aType,
|
|
|
|
const nsSubstring& aMedia)
|
2002-01-09 01:37:50 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2002-09-04 06:57:25 +00:00
|
|
|
mPrettyPrintXML = PR_FALSE;
|
2001-07-04 19:35:23 +00:00
|
|
|
|
2004-07-17 21:45:37 +00:00
|
|
|
nsCAutoString cmd;
|
|
|
|
if (mParser)
|
|
|
|
mParser->GetCommand(cmd);
|
2004-06-26 14:32:11 +00:00
|
|
|
if (cmd.EqualsASCII(kLoadAsData))
|
2002-10-11 00:38:29 +00:00
|
|
|
return NS_OK; // Do not load stylesheets when loading as data
|
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
NS_ConvertUTF16toUTF8 type(aType);
|
2009-11-20 23:12:42 +00:00
|
|
|
if (type.EqualsIgnoreCase(TEXT_XSL) ||
|
2011-05-28 12:34:36 +00:00
|
|
|
type.EqualsIgnoreCase(APPLICATION_XSLT_XML) ||
|
2009-11-20 23:12:42 +00:00
|
|
|
type.EqualsIgnoreCase(TEXT_XML) ||
|
|
|
|
type.EqualsIgnoreCase(APPLICATION_XML)) {
|
2002-08-29 06:53:59 +00:00
|
|
|
if (aAlternate) {
|
|
|
|
// don't load alternate XSLT
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-04-03 18:57:33 +00:00
|
|
|
// LoadXSLStyleSheet needs a mDocShell.
|
|
|
|
if (!mDocShell)
|
2002-01-09 01:37:50 +00:00
|
|
|
return NS_OK;
|
2000-08-30 00:35:43 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIURI> url;
|
2010-04-23 16:10:07 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(url), aHref, nsnull,
|
2010-04-19 15:40:15 +00:00
|
|
|
mDocument->GetDocBaseURI());
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2004-10-24 17:25:58 +00:00
|
|
|
// Do security check
|
2005-10-14 09:07:29 +00:00
|
|
|
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
|
2004-04-25 16:55:27 +00:00
|
|
|
rv = secMan->
|
2008-03-04 05:39:09 +00:00
|
|
|
CheckLoadURIWithPrincipal(mDocument->NodePrincipal(), url,
|
|
|
|
nsIScriptSecurityManager::ALLOW_CHROME);
|
2002-12-03 09:20:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
|
|
|
|
2004-10-24 17:25:58 +00:00
|
|
|
// Do content policy check
|
|
|
|
PRInt16 decision = nsIContentPolicy::ACCEPT;
|
|
|
|
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_STYLESHEET,
|
|
|
|
url,
|
2007-08-08 01:16:09 +00:00
|
|
|
mDocument->NodePrincipal(),
|
2004-10-24 17:25:58 +00:00
|
|
|
aElement,
|
|
|
|
type,
|
|
|
|
nsnull,
|
2005-08-19 15:00:01 +00:00
|
|
|
&decision,
|
2007-08-08 01:16:09 +00:00
|
|
|
nsContentUtils::GetContentPolicy(),
|
|
|
|
nsContentUtils::GetSecurityManager());
|
2004-10-24 17:25:58 +00:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (NS_CP_REJECTED(decision)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-12-03 09:20:43 +00:00
|
|
|
return LoadXSLStyleSheet(url);
|
|
|
|
}
|
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
// Let nsContentSink deal with css.
|
|
|
|
rv = nsContentSink::ProcessStyleLink(aElement, aHref, aAlternate,
|
|
|
|
aTitle, aType, aMedia);
|
|
|
|
|
2007-04-20 22:59:18 +00:00
|
|
|
// nsContentSink::ProcessStyleLink handles the bookkeeping here wrt
|
|
|
|
// pending sheets.
|
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
return rv;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
2003-06-17 16:40:34 +00:00
|
|
|
nsXMLContentSink::SetDocumentCharset(nsACString& aCharset)
|
2002-01-09 01:37:50 +00:00
|
|
|
{
|
|
|
|
if (mDocument) {
|
2003-10-22 06:09:48 +00:00
|
|
|
mDocument->SetDocumentCharacterSet(aCharset);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-16 06:16:17 +00:00
|
|
|
|
2004-11-02 19:52:32 +00:00
|
|
|
nsISupports *
|
|
|
|
nsXMLContentSink::GetTarget()
|
|
|
|
{
|
|
|
|
return mDocument;
|
|
|
|
}
|
|
|
|
|
2009-04-15 22:34:50 +00:00
|
|
|
PRBool
|
|
|
|
nsXMLContentSink::IsScriptExecuting()
|
|
|
|
{
|
|
|
|
return IsScriptExecutingImpl();
|
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
2008-10-15 21:29:35 +00:00
|
|
|
nsXMLContentSink::FlushText(PRBool aReleaseTextNode)
|
2002-01-09 01:37:50 +00:00
|
|
|
{
|
2008-10-15 21:29:35 +00:00
|
|
|
nsresult rv = NS_OK;
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2008-10-15 21:29:35 +00:00
|
|
|
if (mTextLength != 0) {
|
|
|
|
if (mLastTextNode) {
|
|
|
|
if ((mLastTextNodeSize + mTextLength) > mTextSize && !mXSLTProcessor) {
|
|
|
|
mLastTextNodeSize = 0;
|
|
|
|
mLastTextNode = nsnull;
|
|
|
|
FlushText(aReleaseTextNode);
|
|
|
|
} else {
|
|
|
|
PRBool 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;
|
|
|
|
}
|
2007-06-27 04:22:35 +00:00
|
|
|
|
2008-10-15 21:29:35 +00:00
|
|
|
mLastTextNodeSize += mTextLength;
|
|
|
|
mTextLength = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIContent> textContent;
|
|
|
|
rv = NS_NewTextNode(getter_AddRefs(textContent),
|
|
|
|
mNodeInfoManager);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-27 04:22:35 +00:00
|
|
|
|
2008-10-15 21:29:35 +00:00
|
|
|
mLastTextNode = textContent;
|
|
|
|
|
|
|
|
// Set the text in the text node
|
|
|
|
textContent->SetText(mText, mTextLength, PR_FALSE);
|
|
|
|
mLastTextNodeSize += mTextLength;
|
|
|
|
mTextLength = 0;
|
|
|
|
|
|
|
|
// Add text to its parent
|
|
|
|
rv = AddContentAsLeaf(textContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aReleaseTextNode) {
|
|
|
|
mLastTextNodeSize = 0;
|
|
|
|
mLastTextNode = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsIContent*
|
|
|
|
nsXMLContentSink::GetCurrentContent()
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2007-01-30 21:21:06 +00:00
|
|
|
if (mContentStack.Length() == 0) {
|
2003-07-03 05:34:26 +00:00
|
|
|
return nsnull;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2010-10-05 01:25:44 +00:00
|
|
|
return GetCurrentStackNode()->mContent;
|
2007-01-30 21:21:06 +00:00
|
|
|
}
|
2003-07-03 05:34:26 +00:00
|
|
|
|
2010-10-05 01:25:44 +00:00
|
|
|
StackNode*
|
2007-01-30 21:21:06 +00:00
|
|
|
nsXMLContentSink::GetCurrentStackNode()
|
|
|
|
{
|
|
|
|
PRInt32 count = mContentStack.Length();
|
2010-10-05 01:25:44 +00:00
|
|
|
return count != 0 ? &mContentStack[count-1] : nsnull;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
|
|
|
|
nsresult
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::PushContent(nsIContent *aContent)
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
{
|
2003-07-03 05:34:26 +00:00
|
|
|
NS_PRECONDITION(aContent, "Null content being pushed!");
|
2007-01-30 21:21:06 +00:00
|
|
|
StackNode *sn = mContentStack.AppendElement();
|
|
|
|
NS_ENSURE_TRUE(sn, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
sn->mContent = aContent;
|
|
|
|
sn->mNumFlushed = 0;
|
|
|
|
return NS_OK;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
void
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::PopContent()
|
2007-01-30 21:21:06 +00:00
|
|
|
{
|
|
|
|
PRInt32 count = mContentStack.Length();
|
2003-07-03 05:34:26 +00:00
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
NS_WARNING("Popping empty stack");
|
2007-01-30 21:21:06 +00:00
|
|
|
return;
|
1998-11-11 22:06:16 +00: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 00:43:30 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
mContentStack.RemoveElementAt(count - 1);
|
|
|
|
}
|
2003-07-03 05:34:26 +00:00
|
|
|
|
2008-04-17 22:30:51 +00:00
|
|
|
PRBool
|
|
|
|
nsXMLContentSink::HaveNotifiedForCurrentContent() const
|
|
|
|
{
|
|
|
|
PRUint32 stackLength = mContentStack.Length();
|
|
|
|
if (stackLength) {
|
|
|
|
const StackNode& stackNode = mContentStack[stackLength - 1];
|
|
|
|
nsIContent* parent = stackNode.mContent;
|
|
|
|
return stackNode.mNumFlushed == parent->GetChildCount();
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
void
|
2007-04-20 22:59:18 +00:00
|
|
|
nsXMLContentSink::MaybeStartLayout(PRBool aIgnorePendingSheets)
|
2007-01-30 21:21:06 +00:00
|
|
|
{
|
2007-04-20 22:59:18 +00:00
|
|
|
// XXXbz if aIgnorePendingSheets is true, what should we do when
|
|
|
|
// mXSLTProcessor or CanStillPrettyPrint()?
|
2007-01-30 21:21:06 +00:00
|
|
|
if (mLayoutStarted || mXSLTProcessor || CanStillPrettyPrint()) {
|
|
|
|
return;
|
|
|
|
}
|
2007-04-20 22:59:18 +00:00
|
|
|
StartLayout(aIgnorePendingSheets);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2002-04-04 15:42:45 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2004-09-30 22:27:45 +00:00
|
|
|
PRBool
|
|
|
|
nsXMLContentSink::SetDocElement(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aTagName,
|
|
|
|
nsIContent *aContent)
|
|
|
|
{
|
|
|
|
if (mDocElement)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// check for root elements that needs special handling for
|
|
|
|
// prettyprinting
|
|
|
|
if ((aNameSpaceID == kNameSpaceID_XBL &&
|
2006-12-26 17:47:52 +00:00
|
|
|
aTagName == nsGkAtoms::bindings) ||
|
2004-09-30 22:27:45 +00:00
|
|
|
(aNameSpaceID == kNameSpaceID_XSLT &&
|
2006-12-26 17:47:52 +00:00
|
|
|
(aTagName == nsGkAtoms::stylesheet ||
|
|
|
|
aTagName == nsGkAtoms::transform))) {
|
2004-09-30 22:27:45 +00:00
|
|
|
mPrettyPrintHasSpecialRoot = PR_TRUE;
|
|
|
|
if (mPrettyPrintXML) {
|
|
|
|
// In this case, disable script execution, stylesheet
|
|
|
|
// loading, and auto XLinks since we plan to prettyprint.
|
2007-05-30 20:43:41 +00:00
|
|
|
mDocument->ScriptLoader()->SetEnabled(PR_FALSE);
|
2004-09-30 22:27:45 +00:00
|
|
|
if (mCSSLoader) {
|
|
|
|
mCSSLoader->SetEnabled(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocElement = aContent;
|
|
|
|
NS_ADDREF(mDocElement);
|
2010-05-03 13:23:36 +00:00
|
|
|
nsresult rv = mDocument->AppendChildTo(mDocElement, NotifyForDocElement());
|
2005-04-05 23:54:35 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// If we return PR_FALSE here, the caller will bail out because it won't
|
|
|
|
// find a parent content node to append to, which is fine.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-02-10 06:40:40 +00:00
|
|
|
|
|
|
|
if (aTagName == nsGkAtoms::html &&
|
|
|
|
aNameSpaceID == kNameSpaceID_XHTML) {
|
|
|
|
ProcessOfflineManifest(aContent);
|
|
|
|
}
|
|
|
|
|
2004-09-30 22:27:45 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-06-11 10:15:17 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::HandleStartElement(const PRUnichar *aName,
|
|
|
|
const PRUnichar **aAtts,
|
|
|
|
PRUint32 aAttsCount,
|
|
|
|
PRInt32 aIndex,
|
2002-01-09 18:15:36 +00:00
|
|
|
PRUint32 aLineNumber)
|
2007-06-11 10:15:17 +00:00
|
|
|
{
|
|
|
|
return HandleStartElement(aName, aAtts, aAttsCount, aIndex, aLineNumber,
|
|
|
|
PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::HandleStartElement(const PRUnichar *aName,
|
|
|
|
const PRUnichar **aAtts,
|
|
|
|
PRUint32 aAttsCount,
|
|
|
|
PRInt32 aIndex,
|
|
|
|
PRUint32 aLineNumber,
|
|
|
|
PRBool aInterruptable)
|
2002-01-09 01:37:50 +00:00
|
|
|
{
|
2003-10-30 02:17:50 +00:00
|
|
|
NS_PRECONDITION(aIndex >= -1, "Bogus aIndex");
|
|
|
|
NS_PRECONDITION(aAttsCount % 2 == 0, "incorrect aAttsCount");
|
|
|
|
// Adjust aAttsCount so it's the actual number of attributes
|
|
|
|
aAttsCount /= 2;
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
PRBool appendContent = PR_TRUE;
|
|
|
|
nsCOMPtr<nsIContent> content;
|
2001-02-28 23:51:35 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// XXX Hopefully the parser will flag this before we get
|
|
|
|
// here. If we're in the epilog, there should be no
|
|
|
|
// new elements
|
|
|
|
PR_ASSERT(eXMLContentSinkState_InEpilog != mState);
|
2001-02-28 23:51:35 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
FlushText();
|
2007-01-30 21:21:06 +00:00
|
|
|
DidAddContent();
|
2001-02-28 23:51:35 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
mState = eXMLContentSinkState_InDocumentElement;
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
|
|
|
nsContentUtils::SplitExpatName(aName, getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2001-02-28 23:51:35 +00:00
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
if (!OnOpenContainer(aAtts, aAttsCount, nameSpaceID, localName, aLineNumber)) {
|
2002-01-09 01:37:50 +00:00
|
|
|
return NS_OK;
|
2004-01-08 04:25:43 +00:00
|
|
|
}
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2011-06-14 07:56:49 +00:00
|
|
|
nodeInfo = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2008-09-25 22:46:52 +00:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
result = CreateElement(aAtts, aAttsCount, nodeInfo, aLineNumber,
|
2010-10-25 12:17:38 +00:00
|
|
|
getter_AddRefs(content), &appendContent,
|
|
|
|
FROM_PARSER_NETWORK);
|
2002-12-02 23:24:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2007-05-16 02:21:55 +00: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();
|
|
|
|
|
|
|
|
result = PushContent(content);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2004-11-23 17:21:37 +00:00
|
|
|
// Set the ID attribute atom on the node info object for this node
|
|
|
|
// This must occur before the attributes are added so the name
|
|
|
|
// of the id attribute is known.
|
|
|
|
if (aIndex != -1 && NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIAtom> IDAttr = do_GetAtom(aAtts[aIndex]);
|
|
|
|
|
|
|
|
if (IDAttr) {
|
|
|
|
nodeInfo->SetIDAttributeAtom(IDAttr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-06 23:09:32 +00:00
|
|
|
#ifdef MOZ_XTF
|
|
|
|
if (nameSpaceID > kNameSpaceID_LastBuiltin)
|
|
|
|
content->BeginAddingChildren();
|
|
|
|
#endif
|
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
// Set the attributes on the new content element
|
|
|
|
result = AddAttributes(aAtts, content);
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_OK == result) {
|
2004-09-30 22:27:45 +00:00
|
|
|
// Store the element
|
2004-12-15 15:37:23 +00:00
|
|
|
if (!SetDocElement(nameSpaceID, localName, content) && appendContent) {
|
2002-12-02 23:24:57 +00:00
|
|
|
NS_ENSURE_TRUE(parent, NS_ERROR_UNEXPECTED);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2005-04-18 22:58:35 +00:00
|
|
|
parent->AppendChildTo(content, PR_FALSE);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2002-12-02 23:24:57 +00:00
|
|
|
}
|
2002-05-20 22:47:02 +00:00
|
|
|
|
2004-12-01 22:41:20 +00:00
|
|
|
// Some HTML nodes need DoneCreatingElement() called to initialize
|
|
|
|
// properly (eg form state restoration).
|
2007-07-11 03:42:11 +00:00
|
|
|
if (nodeInfo->NamespaceID() == kNameSpaceID_XHTML) {
|
|
|
|
if (nodeInfo->NameAtom() == nsGkAtoms::input ||
|
|
|
|
nodeInfo->NameAtom() == nsGkAtoms::button) {
|
|
|
|
content->DoneCreatingElement();
|
|
|
|
} else if (nodeInfo->NameAtom() == nsGkAtoms::head && !mCurrentHead) {
|
|
|
|
mCurrentHead = content;
|
|
|
|
}
|
2004-12-01 22:41:20 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
if (IsMonolithicContainer(nodeInfo)) {
|
|
|
|
mInMonolithicContainer++;
|
|
|
|
}
|
|
|
|
|
2007-07-11 03:42:11 +00:00
|
|
|
if (content != mDocElement && !mCurrentHead) {
|
|
|
|
// This isn't the root and we're not inside an XHTML <head>.
|
|
|
|
// Might need to start layout
|
|
|
|
MaybeStartLayout(PR_FALSE);
|
|
|
|
}
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2010-08-28 05:54:57 +00:00
|
|
|
if (content == mDocElement) {
|
|
|
|
NotifyDocElementCreated(mDocument);
|
|
|
|
}
|
|
|
|
|
2007-06-11 10:15:17 +00:00
|
|
|
return aInterruptable && NS_SUCCEEDED(result) ? DidProcessATokenImpl() :
|
|
|
|
result;
|
2001-04-30 23:35:09 +00:00
|
|
|
}
|
|
|
|
|
2007-06-11 10:15:17 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::HandleEndElement(const PRUnichar *aName)
|
2007-06-11 10:15:17 +00:00
|
|
|
{
|
|
|
|
return HandleEndElement(aName, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::HandleEndElement(const PRUnichar *aName,
|
|
|
|
PRBool aInterruptable)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
// XXX Hopefully the parser will flag this before we get
|
|
|
|
// here. If we're in the prolog or epilog, there should be
|
|
|
|
// no close tags for elements.
|
|
|
|
PR_ASSERT(eXMLContentSinkState_InDocumentElement == mState);
|
1999-03-31 20:49:25 +00:00
|
|
|
|
|
|
|
FlushText();
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2010-10-05 01:25:44 +00:00
|
|
|
StackNode* sn = GetCurrentStackNode();
|
|
|
|
if (!sn) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2007-01-30 21:21:06 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
2010-10-05 01:25:44 +00:00
|
|
|
sn->mContent.swap(content);
|
|
|
|
PRUint32 numFlushed = sn->mNumFlushed;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
|
|
|
PopContent();
|
2002-12-02 23:24:57 +00:00
|
|
|
NS_ASSERTION(content, "failed to pop content");
|
2004-12-02 02:15:37 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Check that we're closing the right thing
|
|
|
|
nsCOMPtr<nsIAtom> debugNameSpacePrefix, debugTagAtom;
|
2004-12-15 15:37:23 +00:00
|
|
|
PRInt32 debugNameSpaceID;
|
|
|
|
nsContentUtils::SplitExpatName(aName, getter_AddRefs(debugNameSpacePrefix),
|
|
|
|
getter_AddRefs(debugTagAtom),
|
|
|
|
&debugNameSpaceID);
|
2005-09-24 18:43:15 +00:00
|
|
|
NS_ASSERTION(content->NodeInfo()->Equals(debugTagAtom, debugNameSpaceID),
|
2004-12-02 02:15:37 +00:00
|
|
|
"Wrong element being closed");
|
|
|
|
#endif
|
2001-07-04 19:35:23 +00:00
|
|
|
|
2006-11-04 05:45:02 +00:00
|
|
|
result = CloseElement(content);
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2007-07-11 03:42:11 +00:00
|
|
|
if (mCurrentHead == content) {
|
|
|
|
mCurrentHead = nsnull;
|
|
|
|
}
|
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
if (mDocElement == content) {
|
2005-06-02 02:38:20 +00: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-02 23:24:57 +00:00
|
|
|
mState = eXMLContentSinkState_InEpilog;
|
2007-07-11 03:42:11 +00:00
|
|
|
|
|
|
|
// We might have had no occasion to start layout yet. Do so now.
|
|
|
|
MaybeStartLayout(PR_FALSE);
|
2002-12-02 23:24:57 +00:00
|
|
|
}
|
2001-07-04 19:35:23 +00:00
|
|
|
|
2007-02-28 17:28:17 +00:00
|
|
|
PRInt32 stackLen = mContentStack.Length();
|
|
|
|
if (mNotifyLevel >= stackLen) {
|
|
|
|
if (numFlushed < content->GetChildCount()) {
|
|
|
|
NotifyAppend(content, numFlushed);
|
|
|
|
}
|
|
|
|
mNotifyLevel = stackLen - 1;
|
|
|
|
}
|
|
|
|
DidAddContent();
|
|
|
|
|
2010-07-18 22:07:54 +00:00
|
|
|
if (content->GetNameSpaceID() == kNameSpaceID_SVG &&
|
|
|
|
content->Tag() == nsGkAtoms::svg) {
|
2007-05-23 20:05:53 +00:00
|
|
|
FlushTags();
|
2010-07-18 22:07:54 +00:00
|
|
|
nsCOMPtr<nsIRunnable> event = new nsHtml5SVGLoadDispatcher(content);
|
|
|
|
if (NS_FAILED(NS_DispatchToMainThread(event))) {
|
|
|
|
NS_WARNING("failed to dispatch svg load dispatcher");
|
2007-01-30 21:21:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-11 10:15:17 +00:00
|
|
|
return aInterruptable && NS_SUCCEEDED(result) ? DidProcessATokenImpl() :
|
|
|
|
result;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::HandleComment(const PRUnichar *aName)
|
|
|
|
{
|
|
|
|
FlushText();
|
2001-07-04 19:35:23 +00:00
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIContent> comment;
|
2005-09-24 18:43:15 +00:00
|
|
|
nsresult rv = NS_NewCommentNode(getter_AddRefs(comment), mNodeInfoManager);
|
2002-12-11 14:24:49 +00:00
|
|
|
if (comment) {
|
2006-09-12 04:48:12 +00:00
|
|
|
comment->SetText(nsDependentString(aName), PR_FALSE);
|
|
|
|
rv = AddContentAsLeaf(comment);
|
2007-01-30 21:21:06 +00:00
|
|
|
DidAddContent();
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
return NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
1998-12-27 08:24:04 +00:00
|
|
|
|
2002-01-24 22:15:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::HandleCDataSection(const PRUnichar *aData,
|
|
|
|
PRUint32 aLength)
|
2000-06-17 01:49:19 +00:00
|
|
|
{
|
2006-04-06 06:17:51 +00: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 01:37:50 +00:00
|
|
|
FlushText();
|
2000-12-11 22:21:06 +00:00
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIContent> cdata;
|
2005-09-24 18:43:15 +00:00
|
|
|
nsresult rv = NS_NewXMLCDATASection(getter_AddRefs(cdata), mNodeInfoManager);
|
2002-12-11 14:24:49 +00:00
|
|
|
if (cdata) {
|
2006-09-12 04:48:12 +00:00
|
|
|
cdata->SetText(aData, aLength, PR_FALSE);
|
|
|
|
rv = AddContentAsLeaf(cdata);
|
2007-01-30 21:21:06 +00:00
|
|
|
DidAddContent();
|
2000-06-17 01:49:19 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
return NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
2000-06-17 01:49:19 +00: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 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-05-22 00:46:16 +00:00
|
|
|
nsXMLContentSink::HandleDoctypeDecl(const nsAString & aSubset,
|
|
|
|
const nsAString & aName,
|
|
|
|
const nsAString & aSystemId,
|
|
|
|
const nsAString & aPublicId,
|
2002-03-15 09:45:31 +00:00
|
|
|
nsISupports* aCatalogData)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2002-08-13 18:41:16 +00:00
|
|
|
FlushText();
|
|
|
|
|
2000-06-17 01:49:19 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2006-01-19 03:34:18 +00:00
|
|
|
NS_ASSERTION(mDocument, "Shouldn't get here from a document fragment");
|
2000-06-17 01:49:19 +00:00
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
nsCOMPtr<nsIAtom> name = do_GetAtom(aName);
|
|
|
|
NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2000-06-17 01:49:19 +00:00
|
|
|
// Create a new doctype node
|
2003-11-19 01:20:56 +00:00
|
|
|
nsCOMPtr<nsIDOMDocumentType> docType;
|
2005-09-24 18:43:15 +00:00
|
|
|
rv = NS_NewDOMDocumentType(getter_AddRefs(docType), mNodeInfoManager, nsnull,
|
2011-04-14 12:04:21 +00:00
|
|
|
name, aPublicId, aSystemId, aSubset);
|
2000-06-17 01:49:19 +00:00
|
|
|
if (NS_FAILED(rv) || !docType) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-03-15 09:45:31 +00:00
|
|
|
if (aCatalogData && mCSSLoader && mDocument) {
|
|
|
|
// bug 124570 - we only expect additional agent sheets for now -- ignore
|
|
|
|
// exit codes, error are not fatal here, just that the stylesheet won't apply
|
|
|
|
nsCOMPtr<nsIURI> uri(do_QueryInterface(aCatalogData));
|
|
|
|
if (uri) {
|
2010-05-11 20:41:47 +00:00
|
|
|
nsRefPtr<nsCSSStyleSheet> sheet;
|
2009-03-17 01:38:36 +00:00
|
|
|
mCSSLoader->LoadSheetSync(uri, PR_TRUE, PR_TRUE, getter_AddRefs(sheet));
|
2010-05-11 20:41:47 +00:00
|
|
|
|
2002-03-15 09:45:31 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsCAutoString uriStr;
|
|
|
|
uri->GetSpec(uriStr);
|
|
|
|
printf("Loading catalog stylesheet: %s ... %s\n", uriStr.get(), sheet.get() ? "Done" : "Failed");
|
|
|
|
#endif
|
|
|
|
if (sheet) {
|
2003-10-02 21:29:40 +00:00
|
|
|
mDocument->BeginUpdate(UPDATE_STYLE);
|
2004-07-28 07:08:41 +00:00
|
|
|
mDocument->AddCatalogStyleSheet(sheet);
|
2003-10-02 21:29:40 +00:00
|
|
|
mDocument->EndUpdate(UPDATE_STYLE);
|
2002-03-15 09:45:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-19 03:34:18 +00:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(docType);
|
|
|
|
NS_ASSERTION(content, "doctype isn't content?");
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
rv = mDocument->AppendChildTo(content, PR_FALSE);
|
|
|
|
DidAddContent();
|
|
|
|
return NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2007-06-11 10:15:17 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::HandleCharacterData(const PRUnichar *aData,
|
|
|
|
PRUint32 aLength)
|
2007-06-11 10:15:17 +00:00
|
|
|
{
|
|
|
|
return HandleCharacterData(aData, aLength, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::HandleCharacterData(const PRUnichar *aData, PRUint32 aLength,
|
|
|
|
PRBool aInterruptable)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2007-01-30 21:21:06 +00:00
|
|
|
nsresult rv = NS_OK;
|
2003-10-15 20:10:47 +00:00
|
|
|
if (aData && mState != eXMLContentSinkState_InProlog &&
|
|
|
|
mState != eXMLContentSinkState_InEpilog) {
|
2007-01-30 21:21:06 +00:00
|
|
|
rv = AddText(aData, aLength);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2007-06-11 10:15:17 +00:00
|
|
|
return aInterruptable && NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
1998-11-11 22:06:16 +00: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 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::HandleProcessingInstruction(const PRUnichar *aTarget,
|
|
|
|
const PRUnichar *aData)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
FlushText();
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
const nsDependentString target(aTarget);
|
2002-04-25 11:58:08 +00:00
|
|
|
const nsDependentString data(aData);
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIContent> node;
|
2001-01-04 00:30:11 +00:00
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
nsresult rv = NS_NewXMLProcessingInstruction(getter_AddRefs(node),
|
|
|
|
mNodeInfoManager, target, data);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(node));
|
|
|
|
if (ssle) {
|
2007-04-20 22:59:18 +00:00
|
|
|
ssle->InitStyleLinkElement(PR_FALSE);
|
2006-03-17 14:38:57 +00:00
|
|
|
ssle->SetEnableUpdates(PR_FALSE);
|
|
|
|
mPrettyPrintXML = PR_FALSE;
|
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
rv = AddContentAsLeaf(node);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-01-30 21:21:06 +00:00
|
|
|
DidAddContent();
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
if (ssle) {
|
2007-04-20 22:59:18 +00:00
|
|
|
// This is an xml-stylesheet processing instruction... but it might not be
|
|
|
|
// a CSS one if the type is set to something else.
|
2006-03-17 14:38:57 +00:00
|
|
|
ssle->SetEnableUpdates(PR_TRUE);
|
2007-04-20 22:59:18 +00:00
|
|
|
PRBool willNotify;
|
|
|
|
PRBool isAlternate;
|
2011-08-01 07:48:24 +00:00
|
|
|
rv = ssle->UpdateStyleSheet(mFragmentMode ? nsnull : this,
|
|
|
|
&willNotify,
|
|
|
|
&isAlternate);
|
2007-04-20 22:59:18 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (willNotify) {
|
|
|
|
// Successfully started a stylesheet load
|
2011-08-01 07:48:24 +00:00
|
|
|
if (!isAlternate && !mFragmentMode) {
|
2007-04-20 22:59:18 +00:00
|
|
|
++mPendingSheetCount;
|
|
|
|
mScriptLoader->AddExecuteBlocker();
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2007-04-20 22:59:18 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2006-03-17 14:38:57 +00:00
|
|
|
}
|
2001-09-05 04:20:54 +00:00
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
// If it's not a CSS stylesheet PI...
|
|
|
|
nsAutoString type;
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::type, type);
|
|
|
|
|
|
|
|
if (mState != eXMLContentSinkState_InProlog ||
|
|
|
|
!target.EqualsLiteral("xml-stylesheet") ||
|
2007-04-20 22:59:18 +00:00
|
|
|
type.IsEmpty() ||
|
2006-03-17 14:38:57 +00:00
|
|
|
type.LowerCaseEqualsLiteral("text/css")) {
|
2007-01-30 21:21:06 +00:00
|
|
|
return DidProcessATokenImpl();
|
2006-03-17 14:38:57 +00:00
|
|
|
}
|
1999-01-12 16:37:24 +00:00
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
nsAutoString href, title, media;
|
|
|
|
PRBool isAlternate = PR_FALSE;
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
// If there was no href, we can't do anything with this PI
|
2008-11-28 21:21:55 +00:00
|
|
|
if (!ParsePIData(data, href, title, media, isAlternate)) {
|
2007-01-30 21:21:06 +00:00
|
|
|
return DidProcessATokenImpl();
|
2006-03-17 14:38:57 +00:00
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
rv = ProcessStyleLink(node, href, isAlternate, title, type, media);
|
|
|
|
return NS_SUCCEEDED(rv) ? DidProcessATokenImpl() : rv;
|
2006-03-17 14:38:57 +00:00
|
|
|
}
|
2006-03-16 13:47:42 +00:00
|
|
|
|
2006-03-17 14:38:57 +00:00
|
|
|
/* static */
|
2008-11-28 21:21:55 +00:00
|
|
|
PRBool
|
2006-03-17 14:38:57 +00:00
|
|
|
nsXMLContentSink::ParsePIData(const nsString &aData, nsString &aHref,
|
|
|
|
nsString &aTitle, nsString &aMedia,
|
|
|
|
PRBool &aIsAlternate)
|
|
|
|
{
|
|
|
|
// If there was no href, we can't do anything with this PI
|
2008-11-28 21:21:55 +00:00
|
|
|
if (!nsParserUtils::GetQuotedAttributeValue(aData, nsGkAtoms::href, aHref)) {
|
|
|
|
return PR_FALSE;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2006-03-17 14:38:57 +00:00
|
|
|
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(aData, nsGkAtoms::title, aTitle);
|
|
|
|
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(aData, nsGkAtoms::media, aMedia);
|
|
|
|
|
|
|
|
nsAutoString alternate;
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(aData, nsGkAtoms::alternate, alternate);
|
|
|
|
|
|
|
|
aIsAlternate = alternate.EqualsLiteral("yes");
|
2008-11-28 21:21:55 +00:00
|
|
|
|
|
|
|
return PR_TRUE;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2002-08-13 18:41:16 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-17 09:17:35 +00:00
|
|
|
nsXMLContentSink::HandleXMLDeclaration(const PRUnichar *aVersion,
|
|
|
|
const PRUnichar *aEncoding,
|
2004-12-21 13:25:31 +00:00
|
|
|
PRInt32 aStandalone)
|
2002-08-13 18:41:16 +00:00
|
|
|
{
|
2004-12-17 09:17:35 +00:00
|
|
|
mDocument->SetXMLDeclaration(aVersion, aEncoding, aStandalone);
|
2002-08-13 18:41:16 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
return DidProcessATokenImpl();
|
2002-08-13 18:41:16 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::ReportError(const PRUnichar* aErrorText,
|
2006-01-21 02:02:02 +00:00
|
|
|
const PRUnichar* aSourceText,
|
2006-08-25 16:34:57 +00:00
|
|
|
nsIScriptError *aError,
|
|
|
|
PRBool *_retval)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2006-08-25 16:34:57 +00:00
|
|
|
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult rv = NS_OK;
|
2006-08-25 16:34:57 +00:00
|
|
|
|
|
|
|
// The expat driver should report the error. We're just cleaning up the mess.
|
|
|
|
*_retval = PR_TRUE;
|
2002-10-22 05:28:36 +00:00
|
|
|
|
|
|
|
mPrettyPrintXML = PR_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 00:43:30 +00:00
|
|
|
|
2002-03-12 22:17:18 +00:00
|
|
|
mState = eXMLContentSinkState_InProlog;
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
// XXX need to stop scripts here -- hsivonen
|
|
|
|
|
|
|
|
// stop observing in order to avoid crashing when removing content
|
|
|
|
mDocument->RemoveObserver(this);
|
2009-05-17 14:22:55 +00:00
|
|
|
mIsDocumentObserver = PR_FALSE;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2002-03-12 22:17:18 +00:00
|
|
|
// Clear the current content and
|
|
|
|
// prepare to set <parsererror> as the document root
|
2004-12-04 17:51:12 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mDocument));
|
|
|
|
if (node) {
|
2002-03-12 22:17:18 +00:00
|
|
|
for (;;) {
|
|
|
|
nsCOMPtr<nsIDOMNode> child, dummy;
|
2004-12-04 17:51:12 +00:00
|
|
|
node->GetLastChild(getter_AddRefs(child));
|
2002-03-12 22:17:18 +00:00
|
|
|
if (!child)
|
|
|
|
break;
|
2004-12-04 17:51:12 +00:00
|
|
|
node->RemoveChild(child, getter_AddRefs(dummy));
|
2002-03-12 22:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(mDocElement);
|
|
|
|
|
2005-04-06 06:28:28 +00: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 03:40:36 +00:00
|
|
|
mTextLength = 0;
|
|
|
|
|
2003-03-26 01:10:14 +00:00
|
|
|
if (mXSLTProcessor) {
|
|
|
|
// Get rid of the XSLT processor.
|
|
|
|
mXSLTProcessor->CancelLoads();
|
|
|
|
mXSLTProcessor = nsnull;
|
2002-04-25 11:58:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
// release the nodes on stack
|
|
|
|
mContentStack.Clear();
|
|
|
|
mNotifyLevel = 0;
|
|
|
|
|
2009-02-27 18:37:51 +00:00
|
|
|
rv = HandleProcessingInstruction(NS_LITERAL_STRING("xml-stylesheet").get(),
|
|
|
|
NS_LITERAL_STRING("href=\"chrome://global/locale/intl.css\" type=\"text/css\"").get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
const PRUnichar* noAtts[] = { 0, 0 };
|
2000-01-21 01:32:32 +00:00
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(errorNs,
|
|
|
|
"http://www.mozilla.org/newlayout/xml/parsererror.xml");
|
|
|
|
|
|
|
|
nsAutoString parsererror(errorNs);
|
|
|
|
parsererror.Append((PRUnichar)0xFFFF);
|
|
|
|
parsererror.AppendLiteral("parsererror");
|
|
|
|
|
2007-06-11 10:15:17 +00:00
|
|
|
rv = HandleStartElement(parsererror.get(), noAtts, 0, -1, (PRUint32)-1,
|
|
|
|
PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-01-21 00:05:36 +00:00
|
|
|
|
2007-06-11 10:15:17 +00:00
|
|
|
rv = HandleCharacterData(aErrorText, nsCRT::strlen(aErrorText), PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2004-12-15 15:37:23 +00:00
|
|
|
nsAutoString sourcetext(errorNs);
|
|
|
|
sourcetext.Append((PRUnichar)0xFFFF);
|
|
|
|
sourcetext.AppendLiteral("sourcetext");
|
|
|
|
|
2007-06-11 10:15:17 +00:00
|
|
|
rv = HandleStartElement(sourcetext.get(), noAtts, 0, -1, (PRUint32)-1,
|
|
|
|
PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2007-06-11 10:15:17 +00:00
|
|
|
rv = HandleCharacterData(aSourceText, nsCRT::strlen(aSourceText), PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2007-06-11 10:15:17 +00:00
|
|
|
rv = HandleEndElement(sourcetext.get(), PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2007-06-11 10:15:17 +00:00
|
|
|
rv = HandleEndElement(parsererror.get(), PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2007-01-30 21:21:06 +00:00
|
|
|
FlushTags();
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return NS_OK;
|
1998-11-11 22:06:16 +00: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 00:43:30 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::AddAttributes(const PRUnichar** aAtts,
|
2002-12-02 23:24:57 +00:00
|
|
|
nsIContent* aContent)
|
1998-12-18 01:36:41 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
// Add tag attributes to the content attributes
|
2004-12-15 15:37:23 +00:00
|
|
|
nsCOMPtr<nsIAtom> prefix, localName;
|
2002-01-09 01:37:50 +00:00
|
|
|
while (*aAtts) {
|
|
|
|
PRInt32 nameSpaceID;
|
2004-12-15 15:37:23 +00:00
|
|
|
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
|
|
|
|
getter_AddRefs(localName), &nameSpaceID);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
// Add attribute to content
|
2004-12-15 15:37:23 +00:00
|
|
|
aContent->SetAttr(nameSpaceID, localName, prefix,
|
2004-01-15 17:07:27 +00:00
|
|
|
nsDependentString(aAtts[1]), PR_FALSE);
|
2002-01-09 01:37:50 +00:00
|
|
|
aAtts += 2;
|
|
|
|
}
|
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
return NS_OK;
|
1998-12-18 01:36:41 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
#define NS_ACCUMULATION_BUFFER_SIZE 4096
|
|
|
|
|
1998-11-12 23:55:47 +00:00
|
|
|
nsresult
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::AddText(const PRUnichar* aText,
|
|
|
|
PRInt32 aLength)
|
1998-11-12 23:55:47 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
// Create buffer when we first need it
|
|
|
|
if (0 == mTextSize) {
|
|
|
|
mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * NS_ACCUMULATION_BUFFER_SIZE);
|
|
|
|
if (nsnull == mText) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mTextSize = NS_ACCUMULATION_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy data from string into our buffer; flush buffer when it fills up
|
|
|
|
PRInt32 offset = 0;
|
|
|
|
while (0 != aLength) {
|
|
|
|
PRInt32 amount = mTextSize - mTextLength;
|
|
|
|
if (0 == amount) {
|
2006-04-06 06:17:51 +00:00
|
|
|
// XSLT wants adjacent textnodes merged.
|
|
|
|
if (mConstrainSize && !mXSLTProcessor) {
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult rv = FlushText();
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-06-11 09:15:23 +00:00
|
|
|
|
|
|
|
amount = mTextSize - mTextLength;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mTextSize += aLength;
|
|
|
|
mText = (PRUnichar *) PR_REALLOC(mText, sizeof(PRUnichar) * mTextSize);
|
|
|
|
if (nsnull == mText) {
|
2007-06-11 09:15:23 +00:00
|
|
|
mTextSize = 0;
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2007-06-11 09:15:23 +00:00
|
|
|
|
|
|
|
amount = aLength;
|
1999-05-13 20:27:47 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-11 09:15:23 +00:00
|
|
|
if (amount > aLength) {
|
|
|
|
amount = aLength;
|
|
|
|
}
|
|
|
|
memcpy(&mText[mTextLength], &aText[offset], sizeof(PRUnichar) * amount);
|
|
|
|
mTextLength += amount;
|
|
|
|
offset += amount;
|
2002-01-09 01:37:50 +00:00
|
|
|
aLength -= amount;
|
1999-05-13 20:27:47 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
|
1999-05-13 20:27:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-01-30 21:21:06 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsXMLContentSink::FlushPendingNotifications(mozFlushType aType)
|
|
|
|
{
|
|
|
|
// Only flush tags if we're not doing the notification ourselves
|
|
|
|
// (since we aren't reentrant)
|
|
|
|
if (!mInNotification) {
|
2009-05-17 14:22:55 +00:00
|
|
|
if (mIsDocumentObserver) {
|
|
|
|
// Only flush if we're still a document observer (so that our child
|
|
|
|
// counts should be correct).
|
|
|
|
if (aType >= Flush_ContentAndNotify) {
|
|
|
|
FlushTags();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
FlushText(PR_FALSE);
|
|
|
|
}
|
2007-01-30 21:21:06 +00:00
|
|
|
}
|
2009-04-21 23:53:52 +00:00
|
|
|
if (aType >= Flush_InterruptibleLayout) {
|
2007-01-30 21:21:06 +00:00
|
|
|
// Make sure that layout has started so that the reflow flush
|
|
|
|
// will actually happen.
|
2007-04-20 22:59:18 +00:00
|
|
|
MaybeStartLayout(PR_TRUE);
|
2007-01-30 21:21:06 +00: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()
|
|
|
|
{
|
2007-07-11 03:42:11 +00:00
|
|
|
mDeferredFlushTags = PR_FALSE;
|
2007-03-09 23:43:50 +00:00
|
|
|
PRBool oldBeganUpdate = mBeganUpdate;
|
2007-05-17 23:54:35 +00:00
|
|
|
PRUint32 oldUpdates = mUpdatesInNotification;
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2007-05-17 23:54:35 +00:00
|
|
|
mUpdatesInNotification = 0;
|
2007-01-30 21:21:06 +00:00
|
|
|
++mInNotification;
|
2007-04-07 00:20:09 +00:00
|
|
|
{
|
|
|
|
// Scope so we call EndUpdate before we decrease mInNotification
|
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_CONTENT_MODEL, PR_TRUE);
|
|
|
|
mBeganUpdate = PR_TRUE;
|
|
|
|
|
|
|
|
// Don't release last text node in case we need to add to it again
|
2008-10-15 21:29:35 +00:00
|
|
|
FlushText(PR_FALSE);
|
2007-04-07 00:20:09 +00: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.
|
|
|
|
|
|
|
|
PRInt32 stackPos;
|
|
|
|
PRInt32 stackLen = mContentStack.Length();
|
|
|
|
PRBool flushed = PR_FALSE;
|
|
|
|
PRUint32 childCount;
|
|
|
|
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);
|
|
|
|
flushed = PR_TRUE;
|
|
|
|
}
|
2007-01-30 21:21:06 +00:00
|
|
|
|
2007-04-07 00:20:09 +00:00
|
|
|
mContentStack[stackPos].mNumFlushed = childCount;
|
2007-01-30 21:21:06 +00:00
|
|
|
}
|
2007-04-07 00:20:09 +00:00
|
|
|
mNotifyLevel = stackLen - 1;
|
2007-01-30 21:21:06 +00:00
|
|
|
}
|
|
|
|
--mInNotification;
|
|
|
|
|
2007-05-17 23:54:35 +00:00
|
|
|
if (mUpdatesInNotification > 1) {
|
|
|
|
UpdateChildCounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
mUpdatesInNotification = oldUpdates;
|
2007-03-09 23:43:50 +00:00
|
|
|
mBeganUpdate = oldBeganUpdate;
|
|
|
|
|
2007-01-30 21:21:06 +00: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>.
|
|
|
|
PRInt32 stackLen = mContentStack.Length();
|
|
|
|
PRInt32 stackPos = stackLen - 1;
|
|
|
|
while (stackPos >= 0) {
|
|
|
|
StackNode & node = mContentStack[stackPos];
|
|
|
|
node.mNumFlushed = node.mContent->GetChildCount();
|
|
|
|
|
|
|
|
stackPos--;
|
|
|
|
}
|
|
|
|
mNotifyLevel = stackLen - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsXMLContentSink::IsMonolithicContainer(nsINodeInfo* aNodeInfo)
|
|
|
|
{
|
|
|
|
return ((aNodeInfo->NamespaceID() == kNameSpaceID_XHTML &&
|
|
|
|
(aNodeInfo->NameAtom() == nsGkAtoms::tr ||
|
|
|
|
aNodeInfo->NameAtom() == nsGkAtoms::select ||
|
|
|
|
aNodeInfo->NameAtom() == nsGkAtoms::object ||
|
2011-06-02 11:11:33 +00:00
|
|
|
aNodeInfo->NameAtom() == nsGkAtoms::applet)) ||
|
|
|
|
(aNodeInfo->NamespaceID() == kNameSpaceID_MathML &&
|
2007-01-30 21:21:06 +00:00
|
|
|
(aNodeInfo->NameAtom() == nsGkAtoms::math))
|
|
|
|
);
|
|
|
|
}
|