| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "app.h" | 7 #include "app.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 const std::vector<CJS_Value>& params, | 239 const std::vector<CJS_Value>& params, |
| 240 CJS_Value& vRet, | 240 CJS_Value& vRet, |
| 241 CFX_WideString& sError) { | 241 CFX_WideString& sError) { |
| 242 return TRUE; | 242 return TRUE; |
| 243 } | 243 } |
| 244 | 244 |
| 245 FX_BOOL app::alert(IJS_Context* cc, | 245 FX_BOOL app::alert(IJS_Context* cc, |
| 246 const std::vector<CJS_Value>& params, | 246 const std::vector<CJS_Value>& params, |
| 247 CJS_Value& vRet, | 247 CJS_Value& vRet, |
| 248 CFX_WideString& sError) { | 248 CFX_WideString& sError) { |
| 249 int iSize = params.size(); | 249 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 250 if (iSize < 1) | 250 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 251 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams( |
| 252 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); |
| 253 |
| 254 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
| 255 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 251 return FALSE; | 256 return FALSE; |
| 257 } |
| 252 | 258 |
| 253 CFX_WideString swMsg = L""; | 259 CFX_WideString swMsg; |
| 254 CFX_WideString swTitle = L""; | 260 if (newParams[0].GetType() == CJS_Value::VT_object) { |
| 255 int iIcon = 0; | 261 CJS_Array carray(pRuntime); |
| 256 int iType = 0; | 262 if (newParams[0].ConvertToArray(carray)) { |
| 257 | 263 swMsg = L"["; |
| 258 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 264 CJS_Value element(pRuntime); |
| 259 v8::Isolate* isolate = pRuntime->GetIsolate(); | 265 for (int i = 0; i < carray.GetLength(); ++i) { |
| 260 | 266 if (i) |
| 261 if (iSize == 1) { | 267 swMsg += L", "; |
| 262 if (params[0].GetType() == CJS_Value::VT_object) { | 268 carray.GetElement(i, element); |
| 263 v8::Local<v8::Object> pObj = params[0].ToV8Object(); | 269 swMsg += element.ToCFXWideString(); |
| 264 { | |
| 265 v8::Local<v8::Value> pValue = | |
| 266 FXJS_GetObjectElement(isolate, pObj, L"cMsg"); | |
| 267 swMsg = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown) | |
| 268 .ToCFXWideString(); | |
| 269 | |
| 270 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle"); | |
| 271 swTitle = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown) | |
| 272 .ToCFXWideString(); | |
| 273 | |
| 274 pValue = FXJS_GetObjectElement(isolate, pObj, L"nIcon"); | |
| 275 iIcon = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown).ToInt(); | |
| 276 | |
| 277 pValue = FXJS_GetObjectElement(isolate, pObj, L"nType"); | |
| 278 iType = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown).ToInt(); | |
| 279 } | 270 } |
| 280 | 271 swMsg += L"]"; |
| 281 if (swMsg == L"") { | |
| 282 CJS_Array carray(pRuntime); | |
| 283 if (params[0].ConvertToArray(carray)) { | |
| 284 int iLength = carray.GetLength(); | |
| 285 CJS_Value* pValue = new CJS_Value(pRuntime); | |
| 286 for (int i = 0; i < iLength; ++i) { | |
| 287 carray.GetElement(i, *pValue); | |
| 288 swMsg += (*pValue).ToCFXWideString(); | |
| 289 if (i < iLength - 1) | |
| 290 swMsg += L", "; | |
| 291 } | |
| 292 | |
| 293 delete pValue; | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 if (swTitle == L"") | |
| 298 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); | |
| 299 } else if (params[0].GetType() == CJS_Value::VT_boolean) { | |
| 300 FX_BOOL bGet = params[0].ToBool(); | |
| 301 if (bGet) | |
| 302 swMsg = L"true"; | |
| 303 else | |
| 304 swMsg = L"false"; | |
| 305 | |
| 306 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); | |
| 307 } else { | 272 } else { |
| 308 swMsg = params[0].ToCFXWideString(); | 273 swMsg = newParams[0].ToCFXWideString(); |
| 309 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); | |
| 310 } | 274 } |
| 311 } else { | 275 } else { |
| 312 if (params[0].GetType() == CJS_Value::VT_boolean) { | 276 swMsg = newParams[0].ToCFXWideString(); |
| 313 FX_BOOL bGet = params[0].ToBool(); | 277 } |
| 314 if (bGet) | |
| 315 swMsg = L"true"; | |
| 316 else | |
| 317 swMsg = L"false"; | |
| 318 } else { | |
| 319 swMsg = params[0].ToCFXWideString(); | |
| 320 } | |
| 321 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); | |
| 322 | 278 |
| 323 for (int i = 1; i < iSize; i++) { | 279 int iIcon = 0; |
| 324 if (i == 1) | 280 if (newParams[1].GetType() != CJS_Value::VT_unknown) |
| 325 iIcon = params[i].ToInt(); | 281 iIcon = newParams[1].ToInt(); |
| 326 if (i == 2) | 282 |
| 327 iType = params[i].ToInt(); | 283 int iType = 0; |
| 328 if (i == 3) | 284 if (newParams[2].GetType() != CJS_Value::VT_unknown) |
| 329 swTitle = params[i].ToCFXWideString(); | 285 iType = newParams[2].ToInt(); |
| 330 } | 286 |
| 331 } | 287 CFX_WideString swTitle; |
| 288 if (newParams[3].GetType() != CJS_Value::VT_unknown) |
| 289 swTitle = newParams[3].ToCFXWideString(); |
| 290 else |
| 291 swTitle = JSGetStringFromID(pContext, IDS_STRING_JSALERT); |
| 332 | 292 |
| 333 pRuntime->BeginBlock(); | 293 pRuntime->BeginBlock(); |
| 334 vRet = MsgBox(pRuntime->GetReaderApp(), swMsg.c_str(), swTitle.c_str(), iType, | 294 vRet = MsgBox(pRuntime->GetReaderApp(), swMsg.c_str(), swTitle.c_str(), iType, |
| 335 iIcon); | 295 iIcon); |
| 336 pRuntime->EndBlock(); | 296 pRuntime->EndBlock(); |
| 337 return TRUE; | 297 return TRUE; |
| 338 } | 298 } |
| 339 | 299 |
| 340 FX_BOOL app::beep(IJS_Context* cc, | 300 FX_BOOL app::beep(IJS_Context* cc, |
| 341 const std::vector<CJS_Value>& params, | 301 const std::vector<CJS_Value>& params, |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 750 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
| 791 return FALSE; | 751 return FALSE; |
| 792 } | 752 } |
| 793 | 753 |
| 794 FX_BOOL app::execDialog(IJS_Context* cc, | 754 FX_BOOL app::execDialog(IJS_Context* cc, |
| 795 const std::vector<CJS_Value>& params, | 755 const std::vector<CJS_Value>& params, |
| 796 CJS_Value& vRet, | 756 CJS_Value& vRet, |
| 797 CFX_WideString& sError) { | 757 CFX_WideString& sError) { |
| 798 return TRUE; | 758 return TRUE; |
| 799 } | 759 } |
| OLD | NEW |