Bug 1013936, part 1 - Add various methods to nsIDocument to help determine its type. r=bz
authorJonathan Watt <jwatt@jwatt.org>
Sat, 24 May 2014 20:28:48 +0100
changeset 184823 027f3c05a629b613a9e88dcbb788ae34bfc9c688
parent 184822 b42ec325e34dd39f86f6fe87bf4a7a431513962e
child 184824 feff69cd698fec5e1fcc8fe7ed9418b13c98446f
push id26836
push usercbook@mozilla.com
push dateMon, 26 May 2014 12:37:49 +0000
treeherdermozilla-central@5cd52de816f9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1013936
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1013936, part 1 - Add various methods to nsIDocument to help determine its type. r=bz
content/base/public/nsIDocument.h
content/base/src/nsDocument.cpp
content/html/document/src/nsHTMLDocument.cpp
content/html/document/src/nsHTMLDocument.h
content/svg/document/src/SVGDocument.h
content/xml/document/src/XMLDocument.cpp
content/xul/document/src/XULDocument.cpp
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -1216,25 +1216,33 @@ public:
   /**
    * Returns true if this is what HTML 5 calls an "HTML document" (for example
    * regular HTML document with Content-Type "text/html", image documents and
    * media documents).  Returns false for XHTML and any other documents parsed
    * by the XML parser.
    */
   bool IsHTML() const
   {
-    return mIsRegularHTML;
+    return mType == eHTML;
+  }
+  bool IsHTMLOrXHTML() const
+  {
+    return mType == eHTML || mType == eXHTML;
   }
   bool IsXML() const
   {
     return !IsHTML();
   }
