Bug 1376164 - Turn nsDocumentViewer::mHintCharset and mForceCharacterSet into const mozilla::Encoding*. r=hsivonen
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sun, 25 Jun 2017 22:46:08 +0900
changeset 414920 5554fd16af9b429902897cb1d32f1fcd7d47517b
parent 414919 8a35db6fffa6adbb42fb3f5f837c55ad124399e7
child 414921 886e2e0b90a7e7c44b4d41b232de9a71255d3969
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs1376164
milestone56.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 1376164 - Turn nsDocumentViewer::mHintCharset and mForceCharacterSet into const mozilla::Encoding*. r=hsivonen MozReview-Commit-ID: HTi2eNwDH99
docshell/base/nsDocShell.cpp
docshell/base/nsIContentViewer.idl
dom/html/nsHTMLDocument.cpp
layout/base/nsDocumentViewer.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -9387,18 +9387,18 @@ nsDocShell::SetupNewViewer(nsIContentVie
   // Init settings
   DoGetPositionAndSize(&x, &y, &cx, &cy);
 
   nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
   NS_ENSURE_SUCCESS(GetSameTypeParent(getter_AddRefs(parentAsItem)),
                     NS_ERROR_FAILURE);
   nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
 
-  nsAutoCString forceCharset;
-  nsAutoCString hintCharset;
+  const Encoding* forceCharset = nullptr;
+  const Encoding* hintCharset = nullptr;
   int32_t hintCharsetSource;
   int32_t minFontSize;
   float textZoom;
   float pageZoom;
   float overrideDPPX;
   bool styleDisabled;
   // |newMUDV| also serves as a flag to set the data from the above vars
   nsCOMPtr<nsIContentViewer> newCv;
@@ -9423,20 +9423,18 @@ nsDocShell::SetupNewViewer(nsIContentVie
     } else {
       // No old content viewer, so get state from parent's content viewer
       parent->GetContentViewer(getter_AddRefs(oldCv));
     }
 
     if (oldCv) {
       newCv = aNewViewer;
       if (newCv) {
-        NS_ENSURE_SUCCESS(oldCv->GetForceCharacterSet(forceCharset),
-                          NS_ERROR_FAILURE);
-        NS_ENSURE_SUCCESS(oldCv->GetHintCharacterSet(hintCharset),
-                          NS_ERROR_FAILURE);
+        forceCharset = oldCv->GetForceCharset();
+        hintCharset = oldCv->GetHintCharset();
         NS_ENSURE_SUCCESS(oldCv->GetHintCharacterSetSource(&hintCharsetSource),
                           NS_ERROR_FAILURE);
         NS_ENSURE_SUCCESS(oldCv->GetMinFontSize(&minFontSize),
                           NS_ERROR_FAILURE);
         NS_ENSURE_SUCCESS(oldCv->GetTextZoom(&textZoom),
                           NS_ERROR_FAILURE);
         NS_ENSURE_SUCCESS(oldCv->GetFullZoom(&pageZoom),
                           NS_ERROR_FAILURE);
@@ -9493,20 +9491,18 @@ nsDocShell::SetupNewViewer(nsIContentVie
     mContentViewer = nullptr;
     NS_WARNING("ContentViewer Initialization failed");
     return NS_ERROR_FAILURE;
   }
 
   // If we have old state to copy, set the old state onto the new content
   // viewer
   if (newCv) {
-    NS_ENSURE_SUCCESS(newCv->SetForceCharacterSet(forceCharset),
-                      NS_ERROR_FAILURE);
-    NS_ENSURE_SUCCESS(newCv->SetHintCharacterSet(hintCharset),
-                      NS_ERROR_FAILURE);
+    newCv->SetForceCharset(forceCharset);
+    newCv->SetHintCharset(hintCharset);
     NS_ENSURE_SUCCESS(newCv->SetHintCharacterSetSource(hintCharsetSource),
                       NS_ERROR_FAILURE);
     NS_ENSURE_SUCCESS(newCv->SetMinFontSize(minFontSize),
                       NS_ERROR_FAILURE);
     NS_ENSURE_SUCCESS(newCv->SetTextZoom(textZoom),
                       NS_ERROR_FAILURE);
     NS_ENSURE_SUCCESS(newCv->SetFullZoom(pageZoom),
                       NS_ERROR_FAILURE);
--- a/docshell/base/nsIContentViewer.idl
+++ b/docshell/base/nsIContentViewer.idl
@@ -16,25 +16,29 @@ interface nsIPrintSettings;
 #include "nsTArray.h"
 #include "nsRect.h"
 
 class nsIWidget;
 class nsIPresShell;
 class nsPresContext;
 class nsView;
 class nsDOMNavigationTiming;
+namespace mozilla {
+class Encoding;
+}
 %}
 
 [ptr] native nsIWidgetPtr(nsIWidget);
 [ref] native nsIntRectRef(nsIntRect);
 [ptr] native nsIPresShellPtr(nsIPresShell);
 [ptr] native nsPresContextPtr(nsPresContext);
 [ptr] native nsViewPtr(nsView);
 [ptr] native nsDOMNavigationTimingPtr(nsDOMNavigationTiming);
 [ref] native nsIContentViewerTArray(nsTArray<nsCOMPtr<nsIContentViewer> >);
+[ptr] native Encoding(const mozilla::Encoding);
 
 [scriptable, builtinclass, uuid(2da17016-7851-4a45-a7a8-00b360e01595)]
 interface nsIContentViewer : nsISupports
 {
   [noscript] void init(in nsIWidgetPtr aParentWidget,
                        [const] in nsIntRectRef aBounds);
 
   attribute nsIDocShell container;
@@ -277,9 +281,14 @@ interface nsIContentViewer : nsISupports
    * @param mediaType The media type to be emulated
    */
   void emulateMedium(in AString aMediaType);
 
   /*
    * Restore the viewer's natural media type
    */
   void stopEmulatingMedium();
+
+  [noscript, notxpcom] Encoding getHintCharset();
+  [noscript, notxpcom] void setHintCharset(in Encoding aEncoding);
+  [noscript, notxpcom] Encoding getForceCharset();
+  [noscript, notxpcom] void setForceCharset(in Encoding aEncoding);
 };
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -146,30 +146,16 @@ static bool ConvertToMidasInternalComman
 static bool ConvertToMidasInternalCommand(const nsAString & inCommandID,
                                             nsACString& outCommandID);
 
 // ==================================================================
 // =
 // ==================================================================
 
 static bool
-IsAsciiCompatible(const nsACString& aPreferredName)
-{
-  // HZ and UTF-7 are no longer in mozilla-central, but keeping them here
-  // just in case for the benefit of comm-central.
-  return !(aPreferredName.LowerCaseEqualsLiteral("utf-16") ||
-           aPreferredName.LowerCaseEqualsLiteral("utf-16be") ||
-           aPreferredName.LowerCaseEqualsLiteral("utf-16le") ||
-           aPreferredName.LowerCaseEqualsLiteral("replacement") ||
-           aPreferredName.LowerCaseEqualsLiteral("hz-gb-2312") ||
-           aPreferredName.LowerCaseEqualsLiteral("utf-7") ||
-           aPreferredName.LowerCaseEqualsLiteral("x-imap4-modified-utf7"));
-}
-
-static bool
 IsAsciiCompatible(const Encoding* aEncoding)
 {
   return aEncoding->IsAsciiCompatible() || aEncoding == ISO_2022_JP_ENCODING;
 }
 
 nsresult
 NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData)
 {
@@ -295,63 +281,56 @@ nsHTMLDocument::TryHintCharset(nsIConten
                                int32_t& aCharsetSource,
                                NotNull<const Encoding*>& aEncoding)
 {
   if (aCv) {
     int32_t requestCharsetSource;
     nsresult rv = aCv->GetHintCharacterSetSource(&requestCharsetSource);
 
     if(NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) {
-      nsAutoCString requestCharset;
-      rv = aCv->GetHintCharacterSet(requestCharset);
+      auto requestCharset = aCv->GetHintCharset();
       aCv->SetHintCharacterSetSource((int32_t)(kCharsetUninitialized));
 
       if (requestCharsetSource <= aCharsetSource)
         return;
 
-      if (NS_SUCCEEDED(rv) && !requestCharset.IsEmpty()) {
-        auto encoding = Encoding::ForName(requestCharset);
-        if (IsAsciiCompatible(encoding)) {
-          aCharsetSource = requestCharsetSource;
-          aEncoding = encoding;
-        }
-        return;
+      if (requestCharset && IsAsciiCompatible(requestCharset)) {
+        aCharsetSource = requestCharsetSource;
+        aEncoding = WrapNotNull(requestCharset);
       }
+      return;
     }
   }
   return;
 }
 
 
 void
 nsHTMLDocument::TryUserForcedCharset(nsIContentViewer* aCv,
                                      nsIDocShell*  aDocShell,
                                      int32_t& aCharsetSource,
                                      NotNull<const Encoding*>& aEncoding)
 {
-  nsresult rv = NS_OK;
-
   if(kCharsetFromUserForced <= aCharsetSource)
     return;
 
   // mCharacterSet not updated yet for channel, so check aEncoding, too.
   if (WillIgnoreCharsetOverride() || !IsAsciiCompatible(aEncoding)) {
     return;
   }
 
-  nsAutoCString forceCharsetFromDocShell;
+  const Encoding* forceCharsetFromDocShell = nullptr;
   if (aCv) {
     // XXX mailnews-only
-    rv = aCv->GetForceCharacterSet(forceCharsetFromDocShell);
+    forceCharsetFromDocShell = aCv->GetForceCharset();
   }
 
-  if(NS_SUCCEEDED(rv) &&
-     !forceCharsetFromDocShell.IsEmpty() &&
+  if(forceCharsetFromDocShell &&
      IsAsciiCompatible(forceCharsetFromDocShell)) {
-    aEncoding = Encoding::ForName(forceCharsetFromDocShell);
+    aEncoding = WrapNotNull(forceCharsetFromDocShell);
     aCharsetSource = kCharsetFromUserForced;
     return;
   }
 
   if (aDocShell) {
     // This is the Character Encoding menu code path in Firefox
     auto encoding = nsDocShell::Cast(aDocShell)->GetForcedCharset();
 
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -397,19 +397,19 @@ protected:
 
 #ifdef DEBUG
   FILE* mDebugFile;
 #endif // DEBUG
 #endif // NS_PRINTING
 
   /* character set member data */
   int32_t mHintCharsetSource;
-  nsCString mHintCharset;
-  nsCString mForceCharacterSet;
-  
+  const Encoding* mHintCharset;
+  const Encoding* mForceCharacterSet;
+
   bool mIsPageMode;
   bool mInitializedForPrintPreview;
   bool mHidden;
   bool mPrintRelated; // Only use for asserts.
   bool mPresShellDestroyed; // Only use for asserts.
   bool mDestroyWasFull; // Only use for asserts.
 };
 
@@ -537,16 +537,18 @@ nsDocumentViewer::nsDocumentViewer()
     mOriginalPrintPreviewScale(0.0),
     mPrintPreviewZoom(1.0),
 #endif // NS_PRINT_PREVIEW
 #ifdef DEBUG
     mDebugFile(nullptr),
 #endif // DEBUG
 #endif // NS_PRINTING
     mHintCharsetSource(kCharsetUninitialized),
+    mHintCharset(nullptr),
+    mForceCharacterSet(nullptr),
     mIsPageMode(false),
     mInitializedForPrintPreview(false),
     mHidden(false),
     mPrintRelated(false),
     mPresShellDestroyed(true),
     mDestroyWasFull(false)
 {
   PrepareToStartLoad();
@@ -3359,25 +3361,37 @@ nsDocumentViewer::StopEmulatingMedium()
                                           nullptr);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsDocumentViewer::GetForceCharacterSet(nsACString& aForceCharacterSet)
 {
-  aForceCharacterSet = mForceCharacterSet;
+  auto encoding = nsDocumentViewer::GetForceCharset();
+  if (encoding) {
+    encoding->Name(aForceCharacterSet);
+  } else {
+    aForceCharacterSet.Truncate();
+  }
   return NS_OK;
 }
 
+/* [noscript,notxpcom] Encoding getForceCharset (); */
+NS_IMETHODIMP_(const Encoding *)
+nsDocumentViewer::GetForceCharset()
+{
+  return mForceCharacterSet;
+}
+
 static void
 SetChildForceCharacterSet(nsIContentViewer* aChild, void* aClosure)
 {
-  const nsACString* charset = static_cast<nsACString*>(aClosure);
-  aChild->SetForceCharacterSet(*charset);
+  auto encoding = static_cast<const Encoding*>(aClosure);
+  aChild->SetForceCharset(encoding);
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::SetForceCharacterSet(const nsACString& 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
@@ -3386,39 +3400,52 @@ nsDocumentViewer::SetForceCharacterSet(c
   if (!aForceCharacterSet.IsEmpty()) {
     if (aForceCharacterSet.EqualsLiteral("replacement")) {
       encoding = REPLACEMENT_ENCODING;
     } else if (!(encoding = Encoding::ForLabel(aForceCharacterSet))) {
       // Reject unknown labels
       return NS_ERROR_INVALID_ARG;
     }
   }
-  if (encoding) {
-    encoding->Name(mForceCharacterSet);
-  } else {
-    mForceCharacterSet.Truncate();
-  }
+  nsDocumentViewer::SetForceCharset(encoding);
+  return NS_OK;
+}
+
+/* [noscript,notxpcom] void setForceCharset (in Encoding aEncoding); */
+NS_IMETHODIMP_(void)
+nsDocumentViewer::SetForceCharset(const Encoding *aEncoding)
+{
+  mForceCharacterSet = aEncoding;
   // now set the force char set on all children of mContainer
-  CallChildren(SetChildForceCharacterSet, (void*) &aForceCharacterSet);
-  return NS_OK;
+  CallChildren(SetChildForceCharacterSet, (void*) aEncoding);
 }
 
 NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSet(nsACString& aHintCharacterSet)
 {
-
-  if(kCharsetUninitialized == mHintCharsetSource) {
-    aHintCharacterSet.Truncate();
+  auto encoding = nsDocumentViewer::GetHintCharset();
+  if (encoding) {
+    encoding->Name(aHintCharacterSet);
   } else {
-    aHintCharacterSet = mHintCharset;
-    // this can't possibly be right.  we can't set a value just because somebody got a related value!
-    //mHintCharsetSource = kCharsetUninitialized;
+    aHintCharacterSet.Truncate();
   }
   return NS_OK;
 }
 
+/* [noscript,notxpcom] Encoding getHintCharset (); */
+NS_IMETHODIMP_(const Encoding *)
+nsDocumentViewer::GetHintCharset()
+{
+  if(kCharsetUninitialized == mHintCharsetSource) {
+    return nullptr;
+  }
+  // this can't possibly be right.  we can't set a value just because somebody got a related value!
+  //mHintCharsetSource = kCharsetUninitialized;
+  return mHintCharset;
+}
+
 NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSetSource(int32_t *aHintCharacterSetSource)
 {
   NS_ENSURE_ARG_POINTER(aHintCharacterSetSource);
 
   *aHintCharacterSetSource = mHintCharsetSource;
   return NS_OK;
 }
 
@@ -3436,18 +3463,18 @@ nsDocumentViewer::SetHintCharacterSetSou
   CallChildren(SetChildHintCharacterSetSource,
                       NS_INT32_TO_PTR(aHintCharacterSetSource));
   return NS_OK;
 }
 
 static void
 SetChildHintCharacterSet(nsIContentViewer* aChild, void* aClosure)
 {
-  const nsACString* charset = static_cast<nsACString*>(aClosure);
-  aChild->SetHintCharacterSet(*charset);
+  auto encoding = static_cast<const Encoding*>(aClosure);
+  aChild->SetHintCharset(encoding);
 }
 
 NS_IMETHODIMP
 nsDocumentViewer::SetHintCharacterSet(const nsACString& 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
@@ -3456,24 +3483,27 @@ nsDocumentViewer::SetHintCharacterSet(co
   if (!aHintCharacterSet.IsEmpty()) {
     if (aHintCharacterSet.EqualsLiteral("replacement")) {
       encoding = REPLACEMENT_ENCODING;
     } else if (!(encoding = Encoding::ForLabel(aHintCharacterSet))) {
       // Reject unknown labels
       return NS_ERROR_INVALID_ARG;
     }
   }
-  if (encoding) {
-    encoding->Name(mHintCharset);
-  } else {
-    mHintCharset.Truncate();
-  }
+  nsDocumentViewer::SetHintCharset(encoding);
+  return NS_OK;
+}
+
+/* [noscript,notxpcom] void setHintCharset (in Encoding aEncoding); */
+NS_IMETHODIMP_(void)
+nsDocumentViewer::SetHintCharset(const Encoding *aEncoding)
+{
+  mHintCharset = aEncoding;
   // now set the hint char set on all children of mContainer
-  CallChildren(SetChildHintCharacterSet, (void*) &aHintCharacterSet);
-  return NS_OK;
+  CallChildren(SetChildHintCharacterSet, (void*) aEncoding);
 }
 
 static void
 AppendChildSubtree(nsIContentViewer* aChild, void* aClosure)
 {
   nsTArray<nsCOMPtr<nsIContentViewer> >& array =
     *static_cast<nsTArray<nsCOMPtr<nsIContentViewer> >*>(aClosure);
   aChild->AppendSubtree(array);