Break circular dependence between {Byte,Wide}String

Make ByteString willfully ignorant that WideString exists, doing
all the conversions in WideString. It was nearly this way except
for one method, UTF8Decode, which just called into widestring
anyways.

Change-Id: Ied8077d358cac600dcc1788d47eac3ed4e380029
Reviewed-on: https://pdfium-review.googlesource.com/c/45790
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp
index 3ff0e35..4ba42f9 100644
--- a/core/fxcrt/bytestring.cpp
+++ b/core/fxcrt/bytestring.cpp
@@ -668,10 +668,6 @@
   return nCount;
 }
 
-WideString ByteString::UTF8Decode() const {
-  return WideString::FromUTF8(AsStringView());
-}
-
 int ByteString::Compare(const ByteStringView& str) const {
   if (!m_pData)
     return str.IsEmpty() ? 0 : -1;
diff --git a/core/fxcrt/bytestring.h b/core/fxcrt/bytestring.h
index 5975acb..b61ac19 100644
--- a/core/fxcrt/bytestring.h
+++ b/core/fxcrt/bytestring.h
@@ -24,7 +24,6 @@
 class ByteString_Assign_Test;
 class ByteString_Concat_Test;
 class StringPool_ByteString_Test;
-class WideString;
 
 // A mutable string with shared buffers using copy-on-write semantics that
 // avoids the cost of std::string's iterator stability guarantees.
@@ -194,11 +193,8 @@
   void TrimRight(const ByteStringView& targets);
 
   size_t Replace(const ByteStringView& lpszOld, const ByteStringView& lpszNew);
-
   size_t Remove(char ch);
 
-  WideString UTF8Decode() const;
-
   uint32_t GetID() const { return AsStringView().GetID(); }
 
  protected:
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp
index fab039c..00b4cba 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -232,7 +232,8 @@
   lf.lfItalic = pFont->IsItalic();
   lf.lfCharSet = DEFAULT_CHARSET;
 
-  const WideString wsName = pFont->GetFaceName().UTF8Decode();
+  const WideString wsName =
+      WideString::FromUTF8(pFont->GetFaceName().AsStringView());
   size_t iNameLen =
       std::min(wsName.GetLength(), static_cast<size_t>(LF_FACESIZE - 1));
   memcpy(lf.lfFaceName, wsName.c_str(), sizeof(lf.lfFaceName[0]) * iNameLen);
diff --git a/fpdfsdk/fpdf_structtree.cpp b/fpdfsdk/fpdf_structtree.cpp
index fd8f1af..74aa592 100644
--- a/fpdfsdk/fpdf_structtree.cpp
+++ b/fpdfsdk/fpdf_structtree.cpp
@@ -95,7 +95,9 @@
                            unsigned long buflen) {
   CPDF_StructElement* elem =
       CPDFStructElementFromFPDFStructElement(struct_element);
-  return elem ? WideStringToBuffer(elem->GetType().UTF8Decode(), buffer, buflen)
+  return elem ? WideStringToBuffer(
+                    WideString::FromUTF8(elem->GetType().AsStringView()),
+                    buffer, buflen)
               : 0;
 }
 
@@ -105,9 +107,10 @@
                             unsigned long buflen) {
   CPDF_StructElement* elem =
       CPDFStructElementFromFPDFStructElement(struct_element);
-  return elem
-             ? WideStringToBuffer(elem->GetTitle().UTF8Decode(), buffer, buflen)
-             : 0;
+  return elem ? WideStringToBuffer(
+                    WideString::FromUTF8(elem->GetTitle().AsStringView()),
+                    buffer, buflen)
+              : 0;
 }
 
 FPDF_EXPORT int FPDF_CALLCONV
