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 "nsIXMLDocument.h"
|
|
|
|
#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"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIWebShell.h"
|
2000-03-11 00:29:47 +00:00
|
|
|
#include "nsIDocShell.h"
|
1999-12-18 02:09:29 +00:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsITextContent.h"
|
2001-05-19 02:59:15 +00:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIDOMComment.h"
|
1999-03-31 20:49:25 +00:00
|
|
|
#include "nsIDOMCDATASection.h"
|
2000-06-17 01:49:19 +00:00
|
|
|
#include "nsDOMDocumentType.h"
|
1998-11-11 22:06:16 +00:00
|
|
|
#include "nsIHTMLContent.h"
|
(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 "nsXSLContentSink.h"
|
|
|
|
#include "nsParserCIID.h"
|
2001-02-22 03:01:34 +00:00
|
|
|
#include "nsParserUtils.h"
|
2000-09-02 15:34:07 +00:00
|
|
|
#include "nsIDocumentViewer.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"
|
2001-08-01 23:04:32 +00:00
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsICharsetConverterManager.h"
|
|
|
|
#include "nsICharsetConverterManager2.h"
|
2001-12-17 07:14:49 +00:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsUnicharUtils.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
|
|
|
|
1999-07-18 00:34:41 +00:00
|
|
|
static char kNameSpaceSeparator = ':';
|
1999-03-31 20:49:25 +00:00
|
|
|
static char kStyleSheetPI[] = "xml-stylesheet";
|
2001-11-02 10:13:05 +00:00
|
|
|
#define kXSLType "text/xsl"
|
1998-12-27 08:24:04 +00:00
|
|
|
|
2000-09-02 15:34:07 +00:00
|
|
|
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2000-01-19 04:44:10 +00:00
|
|
|
nsINameSpaceManager* nsXMLContentSink::gNameSpaceManager = nsnull;
|
|
|
|
PRUint32 nsXMLContentSink::gRefCnt = 0;
|
1999-08-28 07:31:08 +00:00
|
|
|
|
1998-11-14 00:21:19 +00:00
|
|
|
// XXX Open Issues:
|
2001-04-30 23:35:09 +00:00
|
|
|
// 1) what's not allowed - We need to figure out which HTML tags
|
1998-11-14 00:21:19 +00:00
|
|
|
// (prefixed with a HTML namespace qualifier) are explicitly not
|
|
|
|
// allowed (if any).
|
2001-04-30 23:35:09 +00:00
|
|
|
// 2) factoring code with nsHTMLContentSink - There's some amount of
|
1998-11-14 00:21:19 +00:00
|
|
|
// common code between this and the HTML content sink. This will
|
|
|
|
// increase as we support more and more HTML elements. How can code
|
|
|
|
// from the code be factored?
|
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
nsresult
|
|
|
|
NS_NewXMLContentSink(nsIXMLContentSink** aResult,
|
|
|
|
nsIDocument* aDoc,
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* aURL,
|
1998-11-11 22:06:16 +00:00
|
|
|
nsIWebShell* aWebShell)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
nsresult rv = it->Init(aDoc, aURL, aWebShell);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
delete it;
|
|
|
|
return rv;
|
|
|
|
}
|
2000-09-02 15:34:07 +00:00
|
|
|
return it->QueryInterface(NS_GET_IID(nsIXMLContentSink), (void **)aResult);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXMLContentSink::nsXMLContentSink()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
2000-01-19 04:44:10 +00:00
|
|
|
gRefCnt++;
|
|
|
|
if (gRefCnt == 1) {
|
|
|
|
nsresult rv = nsServiceManager::GetService(kNameSpaceManagerCID,
|
|
|
|
NS_GET_IID(nsINameSpaceManager),
|
|
|
|
(nsISupports**) &gNameSpaceManager);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get namespace manager");
|
|
|
|
}
|
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
mDocument = nsnull;
|
|
|
|
mDocumentURL = nsnull;
|
1999-05-26 23:58:06 +00:00
|
|
|
mDocumentBaseURL = nsnull;
|
1998-11-11 22:06:16 +00:00
|
|
|
mWebShell = nsnull;
|
1998-12-11 17:02:37 +00:00
|
|
|
mParser = nsnull;
|
1998-11-11 22:06:16 +00:00
|
|
|
mRootElement = nsnull;
|
|
|
|
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
|
|
|
mStyleSheetCount = 0;
|
|
|
|
mCSSLoader = nsnull;
|
1999-06-28 14:49:29 +00:00
|
|
|
mXSLTransformMediator = nsnull;
|
2001-05-17 05:54:16 +00:00
|
|
|
mNeedToBlockParser = PR_FALSE;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXMLContentSink::~nsXMLContentSink()
|
|
|
|
{
|
2000-01-19 04:44:10 +00:00
|
|
|
gRefCnt--;
|
|
|
|
if (gRefCnt == 0) {
|
|
|
|
NS_IF_RELEASE(gNameSpaceManager);
|
|
|
|
}
|
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
NS_IF_RELEASE(mDocument);
|
|
|
|
NS_IF_RELEASE(mDocumentURL);
|
1999-05-26 23:58:06 +00:00
|
|
|
NS_IF_RELEASE(mDocumentBaseURL);
|
1998-11-11 22:06:16 +00:00
|
|
|
NS_IF_RELEASE(mWebShell);
|
1998-12-11 17:02:37 +00:00
|
|
|
NS_IF_RELEASE(mParser);
|
1998-11-11 22:06:16 +00:00
|
|
|
NS_IF_RELEASE(mRootElement);
|
|
|
|
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,
|
1998-11-11 22:06:16 +00:00
|
|
|
nsIWebShell* aContainer)
|
|
|
|
{
|
2001-09-05 04:20:54 +00:00
|
|
|
NS_ENSURE_TRUE(gNameSpaceManager, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
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);
|
1998-11-11 22:06:16 +00:00
|
|
|
mWebShell = aContainer;
|
2000-01-12 10:33:00 +00:00
|
|
|
NS_IF_ADDREF(aContainer);
|
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);
|
|
|
|
loader->AddObserver(this);
|
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
mState = eXMLContentSinkState_InProlog;
|
|
|
|
mDocElement = nsnull;
|
|
|
|
mRootElement = nsnull;
|
|
|
|
|
1999-05-26 23:58:06 +00:00
|
|
|
nsIHTMLContentContainer* htmlContainer = nsnull;
|
2000-09-02 15:34:07 +00:00
|
|
|
if (NS_SUCCEEDED(aDoc->QueryInterface(NS_GET_IID(nsIHTMLContentContainer), (void**)&htmlContainer))) {
|
1999-05-26 23:58:06 +00:00
|
|
|
htmlContainer->GetCSSLoader(mCSSLoader);
|
|
|
|
NS_RELEASE(htmlContainer);
|
|
|
|
}
|
|
|
|
|
2000-05-10 13:13:39 +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)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
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
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
/**
|
|
|
|
* DOCTYPE declaration is covered with very strict rules, which
|
|
|
|
* makes our life here simpler because the XML parser has already
|
|
|
|
* detected errors. The only slightly problematic case is whitespace
|
|
|
|
* between the tokens. There MUST be whitespace between the tokens
|
|
|
|
* EXCEPT right before > and [.
|
|
|
|
*/
|
|
|
|
static const char* kWhitespace = " \r\n\t\b"; // Optimized for typical cases
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetDocTypeToken(nsString& aStr,
|
|
|
|
nsString& aToken,
|
|
|
|
PRBool aQuotedString)
|
|
|
|
{
|
|
|
|
aStr.Trim(kWhitespace,PR_TRUE,PR_FALSE); // If we don't do this we must look ahead
|
|
|
|
// before Cut() and adjust the cut amount.
|
|
|
|
|
|
|
|
if (aQuotedString) {
|
2002-01-30 06:04:29 +00:00
|
|
|
PRInt32 endQuote = aStr.FindChar(aStr[0],1);
|
2002-01-09 01:37:50 +00:00
|
|
|
aStr.Mid(aToken,1,endQuote-1);
|
|
|
|
aStr.Cut(0,endQuote+1);
|
|
|
|
} else {
|
|
|
|
static const char* kDelimiter = " >[\r\n\t\b"; // Optimized for typical cases
|
|
|
|
PRInt32 tokenEnd = aStr.FindCharInSet(kDelimiter);
|
|
|
|
if (tokenEnd > 0) {
|
|
|
|
aStr.Left(aToken, tokenEnd);
|
|
|
|
aStr.Cut(0, tokenEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
nsresult CharsetConvRef(const nsString& aDocCharset, const nsCString& aRefInDocCharset, nsString& aRefInUnicode);
|
|
|
|
|
2000-10-24 01:03:31 +00:00
|
|
|
void
|
|
|
|
nsXMLContentSink::ScrollToRef()
|
|
|
|
{
|
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
|
|
|
|
nsAutoString ref = NS_ConvertUTF8toUCS2(unescapedRef);
|
|
|
|
|
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
|
2001-08-31 04:28:26 +00:00
|
|
|
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())
|
|
|
|
rv = shell->GoToAnchor(ref);
|
|
|
|
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)) {
|
|
|
|
rv = CharsetConvRef(docCharset, unescapedRef, ref);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && !ref.IsEmpty())
|
|
|
|
rv = shell->GoToAnchor(ref);
|
|
|
|
}
|
|
|
|
}
|
2000-10-24 01:03:31 +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);
|
|
|
|
|
2000-11-27 23:23:28 +00:00
|
|
|
nsresult rv = NS_OK;
|
1999-06-28 14:49:29 +00:00
|
|
|
if (mXSLTransformMediator) {
|
(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
|
|
|
rv = SetupTransformMediator();
|
|
|
|
}
|
1999-06-28 14:49:29 +00:00
|
|
|
|
2001-05-17 05:54:16 +00:00
|
|
|
nsCOMPtr<nsIScriptLoader> loader;
|
|
|
|
mDocument->GetScriptLoader(getter_AddRefs(loader));
|
|
|
|
if (loader) {
|
|
|
|
loader->RemoveObserver(this);
|
|
|
|
}
|
|
|
|
|
1999-06-28 14:49:29 +00:00
|
|
|
if (!mXSLTransformMediator || NS_FAILED(rv)) {
|
2000-09-02 15:34:07 +00:00
|
|
|
StartLayout();
|
2000-10-24 01:03:31 +00:00
|
|
|
ScrollToRef();
|
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
|
|
|
|
// actually borken.
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-06-28 14:49:29 +00:00
|
|
|
// The observe method is called on completion of the transform. The nsISupports argument is an
|
|
|
|
// nsIDOMElement interface to the root node of the output content model.
|
|
|
|
NS_IMETHODIMP
|
2001-10-19 20:52:59 +00:00
|
|
|
nsXMLContentSink::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
|
1999-06-28 14:49:29 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2001-10-19 20:52:59 +00:00
|
|
|
if (!nsCRT::strcmp(aTopic, "xslt-done")) {
|
2000-09-02 15:34:07 +00:00
|
|
|
nsCOMPtr<nsIContent> content;
|
1999-06-28 14:49:29 +00:00
|
|
|
|
2000-09-02 15:34:07 +00:00
|
|
|
// Set the output content model on the document
|
|
|
|
content = do_QueryInterface(aSubject, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> resultDOMDoc;
|
|
|
|
mXSLTransformMediator->GetResultDocument(getter_AddRefs(resultDOMDoc));
|
|
|
|
nsCOMPtr<nsIDocument> resultDoc = do_QueryInterface(resultDOMDoc);
|
|
|
|
|
2000-09-16 20:53:08 +00:00
|
|
|
nsCOMPtr<nsIDocument> sourceDoc = mDocument;
|
2000-09-02 15:34:07 +00:00
|
|
|
NS_RELEASE(mDocument);
|
|
|
|
|
|
|
|
mDocument = resultDoc;
|
|
|
|
NS_ADDREF(mDocument);
|
2002-01-24 13:38:51 +00:00
|
|
|
nsCOMPtr<nsIContent> root;
|
|
|
|
mDocument->GetRootContent(getter_AddRefs(root));
|
|
|
|
if (!root)
|
|
|
|
mDocument->SetRootContent(content);
|
2000-09-02 15:34:07 +00:00
|
|
|
|
|
|
|
// Reset the observer on the transform mediator
|
|
|
|
mXSLTransformMediator->SetTransformObserver(nsnull);
|
2000-09-16 20:53:08 +00:00
|
|
|
|
|
|
|
// Start the layout process
|
|
|
|
StartLayout();
|
|
|
|
sourceDoc->EndLoad();
|
2001-03-12 06:34:40 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
|
|
|
if (NS_SUCCEEDED(rv) && contentViewer) {
|
|
|
|
contentViewer->LoadComplete(NS_OK);
|
|
|
|
}
|
2000-09-02 15:34:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Transform failed
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2001-03-12 06:34:40 +00:00
|
|
|
nsCOMPtr<nsIDocumentViewer> documentViewer(do_QueryInterface(contentViewer));
|
|
|
|
if (documentViewer) {
|
2000-09-02 15:34:07 +00:00
|
|
|
documentViewer->SetTransformMediator(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
|
|
|
|
2000-09-02 15:34:07 +00:00
|
|
|
mXSLTransformMediator = nsnull;
|
|
|
|
mDocument->SetRootContent(mDocElement);
|
|
|
|
|
2000-09-16 20:53:08 +00:00
|
|
|
// Start the layout process
|
|
|
|
StartLayout();
|
|
|
|
mDocument->EndLoad();
|
|
|
|
}
|
2000-09-02 15:34:07 +00:00
|
|
|
}
|
1999-06-28 14:49:29 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Provide the transform mediator with the source document's content
|
(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
|
|
|
// model and the output document, and register the XML content sink
|
1999-06-28 14:49:29 +00:00
|
|
|
// as the transform observer. The transform mediator will call
|
|
|
|
// the nsIObserver::Observe() method on the transform observer once
|
|
|
|
// the transform is completed. The nsISupports pointer to the Observe
|
|
|
|
// method will be an nsIDOMElement pointer to the root node of the output
|
|
|
|
// content model.
|
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::SetupTransformMediator()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2000-09-02 15:34:07 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> currentDOMDoc(do_QueryInterface(mDocument));
|
|
|
|
mXSLTransformMediator->SetSourceContentModel(currentDOMDoc);
|
|
|
|
|
|
|
|
// Create the result document
|
|
|
|
nsCOMPtr<nsIDOMDocument> resultDOMDoc;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> url;
|
|
|
|
mDocument->GetBaseURL(*getter_AddRefs(url));
|
|
|
|
|
|
|
|
nsAutoString emptyStr;
|
|
|
|
rv = NS_NewDOMDocument(getter_AddRefs(resultDOMDoc), emptyStr, emptyStr, nsnull, url);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXMLDocument> resultXMLDoc(do_QueryInterface(resultDOMDoc));
|
|
|
|
resultXMLDoc->SetDefaultStylesheets(url);
|
|
|
|
|
2001-03-12 06:34:40 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
|
|
|
if (NS_SUCCEEDED(rv) && contentViewer) {
|
|
|
|
contentViewer->SetDOMDocument(resultDOMDoc);
|
|
|
|
}
|
|
|
|
|
2000-09-02 15:34:07 +00:00
|
|
|
mXSLTransformMediator->SetResultDocument(resultDOMDoc);
|
|
|
|
mXSLTransformMediator->SetTransformObserver(this);
|
1999-06-28 14:49:29 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
(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
|
|
|
|
nsXMLContentSink::SplitXMLName(nsAReadableString& aString, nsIAtom **aPrefix,
|
|
|
|
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
|
|
|
|
nsXMLContentSink::CreateElement(const PRUnichar** aAtts, PRUint32 aAttsCount, PRInt32 aNameSpaceID,
|
|
|
|
nsINodeInfo* aNodeInfo, nsIContent** aResult)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
GetElementFactory(aNameSpaceID, getter_AddRefs(elementFactory));
|
|
|
|
if (elementFactory)
|
|
|
|
// Create the content element using the element factory.
|
|
|
|
elementFactory->CreateInstanceByTag(aNodeInfo, aResult);
|
|
|
|
else {
|
|
|
|
NS_NewXMLElement(aResult, aNodeInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
static void
|
|
|
|
ParseProcessingInstruction(const nsString& aText,
|
|
|
|
nsString& aTarget,
|
|
|
|
nsString& aData)
|
|
|
|
{
|
|
|
|
PRInt32 offset;
|
2001-10-16 05:55:04 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
aTarget.Truncate();
|
|
|
|
aData.Truncate();
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
offset = aText.FindCharInSet(" \n\r\t");
|
|
|
|
if (-1 != offset) {
|
|
|
|
aText.Mid(aTarget, 2, offset-2);
|
|
|
|
aText.Mid(aData, offset+1, aText.Length()-offset-3);
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Create a transform mediator
|
|
|
|
rv = NS_NewTransformMediator(getter_AddRefs(mXSLTransformMediator),
|
|
|
|
NS_LITERAL_CSTRING(kXSLType));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// 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
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Create the XML parser
|
|
|
|
nsCOMPtr<nsIParser> parser(do_CreateInstance(kCParserCID, &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Enable the transform mediator. It will start the transform
|
|
|
|
// as soon as it has enough state to do so. The state needed is
|
|
|
|
// the source content model, the style content model, the current
|
|
|
|
// document, and an observer. The XML and XSL content sinks provide
|
|
|
|
// this state by calling the various setters on nsITransformMediator.
|
|
|
|
mXSLTransformMediator->SetEnabled(PR_TRUE);
|
2001-02-03 01:16:20 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// The document viewer owns the transform mediator.
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
|
|
|
nsCOMPtr<nsIDocumentViewer> documentViewer(do_QueryInterface(contentViewer));
|
|
|
|
if (documentViewer) {
|
|
|
|
documentViewer->SetTransformMediator(mXSLTransformMediator);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Create the XSL stylesheet document
|
|
|
|
nsCOMPtr<nsIDOMDocument> styleDOMDoc;
|
|
|
|
nsAutoString emptyStr;
|
|
|
|
emptyStr.Truncate();
|
|
|
|
rv = NS_NewDOMDocument(getter_AddRefs(styleDOMDoc), emptyStr, emptyStr, nsnull, aUrl);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsCOMPtr<nsIDocument> styleDoc(do_QueryInterface(styleDOMDoc));
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Create the XSL content sink
|
|
|
|
nsCOMPtr<nsIXMLContentSink> sink;
|
|
|
|
rv = NS_NewXSLContentSink(getter_AddRefs(sink), mXSLTransformMediator, styleDoc, aUrl, mWebShell);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Hook up the content sink to the parser's output and ask the parser
|
|
|
|
// to start parsing the URL specified by aURL.
|
|
|
|
parser->SetContentSink(sink);
|
2002-01-30 06:04:29 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(utf8, "UTF-8");
|
2002-01-09 01:37:50 +00:00
|
|
|
styleDoc->SetDocumentCharacterSet(utf8);
|
|
|
|
parser->SetDocumentCharset(utf8, kCharsetFromDocTypeDefault);
|
|
|
|
parser->Parse(aUrl);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Set the parser as the stream listener and start the URL load
|
|
|
|
nsCOMPtr<nsIStreamListener> sl;
|
|
|
|
rv = parser->QueryInterface(NS_GET_IID(nsIStreamListener), (void**)getter_AddRefs(sl));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
rv = NS_OpenURI(sl, nsnull, aUrl);
|
1999-06-28 14:49:29 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return rv;
|
|
|
|
}
|
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;
|
2001-07-04 19:35:23 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (aType.EqualsIgnoreCase(kXSLType) ||
|
|
|
|
aType.EqualsIgnoreCase(kXMLTextContentType) ||
|
|
|
|
aType.EqualsIgnoreCase(kXMLApplicationContentType)) {
|
|
|
|
// LoadXSLStyleSheet needs a mWebShell.
|
|
|
|
if (!mWebShell)
|
|
|
|
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
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> secMan =
|
|
|
|
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = secMan->CheckLoadURI(mDocumentURL, url,
|
|
|
|
nsIScriptSecurityManager::ALLOW_CHROME);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_OK;
|
|
|
|
rv = LoadXSLStyleSheet(url);
|
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-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::ProcessBASETag()
|
2001-11-03 10:12:20 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (mDocument) {
|
|
|
|
nsAutoString value;
|
|
|
|
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mBaseElement->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::target, value)) {
|
|
|
|
mDocument->SetBaseTarget(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mBaseElement->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::href, value)) {
|
|
|
|
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);
|
|
|
|
mDocument->GetBaseURL(mDocumentBaseURL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAReadableString& aValue,nsIHTMLContent* 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)");
|
|
|
|
|
|
|
|
// see if we have a refresh "header".
|
|
|
|
if (aHeader == nsHTMLAtoms::refresh) {
|
|
|
|
// first get our baseURI
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(mWebShell, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(docShell);
|
|
|
|
rv = webNav->GetCurrentURI(getter_AddRefs(baseURI));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1998-11-12 23:55:47 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIRefreshURI> reefer = do_QueryInterface(mWebShell);
|
|
|
|
if (reefer) {
|
2002-02-08 22:46:09 +00:00
|
|
|
rv = reefer->SetupRefreshURIFromHeader(baseURI, aValue);
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
} // END refresh
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::ProcessMETATag()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
mMetaElement->GetAttr(kNameSpaceID_HTML, nsHTMLAtoms::httpEquiv, header);
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!header.IsEmpty()) {
|
2002-01-09 01:37:50 +00:00
|
|
|
nsAutoString result;
|
|
|
|
mMetaElement->GetAttr(kNameSpaceID_HTML, 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)));
|
|
|
|
rv=ProcessHeaderData(fieldAtom,result,mMetaElement);
|
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
|
|
|
|
nsXMLContentSink::SetDocumentCharset(nsAWritableString& aCharset)
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
nsIContent* content;
|
|
|
|
rv = NS_NewTextNode(&content);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Set the content's document
|
|
|
|
content->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
2001-05-17 05:54:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Set the text in the text node
|
|
|
|
nsITextContent* text = nsnull;
|
|
|
|
content->QueryInterface(NS_GET_IID(nsITextContent), (void**) &text);
|
|
|
|
text->SetText(mText, mTextLength, PR_FALSE);
|
|
|
|
NS_RELEASE(text);
|
|
|
|
|
|
|
|
// Add text to its parent
|
|
|
|
AddContentAsLeaf(content);
|
|
|
|
NS_RELEASE(content);
|
2001-05-17 05:54:16 +00:00
|
|
|
}
|
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
|
|
|
}
|
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);
|
|
|
|
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
|
|
|
PRBool
|
|
|
|
nsXMLContentSink::IsHTMLNameSpace(PRInt32 aID)
|
(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
|
|
|
return PRBool(kNameSpaceID_HTML == aID);
|
1999-03-11 05:29:36 +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
|
|
|
|
nsCOMPtr<nsIScrollable> scrollableContainer(do_QueryInterface(mWebShell));
|
|
|
|
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-01-09 01:37:50 +00:00
|
|
|
nsIURL* url;
|
|
|
|
nsresult rv = mDocumentURL->QueryInterface(NS_GET_IID(nsIURL), (void**)&url);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = url->GetRef(ref);
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_RELEASE(url);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mWebShell));
|
|
|
|
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);
|
|
|
|
if (nsnull != rootView) {
|
|
|
|
nsIScrollableView* sview = nsnull;
|
|
|
|
rootView->QueryInterface(NS_GET_IID(nsIScrollableView), (void**) &sview);
|
|
|
|
if (nsnull != sview) {
|
|
|
|
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<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
nsresult rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
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-01-09 01:37:50 +00:00
|
|
|
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
|
|
|
if (! aResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2001-02-28 23:51:35 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
XMLElementFactoryImpl* result = new XMLElementFactoryImpl();
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ADDREF(result);
|
|
|
|
*aResult = result;
|
|
|
|
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-01-09 01:37:50 +00:00
|
|
|
void
|
|
|
|
nsXMLContentSink::GetElementFactory(PRInt32 aNameSpaceID,
|
|
|
|
nsIElementFactory** aResult)
|
|
|
|
{
|
|
|
|
gNameSpaceManager->GetElementFactory(aNameSpaceID, aResult);
|
|
|
|
}
|
2001-02-28 23:51:35 +00:00
|
|
|
|
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 isHTML = PR_FALSE;
|
|
|
|
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,
|
|
|
|
*getter_AddRefs(nodeInfo));
|
|
|
|
|
|
|
|
isHTML = IsHTMLNameSpace(nameSpaceID);
|
|
|
|
|
|
|
|
if (isHTML) {
|
|
|
|
if (tagAtom.get() == nsHTMLAtoms::script) {
|
|
|
|
result = ProcessStartSCRIPTTag(aLineNumber);
|
|
|
|
// Don't append the content to the tree until we're all
|
|
|
|
// done collecting its contents
|
|
|
|
appendContent = PR_FALSE;
|
|
|
|
} else if (tagAtom.get() == nsHTMLAtoms::title) {
|
|
|
|
if (mTitleText.IsEmpty())
|
|
|
|
mInTitle = PR_TRUE; // The first title wins
|
2001-04-30 23:35:09 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIHTMLContent> htmlContent;
|
|
|
|
result = NS_CreateHTMLElement(getter_AddRefs(htmlContent), nodeInfo, PR_TRUE);
|
|
|
|
content = do_QueryInterface(htmlContent);
|
|
|
|
|
|
|
|
if (tagAtom.get() == nsHTMLAtoms::style) {
|
|
|
|
mStyleElement = htmlContent;
|
|
|
|
}
|
|
|
|
else if (tagAtom.get() == nsHTMLAtoms::base) {
|
|
|
|
if (!mBaseElement) {
|
|
|
|
mBaseElement = htmlContent; // The first base wins
|
|
|
|
}
|
|
|
|
} else if (tagAtom.get() == nsHTMLAtoms::meta) {
|
|
|
|
if (!mMetaElement) {
|
|
|
|
mMetaElement = htmlContent;
|
2001-04-30 23:35:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
else
|
|
|
|
CreateElement(aAtts, aAttsCount, nameSpaceID, nodeInfo, getter_AddRefs(content));
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_OK == result) {
|
|
|
|
PRInt32 id;
|
|
|
|
mDocument->GetAndIncrementContentID(&id);
|
|
|
|
content->SetContentID(id);
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(content));
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (ssle) {
|
|
|
|
// We stopped supporting <style src="..."> for XHTML as it is
|
|
|
|
// non-standard.
|
|
|
|
if (isHTML && tagAtom.get() == nsHTMLAtoms::style) {
|
|
|
|
ssle->InitStyleLinkElement(nsnull, PR_TRUE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ssle->InitStyleLinkElement(mParser, PR_FALSE);
|
|
|
|
ssle->SetEnableUpdates(PR_FALSE);
|
|
|
|
}
|
2001-04-30 23:35:09 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
content->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Set the attributes on the new content element
|
|
|
|
result = AddAttributes(aAtts, content, isHTML);
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_OK == result) {
|
|
|
|
// If this is the document element
|
|
|
|
if (!mDocElement) {
|
|
|
|
mDocElement = content;
|
|
|
|
NS_ADDREF(mDocElement);
|
|
|
|
|
|
|
|
// For XSL, we need to wait till after the transform
|
|
|
|
// to set the root content object.
|
|
|
|
if (!mXSLTransformMediator)
|
|
|
|
mDocument->SetRootContent(mDocElement);
|
|
|
|
}
|
|
|
|
else if (appendContent) {
|
|
|
|
nsCOMPtr<nsIContent> parent = getter_AddRefs(GetCurrentContent());
|
|
|
|
|
|
|
|
parent->AppendChildTo(content, PR_FALSE, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
PushContent(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the ID attribute atom on the node info object for this node
|
|
|
|
if (aIndex != -1) {
|
|
|
|
nsCOMPtr<nsIAtom> IDAttr = dont_AddRef(NS_NewAtom((const PRUnichar *) aAtts[aIndex]));
|
|
|
|
if (IDAttr && NS_SUCCEEDED(result)) {
|
|
|
|
result = nodeInfo->SetIDAttributeAtom(IDAttr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ssle) {
|
|
|
|
ssle->SetEnableUpdates(PR_TRUE);
|
|
|
|
result = ssle->UpdateStyleSheet(PR_TRUE, mDocument, mStyleSheetCount);
|
|
|
|
if (NS_SUCCEEDED(result) || (result == NS_ERROR_HTMLPARSER_BLOCK)) {
|
|
|
|
if (result == NS_ERROR_HTMLPARSER_BLOCK && mParser) {
|
|
|
|
mParser->BlockParser();
|
|
|
|
}
|
|
|
|
mStyleSheetCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 popContent = PR_TRUE;
|
|
|
|
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-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIContent> currentContent(dont_AddRef(GetCurrentContent()));
|
2001-07-04 19:35:23 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (currentContent && currentContent->IsContentOfType(nsIContent::eHTML)) {
|
|
|
|
nsCOMPtr<nsIAtom> tagAtom;
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
currentContent->GetTag(*getter_AddRefs(tagAtom));
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (tagAtom.get() == nsHTMLAtoms::script) {
|
|
|
|
result = ProcessEndSCRIPTTag();
|
|
|
|
appendContent = PR_TRUE;
|
|
|
|
} else if (tagAtom.get() == nsHTMLAtoms::title) {
|
|
|
|
if (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.get() == nsHTMLAtoms::style) {
|
|
|
|
if (mStyleElement) {
|
|
|
|
result = ProcessSTYLETag();
|
|
|
|
mStyleElement=nsnull;
|
|
|
|
mStyleText.Truncate();
|
|
|
|
}
|
|
|
|
} else if (tagAtom.get() == nsHTMLAtoms::base) {
|
|
|
|
if (mBaseElement) {
|
|
|
|
result = ProcessBASETag();
|
|
|
|
}
|
|
|
|
} else if (tagAtom.get() == nsHTMLAtoms::meta) {
|
|
|
|
if (mMetaElement) {
|
|
|
|
result = ProcessMETATag();
|
|
|
|
mMetaElement = nsnull; // HTML can have more than one meta so clear this now
|
|
|
|
}
|
2001-05-19 02:59:15 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
if (popContent) {
|
|
|
|
content = getter_AddRefs(PopContent());
|
|
|
|
if (content) {
|
|
|
|
if (mDocElement == content.get()) {
|
|
|
|
mState = eXMLContentSinkState_InEpilog;
|
|
|
|
}
|
|
|
|
else if (appendContent) {
|
|
|
|
nsCOMPtr<nsIContent> parent = getter_AddRefs(GetCurrentContent());
|
(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
|
|
|
parent->AppendChildTo(content, PR_FALSE, PR_FALSE);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// XXX Again, the parser should catch unmatched tags and
|
|
|
|
// we should never get here.
|
|
|
|
PR_ASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-01-09 01:37:50 +00:00
|
|
|
nsIContent *comment;
|
|
|
|
nsIDOMComment *domComment;
|
|
|
|
nsresult result = NS_OK;
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
result = NS_NewCommentNode(&comment);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
result = comment->QueryInterface(NS_GET_IID(nsIDOMComment), (void **)&domComment);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
domComment->AppendData(nsDependentString(aName));
|
|
|
|
NS_RELEASE(domComment);
|
|
|
|
|
|
|
|
comment->SetDocument(mDocument, PR_FALSE, PR_TRUE);
|
|
|
|
result = AddContentAsLeaf(comment);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_RELEASE(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();
|
|
|
|
|
|
|
|
nsIContent *cdata;
|
|
|
|
nsIDOMCDATASection *domCDATA;
|
|
|
|
nsresult result = NS_OK;
|
2000-12-11 22:21:06 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (mInTitle) {
|
|
|
|
mTitleText.Append(aData, aLength);
|
|
|
|
} else if (mStyleElement) {
|
|
|
|
mStyleText.Append(aData, aLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = NS_NewXMLCDATASection(&cdata);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
result = cdata->QueryInterface(NS_GET_IID(nsIDOMCDATASection), (void **)&domCDATA);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
domCDATA->SetData(nsDependentString(aData, aLength));
|
|
|
|
NS_RELEASE(domCDATA);
|
|
|
|
|
|
|
|
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
|
|
|
NS_RELEASE(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-01-24 22:15:58 +00:00
|
|
|
nsXMLContentSink::HandleDoctypeDecl(const PRUnichar *aDoctype,
|
|
|
|
PRUint32 aLength)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2000-06-17 01:49:19 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(mDocument));
|
|
|
|
if (!doc)
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-01-24 22:15:58 +00:00
|
|
|
nsAutoString str(aDoctype, aLength);
|
|
|
|
nsAutoString name, publicId, systemId;
|
2000-06-17 01:49:19 +00:00
|
|
|
|
2000-12-11 22:21:06 +00:00
|
|
|
GetDocTypeToken(str, name, PR_FALSE);
|
2000-06-17 01:49:19 +00:00
|
|
|
|
2000-12-11 22:21:06 +00:00
|
|
|
nsAutoString token;
|
2000-06-17 01:49:19 +00:00
|
|
|
|
2000-12-11 22:21:06 +00:00
|
|
|
GetDocTypeToken(str, token, PR_FALSE);
|
|
|
|
if (token.Equals(NS_LITERAL_STRING("PUBLIC"))) {
|
|
|
|
GetDocTypeToken(str, publicId, PR_TRUE);
|
|
|
|
GetDocTypeToken(str, systemId, PR_TRUE);
|
|
|
|
}
|
|
|
|
else if (token.Equals(NS_LITERAL_STRING("SYSTEM"))) {
|
|
|
|
GetDocTypeToken(str, systemId, PR_TRUE);
|
2000-06-17 01:49:19 +00:00
|
|
|
}
|
|
|
|
|
2002-01-24 22:15:58 +00:00
|
|
|
// The rest is the internal subset (minus whitespace)
|
2000-12-11 22:21:06 +00:00
|
|
|
str.Trim(kWhitespace);
|
|
|
|
|
2000-06-17 01:49:19 +00:00
|
|
|
nsCOMPtr<nsIDOMDocumentType> oldDocType;
|
|
|
|
nsCOMPtr<nsIDOMDocumentType> docType;
|
|
|
|
|
|
|
|
// Create a new doctype node
|
|
|
|
rv = NS_NewDOMDocumentType(getter_AddRefs(docType),
|
|
|
|
name, nsnull, nsnull,
|
|
|
|
publicId, systemId, str);
|
|
|
|
if (NS_FAILED(rv) || !docType) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
nsAutoString data(aData); // XXX replace this with nsDependentString. Change nsParserUtils APIs
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> node;
|
2001-01-04 00:30:11 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// ParseProcessingInstruction(text, target, data);
|
|
|
|
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);
|
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);
|
|
|
|
result = ssle->UpdateStyleSheet(PR_TRUE, mDocument, mStyleSheetCount);
|
|
|
|
if (NS_SUCCEEDED(result) || (result == NS_ERROR_HTMLPARSER_BLOCK))
|
|
|
|
mStyleSheetCount++; // This count may not reflect the real stylesheet count
|
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
if (result == NS_ERROR_HTMLPARSER_BLOCK && mParser) {
|
|
|
|
mParser->BlockParser();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2001-09-05 04:20:54 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// If it's a XSL stylesheet PI...
|
|
|
|
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-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;
|
(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
|
|
|
NS_NAMED_LITERAL_STRING(name, "xmlns");
|
|
|
|
NS_NAMED_LITERAL_STRING(value, "http://www.w3.org/1999/xhtml");
|
2000-01-21 01:32:32 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
const PRUnichar* atts[] = {name.get(), value.get(), 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
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
mState = eXMLContentSinkState_InProlog;
|
|
|
|
NS_IF_RELEASE(mDocElement); // Do this inorder to set the <parsererror> as the document root
|
|
|
|
|
|
|
|
rv = HandleStartElement(NS_LITERAL_STRING("parsererror").get(), atts, 1, -1, -1);
|
|
|
|
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);
|
|
|
|
|
|
|
|
rv = HandleStartElement(NS_LITERAL_STRING("sourcetext").get(), atts, 1, -1, -1);
|
|
|
|
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 {
|
|
|
|
nsCOMPtr<nsINameSpaceManager> manager;
|
|
|
|
mDocument->GetNameSpaceManager(*getter_AddRefs(manager));
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ASSERTION(manager, "no name space manager in document");
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (manager) {
|
|
|
|
rv = manager->CreateRootNameSpace(*getter_AddRefs(nameSpace));
|
|
|
|
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;
|
|
|
|
|
|
|
|
prefixAtom =
|
|
|
|
dont_AddRef(NS_NewAtom(nsDependentSubstring(start, end)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINameSpace> child;
|
|
|
|
rv = nameSpace->CreateChildNameSpace(prefixAtom, nsDependentString(aAtts[1]),
|
|
|
|
*getter_AddRefs(child));
|
|
|
|
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,
|
|
|
|
nsIContent* aContent,
|
|
|
|
PRBool aIsHTML)
|
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;
|
|
|
|
nameAtom = dont_AddRef(NS_NewAtom(key));
|
|
|
|
nameSpacePrefix = nsnull;
|
|
|
|
} else if ((kNameSpaceID_XMLNS == nameSpaceID) && aIsHTML) {
|
|
|
|
// Ooh, what a nice little hack we have here :-)
|
|
|
|
nsAutoString name;
|
|
|
|
nameAtom->ToString(name);
|
|
|
|
nameAtom = dont_AddRef(NS_NewAtom(NS_LITERAL_STRING("xmlns:") + name));
|
|
|
|
nameSpaceID = kNameSpaceID_HTML; // XXX this is wrong, but necessary until HTML can store other namespaces for attrs
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> ni;
|
|
|
|
mNodeInfoManager->GetNodeInfo(nameAtom, nameSpacePrefix, nameSpaceID,
|
|
|
|
*getter_AddRefs(ni));
|
|
|
|
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
|
|
|
|
if (mWebShell) {
|
|
|
|
nsCOMPtr<nsIXMLContent> xmlcontent(do_QueryInterface(aContent));
|
|
|
|
if (xmlcontent) {
|
|
|
|
nsresult rv = xmlcontent->MaybeTriggerAutoLink(mWebShell);
|
|
|
|
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);
|
|
|
|
} else if (mStyleElement) {
|
|
|
|
mStyleText.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAReadableString& str = Substring(aText, aText+aLength);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::ProcessSTYLETag()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsAutoString title;
|
|
|
|
nsAutoString type;
|
|
|
|
nsAutoString media;
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
mStyleElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::title, title);
|
|
|
|
title.CompressWhitespace();
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
mStyleElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, type);
|
|
|
|
type.StripWhitespace();
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
mStyleElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::media, media);
|
|
|
|
ToLowerCase(media);
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsAutoString mimeType;
|
|
|
|
nsAutoString params;
|
|
|
|
nsStyleLinkElement::SplitMimeType(type, mimeType, params);
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
PRBool blockParser = PR_FALSE;//kBlockByDefault;
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (mimeType.IsEmpty() || mimeType.EqualsIgnoreCase("text/css")) {
|
|
|
|
if (!title.IsEmpty()) { // possibly preferred sheet
|
|
|
|
nsAutoString preferredStyle;
|
|
|
|
mDocument->GetHeaderData(nsHTMLAtoms::headerDefaultStyle, preferredStyle);
|
|
|
|
if (preferredStyle.IsEmpty()) {
|
|
|
|
mDocument->SetHeaderData(nsHTMLAtoms::headerDefaultStyle, title);
|
|
|
|
}
|
|
|
|
}
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
PRBool doneLoading = PR_FALSE;
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsIUnicharInputStream* uin = nsnull;
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Create a string to hold the data and wrap it up in a unicode
|
|
|
|
// input stream.
|
|
|
|
rv = NS_NewStringUnicharInputStream(&uin, new nsString(mStyleText));
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Now that we have a url and a unicode input stream, parse the
|
|
|
|
// style sheet.
|
|
|
|
rv = mCSSLoader->LoadInlineStyle(mStyleElement, uin, title, media, kNameSpaceID_Unknown,
|
|
|
|
mStyleSheetCount++,
|
|
|
|
((blockParser) ? mParser : nsnull),
|
|
|
|
doneLoading, this);
|
|
|
|
NS_RELEASE(uin);
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && blockParser && (! doneLoading)) {
|
|
|
|
if (mParser) {
|
|
|
|
mParser->BlockParser();
|
|
|
|
}
|
|
|
|
rv = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
|
|
|
}//if (mimeType.IsEmpty() || mimeType.EqualsIgnoreCase("text/css"))
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-10-05 00:12:21 +00:00
|
|
|
|
|
|
|
nsresult
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::ProcessEndSCRIPTTag()
|
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-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIContent> element(dont_AddRef(GetCurrentContent()));
|
|
|
|
nsCOMPtr<nsIDOMHTMLScriptElement> scriptElement(do_QueryInterface(element));
|
|
|
|
NS_ASSERTION(scriptElement, "null script element in XML content sink");
|
|
|
|
mScriptElements.AppendElement(scriptElement);
|
1999-10-05 00:12:21 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIScriptElement> sele(do_QueryInterface(element));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::ProcessStartSCRIPTTag(PRUint32 aLineNo)
|
2000-01-19 04:44:10 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
// Wait until we get the script content
|
|
|
|
mConstrainSize = PR_FALSE;
|
|
|
|
mScriptLineNo = aLineNo;
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-01-19 19:17:22 +00:00
|
|
|
}
|