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 "../../../third_party/base/nonstd_unique_ptr.h" | 9 #include "../../../third_party/base/nonstd_unique_ptr.h" |
10 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. | 10 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 118 |
119 CJS_Context* pContext = (CJS_Context*)cc; | 119 CJS_Context* pContext = (CJS_Context*)cc; |
120 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); | 120 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); |
121 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 121 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
122 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); | 122 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); |
123 CJS_Array aDocs(pRuntime->GetIsolate()); | 123 CJS_Array aDocs(pRuntime->GetIsolate()); |
124 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { | 124 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { |
125 CJS_Document* pJSDocument = NULL; | 125 CJS_Document* pJSDocument = NULL; |
126 if (pDoc == pCurDoc) { | 126 if (pDoc == pCurDoc) { |
127 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate()); | 127 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate()); |
128 if (FXJS_GetObjDefnID(pObj) == | 128 if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) |
129 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document")) | |
130 pJSDocument = | 129 pJSDocument = |
131 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); | 130 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); |
132 } else { | 131 } else { |
133 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 132 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
134 pRuntime->GetIsolate(), pContext, | 133 pRuntime->GetIsolate(), pContext, CJS_Document::g_nObjDefnID); |
135 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document")); | |
136 pJSDocument = | 134 pJSDocument = |
137 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); | 135 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); |
138 ASSERT(pJSDocument != NULL); | 136 ASSERT(pJSDocument != NULL); |
139 } | 137 } |
140 aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument)); | 138 aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument)); |
141 } | 139 } |
142 if (aDocs.GetLength() > 0) | 140 if (aDocs.GetLength() > 0) |
143 vp << aDocs; | 141 vp << aDocs; |
144 else | 142 else |
145 vp.SetNull(); | 143 vp.SetNull(); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 412 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
415 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000; | 413 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000; |
416 | 414 |
417 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); | 415 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); |
418 ASSERT(pApp); | 416 ASSERT(pApp); |
419 CJS_Timer* pTimer = | 417 CJS_Timer* pTimer = |
420 new CJS_Timer(this, pApp, pRuntime, 0, script, dwInterval, 0); | 418 new CJS_Timer(this, pApp, pRuntime, 0, script, dwInterval, 0); |
421 m_aTimer.Add(pTimer); | 419 m_aTimer.Add(pTimer); |
422 | 420 |
423 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( | 421 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( |
424 pRuntime->GetIsolate(), pContext, | 422 pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID); |
425 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")); | |
426 | |
427 CJS_TimerObj* pJS_TimerObj = | 423 CJS_TimerObj* pJS_TimerObj = |
428 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); | 424 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); |
429 ASSERT(pJS_TimerObj != NULL); | |
430 | |
431 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); | 425 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); |
432 ASSERT(pTimerObj != NULL); | |
433 | |
434 pTimerObj->SetTimer(pTimer); | 426 pTimerObj->SetTimer(pTimer); |
435 | 427 |
436 vRet = pRetObj; | 428 vRet = pRetObj; |
437 | |
438 return TRUE; | 429 return TRUE; |
439 } | 430 } |
440 | 431 |
441 FX_BOOL app::setTimeOut(IFXJS_Context* cc, | 432 FX_BOOL app::setTimeOut(IFXJS_Context* cc, |
442 const CJS_Parameters& params, | 433 const CJS_Parameters& params, |
443 CJS_Value& vRet, | 434 CJS_Value& vRet, |
444 CFX_WideString& sError) { | 435 CFX_WideString& sError) { |
445 if (params.size() > 2 || params.size() == 0) { | 436 if (params.size() > 2 || params.size() == 0) { |
446 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); | 437 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); |
447 return FALSE; | 438 return FALSE; |
(...skipping 14 matching lines...) Expand all Loading... |
462 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000; | 453 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000; |
463 | 454 |
464 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); | 455 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); |
465 ASSERT(pApp); | 456 ASSERT(pApp); |
466 | 457 |
467 CJS_Timer* pTimer = | 458 CJS_Timer* pTimer = |
468 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut); | 459 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut); |
469 m_aTimer.Add(pTimer); | 460 m_aTimer.Add(pTimer); |
470 | 461 |
471 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( | 462 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( |
472 pRuntime->GetIsolate(), pContext, | 463 pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID); |
473 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")); | |
474 | |
475 CJS_TimerObj* pJS_TimerObj = | 464 CJS_TimerObj* pJS_TimerObj = |
476 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); | 465 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); |
477 ASSERT(pJS_TimerObj != NULL); | |
478 | |
479 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); | 466 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); |
480 ASSERT(pTimerObj != NULL); | |
481 | |
482 pTimerObj->SetTimer(pTimer); | 467 pTimerObj->SetTimer(pTimer); |
483 | 468 |
484 vRet = pRetObj; | 469 vRet = pRetObj; |
485 | |
486 return TRUE; | 470 return TRUE; |
487 } | 471 } |
488 | 472 |
489 FX_BOOL app::clearTimeOut(IFXJS_Context* cc, | 473 FX_BOOL app::clearTimeOut(IFXJS_Context* cc, |
490 const CJS_Parameters& params, | 474 const CJS_Parameters& params, |
491 CJS_Value& vRet, | 475 CJS_Value& vRet, |
492 CFX_WideString& sError) { | 476 CFX_WideString& sError) { |
493 CJS_Context* pContext = (CJS_Context*)cc; | 477 CJS_Context* pContext = (CJS_Context*)cc; |
494 ASSERT(pContext != NULL); | |
495 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
496 ASSERT(pRuntime != NULL); | |
497 | |
498 if (params.size() != 1) { | 478 if (params.size() != 1) { |
499 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); | 479 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
500 return FALSE; | 480 return FALSE; |
501 } | 481 } |
502 | 482 |
503 if (params[0].GetType() == CJS_Value::VT_fxobject) { | 483 if (params[0].GetType() == CJS_Value::VT_fxobject) { |
504 v8::Local<v8::Object> pObj = params[0].ToV8Object(); | 484 v8::Local<v8::Object> pObj = params[0].ToV8Object(); |
505 { | 485 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) { |
506 if (FXJS_GetObjDefnID(pObj) == | 486 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { |
507 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) { | 487 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { |
508 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { | 488 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { |
509 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { | 489 pTimer->KillJSTimer(); |
510 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { | |
511 pTimer->KillJSTimer(); | |
512 | 490 |
513 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { | 491 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { |
514 if (m_aTimer[i] == pTimer) { | 492 if (m_aTimer[i] == pTimer) { |
515 m_aTimer.RemoveAt(i); | 493 m_aTimer.RemoveAt(i); |
516 break; | 494 break; |
517 } | |
518 } | 495 } |
| 496 } |
519 | 497 |
520 delete pTimer; | 498 delete pTimer; |
521 pTimerObj->SetTimer(NULL); | 499 pTimerObj->SetTimer(NULL); |
522 } | |
523 } | 500 } |
524 } | 501 } |
525 } | 502 } |
526 } | 503 } |
527 } | 504 } |
528 | 505 |
529 return TRUE; | 506 return TRUE; |
530 } | 507 } |
531 | 508 |
532 FX_BOOL app::clearInterval(IFXJS_Context* cc, | 509 FX_BOOL app::clearInterval(IFXJS_Context* cc, |
533 const CJS_Parameters& params, | 510 const CJS_Parameters& params, |
534 CJS_Value& vRet, | 511 CJS_Value& vRet, |
535 CFX_WideString& sError) { | 512 CFX_WideString& sError) { |
536 CJS_Context* pContext = (CJS_Context*)cc; | 513 CJS_Context* pContext = (CJS_Context*)cc; |
537 ASSERT(pContext != NULL); | |
538 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
539 ASSERT(pRuntime != NULL); | |
540 | |
541 if (params.size() != 1) { | 514 if (params.size() != 1) { |
542 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); | 515 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
543 return FALSE; | 516 return FALSE; |
544 } | 517 } |
545 | 518 |
546 if (params[0].GetType() == CJS_Value::VT_fxobject) { | 519 if (params[0].GetType() == CJS_Value::VT_fxobject) { |
547 v8::Local<v8::Object> pObj = params[0].ToV8Object(); | 520 v8::Local<v8::Object> pObj = params[0].ToV8Object(); |
548 { | 521 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) { |
549 if (FXJS_GetObjDefnID(pObj) == | 522 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { |
550 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) { | 523 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { |
551 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { | 524 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { |
552 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { | 525 pTimer->KillJSTimer(); |
553 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { | |
554 pTimer->KillJSTimer(); | |
555 | 526 |
556 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { | 527 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { |
557 if (m_aTimer[i] == pTimer) { | 528 if (m_aTimer[i] == pTimer) { |
558 m_aTimer.RemoveAt(i); | 529 m_aTimer.RemoveAt(i); |
559 break; | 530 break; |
560 } | |
561 } | 531 } |
| 532 } |
562 | 533 |
563 delete pTimer; | 534 delete pTimer; |
564 pTimerObj->SetTimer(NULL); | 535 pTimerObj->SetTimer(NULL); |
565 } | |
566 } | 536 } |
567 } | 537 } |
568 } | 538 } |
569 } | 539 } |
570 } | 540 } |
571 | 541 |
572 return TRUE; | 542 return TRUE; |
573 } | 543 } |
574 | 544 |
575 FX_BOOL app::execMenuItem(IFXJS_Context* cc, | 545 FX_BOOL app::execMenuItem(IFXJS_Context* cc, |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 CFX_WideString& sError) { | 825 CFX_WideString& sError) { |
856 return FALSE; | 826 return FALSE; |
857 } | 827 } |
858 | 828 |
859 FX_BOOL app::execDialog(IFXJS_Context* cc, | 829 FX_BOOL app::execDialog(IFXJS_Context* cc, |
860 const CJS_Parameters& params, | 830 const CJS_Parameters& params, |
861 CJS_Value& vRet, | 831 CJS_Value& vRet, |
862 CFX_WideString& sError) { | 832 CFX_WideString& sError) { |
863 return TRUE; | 833 return TRUE; |
864 } | 834 } |
OLD | NEW |