Bug 669012 - Part d: Make nsIScriptElement::MaybeProcessScript return a boolean; r=smaug+hsivonen.
authorMs2ger <ms2ger@gmail.com>
Wed, 16 Nov 2011 08:50:18 +0100
changeset 81938 ec02dc79904aca221183c21ba423f7143ba41034
parent 81937 a47f8a6f6705db36906eec0d243e0299a5f7dda6
child 81939 6b58c2e56c261e5064df918c8eb58b032a1a69ad
push idunknown
push userunknown
push dateunknown
reviewerssmaug
bugs669012
milestone11.0a1
Bug 669012 - Part d: Make nsIScriptElement::MaybeProcessScript return a boolean; r=smaug+hsivonen.
content/base/public/nsIScriptElement.h
content/base/src/nsScriptElement.cpp
content/base/src/nsScriptElement.h
content/html/content/src/nsHTMLScriptElement.cpp
--- a/content/base/public/nsIScriptElement.h
+++ b/content/base/public/nsIScriptElement.h
@@ -44,18 +44,18 @@
 #include "nsCOMPtr.h"
 #include "nsIScriptLoaderObserver.h"
 #include "nsWeakPtr.h"
 #include "nsIParser.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsIDOMHTMLScriptElement.h"
 
 #define NS_ISCRIPTELEMENT_IID \
-{ 0xac4c7e7f, 0x0c4a, 0x4796, \
-  { 0xb4, 0xb7, 0x54, 0xbd, 0x13, 0x0f, 0x95, 0x9e } }
+{ 0x5bb3b905, 0x5988, 0x476f, \
+  { 0x95, 0x4f, 0x99, 0x02, 0x59, 0x82, 0x24, 0x67 } }
 
 /**
  * Internal interface implemented by script elements
  */
 class nsIScriptElement : public nsIScriptLoaderObserver {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTELEMENT_IID)
 
@@ -222,40 +222,43 @@ public:
    * element's children, if any are present.
    *
    * @return whether the parser will be blocked while this script is being
    *         loaded
    */
   bool AttemptToExecute()
   {
     mDoneAddingChildren = true;
-    nsresult rv = MaybeProcessScript();
+    bool block = MaybeProcessScript();
     if (!mAlreadyStarted) {
       // Need to lose parser-insertedness here to allow another script to cause
       // execution later.
       LoseParserInsertedness();
     }
-    return rv == NS_ERROR_HTMLPARSER_BLOCK;
+    return block;
   }
 
 protected:
   /**
    * Processes the script if it's in the document-tree and links to or
    * contains a script. Once it has been evaluated there is no way to make it
    * reevaluate the script, you'll have to create a new element. This also means
    * that when adding a src attribute to an element that already contains an
    * inline script, the script referenced by the src attribute will not be
    * loaded.
    *
    * In order to be able to use multiple childNodes, or to use the
    * fallback mechanism of using both inline script and linked script you have
    * to add all attributes and childNodes before adding the element to the
    * document-tree.
+   *
+   * @return whether the parser will be blocked while this script is being
+   *         loaded
    */
-  virtual nsresult MaybeProcessScript() = 0;
+  virtual bool MaybeProcessScript() = 0;
 
   /**
    * The start line number of the script.
    */
   PRUint32 mLineNumber;
   
   /**
    * The "already started" flag per HTML5.
--- a/content/base/src/nsScriptElement.cpp
+++ b/content/base/src/nsScriptElement.cpp
@@ -142,52 +142,43 @@ void
 nsScriptElement::ContentInserted(nsIDocument *aDocument,
                                  nsIContent* aContainer,
                                  nsIContent* aChild,
                                  PRInt32 aIndexInContainer)
 {
   MaybeProcessScript();
 }
 
-nsresult
+bool
 nsScriptElement::MaybeProcessScript()
 {
   nsCOMPtr<nsIContent> cont =
     do_QueryInterface((nsIScriptElement*) this);
 
   NS_ASSERTION(cont->DebugGetSlots()->mMutationObservers.Contains(this),
                "You forgot to add self as observer");
 
   if (mAlreadyStarted || !mDoneAddingChildren || !cont->IsInDoc() ||
       mMalformed || !HasScriptContent()) {
-    return NS_OK;
+    return false;
   }
 
   FreezeUriAsyncDefer();
 
   mAlreadyStarted = true;
 
   nsIDocument* ownerDoc = cont->OwnerDoc();
   nsCOMPtr<nsIParser> parser = ((nsIScriptElement*) this)->GetCreatorParser();
   if (parser) {
     nsCOMPtr<nsIContentSink> sink = parser->GetContentSink();
     if (sink) {
       nsCOMPtr<nsIDocument> parserDoc = do_QueryInterface(sink->GetTarget());
       if (ownerDoc != parserDoc) {
         // Willful violation of HTML5 as of 2010-12-01
-        return NS_OK;
+        return false;
       }
     }
   }
 
   nsRefPtr<nsScriptLoader> loader = ownerDoc->ScriptLoader();
   nsresult scriptresult = loader->ProcessScriptElement(this);
-
-  // The only error we don't ignore is NS_ERROR_HTMLPARSER_BLOCK
-  // However we don't want to override other success values
-  // (such as NS_CONTENT_SCRIPT_IS_EVENTHANDLER)
-  if (NS_FAILED(scriptresult) &&
-      scriptresult != NS_ERROR_HTMLPARSER_BLOCK) {
-    scriptresult = NS_OK;
-  }
-
-  return scriptresult;
+  return scriptresult == NS_ERROR_HTMLPARSER_BLOCK;
 }
--- a/content/base/src/nsScriptElement.h
+++ b/content/base/src/nsScriptElement.h
@@ -67,10 +67,10 @@ public:
 protected:
   // Internal methods
 
   /**
    * Check if this element contains any script, linked or inline
    */
   virtual bool HasScriptContent() = 0;
 
-  virtual nsresult MaybeProcessScript();
+  virtual bool MaybeProcessScript();
 };
--- a/content/html/content/src/nsHTMLScriptElement.cpp
+++ b/content/html/content/src/nsHTMLScriptElement.cpp
@@ -117,21 +117,18 @@ public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   // nsGenericElement
   virtual nsresult AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
                                 const nsAString* aValue, bool aNotify);
 
   virtual nsXPCClassInfo* GetClassInfo();
 protected:
-  bool IsOnloadEventForWindow();
-
   // nsScriptElement
   virtual bool HasScriptContent();
-  virtual nsresult MaybeProcessScript();
 };
 
 
 NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Script)
 
 
 nsHTMLScriptElement::nsHTMLScriptElement(already_AddRefed<nsINodeInfo> aNodeInfo,
                                          FromParser aFromParser)
@@ -315,19 +312,8 @@ nsHTMLScriptElement::FreezeUriAsyncDefer
 }
 
 bool
 nsHTMLScriptElement::HasScriptContent()
 {
   return (mFrozen ? mExternal : HasAttr(kNameSpaceID_None, nsGkAtoms::src)) ||
          nsContentUtils::HasNonEmptyTextContent(this);
 }
-
-nsresult
-nsHTMLScriptElement::MaybeProcessScript()
-{
-  nsresult rv = nsScriptElement::MaybeProcessScript();
-  if (rv == NS_CONTENT_SCRIPT_IS_EVENTHANDLER)
-    // Don't return NS_CONTENT_SCRIPT_IS_EVENTHANDLER since callers can't deal
-    rv = NS_OK;
-
-  return rv;
-}