Bug 720124 - Remove dead code from HTMLContentSink: form; r=hsivonen
authorMs2ger <ms2ger@gmail.com>
Wed, 25 Jan 2012 08:50:03 +0100
changeset 86427 92474bceca8a2f890e00a608b7eaec545a6039dc
parent 86426 5c0b40af4d51d8f44b9553eb7289bbfd75512df0
child 86428 ffa1adda4c4ff548c0d99fa437c9c1913d70cea3
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs720124
milestone12.0a1
Bug 720124 - Remove dead code from HTMLContentSink: form; r=hsivonen
content/html/document/src/nsHTMLContentSink.cpp
--- a/content/html/document/src/nsHTMLContentSink.cpp
+++ b/content/html/document/src/nsHTMLContentSink.cpp
@@ -68,20 +68,16 @@
 #include "mozilla/Preferences.h"
 
 #include "nsGenericHTMLElement.h"
 
 #include "nsIDOMDocument.h"
 #include "nsIDOMDocumentType.h"
 #include "nsIScriptElement.h"
 
-#include "nsIDOMHTMLFormElement.h"
-#include "nsIFormControl.h"
-#include "nsIForm.h"
-
 #include "nsIComponentManager.h"
 #include "nsIServiceManager.h"
 
 #include "nsGkAtoms.h"
 #include "nsContentUtils.h"
 #include "nsIChannel.h"
 #include "nsIHttpChannel.h"
 #include "nsIDocShell.h"
@@ -156,27 +152,24 @@ static const contentCreatorCallback sCon
 #undef HTML_HTMLELEMENT_TAG
 #undef HTML_OTHER
   NS_NewHTMLUnknownElement
 };
 
 class SinkContext;
 class HTMLContentSink;
 
-static void MaybeSetForm(nsGenericHTMLElement*, nsHTMLTag, HTMLContentSink*);
-
 class HTMLContentSink : public nsContentSink,
 #ifdef DEBUG
                         public nsIDebugDumpContent,
 #endif
                         public nsIHTMLContentSink
 {
 public:
   friend class SinkContext;
-  friend void MaybeSetForm(nsGenericHTMLElement*, nsHTMLTag, HTMLContentSink*);
 
   HTMLContentSink();
   virtual ~HTMLContentSink();
 
   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
 
   nsresult Init(nsIDocument* aDoc, nsIURI* aURI, nsISupports* aContainer,
                 nsIChannel* aChannel);
@@ -206,17 +199,17 @@ public:
   NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
   NS_IMETHOD DidProcessTokens(void);
   NS_IMETHOD WillProcessAToken(void);
   NS_IMETHOD DidProcessAToken(void);
   NS_IMETHOD BeginContext(PRInt32 aID);
   NS_IMETHOD EndContext(PRInt32 aID);
   NS_IMETHOD OpenHead();
   NS_IMETHOD IsEnabled(PRInt32 aTag, bool* aReturn);
-  NS_IMETHOD_(bool) IsFormOnStack();
+  NS_IMETHOD_(bool) IsFormOnStack() { return false; }
 
 #ifdef DEBUG
   // nsIDebugDumpContent
   NS_IMETHOD DumpContentModel();
 #endif
 
 protected:
   // If aCheckIfPresent is true, will only set an attribute in cases
@@ -239,45 +232,40 @@ protected:
 
   // The maximum length of a text run
   PRInt32 mMaxTextRun;
 
   nsRefPtr<nsGenericHTMLElement> mRoot;
   nsRefPtr<nsGenericHTMLElement> mBody;
   nsRefPtr<nsGenericHTMLElement> mHead;
 
-  nsRefPtr<nsGenericHTMLElement> mCurrentForm;
-
   nsAutoTArray<SinkContext*, 8> mContextStack;
   SinkContext* mCurrentContext;
   SinkContext* mHeadContext;
 
   // Boolean indicating whether we've seen a <head> tag that might have had
   // attributes once already.
   bool mHaveSeenHead;
 
   // Boolean indicating whether we've notified insertion of our root content
   // yet.  We want to make sure to only do this once.
   bool mNotifiedRootInsertion;
 
   PRUint8 mScriptEnabled : 1;
   PRUint8 mFramesEnabled : 1;
-  PRUint8 mFormOnStack : 1;
-  PRUint8 unused : 5;  // bits available if someone needs one
+  PRUint8 unused : 6;  // bits available if someone needs one
 
   nsINodeInfo* mNodeInfoCache[NS_HTML_TAG_MAX + 1];
 
   nsresult FlushTags();
 
   // Routines for tags that require special handling
   nsresult CloseHTML();
   nsresult OpenBody(const nsIParserNode& aNode);
   nsresult CloseBody();
-  nsresult OpenForm(const nsIParserNode& aNode);
-  nsresult CloseForm();
 
   nsresult OpenHeadContext();
   void CloseHeadContext();
 
   // nsContentSink overrides
   void UpdateChildCounts();
 
   void NotifyInsert(nsIContent* aContent,
@@ -455,49 +443,16 @@ HTMLContentSink::AddAttributes(const nsI
       // Add attribute to content
       aContent->SetAttr(kNameSpaceID_None, keyAtom, v, aNotify);
     }
   }
 
   return NS_OK;
 }
 
