Remove MsgBox()/Alert() from CJS_EmbedObj.

They're only related to the |app| object, not all embed's.
Alert() itself unused.

Review-Url: https://codereview.chromium.org/2224073002
diff --git a/fpdfsdk/javascript/JS_Object.cpp b/fpdfsdk/javascript/JS_Object.cpp
index e72d0f3..d970297 100644
--- a/fpdfsdk/javascript/JS_Object.cpp
+++ b/fpdfsdk/javascript/JS_Object.cpp
@@ -16,24 +16,6 @@
   m_pJSObject = nullptr;
 }
 
-int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp,
-                         const FX_WCHAR* swMsg,
-                         const FX_WCHAR* swTitle,
-                         FX_UINT nType,
-                         FX_UINT nIcon) {
-  if (!pApp)
-    return 0;
-
-  if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
-    pDoc->KillFocusAnnot();
-
-  return pApp->JS_appAlert(swMsg, swTitle, nType, nIcon);
-}
-
-void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) {
-  CJS_Object::Alert(pContext, swMsg);
-}
-
 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) {
   CJS_Object* pJSObj = data.GetParameter();
   pJSObj->ExitInstance();
@@ -66,9 +48,3 @@
 void CJS_Object::InitInstance(IJS_Runtime* pIRuntime) {}
 
 void CJS_Object::ExitInstance() {}
-
-void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) {
-  CPDFDoc_Environment* pApp = pContext->GetReaderApp();
-  if (pApp)
-    pApp->JS_appAlert(swMsg, nullptr, 0, 3);
-}
diff --git a/fpdfsdk/javascript/JS_Object.h b/fpdfsdk/javascript/JS_Object.h
index 3f0db0e..5875861 100644
--- a/fpdfsdk/javascript/JS_Object.h
+++ b/fpdfsdk/javascript/JS_Object.h
@@ -25,13 +25,6 @@
 
   CJS_Object* GetJSObject() const { return m_pJSObject; }
 
-  int MsgBox(CPDFDoc_Environment* pApp,
-             const FX_WCHAR* swMsg,
-             const FX_WCHAR* swTitle,
-             FX_UINT nType,
-             FX_UINT nIcon);
-  void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg);
-
  protected:
   CJS_Object* m_pJSObject;
 };
@@ -53,9 +46,7 @@
   void SetEmbedObject(CJS_EmbedObj* pObj) { m_pEmbedObj.reset(pObj); }
   CJS_EmbedObj* GetEmbedObject() const { return m_pEmbedObj.get(); }
 
-  static void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg);
-
-  v8::Isolate* GetIsolate() { return m_pIsolate; }
+  v8::Isolate* GetIsolate() const { return m_pIsolate; }
 
  protected:
   std::unique_ptr<CJS_EmbedObj> m_pEmbedObj;
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index 6af59bd..aa0efb1 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -77,6 +77,12 @@
   return result;
 }
 
+void AlertIfPossible(CJS_Context* pContext, const FX_WCHAR* swMsg) {
+  CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+  if (pApp)
+    pApp->JS_appAlert(swMsg, nullptr, 0, 3);
+}
+
 }  // namespace
 
 bool CJS_PublicMethods::IsNumber(const CFX_WideString& str) {
@@ -913,7 +919,7 @@
     if (!IsNumber(swTemp.c_str())) {
       pEvent->Rc() = FALSE;
       sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
-      Alert(pContext, sError.c_str());
+      AlertIfPossible(pContext, sError.c_str());
     }
     return TRUE;  // it happens after the last keystroke and before validating,
   }
@@ -1122,7 +1128,7 @@
     CFX_WideString swMsg;
     swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(),
                  sFormat.c_str());
-    Alert(pContext, swMsg.c_str());
+    AlertIfPossible(pContext, swMsg.c_str());
     return FALSE;
   }
 
@@ -1214,7 +1220,7 @@
       CFX_WideString swMsg;
       swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(),
                    sFormat.c_str());
-      Alert(pContext, swMsg.c_str());
+      AlertIfPossible(pContext, swMsg.c_str());
       pEvent->Rc() = FALSE;
       return TRUE;
     }
@@ -1432,7 +1438,7 @@
 
     if (iIndexMask != wstrMask.GetLength() ||
         (iIndexMask != valEvent.GetLength() && wstrMask.GetLength() != 0)) {
-      Alert(
+      AlertIfPossible(
           pContext,
           JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str());
       pEvent->Rc() = FALSE;
@@ -1449,23 +1455,26 @@
   FX_STRSIZE combined_len = valEvent.GetLength() + wChange.GetLength() +
                             pEvent->SelStart() - pEvent->SelEnd();
   if (combined_len > wstrMask.GetLength()) {
-    Alert(pContext,
-          JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
+    AlertIfPossible(
+        pContext,
+        JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
     pEvent->Rc() = FALSE;
     return TRUE;
   }
 
   if (iIndexMask >= wstrMask.GetLength() && !wChange.IsEmpty()) {
-    Alert(pContext,
-          JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
+    AlertIfPossible(
+        pContext,
+        JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
     pEvent->Rc() = FALSE;
     return TRUE;
   }
 
   for (FX_STRSIZE i = 0; i < wChange.GetLength(); ++i) {
     if (iIndexMask >= wstrMask.GetLength()) {
-      Alert(pContext,
-            JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
+      AlertIfPossible(
+          pContext,
+          JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
       pEvent->Rc() = FALSE;
       return TRUE;
     }
@@ -1584,7 +1593,7 @@
     CFX_WideString swMsg;
     swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(),
                  sFormat.c_str());
-    Alert((CJS_Context*)cc, swMsg.c_str());
+    AlertIfPossible((CJS_Context*)cc, swMsg.c_str());
     return FALSE;
   }
 
@@ -1768,7 +1777,7 @@
   }
 
   if (!swMsg.IsEmpty()) {
-    Alert(pContext, swMsg.c_str());
+    AlertIfPossible(pContext, swMsg.c_str());
     pEvent->Rc() = FALSE;
   }
   return TRUE;
diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp
index 755652d..50afd9a 100644
--- a/fpdfsdk/javascript/app.cpp
+++ b/fpdfsdk/javascript/app.cpp
@@ -403,6 +403,12 @@
     return FALSE;
   }
 
+  CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
+  if (!pApp) {
+    vRet = 0;
+    return TRUE;
+  }
+
   CFX_WideString swMsg;
   if (newParams[0].GetType() == CJS_Value::VT_object) {
     CJS_Array carray;
@@ -438,8 +444,10 @@
     swTitle = JSGetStringFromID(pContext, IDS_STRING_JSALERT);
 
   pRuntime->BeginBlock();
-  vRet = MsgBox(pRuntime->GetReaderApp(), swMsg.c_str(), swTitle.c_str(), iType,
-                iIcon);
+  if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
+    pDoc->KillFocusAnnot();
+
+  vRet = pApp->JS_appAlert(swMsg.c_str(), swTitle.c_str(), iType, iIcon);
   pRuntime->EndBlock();
   return TRUE;
 }