Bug 1191841 - Perform label resolution in scriptable charset setters of nsIContentViewer. r=emk, a=rkent THUNDERBIRD_45_VERBRANCH
authorHenri Sivonen <hsivonen@hsivonen.fi>
Mon, 22 Aug 2016 20:18:24 +0300
branchTHUNDERBIRD_45_VERBRANCH
changeset 312616 83ee87b301bd952e4fef2de8189062ea0b19276a
parent 312615 5c894801eb1e1269e4e5d940402d0389c46f6daf
child 312617 eb6f18dbfe8db1093d52590efa19f9d1bebef7dd
push id398
push userkent@caspia.com
push dateMon, 23 Jan 2017 21:52:12 +0000
treeherdermozilla-esr45@83ee87b301bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk, rkent
bugs1191841
milestone45.7.0
Bug 1191841 - Perform label resolution in scriptable charset setters of nsIContentViewer. r=emk, a=rkent MozReview-Commit-ID: facCC1K7Dk
layout/base/nsDocumentViewer.cpp
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -3136,17 +3136,31 @@ SetChildForceCharacterSet(nsIContentView
 {
   const nsACString* charset = static_cast<nsACString*>(aClosure);
   aChild->SetForceCharacterSet(*charset);
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::SetForceCharacterSet(const nsACString& aForceCharacterSet)
 {
-  mForceCharacterSet = aForceCharacterSet;
+  // This method is scriptable, so add-ons could pass in something other
+  // than a canonical name. However, in case where the input is a canonical
+  // name, "replacement" doesn't survive label resolution. Additionally, the
+  // empty string means no hint.
+  nsAutoCString encoding;
+  if (!aForceCharacterSet.IsEmpty()) {
+    if (aForceCharacterSet.EqualsLiteral("replacement")) {
+      encoding.AssignLiteral("replacement");
+    } else if (!EncodingUtils::FindEncodingForLabel(aForceCharacterSet,
+                                                    encoding)) {
+      // Reject unknown labels
+      return NS_ERROR_INVALID_ARG;
+    }
+  }
+  mForceCharacterSet = encoding;
   // now set the force char set on all children of mContainer
   CallChildren(SetChildForceCharacterSet, (void*) &aForceCharacterSet);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSet(nsACString& aHintCharacterSet)
 {
 
@@ -3189,17 +3203,31 @@ SetChildHintCharacterSet(nsIContentViewe
 {
   const nsACString* charset = static_cast<nsACString*>(aClosure);
   aChild->SetHintCharacterSet(*charset);
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::SetHintCharacterSet(const nsACString& aHintCharacterSet)
 {
-  mHintCharset = aHintCharacterSet;
+  // This method is scriptable, so add-ons could pass in something other
+  // than a canonical name. However, in case where the input is a canonical
+  // name, "replacement" doesn't survive label resolution. Additionally, the
+  // empty string means no hint.
+  nsAutoCString encoding;
+  if (!aHintCharacterSet.IsEmpty()) {
+    if (aHintCharacterSet.EqualsLiteral("replacement")) {
+      encoding.AssignLiteral("replacement");
+    } else if (!EncodingUtils::FindEncodingForLabel(aHintCharacterSet,
+                                                    encoding)) {
+      // Reject unknown labels
+      return NS_ERROR_INVALID_ARG;
+    }
+  }
+  mHintCharset = encoding;
   // now set the hint char set on all children of mContainer
   CallChildren(SetChildHintCharacterSet, (void*) &aHintCharacterSet);
   return NS_OK;
 }
 
 static void
 AppendChildSubtree(nsIContentViewer* aChild, void* aClosure)
 {