XFA: merge patch from CL 733693003, getting rid of more casts

Getting rid of more (FX_LPCWSTR) casts and fixing two bugs revealed by this.

Since casts to FX_LPCWSTR have been shown to hide bugs I tried removing
more of them, targeting those places where a cast was used to force a
conversion from CFX_WideString to FX_LPCWSTR, replacing these casts with
calls to the newly added .c_str() function. This revealed two places
where the cast was hiding a bug -- where ->c_str() was required instead!

This removes ~33 FX_LPCWSTR casts and there are ~31 left, many of which
will go away in some future change.

Also includes this change:

Removing unnecessary casts from wchar_t* to wchar_t*, by various names.

Original patch from Bruce Dawson(brucedawson@chromium.org)

TBR=bo_xu@foxitsoftware.com, tsepez@chromium.org

Review URL: https://codereview.chromium.org/811593007
diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h
index 364c510..47e8ecd 100644
--- a/core/include/fxcrt/fx_string.h
+++ b/core/include/fxcrt/fx_string.h
@@ -640,9 +640,16 @@
 
     static FX_STRSIZE       WStringLength(const unsigned short* str);
 
+    // Explicit conversion to raw string
+    FX_LPCWSTR c_str() const
+    {
+        return m_pData ? m_pData->m_String : L"";
+    }
+
+    // Implicit conversion to C-style wide string -- deprecated
     operator FX_LPCWSTR() const
     {
-        return m_pData ? m_pData->m_String : (FX_WCHAR*)L"";
+        return m_pData ? m_pData->m_String : L"";
     }
 
     void					Empty();
@@ -762,12 +769,12 @@
 };
 inline CFX_WideStringC::CFX_WideStringC(const CFX_WideString& src)
 {
-    m_Ptr = (FX_LPCWSTR)src;
+    m_Ptr = src.c_str();
     m_Length = src.GetLength();
 }
 inline CFX_WideStringC& CFX_WideStringC::operator = (const CFX_WideString& src)
 {
-    m_Ptr = (FX_LPCWSTR)src;
+    m_Ptr = src.c_str();
     m_Length = src.GetLength();
     return *this;
 }
@@ -841,6 +848,6 @@
 }
 inline CFX_ByteString	FX_UTF8Encode(const CFX_WideString &wsStr)
 {
-    return FX_UTF8Encode((FX_LPCWSTR)wsStr, wsStr.GetLength());
+    return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength());
 }
 #endif
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index 36b6ce2..dd646ca 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -228,7 +228,7 @@
     CFX_ByteString result;
     int src_len = str.GetLength();
     FX_LPSTR dest_buf = result.GetBuffer(src_len * 2);
-    FX_LPCWSTR src_buf = str;
+    FX_LPCWSTR src_buf = str.c_str();
     int dest_pos = 0;
     for (int src_pos = 0; src_pos < src_len; src_pos ++) {
         FX_DWORD charcode = CharCodeFromUnicode(src_buf[src_pos]);
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
index dd4eedd..e431c6a 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp
@@ -175,9 +175,9 @@
         if (filepath[2] != '\\') {
             result += '/';
         }
-        result += ChangeSlash((FX_LPCWSTR)filepath + 2);
+        result += ChangeSlash(filepath.c_str() + 2);
     } else if (filepath.GetLength() > 1 && filepath[0] == '\\' && filepath[1] == '\\') {
-        result = ChangeSlash((FX_LPCWSTR)filepath + 1);
+        result = ChangeSlash(filepath.c_str() + 1);
     } else {
         result = ChangeSlash(filepath);
     }
@@ -217,7 +217,7 @@
         CFX_WideString result;
         result += wsFileName[1];
         result += ':';
