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