diff --git a/content/base/public/Makefile.in b/content/base/public/Makefile.in index 4d826095920d..2a2684f8297f 100644 --- a/content/base/public/Makefile.in +++ b/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/content/base/public/nsContentErrors.h b/content/base/public/nsContentErrors.h index 523e387a8a59..d78e76fae322 100644 --- a/content/base/public/nsContentErrors.h +++ b/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/content/base/public/nsIContent.h b/content/base/public/nsIContent.h index 00732d94ec15..a00bcf440b50 100644 --- a/content/base/public/nsIContent.h +++ b/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/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 01e1f0710718..56327f24cc33 100644 --- a/content/base/public/nsIDocument.h +++ b/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/content/base/public/nsINode.h b/content/base/public/nsINode.h index 91f3322631b9..f3eb6fa63756 100644 --- a/content/base/public/nsINode.h +++ b/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/content/base/public/nsIScriptElement.h b/content/base/public/nsIScriptElement.h index a00db6b0352b..8e65e1a07f47 100644 --- a/content/base/public/nsIScriptElement.h +++ b/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/content/base/public/nsIScriptLoaderObserver.idl b/content/base/public/nsIScriptLoaderObserver.idl index 03b747b1aa9d..f07cde36502e 100644 --- a/content/base/public/nsIScriptLoaderObserver.idl +++ b/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/content/base/src/Makefile.in b/content/base/src/Makefile.in index 28da2e554c9e..6dd4c4b73616 100644 --- a/content/base/src/Makefile.in +++ b/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/content/base/src/nsContentSink.cpp b/content/base/src/nsContentSink.cpp index 00b5066a49d6..560fd11234f6 100644 --- a/content/base/src/nsContentSink.cpp +++ b/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