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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 404 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
407 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000; | 405 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000; |
408 | 406 |
409 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); | 407 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); |
410 ASSERT(pApp); | 408 ASSERT(pApp); |
411 CJS_Timer* pTimer = | 409 CJS_Timer* pTimer = |
412 new CJS_Timer(this, pApp, pRuntime, 0, script, dwInterval, 0); | 410 new CJS_Timer(this, pApp, pRuntime, 0, script, dwInterval, 0); |
413 m_aTimer.Add(pTimer); | 411 m_aTimer.Add(pTimer); |
414 | 412 |
415 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( | 413 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( |
416 pRuntime->GetIsolate(), pContext, | 414 pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID); |
417 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")); | |
418 | |
419 CJS_TimerObj* pJS_TimerObj = | 415 CJS_TimerObj* pJS_TimerObj = |
420 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); | 416 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); |
421 ASSERT(pJS_TimerObj != NULL); | |
422 | |
423 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); | 417 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); |
424 ASSERT(pTimerObj != NULL); | |
425 | |
426 pTimerObj->SetTimer(pTimer); | 418 pTimerObj->SetTimer(pTimer); |
427 | 419 |
428 vRet = pRetObj; | 420 vRet = pRetObj; |
429 | |
430 return TRUE; | 421 return TRUE; |
431 } | 422 } |
432 | 423 |
433 FX_BOOL app::setTimeOut(IFXJS_Context* cc, | 424 FX_BOOL app::setTimeOut(IFXJS_Context* cc, |
434 const CJS_Parameters& params, | 425 const CJS_Parameters& params, |
435 CJS_Value& vRet, | 426 CJS_Value& vRet, |
436 CFX_WideString& sError) { | 427 CFX_WideString& sError) { |
437 if (params.size() > 2 || params.size() == 0) { | 428 if (params.size() > 2 || params.size() == 0) { |
438 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); | 429 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); |
439 return FALSE; | 430 return FALSE; |
(...skipping 14 matching lines...) Expand all Loading... | |
454 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000; | 445 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000; |
455 | 446 |
456 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); | 447 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); |
457 ASSERT(pApp); | 448 ASSERT(pApp); |
458 | 449 |
459 CJS_Timer* pTimer = | 450 CJS_Timer* pTimer = |
460 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut); | 451 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut); |
461 m_aTimer.Add(pTimer); | 452 m_aTimer.Add(pTimer); |
462 | 453 |
463 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( | 454 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( |
464 pRuntime->GetIsolate(), pContext, | 455 pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID); |
465 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")); | |
466 | |
467 CJS_TimerObj* pJS_TimerObj = | 456 CJS_TimerObj* pJS_TimerObj = |
468 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); | 457 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); |
469 ASSERT(pJS_TimerObj != NULL); | |
470 | |
471 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); | 458 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); |
472 ASSERT(pTimerObj != NULL); | |
473 | |
474 pTimerObj->SetTimer(pTimer); | 459 pTimerObj->SetTimer(pTimer); |
475 | 460 |
476 vRet = pRetObj; | 461 vRet = pRetObj; |
477 | |
478 return TRUE; | 462 return TRUE; |
479 } | 463 } |
480 | 464 |
481 FX_BOOL app::clearTimeOut(IFXJS_Context* cc, | 465 FX_BOOL app::clearTimeOut(IFXJS_Context* cc, |
482 const CJS_Parameters& params, | 466 const CJS_Parameters& params, |
483 CJS_Value& vRet, | 467 CJS_Value& vRet, |
484 CFX_WideString& sError) { | 468 CFX_WideString& sError) { |
485 CJS_Context* pContext = (CJS_Context*)cc; | 469 CJS_Context* pContext = (CJS_Context*)cc; |
486 ASSERT(pContext != NULL); | |
487 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
488 ASSERT(pRuntime != NULL); | |
489 | |
490 if (params.size() != 1) { | 470 if (params.size() != 1) { |
491 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); | 471 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
492 return FALSE; | 472 return FALSE; |
493 } | 473 } |
494 | 474 |
495 if (params[0].GetType() == CJS_Value::VT_fxobject) { | 475 if (params[0].GetType() == CJS_Value::VT_fxobject) { |
496 v8::Local<v8::Object> pObj = params[0].ToV8Object(); | 476 v8::Local<v8::Object> pObj = params[0].ToV8Object(); |
497 { | 477 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) { |
498 if (FXJS_GetObjDefnID(pObj) == | |
499 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) { | |
500 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { | 478 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { |
Lei Zhang
2015/10/06 01:15:21
indentation's off
Tom Sepez
2015/10/06 15:33:20
Yow. Git cl format not withstanding.
| |
501 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { | 479 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { |
502 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { | 480 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { |
503 pTimer->KillJSTimer(); | 481 pTimer->KillJSTimer(); |
504 | 482 |
505 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { | 483 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { |
506 if (m_aTimer[i] == pTimer) { | 484 if (m_aTimer[i] == pTimer) { |
507 m_aTimer.RemoveAt(i); | 485 m_aTimer.RemoveAt(i); |
508 break; | 486 break; |
509 } | 487 } |
510 } | 488 } |
511 | 489 |
512 delete pTimer; | 490 delete pTimer; |
513 pTimerObj->SetTimer(NULL); | 491 pTimerObj->SetTimer(NULL); |
514 } | 492 } |
515 } | 493 } |
516 } | 494 } |
517 } | |
518 } | 495 } |
519 } | 496 } |
520 | 497 |
521 return TRUE; | 498 return TRUE; |
522 } | 499 } |
523 | 500 |
524 FX_BOOL app::clearInterval(IFXJS_Context* cc, | 501 FX_BOOL app::clearInterval(IFXJS_Context* cc, |
525 const CJS_Parameters& params, | 502 const CJS_Parameters& params, |
526 CJS_Value& vRet, | 503 CJS_Value& vRet, |
527 CFX_WideString& sError) { | 504 CFX_WideString& sError) { |
528 CJS_Context* pContext = (CJS_Context*)cc; | 505 CJS_Context* pContext = (CJS_Context*)cc; |
529 ASSERT(pContext != NULL); | |
530 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
531 ASSERT(pRuntime != NULL); | |
532 | |
533 if (params.size() != 1) { | 506 if (params.size() != 1) { |
534 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); | 507 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
535 return FALSE; | 508 return FALSE; |
536 } | 509 } |
537 | 510 |
538 if (params[0].GetType() == CJS_Value::VT_fxobject) { | 511 if (params[0].GetType() == CJS_Value::VT_fxobject) { |
539 v8::Local<v8::Object> pObj = params[0].ToV8Object(); | 512 v8::Local<v8::Object> pObj = params[0].ToV8Object(); |
540 { | 513 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) { |
541 if (FXJS_GetObjDefnID(pObj) == | |
542 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) { | |
543 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { | 514 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { |
Lei Zhang
2015/10/06 01:15:21
ditto indentation
Tom Sepez
2015/10/06 15:33:20
Ditto yow.
| |
544 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { | 515 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { |
545 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { | 516 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) { |
546 pTimer->KillJSTimer(); | 517 pTimer->KillJSTimer(); |
547 | 518 |
548 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { | 519 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { |
549 if (m_aTimer[i] == pTimer) { | 520 if (m_aTimer[i] == pTimer) { |
550 m_aTimer.RemoveAt(i); | 521 m_aTimer.RemoveAt(i); |
551 break; | 522 break; |
552 } | 523 } |
553 } | 524 } |
554 | 525 |
555 delete pTimer; | 526 delete pTimer; |
556 pTimerObj->SetTimer(NULL); | 527 pTimerObj->SetTimer(NULL); |
557 } | 528 } |
558 } | 529 } |
559 } | |
560 } | 530 } |
561 } | 531 } |
562 } | 532 } |
563 | 533 |
564 return TRUE; | 534 return TRUE; |
565 } | 535 } |
566 | 536 |
567 FX_BOOL app::execMenuItem(IFXJS_Context* cc, | 537 FX_BOOL app::execMenuItem(IFXJS_Context* cc, |
568 const CJS_Parameters& params, | 538 const CJS_Parameters& params, |
569 CJS_Value& vRet, | 539 CJS_Value& vRet, |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 CFX_WideString& sError) { | 817 CFX_WideString& sError) { |
848 return FALSE; | 818 return FALSE; |
849 } | 819 } |
850 | 820 |
851 FX_BOOL app::execDialog(IFXJS_Context* cc, | 821 FX_BOOL app::execDialog(IFXJS_Context* cc, |
852 const CJS_Parameters& params, | 822 const CJS_Parameters& params, |
853 CJS_Value& vRet, | 823 CJS_Value& vRet, |
854 CFX_WideString& sError) { | 824 CFX_WideString& sError) { |
855 return TRUE; | 825 return TRUE; |
856 } | 826 } |
OLD | NEW |