Backout 6db369a15ea7 (bug 599320) for frequent failures in bug599320-1.html
authorEd Morley <emorley@mozilla.com>
Tue, 16 Oct 2012 12:22:31 +0100
changeset 110534 ea4e5cb4e240f13062ba60595ff0c003d224e6c1
parent 110533 bf68f3cd1e66c1f27544d13acad5cf767348d1b9
child 110535 2eeaa1babcb5c299332261f5de81b800f4027af6
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
bugs599320
milestone19.0a1
backs out6db369a15ea76e1226b1b03435ac44cc55981943
Backout 6db369a15ea7 (bug 599320) for frequent failures in bug599320-1.html
content/html/document/src/nsHTMLDocument.cpp
content/html/document/src/nsHTMLDocument.h
parser/html/nsHtml5MetaScannerCppSupplement.h
parser/html/nsHtml5StreamParser.cpp
parser/htmlparser/tests/reftest/bug599320-1-ref.html
parser/htmlparser/tests/reftest/bug599320-1.html
parser/htmlparser/tests/reftest/frame599320-1-ref.html
parser/htmlparser/tests/reftest/frame599320-1.html
parser/htmlparser/tests/reftest/reftest.list
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -308,41 +308,45 @@ nsHTMLDocument::CreateShell(nsPresContex
                             nsIViewManager* aViewManager,
                             nsStyleSet* aStyleSet,
                             nsIPresShell** aInstancePtrResult)
 {
   return doCreateShell(aContext, aViewManager, aStyleSet, mCompatMode,
                        aInstancePtrResult);
 }
 
-void
+// The following Try*Charset will return false only if the charset source
+// should be considered (ie. aCharsetSource < thisCharsetSource) but we failed
+// to get the charset from this source.
+
+bool
 nsHTMLDocument::TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
                                int32_t& aCharsetSource, nsACString& aCharset)
 {
   if (aMarkupDV) {
     int32_t requestCharsetSource;
     nsresult rv = aMarkupDV->GetHintCharacterSetSource(&requestCharsetSource);
 
     if(NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) {
       nsAutoCString requestCharset;
       rv = aMarkupDV->GetHintCharacterSet(requestCharset);
       aMarkupDV->SetHintCharacterSetSource((int32_t)(kCharsetUninitialized));
 
       if(requestCharsetSource <= aCharsetSource)
-        return;
-
-      if(NS_SUCCEEDED(rv) && IsAsciiCompatible(requestCharset)) {
+        return true;
+
+      if(NS_SUCCEEDED(rv)) {
         aCharsetSource = requestCharsetSource;
         aCharset = requestCharset;
 
-        return;
+        return true;
       }
     }
   }
-  return;
+  return false;
 }
 
 
 bool
 nsHTMLDocument::TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
                                      nsIDocShell*  aDocShell,
                                      int32_t& aCharsetSource,
                                      nsACString& aCharset)
