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 "fpdfsdk/javascript/app.h" | 7 #include "fpdfsdk/javascript/app.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 END_JS_STATIC_METHOD() | 202 END_JS_STATIC_METHOD() |
203 | 203 |
204 IMPLEMENT_JS_CLASS(CJS_App, app) | 204 IMPLEMENT_JS_CLASS(CJS_App, app) |
205 | 205 |
206 app::app(CJS_Object* pJSObject) | 206 app::app(CJS_Object* pJSObject) |
207 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {} | 207 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {} |
208 | 208 |
209 app::~app() { | 209 app::~app() { |
210 } | 210 } |
211 | 211 |
212 FX_BOOL app::activeDocs(IJS_Context* cc, | 212 bool app::activeDocs(IJS_Context* cc, |
213 CJS_PropValue& vp, | 213 CJS_PropValue& vp, |
214 CFX_WideString& sError) { | 214 CFX_WideString& sError) { |
215 if (!vp.IsGetting()) | 215 if (!vp.IsGetting()) |
216 return FALSE; | 216 return false; |
217 | 217 |
218 CJS_Context* pContext = (CJS_Context*)cc; | 218 CJS_Context* pContext = (CJS_Context*)cc; |
219 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 219 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
220 CJS_Document* pJSDocument = nullptr; | 220 CJS_Document* pJSDocument = nullptr; |
221 v8::Local<v8::Object> pObj = pRuntime->GetThisObj(); | 221 v8::Local<v8::Object> pObj = pRuntime->GetThisObj(); |
222 if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) { | 222 if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) { |
223 pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj)); | 223 pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj)); |
224 } | 224 } |
225 | 225 |
226 CJS_Array aDocs; | 226 CJS_Array aDocs; |
227 aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument)); | 227 aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument)); |
228 | 228 |
229 if (aDocs.GetLength(pRuntime) > 0) | 229 if (aDocs.GetLength(pRuntime) > 0) |
230 vp << aDocs; | 230 vp << aDocs; |
231 else | 231 else |
232 vp.GetJSValue()->SetNull(pRuntime); | 232 vp.GetJSValue()->SetNull(pRuntime); |
233 | 233 |
234 return TRUE; | 234 return true; |
235 } | 235 } |
236 | 236 |
237 FX_BOOL app::calculate(IJS_Context* cc, | 237 bool app::calculate(IJS_Context* cc, |
238 CJS_PropValue& vp, | 238 CJS_PropValue& vp, |
239 CFX_WideString& sError) { | 239 CFX_WideString& sError) { |
240 if (vp.IsSetting()) { | 240 if (vp.IsSetting()) { |
241 bool bVP; | 241 bool bVP; |
242 vp >> bVP; | 242 vp >> bVP; |
243 m_bCalculate = (FX_BOOL)bVP; | 243 m_bCalculate = (bool)bVP; |
244 | 244 |
245 CJS_Context* pContext = (CJS_Context*)cc; | 245 CJS_Context* pContext = (CJS_Context*)cc; |
246 pContext->GetFormFillEnv() | 246 pContext->GetFormFillEnv()->GetInterForm()->EnableCalculate( |
247 ->GetInterForm() | 247 (bool)m_bCalculate); |
248 ->EnableCalculate((FX_BOOL)m_bCalculate); | |
249 } else { | 248 } else { |
250 vp << (bool)m_bCalculate; | 249 vp << (bool)m_bCalculate; |
251 } | 250 } |
252 return TRUE; | 251 return true; |
253 } | 252 } |
254 | 253 |
255 FX_BOOL app::formsVersion(IJS_Context* cc, | 254 bool app::formsVersion(IJS_Context* cc, |
| 255 CJS_PropValue& vp, |
| 256 CFX_WideString& sError) { |
| 257 if (vp.IsGetting()) { |
| 258 vp << JS_NUM_FORMSVERSION; |
| 259 return true; |
| 260 } |
| 261 |
| 262 return false; |
| 263 } |
| 264 |
| 265 bool app::viewerType(IJS_Context* cc, |
| 266 CJS_PropValue& vp, |
| 267 CFX_WideString& sError) { |
| 268 if (vp.IsGetting()) { |
| 269 vp << JS_STR_VIEWERTYPE; |
| 270 return true; |
| 271 } |
| 272 |
| 273 return false; |
| 274 } |
| 275 |
| 276 bool app::viewerVariation(IJS_Context* cc, |
256 CJS_PropValue& vp, | 277 CJS_PropValue& vp, |
257 CFX_WideString& sError) { | 278 CFX_WideString& sError) { |
258 if (vp.IsGetting()) { | 279 if (vp.IsGetting()) { |
259 vp << JS_NUM_FORMSVERSION; | 280 vp << JS_STR_VIEWERVARIATION; |
260 return TRUE; | 281 return true; |
261 } | 282 } |
262 | 283 |
263 return FALSE; | 284 return false; |
264 } | 285 } |
265 | 286 |
266 FX_BOOL app::viewerType(IJS_Context* cc, | 287 bool app::viewerVersion(IJS_Context* cc, |
267 CJS_PropValue& vp, | 288 CJS_PropValue& vp, |
268 CFX_WideString& sError) { | 289 CFX_WideString& sError) { |
269 if (vp.IsGetting()) { | |
270 vp << JS_STR_VIEWERTYPE; | |
271 return TRUE; | |
272 } | |
273 | |
274 return FALSE; | |
275 } | |
276 | |
277 FX_BOOL app::viewerVariation(IJS_Context* cc, | |
278 CJS_PropValue& vp, | |
279 CFX_WideString& sError) { | |
280 if (vp.IsGetting()) { | |
281 vp << JS_STR_VIEWERVARIATION; | |
282 return TRUE; | |
283 } | |
284 | |
285 return FALSE; | |
286 } | |
287 | |
288 FX_BOOL app::viewerVersion(IJS_Context* cc, | |
289 CJS_PropValue& vp, | |
290 CFX_WideString& sError) { | |
291 if (!vp.IsGetting()) | 290 if (!vp.IsGetting()) |
292 return FALSE; | 291 return false; |
293 #ifdef PDF_ENABLE_XFA | 292 #ifdef PDF_ENABLE_XFA |
294 CJS_Context* pJSContext = static_cast<CJS_Context*>(cc); | 293 CJS_Context* pJSContext = static_cast<CJS_Context*>(cc); |
295 CPDFXFA_Context* pXFAContext = pJSContext->GetFormFillEnv()->GetXFAContext(); | 294 CPDFXFA_Context* pXFAContext = pJSContext->GetFormFillEnv()->GetXFAContext(); |
296 if (pXFAContext->GetDocType() == 1 || pXFAContext->GetDocType() == 2) { | 295 if (pXFAContext->GetDocType() == 1 || pXFAContext->GetDocType() == 2) { |
297 vp << JS_NUM_VIEWERVERSION_XFA; | 296 vp << JS_NUM_VIEWERVERSION_XFA; |
298 return TRUE; | 297 return true; |
299 } | 298 } |
300 #endif // PDF_ENABLE_XFA | 299 #endif // PDF_ENABLE_XFA |
301 vp << JS_NUM_VIEWERVERSION; | 300 vp << JS_NUM_VIEWERVERSION; |
302 return TRUE; | 301 return true; |
303 } | 302 } |
304 | 303 |
305 FX_BOOL app::platform(IJS_Context* cc, | 304 bool app::platform(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
306 CJS_PropValue& vp, | |
307 CFX_WideString& sError) { | |
308 if (!vp.IsGetting()) | 305 if (!vp.IsGetting()) |
309 return FALSE; | 306 return false; |
310 #ifdef PDF_ENABLE_XFA | 307 #ifdef PDF_ENABLE_XFA |
311 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 308 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
312 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetFormFillEnv(); | 309 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetFormFillEnv(); |
313 if (!pFormFillEnv) | 310 if (!pFormFillEnv) |
314 return FALSE; | 311 return false; |
315 CFX_WideString platfrom = pFormFillEnv->GetPlatform(); | 312 CFX_WideString platfrom = pFormFillEnv->GetPlatform(); |
316 if (!platfrom.IsEmpty()) { | 313 if (!platfrom.IsEmpty()) { |
317 vp << platfrom; | 314 vp << platfrom; |
318 return TRUE; | 315 return true; |
319 } | 316 } |
320 #endif | 317 #endif |
321 vp << JS_STR_PLATFORM; | 318 vp << JS_STR_PLATFORM; |
322 return TRUE; | 319 return true; |
323 } | 320 } |
324 | 321 |
325 FX_BOOL app::language(IJS_Context* cc, | 322 bool app::language(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
326 CJS_PropValue& vp, | |
327 CFX_WideString& sError) { | |
328 if (!vp.IsGetting()) | 323 if (!vp.IsGetting()) |
329 return FALSE; | 324 return false; |
330 #ifdef PDF_ENABLE_XFA | 325 #ifdef PDF_ENABLE_XFA |
331 CPDFSDK_FormFillEnvironment* pFormFillEnv = | 326 CPDFSDK_FormFillEnvironment* pFormFillEnv = |
332 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetFormFillEnv(); | 327 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetFormFillEnv(); |
333 if (!pFormFillEnv) | 328 if (!pFormFillEnv) |
334 return FALSE; | 329 return false; |
335 CFX_WideString language = pFormFillEnv->GetLanguage(); | 330 CFX_WideString language = pFormFillEnv->GetLanguage(); |
336 if (!language.IsEmpty()) { | 331 if (!language.IsEmpty()) { |
337 vp << language; | 332 vp << language; |
338 return TRUE; | 333 return true; |
339 } | 334 } |
340 #endif | 335 #endif |
341 vp << JS_STR_LANGUAGE; | 336 vp << JS_STR_LANGUAGE; |
342 return TRUE; | 337 return true; |
343 } | 338 } |
344 | 339 |
345 // creates a new fdf object that contains no data | 340 // creates a new fdf object that contains no data |
346 // comment: need reader support | 341 // comment: need reader support |
347 // note: | 342 // note: |
348 // CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF(); | 343 // CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF(); |
349 FX_BOOL app::newFDF(IJS_Context* cc, | 344 bool app::newFDF(IJS_Context* cc, |
350 const std::vector<CJS_Value>& params, | 345 const std::vector<CJS_Value>& params, |
351 CJS_Value& vRet, | 346 CJS_Value& vRet, |
352 CFX_WideString& sError) { | 347 CFX_WideString& sError) { |
353 return TRUE; | 348 return true; |
354 } | 349 } |
355 // opens a specified pdf document and returns its document object | 350 // opens a specified pdf document and returns its document object |
356 // comment:need reader support | 351 // comment:need reader support |
357 // note: as defined in js reference, the proto of this function's fourth | 352 // note: as defined in js reference, the proto of this function's fourth |
358 // parmeters, how old an fdf document while do not show it. | 353 // parmeters, how old an fdf document while do not show it. |
359 // CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool | 354 // CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool |
360 // bUserConv); | 355 // bUserConv); |
361 | 356 |
362 FX_BOOL app::openFDF(IJS_Context* cc, | 357 bool app::openFDF(IJS_Context* cc, |
363 const std::vector<CJS_Value>& params, | 358 const std::vector<CJS_Value>& params, |
364 CJS_Value& vRet, | 359 CJS_Value& vRet, |
365 CFX_WideString& sError) { | 360 CFX_WideString& sError) { |
366 return TRUE; | 361 return true; |
367 } | 362 } |
368 | 363 |
369 FX_BOOL app::alert(IJS_Context* cc, | 364 bool app::alert(IJS_Context* cc, |
370 const std::vector<CJS_Value>& params, | 365 const std::vector<CJS_Value>& params, |
371 CJS_Value& vRet, | 366 CJS_Value& vRet, |
372 CFX_WideString& sError) { | 367 CFX_WideString& sError) { |
373 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 368 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
374 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams( | 369 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams( |
375 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); | 370 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); |
376 | 371 |
377 if (newParams[0].GetType() == CJS_Value::VT_unknown) { | 372 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
378 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 373 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
379 return FALSE; | 374 return false; |
380 } | 375 } |
381 | 376 |
382 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); | 377 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); |
383 if (!pFormFillEnv) { | 378 if (!pFormFillEnv) { |
384 vRet = CJS_Value(pRuntime, 0); | 379 vRet = CJS_Value(pRuntime, 0); |
385 return TRUE; | 380 return true; |
386 } | 381 } |
387 | 382 |
388 CFX_WideString swMsg; | 383 CFX_WideString swMsg; |
389 if (newParams[0].GetType() == CJS_Value::VT_object) { | 384 if (newParams[0].GetType() == CJS_Value::VT_object) { |
390 CJS_Array carray; | 385 CJS_Array carray; |
391 if (newParams[0].ConvertToArray(pRuntime, carray)) { | 386 if (newParams[0].ConvertToArray(pRuntime, carray)) { |
392 swMsg = L"["; | 387 swMsg = L"["; |
393 CJS_Value element(pRuntime); | 388 CJS_Value element(pRuntime); |
394 for (int i = 0; i < carray.GetLength(pRuntime); ++i) { | 389 for (int i = 0; i < carray.GetLength(pRuntime); ++i) { |
395 if (i) | 390 if (i) |
(...skipping 22 matching lines...) Expand all Loading... |
418 swTitle = newParams[3].ToCFXWideString(pRuntime); | 413 swTitle = newParams[3].ToCFXWideString(pRuntime); |
419 else | 414 else |
420 swTitle = JSGetStringFromID(IDS_STRING_JSALERT); | 415 swTitle = JSGetStringFromID(IDS_STRING_JSALERT); |
421 | 416 |
422 pRuntime->BeginBlock(); | 417 pRuntime->BeginBlock(); |
423 pFormFillEnv->KillFocusAnnot(0); | 418 pFormFillEnv->KillFocusAnnot(0); |
424 | 419 |
425 vRet = CJS_Value(pRuntime, pFormFillEnv->JS_appAlert( | 420 vRet = CJS_Value(pRuntime, pFormFillEnv->JS_appAlert( |
426 swMsg.c_str(), swTitle.c_str(), iType, iIcon)); | 421 swMsg.c_str(), swTitle.c_str(), iType, iIcon)); |
427 pRuntime->EndBlock(); | 422 pRuntime->EndBlock(); |
428 return TRUE; | 423 return true; |
429 } | 424 } |
430 | 425 |
431 FX_BOOL app::beep(IJS_Context* cc, | 426 bool app::beep(IJS_Context* cc, |
432 const std::vector<CJS_Value>& params, | 427 const std::vector<CJS_Value>& params, |
433 CJS_Value& vRet, | 428 CJS_Value& vRet, |
434 CFX_WideString& sError) { | 429 CFX_WideString& sError) { |
435 if (params.size() == 1) { | 430 if (params.size() == 1) { |
436 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 431 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
437 pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime)); | 432 pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime)); |
438 return TRUE; | 433 return true; |
439 } | 434 } |
440 | 435 |
441 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 436 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
442 return FALSE; | 437 return false; |
443 } | 438 } |
444 | 439 |
445 FX_BOOL app::findComponent(IJS_Context* cc, | 440 bool app::findComponent(IJS_Context* cc, |
446 const std::vector<CJS_Value>& params, | 441 const std::vector<CJS_Value>& params, |
447 CJS_Value& vRet, | 442 CJS_Value& vRet, |
448 CFX_WideString& sError) { | 443 CFX_WideString& sError) { |
449 return TRUE; | 444 return true; |
450 } | 445 } |
451 | 446 |
452 FX_BOOL app::popUpMenuEx(IJS_Context* cc, | 447 bool app::popUpMenuEx(IJS_Context* cc, |
453 const std::vector<CJS_Value>& params, | 448 const std::vector<CJS_Value>& params, |
454 CJS_Value& vRet, | 449 CJS_Value& vRet, |
455 CFX_WideString& sError) { | 450 CFX_WideString& sError) { |
456 return FALSE; | 451 return false; |
457 } | 452 } |
458 | 453 |
459 FX_BOOL app::fs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 454 bool app::fs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
460 return FALSE; | 455 return false; |
461 } | 456 } |
462 | 457 |
463 FX_BOOL app::setInterval(IJS_Context* cc, | 458 bool app::setInterval(IJS_Context* cc, |
464 const std::vector<CJS_Value>& params, | 459 const std::vector<CJS_Value>& params, |
465 CJS_Value& vRet, | 460 CJS_Value& vRet, |
466 CFX_WideString& sError) { | 461 CFX_WideString& sError) { |
467 if (params.size() > 2 || params.size() == 0) { | 462 if (params.size() > 2 || params.size() == 0) { |
468 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 463 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
469 return FALSE; | 464 return false; |
470 } | 465 } |
471 | 466 |
472 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 467 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
473 CFX_WideString script = | 468 CFX_WideString script = |
474 params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L""; | 469 params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L""; |
475 if (script.IsEmpty()) { | 470 if (script.IsEmpty()) { |
476 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); | 471 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); |
477 return TRUE; | 472 return true; |
478 } | 473 } |
479 | 474 |
480 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; | 475 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; |
481 | 476 |
482 GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(), | 477 GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(), |
483 pRuntime, 0, script, dwInterval, 0); | 478 pRuntime, 0, script, dwInterval, 0); |
484 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); | 479 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); |
485 | 480 |
486 v8::Local<v8::Object> pRetObj = | 481 v8::Local<v8::Object> pRetObj = |
487 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); | 482 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); |
488 CJS_TimerObj* pJS_TimerObj = | 483 CJS_TimerObj* pJS_TimerObj = |
489 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); | 484 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); |
490 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); | 485 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); |
491 pTimerObj->SetTimer(timerRef); | 486 pTimerObj->SetTimer(timerRef); |
492 | 487 |
493 vRet = CJS_Value(pRuntime, pRetObj); | 488 vRet = CJS_Value(pRuntime, pRetObj); |
494 return TRUE; | 489 return true; |
495 } | 490 } |
496 | 491 |
497 FX_BOOL app::setTimeOut(IJS_Context* cc, | 492 bool app::setTimeOut(IJS_Context* cc, |
498 const std::vector<CJS_Value>& params, | 493 const std::vector<CJS_Value>& params, |
499 CJS_Value& vRet, | 494 CJS_Value& vRet, |
500 CFX_WideString& sError) { | 495 CFX_WideString& sError) { |
501 if (params.size() > 2 || params.size() == 0) { | 496 if (params.size() > 2 || params.size() == 0) { |
502 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 497 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
503 return FALSE; | 498 return false; |
504 } | 499 } |
505 | 500 |
506 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 501 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
507 CFX_WideString script = params[0].ToCFXWideString(pRuntime); | 502 CFX_WideString script = params[0].ToCFXWideString(pRuntime); |
508 if (script.IsEmpty()) { | 503 if (script.IsEmpty()) { |
509 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); | 504 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); |
510 return TRUE; | 505 return true; |
511 } | 506 } |
512 | 507 |
513 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; | 508 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; |
514 GlobalTimer* timerRef = | 509 GlobalTimer* timerRef = |
515 new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script, | 510 new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script, |
516 dwTimeOut, dwTimeOut); | 511 dwTimeOut, dwTimeOut); |
517 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); | 512 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); |
518 | 513 |
519 v8::Local<v8::Object> pRetObj = | 514 v8::Local<v8::Object> pRetObj = |
520 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); | 515 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); |
521 | 516 |
522 CJS_TimerObj* pJS_TimerObj = | 517 CJS_TimerObj* pJS_TimerObj = |
523 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); | 518 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); |
524 | 519 |
525 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); | 520 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); |
526 pTimerObj->SetTimer(timerRef); | 521 pTimerObj->SetTimer(timerRef); |
527 | 522 |
528 vRet = CJS_Value(pRuntime, pRetObj); | 523 vRet = CJS_Value(pRuntime, pRetObj); |
529 return TRUE; | 524 return true; |
530 } | 525 } |
531 | 526 |
532 FX_BOOL app::clearTimeOut(IJS_Context* cc, | 527 bool app::clearTimeOut(IJS_Context* cc, |
533 const std::vector<CJS_Value>& params, | 528 const std::vector<CJS_Value>& params, |
534 CJS_Value& vRet, | 529 CJS_Value& vRet, |
535 CFX_WideString& sError) { | 530 CFX_WideString& sError) { |
536 if (params.size() != 1) { | 531 if (params.size() != 1) { |
537 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 532 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
538 return FALSE; | 533 return false; |
539 } | 534 } |
540 | 535 |
541 app::ClearTimerCommon(CJS_Runtime::FromContext(cc), params[0]); | 536 app::ClearTimerCommon(CJS_Runtime::FromContext(cc), params[0]); |
542 return TRUE; | 537 return true; |
543 } | 538 } |
544 | 539 |
545 FX_BOOL app::clearInterval(IJS_Context* cc, | 540 bool app::clearInterval(IJS_Context* cc, |
546 const std::vector<CJS_Value>& params, | 541 const std::vector<CJS_Value>& params, |
547 CJS_Value& vRet, | 542 CJS_Value& vRet, |
548 CFX_WideString& sError) { | 543 CFX_WideString& sError) { |
549 if (params.size() != 1) { | 544 if (params.size() != 1) { |
550 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 545 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
551 return FALSE; | 546 return false; |
552 } | 547 } |
553 | 548 |
554 app::ClearTimerCommon(CJS_Runtime::FromContext(cc), params[0]); | 549 app::ClearTimerCommon(CJS_Runtime::FromContext(cc), params[0]); |
555 return TRUE; | 550 return true; |
556 } | 551 } |
557 | 552 |
558 void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) { | 553 void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) { |
559 if (param.GetType() != CJS_Value::VT_object) | 554 if (param.GetType() != CJS_Value::VT_object) |
560 return; | 555 return; |
561 | 556 |
562 v8::Local<v8::Object> pObj = param.ToV8Object(pRuntime); | 557 v8::Local<v8::Object> pObj = param.ToV8Object(pRuntime); |
563 if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) | 558 if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) |
564 return; | 559 return; |
565 | 560 |
566 CJS_Object* pJSObj = param.ToCJSObject(pRuntime); | 561 CJS_Object* pJSObj = param.ToCJSObject(pRuntime); |
567 if (!pJSObj) | 562 if (!pJSObj) |
568 return; | 563 return; |
569 | 564 |
570 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject()); | 565 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject()); |
571 if (!pTimerObj) | 566 if (!pTimerObj) |
572 return; | 567 return; |
573 | 568 |
574 GlobalTimer::Cancel(pTimerObj->GetTimerID()); | 569 GlobalTimer::Cancel(pTimerObj->GetTimerID()); |
575 } | 570 } |
576 | 571 |
577 FX_BOOL app::execMenuItem(IJS_Context* cc, | 572 bool app::execMenuItem(IJS_Context* cc, |
578 const std::vector<CJS_Value>& params, | 573 const std::vector<CJS_Value>& params, |
579 CJS_Value& vRet, | 574 CJS_Value& vRet, |
580 CFX_WideString& sError) { | 575 CFX_WideString& sError) { |
581 return FALSE; | 576 return false; |
582 } | 577 } |
583 | 578 |
584 void app::TimerProc(GlobalTimer* pTimer) { | 579 void app::TimerProc(GlobalTimer* pTimer) { |
585 CJS_Runtime* pRuntime = pTimer->GetRuntime(); | 580 CJS_Runtime* pRuntime = pTimer->GetRuntime(); |
586 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0)) | 581 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0)) |
587 RunJsScript(pRuntime, pTimer->GetJScript()); | 582 RunJsScript(pRuntime, pTimer->GetJScript()); |
588 } | 583 } |
589 | 584 |
590 void app::CancelProc(GlobalTimer* pTimer) { | 585 void app::CancelProc(GlobalTimer* pTimer) { |
591 m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer)); | 586 m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer)); |
592 } | 587 } |
593 | 588 |
594 void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) { | 589 void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) { |
595 if (!pRuntime->IsBlocking()) { | 590 if (!pRuntime->IsBlocking()) { |
596 IJS_Context* pContext = pRuntime->NewContext(); | 591 IJS_Context* pContext = pRuntime->NewContext(); |
597 pContext->OnExternal_Exec(); | 592 pContext->OnExternal_Exec(); |
598 CFX_WideString wtInfo; | 593 CFX_WideString wtInfo; |
599 pContext->RunScript(wsScript, &wtInfo); | 594 pContext->RunScript(wsScript, &wtInfo); |
600 pRuntime->ReleaseContext(pContext); | 595 pRuntime->ReleaseContext(pContext); |
601 } | 596 } |
602 } | 597 } |
603 | 598 |
604 FX_BOOL app::goBack(IJS_Context* cc, | 599 bool app::goBack(IJS_Context* cc, |
| 600 const std::vector<CJS_Value>& params, |
| 601 CJS_Value& vRet, |
| 602 CFX_WideString& sError) { |
| 603 // Not supported. |
| 604 return true; |
| 605 } |
| 606 |
| 607 bool app::goForward(IJS_Context* cc, |
605 const std::vector<CJS_Value>& params, | 608 const std::vector<CJS_Value>& params, |
606 CJS_Value& vRet, | 609 CJS_Value& vRet, |
607 CFX_WideString& sError) { | 610 CFX_WideString& sError) { |
608 // Not supported. | 611 // Not supported. |
609 return TRUE; | 612 return true; |
610 } | 613 } |
611 | 614 |
612 FX_BOOL app::goForward(IJS_Context* cc, | 615 bool app::mailMsg(IJS_Context* cc, |
613 const std::vector<CJS_Value>& params, | 616 const std::vector<CJS_Value>& params, |
614 CJS_Value& vRet, | 617 CJS_Value& vRet, |
615 CFX_WideString& sError) { | 618 CFX_WideString& sError) { |
616 // Not supported. | |
617 return TRUE; | |
618 } | |
619 | |
620 FX_BOOL app::mailMsg(IJS_Context* cc, | |
621 const std::vector<CJS_Value>& params, | |
622 CJS_Value& vRet, | |
623 CFX_WideString& sError) { | |
624 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 619 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
625 std::vector<CJS_Value> newParams = | 620 std::vector<CJS_Value> newParams = |
626 JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", | 621 JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", |
627 L"cBcc", L"cSubject", L"cMsg"); | 622 L"cBcc", L"cSubject", L"cMsg"); |
628 | 623 |
629 if (newParams[0].GetType() == CJS_Value::VT_unknown) { | 624 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
630 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 625 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
631 return FALSE; | 626 return false; |
632 } | 627 } |
633 bool bUI = newParams[0].ToBool(pRuntime); | 628 bool bUI = newParams[0].ToBool(pRuntime); |
634 | 629 |
635 CFX_WideString cTo; | 630 CFX_WideString cTo; |
636 if (newParams[1].GetType() != CJS_Value::VT_unknown) { | 631 if (newParams[1].GetType() != CJS_Value::VT_unknown) { |
637 cTo = newParams[1].ToCFXWideString(pRuntime); | 632 cTo = newParams[1].ToCFXWideString(pRuntime); |
638 } else { | 633 } else { |
639 if (!bUI) { | 634 if (!bUI) { |
640 // cTo parameter required when UI not invoked. | 635 // cTo parameter required when UI not invoked. |
641 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 636 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
642 return FALSE; | 637 return false; |
643 } | 638 } |
644 } | 639 } |
645 | 640 |
646 CFX_WideString cCc; | 641 CFX_WideString cCc; |
647 if (newParams[2].GetType() != CJS_Value::VT_unknown) | 642 if (newParams[2].GetType() != CJS_Value::VT_unknown) |
648 cCc = newParams[2].ToCFXWideString(pRuntime); | 643 cCc = newParams[2].ToCFXWideString(pRuntime); |
649 | 644 |
650 CFX_WideString cBcc; | 645 CFX_WideString cBcc; |
651 if (newParams[3].GetType() != CJS_Value::VT_unknown) | 646 if (newParams[3].GetType() != CJS_Value::VT_unknown) |
652 cBcc = newParams[3].ToCFXWideString(pRuntime); | 647 cBcc = newParams[3].ToCFXWideString(pRuntime); |
653 | 648 |
654 CFX_WideString cSubject; | 649 CFX_WideString cSubject; |
655 if (newParams[4].GetType() != CJS_Value::VT_unknown) | 650 if (newParams[4].GetType() != CJS_Value::VT_unknown) |
656 cSubject = newParams[4].ToCFXWideString(pRuntime); | 651 cSubject = newParams[4].ToCFXWideString(pRuntime); |
657 | 652 |
658 CFX_WideString cMsg; | 653 CFX_WideString cMsg; |
659 if (newParams[5].GetType() != CJS_Value::VT_unknown) | 654 if (newParams[5].GetType() != CJS_Value::VT_unknown) |
660 cMsg = newParams[5].ToCFXWideString(pRuntime); | 655 cMsg = newParams[5].ToCFXWideString(pRuntime); |
661 | 656 |
662 pRuntime->BeginBlock(); | 657 pRuntime->BeginBlock(); |
663 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 658 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
664 pContext->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), | 659 pContext->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), |
665 cSubject.c_str(), cCc.c_str(), | 660 cSubject.c_str(), cCc.c_str(), |
666 cBcc.c_str(), cMsg.c_str()); | 661 cBcc.c_str(), cMsg.c_str()); |
667 pRuntime->EndBlock(); | 662 pRuntime->EndBlock(); |
668 return TRUE; | 663 return true; |
669 } | 664 } |
670 | 665 |
671 FX_BOOL app::launchURL(IJS_Context* cc, | 666 bool app::launchURL(IJS_Context* cc, |
672 const std::vector<CJS_Value>& params, | 667 const std::vector<CJS_Value>& params, |
673 CJS_Value& vRet, | 668 CJS_Value& vRet, |
674 CFX_WideString& sError) { | 669 CFX_WideString& sError) { |
675 // Unsafe, not supported. | 670 // Unsafe, not supported. |
676 return TRUE; | 671 return true; |
677 } | 672 } |
678 | 673 |
679 FX_BOOL app::runtimeHighlight(IJS_Context* cc, | 674 bool app::runtimeHighlight(IJS_Context* cc, |
680 CJS_PropValue& vp, | 675 CJS_PropValue& vp, |
681 CFX_WideString& sError) { | 676 CFX_WideString& sError) { |
682 if (vp.IsSetting()) { | 677 if (vp.IsSetting()) { |
683 vp >> m_bRuntimeHighLight; | 678 vp >> m_bRuntimeHighLight; |
684 } else { | 679 } else { |
685 vp << m_bRuntimeHighLight; | 680 vp << m_bRuntimeHighLight; |
686 } | 681 } |
687 return TRUE; | 682 return true; |
688 } | 683 } |
689 | 684 |
690 FX_BOOL app::fullscreen(IJS_Context* cc, | 685 bool app::fullscreen(IJS_Context* cc, |
691 CJS_PropValue& vp, | 686 CJS_PropValue& vp, |
692 CFX_WideString& sError) { | 687 CFX_WideString& sError) { |
693 return FALSE; | 688 return false; |
694 } | 689 } |
695 | 690 |
696 FX_BOOL app::popUpMenu(IJS_Context* cc, | 691 bool app::popUpMenu(IJS_Context* cc, |
| 692 const std::vector<CJS_Value>& params, |
| 693 CJS_Value& vRet, |
| 694 CFX_WideString& sError) { |
| 695 return false; |
| 696 } |
| 697 |
| 698 bool app::browseForDoc(IJS_Context* cc, |
697 const std::vector<CJS_Value>& params, | 699 const std::vector<CJS_Value>& params, |
698 CJS_Value& vRet, | 700 CJS_Value& vRet, |
699 CFX_WideString& sError) { | 701 CFX_WideString& sError) { |
700 return FALSE; | |
701 } | |
702 | |
703 FX_BOOL app::browseForDoc(IJS_Context* cc, | |
704 const std::vector<CJS_Value>& params, | |
705 CJS_Value& vRet, | |
706 CFX_WideString& sError) { | |
707 // Unsafe, not supported. | 702 // Unsafe, not supported. |
708 return TRUE; | 703 return true; |
709 } | 704 } |
710 | 705 |
711 CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) { | 706 CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) { |
712 CFX_WideString sRet = L"/"; | 707 CFX_WideString sRet = L"/"; |
713 | 708 |
714 for (int i = 0, sz = sOldPath.GetLength(); i < sz; i++) { | 709 for (int i = 0, sz = sOldPath.GetLength(); i < sz; i++) { |
715 wchar_t c = sOldPath.GetAt(i); | 710 wchar_t c = sOldPath.GetAt(i); |
716 if (c == L':') { | 711 if (c == L':') { |
717 } else { | 712 } else { |
718 if (c == L'\\') { | 713 if (c == L'\\') { |
719 sRet += L"/"; | 714 sRet += L"/"; |
720 } else { | 715 } else { |
721 sRet += c; | 716 sRet += c; |
722 } | 717 } |
723 } | 718 } |
724 } | 719 } |
725 | 720 |
726 return sRet; | 721 return sRet; |
727 } | 722 } |
728 | 723 |
729 FX_BOOL app::newDoc(IJS_Context* cc, | 724 bool app::newDoc(IJS_Context* cc, |
730 const std::vector<CJS_Value>& params, | 725 const std::vector<CJS_Value>& params, |
731 CJS_Value& vRet, | 726 CJS_Value& vRet, |
732 CFX_WideString& sError) { | 727 CFX_WideString& sError) { |
733 return FALSE; | 728 return false; |
734 } | 729 } |
735 | 730 |
736 FX_BOOL app::openDoc(IJS_Context* cc, | 731 bool app::openDoc(IJS_Context* cc, |
737 const std::vector<CJS_Value>& params, | 732 const std::vector<CJS_Value>& params, |
738 CJS_Value& vRet, | 733 CJS_Value& vRet, |
739 CFX_WideString& sError) { | 734 CFX_WideString& sError) { |
740 return FALSE; | 735 return false; |
741 } | 736 } |
742 | 737 |
743 FX_BOOL app::response(IJS_Context* cc, | 738 bool app::response(IJS_Context* cc, |
744 const std::vector<CJS_Value>& params, | 739 const std::vector<CJS_Value>& params, |
745 CJS_Value& vRet, | 740 CJS_Value& vRet, |
746 CFX_WideString& sError) { | 741 CFX_WideString& sError) { |
747 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 742 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
748 std::vector<CJS_Value> newParams = | 743 std::vector<CJS_Value> newParams = |
749 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", | 744 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", |
750 L"cDefault", L"bPassword", L"cLabel"); | 745 L"cDefault", L"bPassword", L"cLabel"); |
751 | 746 |
752 if (newParams[0].GetType() == CJS_Value::VT_unknown) { | 747 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
753 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 748 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
754 return FALSE; | 749 return false; |
755 } | 750 } |
756 CFX_WideString swQuestion = newParams[0].ToCFXWideString(pRuntime); | 751 CFX_WideString swQuestion = newParams[0].ToCFXWideString(pRuntime); |
757 | 752 |
758 CFX_WideString swTitle = L"PDF"; | 753 CFX_WideString swTitle = L"PDF"; |
759 if (newParams[1].GetType() != CJS_Value::VT_unknown) | 754 if (newParams[1].GetType() != CJS_Value::VT_unknown) |
760 swTitle = newParams[1].ToCFXWideString(pRuntime); | 755 swTitle = newParams[1].ToCFXWideString(pRuntime); |
761 | 756 |
762 CFX_WideString swDefault; | 757 CFX_WideString swDefault; |
763 if (newParams[2].GetType() != CJS_Value::VT_unknown) | 758 if (newParams[2].GetType() != CJS_Value::VT_unknown) |
764 swDefault = newParams[2].ToCFXWideString(pRuntime); | 759 swDefault = newParams[2].ToCFXWideString(pRuntime); |
(...skipping 10 matching lines...) Expand all Loading... |
775 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]); | 770 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]); |
776 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); | 771 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); |
777 | 772 |
778 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 773 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
779 int nLengthBytes = pContext->GetFormFillEnv()->JS_appResponse( | 774 int nLengthBytes = pContext->GetFormFillEnv()->JS_appResponse( |
780 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), | 775 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), |
781 bPassword, pBuff.get(), MAX_INPUT_BYTES); | 776 bPassword, pBuff.get(), MAX_INPUT_BYTES); |
782 | 777 |
783 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) { | 778 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) { |
784 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG); | 779 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG); |
785 return FALSE; | 780 return false; |
786 } | 781 } |
787 | 782 |
788 vRet = CJS_Value(pRuntime, CFX_WideString::FromUTF16LE( | 783 vRet = CJS_Value(pRuntime, CFX_WideString::FromUTF16LE( |
789 reinterpret_cast<uint16_t*>(pBuff.get()), | 784 reinterpret_cast<uint16_t*>(pBuff.get()), |
790 nLengthBytes / sizeof(uint16_t)) | 785 nLengthBytes / sizeof(uint16_t)) |
791 .c_str()); | 786 .c_str()); |
792 | 787 |
793 return TRUE; | 788 return true; |
794 } | 789 } |
795 | 790 |
796 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 791 bool app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
797 return FALSE; | 792 return false; |
798 } | 793 } |
799 | 794 |
800 FX_BOOL app::execDialog(IJS_Context* cc, | 795 bool app::execDialog(IJS_Context* cc, |
801 const std::vector<CJS_Value>& params, | 796 const std::vector<CJS_Value>& params, |
802 CJS_Value& vRet, | 797 CJS_Value& vRet, |
803 CFX_WideString& sError) { | 798 CFX_WideString& sError) { |
804 return TRUE; | 799 return true; |
805 } | 800 } |
OLD | NEW |