-static void
-MaybeSetForm(nsGenericHTMLElement* aContent, nsHTMLTag aNodeType,
-             HTMLContentSink* aSink)
-{
-  nsGenericHTMLElement* form = aSink->mCurrentForm;
-
-  if (!form) {
-    return;
-  }
-
-  switch (aNodeType) {
-    case eHTMLTag_button:
-    case eHTMLTag_fieldset:
-    case eHTMLTag_label:
-    case eHTMLTag_object:
-    case eHTMLTag_input:
-    case eHTMLTag_select:
-    case eHTMLTag_textarea:
-      break;
-    default:
-      return;
-  }
-  
-  nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(aContent));
-  NS_ASSERTION(formControl,
-               "nsGenericHTMLElement didn't implement nsIFormControl");
-  nsCOMPtr<nsIDOMHTMLFormElement> formElement(do_QueryInterface(form));
-  NS_ASSERTION(formElement,
-               "nsGenericHTMLElement didn't implement nsIDOMHTMLFormElement");
-
-  formControl->SetForm(formElement);
-}
-
 /**
  * Factory subroutine to create all of the html content objects.
  */
 already_AddRefed<nsGenericHTMLElement>
 HTMLContentSink::CreateContentObject(const nsIParserNode& aNode,
                                      nsHTMLTag aNodeType)
 {
   // Find/create atom for the tag name
@@ -720,30 +675,29 @@ SinkContext::OpenContainer(const nsIPars
 
   mStack[mStackPos].mType = nodeType;
   mStack[mStackPos].mContent = content;
   mStack[mStackPos].mNumFlushed = 0;
   mStack[mStackPos].mInsertionPoint = -1;
   ++mStackPos;
 
   rv = mSink->AddAttributes(aNode, content);
-  MaybeSetForm(content, nodeType, mSink);
 
   mStack[mStackPos - 2].Add(content);
 
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mSink->IsMonolithicContainer(nodeType)) {
     mSink->mInMonolithicContainer++;
   }
 
   // Special handling for certain tags
   switch (nodeType) {
     case eHTMLTag_form:
-      mSink->mCurrentForm = content;
+      MOZ_NOT_REACHED("Must not use HTMLContentSink for forms.");
       break;
 
     case eHTMLTag_frameset:
       MOZ_NOT_REACHED("Must not use HTMLContentSink for frames.");
       break;
 
     case eHTMLTag_noembed:
     case eHTMLTag_noframes:
@@ -813,17 +767,17 @@ SinkContext::CloseContainer(const nsHTML
 
   if (mStackPos <= 0) {
     return NS_OK; // Fix crash - Ref. bug 45975 or 45007
   }
 
   --mStackPos;
   nsHTMLTag nodeType = mStack[mStackPos].mType;
 
-  NS_ASSERTION(nodeType == eHTMLTag_form || nodeType == aTag,
+  NS_ASSERTION(nodeType == aTag,
                "Tag mismatch.  Closing tag on wrong context or something?");
 
   nsGenericHTMLElement* content = mStack[mStackPos].mContent;
 
   content->Compact();
 
   // If we're in a state where we do append notifications as
   // we go up the tree, and we're at the level where the next
@@ -860,28 +814,17 @@ SinkContext::CloseContainer(const nsHTML
   // Special handling for certain tags
   switch (nodeType) {
   case eHTMLTag_noembed:
   case eHTMLTag_noframes:
     MOZ_NOT_REACHED("Must not use HTMLContentSink for noembed/noframes.");
     break;
 
   case eHTMLTag_form:
-    {
-      mSink->mFormOnStack = false;
-      // If there's a FORM on the stack, but this close tag doesn't
-      // close the form, then close out the form *and* close out the
-      // next container up. This is since the parser doesn't do fix up
-      // of invalid form nesting. When the end FORM tag comes through,
-      // we'll ignore it.
-      if (aTag != nodeType) {
-        result = CloseContainer(aTag);
-      }
-    }
-
+    MOZ_NOT_REACHED("Must not use HTMLContentSink for forms.");
     break;
 
 #ifdef MOZ_MEDIA
   case eHTMLTag_video:
   case eHTMLTag_audio:
 #endif
   case eHTMLTag_select:
   case eHTMLTag_textarea:
@@ -932,26 +875,19 @@ SinkContext::AddLeaf(const nsIParserNode
       FlushTextAndRelease();
 
       // Create new leaf content object
       nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
       nsRefPtr<nsGenericHTMLElement> content =
         mSink->CreateContentObject(aNode, nodeType);
       NS_ENSURE_TRUE(content, NS_ERROR_OUT_OF_MEMORY);
 
-      if (nodeType == eHTMLTag_form) {
-        mSink->mCurrentForm = content;
-      }
-
       rv = mSink->AddAttributes(aNode, content);
-
       NS_ENSURE_SUCCESS(rv, rv);
 
-      MaybeSetForm(content, nodeType, mSink);
-
       // Add new leaf to its parent
       AddLeaf(content);
 
       // Additional processing needed once the element is in the tree
       switch (nodeType) {
       case eHTMLTag_meta:
         MOZ_NOT_REACHED("Must not use HTMLContentSink for metas.");
         rv = NS_ERROR_NOT_IMPLEMENTED;
@@ -1429,28 +1365,26 @@ HTMLContentSink::~HTMLContentSink()
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLContentSink)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLContentSink, nsContentSink)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mHTMLDocument)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRoot)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mBody)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mHead)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCurrentForm)
   for (PRUint32 i = 0; i < ArrayLength(tmp->mNodeInfoCache); ++i) {
     NS_IF_RELEASE(tmp->mNodeInfoCache[i]);
   }
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLContentSink,
                                                   nsContentSink)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mHTMLDocument)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRoot)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mBody)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mHead)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentForm)
   for (PRUint32 i = 0; i < ArrayLength(tmp->mNodeInfoCache); ++i) {
     NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mNodeInfoCache[i]");
     cb.NoteXPCOMChild(tmp->mNodeInfoCache[i]);
   }
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLContentSink)
   NS_INTERFACE_TABLE_BEGIN
