Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 BEGIN_JS_STATIC_PROP(CJS_TimerObj) | 25 BEGIN_JS_STATIC_PROP(CJS_TimerObj) |
| 26 END_JS_STATIC_PROP() | 26 END_JS_STATIC_PROP() |
| 27 | 27 |
| 28 BEGIN_JS_STATIC_METHOD(CJS_TimerObj) | 28 BEGIN_JS_STATIC_METHOD(CJS_TimerObj) |
| 29 END_JS_STATIC_METHOD() | 29 END_JS_STATIC_METHOD() |
| 30 | 30 |
| 31 IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj) | 31 IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj) |
| 32 | 32 |
| 33 TimerObj::TimerObj(CJS_Object* pJSObject) | 33 TimerObj::TimerObj(CJS_Object* pJSObject) |
| 34 : CJS_EmbedObj(pJSObject), m_pTimer(nullptr) {} | 34 : CJS_EmbedObj(pJSObject), m_nTimerID(0) {} |
| 35 | 35 |
| 36 TimerObj::~TimerObj() {} | 36 TimerObj::~TimerObj() {} |
| 37 | 37 |
| 38 void TimerObj::SetTimer(CJS_Timer* pTimer) { | 38 void TimerObj::SetTimer(CJS_Timer* pTimer) { |
|
Lei Zhang
2016/08/05 22:29:55
Maybe just take the ID?
Tom Sepez
2016/08/05 23:11:42
I wanted to prove that you weren't just making up
| |
| 39 m_pTimer = pTimer; | 39 m_nTimerID = pTimer->GetTimerID(); |
| 40 } | |
| 41 | |
| 42 CJS_Timer* TimerObj::GetTimer() const { | |
| 43 return m_pTimer; | |
| 44 } | 40 } |
| 45 | 41 |
| 46 #define JS_STR_VIEWERTYPE L"pdfium" | 42 #define JS_STR_VIEWERTYPE L"pdfium" |
| 47 #define JS_STR_VIEWERVARIATION L"Full" | 43 #define JS_STR_VIEWERVARIATION L"Full" |
| 48 #define JS_STR_PLATFORM L"WIN" | 44 #define JS_STR_PLATFORM L"WIN" |
| 49 #define JS_STR_LANGUANGE L"ENU" | 45 #define JS_STR_LANGUANGE L"ENU" |
| 50 #define JS_NUM_VIEWERVERSION 8 | 46 #define JS_NUM_VIEWERVERSION 8 |
| 51 #ifdef PDF_ENABLE_XFA | 47 #ifdef PDF_ENABLE_XFA |
| 52 #define JS_NUM_VIEWERVERSION_XFA 11 | 48 #define JS_NUM_VIEWERVERSION_XFA 11 |
| 53 #endif // PDF_ENABLE_XFA | 49 #endif // PDF_ENABLE_XFA |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 return; | 462 return; |
| 467 | 463 |
| 468 CJS_Object* pJSObj = param.ToCJSObject(); | 464 CJS_Object* pJSObj = param.ToCJSObject(); |
| 469 if (!pJSObj) | 465 if (!pJSObj) |
| 470 return; | 466 return; |
| 471 | 467 |
| 472 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject()); | 468 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject()); |
| 473 if (!pTimerObj) | 469 if (!pTimerObj) |
| 474 return; | 470 return; |
| 475 | 471 |
| 476 CJS_Timer* pTimer = pTimerObj->GetTimer(); | 472 CJS_Timer::Cancel(pTimerObj->GetTimerID()); |
| 477 if (!pTimer) | |
| 478 return; | |
| 479 | |
| 480 pTimer->KillJSTimer(); | |
| 481 auto iter = std::find_if(m_Timers.begin(), m_Timers.end(), | |
| 482 [pTimer](const std::unique_ptr<CJS_Timer>& that) { | |
| 483 return pTimer == that.get(); | |
| 484 }); | |
| 485 | |
| 486 if (iter != m_Timers.end()) | |
| 487 m_Timers.erase(iter); | |
| 488 | |
| 489 pTimerObj->SetTimer(nullptr); | |
| 490 } | 473 } |
| 491 | 474 |
| 492 FX_BOOL app::execMenuItem(IJS_Context* cc, | 475 FX_BOOL app::execMenuItem(IJS_Context* cc, |
| 493 const std::vector<CJS_Value>& params, | 476 const std::vector<CJS_Value>& params, |
| 494 CJS_Value& vRet, | 477 CJS_Value& vRet, |
| 495 CFX_WideString& sError) { | 478 CFX_WideString& sError) { |
| 496 return FALSE; | 479 return FALSE; |
| 497 } | 480 } |
| 498 | 481 |
| 499 void app::TimerProc(CJS_Timer* pTimer) { | 482 void app::TimerProc(CJS_Timer* pTimer) { |
| 500 CJS_Runtime* pRuntime = pTimer->GetRuntime(); | 483 CJS_Runtime* pRuntime = pTimer->GetRuntime(); |
| 484 if (pRuntime && (!pTimer->IsOneTime() || pTimer->GetTimeOut() > 0)) | |
| 485 RunJsScript(pRuntime, pTimer->GetJScript()); | |
| 486 } | |
| 501 | 487 |
| 502 switch (pTimer->GetType()) { | 488 void app::CancelProc(CJS_Timer* pTimer) { |
| 503 case 0: // interval | 489 auto iter = std::find_if(m_Timers.begin(), m_Timers.end(), |
| 504 if (pRuntime) | 490 [pTimer](const std::unique_ptr<CJS_Timer>& that) { |
| 505 RunJsScript(pRuntime, pTimer->GetJScript()); | 491 return pTimer == that.get(); |
| 506 break; | 492 }); |
| 507 case 1: | 493 |
| 508 if (pTimer->GetTimeOut() > 0) { | 494 if (iter != m_Timers.end()) |
| 509 if (pRuntime) | 495 m_Timers.erase(iter); |
| 510 RunJsScript(pRuntime, pTimer->GetJScript()); | |
| 511 pTimer->KillJSTimer(); | |
| 512 } | |
| 513 break; | |
| 514 } | |
| 515 } | 496 } |
| 516 | 497 |
| 517 void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) { | 498 void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) { |
| 518 if (!pRuntime->IsBlocking()) { | 499 if (!pRuntime->IsBlocking()) { |
| 519 IJS_Context* pContext = pRuntime->NewContext(); | 500 IJS_Context* pContext = pRuntime->NewContext(); |
| 520 pContext->OnExternal_Exec(); | 501 pContext->OnExternal_Exec(); |
| 521 CFX_WideString wtInfo; | 502 CFX_WideString wtInfo; |
| 522 pContext->RunScript(wsScript, &wtInfo); | 503 pContext->RunScript(wsScript, &wtInfo); |
| 523 pRuntime->ReleaseContext(pContext); | 504 pRuntime->ReleaseContext(pContext); |
| 524 } | 505 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 698 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
| 718 return FALSE; | 699 return FALSE; |
| 719 } | 700 } |
| 720 | 701 |
| 721 FX_BOOL app::execDialog(IJS_Context* cc, | 702 FX_BOOL app::execDialog(IJS_Context* cc, |
| 722 const std::vector<CJS_Value>& params, | 703 const std::vector<CJS_Value>& params, |
| 723 CJS_Value& vRet, | 704 CJS_Value& vRet, |
| 724 CFX_WideString& sError) { | 705 CFX_WideString& sError) { |
| 725 return TRUE; | 706 return TRUE; |
| 726 } | 707 } |
| OLD | NEW |