@@ -352,18 +356,16 @@ nsHTMLDocument::TryUserForcedCharset(nsI
   if(kCharsetFromUserForced <= aCharsetSource)
     return true;
 
   nsAutoCString forceCharsetFromDocShell;
   if (aMarkupDV) {
     rv = aMarkupDV->GetForceCharacterSet(forceCharsetFromDocShell);
   }
 
-  // Not making the IsAsciiCompatible() check here to allow the user to
-  // force UTF-16 from the menu.
   if(NS_SUCCEEDED(rv) && !forceCharsetFromDocShell.IsEmpty()) {
     aCharset = forceCharsetFromDocShell;
     //TODO: we should define appropriate constant for force charset
     aCharsetSource = kCharsetFromUserForced;
   } else if (aDocShell) {
     nsCOMPtr<nsIAtom> csAtom;
     aDocShell->GetForcedCharset(getter_AddRefs(csAtom));
     if (csAtom) {
@@ -385,22 +387,17 @@ nsHTMLDocument::TryCacheCharset(nsICachi
   nsresult rv;
 
   if (kCharsetFromCache <= aCharsetSource) {
     return true;
   }
 
   nsCString cachedCharset;
   rv = aCachingChannel->GetCacheTokenCachedCharset(cachedCharset);
-  // Check IsAsciiCompatible() even in the cache case, because the value
-  // might be stale and in the case of a stale charset that is not a rough
-  // ASCII superset, the parser has no way to recover.
-  if (NS_SUCCEEDED(rv) &&
-      !cachedCharset.IsEmpty() &&
-      IsAsciiCompatible(cachedCharset))
+  if (NS_SUCCEEDED(rv) && !cachedCharset.IsEmpty())
   {
     aCharset = cachedCharset;
     aCharsetSource = kCharsetFromCache;
 
     return true;
   }
 
   return false;
@@ -415,113 +412,93 @@ CheckSameOrigin(nsINode* aNode1, nsINode
   bool equal;
   return
     NS_SUCCEEDED(aNode1->NodePrincipal()->
                    Equals(aNode2->NodePrincipal(), &equal)) &&
     equal;
 }
 
 bool
-nsHTMLDocument::IsAsciiCompatible(const nsACString& aPreferredName)
-{
-  return !(aPreferredName.LowerCaseEqualsLiteral("utf-16") ||
-           aPreferredName.LowerCaseEqualsLiteral("utf-16be") ||
-           aPreferredName.LowerCaseEqualsLiteral("utf-16le") ||
-           aPreferredName.LowerCaseEqualsLiteral("utf-7") ||
-           aPreferredName.LowerCaseEqualsLiteral("x-imap4-modified-utf7"));
-}
-
-void
 nsHTMLDocument::TryParentCharset(nsIDocShell*  aDocShell,
                                  nsIDocument* aParentDocument,
                                  int32_t& aCharsetSource,
                                  nsACString& aCharset)
 {
-  if (!aDocShell) {
-    return;
-  }
-  int32_t source;
-  nsCOMPtr<nsIAtom> csAtom;
-  int32_t parentSource;
-  nsAutoCString parentCharset;
-  aDocShell->GetParentCharset(getter_AddRefs(csAtom));
-  if (!csAtom) {
-    return;
-  }
-  aDocShell->GetParentCharsetSource(&parentSource);
-  csAtom->ToUTF8String(parentCharset);
-  if (kCharsetFromParentForced <= parentSource) {
-    source = kCharsetFromParentForced;
-  } else if (kCharsetFromHintPrevDoc == parentSource) {
-    // Make sure that's OK
-    if (!aParentDocument ||
-        !CheckSameOrigin(this, aParentDocument) ||
-        !IsAsciiCompatible(parentCharset)) {
-      return;
+  if (aDocShell) {
+    int32_t source;
+    nsCOMPtr<nsIAtom> csAtom;
+    int32_t parentSource;
+    aDocShell->GetParentCharsetSource(&parentSource);
+    if (kCharsetFromParentForced <= parentSource)
+      source = kCharsetFromParentForced;
+    else if (kCharsetFromHintPrevDoc == parentSource) {
+      // Make sure that's OK
+      if (!aParentDocument || !CheckSameOrigin(this, aParentDocument)) {
+        return false;
+      }
+      
+      // if parent is posted doc, set this prevent autodections
+      // I'm not sure this makes much sense... but whatever.
+      source = kCharsetFromHintPrevDoc;
     }
-
-    // if parent is posted doc, set this prevent autodetections
-    // I'm not sure this makes much sense... but whatever.
-    source = kCharsetFromHintPrevDoc;
-  } else if (kCharsetFromCache <= parentSource) {
-    // Make sure that's OK
-    if (!aParentDocument ||
-        !CheckSameOrigin(this, aParentDocument) ||
-        !IsAsciiCompatible(parentCharset)) {
-      return;
+    else if (kCharsetFromCache <= parentSource) {
+      // Make sure that's OK
+      if (!aParentDocument || !CheckSameOrigin(this, aParentDocument)) {
+        return false;
+      }
+
+      source = kCharsetFromParentFrame;
     }
-
-    source = kCharsetFromParentFrame;
-  } else {
-    return;
+    else
+      return false;
+
+    if (source < aCharsetSource)
+      return true;
+
+    aDocShell->GetParentCharset(getter_AddRefs(csAtom));
+    if (csAtom) {
+      csAtom->ToUTF8String(aCharset);
+      aCharsetSource = source;
+      return true;
+    }
   }
-
-  if (source < aCharsetSource) {
-    return;
-  }
-
-  aCharset.Assign(parentCharset);
-  aCharsetSource = source;
+  return false;
 }
 
-void
+bool
 nsHTMLDocument::UseWeakDocTypeDefault(int32_t& aCharsetSource,
                                       nsACString& aCharset)
 {
   if (kCharsetFromWeakDocTypeDefault <= aCharsetSource)
-    return;
+    return true;
+  // fallback value in case docshell return error
+  aCharset.AssignLiteral("ISO-8859-1");
 
   const nsAdoptingCString& defCharset =
     Preferences::GetLocalizedCString("intl.charset.default");
 
-  // Don't let the user break things by setting intl.charset.default to
-  // not a rough ASCII superset
-  if (!defCharset.IsEmpty() && IsAsciiCompatible(defCharset)) {
+  if (!defCharset.IsEmpty()) {
     aCharset = defCharset;
-  } else {
-    aCharset.AssignLiteral("ISO-8859-1");
+    aCharsetSource = kCharsetFromWeakDocTypeDefault;
   }
-  aCharsetSource = kCharsetFromWeakDocTypeDefault;
-  return;
+  return true;
 }
 
 bool
 nsHTMLDocument::TryDefaultCharset( nsIMarkupDocumentViewer* aMarkupDV,
                                    int32_t& aCharsetSource,
                                    nsACString& aCharset)
 {
   if(kCharsetFromUserDefault <= aCharsetSource)
     return true;
 
   nsAutoCString defaultCharsetFromDocShell;
   if (aMarkupDV) {
     nsresult rv =
       aMarkupDV->GetDefaultCharacterSet(defaultCharsetFromDocShell);
-    // Not making the IsAsciiCompatible() check here to allow the user to
-    // force UTF-16 from the menu.
     if(NS_SUCCEEDED(rv)) {
       aCharset = defaultCharsetFromDocShell;
 
       aCharsetSource = kCharsetFromUserDefault;
       return true;
     }
   }
   return false;
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -213,33 +213,31 @@ protected:
   nsRefPtr<nsContentList> mForms;
   nsRefPtr<nsContentList> mFormControls;
 
   /** # of forms in the document, synchronously set */
   int32_t mNumForms;
 
   static uint32_t gWyciwygSessionCnt;
 
-  static bool IsAsciiCompatible(const nsACString& aPreferredName);
-
-  static void TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
+  static bool TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
                                int32_t& aCharsetSource,
                                nsACString& aCharset);
   static bool TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
                                      nsIDocShell*  aDocShell,
                                      int32_t& aCharsetSource,
                                      nsACString& aCharset);
   static bool TryCacheCharset(nsICachingChannel* aCachingChannel,
                                 int32_t& aCharsetSource,
                                 nsACString& aCharset);
   // aParentDocument could be null.
-  void TryParentCharset(nsIDocShell*  aDocShell,
+  bool TryParentCharset(nsIDocShell*  aDocShell,
                           nsIDocument* aParentDocument,
                           int32_t& charsetSource, nsACString& aCharset);
-  static void UseWeakDocTypeDefault(int32_t& aCharsetSource,
+  static bool UseWeakDocTypeDefault(int32_t& aCharsetSource,
                                       nsACString& aCharset);
   static bool TryDefaultCharset(nsIMarkupDocumentViewer* aMarkupDV,
                                   int32_t& aCharsetSource,
                                   nsACString& aCharset);
 
   // Override so we can munge the charset on our wyciwyg channel as needed.
   virtual void SetDocumentCharacterSet(const nsACString& aCharSetID);
 
--- a/parser/html/nsHtml5MetaScannerCppSupplement.h
+++ b/parser/html/nsHtml5MetaScannerCppSupplement.h
@@ -51,17 +51,20 @@ nsHtml5MetaScanner::tryCharset(nsString*
   res = nsCharsetAlias::GetPreferred(encoding, preferred);
   if (NS_FAILED(res)) {
     return false;
   }
   if (preferred.LowerCaseEqualsLiteral("utf-16") ||
       preferred.LowerCaseEqualsLiteral("utf-16be") ||
       preferred.LowerCaseEqualsLiteral("utf-16le") ||
       preferred.LowerCaseEqualsLiteral("utf-7") ||
-      preferred.LowerCaseEqualsLiteral("x-imap4-modified-utf7")) {
+      preferred.LowerCaseEqualsLiteral("jis_x0212-1990") ||
+      preferred.LowerCaseEqualsLiteral("x-jis0208") ||
+      preferred.LowerCaseEqualsLiteral("x-imap4-modified-utf7") ||
+      preferred.LowerCaseEqualsLiteral("x-user-defined")) {
     return false;
   }
   res = convManager->GetUnicodeDecoderRaw(preferred.get(), getter_AddRefs(mUnicodeDecoder));
   if (res == NS_ERROR_UCONV_NOCONV) {
     return false;
   } else if (NS_FAILED(res)) {
     NS_ERROR("Getting an encoding decoder failed in a bad way.");
     mUnicodeDecoder = nullptr;
--- a/parser/html/nsHtml5StreamParser.cpp
+++ b/parser/html/nsHtml5StreamParser.cpp
@@ -1208,17 +1208,20 @@ nsHtml5StreamParser::PreferredForInterna
   // ??? Explicit further blacklist of character sets that are not
   // "rough supersets" of ASCII.  Some of these are handled above (utf-16),
   // some by the XSS smuggling blacklist in charsetData.properties,
   // maybe all of the remainder should also be blacklisted there.
   if (preferred.LowerCaseEqualsLiteral("utf-16") ||
       preferred.LowerCaseEqualsLiteral("utf-16be") ||
       preferred.LowerCaseEqualsLiteral("utf-16le") ||
       preferred.LowerCaseEqualsLiteral("utf-7") ||
-      preferred.LowerCaseEqualsLiteral("x-imap4-modified-utf7")) {
+      preferred.LowerCaseEqualsLiteral("jis_x0212-1990") ||
+      preferred.LowerCaseEqualsLiteral("x-jis0208") ||
+      preferred.LowerCaseEqualsLiteral("x-imap4-modified-utf7") ||
+      preferred.LowerCaseEqualsLiteral("x-user-defined")) {
     // Not a rough ASCII superset
     mTreeBuilder->MaybeComplainAboutCharset("EncMetaNonRoughSuperset",
                                             true,
                                             mTokenizer->getLineNumber());
     return false;
   }
   aEncoding.Assign(preferred);
   return true;
deleted file mode 100644
--- a/parser/htmlparser/tests/reftest/bug599320-1-ref.html
+++ /dev/null
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-<meta charset=utf-8>
-<meta content="width=device-width, initial-scale=1" name="viewport">
-<title>UTF-16 doc</title>
-</head>
-<body>
-<h1>UTF-16 doc</h1>
-
-<p>Euro sign: €</p>
-<p>iframe:</p>
-<iframe src=frame599320-1-ref.html width=300 height=400></iframe>
-
-</body>
-</html>
-
deleted file mode 100644
index 590e9126c3fa1abdde37eca08dd8708c670da3b2..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
--- a/parser/htmlparser/tests/reftest/frame599320-1-ref.html
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-<meta charset=utf-8>
-<meta content="width=device-width, initial-scale=1" name="viewport">
-<title>Non-UTF-16 doc</title>
-</head>
-<body>
-<h1>Non-UTF-16 doc</h1>
-
-<p>Euro sign: €</p>
-
-</body>
-</html>
-
deleted file mode 100644
--- a/parser/htmlparser/tests/reftest/frame599320-1.html
+++ /dev/null
@@ -1,1086 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-<!-- More than 1 KB of space -->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-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.document.documentElement.removeAttribute("class");</script>
-</body>
-</html>
-
--- a/parser/htmlparser/tests/reftest/reftest.list
+++ b/parser/htmlparser/tests/reftest/reftest.list
@@ -1,16 +1,15 @@
 == bug535530-1.html bug535530-1-ref.html
 == view-source:bug535530-2.html bug535530-2-ref.html
 == bug566280-1.html bug566280-1-ref.html
 == bug577418-1.html bug577418-1-ref.html
 == bug582788-1.html bug582788-1-ref.html
 == bug582940-1.html bug582940-1-ref.html
 == bug592656-1.html bug592656-1-ref.html
-== bug599320-1.html bug599320-1-ref.html
 == bug608373-1.html bug608373-1-ref.html
 fails-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia) == view-source:bug482921-1.html bug482921-1-ref.html # bug 703201
 == view-source:bug482921-2.xhtml bug482921-2-ref.html
 == bug659763-1.html bug659763-1-ref.html
 == bug659763-2.html bug659763-2-ref.html
 == bug659763-3.html bug659763-3-ref.html
 == bug659763-4.html bug659763-4-ref.html
 == bug659763-5.html bug659763-5-ref.html