-        result += ChangeSlash(((FX_LPCWSTR)wsFileName) + 2);
+        result += ChangeSlash(wsFileName.c_str() + 2);
         return result;
     } else {
         CFX_WideString result;
diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp
index 821b998..6b7e6bf 100644
--- a/core/src/fpdfdoc/doc_form.cpp
+++ b/core/src/fpdfdoc/doc_form.cpp
@@ -161,7 +161,7 @@
     for (int i = 0; i < ptr_array.GetSize(); i ++) {
         _Node *pNode = (_Node *)ptr_array[i];
         if (pNode->short_name.GetLength() == short_name.GetLength() &&
-                FXSYS_memcmp32((FX_LPCWSTR)pNode->short_name, (FX_LPCWSTR)short_name, short_name.GetLength()*sizeof(FX_WCHAR)) == 0) {
+                FXSYS_memcmp32(pNode->short_name.c_str(), short_name.c_str(), short_name.GetLength()*sizeof(FX_WCHAR)) == 0) {
             return pNode;
         }
     }
diff --git a/core/src/fxcrt/fx_basic_bstring.cpp b/core/src/fxcrt/fx_basic_bstring.cpp
index 60153fa..c54148d 100644
--- a/core/src/fxcrt/fx_basic_bstring.cpp
+++ b/core/src/fxcrt/fx_basic_bstring.cpp
@@ -971,7 +971,7 @@
 }
 CFX_ByteString CFX_ByteString::FromUnicode(const CFX_WideString& str)
 {
-    return FromUnicode((FX_LPCWSTR)str, str.GetLength());
+    return FromUnicode(str.c_str(), str.GetLength());
 }
 void CFX_ByteString::ConvertFrom(const CFX_WideString& str, CFX_CharMap* pCharMap)
 {
diff --git a/core/src/fxcrt/fx_basic_buffer.cpp b/core/src/fxcrt/fx_basic_buffer.cpp
index 1734423..b208142 100644
--- a/core/src/fxcrt/fx_basic_buffer.cpp
+++ b/core/src/fxcrt/fx_basic_buffer.cpp
@@ -192,7 +192,7 @@
 }
 CFX_WideTextBuf& CFX_WideTextBuf::operator << (const CFX_WideString &str)
 {
-    AppendBlock((FX_LPCWSTR)str, str.GetLength() * sizeof(FX_WCHAR));
+    AppendBlock(str.c_str(), str.GetLength() * sizeof(FX_WCHAR));
     return *this;
 }
 CFX_WideTextBuf& CFX_WideTextBuf::operator << (int i)
diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp
index 330c675..e74c52d 100644
--- a/core/src/fxcrt/fx_extension.cpp
+++ b/core/src/fxcrt/fx_extension.cpp
@@ -158,7 +158,7 @@
         iLength = (FX_INT32)FXSYS_strlen(pcsStr);
     }
     CFX_WideString ws = CFX_WideString::FromLocal(pcsStr, iLength);
-    return FXSYS_wcstof((FX_LPCWSTR)ws, iLength, pUsedLen);
+    return FXSYS_wcstof(ws.c_str(), iLength, pUsedLen);
 }
 FX_FLOAT FXSYS_wcstof(FX_LPCWSTR pwsStr, FX_INT32 iLength, FX_INT32 *pUsedLen)
 {
diff --git a/core/src/fxcrt/fx_xml_parser.cpp b/core/src/fxcrt/fx_xml_parser.cpp
index ea471d4..8049a55 100644
--- a/core/src/fxcrt/fx_xml_parser.cpp
+++ b/core/src/fxcrt/fx_xml_parser.cpp
@@ -670,18 +670,13 @@
 {
     CFX_ByteStringC bsSpace, bsName;
     FX_XML_SplitQualifiedName(name, bsSpace, bsName);
-    const CFX_WideString* pValue = m_AttrMap.Lookup(bsSpace, bsName);
-    if (pValue) {
-        attribute = CFX_WideString((FX_LPCWSTR)*pValue, pValue->GetLength());
-        return TRUE;
-    }
-    return FALSE;
+    return GetAttrValue(bsSpace, bsName, attribute);
 }
 FX_BOOL CXML_Element::GetAttrValue(FX_BSTR space, FX_BSTR name, CFX_WideString& attribute) const
 {
     const CFX_WideString* pValue = m_AttrMap.Lookup(space, name);
     if (pValue) {
-        attribute = CFX_WideString((FX_LPCWSTR)*pValue, pValue->GetLength());
+        attribute = *pValue;
         return TRUE;
     }
     return FALSE;
diff --git a/core/src/fxcrt/fxcrt_platforms.cpp b/core/src/fxcrt/fxcrt_platforms.cpp
index e14e362..1c47ee6 100644
--- a/core/src/fxcrt/fxcrt_platforms.cpp
+++ b/core/src/fxcrt/fxcrt_platforms.cpp
@@ -56,7 +56,7 @@
     }
     CFX_WideString strMode;
     FXCRT_GetFileModeString(dwMode, strMode);
-    m_hFile = FXSYS_wfopen(fileName.GetPtr(), (FX_LPCWSTR)strMode);
+    m_hFile = FXSYS_wfopen(fileName.GetPtr(), strMode.c_str());
     return m_hFile != NULL;
 }
 void CFXCRT_FileAccess_CRT::Close()
