From 5dcf597768697795c7e9721eee58ed8aca085e37 Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Sat, 24 May 2014 20:28:48 +0100 Subject: [PATCH] Bug 1013936, part 1 - Add various methods to nsIDocument to help determine its type. r=bz --- content/base/public/nsIDocument.h | 44 ++++++++++++++------ content/base/src/nsDocument.cpp | 2 +- content/html/document/src/nsHTMLDocument.cpp | 10 +++-- content/html/document/src/nsHTMLDocument.h | 5 ++- content/svg/document/src/SVGDocument.h | 1 + content/xml/document/src/XMLDocument.cpp | 2 + content/xul/document/src/XULDocument.cpp | 2 +- 7 files changed, 46 insertions(+), 20 deletions(-) diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index edd0fc4a362..138e9bdbd42 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -1221,15 +1221,23 @@ public: */ 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() { @@ -2402,15 +2410,6 @@ protected: // 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; @@ -2514,6 +2513,27 @@ protected: 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. @@ -2596,8 +2616,6 @@ protected: nsCOMPtr mStateObjectContainer; nsCOMPtr mStateObjectCached; - uint8_t mDefaultElementType; - uint32_t mInSyncOperationCount; nsRefPtr mXPathEvaluator; diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index a9a0a67b3be..979e84f37a0 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -9114,7 +9114,7 @@ nsDocument::CloneDocHelper(nsDocument* clone) const clone->mSecurityInfo = mSecurityInfo; // State from nsDocument - clone->mIsRegularHTML = mIsRegularHTML; + clone->mType = mType; clone->mXMLDeclarationBits = mXMLDeclarationBits; clone->mBaseTarget = mBaseTarget; return NS_OK; diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index b168b4cce6d..476861cba6a 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -190,7 +190,7 @@ nsHTMLDocument::nsHTMLDocument() // 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; } @@ -535,7 +535,8 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, 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; } @@ -565,7 +566,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, if (!viewSource && xhtml) { // We're parsing XHTML as XML, remember that. - mIsRegularHTML = false; + mType = eXHTML; mCompatMode = eCompatibility_FullStandards; loadAsHtml5 = false; } @@ -3575,7 +3576,8 @@ nsHTMLDocument::DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const bool nsHTMLDocument::WillIgnoreCharsetOverride() { - if (!mIsRegularHTML) { + if (mType != eHTML) { + MOZ_ASSERT(mType == eXHTML); return true; } if (mCharacterSetSource == kCharsetFromByteOrderMark) { diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index 6d894d48f60..407f679bdf6 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -111,7 +111,10 @@ public: 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; diff --git a/content/svg/document/src/SVGDocument.h b/content/svg/document/src/SVGDocument.h index 53cfc134459..44ec512b080 100644 --- a/content/svg/document/src/SVGDocument.h +++ b/content/svg/document/src/SVGDocument.h @@ -20,6 +20,7 @@ public: SVGDocument() : XMLDocument("image/svg+xml") { + mType = eSVG; } virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE; diff --git a/content/xml/document/src/XMLDocument.cpp b/content/xml/document/src/XMLDocument.cpp index 54da9349127..caec937fdcd 100644 --- a/content/xml/document/src/XMLDocument.cpp +++ b/content/xml/document/src/XMLDocument.cpp @@ -219,6 +219,8 @@ XMLDocument::XMLDocument(const char* aContentType) { // NOTE! nsDocument::operator new() zeroes out all members, so don't // bother initializing members to 0. + + mType = eGenericXML; } XMLDocument::~XMLDocument() diff --git a/content/xul/document/src/XULDocument.cpp b/content/xul/document/src/XULDocument.cpp index 5067dda4e73..3b98ec9dd03 100644 --- a/content/xul/document/src/XULDocument.cpp +++ b/content/xul/document/src/XULDocument.cpp @@ -202,7 +202,7 @@ XULDocument::XULDocument(void) mCharacterSet.AssignLiteral("UTF-8"); mDefaultElementType = kNameSpaceID_XUL; - mIsXUL = true; + mType = eXUL; mDelayFrameLoaderInitialization = true;