Bug 1525662 - Part 2: Remember plain-textness of HTML documents post loading. r=hsivonen
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 23 Feb 2019 17:06:52 +0100
changeset 522002 dc422efc3103
parent 522001 65a5625c4790
child 522003 7b61f5d7f7d2
push id10870
push usernbeleuzu@mozilla.com
push dateFri, 15 Mar 2019 20:00:07 +0000
treeherdermozilla-beta@c594aee5b7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs1525662
milestone67.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 1525662 - Part 2: Remember plain-textness of HTML documents post loading. r=hsivonen Based on the current implementation of nsContentUtils::IsPlainTextType(), we could just call that function again if we need to know whether we're dealing with plain text content or not later on, but doing it this way ensures we're always consistent with the current code in StartDocumentLoad(), which includes some additional sanity checks. Differential Revision: https://phabricator.services.mozilla.com/D20952
dom/html/nsHTMLDocument.cpp
dom/html/nsHTMLDocument.h
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -176,17 +176,18 @@ nsHTMLDocument::nsHTMLDocument()
       mLoadFlags(0),
       mTooDeepWriteRecursion(false),
       mDisableDocWrite(false),
       mWarnedWidthHeight(false),
       mContentEditableCount(0),
       mEditingState(EditingState::eOff),
       mDisableCookieAccess(false),
       mPendingMaybeEditingStateChanged(false),
-      mHasBeenEditable(false) {
+      mHasBeenEditable(false),
+      mIsPlainText(false) {
   mType = eHTML;
   mDefaultElementType = kNameSpaceID_XHTML;
   mCompatMode = eCompatibility_NavQuirks;
 }
 
 nsHTMLDocument::~nsHTMLDocument() {}
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, Document, mAll,
@@ -487,25 +488,25 @@ nsresult nsHTMLDocument::StartDocumentLo
   if (!(view || viewSource || asData)) {
     MOZ_ASSERT(false, "Bad parser command");
     return NS_ERROR_INVALID_ARG;
   }
 
   bool html = contentType.EqualsLiteral(TEXT_HTML);
   bool xhtml = !html && (contentType.EqualsLiteral(APPLICATION_XHTML_XML) ||
                          contentType.EqualsLiteral(APPLICATION_WAPXHTML_XML));
-  bool plainText =
+  mIsPlainText =
       !html && !xhtml && nsContentUtils::IsPlainTextType(contentType);
-  if (!(html || xhtml || plainText || viewSource)) {
+  if (!(html || xhtml || mIsPlainText || viewSource)) {
     MOZ_ASSERT(false, "Channel with bad content type.");
     return NS_ERROR_INVALID_ARG;
   }
 
   bool forceUtf8 =
-      plainText && nsContentUtils::IsUtf8OnlyPlainTextType(contentType);
+      mIsPlainText && nsContentUtils::IsUtf8OnlyPlainTextType(contentType);
 
   bool loadAsHtml5 = true;
 
   if (!viewSource && xhtml) {
     // We're parsing XHTML as XML, remember that.
     mType = eXHTML;
     mCompatMode = eCompatibility_FullStandards;
     loadAsHtml5 = false;
@@ -544,17 +545,17 @@ nsresult nsHTMLDocument::StartDocumentLo
   }
 
   nsCOMPtr<nsICachingChannel> cachingChan = do_QueryInterface(aChannel);
   nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
 
   bool loadWithPrototype = false;
   if (loadAsHtml5) {
     mParser = nsHtml5Module::NewHtml5Parser();
-    if (plainText) {
+    if (mIsPlainText) {
       if (viewSource) {
         mParser->MarkAsNotScriptCreated("view-source-plain");
       } else {
         mParser->MarkAsNotScriptCreated("plain-text");
       }
     } else if (viewSource && !html) {
       mParser->MarkAsNotScriptCreated("view-source-xml");
     } else {
@@ -701,17 +702,17 @@ nsresult nsHTMLDocument::StartDocumentLo
       // about:blank *only*
       nsCOMPtr<nsIHTMLContentSink> htmlsink;
       NS_NewHTMLContentSink(getter_AddRefs(htmlsink), this, uri, docShell,
                             aChannel);
       mParser->SetContentSink(htmlsink);
     }
   }
 
-  if (plainText && !nsContentUtils::IsChildOfSameType(this) &&
+  if (mIsPlainText && !nsContentUtils::IsChildOfSameType(this) &&
       Preferences::GetBool("plain_text.wrap_long_lines")) {
     nsCOMPtr<nsIStringBundleService> bundleService =
         do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
     NS_ASSERTION(NS_SUCCEEDED(rv) && bundleService,
                  "The bundle service could not be loaded");
     nsCOMPtr<nsIStringBundle> bundle;
     rv = bundleService->CreateBundle(
         "chrome://global/locale/browser.properties", getter_AddRefs(bundle));
--- a/dom/html/nsHTMLDocument.h
+++ b/dom/html/nsHTMLDocument.h
@@ -338,16 +338,21 @@ class nsHTMLDocument : public mozilla::d
    * Temporary flag that is set in EndUpdate() to ignore
    * MaybeEditingStateChanged() script runners from a nested scope.
    */
   bool mPendingMaybeEditingStateChanged;
 
   // mHasBeenEditable is set to true when mEditingState is firstly set to
   // eDesignMode or eContentEditable.
   bool mHasBeenEditable;
+
+  /**
+   * Set to true once we know that we are loading plain text content.
+   */
+  bool mIsPlainText;
 };
 
 namespace mozilla {
 namespace dom {
 
 inline nsHTMLDocument* Document::AsHTMLDocument() {
   MOZ_ASSERT(IsHTMLOrXHTML());
   return static_cast<nsHTMLDocument*>(this);