diff --git a/fpdfsdk/include/javascript/JS_Define.h b/fpdfsdk/include/javascript/JS_Define.h
index a60db4a..8ead492 100644
--- a/fpdfsdk/include/javascript/JS_Define.h
+++ b/fpdfsdk/include/javascript/JS_Define.h
@@ -332,8 +332,8 @@
 	ASSERT(pObj != NULL);\
 	FX_BOOL bRet = FALSE;\
 	MEMLEAKCHECK_1();\
-	bRet = pObj->QueryProperty((FX_LPCWSTR)propname);\
-	MEMLEAKCHECK_2(class_name, (FX_LPCWSTR)prop_name);\
+	bRet = pObj->QueryProperty(propname.c_str());\
+	MEMLEAKCHECK_2(class_name, prop_name.c_str());\
 	if (bRet)\
 	{\
 		info.GetReturnValue().Set(0x004);\
@@ -364,7 +364,7 @@
 	JS_ErrorString sError;\
 	FX_BOOL bRet = FALSE;\
 	MEMLEAKCHECK_1();\
-	bRet = pObj->DoProperty(cc, (FX_LPCWSTR)propname, value, sError);\
+	bRet = pObj->DoProperty(cc, propname.c_str(), value, sError);\
 	MEMLEAKCHECK_2(class_name, L"GetProperty");\
 	if (bRet)\
 	{\
@@ -399,7 +399,7 @@
 	JS_ErrorString sError;\
 	FX_BOOL bRet = FALSE;\
 	MEMLEAKCHECK_1();\
-	bRet = pObj->DoProperty(cc, (FX_LPCWSTR)propname, PropValue, sError);\
+	bRet = pObj->DoProperty(cc, propname.c_str(), PropValue, sError);\
 	MEMLEAKCHECK_2(class_name,L"PutProperty");\
 	if (bRet)\
 	{\
@@ -431,7 +431,7 @@
 	JS_ErrorString sError;\
 	FX_BOOL bRet = FALSE;\
 	MEMLEAKCHECK_1();\
-	bRet = pObj->DelProperty(cc, (FX_LPCWSTR)propname, sError);\
+	bRet = pObj->DelProperty(cc, propname.c_str(), sError);\
 	MEMLEAKCHECK_2(class_name,L"DelProperty");\
 	if (bRet)\
 	{\
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index c301a87..5dbd4f7 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -1711,9 +1711,9 @@
 			FX_INT32 nCurSel = pField->GetSelectedIndex(0);
 
 			if (nCurSel < 0)
-				pEdit->SetText((FX_LPCWSTR)pField->GetValue());
+				pEdit->SetText(pField->GetValue().c_str());
 			else
-				pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(nCurSel));
+				pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str());
 		}
 
 		CPDF_Rect rcContent = pEdit->GetContentRect();
@@ -1798,7 +1798,7 @@
 				}
 			}
 
-			pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(i));
+			pEdit->SetText(pField->GetOptionLabel(i).c_str());
 
 			CPDF_Rect rcContent = pEdit->GetContentRect();
 			FX_FLOAT fItemHeight = rcContent.Height();
@@ -1924,7 +1924,7 @@
 		if (sValue)
 			pEdit->SetText(sValue);
 		else
-			pEdit->SetText((FX_LPCWSTR)pField->GetValue());
+			pEdit->SetText(pField->GetValue().c_str());
 
 		CPDF_Rect rcContent = pEdit->GetContentRect();
 
@@ -3051,7 +3051,7 @@
 			return FALSE;
 	}
 
-	pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)csDestination);
+	pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str());
 	
 	return TRUE;
 }
@@ -3223,7 +3223,7 @@
 			return FALSE;
 	}
 
-	pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)sDestination);
+	pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str());
 	
 	if (bUrlEncoded && pBuffer)
 	{
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index 9ee9639..2c12068 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -605,7 +605,7 @@
 	ASSERT(pRuntime != NULL);
 
 	pRuntime->BeginBlock();
-    pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
+	pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str());
 	pRuntime->EndBlock();
 	return TRUE;
 }
@@ -999,7 +999,7 @@
 
 	pRuntime->BeginBlock();
 	CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
