Change CPDF_NameTree::LookupNamedDest() to take a ByteString.

Names in PDFs are ByteStrings, so make LookupNamedDest() take a
ByteString instead of a WideString. Encapsulate the need for a
WideString, which is more of an implementation detail.

Change-Id: I23bbfbb923928a3a2a1a2d059cae945d6f155ff2
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/69730
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_dest.cpp b/core/fpdfdoc/cpdf_dest.cpp
index 47f149b..e99dc86 100644
--- a/core/fpdfdoc/cpdf_dest.cpp
+++ b/core/fpdfdoc/cpdf_dest.cpp
@@ -49,7 +49,7 @@
     auto name_tree = CPDF_NameTree::Create(pDoc, "Dests");
     if (!name_tree)
       return CPDF_Dest();
-    return CPDF_Dest(name_tree->LookupNamedDest(pDoc, pDest->GetUnicodeText()));
+    return CPDF_Dest(name_tree->LookupNamedDest(pDoc, pDest->GetString()));
   }
 
   const CPDF_Array* pArray = pDest->AsArray();
diff --git a/core/fpdfdoc/cpdf_nametree.cpp b/core/fpdfdoc/cpdf_nametree.cpp
index d6c5094..810faf6 100644
--- a/core/fpdfdoc/cpdf_nametree.cpp
+++ b/core/fpdfdoc/cpdf_nametree.cpp
@@ -451,13 +451,13 @@
 }
 
 CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc,
-                                           const WideString& sName) {
-  CPDF_Object* pValue = LookupValue(sName);
+                                           const ByteString& name) {
+  CPDF_Object* pValue = LookupValue(PDF_DecodeText(name.raw_span()));
   if (!pValue) {
     CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDictFor("Dests");
     if (!pDests)
       return nullptr;
-    pValue = pDests->GetDirectObjectFor(PDF_EncodeText(sName));
+    pValue = pDests->GetDirectObjectFor(name);
   }
   if (!pValue)
     return nullptr;
diff --git a/core/fpdfdoc/cpdf_nametree.h b/core/fpdfdoc/cpdf_nametree.h
index 96a89a0..0d77b44 100644
--- a/core/fpdfdoc/cpdf_nametree.h
+++ b/core/fpdfdoc/cpdf_nametree.h
@@ -41,7 +41,7 @@
 
   CPDF_Object* LookupValueAndName(int nIndex, WideString* csName) const;
   CPDF_Object* LookupValue(const WideString& csName) const;
-  CPDF_Array* LookupNamedDest(CPDF_Document* pDoc, const WideString& sName);
+  CPDF_Array* LookupNamedDest(CPDF_Document* pDoc, const ByteString& name);
 
   size_t GetCount() const;
   CPDF_Dictionary* GetRootForTesting() const { return m_pRoot.Get(); }
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 613740b..3582837 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -1031,9 +1031,8 @@
   if (!name_tree)
     return nullptr;
 
-  ByteStringView name_view(name);
-  return FPDFDestFromCPDFArray(
-      name_tree->LookupNamedDest(pDoc, PDF_DecodeText(name_view.raw_span())));
+  ByteString dest_name(name);
+  return FPDFDestFromCPDFArray(name_tree->LookupNamedDest(pDoc, dest_name));
 }
 
 #ifdef PDF_ENABLE_V8
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 8f75375..07c5945 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -1394,7 +1394,7 @@
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
   CPDF_Array* destArray =
-      name_tree->LookupNamedDest(pDocument, pRuntime->ToWideString(params[0]));
+      name_tree->LookupNamedDest(pDocument, pRuntime->ToByteString(params[0]));
   if (!destArray)
     return CJS_Result::Failure(JSMessage::kBadObjectError);