+  bool IsSVG() const
+  {
+    return mType == eSVG;
+  }
   bool IsXUL() const
   {
-    return mIsXUL;
+    return mType == eXUL;
   }
   bool IsUnstyledDocument()
   {
     return IsLoadedAsData() || IsLoadedAsInteractiveData();
   }
   bool LoadsFullXULStyleSheetUpFront()
   {
     return IsXUL() || AllowXULXBL();
@@ -2397,25 +2405,16 @@ protected:
   bool mMathMLEnabled;
 
   // True if this document is the initial document for a window.  This should
   // basically be true only for documents that exist in newly-opened windows or
   // documents created to satisfy a GetDocument() on a window when there's no
   // document in it.
   bool mIsInitialDocumentInWindow;
 
-  bool mIsRegularHTML;
-  bool mIsXUL;
-
-  enum {
-    eTriUnset = 0,
-    eTriFalse,
-    eTriTrue
-  } mAllowXULXBL;
-
   // True if we're loaded as data and therefor has any dangerous stuff, such
   // as scripts and plugins, disabled.
   bool mLoadedAsData;
 
   // This flag is only set in XMLDocument, for e.g. documents used in XBL. We
   // don't want animations to play in such documents, so we need to store the
   // flag here so that we can check it in nsDocument::GetAnimationController.
   bool mLoadedAsInteractiveData;
@@ -2509,16 +2508,37 @@ protected:
 #ifdef DEBUG
   /**
    * This is true while FlushPendingLinkUpdates executes.  Calls to
    * [Un]RegisterPendingLinkUpdate will assert when this is true.
    */
   bool mIsLinkUpdateRegistrationsForbidden;
 #endif
 
+  enum Type {
+    eUnknown, // should never be used
+    eHTML,
+    eXHTML,
+    eGenericXML,
+    eSVG,
+    eXUL
+  };
+
+  uint8_t mType;
+
+  uint8_t mDefaultElementType;
+
+  enum {
+    eTriUnset = 0,
+    eTriFalse,
+    eTriTrue
+  };
+
+  uint8_t mAllowXULXBL;
+
   // The document's script global object, the object from which the
   // document can get its script context and scope. This is the
   // *inner* window object.
   nsCOMPtr<nsIScriptGlobalObject> mScriptGlobalObject;
 
   // If mIsStaticDocument is true, mOriginalDocument points to the original
   // document.
   nsCOMPtr<nsIDocument> mOriginalDocument;
@@ -2591,18 +2611,16 @@ protected:
   nsIBFCacheEntry *mBFCacheEntry;
 
   // Our base target.
   nsString mBaseTarget;
 
   nsCOMPtr<nsIStructuredCloneContainer> mStateObjectContainer;
   nsCOMPtr<nsIVariant> mStateObjectCached;
 
-  uint8_t mDefaultElementType;
-
   uint32_t mInSyncOperationCount;
 
   nsRefPtr<mozilla::dom::XPathEvaluator> mXPathEvaluator;
 
   uint32_t mBlockDOMContentLoaded;
   bool mDidFireDOMContentLoaded:1;
 };
 
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -9109,17 +9109,17 @@ nsDocument::CloneDocHelper(nsDocument* c
   clone->mCharacterSetSource = mCharacterSetSource;
   clone->mCompatMode = mCompatMode;
   clone->mBidiOptions = mBidiOptions;
   clone->mContentLanguage = mContentLanguage;
   clone->SetContentTypeInternal(GetContentTypeInternal());
   clone->mSecurityInfo = mSecurityInfo;
 
   // State from nsDocument
-  clone->mIsRegularHTML = mIsRegularHTML;
+  clone->mType = mType;
   clone->mXMLDeclarationBits = mXMLDeclarationBits;
   clone->mBaseTarget = mBaseTarget;
   return NS_OK;
 }
 
 void
 nsDocument::SetReadyStateInternal(ReadyState rs)
 {
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -185,17 +185,17 @@ NS_NewHTMLDocument(nsIDocument** aInstan
   // bother initializing members to 0.
 
 nsHTMLDocument::nsHTMLDocument()
   : nsDocument("text/html")
 {
   // NOTE! nsDocument::operator new() zeroes out all members, so don't
   // bother initializing members to 0.
 
-  mIsRegularHTML = true;
+  mType = eHTML;
   mDefaultElementType = kNameSpaceID_XHTML;
   mCompatMode = eCompatibility_NavQuirks;
 }
 
 nsHTMLDocument::~nsHTMLDocument()
 {
 }
 
@@ -530,17 +530,18 @@ nsHTMLDocument::StartDocumentLoad(const 
   if (!aCommand) {
     MOZ_ASSERT(false, "Command is mandatory");
     return NS_ERROR_INVALID_POINTER;
   }
   if (aSink) {
     MOZ_ASSERT(false, "Got a sink override. Should not happen for HTML doc.");
     return NS_ERROR_INVALID_ARG;
   }
-  if (!mIsRegularHTML) {
+  if (mType != eHTML) {
+    MOZ_ASSERT(mType == eXHTML);
     MOZ_ASSERT(false, "Must not set HTML doc to XHTML mode before load start.");
     return NS_ERROR_DOM_INVALID_STATE_ERR;
   }
 
   nsAutoCString contentType;
   aChannel->GetContentType(contentType);
 
   bool view = !strcmp(aCommand, "view") ||
@@ -560,17 +561,17 @@ nsHTMLDocument::StartDocumentLoad(const 
     MOZ_ASSERT(false, "Channel with bad content type.");
     return NS_ERROR_INVALID_ARG;
   }
 
   bool loadAsHtml5 = true;
 
   if (!viewSource && xhtml) {
       // We're parsing XHTML as XML, remember that.
-      mIsRegularHTML = false;
+      mType = eXHTML;
       mCompatMode = eCompatibility_FullStandards;
       loadAsHtml5 = false;
   }
   
   // TODO: Proper about:blank treatment is bug 543435
   if (loadAsHtml5 && view) {
     // mDocumentURI hasn't been set, yet, so get the URI from the channel
     nsCOMPtr<nsIURI> uri;
@@ -3570,17 +3571,18 @@ nsHTMLDocument::DocAddSizeOfExcludingThi
   // - mFormControls
   // - mWyciwygChannel
   // - mMidasCommandManager
 }
 
 bool
 nsHTMLDocument::WillIgnoreCharsetOverride()
 {
-  if (!mIsRegularHTML) {
+  if (mType != eHTML) {
+    MOZ_ASSERT(mType == eXHTML);
     return true;
   }
   if (mCharacterSetSource == kCharsetFromByteOrderMark) {
     return true;
   }
   if (!EncodingUtils::IsAsciiCompatible(mCharacterSet)) {
     return true;
   }
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -106,17 +106,20 @@ public:
   mozilla::dom::HTMLAllCollection* All();
 
   nsISupports* ResolveName(const nsAString& aName, nsWrapperCache **aCache);
 
   virtual void AddedForm() MOZ_OVERRIDE;
   virtual void RemovedForm() MOZ_OVERRIDE;
   virtual int32_t GetNumFormsSynchronous() MOZ_OVERRIDE;
   virtual void TearingDownEditor(nsIEditor *aEditor) MOZ_OVERRIDE;
-  virtual void SetIsXHTML(bool aXHTML) MOZ_OVERRIDE { mIsRegularHTML = !aXHTML; }
+  virtual void SetIsXHTML(bool aXHTML) MOZ_OVERRIDE
+  {
+    mType = (aXHTML ? eXHTML : eHTML);
+  }
   virtual void SetDocWriteDisabled(bool aDisabled) MOZ_OVERRIDE
   {
     mDisableDocWrite = aDisabled;
   }
 
   nsresult ChangeContentEditableCount(nsIContent *aElement, int32_t aChange) MOZ_OVERRIDE;
   void DeferredContentEditableCountChange(nsIContent *aElement);
 
--- a/content/svg/document/src/SVGDocument.h
+++ b/content/svg/document/src/SVGDocument.h
@@ -15,16 +15,17 @@ namespace mozilla {
 namespace dom {
 
 class SVGDocument MOZ_FINAL : public XMLDocument
 {
 public:
   SVGDocument()
     : XMLDocument("image/svg+xml")
   {
+    mType = eSVG;
   }
 
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE;
 
   // WebIDL API
   void GetDomain(nsAString& aDomain, ErrorResult& aRv);
   nsSVGElement* GetRootElement(ErrorResult& aRv);
 
--- a/content/xml/document/src/XMLDocument.cpp
+++ b/content/xml/document/src/XMLDocument.cpp
@@ -214,16 +214,18 @@ namespace mozilla {
 namespace dom {
 
 XMLDocument::XMLDocument(const char* aContentType)
   : nsDocument(aContentType),
     mAsync(true)
 {
   // NOTE! nsDocument::operator new() zeroes out all members, so don't
   // bother initializing members to 0.
+
+  mType = eGenericXML;
 }
 
 XMLDocument::~XMLDocument()
 {
   // XXX We rather crash than hang
   mLoopingForSyncLoad = false;
 }
 
--- a/content/xul/document/src/XULDocument.cpp
+++ b/content/xul/document/src/XULDocument.cpp
@@ -197,17 +197,17 @@ XULDocument::XULDocument(void)
 {
     // NOTE! nsDocument::operator new() zeroes out all members, so don't
     // bother initializing members to 0.
 
     // Override the default in nsDocument
     mCharacterSet.AssignLiteral("UTF-8");
 
     mDefaultElementType = kNameSpaceID_XUL;
-    mIsXUL = true;
+    mType = eXUL;
 
     mDelayFrameLoaderInitialization = true;
 
     mAllowXULXBL = eTriTrue;
 }
 
 XULDocument::~XULDocument()
 {