diff --git a/fxbarcode/cbc_ean13.cpp b/fxbarcode/cbc_ean13.cpp
index a111fdb..3d3dc0a 100644
--- a/fxbarcode/cbc_ean13.cpp
+++ b/fxbarcode/cbc_ean13.cpp
@@ -42,7 +42,7 @@
     ByteString byteString = encodeContents.UTF8Encode();
     int32_t checksum = pWriter->CalcChecksum(byteString);
     byteString += checksum - 0 + '0';
-    encodeContents = byteString.UTF8Decode();
+    encodeContents = WideString::FromUTF8(byteString.AsStringView());
   }
   if (length > 13)
     encodeContents = encodeContents.Left(13);
diff --git a/fxbarcode/cbc_upca.cpp b/fxbarcode/cbc_upca.cpp
index 834eecf..c608faa 100644
--- a/fxbarcode/cbc_upca.cpp
+++ b/fxbarcode/cbc_upca.cpp
@@ -41,7 +41,7 @@
     ByteString byteString = encodeContents.UTF8Encode();
     int32_t checksum = pWriter->CalcChecksum(byteString);
     byteString += checksum - 0 + '0';
-    encodeContents = byteString.UTF8Decode();
+    encodeContents = WideString::FromUTF8(byteString.AsStringView());
   }
   if (length > 12)
     encodeContents = encodeContents.Left(12);
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index 35619c0..6589f70 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -326,15 +326,16 @@
         SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::NUMBER,
                            pData->data.dData, false, "",
                            v8::Local<v8::Object>(), pData->bPersistent == 1);
-        pRuntime->PutObjectProperty(ToV8Object(), pData->data.sKey.UTF8Decode(),
-                                    pRuntime->NewNumber(pData->data.dData));
+        pRuntime->PutObjectProperty(
+            ToV8Object(), WideString::FromUTF8(pData->data.sKey.AsStringView()),
+            pRuntime->NewNumber(pData->data.dData));
         break;
       case CFX_Value::DataType::BOOLEAN:
         SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::BOOLEAN, 0,
                            pData->data.bData == 1, "", v8::Local<v8::Object>(),
                            pData->bPersistent == 1);
         pRuntime->PutObjectProperty(
-            ToV8Object(), pData->data.sKey.UTF8Decode(),
+            ToV8Object(), WideString::FromUTF8(pData->data.sKey.AsStringView()),
             pRuntime->NewBoolean(pData->data.bData == 1));
         break;
       case CFX_Value::DataType::STRING:
@@ -342,8 +343,10 @@
                            false, pData->data.sData, v8::Local<v8::Object>(),
                            pData->bPersistent == 1);
         pRuntime->PutObjectProperty(
-            ToV8Object(), pData->data.sKey.UTF8Decode(),
-            pRuntime->NewString(pData->data.sData.UTF8Decode().AsStringView()));
+            ToV8Object(), WideString::FromUTF8(pData->data.sKey.AsStringView()),
+            pRuntime->NewString(
+                WideString::FromUTF8(pData->data.sData.AsStringView())
+                    .AsStringView()));
         break;
       case CFX_Value::DataType::OBJECT: {
         v8::Local<v8::Object> pObj = pRuntime->NewObject();
@@ -351,16 +354,18 @@
           PutObjectProperty(pObj, &pData->data);
           SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::OBJECT, 0,
                              false, "", pObj, pData->bPersistent == 1);
-          pRuntime->PutObjectProperty(ToV8Object(),
-                                      pData->data.sKey.UTF8Decode(), pObj);
+          pRuntime->PutObjectProperty(
+              ToV8Object(),
+              WideString::FromUTF8(pData->data.sKey.AsStringView()), pObj);
         }
       } break;
       case CFX_Value::DataType::NULLOBJ:
         SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::NULLOBJ, 0,
                            false, "", v8::Local<v8::Object>(),
                            pData->bPersistent == 1);
