2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** 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>
|
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 ***** */
|
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 "nsIUnicharInputStream.h"
|
|
|
|
#include "nsIDocument.h"
|
2000-06-17 01:49:19 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMDocumentType.h"
|
|
|
|
#include "nsIDOMDOMImplementation.h"
|
2001-09-21 03:55:50 +00:00
|
|
|
#include "nsIDOMNSDocument.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIXMLContent.h"
|
1999-12-03 09:24:22 +00:00
|
|
|
#include "nsIScriptGlobalObject.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"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsITextContent.h"
|
2001-05-19 02:59:15 +00:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#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"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIHTMLContent.h"
|
2003-10-05 07:29:50 +00:00
|
|
|
#include "nsIDOMHTMLScriptElement.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 "nsVoidArray.h"
|
|
|
|
#include "nsCRT.h"
|
1999-05-26 23:58:06 +00:00
|
|
|
#include "nsICSSLoader.h"
|
1998-11-26 01:34:53 +00:00
|
|
|
#include "nsICSSStyleSheet.h"
|
1998-11-12 23:55:47 +00:00
|
|
|
#include "nsHTMLAtoms.h"
|
2001-02-19 12:55:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
1999-02-18 00:18:50 +00:00
|
|
|
#include "nsLayoutAtoms.h"
|
1998-11-12 23:55:47 +00:00
|
|
|
#include "nsIScriptContext.h"
|
1998-12-11 02:53:49 +00:00
|
|
|
#include "nsINameSpace.h"
|
|
|
|
#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-03-14 07:35:40 +00:00
|
|
|
#include "nsIScrollable.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"
|
2003-10-05 07:29:50 +00:00
|
|
|
#include "nsIScriptLoader.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 "nsIDOMWindowInternal.h"
|
|
|
|
#include "nsIChannel.h"
|
2002-07-02 17:58:24 +00:00
|
|
|
#include "nsIPrincipal.h"
|
2002-09-04 06:57:25 +00:00
|
|
|
#include "nsXBLAtoms.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"
|
1999-02-26 17:13:51 +00:00
|
|
|
|
2003-05-27 03:49:22 +00:00
|
|
|
static const char kNameSpaceSeparator = ':';
|
2001-11-02 10:13:05 +00:00
|
|
|
#define kXSLType "text/xsl"
|
1998-12-27 08:24:04 +00:00
|
|
|
|
2003-05-27 03:49:22 +00:00
|
|
|
static const char kLoadAsData[] = "loadAsData";
|
2002-10-11 00:38:29 +00:00
|
|
|
|
2003-01-14 22:32:18 +00:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
nsXMLContentSink* it;
|
|
|
|
NS_NEWXPCOM(it, nsXMLContentSink);
|
|
|
|
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()
|
2004-01-28 12:14:17 +00:00
|
|
|
: mDocElement(nsnull),
|
|
|
|
mText(nsnull),
|
|
|
|
mTextLength(0),
|
|
|
|
mTextSize(0),
|
|
|
|
mConstrainSize(PR_TRUE),
|
|
|
|
mInTitle(PR_FALSE),
|
|
|
|
mPrettyPrintXML(PR_TRUE),
|
|
|
|
mPrettyPrintHasSpecialRoot(PR_FALSE),
|
|
|
|
mPrettyPrintHasFactoredElements(PR_FALSE),
|
2004-04-20 17:12:48 +00:00
|
|
|
mHasProcessedBase(PR_FALSE),
|
|
|
|
mAllowAutoXLinks(PR_TRUE)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXMLContentSink::~nsXMLContentSink()
|
|
|
|
{
|
2004-01-08 04:25:43 +00:00
|
|
|
NS_ASSERTION(mNameSpaceStack.Count() == 0, "Namespaces left on the stack!");
|
1998-11-11 22:06:16 +00:00
|
|
|
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
|
|
|
|
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;
|
2003-10-05 07:29:50 +00:00
|
|
|
return NS_OK;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 11:28:06 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED4(nsXMLContentSink,
|
2003-10-05 07:29:50 +00:00
|
|
|
nsContentSink,
|
|
|
|
nsIContentSink,
|
|
|
|
nsIXMLContentSink,
|
|
|
|
nsIExpatSink,
|
2003-10-05 11:28:06 +00:00
|
|
|
nsITransformObserver)
|
2003-10-05 07:29:50 +00:00
|
|
|
|
|
|
|
// nsIContentSink
|
(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::WillBuildModel(void)
|
|
|
|
{
|
|
|
|
// 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) {
|
|
|
|
nsAutoString command;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-10-09 07:03:15 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::MaybePrettyPrint()
|
2002-09-04 06:57:25 +00:00
|
|
|
{
|
|
|
|
if (!mPrettyPrintXML || (mPrettyPrintHasFactoredElements &&
|
|
|
|
!mPrettyPrintHasSpecialRoot)) {
|
|
|
|
mPrettyPrintXML = PR_FALSE;
|
|
|
|
|
2002-10-09 07:03:15 +00:00
|
|
|
return NS_OK;
|
2002-09-04 06:57:25 +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);
|
|
|
|
|
2002-10-22 05:28:36 +00:00
|
|
|
return printer->PrettyPrint(mDocument);
|
2002-09-04 06:57:25 +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
|
2003-07-22 18:38:08 +00:00
|
|
|
nsXMLContentSink::DidBuildModel()
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2002-01-07 23:51:36 +00:00
|
|
|
if (mTitleText.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIDOMNSDocument> dom_doc(do_QueryInterface(mDocument));
|
|
|
|
if (dom_doc) {
|
2004-01-29 22:04:45 +00:00
|
|
|
dom_doc->SetTitle(EmptyString());
|
2002-01-07 23:51:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-26 01:10:14 +00:00
|
|
|
if (mXSLTProcessor) {
|
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.
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIScriptLoader *loader = mDocument->GetScriptLoader();
|
2002-06-20 12:04:22 +00:00
|
|
|
if (loader) {
|
|
|
|
loader->RemoveObserver(this);
|
|
|
|
}
|
|
|
|
|
2004-01-09 22:55:13 +00:00
|
|
|
if (mDocElement) {
|
|
|
|
// 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?
|
|
|
|
NS_ASSERTION(mDocument->IndexOf(mDocElement) != -1,
|
|
|
|
"mDocElement not in doc?");
|
2004-01-09 23:54:21 +00:00
|
|
|
|
2004-01-15 03:18:03 +00:00
|
|
|
mozAutoDocUpdate docUpdate(mDocument, UPDATE_CONTENT_MODEL, PR_TRUE);
|
2004-01-09 22:55:13 +00:00
|
|
|
mDocument->ContentInserted(nsnull, mDocElement,
|
|
|
|
// XXXbz is this last arg relevant if
|
|
|
|
// the container is null?
|
|
|
|
mDocument->IndexOf(mDocElement));
|
|
|
|
}
|
|
|
|
|
2003-10-20 19:33:46 +00:00
|
|
|
// Check if we want to prettyprint
|
|
|
|
MaybePrettyPrint();
|
|
|
|
|
2002-04-15 22:53:58 +00:00
|
|
|
StartLayout();
|
|
|
|
|
2002-04-16 22:21:54 +00:00
|
|
|
#if 0 /* Disable until this works for XML */
|
2002-04-15 22:53:58 +00:00
|
|
|
// Scroll to Anchor only if the document was *not* loaded through history means.
|
2003-04-03 18:57:33 +00:00
|
|
|
if (mDocShell) {
|
2002-04-15 22:53:58 +00:00
|
|
|
PRUint32 documentLoadType = 0;
|
2003-04-03 18:57:33 +00:00
|
|
|
mDocShell->GetLoadType(&documentLoadType);
|
2003-03-16 01:12:32 +00:00
|
|
|
ScrollToRef(!(documentLoadType & nsIDocShell::LOAD_CMD_HISTORY));
|
2002-04-04 22:10:10 +00:00
|
|
|
}
|
2002-04-16 22:21:54 +00:00
|
|
|
#else
|
2003-03-14 01:16:31 +00:00
|
|
|
ScrollToRef(PR_TRUE);
|
2002-04-16 22:21:54 +00:00
|
|
|
#endif
|
2002-04-15 22:53:58 +00:00
|
|
|
|
2000-09-02 15:34:07 +00:00
|
|
|
mDocument->EndLoad();
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
1998-12-11 17:02:37 +00:00
|
|
|
// Drop our reference to the parser to get rid of a circular
|
|
|
|
// reference.
|
2003-12-24 13:43:25 +00:00
|
|
|
mParser = nsnull;
|
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
|
|
|
|
nsXMLContentSink::OnDocumentCreated(nsIDOMDocument* aResultDocument)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aResultDocument);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
2003-04-03 18:57:33 +00:00
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
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
|
|
|
if (contentViewer) {
|
|
|
|
contentViewer->SetDOMDocument(aResultDocument);
|
|
|
|
}
|
|
|
|
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,
|
|
|
|
nsIDOMDocument* 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
|
|
|
|
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.
|
|
|
|
if (aResultDocument) {
|
|
|
|
// We have an error document.
|
|
|
|
contentViewer->SetDOMDocument(aResultDocument);
|
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.
|
2003-12-24 13:43:25 +00:00
|
|
|
mDocument = do_QueryInterface(aResultDocument);
|
2002-06-20 12:04:22 +00:00
|
|
|
}
|
2000-09-02 15:34:07 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIScriptLoader *loader = originalDocument->GetScriptLoader();
|
2002-06-20 12:04:22 +00:00
|
|
|
if (loader) {
|
|
|
|
loader->RemoveObserver(this);
|
|
|
|
}
|
|
|
|
|
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?
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIContent *rootContent = mDocument->GetRootContent();
|
2003-10-11 00:27:45 +00:00
|
|
|
if (rootContent) {
|
|
|
|
NS_ASSERTION(mDocument->IndexOf(rootContent) != -1,
|
|
|
|
"rootContent not in doc?");
|
|
|
|
mDocument->BeginUpdate(UPDATE_CONTENT_MODEL);
|
2003-10-20 19:33:46 +00:00
|
|
|
mDocument->ContentInserted(nsnull, rootContent,
|
2003-10-11 00:27:45 +00:00
|
|
|
// XXXbz is this last arg relevant if
|
|
|
|
// the container is null?
|
|
|
|
mDocument->IndexOf(rootContent));
|
|
|
|
mDocument->EndUpdate(UPDATE_CONTENT_MODEL);
|
|
|
|
}
|
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
// Start the layout process
|
|
|
|
StartLayout();
|
2002-04-25 11:58:08 +00:00
|
|
|
|
|
|
|
#if 0 /* Disable until this works for XML */
|
2002-06-20 12:04:22 +00:00
|
|
|
// Scroll to Anchor only if the document was *not* loaded through history means.
|
|
|
|
PRUint32 documentLoadType = 0;
|
|
|
|
docShell->GetLoadType(&documentLoadType);
|
2003-03-16 01:13:23 +00:00
|
|
|
ScrollToRef(!(documentLoadType & nsIDocShell::LOAD_CMD_HISTORY));
|
2002-04-25 11:58:08 +00:00
|
|
|
#else
|
2003-03-14 01:16:31 +00:00
|
|
|
ScrollToRef(PR_TRUE);
|
2002-04-25 11:58:08 +00:00
|
|
|
#endif
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
(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)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
(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)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-11 17:02:37 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::SetParser(nsIParser* aParser)
|
|
|
|
{
|
|
|
|
mParser = aParser;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-16 05:55:04 +00:00
|
|
|
// static
|
|
|
|
void
|
2004-04-29 23:34:19 +00:00
|
|
|
nsXMLContentSink::SplitXMLName(const nsAFlatString& aString, nsIAtom **aPrefix,
|
2001-10-16 05:55:04 +00:00
|
|
|
nsIAtom **aLocalName)
|
1998-12-11 02:53:49 +00:00
|
|
|
{
|
2004-04-29 23:34:19 +00:00
|
|
|
nsAFlatString::const_iterator iter, end;
|
2001-10-16 05:55:04 +00:00
|
|
|
|
|
|
|
aString.BeginReading(iter);
|
|
|
|
aString.EndReading(end);
|
|
|
|
|
|
|
|
FindCharInReadable(kNameSpaceSeparator, iter, end);
|
|
|
|
|
|
|
|
if (iter != end) {
|
|
|
|
nsReadingIterator<PRUnichar> start;
|
|
|
|
|
|
|
|
aString.BeginReading(start);
|
|
|
|
|
|
|
|
*aPrefix = NS_NewAtom(nsDependentSubstring(start, iter));
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
*aLocalName = NS_NewAtom(nsDependentSubstring(iter, end));
|
|
|
|
|
|
|
|
return;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2001-10-16 05:55:04 +00:00
|
|
|
|
|
|
|
*aPrefix = nsnull;
|
|
|
|
*aLocalName = NS_NewAtom(aString);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
nsIContent** aResult, PRBool* aAppendContent)
|
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
|
|
|
|
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(),
|
|
|
|
aNodeInfo);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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 =
|
|
|
|
nsContentUtils::GetNSManagerWeakRef()->
|
|
|
|
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
|
|
|
|
2004-04-12 23:21:42 +00:00
|
|
|
if (aNodeInfo->Equals(nsHTMLAtoms::script, kNameSpaceID_XHTML)) {
|
2002-12-02 23:24:57 +00:00
|
|
|
// Don't append the content to the tree until we're all
|
|
|
|
// done collecting its contents
|
|
|
|
mConstrainSize = PR_FALSE;
|
|
|
|
mScriptLineNo = aLineNumber;
|
|
|
|
*aAppendContent = PR_FALSE;
|
|
|
|
}
|
2004-04-12 23:21:42 +00:00
|
|
|
else if (aNodeInfo->Equals(nsHTMLAtoms::title, kNameSpaceID_XHTML)) {
|
2002-12-02 23:24:57 +00:00
|
|
|
if (mTitleText.IsEmpty()) {
|
|
|
|
mInTitle = PR_TRUE; // The first title wins
|
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2004-04-12 23:21:42 +00:00
|
|
|
else if (aNodeInfo->Equals(nsHTMLAtoms::link, kNameSpaceID_XHTML) ||
|
|
|
|
aNodeInfo->Equals(nsHTMLAtoms::style, kNameSpaceID_XHTML) ||
|
|
|
|
aNodeInfo->Equals(nsHTMLAtoms::style, kNameSpaceID_SVG)) {
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(content));
|
2002-12-02 23:24:57 +00:00
|
|
|
if (ssle) {
|
|
|
|
ssle->InitStyleLinkElement(mParser, PR_FALSE);
|
|
|
|
ssle->SetEnableUpdates(PR_FALSE);
|
|
|
|
}
|
2004-04-12 23:21:42 +00:00
|
|
|
}
|
|
|
|
else if (aNodeInfo->Equals(nsHTMLAtoms::img, kNameSpaceID_XHTML) ||
|
|
|
|
aNodeInfo->Equals(nsHTMLAtoms::input, kNameSpaceID_XHTML) ||
|
|
|
|
aNodeInfo->Equals(nsHTMLAtoms::object, kNameSpaceID_XHTML) ||
|
|
|
|
aNodeInfo->Equals(nsHTMLAtoms::applet, kNameSpaceID_XHTML)) {
|
2003-03-19 03:47:09 +00:00
|
|
|
nsAutoString cmd;
|
|
|
|
if (mParser) {
|
|
|
|
mParser->GetCommand(cmd);
|
|
|
|
}
|
2004-06-26 14:32:11 +00:00
|
|
|
if (cmd.EqualsASCII(kLoadAsData)) {
|
2004-04-12 23:21:42 +00:00
|
|
|
// XXXbz Should this be done to all elements, not just XHTML ones?
|
|
|
|
// We don't have any non-XHTML image loading things yet, but....
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imgLoader(do_QueryInterface(content));
|
2003-03-19 03:47:09 +00:00
|
|
|
if (imgLoader) {
|
|
|
|
imgLoader->SetLoadingEnabled(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
nsXMLContentSink::CloseElement(nsIContent* aContent, PRBool* aAppendContent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent, "missing element to close");
|
|
|
|
|
|
|
|
*aAppendContent = PR_FALSE;
|
2004-04-12 23:21:42 +00:00
|
|
|
|
|
|
|
nsINodeInfo* nodeInfo = aContent->GetNodeInfo();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2004-04-12 23:21:42 +00:00
|
|
|
if (nodeInfo->Equals(nsHTMLAtoms::script, kNameSpaceID_XHTML)) {
|
2002-12-02 23:24:57 +00:00
|
|
|
rv = ProcessEndSCRIPTTag(aContent);
|
|
|
|
*aAppendContent = PR_TRUE;
|
|
|
|
}
|
2004-04-12 23:21:42 +00:00
|
|
|
else if (nodeInfo->Equals(nsHTMLAtoms::title, kNameSpaceID_XHTML) &&
|
|
|
|
mInTitle) {
|
2002-12-02 23:24:57 +00:00
|
|
|
// The first title wins
|
|
|
|
nsCOMPtr<nsIDOMNSDocument> dom_doc(do_QueryInterface(mDocument));
|
|
|
|
if (dom_doc) {
|
|
|
|
mTitleText.CompressWhitespace();
|
|
|
|
dom_doc->SetTitle(mTitleText);
|
|
|
|
}
|
|
|
|
mInTitle = PR_FALSE;
|
|
|
|
}
|
2004-04-12 23:21:42 +00:00
|
|
|
else if (nodeInfo->Equals(nsHTMLAtoms::base, kNameSpaceID_XHTML) &&
|
|
|
|
!mHasProcessedBase) {
|
2002-12-02 23:24:57 +00:00
|
|
|
// The first base wins
|
|
|
|
rv = ProcessBASETag(aContent);
|
|
|
|
mHasProcessedBase = PR_TRUE;
|
|
|
|
}
|
2004-04-20 17:12:48 +00:00
|
|
|
else if (nodeInfo->Equals(nsHTMLAtoms::meta, kNameSpaceID_XHTML) &&
|
|
|
|
// 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);
|
|
|
|
}
|
2004-04-12 23:21:42 +00:00
|
|
|
else if (nodeInfo->Equals(nsHTMLAtoms::link, kNameSpaceID_XHTML) ||
|
|
|
|
nodeInfo->Equals(nsHTMLAtoms::style, kNameSpaceID_XHTML) ||
|
|
|
|
nodeInfo->Equals(nsHTMLAtoms::style, kNameSpaceID_SVG)) {
|
2002-12-02 23:24:57 +00:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aContent));
|
|
|
|
if (ssle) {
|
|
|
|
ssle->SetEnableUpdates(PR_TRUE);
|
2003-01-06 14:55:13 +00:00
|
|
|
rv = ssle->UpdateStyleSheet(nsnull, nsnull);
|
2002-12-03 05:48:14 +00:00
|
|
|
if (rv == NS_ERROR_HTMLPARSER_BLOCK && mParser) {
|
|
|
|
mParser->BlockParser();
|
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)) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc( do_QueryInterface(mDocument) );
|
|
|
|
nsCOMPtr<nsIDOMNode> trash;
|
|
|
|
nsCOMPtr<nsIDOMNode> child( do_QueryInterface(aContent) );
|
|
|
|
NS_ASSERTION(child, "not a dom node");
|
|
|
|
domDoc->AppendChild(child, getter_AddRefs(trash));
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
result = parent->AppendChildTo(aContent, PR_FALSE, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2003-03-26 01:10:14 +00:00
|
|
|
mXSLTProcessor =
|
2003-04-01 19:50:42 +00:00
|
|
|
do_CreateInstance("@mozilla.org/document-transformer;1?type=xslt");
|
2003-03-26 01:10:14 +00:00
|
|
|
if (!mXSLTProcessor) {
|
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
|
|
|
|
2003-03-26 01:10:14 +00:00
|
|
|
mXSLTProcessor->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) {
|
2003-03-26 01:10:14 +00:00
|
|
|
mXSLTProcessor = nsnull;
|
2003-10-22 06:09:48 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2002-09-27 04:22:13 +00:00
|
|
|
}
|
|
|
|
|
2004-04-25 16:55:27 +00:00
|
|
|
return mXSLTProcessor->LoadStyleSheet(aUrl, loadGroup, mDocument->GetPrincipal());
|
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,
|
2003-10-05 07:29:50 +00:00
|
|
|
const nsAString& aHref,
|
2002-01-09 01:37:50 +00:00
|
|
|
PRBool aAlternate,
|
2003-10-05 07:29:50 +00:00
|
|
|
const nsAString& aTitle,
|
|
|
|
const nsAString& aType,
|
|
|
|
const nsAString& 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
|
|
|
|
2002-10-11 00:38:29 +00:00
|
|
|
nsAutoString 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);
|
|
|
|
if (type.EqualsIgnoreCase(kXSLType) ||
|
|
|
|
type.EqualsIgnoreCase(kXMLTextContentType) ||
|
|
|
|
type.EqualsIgnoreCase(kXMLApplicationContentType)) {
|
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;
|
2004-01-09 23:54:21 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(url), aHref, nsnull, mDocumentBaseURI);
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2003-10-30 03:01:25 +00:00
|
|
|
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
|
2004-04-25 16:55:27 +00:00
|
|
|
rv = secMan->
|
|
|
|
CheckLoadURIWithPrincipal(mDocument->GetPrincipal(), url,
|
|
|
|
nsIScriptSecurityManager::ALLOW_CHROME);
|
2002-12-03 09:20:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
rv = secMan->CheckSameOriginURI(mDocumentURI, url);
|
2002-12-03 09:20:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (rv == NS_ERROR_HTMLPARSER_BLOCK) {
|
|
|
|
if (mParser) {
|
2002-12-03 05:48:14 +00:00
|
|
|
mParser->BlockParser();
|
2002-03-27 06:19:14 +00:00
|
|
|
}
|
2003-10-05 07:29:50 +00:00
|
|
|
return NS_OK;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 07:29:50 +00:00
|
|
|
return rv;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2001-11-03 10:12:20 +00:00
|
|
|
nsresult
|
2002-12-02 23:24:57 +00:00
|
|
|
nsXMLContentSink::ProcessBASETag(nsIContent* aContent)
|
2001-11-03 10:12:20 +00:00
|
|
|
{
|
2002-12-02 23:24:57 +00:00
|
|
|
NS_ASSERTION(aContent, "missing base-element");
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (mDocument) {
|
|
|
|
nsAutoString value;
|
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
if (aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::target, value) ==
|
|
|
|
NS_CONTENT_ATTR_HAS_VALUE) {
|
2002-01-09 01:37:50 +00:00
|
|
|
mDocument->SetBaseTarget(value);
|
|
|
|
}
|
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
if (aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::href, value) ==
|
|
|
|
NS_CONTENT_ATTR_HAS_VALUE) {
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(baseURI), value);
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-01-09 23:54:21 +00:00
|
|
|
rv = mDocument->SetBaseURI(baseURI); // The document checks if it is legal to set this base
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-01-09 23:54:21 +00:00
|
|
|
mDocumentBaseURI = mDocument->GetBaseURI();
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-11-03 10:12:20 +00:00
|
|
|
}
|
2003-10-21 22:11:49 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2001-02-03 01:16:20 +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
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRBool didFlush = PR_FALSE;
|
|
|
|
if (0 != mTextLength) {
|
|
|
|
if (aCreateTextNode) {
|
2003-03-26 07:41:30 +00:00
|
|
|
nsCOMPtr<nsITextContent> textContent;
|
|
|
|
rv = NS_NewTextNode(getter_AddRefs(textContent));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-05-17 05:54:16 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
// Set the content's document
|
|
|
|
textContent->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
// Set the text in the text node
|
|
|
|
textContent->SetText(mText, mTextLength, PR_FALSE);
|
|
|
|
|
|
|
|
// Add text to its parent
|
|
|
|
AddContentAsLeaf(textContent);
|
1998-11-16 06:16:17 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
mTextLength = 0;
|
|
|
|
didFlush = PR_TRUE;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2003-03-26 07:41:30 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (nsnull != aDidFlush) {
|
|
|
|
*aDidFlush = didFlush;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
#define NS_ACCUMULATION_BUFFER_SIZE 4096
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsXMLContentSink::GetNameSpaceId(nsIAtom* aPrefix)
|
|
|
|
{
|
|
|
|
PRInt32 id = aPrefix ? kNameSpaceID_Unknown : kNameSpaceID_None;
|
2003-07-03 05:34:26 +00:00
|
|
|
PRInt32 count = mNameSpaceStack.Count();
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2003-07-03 05:34:26 +00:00
|
|
|
if (count > 0) {
|
|
|
|
mNameSpaceStack[count - 1]->FindNameSpaceID(aPrefix, &id);
|
2001-05-17 05:54:16 +00:00
|
|
|
}
|
2001-06-29 09:59:45 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return id;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2003-07-03 05:34:26 +00:00
|
|
|
already_AddRefed<nsINameSpace>
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::PopNameSpaces()
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2003-07-03 05:34:26 +00:00
|
|
|
PRInt32 count = mNameSpaceStack.Count();
|
|
|
|
|
2004-01-08 04:25:43 +00:00
|
|
|
NS_ASSERTION(count > 0, "Bogus Count() or bogus PopNameSpaces call");
|
2003-07-03 05:34:26 +00:00
|
|
|
if (count == 0) {
|
|
|
|
return nsnull;
|
1999-02-26 17:13:51 +00:00
|
|
|
}
|
2003-07-03 05:34:26 +00:00
|
|
|
|
|
|
|
nsINameSpace* nameSpace = mNameSpaceStack[count - 1];
|
|
|
|
NS_ADDREF(nameSpace);
|
|
|
|
mNameSpaceStack.RemoveObjectAt(count - 1);
|
|
|
|
return nameSpace;
|
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
|
|
|
{
|
2003-07-03 05:34:26 +00:00
|
|
|
PRInt32 count = mContentStack.Count();
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
return nsnull;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2003-07-03 05:34:26 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(count > 0, "Bogus Count()");
|
|
|
|
|
|
|
|
return mContentStack[count-1];
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
PRInt32
|
|
|
|
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!");
|
|
|
|
mContentStack.AppendObject(aContent);
|
|
|
|
return mContentStack.Count();
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
|
2003-07-03 05:34:26 +00:00
|
|
|
already_AddRefed<nsIContent>
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::PopContent()
|
|
|
|
{
|
2003-07-03 05:34:26 +00:00
|
|
|
PRInt32 count = mContentStack.Count();
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
NS_WARNING("Popping empty stack");
|
|
|
|
return nsnull;
|
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
|
|
|
|
2003-07-03 05:34:26 +00:00
|
|
|
NS_ASSERTION(count > 0, "Bogus Count()");
|
|
|
|
|
|
|
|
nsIContent* content = mContentStack[count - 1];
|
|
|
|
NS_IF_ADDREF(content);
|
|
|
|
mContentStack.RemoveObjectAt(count - 1);
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXMLContentSink::StartLayout()
|
|
|
|
{
|
|
|
|
// Reset scrolling to default settings for this shell.
|
|
|
|
// This must happen before the initial reflow, when we create the root frame
|
2003-04-03 18:57:33 +00:00
|
|
|
nsCOMPtr<nsIScrollable> scrollableContainer(do_QueryInterface(mDocShell));
|
2002-01-09 01:37:50 +00:00
|
|
|
if (scrollableContainer) {
|
|
|
|
scrollableContainer->ResetScrollbarPreferences();
|
|
|
|
}
|
|
|
|
PRBool topLevelFrameset = PR_FALSE;
|
2003-04-03 18:57:33 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));
|
2002-01-09 01:37:50 +00:00
|
|
|
if (docShellAsItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> root;
|
|
|
|
docShellAsItem->GetSameTypeRootTreeItem(getter_AddRefs(root));
|
2004-01-28 12:14:17 +00:00
|
|
|
if(docShellAsItem == root) {
|
2002-01-09 01:37:50 +00:00
|
|
|
topLevelFrameset = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2004-01-28 12:14:17 +00:00
|
|
|
|
|
|
|
nsContentSink::StartLayout(topLevelFrameset);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-04-04 15:42:45 +00:00
|
|
|
#ifdef MOZ_MATHML
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// MathML Element Factory - temporary location for bug 132844
|
|
|
|
// Will be factored out post 1.0
|
|
|
|
|
|
|
|
nsresult
|
2004-06-25 12:26:02 +00:00
|
|
|
NS_NewMathMLElement(nsIContent** aResult, nsINodeInfo* aNodeInfo)
|
2002-04-04 15:42:45 +00:00
|
|
|
{
|
2003-09-13 17:55:56 +00:00
|
|
|
static const char kMathMLStyleSheetURI[] = "resource://gre/res/mathml.css";
|
2002-04-04 15:42:45 +00:00
|
|
|
|
2003-10-21 16:16:42 +00:00
|
|
|
aNodeInfo->SetIDAttributeAtom(nsHTMLAtoms::id);
|
|
|
|
|
2002-04-04 15:42:45 +00:00
|
|
|
// this bit of code is to load mathml.css on demand
|
2004-06-25 12:26:02 +00:00
|
|
|
nsIDocument* doc = nsContentUtils::GetDocument(aNodeInfo);
|
2002-04-04 15:42:45 +00:00
|
|
|
if (doc) {
|
2004-01-13 23:14:49 +00:00
|
|
|
nsICSSLoader* cssLoader = doc->GetCSSLoader();
|
|
|
|
PRBool enabled;
|
|
|
|
if (cssLoader && NS_SUCCEEDED(cssLoader->GetEnabled(&enabled)) && enabled) {
|
|
|
|
PRBool alreadyLoaded = PR_FALSE;
|
|
|
|
PRInt32 sheetCount = doc->GetNumberOfStyleSheets(PR_TRUE);
|
|
|
|
for (PRInt32 i = 0; i < sheetCount; i++) {
|
|
|
|
nsIStyleSheet* sheet = doc->GetStyleSheetAt(i, PR_TRUE);
|
|
|
|
NS_ASSERTION(sheet, "unexpected null stylesheet in the document");
|
|
|
|
if (sheet) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
sheet->GetURL(*getter_AddRefs(uri));
|
|
|
|
nsCAutoString uriStr;
|
|
|
|
uri->GetSpec(uriStr);
|
|
|
|
if (uriStr.Equals(kMathMLStyleSheetURI)) {
|
|
|
|
alreadyLoaded = PR_TRUE;
|
|
|
|
break;
|
2002-12-16 22:22:12 +00:00
|
|
|
}
|
2002-04-04 15:42:45 +00:00
|
|
|
}
|
2004-01-13 23:14:49 +00:00
|
|
|
}
|
|
|
|
if (!alreadyLoaded) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), kMathMLStyleSheetURI);
|
|
|
|
if (uri) {
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
|
|
|
cssLoader->LoadAgentSheet(uri, getter_AddRefs(sheet));
|
2002-04-04 15:42:45 +00:00
|
|
|
#ifdef NS_DEBUG
|
2004-01-13 23:14:49 +00:00
|
|
|
nsCAutoString uriStr;
|
|
|
|
uri->GetSpec(uriStr);
|
|
|
|
printf("MathML Factory: loading catalog stylesheet: %s ... %s\n", uriStr.get(), sheet.get() ? "Done" : "Failed");
|
|
|
|
NS_ASSERTION(uriStr.Equals(kMathMLStyleSheetURI), "resolved URI unexpected");
|
2002-04-04 15:42:45 +00:00
|
|
|
#endif
|
2004-01-13 23:14:49 +00:00
|
|
|
if (sheet) {
|
|
|
|
doc->BeginUpdate(UPDATE_STYLE);
|
|
|
|
doc->AddStyleSheet(sheet, NS_STYLESHEET_FROM_CATALOG);
|
|
|
|
doc->EndUpdate(UPDATE_STYLE);
|
2002-04-04 15:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NewXMLElement(aResult, aNodeInfo);
|
|
|
|
}
|
|
|
|
#endif // MOZ_MATHML
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::HandleStartElement(const PRUnichar *aName,
|
|
|
|
const PRUnichar **aAtts,
|
2002-01-09 18:15:36 +00:00
|
|
|
PRUint32 aAttsCount,
|
2003-10-30 02:17:50 +00:00
|
|
|
PRInt32 aIndex,
|
2002-01-09 18:15:36 +00:00
|
|
|
PRUint32 aLineNumber)
|
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();
|
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
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIAtom> nameSpacePrefix, tagAtom;
|
2001-02-28 23:51:35 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
SplitXMLName(nsDependentString(aName), getter_AddRefs(nameSpacePrefix),
|
|
|
|
getter_AddRefs(tagAtom));
|
2001-02-28 23:51:35 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// We must register namespace declarations found in the attribute list
|
|
|
|
// of an element before creating the element. This is because the
|
|
|
|
// namespace prefix for an element might be declared within the attribute
|
|
|
|
// list.
|
|
|
|
result = PushNameSpacesFrom(aAtts);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
PRInt32 nameSpaceID = GetNameSpaceId(nameSpacePrefix);
|
|
|
|
|
2004-01-08 04:25:43 +00:00
|
|
|
if (!OnOpenContainer(aAtts, aAttsCount, nameSpaceID, tagAtom, aLineNumber)) {
|
|
|
|
// Pop the namespaces we pushed for this element, since HandleEndElement
|
|
|
|
// won't get called for it.
|
|
|
|
nsINameSpace* nameSpace = PopNameSpaces().get();
|
|
|
|
NS_IF_RELEASE(nameSpace);
|
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;
|
|
|
|
|
|
|
|
mNodeInfoManager->GetNodeInfo(tagAtom, nameSpacePrefix, nameSpaceID,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(nodeInfo));
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
result = CreateElement(aAtts, aAttsCount, nodeInfo, aLineNumber,
|
|
|
|
getter_AddRefs(content), &appendContent);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
content->SetContentID(mDocument->GetAndIncrementContentID());
|
2002-12-02 23:24:57 +00:00
|
|
|
content->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
|
|
|
|
// 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) {
|
2002-12-02 23:24:57 +00:00
|
|
|
// If this is the document element
|
|
|
|
if (!mDocElement) {
|
|
|
|
|
|
|
|
// check for root elements that needs special handling for
|
|
|
|
// prettyprinting
|
|
|
|
if ((nameSpaceID == kNameSpaceID_XBL &&
|
|
|
|
tagAtom == nsXBLAtoms::bindings) ||
|
|
|
|
(nameSpaceID == kNameSpaceID_XSLT &&
|
|
|
|
(tagAtom == nsLayoutAtoms::stylesheet ||
|
|
|
|
tagAtom == nsLayoutAtoms::transform))) {
|
|
|
|
mPrettyPrintHasSpecialRoot = PR_TRUE;
|
2004-04-20 17:12:48 +00:00
|
|
|
if (mPrettyPrintXML) {
|
|
|
|
// In this case, disable script execution, stylesheet
|
|
|
|
// loading, and auto XLinks since we plan to prettyprint.
|
|
|
|
mAllowAutoXLinks = PR_FALSE;
|
|
|
|
nsIScriptLoader* scriptLoader = mDocument->GetScriptLoader();
|
|
|
|
if (scriptLoader) {
|
|
|
|
scriptLoader->SetEnabled(PR_FALSE);
|
|
|
|
}
|
|
|
|
if (mCSSLoader) {
|
|
|
|
mCSSLoader->SetEnabled(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
2002-04-25 11:58:08 +00:00
|
|
|
}
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
mDocElement = content;
|
|
|
|
NS_ADDREF(mDocElement);
|
2002-09-04 06:57:25 +00:00
|
|
|
|
2003-08-05 19:34:04 +00:00
|
|
|
mDocument->SetRootContent(mDocElement);
|
2002-12-02 23:24:57 +00:00
|
|
|
}
|
|
|
|
else if (appendContent) {
|
2003-07-03 05:34:26 +00:00
|
|
|
nsCOMPtr<nsIContent> parent = GetCurrentContent();
|
2002-12-02 23:24:57 +00:00
|
|
|
NS_ENSURE_TRUE(parent, NS_ERROR_UNEXPECTED);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
parent->AppendChildTo(content, PR_FALSE, PR_FALSE);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
PushContent(content);
|
|
|
|
}
|
2002-05-20 22:47:02 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
// Set the ID attribute atom on the node info object for this node
|
2003-10-30 02:17:50 +00:00
|
|
|
if (aIndex != -1 && NS_SUCCEEDED(result)) {
|
2002-12-02 23:24:57 +00:00
|
|
|
nsCOMPtr<nsIAtom> IDAttr = do_GetAtom(aAtts[aIndex]);
|
|
|
|
|
|
|
|
if (IDAttr) {
|
2003-11-15 05:27:37 +00:00
|
|
|
nodeInfo->SetIDAttributeAtom(IDAttr);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2001-04-30 23:35:09 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::HandleEndElement(const PRUnichar *aName)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2002-01-09 01:37:50 +00:00
|
|
|
PRBool appendContent = PR_FALSE;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2003-07-03 05:34:26 +00:00
|
|
|
nsCOMPtr<nsIContent> content = PopContent();
|
2002-12-02 23:24:57 +00:00
|
|
|
NS_ASSERTION(content, "failed to pop content");
|
2001-07-04 19:35:23 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
result = CloseElement(content, &appendContent);
|
2004-01-10 21:43:32 +00:00
|
|
|
|
|
|
|
// Make sure to pop the namespaces no matter whether CloseElement
|
|
|
|
// succeeded.
|
|
|
|
nsINameSpace* nameSpace = PopNameSpaces().get();
|
|
|
|
NS_IF_RELEASE(nameSpace);
|
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
if (mDocElement == content) {
|
|
|
|
mState = eXMLContentSinkState_InEpilog;
|
|
|
|
}
|
|
|
|
else if (appendContent) {
|
2003-07-03 05:34:26 +00:00
|
|
|
nsCOMPtr<nsIContent> parent = GetCurrentContent();
|
2002-12-02 23:24:57 +00:00
|
|
|
NS_ENSURE_TRUE(parent, NS_ERROR_UNEXPECTED);
|
(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-12-02 23:24:57 +00:00
|
|
|
parent->AppendChildTo(content, PR_FALSE, PR_FALSE);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2002-12-02 23:24:57 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (mNeedToBlockParser || (mParser && !mParser->IsParserEnabled())) {
|
|
|
|
if (mParser) mParser->BlockParser();
|
|
|
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
2001-07-04 19:35:23 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
nsresult result = NS_NewCommentNode(getter_AddRefs(comment));
|
|
|
|
if (comment) {
|
|
|
|
nsCOMPtr<nsIDOMComment> domComment = do_QueryInterface(comment, &result);
|
|
|
|
if (domComment) {
|
2002-01-09 01:37:50 +00:00
|
|
|
domComment->AppendData(nsDependentString(aName));
|
|
|
|
comment->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
result = AddContentAsLeaf(comment);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
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
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
FlushText();
|
2000-12-11 22:21:06 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (mInTitle) {
|
|
|
|
mTitleText.Append(aData, aLength);
|
|
|
|
}
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIContent> cdata;
|
|
|
|
nsresult result = NS_NewXMLCDATASection(getter_AddRefs(cdata));
|
|
|
|
if (cdata) {
|
|
|
|
nsCOMPtr<nsIDOMCDATASection> domCDATA = do_QueryInterface(cdata);
|
|
|
|
if (domCDATA) {
|
2002-01-09 01:37:50 +00:00
|
|
|
domCDATA->SetData(nsDependentString(aData, aLength));
|
|
|
|
cdata->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
result = AddContentAsLeaf(cdata);
|
2000-06-17 01:49:19 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
return result;
|
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;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(mDocument));
|
|
|
|
if (!doc)
|
|
|
|
return NS_OK;
|
|
|
|
|
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;
|
|
|
|
rv = NS_NewDOMDocumentType(getter_AddRefs(docType), name, nsnull, nsnull,
|
2002-05-22 00:46:16 +00:00
|
|
|
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) {
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
2002-12-03 05:48:14 +00:00
|
|
|
mCSSLoader->LoadAgentSheet(uri, getter_AddRefs(sheet));
|
|
|
|
|
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);
|
2002-03-15 09:45:31 +00:00
|
|
|
mDocument->AddStyleSheet(sheet, NS_STYLESHEET_FROM_CATALOG);
|
2003-10-02 21:29:40 +00:00
|
|
|
mDocument->EndUpdate(UPDATE_STYLE);
|
2002-03-15 09:45:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-17 01:49:19 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> tmpNode;
|
|
|
|
|
2001-01-04 00:30:11 +00:00
|
|
|
return doc->AppendChild(docType, getter_AddRefs(tmpNode));
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2001-06-29 22:56:58 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::HandleCharacterData(const PRUnichar *aData,
|
|
|
|
PRUint32 aLength)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2003-10-15 20:10:47 +00:00
|
|
|
if (aData && mState != eXMLContentSinkState_InProlog &&
|
|
|
|
mState != eXMLContentSinkState_InEpilog) {
|
|
|
|
return AddText(aData, aLength);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2003-10-15 20:10:47 +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
|
|
|
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
|
|
|
nsresult result = NS_OK;
|
|
|
|
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
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
result = NS_NewXMLProcessingInstruction(getter_AddRefs(node), target, data);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(node));
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (ssle) {
|
|
|
|
ssle->InitStyleLinkElement(mParser, PR_FALSE);
|
|
|
|
ssle->SetEnableUpdates(PR_FALSE);
|
2002-09-04 06:57:25 +00:00
|
|
|
mPrettyPrintXML = PR_FALSE;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
result = AddContentAsLeaf(node);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (ssle) {
|
|
|
|
ssle->SetEnableUpdates(PR_TRUE);
|
2003-01-06 14:55:13 +00:00
|
|
|
result = ssle->UpdateStyleSheet(nsnull, nsnull);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-12-03 05:48:14 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
if (result == NS_ERROR_HTMLPARSER_BLOCK && mParser) {
|
|
|
|
mParser->BlockParser();
|
|
|
|
}
|
|
|
|
return result;
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-05 04:20:54 +00:00
|
|
|
|
2002-04-05 11:29:40 +00:00
|
|
|
// If it's not a CSS stylesheet PI...
|
2002-01-09 01:37:50 +00:00
|
|
|
nsAutoString type;
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("type"), type);
|
|
|
|
if (mState == eXMLContentSinkState_InProlog &&
|
2004-05-22 22:15:22 +00:00
|
|
|
target.EqualsLiteral("xml-stylesheet") &&
|
2004-06-17 00:13:25 +00:00
|
|
|
!type.LowerCaseEqualsLiteral("text/css")) {
|
2002-01-09 01:37:50 +00:00
|
|
|
nsAutoString href, title, media, alternate;
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("href"), href);
|
|
|
|
// If there was no href, we can't do anything with this PI
|
|
|
|
if (href.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("title"), title);
|
|
|
|
title.CompressWhitespace();
|
1999-01-12 16:37:24 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("media"), media);
|
|
|
|
ToLowerCase(media);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("alternate"), alternate);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2004-05-22 22:15:22 +00:00
|
|
|
result = ProcessStyleLink(node, href, alternate.EqualsLiteral("yes"),
|
2002-01-09 01:37:50 +00:00
|
|
|
title, type, media);
|
2000-01-21 01:32:32 +00:00
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
return result;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2002-08-13 18:41:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::HandleXMLDeclaration(const PRUnichar *aData,
|
|
|
|
PRUint32 aLength)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aData);
|
|
|
|
// strlen("<?xml version='a'?>") == 19, shortest decl
|
|
|
|
NS_ENSURE_TRUE(aLength >= 19, NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
// <?xml version="a" encoding="a" standalone="yes|no"?>
|
|
|
|
const nsAString& data = Substring(aData + 6, aData + aLength - 2); // strip out "<?xml " and "?>"
|
|
|
|
|
|
|
|
nsAutoString version, encoding, standalone;
|
|
|
|
|
|
|
|
// XXX If this is too slow we need to parse this here
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("version"), version);
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("encoding"), encoding);
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("standalone"), standalone);
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
mDocument->SetXMLDeclaration(version, encoding, standalone);
|
|
|
|
return NS_OK;
|
2002-08-13 18:41:16 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::ReportError(const PRUnichar* aErrorText,
|
|
|
|
const PRUnichar* aSourceText)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult rv = NS_OK;
|
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;
|
|
|
|
|
2004-04-14 19:31:33 +00:00
|
|
|
// Since we're blowing away all the content we've created up to now,
|
|
|
|
// blow away our namespace stack too.
|
|
|
|
mNameSpaceStack.Clear();
|
|
|
|
|
2002-03-12 22:17:18 +00:00
|
|
|
// Clear the current content and
|
|
|
|
// prepare to set <parsererror> as the document root
|
|
|
|
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mDocument));
|
|
|
|
if (node) {
|
|
|
|
for (;;) {
|
|
|
|
nsCOMPtr<nsIDOMNode> child, dummy;
|
|
|
|
node->GetLastChild(getter_AddRefs(child));
|
|
|
|
if (!child)
|
|
|
|
break;
|
|
|
|
node->RemoveChild(child, getter_AddRefs(dummy));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(mDocElement);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(name, "xmlns");
|
2002-03-12 22:17:18 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(value, "http://www.mozilla.org/newlayout/xml/parsererror.xml");
|
2000-01-21 01:32:32 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
const PRUnichar* atts[] = {name.get(), value.get(), nsnull};
|
|
|
|
|
2003-11-03 09:18:29 +00:00
|
|
|
rv = HandleStartElement(NS_LITERAL_STRING("parsererror").get(), atts, 2,
|
2003-10-30 02:17:50 +00:00
|
|
|
-1, (PRUint32)-1);
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
2000-01-21 00:05:36 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
rv = HandleCharacterData(aErrorText, nsCRT::strlen(aErrorText));
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
2002-03-12 22:17:18 +00:00
|
|
|
const PRUnichar* noAtts[] = {0, 0};
|
2002-05-20 22:47:02 +00:00
|
|
|
rv = HandleStartElement(NS_LITERAL_STRING("sourcetext").get(), noAtts, 0,
|
2003-10-30 02:17:50 +00:00
|
|
|
-1, (PRUint32)-1);
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
|
|
|
rv = HandleCharacterData(aSourceText, nsCRT::strlen(aSourceText));
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
|
|
|
rv = HandleEndElement(NS_LITERAL_STRING("sourcetext").get());
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
|
|
|
rv = HandleEndElement(NS_LITERAL_STRING("parsererror").get());
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
|
|
|
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::PushNameSpacesFrom(const PRUnichar** aAtts)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsINameSpace> nameSpace;
|
|
|
|
nsresult rv = NS_OK;
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2003-07-03 05:34:26 +00:00
|
|
|
if (0 < mNameSpaceStack.Count()) {
|
|
|
|
nameSpace = mNameSpaceStack[mNameSpaceStack.Count() - 1];
|
2002-01-09 01:37:50 +00:00
|
|
|
} else {
|
2003-06-13 20:10:01 +00:00
|
|
|
rv = nsContentUtils::GetNSManagerWeakRef()->
|
|
|
|
CreateRootNameSpace(getter_AddRefs(nameSpace));
|
2002-11-29 23:44:07 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ENSURE_TRUE(nameSpace, NS_ERROR_UNEXPECTED);
|
2000-10-24 01:03:31 +00:00
|
|
|
|
2004-06-11 15:05:29 +00:00
|
|
|
static NS_NAMED_LITERAL_STRING(kNameSpaceDef, "xmlns");
|
2002-01-09 01:37:50 +00:00
|
|
|
static const PRUint32 xmlns_len = kNameSpaceDef.Length();
|
2001-03-21 03:00:18 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
while (*aAtts) {
|
|
|
|
const nsDependentString key(aAtts[0]);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Look for "xmlns" at the start of the attribute name
|
1998-11-12 23:55:47 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
PRUint32 key_len = key.Length();
|
2001-05-17 05:54:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (key_len >= xmlns_len &&
|
|
|
|
nsDependentSubstring(key, 0, xmlns_len).Equals(kNameSpaceDef)) {
|
|
|
|
nsCOMPtr<nsIAtom> prefixAtom;
|
2001-05-17 05:54:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// If key_len > xmlns_len we have a xmlns:foo type attribute,
|
|
|
|
// extract the prefix. If not, we have a xmlns attribute in
|
|
|
|
// which case there is no prefix.
|
(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
|
|
|
if (key_len > xmlns_len) {
|
|
|
|
nsReadingIterator<PRUnichar> start, end;
|
2001-05-17 05:54:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
key.BeginReading(start);
|
|
|
|
key.EndReading(end);
|
1998-12-18 01:36:41 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
start.advance(xmlns_len);
|
1998-12-15 06:10:59 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (*start == ':') {
|
|
|
|
++start;
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
prefixAtom = do_GetAtom(Substring(start, end));
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINameSpace> child;
|
|
|
|
rv = nameSpace->CreateChildNameSpace(prefixAtom, nsDependentString(aAtts[1]),
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(child));
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nameSpace = child;
|
|
|
|
}
|
|
|
|
aAtts += 2;
|
1998-11-12 23:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-03 05:34:26 +00:00
|
|
|
mNameSpaceStack.AppendObject(nameSpace);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
return NS_OK;
|
1998-11-12 23:55:47 +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
|
|
|
|
nsCOMPtr<nsIAtom> nameSpacePrefix, nameAtom;
|
1998-12-18 01:36:41 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
while (*aAtts) {
|
|
|
|
// Get upper-cased key
|
|
|
|
const nsDependentString key(aAtts[0]);
|
2001-02-09 22:36:23 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
SplitXMLName(key, getter_AddRefs(nameSpacePrefix),
|
|
|
|
getter_AddRefs(nameAtom));
|
|
|
|
|
|
|
|
PRInt32 nameSpaceID;
|
|
|
|
|
|
|
|
if (nameSpacePrefix) {
|
|
|
|
nameSpaceID = GetNameSpaceId(nameSpacePrefix);
|
|
|
|
} else {
|
|
|
|
if (nameAtom.get() == nsLayoutAtoms::xmlnsNameSpace)
|
|
|
|
nameSpaceID = kNameSpaceID_XMLNS;
|
|
|
|
else
|
|
|
|
nameSpaceID = kNameSpaceID_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kNameSpaceID_Unknown == nameSpaceID) {
|
|
|
|
nameSpaceID = kNameSpaceID_None;
|
2002-12-11 14:24:49 +00:00
|
|
|
nameAtom = do_GetAtom(key);
|
2002-01-09 01:37:50 +00:00
|
|
|
nameSpacePrefix = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add attribute to content
|
2004-01-15 17:07:27 +00:00
|
|
|
aContent->SetAttr(nameSpaceID, nameAtom, nameSpacePrefix,
|
|
|
|
nsDependentString(aAtts[1]), PR_FALSE);
|
2002-01-09 01:37:50 +00:00
|
|
|
aAtts += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Give autoloading links a chance to fire
|
2004-04-20 17:12:48 +00:00
|
|
|
if (mDocShell && mAllowAutoXLinks) {
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIXMLContent> xmlcontent(do_QueryInterface(aContent));
|
|
|
|
if (xmlcontent) {
|
2003-04-03 18:57:33 +00:00
|
|
|
nsresult rv = xmlcontent->MaybeTriggerAutoLink(mDocShell);
|
2002-01-09 01:37:50 +00:00
|
|
|
if (rv == NS_XML_AUTOLINK_REPLACE ||
|
|
|
|
rv == NS_XML_AUTOLINK_UNDEFINED) {
|
|
|
|
// If we do not terminate the parse, we just keep generating link trigger
|
|
|
|
// events. We want to parse only up to the first replace link, and stop.
|
|
|
|
mParser->Terminate();
|
|
|
|
}
|
|
|
|
}
|
2001-05-17 05:54:16 +00:00
|
|
|
}
|
1998-12-18 01:36:41 +00:00
|
|
|
|
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
|
|
|
if (mInTitle) {
|
|
|
|
mTitleText.Append(aText,aLength);
|
|
|
|
}
|
1999-05-13 20:27: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;
|
|
|
|
}
|
|
|
|
|
2002-03-23 22:46:13 +00:00
|
|
|
const nsAString& str = Substring(aText, aText+aLength);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
// Copy data from string into our buffer; flush buffer when it fills up
|
|
|
|
PRInt32 offset = 0;
|
|
|
|
PRBool isLastCharCR = PR_FALSE;
|
|
|
|
while (0 != aLength) {
|
|
|
|
PRInt32 amount = mTextSize - mTextLength;
|
|
|
|
if (amount > aLength) {
|
|
|
|
amount = aLength;
|
|
|
|
}
|
|
|
|
if (0 == amount) {
|
|
|
|
if (mConstrainSize) {
|
|
|
|
nsresult rv = FlushText();
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mTextSize += aLength;
|
|
|
|
mText = (PRUnichar *) PR_REALLOC(mText, sizeof(PRUnichar) * mTextSize);
|
|
|
|
if (nsnull == mText) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-13 20:27:47 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
mTextLength +=
|
|
|
|
nsContentUtils::CopyNewlineNormalizedUnicodeTo(str,
|
|
|
|
offset,
|
|
|
|
&mText[mTextLength],
|
|
|
|
amount,
|
|
|
|
isLastCharCR);
|
|
|
|
offset += amount;
|
|
|
|
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;
|
|
|
|
}
|
1999-10-05 00:12:21 +00:00
|
|
|
|
|
|
|
nsresult
|
2002-12-02 23:24:57 +00:00
|
|
|
nsXMLContentSink::ProcessEndSCRIPTTag(nsIContent* aContent)
|
1999-10-05 00:12:21 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult result = NS_OK;
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLScriptElement> scriptElement(do_QueryInterface(aContent));
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ASSERTION(scriptElement, "null script element in XML content sink");
|
2003-12-24 13:43:25 +00:00
|
|
|
mScriptElements.AppendObject(scriptElement);
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
nsCOMPtr<nsIScriptElement> sele(do_QueryInterface(aContent));
|
2002-01-09 01:37:50 +00:00
|
|
|
if (sele) {
|
|
|
|
sele->SetLineNumber(mScriptLineNo);
|
|
|
|
}
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
mConstrainSize = PR_TRUE;
|
|
|
|
// Assume that we're going to block the parser with a script load.
|
|
|
|
// If it's an inline script, we'll be told otherwise in the call
|
|
|
|
// to our ScriptAvailable method.
|
|
|
|
mNeedToBlockParser = PR_TRUE;
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return result;
|
1999-10-05 00:12:21 +00:00
|
|
|
}
|