Bug 1525662 - Part 2: Remember plain-textness of HTML documents post loading. r=hsivonen
☠☠ backed out by 10f3bcf2a0ed ☠ ☠
authorJan Henning <jh+bugzilla@buttercookie.de>
Tue, 05 Mar 2019 18:01:11 +0000
changeset 520311 f07e25fac5b20976178fb2e4dd7f95a6e252207a
parent 520310 a8ec11730706c4e34b66e19dc0d365ca5caec379
child 520312 aaa8fbdbbe48b39e1323f1b0bd741a537b45b860
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [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
@@ -174,17 +174,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,
@@ -469,25 +470,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;
@@ -524,17 +525,17 @@ nsresult nsHTMLDocument::StartDocumentLo
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   nsCOMPtr<nsICachingChannel> cachingChan = do_QueryInterface(aChannel);
 
   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 {
@@ -670,17 +671,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
@@ -333,16 +333,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);