-        pRuntime->PutObjectProperty(ToV8Object(), pData->data.sKey.UTF8Decode(),
-                                    pRuntime->NewNull());
+        pRuntime->PutObjectProperty(
+            ToV8Object(), WideString::FromUTF8(pData->data.sKey.AsStringView()),
+            pRuntime->NewNull());
         break;
     }
   }
@@ -462,29 +467,35 @@
     CFX_KeyValue* pObjData = pData->objData.GetAt(i);
     switch (pObjData->nType) {
       case CFX_Value::DataType::NUMBER:
-        pRuntime->PutObjectProperty(pObj, pObjData->sKey.UTF8Decode(),
-                                    pRuntime->NewNumber(pObjData->dData));
+        pRuntime->PutObjectProperty(
+            pObj, WideString::FromUTF8(pObjData->sKey.AsStringView()),
+            pRuntime->NewNumber(pObjData->dData));
         break;
       case CFX_Value::DataType::BOOLEAN:
-        pRuntime->PutObjectProperty(pObj, pObjData->sKey.UTF8Decode(),
-                                    pRuntime->NewBoolean(pObjData->bData == 1));
+        pRuntime->PutObjectProperty(
+            pObj, WideString::FromUTF8(pObjData->sKey.AsStringView()),
+            pRuntime->NewBoolean(pObjData->bData == 1));
         break;
       case CFX_Value::DataType::STRING:
         pRuntime->PutObjectProperty(
-            pObj, pObjData->sKey.UTF8Decode(),
-            pRuntime->NewString(pObjData->sData.UTF8Decode().AsStringView()));
+            pObj, WideString::FromUTF8(pObjData->sKey.AsStringView()),
+            pRuntime->NewString(
+                WideString::FromUTF8(pObjData->sData.AsStringView())
+                    .AsStringView()));
         break;
       case CFX_Value::DataType::OBJECT: {
         v8::Local<v8::Object> pNewObj = pRuntime->NewObject();
         if (!pNewObj.IsEmpty()) {
           PutObjectProperty(pNewObj, pObjData);
-          pRuntime->PutObjectProperty(pObj, pObjData->sKey.UTF8Decode(),
-                                      pNewObj);
+          pRuntime->PutObjectProperty(
+              pObj, WideString::FromUTF8(pObjData->sKey.AsStringView()),
+              pNewObj);
         }
       } break;
       case CFX_Value::DataType::NULLOBJ:
-        pRuntime->PutObjectProperty(pObj, pObjData->sKey.UTF8Decode(),
-                                    pRuntime->NewNull());
+        pRuntime->PutObjectProperty(
+            pObj, WideString::FromUTF8(pObjData->sKey.AsStringView()),
+            pRuntime->NewNull());
         break;
     }
   }
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index 72730ab..7c88398 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -772,7 +772,7 @@
       table.clear();
   }
   pFont->m_wsFamilyNames = GetNames(table.empty() ? nullptr : table.data());
-  pFont->m_wsFamilyNames.push_back(ByteString(pFace->family_name).UTF8Decode());
+  pFont->m_wsFamilyNames.push_back(WideString::FromUTF8(pFace->family_name));
   pFont->m_wsFaceName =
       pFaceName ? *pFaceName
                 : WideString::FromLocal(FXFT_Get_Postscript_Name(pFace));
diff --git a/xfa/fgas/font/cfx_fontsourceenum_file.cpp b/xfa/fgas/font/cfx_fontsourceenum_file.cpp
index 05483b9..395d9d2 100644
--- a/xfa/fgas/font/cfx_fontsourceenum_file.cpp
+++ b/xfa/fgas/font/cfx_fontsourceenum_file.cpp
@@ -77,7 +77,7 @@
 }
 
 void CFX_FontSourceEnum_File::GetNext() {
-  m_wsNext = GetNextFile().UTF8Decode();
+  m_wsNext = WideString::FromUTF8(GetNextFile().AsStringView());
 }
 
 bool CFX_FontSourceEnum_File::HasNext() const {