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"
|
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"
|
2002-03-27 06:19:14 +00:00
|
|
|
#include "nsICookieService.h"
|
|
|
|
#include "nsIPrompt.h"
|
|
|
|
#include "nsIDOMWindowInternal.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIHttpChannel.h"
|
2002-07-02 17:58:24 +00:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIAggregatePrincipal.h"
|
|
|
|
#include "nsICodebasePrincipal.h"
|
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 = ':';
|
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,
|
2002-03-27 06:19:14 +00:00
|
|
|
nsIWebShell* aWebShell,
|
|
|
|
nsIChannel* aChannel)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsXMLContentSink* it;
|
|
|
|
NS_NEWXPCOM(it, nsXMLContentSink);
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-03-27 06:19:14 +00:00
|
|
|
nsresult rv = it->Init(aDoc, aURL, aWebShell, aChannel);
|
1998-11-11 22:06:16 +00:00
|
|
|
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) {
|
2002-05-20 22:47:02 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
nsServiceManager::GetService(kNameSpaceManagerCID,
|
|
|
|
NS_GET_IID(nsINameSpaceManager),
|
|
|
|
(nsISupports**) &gNameSpaceManager);
|
|
|
|
|
2000-01-19 04:44:10 +00:00
|
|
|
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
|
|
|
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;
|
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(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,
|
2002-03-27 06:19:14 +00:00
|
|
|
nsIWebShell* aContainer,
|
|
|
|
nsIChannel* aChannel)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
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;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2002-03-27 06:19:14 +00:00
|
|
|
ProcessHTTPHeaders(aChannel);
|
|
|
|
|
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)
|
2002-06-20 12:04:22 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITransformObserver)
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptLoaderObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXMLContentSink)
|
1999-12-07 14:06:36 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
1998-11-11 22:06:16 +00:00
|
|
|
|
|
|
|
// nsIContentSink
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
1998-11-11 22:06:16 +00:00
|
|
|
nsXMLContentSink::WillBuildModel(void)
|
|
|
|
{
|
|
|
|
// Notify document that the load is beginning
|
|
|
|
mDocument->BeginLoad();
|
1999-07-14 17:59:19 +00:00
|
|
|
return NS_OK;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2001-08-01 23:04:32 +00:00
|
|
|
// This function's implementation is in nsHTMLContentSink.cpp
|
|
|
|
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
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
// Kick off layout for non-XSLT transformed documents.
|
2002-04-15 22:53:58 +00:00
|
|
|
if (!mXSLTransformMediator || NS_FAILED(rv)) {
|
2002-06-20 12:04:22 +00:00
|
|
|
nsCOMPtr<nsIScriptLoader> loader;
|
|
|
|
mDocument->GetScriptLoader(getter_AddRefs(loader));
|
|
|
|
if (loader) {
|
|
|
|
loader->RemoveObserver(this);
|
|
|
|
}
|
|
|
|
|
2002-04-15 22:53:58 +00:00
|
|
|
StartLayout();
|
|
|
|
|
2002-04-16 22:21:54 +00:00
|
|
|
#if 0 /* Disable until this works for XML */
|
2002-04-15 22:53:58 +00:00
|
|
|
// Scroll to Anchor only if the document was *not* loaded through history means.
|
2002-04-04 22:10:10 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
|
|
|
if (docShell) {
|
2002-04-15 22:53:58 +00:00
|
|
|
PRUint32 documentLoadType = 0;
|
2002-04-04 22:10:10 +00:00
|
|
|
docShell->GetLoadType(&documentLoadType);
|
2002-04-15 22:53:58 +00:00
|
|
|
if (!(documentLoadType & nsIDocShell::LOAD_CMD_HISTORY)) {
|
|
|
|
ScrollToRef();
|
|
|
|
}
|
2002-04-04 22:10:10 +00:00
|
|
|
}
|
2002-04-16 22:21:54 +00:00
|
|
|
#else
|
|
|
|
ScrollToRef();
|
|
|
|
#endif
|
2002-04-15 22:53:58 +00:00
|
|
|
|
2000-09-02 15:34:07 +00:00
|
|
|
mDocument->EndLoad();
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:59:19 +00:00
|
|
|
// Ref. Bug 49115
|
|
|
|
// Do this hack to make sure that the parser
|
|
|
|
// doesn't get destroyed, accidently, before
|
|
|
|
// the circularity, between sink & parser, is
|
2002-06-20 12:04:22 +00:00
|
|
|
// actually broken.
|
2001-08-31 00:59:19 +00:00
|
|
|
nsCOMPtr<nsIParser> kungFuDeathGrip(mParser);
|
|
|
|
|
1998-12-11 17:02:37 +00:00
|
|
|
// Drop our reference to the parser to get rid of a circular
|
|
|
|
// reference.
|
|
|
|
NS_IF_RELEASE(mParser);
|
1999-06-28 14:49:29 +00:00
|
|
|
|
1998-11-11 22:06:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-28 14:49:29 +00:00
|
|
|
NS_IMETHODIMP
|
2002-06-20 12:04:22 +00:00
|
|
|
nsXMLContentSink::OnTransformDone(nsresult aResult,
|
|
|
|
nsIDOMDocument* aResultDocument)
|
1999-06-28 14:49:29 +00:00
|
|
|
{
|
2002-06-20 12:04:22 +00:00
|
|
|
NS_ASSERTION(NS_FAILED(aResult) || aResultDocument,
|
|
|
|
"Don't notify about transform success without a document.");
|
2000-09-16 20:53:08 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
// Reset the observer on the transform mediator
|
|
|
|
mXSLTransformMediator->SetTransformObserver(nsnull);
|
2002-04-25 11:58:08 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2001-03-12 06:34:40 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
if (NS_FAILED(aResult) && contentViewer) {
|
|
|
|
// Transform failed.
|
|
|
|
if (aResultDocument) {
|
|
|
|
// We have an error document.
|
|
|
|
contentViewer->SetDOMDocument(aResultDocument);
|
2000-09-02 15:34:07 +00:00
|
|
|
}
|
2002-06-20 12:04:22 +00:00
|
|
|
else {
|
|
|
|
// We don't have an error document, display the
|
|
|
|
// untransformed source document.
|
|
|
|
nsCOMPtr<nsIDOMDocument> document = do_QueryInterface(mDocument);
|
|
|
|
contentViewer->SetDOMDocument(document);
|
|
|
|
}
|
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
nsCOMPtr<nsIDocument> originalDocument = mDocument;
|
|
|
|
if (NS_SUCCEEDED(aResult) || aResultDocument) {
|
|
|
|
// Transform succeeded or it failed and we have an error
|
|
|
|
// document to display.
|
|
|
|
NS_RELEASE(mDocument);
|
|
|
|
CallQueryInterface(aResultDocument, &mDocument); // addrefs
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Transform failed and we don't have an error document, display the
|
|
|
|
// untransformed source document.
|
|
|
|
mDocument->SetRootContent(mDocElement);
|
|
|
|
}
|
2000-09-02 15:34:07 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
nsCOMPtr<nsIScriptLoader> loader;
|
|
|
|
originalDocument->GetScriptLoader(getter_AddRefs(loader));
|
|
|
|
if (loader) {
|
|
|
|
loader->RemoveObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start the layout process
|
|
|
|
StartLayout();
|
2002-04-25 11:58:08 +00:00
|
|
|
|
|
|
|
#if 0 /* Disable until this works for XML */
|
2002-06-20 12:04:22 +00:00
|
|
|
// Scroll to Anchor only if the document was *not* loaded through history means.
|
|
|
|
PRUint32 documentLoadType = 0;
|
|
|
|
docShell->GetLoadType(&documentLoadType);
|
|
|
|
if (!(documentLoadType & nsIDocShell::LOAD_CMD_HISTORY)) {
|
|
|
|
ScrollToRef();
|
|
|
|
}
|
2002-04-25 11:58:08 +00:00
|
|
|
#else
|
2002-06-20 12:04:22 +00:00
|
|
|
ScrollToRef();
|
2002-04-25 11:58:08 +00:00
|
|
|
#endif
|
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
originalDocument->EndLoad();
|
2002-04-25 11:58:08 +00:00
|
|
|
|
2002-06-20 12:04:22 +00:00
|
|
|
return NS_OK;
|
1999-06-28 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2001-03-12 06:34:40 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mWebShell));
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
2002-06-20 12:04:22 +00:00
|
|
|
docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
|
|
|
if (contentViewer) {
|
2001-03-12 06:34:40 +00:00
|
|
|
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
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXMLContentSink::SplitXMLName(const nsAString& aString, nsIAtom **aPrefix,
|
2001-10-16 05:55:04 +00:00
|
|
|
nsIAtom **aLocalName)
|
1998-12-11 02:53:49 +00:00
|
|
|
{
|
2001-10-16 05:55:04 +00:00
|
|
|
nsReadingIterator<PRUnichar> iter, end;
|
|
|
|
|
|
|
|
aString.BeginReading(iter);
|
|
|
|
aString.EndReading(end);
|
|
|
|
|
|
|
|
FindCharInReadable(kNameSpaceSeparator, iter, end);
|
|
|
|
|
|
|
|
if (iter != end) {
|
|
|
|
nsReadingIterator<PRUnichar> start;
|
|
|
|
|
|
|
|
aString.BeginReading(start);
|
|
|
|
|
|
|
|
*aPrefix = NS_NewAtom(nsDependentSubstring(start, iter));
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
*aLocalName = NS_NewAtom(nsDependentSubstring(iter, end));
|
|
|
|
|
|
|
|
return;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2001-10-16 05:55:04 +00:00
|
|
|
|
|
|
|
*aPrefix = nsnull;
|
|
|
|
*aLocalName = NS_NewAtom(aString);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
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
|
|
|
// 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
|
|
|
// 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);
|
2002-03-27 06:19:14 +00:00
|
|
|
} else if (aType.Equals(NS_LITERAL_STRING("text/css"))) {
|
|
|
|
nsCOMPtr<nsIURI> url;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(url), aHref, nsnull, mDocumentBaseURL);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_OK; // The URL is bad, move along, don't propagate the error (for now)
|
|
|
|
}
|
|
|
|
PRBool doneLoading;
|
|
|
|
rv = mCSSLoader->LoadStyleLink(aElement, url, aTitle, aMedia, kNameSpaceID_Unknown,
|
|
|
|
mStyleSheetCount++,
|
|
|
|
((!aAlternate) ? mParser : nsnull),
|
|
|
|
doneLoading,
|
|
|
|
this);
|
|
|
|
if (NS_SUCCEEDED(rv) || (rv == NS_ERROR_HTMLPARSER_BLOCK)) {
|
|
|
|
if (rv == NS_ERROR_HTMLPARSER_BLOCK && mParser) {
|
|
|
|
mParser->BlockParser();
|
|
|
|
}
|
|
|
|
mStyleSheetCount++;
|
|
|
|
}
|
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;
|
|
|
|
|
2002-04-05 11:29:40 +00:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mBaseElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::target, value)) {
|
2002-01-09 01:37:50 +00:00
|
|
|
mDocument->SetBaseTarget(value);
|
|
|
|
}
|
|
|
|
|
2002-04-05 11:29:40 +00:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == mBaseElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::href, value)) {
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(baseURI), value);
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = mDocument->SetBaseURL(baseURI); // The document checks if it is legal to set this base
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
NS_IF_RELEASE(mDocumentBaseURL);
|
|
|
|
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-03-27 11:01:09 +00:00
|
|
|
static PRBool IsAlternateHTTPStyleSheetHeader(const nsAString& aRel)
|
2002-03-27 06:19:14 +00:00
|
|
|
{
|
|
|
|
nsStringArray linkTypes;
|
|
|
|
nsStyleLinkElement::ParseLinkTypes(aRel, linkTypes);
|
|
|
|
if (-1 != linkTypes.IndexOf(NS_LITERAL_STRING("stylesheet"))) { // is it a stylesheet link?
|
|
|
|
|
|
|
|
if (-1 != linkTypes.IndexOf(NS_LITERAL_STRING("alternate"))) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Copied from HTML, should be shared
|
|
|
|
static const PRUnichar kSemiCh = PRUnichar(';');
|
|
|
|
static const PRUnichar kCommaCh = PRUnichar(',');
|
|
|
|
static const PRUnichar kEqualsCh = PRUnichar('=');
|
|
|
|
static const PRUnichar kLessThanCh = PRUnichar('<');
|
|
|
|
static const PRUnichar kGreaterThanCh = PRUnichar('>');
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::ProcessLink(nsIHTMLContent* aElement,
|
|
|
|
const nsAString& aLinkData)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
// parse link content and call process style link
|
|
|
|
nsAutoString href;
|
|
|
|
nsAutoString rel;
|
|
|
|
nsAutoString title;
|
|
|
|
nsAutoString type;
|
|
|
|
nsAutoString media;
|
|
|
|
PRBool didBlock = PR_FALSE;
|
|
|
|
|
|
|
|
nsAutoString stringList(aLinkData); // copy to work buffer
|
|
|
|
|
|
|
|
stringList.Append(kNullCh); // put an extra null at the end
|
|
|
|
|
|
|
|
PRUnichar* start = (PRUnichar*)(const PRUnichar*)stringList.get();
|
|
|
|
PRUnichar* end = start;
|
|
|
|
PRUnichar* last = start;
|
|
|
|
PRUnichar endCh;
|
|
|
|
|
|
|
|
while (kNullCh != *start) {
|
|
|
|
while ((kNullCh != *start) && nsCRT::IsAsciiSpace(*start)) { // skip leading space
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
|
|
|
|
end = start;
|
|
|
|
last = end - 1;
|
|
|
|
|
|
|
|
while ((kNullCh != *end) && (kSemiCh != *end) && (kCommaCh != *end)) { // look for semicolon or comma
|
|
|
|
if ((kApostrophe == *end) || (kQuote == *end) ||
|
|
|
|
(kLessThanCh == *end)) { // quoted string
|
|
|
|
PRUnichar quote = *end;
|
|
|
|
if (kLessThanCh == quote) {
|
|
|
|
quote = kGreaterThanCh;
|
|
|
|
}
|
|
|
|
PRUnichar* closeQuote = (end + 1);
|
|
|
|
while ((kNullCh != *closeQuote) && (quote != *closeQuote)) {
|
|
|
|
closeQuote++; // seek closing quote
|
|
|
|
}
|
|
|
|
if (quote == *closeQuote) { // found closer
|
|
|
|
end = closeQuote; // skip to close quote
|
|
|
|
last = end - 1;
|
|
|
|
if ((kSemiCh != *(end + 1)) && (kNullCh != *(end + 1)) && (kCommaCh != *(end + 1))) {
|
|
|
|
*(++end) = kNullCh; // end string here
|
|
|
|
while ((kNullCh != *(end + 1)) && (kSemiCh != *(end + 1)) &&
|
|
|
|
(kCommaCh != *(end + 1))) { // keep going until semi or comma
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end++;
|
|
|
|
last++;
|
|
|
|
}
|
|
|
|
|
|
|
|
endCh = *end;
|
|
|
|
*end = kNullCh; // end string here
|
|
|
|
|
|
|
|
if (start < end) {
|
|
|
|
if ((kLessThanCh == *start) && (kGreaterThanCh == *last)) {
|
|
|
|
*last = kNullCh;
|
|
|
|
if (href.IsEmpty()) { // first one wins
|
|
|
|
href = (start + 1);
|
|
|
|
href.StripWhitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRUnichar* equals = start;
|
|
|
|
while ((kNullCh != *equals) && (kEqualsCh != *equals)) {
|
|
|
|
equals++;
|
|
|
|
}
|
|
|
|
if (kNullCh != *equals) {
|
|
|
|
*equals = kNullCh;
|
|
|
|
nsAutoString attr(start);
|
|
|
|
attr.StripWhitespace();
|
|
|
|
|
|
|
|
PRUnichar* value = ++equals;
|
|
|
|
while (nsCRT::IsAsciiSpace(*value)) {
|
|
|
|
value++;
|
|
|
|
}
|
|
|
|
if (((kApostrophe == *value) || (kQuote == *value)) &&
|
|
|
|
(*value == *last)) {
|
|
|
|
*last = kNullCh;
|
|
|
|
value++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr.EqualsIgnoreCase("rel")) {
|
|
|
|
if (rel.IsEmpty()) {
|
|
|
|
rel = value;
|
|
|
|
rel.CompressWhitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attr.EqualsIgnoreCase("title")) {
|
|
|
|
if (title.IsEmpty()) {
|
|
|
|
title = value;
|
|
|
|
title.CompressWhitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attr.EqualsIgnoreCase("type")) {
|
|
|
|
if (type.IsEmpty()) {
|
|
|
|
type = value;
|
|
|
|
type.StripWhitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attr.EqualsIgnoreCase("media")) {
|
|
|
|
if (media.IsEmpty()) {
|
|
|
|
media = value;
|
|
|
|
ToLowerCase(media); // HTML4.0 spec is inconsistent, make it case INSENSITIVE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (kCommaCh == endCh) { // hit a comma, process what we've got so far
|
|
|
|
if (!href.IsEmpty()) {
|
|
|
|
result = ProcessStyleLink(
|
|
|
|
aElement,
|
|
|
|
href,
|
|
|
|
!title.IsEmpty() && IsAlternateHTTPStyleSheetHeader(rel),
|
|
|
|
title,
|
|
|
|
type,
|
|
|
|
media);
|
|
|
|
if (NS_ERROR_HTMLPARSER_BLOCK == result) {
|
|
|
|
didBlock = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
href.Truncate();
|
|
|
|
rel.Truncate();
|
|
|
|
title.Truncate();
|
|
|
|
type.Truncate();
|
|
|
|
media.Truncate();
|
|
|
|
}
|
|
|
|
|
|
|
|
start = ++end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!href.IsEmpty()) {
|
|
|
|
result = ProcessStyleLink(
|
|
|
|
aElement,
|
|
|
|
href,
|
|
|
|
!title.IsEmpty() && IsAlternateHTTPStyleSheetHeader(rel),
|
|
|
|
title,
|
|
|
|
type,
|
|
|
|
media);
|
|
|
|
if (NS_SUCCEEDED(result) && didBlock) {
|
|
|
|
result = NS_ERROR_HTMLPARSER_BLOCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Copied from HTML, should be shared
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAString& 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)");
|
2002-08-06 13:51:48 +00:00
|
|
|
|
|
|
|
mDocument->SetHeaderData(aHeader, aValue);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
// 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-03-20 22:50:33 +00:00
|
|
|
rv = reefer->SetupRefreshURIFromHeader(baseURI, NS_ConvertUCS2toUTF8(aValue));
|
2002-01-09 01:37:50 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
} // END refresh
|
2002-03-27 06:19:14 +00:00
|
|
|
else if (aHeader == nsHTMLAtoms::setcookie) {
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(mWebShell, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsCOMPtr<nsICookieService> cookieServ = do_GetService(NS_COOKIESERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-07-02 17:58:24 +00:00
|
|
|
// Get a URI from the document principal
|
|
|
|
// We use the original codebase in case the codebase was changed by SetDomain
|
|
|
|
nsCOMPtr<nsIPrincipal> docPrincipal;
|
|
|
|
rv = mDocument->GetPrincipal(getter_AddRefs(docPrincipal));
|
2002-03-27 06:19:14 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-07-02 17:58:24 +00:00
|
|
|
if (!docPrincipal) return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAggregatePrincipal> agg(do_QueryInterface(docPrincipal, &rv));
|
|
|
|
// Document principal should always be an aggregate
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> originalPrincipal;
|
|
|
|
rv = agg->GetOriginalCodebase(getter_AddRefs(originalPrincipal));
|
|
|
|
nsCOMPtr<nsICodebasePrincipal> originalCodebase(
|
|
|
|
do_QueryInterface(originalPrincipal, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Document's principal is not a codebase (may be system), so can't set cookies
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
|
|
|
rv = originalCodebase->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-03-27 06:19:14 +00:00
|
|
|
char *cookie = ToNewUTF8String(aValue);
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObj;
|
|
|
|
nsCOMPtr<nsIPrompt> prompt;
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj));
|
|
|
|
if (globalObj) {
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> window (do_QueryInterface(globalObj));
|
|
|
|
if (window) {
|
|
|
|
window->GetPrompter(getter_AddRefs(prompt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel;
|
|
|
|
if (mParser) {
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
if (NS_SUCCEEDED(mParser->GetChannel(getter_AddRefs(channel)))) {
|
|
|
|
httpChannel = do_QueryInterface(channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-02 17:58:24 +00:00
|
|
|
rv = cookieServ->SetCookieString(codebaseURI, prompt, cookie, httpChannel);
|
2002-03-27 06:19:14 +00:00
|
|
|
nsCRT::free(cookie);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
} // END set-cookie
|
|
|
|
else if (aHeader == nsHTMLAtoms::link) {
|
|
|
|
rv = ProcessLink(aContent, aValue);
|
|
|
|
}
|
|
|
|
else if (mParser) {
|
|
|
|
// we also need to report back HTTP-EQUIV headers to the channel
|
|
|
|
// so that it can process things like pragma: no-cache or other
|
|
|
|
// cache-control headers. Ideally this should also be the way for
|
|
|
|
// cookies to be set! But we'll worry about that in the next
|
|
|
|
// iteration
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
if (NS_SUCCEEDED(mParser->GetChannel(getter_AddRefs(channel)))) {
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
|
|
|
|
if (httpChannel) {
|
|
|
|
const PRUnichar *header = 0;
|
|
|
|
(void)aHeader->GetUnicode(&header);
|
|
|
|
(void)httpChannel->SetResponseHeader(
|
|
|
|
NS_ConvertUCS2toUTF8(header),
|
|
|
|
NS_ConvertUCS2toUTF8(aValue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Copied from HTML content sink, should be shared
|
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::ProcessHTTPHeaders(nsIChannel* aChannel) {
|
|
|
|
nsresult rv=NS_OK;
|
|
|
|
|
|
|
|
if(aChannel) {
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpchannel(do_QueryInterface(aChannel));
|
|
|
|
if (httpchannel) {
|
2002-08-06 13:51:48 +00:00
|
|
|
const char *const headers[] = {
|
|
|
|
"link",
|
|
|
|
"default-style",
|
|
|
|
"content-style-type",
|
|
|
|
// add more http headers if you need
|
|
|
|
0};
|
2002-03-27 06:19:14 +00:00
|
|
|
const char *const *name=headers;
|
|
|
|
nsCAutoString tmp;
|
|
|
|
|
|
|
|
while(*name) {
|
|
|
|
rv = httpchannel->GetResponseHeader(nsDependentCString(*name), tmp);
|
|
|
|
if (NS_SUCCEEDED(rv) && !tmp.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIAtom> key(dont_AddRef(NS_NewAtom(*name)));
|
|
|
|
ProcessHeaderData(key,NS_ConvertASCIItoUCS2(tmp),nsnull);
|
|
|
|
}
|
|
|
|
name++;
|
|
|
|
}//while
|
|
|
|
}//if - httpchannel
|
|
|
|
}//if - channel
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
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;
|
2002-04-05 11:29:40 +00:00
|
|
|
mMetaElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::httpEquiv, header);
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!header.IsEmpty()) {
|
2002-01-09 01:37:50 +00:00
|
|
|
nsAutoString result;
|
2002-04-05 11:29:40 +00:00
|
|
|
mMetaElement->GetAttr(kNameSpaceID_None, nsHTMLAtoms::content, result);
|
2002-01-24 02:03:19 +00:00
|
|
|
if (!result.IsEmpty()) {
|
2002-01-09 01:37:50 +00:00
|
|
|
ToLowerCase(header);
|
|
|
|
nsCOMPtr<nsIAtom> fieldAtom(dont_AddRef(NS_NewAtom(header)));
|
|
|
|
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
|
2002-03-23 22:46:13 +00:00
|
|
|
nsXMLContentSink::SetDocumentCharset(nsAString& aCharset)
|
2002-01-09 01:37:50 +00:00
|
|
|
{
|
|
|
|
if (mDocument) {
|
|
|
|
return mDocument->SetDocumentCharacterSet(aCharset);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-16 06:16:17 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRBool didFlush = PR_FALSE;
|
|
|
|
if (0 != mTextLength) {
|
|
|
|
if (aCreateTextNode) {
|
|
|
|
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
|
|
|
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-04-04 15:42:45 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
2001-02-28 23:51:35 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
XMLElementFactoryImpl* result = new XMLElementFactoryImpl();
|
2002-04-04 15:42:45 +00:00
|
|
|
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
*aResult = result;
|
2002-04-04 15:42:45 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-05-19 02:59:15 +00:00
|
|
|
|
2001-02-28 23:51:35 +00:00
|
|
|
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
XMLElementFactoryImpl::CreateInstanceByTag(nsINodeInfo *aNodeInfo,
|
|
|
|
nsIContent** aResult)
|
|
|
|
{
|
|
|
|
return NS_NewXMLElement(aResult, aNodeInfo);
|
|
|
|
}
|
2001-02-28 23:51:35 +00:00
|
|
|
|
2002-04-04 15:42:45 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_MATHML
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// MathML Element Factory - temporary location for bug 132844
|
|
|
|
// Will be factored out post 1.0
|
|
|
|
|
|
|
|
class MathMLElementFactoryImpl : public nsIElementFactory
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
MathMLElementFactoryImpl();
|
|
|
|
virtual ~MathMLElementFactoryImpl();
|
|
|
|
|
|
|
|
public:
|
|
|
|
friend
|
|
|
|
nsresult
|
|
|
|
NS_NewMathMLElementFactory(nsIElementFactory** aResult);
|
|
|
|
|
|
|
|
// nsISupports interface
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIElementFactory interface
|
|
|
|
NS_IMETHOD CreateInstanceByTag(nsINodeInfo *aNodeInfo, nsIContent** aResult);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
MathMLElementFactoryImpl::MathMLElementFactoryImpl()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
MathMLElementFactoryImpl::~MathMLElementFactoryImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(MathMLElementFactoryImpl, nsIElementFactory)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewMathMLElementFactory(nsIElementFactory** aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
|
|
|
|
MathMLElementFactoryImpl* result = new MathMLElementFactoryImpl();
|
|
|
|
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
*aResult = result;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MathMLElementFactoryImpl::CreateInstanceByTag(nsINodeInfo* aNodeInfo,
|
|
|
|
nsIContent** aResult)
|
|
|
|
{
|
|
|
|
static const char kMathMLStyleSheetURI[] = "resource:///res/mathml.css";
|
|
|
|
|
|
|
|
// this bit of code is to load mathml.css on demand
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
aNodeInfo->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (doc) {
|
|
|
|
PRBool alreadyLoaded = PR_FALSE;
|
|
|
|
PRInt32 i = 0, sheetCount = 0;
|
|
|
|
doc->GetNumberOfStyleSheets(&sheetCount);
|
|
|
|
for (; i < sheetCount; i++) {
|
|
|
|
nsCOMPtr<nsIStyleSheet> sheet;
|
|
|
|
doc->GetStyleSheetAt(i, getter_AddRefs(sheet));
|
|
|
|
NS_ASSERTION(sheet, "unexpected null stylesheet in the document");
|
|
|
|
if (sheet) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
sheet->GetURL(*getter_AddRefs(uri));
|
|
|
|
nsCAutoString uriStr;
|
|
|
|
uri->GetSpec(uriStr);
|
|
|
|
if (uriStr.Equals(kMathMLStyleSheetURI)) {
|
|
|
|
alreadyLoaded = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!alreadyLoaded) {
|
|
|
|
nsCOMPtr<nsIHTMLContentContainer> htmlContainer(do_QueryInterface(doc));
|
|
|
|
if (htmlContainer) {
|
|
|
|
nsCOMPtr<nsICSSLoader> cssLoader;
|
|
|
|
htmlContainer->GetCSSLoader(*getter_AddRefs(cssLoader));
|
|
|
|
if (cssLoader) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), kMathMLStyleSheetURI);
|
|
|
|
if (uri) {
|
|
|
|
PRBool complete;
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
|
|
|
cssLoader->LoadAgentSheet(uri, *getter_AddRefs(sheet), complete, nsnull);
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsCAutoString uriStr;
|
|
|
|
uri->GetSpec(uriStr);
|
|
|
|
printf("MathML Factory: loading catalog stylesheet: %s ... %s\n", uriStr.get(), sheet.get() ? "Done" : "Failed");
|
|
|
|
NS_ASSERTION(uriStr.Equals(kMathMLStyleSheetURI), "resolved URI unexpected");
|
|
|
|
#endif
|
|
|
|
if (sheet) {
|
|
|
|
doc->AddStyleSheet(sheet, NS_STYLESHEET_FROM_CATALOG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NewXMLElement(aResult, aNodeInfo);
|
|
|
|
}
|
|
|
|
#endif // MOZ_MATHML
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
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 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));
|
|
|
|
|
2002-05-20 22:47:02 +00:00
|
|
|
const PRBool isXHTML = nameSpaceID == kNameSpaceID_XHTML;
|
2002-01-09 01:37:50 +00:00
|
|
|
|
2002-05-20 22:47:02 +00:00
|
|
|
if (isXHTML) {
|
2002-01-09 01:37:50 +00:00
|
|
|
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);
|
|
|
|
|
2002-04-05 11:29:40 +00:00
|
|
|
if (tagAtom == nsHTMLAtoms::base) {
|
2002-01-09 01:37:50 +00:00
|
|
|
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-05-20 22:47:02 +00:00
|
|
|
if (isXHTML &&
|
2002-04-25 11:58:08 +00:00
|
|
|
((tagAtom == nsHTMLAtoms::link) ||
|
|
|
|
(tagAtom == nsHTMLAtoms::style))) {
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(content));
|
2001-04-30 23:35:09 +00:00
|
|
|
|
2002-04-25 11:58:08 +00:00
|
|
|
if (ssle) {
|
|
|
|
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
|
2002-05-20 22:47:02 +00:00
|
|
|
result = AddAttributes(aAtts, content, isXHTML);
|
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
|
2002-05-20 22:47:02 +00:00
|
|
|
if ((aIndex != (PRUint32)-1) && NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIAtom> IDAttr =
|
|
|
|
dont_AddRef(NS_NewAtom((const PRUnichar *)aAtts[aIndex]));
|
|
|
|
|
|
|
|
if (IDAttr) {
|
2002-01-09 01:37:50 +00:00
|
|
|
result = nodeInfo->SetIDAttributeAtom(IDAttr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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()));
|
2002-04-25 11:58:08 +00:00
|
|
|
nsCOMPtr<nsIAtom> tagAtom;
|
2001-07-04 19:35:23 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (currentContent && currentContent->IsContentOfType(nsIContent::eHTML)) {
|
|
|
|
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;
|
|
|
|
}
|
2002-04-05 11:29:40 +00:00
|
|
|
} else if (tagAtom == nsHTMLAtoms::base) {
|
2002-01-09 01:37:50 +00:00
|
|
|
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-04-25 11:58:08 +00:00
|
|
|
if (currentContent &&
|
|
|
|
currentContent->IsContentOfType(nsIContent::eHTML) &&
|
|
|
|
((tagAtom == nsHTMLAtoms::link) ||
|
|
|
|
(tagAtom == nsHTMLAtoms::style))) {
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(content));
|
2002-04-12 13:24:32 +00:00
|
|
|
|
2002-04-25 11:58:08 +00:00
|
|
|
if (ssle) {
|
|
|
|
ssle->SetEnableUpdates(PR_TRUE);
|
|
|
|
result = ssle->UpdateStyleSheet(nsnull, mStyleSheetCount);
|
|
|
|
if (NS_SUCCEEDED(result) || (result == NS_ERROR_HTMLPARSER_BLOCK)) {
|
|
|
|
if (result == NS_ERROR_HTMLPARSER_BLOCK && mParser) {
|
|
|
|
mParser->BlockParser();
|
|
|
|
}
|
|
|
|
mStyleSheetCount++;
|
2002-04-12 13:24:32 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-22 00:46:16 +00:00
|
|
|
nsXMLContentSink::HandleDoctypeDecl(const nsAString & aSubset,
|
|
|
|
const nsAString & aName,
|
|
|
|
const nsAString & aSystemId,
|
|
|
|
const nsAString & aPublicId,
|
2002-03-15 09:45:31 +00:00
|
|
|
nsISupports* aCatalogData)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2000-06-17 01:49:19 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(mDocument));
|
|
|
|
if (!doc)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocumentType> docType;
|
|
|
|
|
|
|
|
// Create a new doctype node
|
|
|
|
rv = NS_NewDOMDocumentType(getter_AddRefs(docType),
|
2002-05-22 00:46:16 +00:00
|
|
|
aName, nsnull, nsnull,
|
|
|
|
aPublicId, aSystemId, aSubset);
|
2000-06-17 01:49:19 +00:00
|
|
|
if (NS_FAILED(rv) || !docType) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-03-15 09:45:31 +00:00
|
|
|
if (aCatalogData && mCSSLoader && mDocument) {
|
|
|
|
// bug 124570 - we only expect additional agent sheets for now -- ignore
|
|
|
|
// exit codes, error are not fatal here, just that the stylesheet won't apply
|
|
|
|
nsCOMPtr<nsIURI> uri(do_QueryInterface(aCatalogData));
|
|
|
|
if (uri) {
|
|
|
|
PRBool complete;
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
|
|
|
mCSSLoader->LoadAgentSheet(uri, *getter_AddRefs(sheet), complete, nsnull);
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsCAutoString uriStr;
|
|
|
|
uri->GetSpec(uriStr);
|
|
|
|
printf("Loading catalog stylesheet: %s ... %s\n", uriStr.get(), sheet.get() ? "Done" : "Failed");
|
|
|
|
#endif
|
|
|
|
if (sheet) {
|
|
|
|
mDocument->AddStyleSheet(sheet, NS_STYLESHEET_FROM_CATALOG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-17 01:49:19 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> tmpNode;
|
|
|
|
|
2001-01-04 00:30:11 +00:00
|
|
|
return doc->AppendChild(docType, getter_AddRefs(tmpNode));
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2001-06-29 22:56:58 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::HandleCharacterData(const PRUnichar *aData,
|
|
|
|
PRUint32 aLength)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (aData) {
|
|
|
|
result = AddText(aData,aLength);
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
return result;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-09 01:37:50 +00:00
|
|
|
nsXMLContentSink::HandleProcessingInstruction(const PRUnichar *aTarget,
|
|
|
|
const PRUnichar *aData)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
FlushText();
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
const nsDependentString target(aTarget);
|
2002-04-25 11:58:08 +00:00
|
|
|
const nsDependentString data(aData);
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsIContent> node;
|
2001-01-04 00:30:11 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
result = NS_NewXMLProcessingInstruction(getter_AddRefs(node), target, data);
|
|
|
|
if (NS_OK == result) {
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(node));
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (ssle) {
|
|
|
|
ssle->InitStyleLinkElement(mParser, PR_FALSE);
|
|
|
|
ssle->SetEnableUpdates(PR_FALSE);
|
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);
|
2002-04-05 11:29:40 +00:00
|
|
|
result = ssle->UpdateStyleSheet(nsnull, mStyleSheetCount);
|
2002-01-09 01:37:50 +00:00
|
|
|
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-04-05 11:29:40 +00:00
|
|
|
// If it's not a CSS stylesheet PI...
|
2002-01-09 01:37:50 +00:00
|
|
|
nsAutoString type;
|
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("type"), type);
|
|
|
|
if (mState == eXMLContentSinkState_InProlog &&
|
|
|
|
target.Equals(NS_LITERAL_STRING("xml-stylesheet")) &&
|
|
|
|
!type.EqualsIgnoreCase("text/css")) {
|
|
|
|
nsAutoString href, title, media, alternate;
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("href"), href);
|
|
|
|
// If there was no href, we can't do anything with this PI
|
|
|
|
if (href.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("title"), title);
|
|
|
|
title.CompressWhitespace();
|
1999-01-12 16:37:24 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("media"), media);
|
|
|
|
ToLowerCase(media);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("alternate"), alternate);
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
result = ProcessStyleLink(node, href, alternate.Equals(NS_LITERAL_STRING("yes")),
|
|
|
|
title, type, media);
|
2000-01-21 01:32:32 +00:00
|
|
|
}
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
return result;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
|
|
|
|
2002-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-03-12 22:17:18 +00:00
|
|
|
mState = eXMLContentSinkState_InProlog;
|
|
|
|
|
|
|
|
// Clear the current content and
|
|
|
|
// prepare to set <parsererror> as the document root
|
|
|
|
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mDocument));
|
|
|
|
if (node) {
|
|
|
|
for (;;) {
|
|
|
|
nsCOMPtr<nsIDOMNode> child, dummy;
|
|
|
|
node->GetLastChild(getter_AddRefs(child));
|
|
|
|
if (!child)
|
|
|
|
break;
|
|
|
|
node->RemoveChild(child, getter_AddRefs(dummy));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(mDocElement);
|
|
|
|
|
2002-04-25 11:58:08 +00:00
|
|
|
if (mXSLTransformMediator) {
|
|
|
|
// Get rid of the transform mediator.
|
|
|
|
mXSLTransformMediator->SetEnabled(PR_FALSE);
|
|
|
|
mXSLTransformMediator = nsnull;
|
|
|
|
}
|
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(name, "xmlns");
|
2002-03-12 22:17:18 +00:00
|
|
|
NS_NAMED_LITERAL_STRING(value, "http://www.mozilla.org/newlayout/xml/parsererror.xml");
|
2000-01-21 01:32:32 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
const PRUnichar* atts[] = {name.get(), value.get(), nsnull};
|
|
|
|
|
2002-05-20 22:47:02 +00:00
|
|
|
rv = HandleStartElement(NS_LITERAL_STRING("parsererror").get(), atts, 1,
|
|
|
|
(PRUint32)-1, (PRUint32)-1);
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
2000-01-21 00:05:36 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
rv = HandleCharacterData(aErrorText, nsCRT::strlen(aErrorText));
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
2002-03-12 22:17:18 +00:00
|
|
|
const PRUnichar* noAtts[] = {0, 0};
|
2002-05-20 22:47:02 +00:00
|
|
|
rv = HandleStartElement(NS_LITERAL_STRING("sourcetext").get(), noAtts, 0,
|
|
|
|
(PRUint32)-1, (PRUint32)-1);
|
2002-01-09 01:37:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
|
|
|
rv = HandleCharacterData(aSourceText, nsCRT::strlen(aSourceText));
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
|
|
|
rv = HandleEndElement(NS_LITERAL_STRING("sourcetext").get());
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
|
|
|
rv = HandleEndElement(NS_LITERAL_STRING("parsererror").get());
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-11-11 22:06:16 +00:00
|
|
|
}
|
(13163, r=alecf, scc, waterson, others; names available on request)
- Fix most of bug 13163 (see TODO for rest). This entails adding a version-string argument to nsIScriptContext::EvaluateString and passing it around lots of places in content sinks.
- Fix leaks and confusion about mSecurityManager and mNameSpaceManager in nsJSEnvironment.cpp. These still need to move from nsJSContext to nsGlobalWindow or thereabouts, jband and vidur are looking at that.
- Added comments and expanded tabs in nsJSEnvironment.cpp, esp. to EvaluateString. Also changed various nsresult vars to be named rv. Also restored brace/style conformity to nsJSProtocolHandler.cpp.
- Factored CompileFunction from AddScriptEventListener to pave the way for brutal sharing of compiled JS event handlers via JS_CloneFunctionObject.
- Lots of nsCOMPtr uses added. I'm using one for mNameSpaceManager. Hold mSecurityManager as a service explicitly, on the other hand (awaiting scc's fix to allow comptrs for services), and release in nsJSContext's dtor (fixing a leak). These two managers should be moved to the window object -- TODO item below.
- Hold JSRuntimeService along with JSRuntime for live of nsJSEnvironment, fix for shaver.
- Fix window.setTimeout etc. so the filename and line number of the timeout expr is propagated. This meant factoring nsJSUtils.cpp code.
- Fix all content sinks to use the same, and up-to-date JavaScript version parsing (whether for script type or for old language attribute); also fix SplitMimeType clones to strip whitespace.
- With waterson, fix bug in brutal-sharing version of XUL content sink: script src= should not evaluate the inline content of its tag.
1999-10-31 00:43:30 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
nsresult
|
|
|
|
nsXMLContentSink::PushNameSpacesFrom(const PRUnichar** aAtts)
|
1998-11-11 22:06:16 +00:00
|
|
|
{
|
2002-01-09 01:37:50 +00:00
|
|
|
nsCOMPtr<nsINameSpace> nameSpace;
|
|
|
|
nsresult rv = NS_OK;
|
1998-11-11 22:06:16 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
if (mNameSpaceStack && (0 < mNameSpaceStack->Count())) {
|
|
|
|
nameSpace =
|
|
|
|
(nsINameSpace*)mNameSpaceStack->ElementAt(mNameSpaceStack->Count() - 1);
|
|
|
|
} else {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
1999-05-13 20:27:47 +00:00
|
|
|
|
2002-01-09 01:37:50 +00:00
|
|
|
// Create buffer when we first need it
|
|
|
|
if (0 == mTextSize) {
|
|
|
|
mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * NS_ACCUMULATION_BUFFER_SIZE);
|
|
|
|
if (nsnull == mText) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mTextSize = NS_ACCUMULATION_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
2002-03-23 22:46:13 +00:00
|
|
|
const nsAString& str = Substring(aText, aText+aLength);
|
2002-01-09 01:37:50 +00:00
|
|
|
|
|
|
|
// Copy data from string into our buffer; flush buffer when it fills up
|
|
|
|
PRInt32 offset = 0;
|
|
|
|
PRBool isLastCharCR = PR_FALSE;
|
|
|
|
while (0 != aLength) {
|
|
|
|
PRInt32 amount = mTextSize - mTextLength;
|
|
|
|
if (amount > aLength) {
|
|
|
|
amount = aLength;
|
|
|
|
}
|
|
|
|
if (0 == amount) {
|
|
|
|
if (mConstrainSize) {
|
|
|
|
nsresult rv = FlushText();
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mTextSize += aLength;
|
|
|
|
mText = (PRUnichar *) PR_REALLOC(mText, sizeof(PRUnichar) * mTextSize);
|
|
|
|
if (nsnull == mText) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-13 20:27:47 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
mTextLength +=
|
|
|
|
nsContentUtils::CopyNewlineNormalizedUnicodeTo(str,
|
|
|
|
offset,
|
|
|
|
&mText[mTextLength],
|
|
|
|
amount,
|
|
|
|
isLastCharCR);
|
|
|
|
offset += amount;
|
|
|
|
aLength -= amount;
|
1999-05-13 20:27:47 +00:00
|
|
|
}
|
2002-01-09 01:37:50 +00:00
|
|
|
|
1999-05-13 20:27:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-10-05 00:12:21 +00:00
|
|
|
|
|
|
|
nsresult
|
2002-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
|
|
|
}
|