Use single-byte strings in more places in pdfium.

Esp. when we'd allocate a wide string anyways ...

Change-Id: I75c660aa2b2c552895354fe56e39b3b9b13f827e
Reviewed-on: https://pdfium-review.googlesource.com/c/46130
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp
index 13bd9af..bcfbdf3 100644
--- a/fxjs/cfxjse_formcalc_context.cpp
+++ b/fxjs/cfxjse_formcalc_context.cpp
@@ -6067,36 +6067,40 @@
 void CFXJSE_FormCalcContext::ThrowNoDefaultPropertyException(
     const ByteStringView& name) const {
   ThrowException(WideString::FromUTF8(name) +
-                 L" doesn't have a default property.");
+                 WideString::FromASCII(" doesn't have a default property."));
 }
 
 void CFXJSE_FormCalcContext::ThrowCompilerErrorException() const {
-  ThrowException(L"Compiler error.");
+  ThrowException(WideString::FromASCII("Compiler error."));
 }
 
 void CFXJSE_FormCalcContext::ThrowDivideByZeroException() const {
-  ThrowException(L"Divide by zero.");
+  ThrowException(WideString::FromASCII("Divide by zero."));
 }
 
 void CFXJSE_FormCalcContext::ThrowServerDeniedException() const {
-  ThrowException(L"Server does not permit operation.");
+  ThrowException(WideString::FromASCII("Server does not permit operation."));
 }
 
 void CFXJSE_FormCalcContext::ThrowPropertyNotInObjectException(
     const WideString& name,
     const WideString& exp) const {
-  ThrowException(L"An attempt was made to reference property '" + name +
-                 L"' of a non-object in SOM expression " + exp + L".");
+  ThrowException(
+      WideString::FromASCII("An attempt was made to reference property '") +
+      name + WideString::FromASCII("' of a non-object in SOM expression ") +
+      exp + L".");
 }
 
 void CFXJSE_FormCalcContext::ThrowParamCountMismatchException(
     const WideString& method) const {
-  ThrowException(L"Incorrect number of parameters calling method '" + method +
-                 L"'.");
+  ThrowException(
+      WideString::FromASCII("Incorrect number of parameters calling method '") +
+      method + L"'.");
 }
 
 void CFXJSE_FormCalcContext::ThrowArgumentMismatchException() const {
-  ThrowException(L"Argument mismatch in property or function argument.");
+  ThrowException(WideString::FromASCII(
+      "Argument mismatch in property or function argument."));
 }
 
 void CFXJSE_FormCalcContext::ThrowException(const WideString& str) const {
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index 529ca53..f199996 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -585,7 +585,7 @@
   CJS_EventHandler* pEvent =
       pRuntime->GetCurrentEventContext()->GetEventHandler();
   if (!pEvent->m_pValue)
-    return CJS_Result::Failure(L"No event handler");
+    return CJS_Result::Failure(WideString::FromASCII("No event handler"));
 
   WideString& Value = pEvent->Value();
   ByteString strValue = StrTrim(Value.ToDefANSI());
@@ -935,8 +935,8 @@
     CJS_Runtime* pRuntime,
     const std::vector<v8::Local<v8::Value>>& params) {
   if (params.size() != 1) {
-    return CJS_Result::Failure(
-        WideString(L"AFDate_KeystrokeEx's parameter size not correct"));
+    return CJS_Result::Failure(WideString::FromASCII(
+        "AFDate_KeystrokeEx's parameter size not correct"));
   }
 
   CJS_EventContext* pContext = pRuntime->GetCurrentEventContext();
diff --git a/fxjs/js_resources.cpp b/fxjs/js_resources.cpp
index 8e891a0..a9f9782 100644
--- a/fxjs/js_resources.cpp
+++ b/fxjs/js_resources.cpp
@@ -7,61 +7,90 @@
 #include "fxjs/js_resources.h"
 
 WideString JSGetStringFromID(JSMessage msg) {
+  const char* msg_string = "";
   switch (msg) {
     case JSMessage::kAlert:
-      return L"Alert";
+      msg_string = "Alert";
+      break;
     case JSMessage::kParamError:
-      return L"Incorrect number of parameters passed to function.";
+      msg_string = "Incorrect number of parameters passed to function.";
+      break;
     case JSMessage::kInvalidInputError:
-      return L"The input value is invalid.";
+      msg_string = "The input value is invalid.";
+      break;
     case JSMessage::kParamTooLongError:
-      return L"The input value is too long.";
+      msg_string = "The input value is too long.";
+      break;
     case JSMessage::kParseDateError:
-      return L"The input value can't be parsed as a valid date/time (%ls).";
+      msg_string =
+          "The input value can't be parsed as a valid date/time (%ls).";
+      break;
     case JSMessage::kRangeBetweenError:
-      return L"The input value must be greater than or equal to %ls"
-             L" and less than or equal to %ls.";
+      msg_string =
+          "The input value must be greater than or equal to %ls"
+          " and less than or equal to %ls.";
+      break;
     case JSMessage::kRangeGreaterError:
-      return L"The input value must be greater than or equal to %ls.";
+      msg_string = "The input value must be greater than or equal to %ls.";
+      break;
     case JSMessage::kRangeLessError:
-      return L"The input value must be less than or equal to %ls.";
+      msg_string = "The input value must be less than or equal to %ls.";
+      break;
     case JSMessage::kNotSupportedError:
-      return L"Operation not supported.";
+      msg_string = "Operation not supported.";
+      break;
     case JSMessage::kBusyError:
-      return L"System is busy.";
+      msg_string = "System is busy.";
+      break;
     case JSMessage::kDuplicateEventError:
-      return L"Duplicate formfield event found.";
+      msg_string = "Duplicate formfield event found.";
+      break;
     case JSMessage::kSecondParamNotDateError:
-      return L"The second parameter can't be converted to a Date.";
+      msg_string = "The second parameter can't be converted to a Date.";
+      break;
     case JSMessage::kSecondParamInvalidDateError:
-      return L"The second parameter is an invalid Date.";
+      msg_string = "The second parameter is an invalid Date.";
+      break;
     case JSMessage::kGlobalNotFoundError:
-      return L"Global value not found.";
+      msg_string = "Global value not found.";
+      break;
     case JSMessage::kReadOnlyError:
-      return L"Cannot assign to readonly property.";
+      msg_string = "Cannot assign to readonly property.";
+      break;
     case JSMessage::kTypeError:
-      return L"Incorrect parameter type.";
+      msg_string = "Incorrect parameter type.";
+      break;
     case JSMessage::kValueError:
-      return L"Incorrect parameter value.";
+      msg_string = "Incorrect parameter value.";
+      break;
     case JSMessage::kPermissionError:
-      return L"Permission denied.";
+      msg_string = "Permission denied.";
+      break;
     case JSMessage::kBadObjectError:
-      return L"Object no longer exists.";
+      msg_string = "Object no longer exists.";
+      break;
     case JSMessage::kObjectTypeError:
-      return L"Object is of the wrong type.";
+      msg_string = "Object is of the wrong type.";
+      break;
     case JSMessage::kUnknownProperty:
-      return L"Unknown property.";
+      msg_string = "Unknown property.";
+      break;
     case JSMessage::kInvalidSetError:
-      return L"Set not possible, invalid or unknown.";
+      msg_string = "Set not possible, invalid or unknown.";
+      break;
 #ifdef PDF_ENABLE_XFA
     case JSMessage::kTooManyOccurances:
-      return L"Too many occurances.";
+      msg_string = "Too many occurances.";
+      break;
     case JSMessage::kUnknownMethod:
-      return L"Unknown method.";
+      msg_string = "Unknown method.";
+      break;
+    default:
+      NOTREACHED();
+      break;
 #endif
   }
-  NOTREACHED();
-  return L"";
+  return WideString::FromASCII(msg_string);
 }
 
 WideString JSFormatErrorString(const char* class_name,
diff --git a/fxjs/xfa/cjx_hostpseudomodel.cpp b/fxjs/xfa/cjx_hostpseudomodel.cpp
index d6899cf..0c362ce 100644
--- a/fxjs/xfa/cjx_hostpseudomodel.cpp
+++ b/fxjs/xfa/cjx_hostpseudomodel.cpp
@@ -126,7 +126,7 @@
     return;
 
   if (bSetting) {
-    ThrowException(L"Unable to set language value.");
+    ThrowException(WideString::FromASCII("Unable to set language value."));
     return;
   }
   pValue->SetString(
@@ -142,7 +142,7 @@
 
   CXFA_FFDoc* hDoc = pNotify->GetHDOC();
   if (bSetting) {
-    ThrowException(L"Unable to set numPages value.");
+    ThrowException(WideString::FromASCII("Unable to set numPages value."));
     return;
   }
   pValue->SetInteger(hDoc->GetDocEnvironment()->CountPages(hDoc));
@@ -156,7 +156,7 @@
     return;
 
   if (bSetting) {
-    ThrowException(L"Unable to set platform value.");
+    ThrowException(WideString::FromASCII("Unable to set platform value."));
     return;
   }
   pValue->SetString(
@@ -208,7 +208,7 @@
     return;
 
   if (bSetting) {
-    ThrowException(L"Unable to set variation value.");
+    ThrowException(WideString::FromASCII("Unable to set variation value."));
     return;
   }
   pValue->SetString("Full");
@@ -218,7 +218,7 @@
                                   bool bSetting,
                                   XFA_Attribute eAttribute) {
   if (bSetting) {
-    ThrowException(L"Unable to set version value.");
+    ThrowException(WideString::FromASCII("Unable to set version value."));
     return;
   }
   pValue->SetString("11");
diff --git a/fxjs/xfa/cjx_layoutpseudomodel.cpp b/fxjs/xfa/cjx_layoutpseudomodel.cpp
index ea3590b..3c6f1e3 100644
--- a/fxjs/xfa/cjx_layoutpseudomodel.cpp
+++ b/fxjs/xfa/cjx_layoutpseudomodel.cpp
@@ -64,7 +64,7 @@
   if (!pNotify)
     return;
   if (bSetting) {
-    ThrowException(L"Unable to set ready value.");
+    ThrowException(WideString::FromASCII("Unable to set ready value."));
     return;
   }
 
@@ -84,7 +84,7 @@
   if (!pNode)
     return CJS_Result::Success();
 
-  WideString unit(L"pt");
+  WideString unit = WideString::FromASCII("pt");
   if (params.size() >= 2) {
     WideString tmp_unit = runtime->ToWideString(params[1]);
     if (!tmp_unit.IsEmpty())
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index c4520bf..98e6866 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -180,26 +180,29 @@
 }
 
 void CJX_Object::ThrowTooManyOccurancesException(const WideString& obj) const {
-  ThrowException(L"The element [" + obj +
-                 L"] has violated its allowable number of occurrences.");
+  ThrowException(WideString::FromASCII("The element [") + obj +
+                 WideString::FromASCII(
+                     "] has violated its allowable number of occurrences."));
 }
 
 void CJX_Object::ThrowInvalidPropertyException() const {
-  ThrowException(L"Invalid property set operation.");
+  ThrowException(WideString::FromASCII("Invalid property set operation."));
 }
 
 void CJX_Object::ThrowIndexOutOfBoundsException() const {
-  ThrowException(L"Index value is out of bounds.");
+  ThrowException(WideString::FromASCII("Index value is out of bounds."));
 }
 
 void CJX_Object::ThrowParamCountMismatchException(
     const WideString& method) const {
-  ThrowException(L"Incorrect number of parameters calling method '" + method +
-                 L"'.");
+  ThrowException(
+      WideString::FromASCII("Incorrect number of parameters calling method '") +
+      method + WideString::FromASCII("'."));
 }
 
 void CJX_Object::ThrowArgumentMismatchException() const {
-  ThrowException(L"Argument mismatch in property or function argument.");
+  ThrowException(WideString::FromASCII(
+      "Argument mismatch in property or function argument."));
 }
 
 void CJX_Object::ThrowException(const WideString& str) const {
diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp
index aee5a8a..8991b6f 100644
--- a/xfa/fxfa/cxfa_fffield.cpp
+++ b/xfa/fxfa/cxfa_fffield.cpp
@@ -661,10 +661,11 @@
 
       IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider();
       if (pAppProvider) {
-        pAppProvider->MsgBox(L"You are not allowed to modify this field.",
-                             L"Calculate Override",
-                             static_cast<uint32_t>(AlertIcon::kWarning),
-                             static_cast<uint32_t>(AlertButton::kOK));
+        pAppProvider->MsgBox(
+            WideString::FromASCII("You are not allowed to modify this field."),
+            WideString::FromASCII("Calculate Override"),
+            static_cast<uint32_t>(AlertIcon::kWarning),
+            static_cast<uint32_t>(AlertButton::kOK));
       }
       return 0;
     }
@@ -685,9 +686,11 @@
       WideString wsMessage = calc->GetMessageText();
       if (!wsMessage.IsEmpty())
         wsMessage += L"\r\n";
+      wsMessage +=
+          WideString::FromASCII("Are you sure you want to modify this field?");
 
-      wsMessage += L"Are you sure you want to modify this field?";
-      if (pAppProvider->MsgBox(wsMessage, L"Calculate Override",
+      if (pAppProvider->MsgBox(wsMessage,
+                               WideString::FromASCII("Calculate Override"),
                                static_cast<uint32_t>(AlertIcon::kWarning),
                                static_cast<uint32_t>(AlertButton::kYesNo)) ==
           static_cast<uint32_t>(AlertReturn::kYes)) {
diff --git a/xfa/fxfa/cxfa_fftextedit.cpp b/xfa/fxfa/cxfa_fftextedit.cpp
index 385a369..cc9c733 100644
--- a/xfa/fxfa/cxfa_fftextedit.cpp
+++ b/xfa/fxfa/cxfa_fftextedit.cpp
@@ -204,10 +204,10 @@
     return;
 
   WideString wsSomField = GetNode()->GetSOMExpression();
-  pAppProvider->MsgBox(wsText + L" can not contain " + wsSomField,
-                       pAppProvider->GetAppTitle(),
-                       static_cast<uint32_t>(AlertIcon::kError),
-                       static_cast<uint32_t>(AlertButton::kOK));
+  pAppProvider->MsgBox(
+      wsText + WideString::FromASCII(" can not contain ") + wsSomField,
+      pAppProvider->GetAppTitle(), static_cast<uint32_t>(AlertIcon::kError),
+      static_cast<uint32_t>(AlertButton::kOK));
 }
 
 bool CXFA_FFTextEdit::IsDataChanged() {
diff --git a/xfa/fxfa/parser/cxfa_script.cpp b/xfa/fxfa/parser/cxfa_script.cpp
index 61970bf..97adb9d 100644
--- a/xfa/fxfa/parser/cxfa_script.cpp
+++ b/xfa/fxfa/parser/cxfa_script.cpp
@@ -50,9 +50,11 @@
 CXFA_Script::Type CXFA_Script::GetContentType() {
   Optional<WideString> cData =
       JSObject()->TryCData(XFA_Attribute::ContentType, false);
-  if (!cData || *cData == L"application/x-formcalc")
+  if (!cData.has_value())
     return Type::Formcalc;
-  if (*cData == L"application/x-javascript")
+  if (cData.value().EqualsASCII("application/x-formcalc"))
+    return Type::Formcalc;
+  if (cData.value().EqualsASCII("application/x-javascript"))
     return Type::Javascript;
   return Type::Unknown;
 }