From 0b9688294eac3bd252471aa145362ca2f67fcd2d Mon Sep 17 00:00:00 2001 From: "cvshook%sicking.cc" Date: Sat, 4 Nov 2006 05:45:02 +0000 Subject: [PATCH] Bug 343730: Don't execute scripts synchronously from BindToTree. Instead we wait until the last EndUpdate has been called. r/sr=bz git-svn-id: svn://10.0.0.236/trunk@214702 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/Makefile.in | 1 - mozilla/content/base/public/nsContentErrors.h | 2 +- mozilla/content/base/public/nsIContent.h | 16 +- mozilla/content/base/public/nsIDocument.h | 8 +- mozilla/content/base/public/nsINode.h | 11 +- .../content/base/public/nsIScriptElement.h | 53 ++- .../base/public/nsIScriptLoaderObserver.idl | 4 +- mozilla/content/base/src/Makefile.in | 2 + mozilla/content/base/src/nsContentSink.cpp | 28 +- mozilla/content/base/src/nsContentSink.h | 1 - mozilla/content/base/src/nsDocument.cpp | 14 +- mozilla/content/base/src/nsDocument.h | 4 +- mozilla/content/base/src/nsScriptElement.cpp | 218 +++++++++ mozilla/content/base/src/nsScriptElement.h | 90 ++++ mozilla/content/base/src/nsScriptLoader.cpp | 450 +++++------------- mozilla/content/base/src/nsScriptLoader.h | 129 ++++- .../html/content/src/nsGenericHTMLElement.cpp | 13 +- .../html/content/src/nsHTMLObjectElement.cpp | 5 +- .../html/content/src/nsHTMLScriptElement.cpp | 205 +------- .../html/content/src/nsHTMLSelectElement.cpp | 6 +- .../content/src/nsHTMLSharedObjectElement.cpp | 6 +- .../content/src/nsHTMLTextAreaElement.cpp | 6 +- .../html/document/src/nsHTMLContentSink.cpp | 101 ++-- .../html/document/src/nsHTMLDocument.cpp | 5 +- .../svg/content/src/nsSVGScriptElement.cpp | 182 +------ .../xml/document/src/nsXMLContentSink.cpp | 83 ++-- .../xml/document/src/nsXMLContentSink.h | 5 +- .../xml/document/src/nsXMLDocument.cpp | 2 +- .../document/src/nsXMLFragmentContentSink.cpp | 14 +- .../xslt/src/xslt/txMozillaXMLOutput.cpp | 68 ++- .../xslt/src/xslt/txMozillaXMLOutput.h | 2 - .../xslt/src/xslt/txMozillaXSLTProcessor.cpp | 1 - .../content/xtf/src/nsXTFElementWrapper.cpp | 4 +- mozilla/content/xtf/src/nsXTFElementWrapper.h | 2 +- .../feeds/src/nsScriptableUnescapeHTML.cpp | 7 +- 35 files changed, 798 insertions(+), 950 deletions(-) create mode 100755 mozilla/content/base/src/nsScriptElement.cpp create mode 100755 mozilla/content/base/src/nsScriptElement.h diff --git a/mozilla/content/base/public/Makefile.in b/mozilla/content/base/public/Makefile.in index 4d826095920..2a2684f8297 100644 --- a/mozilla/content/base/public/Makefile.in +++ b/mozilla/content/base/public/Makefile.in @@ -95,7 +95,6 @@ XPIDLSRCS = \ nsISelectionDisplay.idl \ nsISelectionListener.idl \ nsISelectionPrivate.idl \ - nsIScriptLoader.idl \ nsIScriptLoaderObserver.idl \ nsISyncLoadDOMService.idl \ nsIDragDropHandler.idl \ diff --git a/mozilla/content/base/public/nsContentErrors.h b/mozilla/content/base/public/nsContentErrors.h index 523e387a8a5..d78e76fae32 100644 --- a/mozilla/content/base/public/nsContentErrors.h +++ b/mozilla/content/base/public/nsContentErrors.h @@ -56,7 +56,7 @@ #define NS_XML_AUTOLINK_UNDEFINED \ NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 6) -/** Error codes for nsIScriptLoader */ +/** Error codes for nsScriptLoader */ #define NS_CONTENT_SCRIPT_IS_EVENTHANDLER \ NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 7) diff --git a/mozilla/content/base/public/nsIContent.h b/mozilla/content/base/public/nsIContent.h index 00732d94ec1..a00bcf440b5 100644 --- a/mozilla/content/base/public/nsIContent.h +++ b/mozilla/content/base/public/nsIContent.h @@ -62,8 +62,8 @@ class nsTextFragment; // IID for the nsIContent interface #define NS_ICONTENT_IID \ -{ 0x7796e67b, 0xdc73, 0x4b3d, \ - { 0xb8, 0x34, 0xcc, 0x9f, 0x96, 0xf7, 0x25, 0x56 } } +{ 0x38cb1dfd, 0xeeac, 0x4f35, \ + { 0x93, 0x83, 0xc0, 0xb5, 0xe5, 0xf1, 0xcd, 0xa4 } } // hack to make egcs / gcc 2.95.2 happy class nsIContent_base : public nsINode { @@ -620,12 +620,22 @@ public: * have the parser pass true. See nsHTMLInputElement.cpp and * nsHTMLContentSink::MakeContentObject(). * + * It is ok to ignore an error returned from this function. However the + * following errors may be of interest to some callers: + * + * NS_ERROR_HTMLPARSER_BLOCK Returned by script elements to indicate + * that a script will be loaded asynchronously + * + * This means that implementations will have to deal with returned error + * codes being ignored. + * * @param aHaveNotified Whether there has been a * ContentInserted/ContentAppended notification for this content node * yet. */ - virtual void DoneAddingChildren(PRBool aHaveNotified) + virtual nsresult DoneAddingChildren(PRBool aHaveNotified) { + return NS_OK; } /** diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 01e1f071071..56327f24cc3 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -76,7 +76,7 @@ class nsIDOMDocument; class nsIDOMDocumentType; class nsIObserver; class nsISupportsArray; -class nsIScriptLoader; +class nsScriptLoader; class nsIContentSink; class nsIScriptEventManager; class nsNodeInfoManager; @@ -91,8 +91,8 @@ class nsIDocumentObserver; // IID for the nsIDocument interface #define NS_IDOCUMENT_IID \ -{ 0x3a5ce97e, 0x4f41, 0x42ef, \ - { 0xa7, 0xc9, 0xcc, 0x3d, 0x4e, 0x7a, 0x3d, 0x00 } } +{ 0x1ae3a9cc, 0x3c05, 0x4215, \ + { 0xad, 0xed, 0xe7, 0x89, 0xc4, 0x08, 0x00, 0x91 } } // Flag for AddStyleSheet(). #define NS_STYLESHEET_FROM_CATALOG (1 << 0) @@ -522,7 +522,7 @@ public: /** * Get the script loader for this document */ - virtual nsIScriptLoader* GetScriptLoader() = 0; + virtual nsScriptLoader* GetScriptLoader() = 0; //---------------------------------------------------------------------- diff --git a/mozilla/content/base/public/nsINode.h b/mozilla/content/base/public/nsINode.h index 91f3322631b..f3eb6fa6375 100644 --- a/mozilla/content/base/public/nsINode.h +++ b/mozilla/content/base/public/nsINode.h @@ -94,8 +94,8 @@ class nsIMutationObserver; // IID for the nsINode interface #define NS_INODE_IID \ -{ 0x3d3a28b7, 0x6666, 0x4f93, \ - { 0xb7, 0xe7, 0xa9, 0x56, 0xd5, 0xaf, 0xf7, 0x57 } } +{ 0x98470c4b, 0xe988, 0x4abf, \ + { 0xa4, 0x00, 0x39, 0xbd, 0x00, 0x38, 0x51, 0x4d } } // hack to make egcs / gcc 2.95.2 happy class nsINode_base : public nsIDOMGCParticipant { @@ -571,6 +571,13 @@ public: nsTObserverArray mMutationObservers; }; +#ifdef DEBUG + nsSlots* DebugGetSlots() + { + return GetSlots(); + } +#endif + protected: /** * Functions for managing flags and slots diff --git a/mozilla/content/base/public/nsIScriptElement.h b/mozilla/content/base/public/nsIScriptElement.h index a00db6b0352..8e65e1a07f4 100644 --- a/mozilla/content/base/public/nsIScriptElement.h +++ b/mozilla/content/base/public/nsIScriptElement.h @@ -42,18 +42,27 @@ #include "nsISupports.h" #include "nsIURI.h" #include "nsCOMPtr.h" +#include "nsIScriptLoaderObserver.h" #define NS_ISCRIPTELEMENT_IID \ -{ 0x0511fba1, 0x1b67, 0x4338, \ - { 0x98, 0xff, 0x42, 0xb9, 0x02, 0x0b, 0xeb, 0x92 } } +{ 0x4b916da5, 0x82c4, 0x45ab, \ + { 0x99, 0x15, 0xcc, 0xcd, 0x9e, 0x2c, 0xb1, 0xe6 } } /** * Internal interface implemented by script elements */ -class nsIScriptElement : public nsISupports { +class nsIScriptElement : public nsIScriptLoaderObserver { public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTELEMENT_IID) + nsIScriptElement() + : mLineNumber(0), + mIsEvaluated(PR_FALSE), + mMalformed(PR_FALSE), + mDoneAddingChildren(PR_TRUE) + { + } + /** * Content type identifying the scripting language. Can be empty, in * which case javascript will be assumed. @@ -73,10 +82,40 @@ public: virtual void GetScriptCharset(nsAString& charset) = 0; - virtual void SetScriptLineNumber(PRUint32 aLineNumber) = 0; - virtual PRUint32 GetScriptLineNumber() = 0; - virtual void SetIsMalformed() = 0; - virtual PRBool IsMalformed() = 0; + void SetScriptLineNumber(PRUint32 aLineNumber) + { + mLineNumber = aLineNumber; + } + PRUint32 GetScriptLineNumber() + { + return mLineNumber; + } + + void SetIsMalformed() + { + mMalformed = PR_TRUE; + } + PRBool IsMalformed() + { + return mMalformed; + } + + void PreventExecution() + { + mIsEvaluated = PR_TRUE; + } + + void WillCallDoneAddingChildren() + { + NS_ASSERTION(mDoneAddingChildren, "unexpected, but not fatal"); + mDoneAddingChildren = PR_FALSE; + } + +protected: + PRUint32 mLineNumber; + PRPackedBool mIsEvaluated; + PRPackedBool mMalformed; + PRPackedBool mDoneAddingChildren; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptElement, NS_ISCRIPTELEMENT_IID) diff --git a/mozilla/content/base/public/nsIScriptLoaderObserver.idl b/mozilla/content/base/public/nsIScriptLoaderObserver.idl index 03b747b1aa9..f07cde36502 100644 --- a/mozilla/content/base/public/nsIScriptLoaderObserver.idl +++ b/mozilla/content/base/public/nsIScriptLoaderObserver.idl @@ -62,15 +62,13 @@ interface nsIScriptLoaderObserver : nsISupports { * it is inline). * @param aLineNo At what line does the script appear (generally 1 * if it is a loaded script). - * @param aScript String representation of the string to be evaluated. */ void scriptAvailable(in nsresult aResult, in nsIScriptElement aElement, in boolean aIsInline, in boolean aWasPending, in nsIURI aURI, - in PRInt32 aLineNo, - in AString aScript); + in PRInt32 aLineNo); /** * The script has been evaluated. diff --git a/mozilla/content/base/src/Makefile.in b/mozilla/content/base/src/Makefile.in index 28da2e554c9..6dd4c4b7361 100644 --- a/mozilla/content/base/src/Makefile.in +++ b/mozilla/content/base/src/Makefile.in @@ -85,6 +85,7 @@ EXPORTS = \ nsGkAtoms.h \ nsNodeInfoManager.h \ nsPropertyTable.h \ + nsScriptLoader.h \ nsStubDocumentObserver.h \ nsStubImageDecoderObserver.h \ nsStubMutationObserver.h \ @@ -135,6 +136,7 @@ CPPSRCS = \ nsPlainTextSerializer.cpp \ nsPropertyTable.cpp \ nsRange.cpp \ + nsScriptElement.cpp \ nsScriptEventManager.cpp \ nsScriptLoader.cpp \ nsStubDocumentObserver.cpp \ diff --git a/mozilla/content/base/src/nsContentSink.cpp b/mozilla/content/base/src/nsContentSink.cpp index 00b5066a49d..560fd11234f 100644 --- a/mozilla/content/base/src/nsContentSink.cpp +++ b/mozilla/content/base/src/nsContentSink.cpp @@ -41,7 +41,7 @@ */ #include "nsContentSink.h" -#include "nsIScriptLoader.h" +#include "nsScriptLoader.h" #include "nsIDocument.h" #include "nsICSSLoader.h" #include "nsStyleConsts.h" @@ -112,14 +112,13 @@ nsScriptLoaderObserverProxy::ScriptAvailable(nsresult aResult, PRBool aIsInline, PRBool aWasPending, nsIURI *aURI, - PRInt32 aLineNo, - const nsAString & aScript) + PRInt32 aLineNo) { nsCOMPtr inner = do_QueryReferent(mInner); if (inner) { return inner->ScriptAvailable(aResult, aElement, aIsInline, aWasPending, - aURI, aLineNo, aScript); + aURI, aLineNo); } return NS_OK; @@ -147,7 +146,6 @@ NS_IMPL_ISUPPORTS3(nsContentSink, nsIScriptLoaderObserver) nsContentSink::nsContentSink() - : mNeedToBlockParser(PR_FALSE) { } @@ -179,10 +177,9 @@ nsContentSink::Init(nsIDocument* aDoc, new nsScriptLoaderObserverProxy(this); NS_ENSURE_TRUE(proxy, NS_ERROR_OUT_OF_MEMORY); - nsIScriptLoader *loader = mDocument->GetScriptLoader(); + nsScriptLoader *loader = mDocument->GetScriptLoader(); NS_ENSURE_TRUE(loader, NS_ERROR_FAILURE); - nsresult rv = loader->AddObserver(proxy); - NS_ENSURE_SUCCESS(rv, rv); + loader->AddObserver(proxy); mCSSLoader = aDoc->CSSLoader(); @@ -207,8 +204,7 @@ nsContentSink::ScriptAvailable(nsresult aResult, PRBool aIsInline, PRBool aWasPending, nsIURI *aURI, - PRInt32 aLineNo, - const nsAString& aScript) + PRInt32 aLineNo) { PRUint32 count = mScriptElements.Count(); @@ -216,6 +212,13 @@ nsContentSink::ScriptAvailable(nsresult aResult, return NS_OK; } + // aElement will not be in mScriptElements if a