@@ -1661,22 +1595,16 @@ HTMLContentSink::DidBuildModel(bool aTer
 NS_IMETHODIMP
 HTMLContentSink::SetParser(nsParserBase* aParser)
 {
   NS_PRECONDITION(aParser, "Should have a parser here!");
   mParser = aParser;
   return NS_OK;
 }
 
-NS_IMETHODIMP_(bool)
-HTMLContentSink::IsFormOnStack()
-{
-  return mFormOnStack;
-}
-
 NS_IMETHODIMP
 HTMLContentSink::BeginContext(PRInt32 aPosition)
 {
   NS_PRECONDITION(aPosition > -1, "out of bounds");
 
   if (!mCurrentContext) {
     NS_ERROR("Nonexistent context");
 
@@ -1880,76 +1808,16 @@ HTMLContentSink::CloseBody()
              ("HTMLContentSink::CloseBody: layout final body content"));
 
   mCurrentContext->FlushTags();
   mCurrentContext->CloseContainer(eHTMLTag_body);
 
   return NS_OK;
 }
 
-nsresult
-HTMLContentSink::OpenForm(const nsIParserNode& aNode)
-{
-  nsresult result = NS_OK;
-
-  mCurrentContext->FlushTextAndRelease();
-
-  SINK_TRACE_NODE(SINK_TRACE_CALLS,
-                  "HTMLContentSink::OpenForm", 
-                  eHTMLTag_form,
-                  mCurrentContext->mStackPos, 
-                  this);
-
-  // Close out previous form if it's there. If there is one
-  // around, it's probably because the last one wasn't well-formed.
-  mCurrentForm = nsnull;
-
-  // Check if the parent is a table, tbody, thead, tfoot, tr, col or
-  // colgroup. If so, we fix up by making the form leaf content.
-  if (mCurrentContext->IsCurrentContainer(eHTMLTag_table) ||
-      mCurrentContext->IsCurrentContainer(eHTMLTag_tbody) ||
-      mCurrentContext->IsCurrentContainer(eHTMLTag_thead) ||
-      mCurrentContext->IsCurrentContainer(eHTMLTag_tfoot) ||
-      mCurrentContext->IsCurrentContainer(eHTMLTag_tr) ||
-      mCurrentContext->IsCurrentContainer(eHTMLTag_col) ||
-      mCurrentContext->IsCurrentContainer(eHTMLTag_colgroup)) {
-    result = mCurrentContext->AddLeaf(aNode);
-  } else {
-    mFormOnStack = true;
-    // Otherwise the form can be a content parent.
-    result = mCurrentContext->OpenContainer(aNode);
-  }
-
-  return result;
-}
-
-nsresult
-HTMLContentSink::CloseForm()
-{
-  nsresult result = NS_OK;
-
-  SINK_TRACE_NODE(SINK_TRACE_CALLS,
-                  "HTMLContentSink::CloseForm",
-                  eHTMLTag_form,
-                  mCurrentContext->mStackPos - 1, 
-                  this);
-
-  if (mCurrentForm) {
-    // if this is a well-formed form, close it too
-    if (mCurrentContext->IsCurrentContainer(eHTMLTag_form)) {
-      result = mCurrentContext->CloseContainer(eHTMLTag_form);
-      mFormOnStack = false;
-    }
-
-    mCurrentForm = nsnull;
-  }
-
-  return result;
-}
-
 NS_IMETHODIMP
 HTMLContentSink::IsEnabled(PRInt32 aTag, bool* aReturn)
 {
   nsHTMLTag theHTMLTag = nsHTMLTag(aTag);
 
   if (theHTMLTag == eHTMLTag_script) {
     *aReturn = mScriptEnabled;
   } else if (theHTMLTag == eHTMLTag_frameset) {
@@ -1988,17 +1856,18 @@ HTMLContentSink::OpenContainer(const nsI
         AddAttributes(aNode, mRoot, true, mNotifiedRootInsertion);
         if (!mNotifiedRootInsertion) {
           NotifyRootInsertion();
         }
         ProcessOfflineManifest(mRoot);
       }
       break;
     case eHTMLTag_form:
-      rv = OpenForm(aNode);
+      MOZ_NOT_REACHED("Must not use HTMLContentSink for forms.");
+      rv = NS_ERROR_NOT_IMPLEMENTED;
       break;
     default:
       rv = mCurrentContext->OpenContainer(aNode);
       break;
   }
 
   return rv;
 }
@@ -2018,17 +1887,18 @@ HTMLContentSink::CloseContainer(const eH
       break;
     case eHTMLTag_body:
       rv = CloseBody();
       break;
     case eHTMLTag_html:
       rv = CloseHTML();
       break;
     case eHTMLTag_form:
-      rv = CloseForm();
+      MOZ_NOT_REACHED("Must not use HTMLContentSink for forms.");
+      rv = NS_ERROR_NOT_IMPLEMENTED;
       break;
     default:
       rv = mCurrentContext->CloseContainer(aTag);
       break;
   }
 
   return rv;
 }