2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-11-11 22:06:16 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
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.
|
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
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
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** 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"
|
2000-01-19 03:10:45 +00:00
|
|
|
#include "nsIElementFactory.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"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIURL.h"
|
2001-04-30 23:35:09 +00:00
|
|
|
#include "nsIRefreshURI.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.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"
|
(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"
|
1999-05-26 23:58:06 +00:00
|
|
|
#include "nsIHTMLContentContainer.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"
|
2001-02-19 12:55:42 +00:00
|
|
|
#include "nsContentCID.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"
|
(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 "jsapi.h" // for JSVERSION_* and JS_VersionToString
|
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"
|
1999-06-28 14:49:29 +00:00
|
|
|
#include "nsParserCIID.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"
|
2001-05-19 02:59:15 +00:00
|
|
|
#include "nsStyleLinkElement.h"
|
2003-03-19 03:47:09 +00:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2001-08-01 23:04:32 +00:00
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsICharsetConverterManager.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"
|
|
|
|
#include "nsIHttpChannel.h"
|
2002-07-02 17:58:24 +00:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIAggregatePrincipal.h"
|
|
|
|
#include "nsICodebasePrincipal.h"
|
2002-09-04 06:57:25 +00:00
|
|
|
#include "nsXBLAtoms.h"
|
2002-10-22 05:28:36 +00:00
|
|
|
#include "nsXMLPrettyPrinter.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
|
1999-02-26 17:13:51 +00:00
|
|
|
// XXX misnamed header file, but oh well
|
(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 "nsHTMLTokens.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
|
|
|
|
2002-10-09 07:03:15 +00:00
|
|
|
static NS_DEFINE_CID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2003-01-14 22:32:18 +00:00
|
|
|
class nsScriptLoaderObserverProxy : public nsIScriptLoaderObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsScriptLoaderObserverProxy(nsIScriptLoaderObserver* aInner)
|
|
|
|
: mInner(do_GetWeakReference(aInner))
|
|
|
|
{
|
|
|
|
}
|
2003-03-14 01:16:31 +00:00
|
|
|
virtual ~nsScriptLoaderObserverProxy()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-01-14 22:32:18 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISCRIPTLOADEROBSERVER
|
|
|
|
|
|
|
|
nsWeakPtr mInner;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsScriptLoaderObserverProxy, nsIScriptLoaderObserver);
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptLoaderObserverProxy::ScriptAvailable(nsresult aResult,
|
|
|
|
nsIDOMHTMLScriptElement *aElement,
|
|
|
|
PRBool aIsInline,
|
|
|
|
PRBool aWasPending,
|
|
|
|
nsIURI *aURI,
|
|
|
|
PRInt32 aLineNo,
|
|
|
|
const nsAString & aScript)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScriptLoaderObserver> inner = do_QueryReferent(mInner);
|
|
|
|
|
|
|
|
if (inner) {
|
|
|
|
return inner->ScriptAvailable(aResult, aElement, aIsInline, aWasPending,
|
|
|
|
aURI, aLineNo, aScript);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScriptLoaderObserverProxy::ScriptEvaluated(nsresult aResult,
|
|
|
|
nsIDOMHTMLScriptElement *aElement,
|
|
|
|
PRBool aIsInline,
|
|
|
|
PRBool aWasPending)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScriptLoaderObserver> inner = do_QueryReferent(mInner);
|
|
|
|
|
|
|
|
if (inner) {
|
|
|
|
return inner->ScriptEvaluated(aResult, aElement, aIsInline, aWasPending);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL,
|
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;
|
2003-04-03 18:57:33 +00:00
|
|
|
nsresult rv = it->Init(aDoc, aURL, 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()
|
|
|
|
{
|
2000-01-19 04:44:10 +00:00
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
mDocument = nsnull;
|
|
|
|
mDocumentURL = nsnull;
|
1999-05-26 23:58:06 +00:00
|
|
|
mDocumentBaseURL = nsnull;
|
1998-12-11 17:02:37 +00:00
|
|
|
mParser = nsnull;
|
1998-11-11 22:06:16 +00:00
|
|
|
mDocElement = nsnull;
|
|
|
|
mContentStack = nsnull;
|
1998-12-11 02:53:49 +00:00
|
|
|
mNameSpaceStack = nsnull;
|
1998-11-11 22:06:16 +00:00
|
|
|
mText = nsnull;
|
|
|
|
mTextLength = 0;
|
|
|
|
mTextSize = 0;
|
1998-11-12 23:55:47 +00:00
|
|
|
mConstrainSize = PR_TRUE;
|
2001-02-03 01:16:20 +00:00
|
|
|
mInTitle = PR_FALSE;
|
1999-05-26 23:58:06 +00:00
|
|
|
mCSSLoader = nsnull;
|
2001-05-17 05:54:16 +00:00
|
|
|
mNeedToBlockParser = PR_FALSE;
|
2002-09-04 06:57:25 +00:00
|
|
|
mPrettyPrintXML = PR_TRUE;
|
|
|
|
mPrettyPrintHasSpecialRoot = PR_FALSE;
|
|
|
|
mPrettyPrintHasFactoredElements = PR_FALSE;
|
2002-12-02 23:24:57 +00:00
|
|
|
mHasProcessedBase = PR_FALSE;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXMLContentSink::~nsXMLContentSink()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mDocument);
|
|
|
|
NS_IF_RELEASE(mDocumentURL);
|
1999-05-26 23:58:06 +00:00
|
|
|
NS_IF_RELEASE(mDocumentBaseURL);
|
1998-12-11 17:02:37 +00:00
|
|
|
NS_IF_RELEASE(mParser);
|
1998-11-11 22:06:16 +00:00
|
|
|
NS_IF_RELEASE(mDocElement);
|
1998-12-11 02:53:49 +00:00
|
|
|
if (nsnull != mNameSpaceStack) {
|
|
|
|
// There shouldn't be any here except in an error condition
|
|
|
|
PRInt32 index = mNameSpaceStack->Count();
|
|
|
|
while (0 < index--) {
|
|
|
|
nsINameSpace* nameSpace = (nsINameSpace*)mNameSpaceStack->ElementAt(index);
|
|
|
|
NS_RELEASE(nameSpace);
|
|
|
|
}
|
|
|
|
delete mNameSpaceStack;
|
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
if (nsnull != mText) {
|
1998-11-12 23:55:47 +00:00
|
|
|
PR_FREEIF(mText);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
1999-05-26 23:58:06 +00:00
|
|
|
NS_IF_RELEASE(mCSSLoader);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::Init(nsIDocument* aDoc,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL,
|
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 != aDoc, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != aURL, "null ptr");
|
2000-01-12 10:33:00 +00:00
|
|
|
if ((nsnull == aDoc) || (nsnull == aURL)) {
|
1998-11-11 22:06:16 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocument = aDoc;
|
|
|
|
NS_ADDREF(aDoc);
|
|
|
|
mDocumentURL = aURL;
|
|
|
|
NS_ADDREF(aURL);
|
1999-05-26 23:58:06 +00:00
|
|
|
mDocumentBaseURL = aURL;
|
|
|
|
NS_ADDREF(aURL);
|
2003-04-03 18:57:33 +00:00
|
|
|
mDocShell = do_QueryInterface(aContainer);
|
|
|
|
if (!mDocShell) {
|
2002-09-04 06:57:25 +00:00
|
|
|
mPrettyPrintXML = PR_FALSE;
|
|
|
|
}
|
2003-01-14 22:32:18 +00:00
|
|
|
|
|
|
|
// use this to avoid a circular reference sink->document->scriptloader->sink
|
|
|
|
nsCOMPtr<nsIScriptLoaderObserver> proxy =
|
|
|
|
new nsScriptLoaderObserverProxy(this);
|
|
|
|
NS_ENSURE_TRUE(proxy, NS_ERROR_OUT_OF_MEMORY);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
nsCOMPtr<nsIScriptLoader> loader;
|
|
|
|
nsresult rv = mDocument->GetScriptLoader(getter_AddRefs(loader));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-01-14 22:32:18 +00:00
|
|
|
loader->AddObserver(proxy);
|
2001-05-17 05:54:16 +00:00
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
mState = eXMLContentSinkState_InProlog;
|
|
|
|
mDocElement = nsnull;
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIHTMLContentContainer> htmlContainer = do_QueryInterface(aDoc);
|
|
|
|
if (htmlContainer) {
|
1999-05-26 23:58:06 +00:00
|
|
|
htmlContainer->GetCSSLoader(mCSSLoader);
|
|
|
|
}
|
|
|
|
|
2002-03-27 06:19:14 +00:00
|
|
|
ProcessHTTPHeaders(aChannel);
|
|
|
|
|
2003-06-13 20:10:01 +00:00
|
|
|
return aDoc->GetNodeInfoManager(getter_AddRefs(mNodeInfoManager));
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
1999-06-28 14:49:29 +00:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsXMLContentSink)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsXMLContentSink)
|
1999-12-07 14:06:36 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsXMLContentSink)
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXMLContentSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentSink)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIExpatSink)
|
2002-06-20 12:04:22 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITransformObserver)
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptLoaderObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXMLContentSink)
|
1999-12-07 14:06:36 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
1998-11-11 22:06:16 +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();
|
1999-07-14 17:59:19 +00:00
|
|
|
return NS_OK;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2001-08-01 23:04:32 +00:00
|
|
|
// This function's implementation is in nsHTMLContentSink.cpp
|
2003-06-11 18:16:03 +00:00
|
|
|
nsresult
|
|
|
|
CharsetConvRef(const nsCString& aDocCharset, const nsCString& aRefInDocCharset,
|
|
|
|
nsString& aRefInUnicode);
|
2001-08-01 23:04:32 +00:00
|
|
|
|
2000-10-24 01:03:31 +00:00
|
|
|
void
|
2003-03-14 01:16:31 +00:00
|
|
|
nsXMLContentSink::ScrollToRef(PRBool aReallyScroll)
|
2000-10-24 01:03:31 +00:00
|
|
|
{
|
2001-08-01 23:04:32 +00:00
|
|
|
// XXX Duplicate code in nsHTMLContentSink.
|
|
|
|
// XXX Be sure to change both places if you make changes here.
|
|
|
|
if (!mRef.IsEmpty()) {
|
2001-09-29 08:28:41 +00:00
|
|
|
char* tmpstr = ToNewCString(mRef);
|
2001-08-01 23:04:32 +00:00
|
|
|
if(! tmpstr)
|
|
|
|
return;
|
|
|
|
nsUnescape(tmpstr);
|
|
|
|
nsCAutoString unescapedRef;
|
|
|
|
unescapedRef.Assign(tmpstr);
|
|
|
|
nsMemory::Free(tmpstr);
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
// We assume that the bytes are in UTF-8, as it says in the spec:
|
|
|
|
// http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1
|
2003-06-11 18:16:03 +00:00
|
|
|
NS_ConvertUTF8toUCS2 ref(unescapedRef);
|
2001-08-01 23:04:32 +00:00
|
|
|
|
2000-10-24 01:03:31 +00:00
|
|
|
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mDocument->GetShellAt(i, getter_AddRefs(shell));
|
2000-10-24 01:03:31 +00:00
|
|
|
if (shell) {
|
|
|
|
// Scroll to the anchor
|
2003-03-18 04:09:24 +00:00
|
|
|
if (aReallyScroll) {
|
|
|
|
shell->FlushPendingNotifications(PR_FALSE);
|
|
|
|
}
|
2001-08-01 23:04:32 +00:00
|
|
|
|
|
|
|
// Check an empty string which might be caused by the UTF-8 conversion
|
|
|
|
if (!ref.IsEmpty())
|
2003-03-14 01:16:31 +00:00
|
|
|
rv = shell->GoToAnchor(ref, aReallyScroll);
|
2001-08-01 23:04:32 +00:00
|
|
|
else
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// If UTF-8 URL failed then try to assume the string as a
|
|
|
|
// document's charset.
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsAutoString docCharset;
|
|
|
|
rv = mDocument->GetDocumentCharacterSet(docCharset);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2003-06-11 18:16:03 +00:00
|
|
|
rv = CharsetConvRef(NS_LossyConvertUCS2toASCII(docCharset),
|
|
|
|
unescapedRef, ref);
|
2001-08-01 23:04:32 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && !ref.IsEmpty())
|
2003-03-14 01:16:31 +00:00
|
|
|
rv = shell->GoToAnchor(ref, aReallyScroll);
|
2001-08-01 23:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-24 01:03:31 +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
|
|
|
}
|
|
|
|
|
2002-10-22 05:28:36 +00:00
|
|
|
// Check for correct load-command
|
2002-09-04 06:57:25 +00:00
|
|
|
nsAutoString command;
|
|
|
|
mParser->GetCommand(command);
|
2002-10-22 05:28:36 +00:00
|
|
|
if (!command.Equals(NS_LITERAL_STRING("view"))) {
|
2002-09-04 06:57:25 +00:00
|
|
|
mPrettyPrintXML = PR_FALSE;
|
|
|
|
|
2002-10-09 07:03:15 +00:00
|
|
|
return NS_OK;
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
|
|
|
|
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
|
1998-11-11 22:06:16 +00:00
|
|
|
nsXMLContentSink::DidBuildModel(PRInt32 aQualityLevel)
|
|
|
|
{
|
|
|
|
// XXX this is silly; who cares?
|
|
|
|
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mDocument->GetShellAt(i, getter_AddRefs(shell));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (shell) {
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
1998-11-11 22:06:16 +00:00
|
|
|
if(vm) {
|
|
|
|
vm->SetQuality(nsContentQuality(aQualityLevel));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-07 23:51:36 +00:00
|
|
|
if (mTitleText.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIDOMNSDocument> dom_doc(do_QueryInterface(mDocument));
|
|
|
|
if (dom_doc) {
|
|
|
|
dom_doc->SetTitle(NS_LITERAL_STRING(""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-02 15:34:07 +00:00
|
|
|
mDocument->SetRootContent(mDocElement);
|
|
|
|
|
2002-09-04 06:57:25 +00:00
|
|
|
// Check if we want to prettyprint
|
2002-10-09 07:03:15 +00:00
|
|
|
MaybePrettyPrint();
|
2002-09-04 06:57:25 +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.
|
2002-06-20 12:04:22 +00:00
|
|
|
nsCOMPtr<nsIScriptLoader> loader;
|
|
|
|
mDocument->GetScriptLoader(getter_AddRefs(loader));
|
|
|
|
if (loader) {
|
|
|
|
loader->RemoveObserver(this);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-08-31 00:59:19 +00:00
|
|
|
// Ref. Bug 49115
|
|
|
|
// Do this hack to make sure that the parser
|
|
|
|
// doesn't get destroyed, accidently, before
|
|
|
|
// the circularity, between sink & parser, is
|
2002-06-20 12:04:22 +00:00
|
|
|
// actually broken.
|
2001-08-31 00:59:19 +00:00
|
|
|
nsCOMPtr<nsIParser> kungFuDeathGrip(mParser);
|
|
|
|
|
1998-12-11 17:02:37 +00:00
|
|
|
// Drop our reference to the parser to get rid of a circular
|
|
|
|
// reference.
|
|
|
|
NS_IF_RELEASE(mParser);
|
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.
|
|
|
|
NS_RELEASE(mDocument);
|
|
|
|
CallQueryInterface(aResultDocument, &mDocument); // addrefs
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Transform failed and we don't have an error document, display the
|
|
|
|
// untransformed source document.
|
|
|
|
mDocument->SetRootContent(mDocElement);
|
|
|
|
}
|
2000-09-02 15:34:07 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
nsCOMPtr<nsIScriptLoader> loader;
|
|
|
|
originalDocument->GetScriptLoader(getter_AddRefs(loader));
|
|
|
|
if (loader) {
|
|
|
|
loader->RemoveObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mParser);
|
|
|
|
mParser = aParser;
|
|
|
|
NS_IF_ADDREF(mParser);
|
(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
|
|
|
|
1998-12-11 17:02:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-16 05:55:04 +00:00
|
|
|
// static
|
|
|
|
void
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXMLContentSink::SplitXMLName(const nsAString& aString, nsIAtom **aPrefix,
|
2001-10-16 05:55:04 +00:00
|
|
|
nsIAtom **aLocalName)
|
1998-12-11 02:53:49 +00:00
|
|
|
{
|
2001-10-16 05:55:04 +00:00
|
|
|
nsReadingIterator<PRUnichar> iter, end;
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
*aAppendContent = PR_TRUE;
|
2002-09-04 06:57:25 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-12-02 23:24:57 +00:00
|
|
|
|
2003-06-13 20:10:01 +00:00
|
|
|
PRInt32 nameSpaceID = aNodeInfo->GetNamespaceID();
|
2002-12-02 23:24:57 +00:00
|
|
|
|
|
|
|
// XHTML needs some special attention
|
|
|
|
if (nameSpaceID != kNameSpaceID_XHTML) {
|
|
|
|
// The first step here is to see if someone has provided their
|
|
|
|
// own content element implementation (e.g., XUL or MathML).
|
|
|
|
// This is done based off a contractid/namespace scheme.
|
|
|
|
nsCOMPtr<nsIElementFactory> elementFactory;
|
|
|
|
rv = nsContentUtils::GetNSManagerWeakRef()->
|
|
|
|
GetElementFactory(nameSpaceID, getter_AddRefs(elementFactory));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
elementFactory->CreateInstanceByTag(aNodeInfo, aResult);
|
2002-12-02 23:24:57 +00:00
|
|
|
|
|
|
|
// If we care, find out if we just used a special factory.
|
|
|
|
if (!mPrettyPrintHasFactoredElements && !mPrettyPrintHasSpecialRoot &&
|
|
|
|
mPrettyPrintXML) {
|
|
|
|
PRBool hasFactory = PR_FALSE;
|
|
|
|
rv = nsContentUtils::GetNSManagerWeakRef()->HasRegisteredFactory(nameSpaceID, &hasFactory);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mPrettyPrintHasFactoredElements = hasFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
2002-12-02 23:24:57 +00:00
|
|
|
|
|
|
|
mPrettyPrintHasFactoredElements = PR_TRUE;
|
|
|
|
nsCOMPtr<nsIHTMLContent> htmlContent;
|
|
|
|
rv = NS_CreateHTMLElement(getter_AddRefs(htmlContent), aNodeInfo, PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = CallQueryInterface(htmlContent, aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-06-13 20:10:01 +00:00
|
|
|
nsCOMPtr<nsIAtom> tagAtom = aNodeInfo->GetNameAtom();
|
2002-12-02 23:24:57 +00:00
|
|
|
if (tagAtom == nsHTMLAtoms::script) {
|
|
|
|
// Don't append the content to the tree until we're all
|
|
|
|
// done collecting its contents
|
|
|
|
mConstrainSize = PR_FALSE;
|
|
|
|
mScriptLineNo = aLineNumber;
|
|
|
|
*aAppendContent = PR_FALSE;
|
|
|
|
}
|
|
|
|
else if (tagAtom == nsHTMLAtoms::title) {
|
|
|
|
if (mTitleText.IsEmpty()) {
|
|
|
|
mInTitle = PR_TRUE; // The first title wins
|
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2002-12-02 23:24:57 +00:00
|
|
|
else if (tagAtom == nsHTMLAtoms::link || tagAtom == nsHTMLAtoms::style) {
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(htmlContent));
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
if (ssle) {
|
|
|
|
ssle->InitStyleLinkElement(mParser, PR_FALSE);
|
|
|
|
ssle->SetEnableUpdates(PR_FALSE);
|
|
|
|
}
|
2003-03-19 03:47:09 +00:00
|
|
|
} else if (tagAtom == nsHTMLAtoms::img ||
|
|
|
|
tagAtom == nsHTMLAtoms::input ||
|
|
|
|
tagAtom == nsHTMLAtoms::object ||
|
|
|
|
tagAtom == nsHTMLAtoms::applet) {
|
|
|
|
nsAutoString cmd;
|
|
|
|
if (mParser) {
|
|
|
|
mParser->GetCommand(cmd);
|
|
|
|
}
|
|
|
|
if (cmd.EqualsWithConversion(kLoadAsData)) {
|
|
|
|
// XXXbz Should this be in HandleStartElement so it applies to all
|
|
|
|
// elements, not just XHTML ones? We don't have any non-XHTML
|
|
|
|
// image loading things yet, but....
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imgLoader(do_QueryInterface(htmlContent));
|
|
|
|
if (imgLoader) {
|
|
|
|
imgLoader->SetLoadingEnabled(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
2002-09-04 06:57:25 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (!aContent->IsContentOfType(nsIContent::eHTML)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> tagAtom;
|
2003-06-13 20:10:01 +00:00
|
|
|
aContent->GetTag(getter_AddRefs(tagAtom));
|
2002-12-02 23:24:57 +00:00
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (tagAtom == nsHTMLAtoms::script) {
|
|
|
|
rv = ProcessEndSCRIPTTag(aContent);
|
|
|
|
*aAppendContent = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (tagAtom == nsHTMLAtoms::title && mInTitle) {
|
|
|
|
// The first title wins
|
|
|
|
nsCOMPtr<nsIDOMNSDocument> dom_doc(do_QueryInterface(mDocument));
|
|
|
|
if (dom_doc) {
|
|
|
|
mTitleText.CompressWhitespace();
|
|
|
|
dom_doc->SetTitle(mTitleText);
|
|
|
|
}
|
|
|
|
mInTitle = PR_FALSE;
|
|
|
|
}
|
|
|
|
else if (tagAtom == nsHTMLAtoms::base && !mHasProcessedBase) {
|
|
|
|
// The first base wins
|
|
|
|
rv = ProcessBASETag(aContent);
|
|
|
|
mHasProcessedBase = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (tagAtom == nsHTMLAtoms::meta) {
|
|
|
|
rv = ProcessMETATag(aContent);
|
|
|
|
}
|
|
|
|
else if (tagAtom == nsHTMLAtoms::link || tagAtom == nsHTMLAtoms::style) {
|
|
|
|
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 {
|
|
|
|
nsCOMPtr<nsIContent> parent = getter_AddRefs(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
|
|
|
|
// the XSL stylesheet located at the given URL.
|
|
|
|
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
|
|
|
|
2002-10-22 20:09:13 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2003-03-26 01:10:14 +00:00
|
|
|
nsresult rv = mDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mXSLTProcessor = nsnull;
|
|
|
|
return rv;
|
2002-09-27 04:22:13 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 01:10:14 +00:00
|
|
|
return mXSLTProcessor->LoadStyleSheet(aUrl, loadGroup, mDocumentURL);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-03-02 21:11:39 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
|
|
|
|
const nsString& aHref,
|
|
|
|
PRBool aAlternate,
|
|
|
|
const nsString& aTitle,
|
|
|
|
const nsString& aType,
|
|
|
|
const nsString& aMedia)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
if (cmd.EqualsWithConversion(kLoadAsData))
|
|
|
|
return NS_OK; // Do not load stylesheets when loading as data
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (aType.EqualsIgnoreCase(kXSLType) ||
|
|
|
|
aType.EqualsIgnoreCase(kXMLTextContentType) ||
|
|
|
|
aType.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;
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(url), aHref, nsnull, mDocumentBaseURL);
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2003-03-26 01:10:14 +00:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> secMan =
|
2002-01-09 01:37:50 +00:00
|
|
|
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
2002-12-03 09:20:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
rv = secMan->CheckLoadURI(mDocumentURL, url,
|
|
|
|
nsIScriptSecurityManager::ALLOW_CHROME);
|
2002-12-03 09:20:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
|
|
|
|
|
|
|
rv = secMan->CheckSameOriginURI(mDocumentURL, url);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
|
|
|
|
|
|
|
return LoadXSLStyleSheet(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aType.Equals(NS_LITERAL_STRING("text/css"))) {
|
2002-03-27 06:19:14 +00:00
|
|
|
nsCOMPtr<nsIURI> url;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(url), aHref, nsnull, mDocumentBaseURL);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_OK; // The URL is bad, move along, don't propagate the error (for now)
|
|
|
|
}
|
|
|
|
PRBool doneLoading;
|
|
|
|
rv = mCSSLoader->LoadStyleLink(aElement, url, aTitle, aMedia, kNameSpaceID_Unknown,
|
|
|
|
((!aAlternate) ? mParser : nsnull),
|
|
|
|
doneLoading,
|
|
|
|
this);
|
2002-12-03 05:48:14 +00:00
|
|
|
// XXX should probably use kBlockByDefault here, no?
|
|
|
|
if (NS_SUCCEEDED(rv) && !doneLoading && !aAlternate && mParser) {
|
|
|
|
mParser->BlockParser();
|
2002-03-27 06:19:14 +00:00
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::StyleSheetLoaded(nsICSSStyleSheet* aSheet,
|
|
|
|
PRBool aDidNotify)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
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)) {
|
|
|
|
rv = mDocument->SetBaseURL(baseURI); // The document checks if it is legal to set this base
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
NS_IF_RELEASE(mDocumentBaseURL);
|
2003-06-13 20:10:01 +00:00
|
|
|
mDocument->GetBaseURL(&mDocumentBaseURL);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-11-03 10:12:20 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return rv;
|
2001-11-03 10:12:20 +00:00
|
|
|
}
|
|
|
|
|
2002-03-27 11:01:09 +00:00
|
|
|
static PRBool IsAlternateHTTPStyleSheetHeader(const nsAString& aRel)
|
2002-03-27 06:19:14 +00:00
|
|
|
{
|
|
|
|
nsStringArray linkTypes;
|
|
|
|
nsStyleLinkElement::ParseLinkTypes(aRel, linkTypes);
|
|
|
|
if (-1 != linkTypes.IndexOf(NS_LITERAL_STRING("stylesheet"))) { // is it a stylesheet link?
|
|
|
|
|
|
|
|
if (-1 != linkTypes.IndexOf(NS_LITERAL_STRING("alternate"))) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Copied from HTML, should be shared
|
|
|
|
static const PRUnichar kSemiCh = PRUnichar(';');
|
|
|
|
static const PRUnichar kCommaCh = PRUnichar(',');
|
|
|
|
static const PRUnichar kEqualsCh = PRUnichar('=');
|
|
|
|
static const PRUnichar kLessThanCh = PRUnichar('<');
|
|
|
|
static const PRUnichar kGreaterThanCh = PRUnichar('>');
|
|
|
|
|
|
|
|
nsresult
|
2002-12-02 23:24:57 +00:00
|
|
|
nsXMLContentSink::ProcessLink(nsIContent* aElement,
|
2002-03-27 06:19:14 +00:00
|
|
|
const nsAString& aLinkData)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
// parse link content and call process style link
|
|
|
|
nsAutoString href;
|
|
|
|
nsAutoString rel;
|
|
|
|
nsAutoString title;
|
|
|
|
nsAutoString type;
|
|
|
|
nsAutoString media;
|
|
|
|
PRBool didBlock = PR_FALSE;
|
|
|
|
|
|
|
|
nsAutoString stringList(aLinkData); // copy to work buffer
|
|
|
|
|
|
|
|
stringList.Append(kNullCh); // put an extra null at the end
|
|
|
|
|
|
|
|
PRUnichar* start = (PRUnichar*)(const PRUnichar*)stringList.get();
|
|
|
|
PRUnichar* end = start;
|
|
|
|
PRUnichar* last = start;
|
|
|
|
PRUnichar endCh;
|
|
|
|
|
|
|
|
while (kNullCh != *start) {
|
|
|
|
while ((kNullCh != *start) && nsCRT::IsAsciiSpace(*start)) { // skip leading space
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
|
|
|
|
end = start;
|
|
|
|
last = end - 1;
|
|
|
|
|
|
|
|
while ((kNullCh != *end) && (kSemiCh != *end) && (kCommaCh != *end)) { // look for semicolon or comma
|
|
|
|
if ((kApostrophe == *end) || (kQuote == *end) ||
|
|
|
|
(kLessThanCh == *end)) { // quoted string
|
|
|
|
PRUnichar quote = *end;
|
|
|
|
if (kLessThanCh == quote) {
|
|
|
|
quote = kGreaterThanCh;
|
|
|
|
}
|
|
|
|
PRUnichar* closeQuote = (end + 1);
|
|
|
|
while ((kNullCh != *closeQuote) && (quote != *closeQuote)) {
|
|
|
|
closeQuote++; // seek closing quote
|
|
|
|
}
|
|
|
|
if (quote == *closeQuote) { // found closer
|
|
|
|
end = closeQuote; // skip to close quote
|
|
|
|
last = end - 1;
|
|
|
|
if ((kSemiCh != *(end + 1)) && (kNullCh != *(end + 1)) && (kCommaCh != *(end + 1))) {
|
|
|
|
*(++end) = kNullCh; // end string here
|
|
|
|
while ((kNullCh != *(end + 1)) && (kSemiCh != *(end + 1)) &&
|
|
|
|
(kCommaCh != *(end + 1))) { // keep going until semi or comma
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end++;
|
|
|
|
last++;
|
|
|
|
}
|
|
|
|
|
|
|
|
endCh = *end;
|
|
|
|
*end = kNullCh; // end string here
|
|
|
|
|
|
|
|
if (start < end) {
|
|
|
|
if ((kLessThanCh == *start) && (kGreaterThanCh == *last)) {
|
|
|
|
*last = kNullCh;
|
|
|
|
if (href.IsEmpty()) { // first one wins
|
|
|
|
href = (start + 1);
|
|
|
|
href.StripWhitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRUnichar* equals = start;
|
|
|
|
while ((kNullCh != *equals) && (kEqualsCh != *equals)) {
|
|
|
|
equals++;
|
|
|
|
}
|
|
|
|
if (kNullCh != *equals) {
|
|
|
|
*equals = kNullCh;
|
|
|
|
nsAutoString attr(start);
|
|
|
|
attr.StripWhitespace();
|
|
|
|
|
|
|
|
PRUnichar* value = ++equals;
|
|
|
|
while (nsCRT::IsAsciiSpace(*value)) {
|
|
|
|
value++;
|
|
|
|
}
|
|
|
|
if (((kApostrophe == *value) || (kQuote == *value)) &&
|
|
|
|
(*value == *last)) {
|
|
|
|
*last = kNullCh;
|
|
|
|
value++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr.EqualsIgnoreCase("rel")) {
|
|
|
|
if (rel.IsEmpty()) {
|
|
|
|
rel = value;
|
|
|
|
rel.CompressWhitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attr.EqualsIgnoreCase("title")) {
|
|
|
|
if (title.IsEmpty()) {
|
|
|
|
title = value;
|
|
|
|
title.CompressWhitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attr.EqualsIgnoreCase("type")) {
|
|
|
|
if (type.IsEmpty()) {
|
|
|
|
type = value;
|
|
|
|
type.StripWhitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attr.EqualsIgnoreCase("media")) {
|
|
|
|
if (media.IsEmpty()) {
|
|
|
|
media = value;
|
|
|
|
ToLowerCase(media); // HTML4.0 spec is inconsistent, make it case INSENSITIVE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (kCommaCh == endCh) { // hit a comma, process what we've got so far
|
|
|
|
if (!href.IsEmpty()) {
|
|
|
|
result = ProcessStyleLink(
|
|
|
|
aElement,
|
|
|
|
href,
|
|
|
|
!title.IsEmpty() && IsAlternateHTTPStyleSheetHeader(rel),
|
|
|
|
title,
|
|
|
|
type,
|
|
|
|
media);
|
|
|
|
if (NS_ERROR_HTMLPARSER_BLOCK == result) {
|
|
|
|
didBlock = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
href.Truncate();
|
|
|
|
rel.Truncate();
|
|
|
|
title.Truncate();
|
|
|
|
type.Truncate();
|
|
|
|
media.Truncate();
|
|
|
|
}
|
|
|
|
|
|
|
|
start = ++end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!href.IsEmpty()) {
|
|
|
|
result = ProcessStyleLink(
|
|
|
|
aElement,
|
|
|
|
href,
|
|
|
|
!title.IsEmpty() && IsAlternateHTTPStyleSheetHeader(rel),
|
|
|
|
title,
|
|
|
|
type,
|
|
|
|
media);
|
|
|
|
if (NS_SUCCEEDED(result) && didBlock) {
|
|
|
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Copied from HTML, should be shared
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
2002-12-02 23:24:57 +00:00
|
|
|
nsXMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAString& aValue,nsIContent* aContent)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult rv=NS_OK;
|
|
|
|
// XXX necko isn't going to process headers coming in from the parser
|
|
|
|
//NS_WARNING("need to fix how necko adds mime headers (in HTMLContentSink::ProcessMETATag)");
|
2002-08-06 13:51:48 +00:00
|
|
|
|
2002-09-04 06:57:25 +00:00
|
|
|
// If we add support for linking scripts here then we have to remember to
|
|
|
|
// turn off prettyprinting
|
|
|
|
|
2002-08-06 13:51:48 +00:00
|
|
|
mDocument->SetHeaderData(aHeader, aValue);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2003-04-03 18:57:33 +00:00
|
|
|
if (!mDocShell) return NS_ERROR_FAILURE;
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// see if we have a refresh "header".
|
|
|
|
if (aHeader == nsHTMLAtoms::refresh) {
|
|
|
|
// first get our baseURI
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2003-04-03 18:57:33 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mDocShell);
|
2002-01-09 01:37:50 +00:00
|
|
|
rv = webNav->GetCurrentURI(getter_AddRefs(baseURI));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1998-11-12 23:55:47 +00:00
|
|
|
|
2003-04-03 18:57:33 +00:00
|
|
|
nsCOMPtr<nsIRefreshURI> reefer = do_QueryInterface(mDocShell);
|
2002-01-09 01:37:50 +00:00
|
|
|
if (reefer) {
|
2002-03-20 22:50:33 +00:00
|
|
|
rv = reefer->SetupRefreshURIFromHeader(baseURI, NS_ConvertUCS2toUTF8(aValue));
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
} // END refresh
|
2002-03-27 06:19:14 +00:00
|
|
|
else if (aHeader == nsHTMLAtoms::setcookie) {
|
|
|
|
nsCOMPtr<nsICookieService> cookieServ = do_GetService(NS_COOKIESERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-07-02 17:58:24 +00:00
|
|
|
// Get a URI from the document principal
|
|
|
|
// We use the original codebase in case the codebase was changed by SetDomain
|
|
|
|
nsCOMPtr<nsIPrincipal> docPrincipal;
|
|
|
|
rv = mDocument->GetPrincipal(getter_AddRefs(docPrincipal));
|
2002-03-27 06:19:14 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-07-02 17:58:24 +00:00
|
|
|
if (!docPrincipal) return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAggregatePrincipal> agg(do_QueryInterface(docPrincipal, &rv));
|
|
|
|
// Document principal should always be an aggregate
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> originalPrincipal;
|
|
|
|
rv = agg->GetOriginalCodebase(getter_AddRefs(originalPrincipal));
|
|
|
|
nsCOMPtr<nsICodebasePrincipal> originalCodebase(
|
|
|
|
do_QueryInterface(originalPrincipal, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Document's principal is not a codebase (may be system), so can't set cookies
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
|
|
|
rv = originalCodebase->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-03-27 06:19:14 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObj;
|
|
|
|
nsCOMPtr<nsIPrompt> prompt;
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj));
|
|
|
|
if (globalObj) {
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> window (do_QueryInterface(globalObj));
|
|
|
|
if (window) {
|
|
|
|
window->GetPrompter(getter_AddRefs(prompt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-05 21:27:02 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2002-03-27 06:19:14 +00:00
|
|
|
if (mParser) {
|
2003-05-05 21:27:02 +00:00
|
|
|
mParser->GetChannel(getter_AddRefs(channel));
|
2002-03-27 06:19:14 +00:00
|
|
|
}
|
|
|
|
|
2003-05-05 21:27:02 +00:00
|
|
|
rv = cookieServ->SetCookieString(codebaseURI, prompt, NS_ConvertUCS2toUTF8(aValue).get(), channel);
|
2003-03-25 18:55:59 +00:00
|
|
|
|
2002-03-27 06:19:14 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
} // END set-cookie
|
|
|
|
else if (aHeader == nsHTMLAtoms::link) {
|
|
|
|
rv = ProcessLink(aContent, aValue);
|
|
|
|
}
|
2002-09-21 01:03:38 +00:00
|
|
|
else if (aHeader == nsHTMLAtoms::msthemecompatible) {
|
|
|
|
// Disable theming for the presshell if the value is no.
|
|
|
|
nsAutoString value(aValue);
|
|
|
|
if (value.EqualsIgnoreCase("no")) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mDocument->GetShellAt(0, getter_AddRefs(shell));
|
|
|
|
if (shell)
|
|
|
|
shell->DisableThemeSupport();
|
|
|
|
}
|
|
|
|
}
|
2002-03-27 06:19:14 +00:00
|
|
|
else if (mParser) {
|
|
|
|
// we also need to report back HTTP-EQUIV headers to the channel
|
|
|
|
// so that it can process things like pragma: no-cache or other
|
|
|
|
// cache-control headers. Ideally this should also be the way for
|
|
|
|
// cookies to be set! But we'll worry about that in the next
|
|
|
|
// iteration
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
if (NS_SUCCEEDED(mParser->GetChannel(getter_AddRefs(channel)))) {
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
|
|
|
|
if (httpChannel) {
|
2003-03-25 18:55:59 +00:00
|
|
|
const char *header = 0;
|
|
|
|
(void)aHeader->GetUTF8String(&header);
|
|
|
|
(void)httpChannel->SetResponseHeader(nsDependentCString(header),
|
|
|
|
NS_ConvertUCS2toUTF8(aValue),
|
|
|
|
PR_TRUE);
|
2002-03-27 06:19:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Copied from HTML content sink, should be shared
|
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::ProcessHTTPHeaders(nsIChannel* aChannel) {
|
|
|
|
nsresult rv=NS_OK;
|
|
|
|
|
|
|
|
if(aChannel) {
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpchannel(do_QueryInterface(aChannel));
|
|
|
|
if (httpchannel) {
|
2002-08-06 13:51:48 +00:00
|
|
|
const char *const headers[] = {
|
|
|
|
"link",
|
|
|
|
"default-style",
|
|
|
|
"content-style-type",
|
|
|
|
// add more http headers if you need
|
|
|
|
0};
|
2002-03-27 06:19:14 +00:00
|
|
|
const char *const *name=headers;
|
|
|
|
nsCAutoString tmp;
|
|
|
|
|
|
|
|
while(*name) {
|
|
|
|
rv = httpchannel->GetResponseHeader(nsDependentCString(*name), tmp);
|
|
|
|
if (NS_SUCCEEDED(rv) && !tmp.IsEmpty()) {
|
2002-12-11 14:24:49 +00:00
|
|
|
nsCOMPtr<nsIAtom> key = do_GetAtom(*name);
|
2002-03-27 06:19:14 +00:00
|
|
|
ProcessHeaderData(key,NS_ConvertASCIItoUCS2(tmp),nsnull);
|
|
|
|
}
|
|
|
|
name++;
|
|
|
|
}//while
|
|
|
|
}//if - httpchannel
|
|
|
|
}//if - channel
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
2002-12-02 23:24:57 +00:00
|
|
|
nsXMLContentSink::ProcessMETATag(nsIContent* aContent)
|
2002-01-09 01:37:50 +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;
|
1998-11-12 23:55:47 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// set any HTTP-EQUIV data into document's header data as well as url
|
|
|
|
nsAutoString header;
|
2002-12-02 23:24:57 +00:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::httpEquiv, header);
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!header.IsEmpty()) {
|
2002-01-09 01:37:50 +00:00
|
|
|
nsAutoString result;
|
2002-12-02 23:24:57 +00:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::content, result);
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!result.IsEmpty()) {
|
2002-01-09 01:37:50 +00:00
|
|
|
ToLowerCase(header);
|
|
|
|
nsCOMPtr<nsIAtom> fieldAtom(dont_AddRef(NS_NewAtom(header)));
|
2002-12-02 23:24:57 +00:00
|
|
|
rv = ProcessHeaderData(fieldAtom, result, aContent);
|
2002-01-24 02:03:19 +00:00
|
|
|
}//if (!result.IsEmpty())
|
|
|
|
}//if (!header.IsEmpty())
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2001-02-03 01:16:20 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXMLContentSink::SetDocumentCharset(nsAString& aCharset)
|
2002-01-09 01:37:50 +00:00
|
|
|
{
|
|
|
|
if (mDocument) {
|
|
|
|
return 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;
|
|
|
|
|
|
|
|
if (mNameSpaceStack && mNameSpaceStack->Count() > 0) {
|
|
|
|
PRInt32 index = mNameSpaceStack->Count() - 1;
|
|
|
|
nsINameSpace* nameSpace = (nsINameSpace*)mNameSpaceStack->ElementAt(index);
|
2003-06-13 20:10:01 +00:00
|
|
|
nameSpace->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
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsINameSpace*
|
|
|
|
nsXMLContentSink::PopNameSpaces()
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
if ((nsnull != mNameSpaceStack) && (0 < mNameSpaceStack->Count())) {
|
|
|
|
PRInt32 index = mNameSpaceStack->Count() - 1;
|
|
|
|
nsINameSpace* nameSpace = (nsINameSpace*)mNameSpaceStack->ElementAt(index);
|
|
|
|
mNameSpaceStack->RemoveElementAt(index);
|
|
|
|
return nameSpace;
|
1999-02-26 17:13:51 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
return nsnull;
|
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
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
if (nsnull != mContentStack) {
|
|
|
|
PRUint32 count;
|
|
|
|
mContentStack->Count(&count);
|
|
|
|
PR_ASSERT(count);
|
|
|
|
if (count) {
|
|
|
|
return (nsIContent *)mContentStack->ElementAt(count-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
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
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
PRUint32 count;
|
|
|
|
if (nsnull == mContentStack) {
|
|
|
|
NS_NewISupportsArray(getter_AddRefs(mContentStack));
|
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
mContentStack->AppendElement(aContent);
|
|
|
|
mContentStack->Count(&count);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
nsXMLContentSink::PopContent()
|
|
|
|
{
|
|
|
|
nsIContent* content = nsnull;
|
|
|
|
if (nsnull != mContentStack) {
|
|
|
|
PRUint32 index, count;
|
|
|
|
mContentStack->Count(&count);
|
|
|
|
index = count - 1;
|
|
|
|
content = (nsIContent *)mContentStack->ElementAt(index);
|
|
|
|
mContentStack->RemoveElementAt(index);
|
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
|
|
|
// The caller should NS_RELEASE the returned content object.
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mDocument->GetShellAt(i, getter_AddRefs(shell));
|
|
|
|
if (nsnull != shell) {
|
|
|
|
// Make shell an observer for next time
|
|
|
|
shell->BeginObservingDocument();
|
|
|
|
|
|
|
|
// Resize-reflow this time
|
|
|
|
nsCOMPtr<nsIPresContext> cx;
|
|
|
|
shell->GetPresContext(getter_AddRefs(cx));
|
|
|
|
nsRect r;
|
|
|
|
cx->GetVisibleArea(r);
|
|
|
|
shell->InitialReflow(r.width, r.height);
|
|
|
|
|
|
|
|
// Now trigger a refresh
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
|
|
|
if (vm) {
|
|
|
|
RefreshIfEnabled(vm);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// If the document we are loading has a reference or it is a top level
|
|
|
|
// frameset document, disable the scroll bars on the views.
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString ref;
|
2002-12-11 14:24:49 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(mDocumentURL, &rv);
|
|
|
|
if (url) {
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = url->GetRef(ref);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
if (rv == NS_OK) {
|
2002-03-06 07:48:55 +00:00
|
|
|
NS_UnescapeURL(ref); // XXX this may result in random non-ASCII bytes!
|
|
|
|
mRef = NS_ConvertASCIItoUCS2(ref);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
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));
|
|
|
|
if(docShellAsItem.get() == root.get()) {
|
|
|
|
topLevelFrameset = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
if (!ref.IsEmpty() || topLevelFrameset) {
|
2002-01-09 01:37:50 +00:00
|
|
|
// XXX support more than one presentation-shell here
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Get initial scroll preference and save it away; disable the
|
|
|
|
// scroll bars.
|
|
|
|
ns = mDocument->GetNumberOfShells();
|
|
|
|
for (i = 0; i < ns; i++) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mDocument->GetShellAt(i, getter_AddRefs(shell));
|
|
|
|
if (shell) {
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
shell->GetViewManager(getter_AddRefs(vm));
|
|
|
|
if (vm) {
|
|
|
|
nsIView* rootView = nsnull;
|
|
|
|
vm->GetRootView(rootView);
|
2002-12-11 14:24:49 +00:00
|
|
|
if (rootView) {
|
2002-01-09 01:37:50 +00:00
|
|
|
nsIScrollableView* sview = nsnull;
|
2002-12-11 14:24:49 +00:00
|
|
|
CallQueryInterface(rootView, &sview);
|
|
|
|
if (sview) {
|
2002-01-09 01:37:50 +00:00
|
|
|
sview->SetScrollPreference(nsScrollPreference_kNeverScroll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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::ScriptAvailable(nsresult aResult,
|
|
|
|
nsIDOMHTMLScriptElement *aElement,
|
|
|
|
PRBool aIsInline,
|
|
|
|
PRBool aWasPending,
|
|
|
|
nsIURI *aURI,
|
|
|
|
PRInt32 aLineNo,
|
|
|
|
const nsAString& aScript)
|
1999-03-31 20:49:25 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
// Check if this is the element we were waiting for
|
|
|
|
PRUint32 count;
|
|
|
|
mScriptElements.Count(&count);
|
|
|
|
nsCOMPtr<nsISupports> sup(dont_AddRef(mScriptElements.ElementAt(count-1)));
|
|
|
|
nsCOMPtr<nsIDOMHTMLScriptElement> scriptElement(do_QueryInterface(sup));
|
|
|
|
if (aElement != scriptElement.get()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (mParser && !mParser->IsParserEnabled()) {
|
|
|
|
// make sure to unblock the parser before evaluating the script,
|
|
|
|
// we must unblock the parser even if loading the script failed or
|
|
|
|
// if the script was empty, if we don't, the parser will never be
|
|
|
|
// unblocked.
|
|
|
|
mParser->UnblockParser();
|
2001-01-04 00:30:11 +00:00
|
|
|
}
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Mark the current script as loaded
|
|
|
|
mNeedToBlockParser = PR_FALSE;
|
|
|
|
|
|
|
|
if (NS_FAILED(aResult)) {
|
|
|
|
mScriptElements.RemoveElementAt(count-1);
|
|
|
|
|
|
|
|
if(mParser && aWasPending){
|
|
|
|
// Loading external script failed!. So, resume
|
|
|
|
// parsing since the parser got blocked when loading
|
|
|
|
// external script. - Ref. Bug: 94903
|
|
|
|
mParser->ContinueParsing();
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return NS_OK;
|
1999-03-31 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXMLContentSink::ScriptEvaluated(nsresult aResult,
|
|
|
|
nsIDOMHTMLScriptElement *aElement,
|
|
|
|
PRBool aIsInline,
|
|
|
|
PRBool aWasPending)
|
1999-06-28 14:49:29 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
// Check if this is the element we were waiting for
|
|
|
|
PRUint32 count;
|
|
|
|
mScriptElements.Count(&count);
|
|
|
|
nsCOMPtr<nsISupports> sup(dont_AddRef(mScriptElements.ElementAt(count-1)));
|
|
|
|
nsCOMPtr<nsIDOMHTMLScriptElement> scriptElement(do_QueryInterface(sup));
|
|
|
|
if (aElement != scriptElement.get()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-28 14:49:29 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Pop the script element stack
|
|
|
|
mScriptElements.RemoveElementAt(count-1);
|
1999-06-28 14:49:29 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if(mParser && mParser->IsParserEnabled() && aWasPending){
|
|
|
|
mParser->ContinueParsing();
|
1999-06-28 14:49:29 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-06-28 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
1998-12-27 08:24:04 +00:00
|
|
|
nsresult
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::RefreshIfEnabled(nsIViewManager* vm)
|
(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 (vm) {
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
2003-04-03 18:57:33 +00:00
|
|
|
nsresult rv = mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && contentViewer) {
|
|
|
|
PRBool enabled;
|
|
|
|
contentViewer->GetEnableRendering(&enabled);
|
|
|
|
if (enabled) {
|
|
|
|
vm->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
|
|
|
|
}
|
|
|
|
}
|
2000-09-02 15:34:07 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-09-02 15:34:07 +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
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// XML Element Factory
|
|
|
|
//
|
1999-08-28 07:31:08 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
class XMLElementFactoryImpl : public nsIElementFactory
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
XMLElementFactoryImpl();
|
|
|
|
virtual ~XMLElementFactoryImpl();
|
(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
|
|
|
public:
|
|
|
|
friend
|
|
|
|
nsresult
|
|
|
|
NS_NewXMLElementFactory(nsIElementFactory** aResult);
|
1999-08-28 07:31:08 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// nsISupports interface
|
|
|
|
NS_DECL_ISUPPORTS
|
1998-12-27 08:24:04 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// nsIElementFactory interface
|
|
|
|
NS_IMETHOD CreateInstanceByTag(nsINodeInfo *aNodeInfo, nsIContent** aResult);
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
};
|
2001-11-02 10:13:05 +00:00
|
|
|
|
2001-11-27 09:03:10 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
XMLElementFactoryImpl::XMLElementFactoryImpl()
|
|
|
|
{
|
1999-05-26 23:58:06 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
XMLElementFactoryImpl::~XMLElementFactoryImpl()
|
2001-02-28 23:51:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(XMLElementFactoryImpl, nsIElementFactory)
|
|
|
|
|
|
|
|
|
2001-02-28 23:51:35 +00:00
|
|
|
nsresult
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_NewXMLElementFactory(nsIElementFactory** aResult)
|
2001-02-28 23:51:35 +00:00
|
|
|
{
|
2002-04-04 15:42:45 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
2001-02-28 23:51:35 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
XMLElementFactoryImpl* result = new XMLElementFactoryImpl();
|
2002-04-04 15:42:45 +00:00
|
|
|
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
*aResult = result;
|
2002-04-04 15:42:45 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2001-02-28 23:51:35 +00:00
|
|
|
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XMLElementFactoryImpl::CreateInstanceByTag(nsINodeInfo *aNodeInfo,
|
|
|
|
nsIContent** aResult)
|
|
|
|
{
|
|
|
|
return NS_NewXMLElement(aResult, aNodeInfo);
|
|
|
|
}
|
2001-02-28 23:51:35 +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
|
|
|
|
|
|
|
|
class MathMLElementFactoryImpl : public nsIElementFactory
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
MathMLElementFactoryImpl();
|
|
|
|
virtual ~MathMLElementFactoryImpl();
|
|
|
|
|
|
|
|
public:
|
|
|
|
friend
|
|
|
|
nsresult
|
|
|
|
NS_NewMathMLElementFactory(nsIElementFactory** aResult);
|
|
|
|
|
|
|
|
// nsISupports interface
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIElementFactory interface
|
|
|
|
NS_IMETHOD CreateInstanceByTag(nsINodeInfo *aNodeInfo, nsIContent** aResult);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
MathMLElementFactoryImpl::MathMLElementFactoryImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MathMLElementFactoryImpl::~MathMLElementFactoryImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(MathMLElementFactoryImpl, nsIElementFactory)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewMathMLElementFactory(nsIElementFactory** aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
|
|
|
MathMLElementFactoryImpl* result = new MathMLElementFactoryImpl();
|
|
|
|
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
*aResult = result;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MathMLElementFactoryImpl::CreateInstanceByTag(nsINodeInfo* aNodeInfo,
|
|
|
|
nsIContent** aResult)
|
|
|
|
{
|
|
|
|
static const char kMathMLStyleSheetURI[] = "resource:///res/mathml.css";
|
|
|
|
|
|
|
|
// this bit of code is to load mathml.css on demand
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
2003-06-13 20:10:01 +00:00
|
|
|
aNodeInfo->GetDocument(getter_AddRefs(doc));
|
2002-04-04 15:42:45 +00:00
|
|
|
if (doc) {
|
2002-12-16 22:22:12 +00:00
|
|
|
nsCOMPtr<nsIHTMLContentContainer> htmlContainer(do_QueryInterface(doc));
|
|
|
|
if (htmlContainer) {
|
|
|
|
PRBool enabled;
|
|
|
|
nsCOMPtr<nsICSSLoader> cssLoader;
|
|
|
|
htmlContainer->GetCSSLoader(*getter_AddRefs(cssLoader));
|
|
|
|
if (cssLoader && NS_SUCCEEDED(cssLoader->GetEnabled(&enabled)) && enabled) {
|
|
|
|
PRBool alreadyLoaded = PR_FALSE;
|
|
|
|
PRInt32 i = 0, sheetCount = 0;
|
|
|
|
doc->GetNumberOfStyleSheets(PR_TRUE, &sheetCount);
|
|
|
|
for (; i < sheetCount; i++) {
|
|
|
|
nsCOMPtr<nsIStyleSheet> sheet;
|
|
|
|
doc->GetStyleSheetAt(i, PR_TRUE, getter_AddRefs(sheet));
|
|
|
|
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-04-04 15:42:45 +00:00
|
|
|
}
|
2002-12-16 22:22:12 +00:00
|
|
|
if (!alreadyLoaded) {
|
2002-04-04 15:42:45 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), kMathMLStyleSheetURI);
|
|
|
|
if (uri) {
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
2002-12-03 05:48:14 +00:00
|
|
|
cssLoader->LoadAgentSheet(uri, getter_AddRefs(sheet));
|
2002-04-04 15:42:45 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
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");
|
|
|
|
#endif
|
|
|
|
if (sheet) {
|
|
|
|
doc->AddStyleSheet(sheet, NS_STYLESHEET_FROM_CATALOG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
PRUint32 aIndex,
|
|
|
|
PRUint32 aLineNumber)
|
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);
|
|
|
|
|
|
|
|
if (!OnOpenContainer(aAtts, aAttsCount, nameSpaceID, tagAtom))
|
|
|
|
return NS_OK;
|
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
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
PRInt32 id;
|
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
|
|
|
content->SetContentID(id);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
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;
|
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
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
// For XSLT, we need to wait till after the transform
|
|
|
|
// to set the root content object.
|
2003-03-26 01:10:14 +00:00
|
|
|
if (!mXSLTProcessor) {
|
2002-12-02 23:24:57 +00:00
|
|
|
mDocument->SetRootContent(mDocElement);
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2002-12-02 23:24:57 +00:00
|
|
|
}
|
|
|
|
else if (appendContent) {
|
|
|
|
nsCOMPtr<nsIContent> parent = dont_AddRef(GetCurrentContent());
|
|
|
|
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
|
|
|
|
if ((aIndex != (PRUint32)-1) && NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIAtom> IDAttr = do_GetAtom(aAtts[aIndex]);
|
|
|
|
|
|
|
|
if (IDAttr) {
|
|
|
|
result = 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
|
|
|
|
2002-12-02 23:24:57 +00:00
|
|
|
nsCOMPtr<nsIContent> content = dont_AddRef(PopContent());
|
|
|
|
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);
|
|
|
|
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) {
|
|
|
|
nsCOMPtr<nsIContent> parent = getter_AddRefs(GetCurrentContent());
|
|
|
|
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
|
|
|
nsINameSpace* nameSpace = PopNameSpaces();
|
|
|
|
NS_IF_RELEASE(nameSpace);
|
2001-05-19 02:59:15 +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;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocumentType> docType;
|
|
|
|
|
|
|
|
// Create a new doctype node
|
|
|
|
rv = NS_NewDOMDocumentType(getter_AddRefs(docType),
|
2002-05-22 00:46:16 +00:00
|
|
|
aName, nsnull, nsnull,
|
|
|
|
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) {
|
|
|
|
mDocument->AddStyleSheet(sheet, NS_STYLESHEET_FROM_CATALOG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (aData) {
|
|
|
|
result = AddText(aData,aLength);
|
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
|
|
|
}
|
|
|
|
|
(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 &&
|
|
|
|
target.Equals(NS_LITERAL_STRING("xml-stylesheet")) &&
|
|
|
|
!type.EqualsIgnoreCase("text/css")) {
|
|
|
|
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
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
result = ProcessStyleLink(node, href, alternate.Equals(NS_LITERAL_STRING("yes")),
|
|
|
|
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-04-19 00:28:09 +00:00
|
|
|
return mDocument->SetXMLDeclaration(version, encoding, standalone);
|
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;
|
|
|
|
|
|
|
|
// 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};
|
|
|
|
|
2002-05-20 22:47:02 +00:00
|
|
|
rv = HandleStartElement(NS_LITERAL_STRING("parsererror").get(), atts, 1,
|
|
|
|
(PRUint32)-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,
|
|
|
|
(PRUint32)-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
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (mNameSpaceStack && (0 < mNameSpaceStack->Count())) {
|
|
|
|
nameSpace =
|
|
|
|
(nsINameSpace*)mNameSpaceStack->ElementAt(mNameSpaceStack->Count() - 1);
|
|
|
|
} 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
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
static const NS_NAMED_LITERAL_STRING(kNameSpaceDef, "xmlns");
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (!mNameSpaceStack) {
|
|
|
|
mNameSpaceStack = new nsAutoVoidArray();
|
1998-11-12 23:55:47 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (!mNameSpaceStack) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2001-08-17 22:24:39 +00:00
|
|
|
}
|
1998-11-12 23:55:47 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsINameSpace *tmp = nameSpace;
|
|
|
|
mNameSpaceStack->AppendElement(tmp);
|
|
|
|
NS_ADDREF(tmp);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> ni;
|
|
|
|
mNodeInfoManager->GetNodeInfo(nameAtom, nameSpacePrefix, nameSpaceID,
|
2003-06-13 20:10:01 +00:00
|
|
|
getter_AddRefs(ni));
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Add attribute to content
|
|
|
|
aContent->SetAttr(ni, nsDependentString(aAtts[1]), PR_FALSE);
|
|
|
|
aAtts += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Give autoloading links a chance to fire
|
2003-04-03 18:57:33 +00:00
|
|
|
if (mDocShell) {
|
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");
|
|
|
|
mScriptElements.AppendElement(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
|
|
|
}
|