-	pEnv->JS_docmailForm(NULL, 0, bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
+	pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str());
 	pRuntime->EndBlock();
 
 	return TRUE;
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index 4b1f20a..24de66d 100644
--- a/fpdfsdk/src/javascript/Field.cpp
+++ b/fpdfsdk/src/javascript/Field.cpp
@@ -194,7 +194,7 @@
 	{
 		std::wstring strFieldName;
 		int iControlNo = -1;
-		ParseFieldName((FX_LPCWSTR)swFieldNameTemp, strFieldName, iControlNo);
+		ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
 		if (iControlNo == -1) return FALSE;
 		
 		m_FieldName = strFieldName.c_str();
@@ -1573,7 +1573,7 @@
 				CPDF_FormControl* pFormControl = pFormField->GetControl(i);
 				ASSERT(pFormControl != NULL);
 
-				ExportValusArray.SetElement(i, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
+				ExportValusArray.SetElement(i, CJS_Value(m_isolate,pFormControl->GetExportValue().c_str()));
 			}
 		}
 		else
@@ -1582,7 +1582,7 @@
 			CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex);
 			if (!pFormControl) return FALSE;
 
-			ExportValusArray.SetElement(0, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
+			ExportValusArray.SetElement(0, CJS_Value(m_isolate,pFormControl->GetExportValue().c_str()));
 		}
 
 		vp << ExportValusArray;
@@ -3322,7 +3322,7 @@
 		{
 			if (pFormField->GetControl(i)->IsChecked())
 			{
-				vp << (FX_LPCWSTR)pFormField->GetControl(i)->GetExportValue();
+				vp << pFormField->GetControl(i)->GetExportValue().c_str();
 				break;
 			}
 			else
@@ -3334,7 +3334,7 @@
 		vp << L"";
 	}
 	else
-		vp << (FX_LPCWSTR)pFormField->GetValue();
+		vp << pFormField->GetValue().c_str();
 
 	return TRUE;
 }
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index 4c51c9a..82bffe6 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -1554,7 +1554,7 @@
 	if (JS_PortIsNan(dDate))
 	{
 		CFX_WideString swMsg;
-		swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
+		swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), sFormat.c_str());
 		Alert(pContext, swMsg);
 		return FALSE;
 	}
@@ -1652,7 +1652,7 @@
 		if (bWrongFormat || JS_PortIsNan(dRet))
 		{
 			CFX_WideString swMsg;
-			swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
+			swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), sFormat.c_str());
 			Alert(pContext, swMsg);
 			pEvent->Rc() = FALSE;
 			return TRUE;
@@ -2059,7 +2059,7 @@
 	if (JS_PortIsNan(dDate))
 	{
 		CFX_WideString swMsg;
-		swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
+		swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), sFormat.c_str());
 		Alert((CJS_Context *)cc, swMsg);
 		return FALSE;
 	}
@@ -2304,7 +2304,7 @@
 		{
 			if (sPart.GetLength() > 0)
 			{
-				nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart));
+				nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str()));
 				sPart = L"";
 				nIndex ++;
 			}
@@ -2313,7 +2313,7 @@
 
 	if (sPart.GetLength() > 0)
 	{
-		nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart));	
+		nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str()));	
 	}
 
 	if (nums.GetLength() > 0)
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index 602bfae..7cf2663 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -810,7 +810,7 @@
 	ASSERT(pApp != NULL);
 
 	pRuntime->BeginBlock();
-	pApp->JS_docmailForm(NULL, 0, bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
+	pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str());
 	///////////////////////////////////////////////////////////////////////////////////////////////
 	pRuntime->EndBlock();
 
diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp
index f845ee0..f5bc82c 100644
--- a/fpdfsdk/src/javascript/global.cpp
+++ b/fpdfsdk/src/javascript/global.cpp
@@ -351,7 +351,7 @@
 		CFX_WideString ws = JS_ToString(JS_GetArrayElemnet(pKeyList, i));
 		CFX_ByteString sKey = ws.UTF8Encode();
 
-		v8::Handle<v8::Value> v = JS_GetObjectElement(isolate, pObj, (FX_LPCWSTR)ws);
+		v8::Handle<v8::Value> v = JS_GetObjectElement(isolate, pObj, ws.c_str());
 		FXJSVALUETYPE vt = GET_VALUE_TYPE(v);
 		switch (vt)
 		{