Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: fpdfsdk/src/javascript/app.cpp

Issue 1382263002: Store object definition ID in each js_class. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Use size_t vars with FX_ArraySize. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/app.h ('k') | fpdfsdk/src/javascript/color.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 CJS_Context* pContext = (CJS_Context*)cc; 118 CJS_Context* pContext = (CJS_Context*)cc;
119 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 119 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
120 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 120 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
121 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); 121 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
122 CJS_Array aDocs(pRuntime->GetIsolate()); 122 CJS_Array aDocs(pRuntime->GetIsolate());
123 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { 123 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) {
124 CJS_Document* pJSDocument = NULL; 124 CJS_Document* pJSDocument = NULL;
125 if (pDoc == pCurDoc) { 125 if (pDoc == pCurDoc) {
126 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate()); 126 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate());
127 if (FXJS_GetObjDefnID(pObj) == 127 if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID)
128 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"))
129 pJSDocument = 128 pJSDocument =
130 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); 129 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
131 } else { 130 } else {
132 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 131 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
133 pRuntime->GetIsolate(), pContext, 132 pRuntime->GetIsolate(), pContext, CJS_Document::g_nObjDefnID);
134 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
135 pJSDocument = 133 pJSDocument =
136 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); 134 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
137 ASSERT(pJSDocument != NULL); 135 ASSERT(pJSDocument != NULL);
138 } 136 }
139 aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument)); 137 aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument));
140 } 138 }
141 if (aDocs.GetLength() > 0) 139 if (aDocs.GetLength() > 0)
142 vp << aDocs; 140 vp << aDocs;
143 else 141 else
144 vp.SetNull(); 142 vp.SetNull();
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 405 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
408 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000; 406 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000;
409 407
410 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); 408 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
411 ASSERT(pApp); 409 ASSERT(pApp);
412 CJS_Timer* pTimer = 410 CJS_Timer* pTimer =
413 new CJS_Timer(this, pApp, pRuntime, 0, script, dwInterval, 0); 411 new CJS_Timer(this, pApp, pRuntime, 0, script, dwInterval, 0);
414 m_aTimer.Add(pTimer); 412 m_aTimer.Add(pTimer);
415 413
416 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( 414 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
417 pRuntime->GetIsolate(), pContext, 415 pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID);
418 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
419
420 CJS_TimerObj* pJS_TimerObj = 416 CJS_TimerObj* pJS_TimerObj =
421 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); 417 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
422 ASSERT(pJS_TimerObj != NULL);
423
424 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); 418 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
425 ASSERT(pTimerObj != NULL);
426
427 pTimerObj->SetTimer(pTimer); 419 pTimerObj->SetTimer(pTimer);
428 420
429 vRet = pRetObj; 421 vRet = pRetObj;
430
431 return TRUE; 422 return TRUE;
432 } 423 }
433 424
434 FX_BOOL app::setTimeOut(IFXJS_Context* cc, 425 FX_BOOL app::setTimeOut(IFXJS_Context* cc,
435 const CJS_Parameters& params, 426 const CJS_Parameters& params,
436 CJS_Value& vRet, 427 CJS_Value& vRet,
437 CFX_WideString& sError) { 428 CFX_WideString& sError) {
438 if (params.size() > 2 || params.size() == 0) { 429 if (params.size() > 2 || params.size() == 0) {
439 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); 430 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
440 return FALSE; 431 return FALSE;
(...skipping 14 matching lines...) Expand all
455 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000; 446 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
456 447
457 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); 448 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
458 ASSERT(pApp); 449 ASSERT(pApp);
459 450
460 CJS_Timer* pTimer = 451 CJS_Timer* pTimer =
461 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut); 452 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut);
462 m_aTimer.Add(pTimer); 453 m_aTimer.Add(pTimer);
463 454
464 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( 455 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
465 pRuntime->GetIsolate(), pContext, 456 pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID);
466 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
467
468 CJS_TimerObj* pJS_TimerObj = 457 CJS_TimerObj* pJS_TimerObj =
469 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); 458 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
470 ASSERT(pJS_TimerObj != NULL);
471
472 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); 459 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
473 ASSERT(pTimerObj != NULL);
474
475 pTimerObj->SetTimer(pTimer); 460 pTimerObj->SetTimer(pTimer);
476 461
477 vRet = pRetObj; 462 vRet = pRetObj;
478
479 return TRUE; 463 return TRUE;
480 } 464 }
481 465
482 FX_BOOL app::clearTimeOut(IFXJS_Context* cc, 466 FX_BOOL app::clearTimeOut(IFXJS_Context* cc,
483 const CJS_Parameters& params, 467 const CJS_Parameters& params,
484 CJS_Value& vRet, 468 CJS_Value& vRet,
485 CFX_WideString& sError) { 469 CFX_WideString& sError) {
486 CJS_Context* pContext = (CJS_Context*)cc; 470 CJS_Context* pContext = (CJS_Context*)cc;
487 ASSERT(pContext != NULL);
488 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
489 ASSERT(pRuntime != NULL);
490
491 if (params.size() != 1) { 471 if (params.size() != 1) {
492 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); 472 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
493 return FALSE; 473 return FALSE;
494 } 474 }
495 475
496 if (params[0].GetType() == CJS_Value::VT_fxobject) { 476 if (params[0].GetType() == CJS_Value::VT_fxobject) {
497 v8::Local<v8::Object> pObj = params[0].ToV8Object(); 477 v8::Local<v8::Object> pObj = params[0].ToV8Object();
498 { 478 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
499 if (FXJS_GetObjDefnID(pObj) == 479 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
500 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) { 480 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
501 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { 481 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
502 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { 482 pTimer->KillJSTimer();
503 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
504 pTimer->KillJSTimer();
505 483
506 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { 484 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
507 if (m_aTimer[i] == pTimer) { 485 if (m_aTimer[i] == pTimer) {
508 m_aTimer.RemoveAt(i); 486 m_aTimer.RemoveAt(i);
509 break; 487 break;
510 }
511 } 488 }
489 }
512 490
513 delete pTimer; 491 delete pTimer;
514 pTimerObj->SetTimer(NULL); 492 pTimerObj->SetTimer(NULL);
515 }
516 } 493 }
517 } 494 }
518 } 495 }
519 } 496 }
520 } 497 }
521 498
522 return TRUE; 499 return TRUE;
523 } 500 }
524 501
525 FX_BOOL app::clearInterval(IFXJS_Context* cc, 502 FX_BOOL app::clearInterval(IFXJS_Context* cc,
526 const CJS_Parameters& params, 503 const CJS_Parameters& params,
527 CJS_Value& vRet, 504 CJS_Value& vRet,
528 CFX_WideString& sError) { 505 CFX_WideString& sError) {
529 CJS_Context* pContext = (CJS_Context*)cc; 506 CJS_Context* pContext = (CJS_Context*)cc;
530 ASSERT(pContext != NULL);
531 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
532 ASSERT(pRuntime != NULL);
533
534 if (params.size() != 1) { 507 if (params.size() != 1) {
535 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); 508 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
536 return FALSE; 509 return FALSE;
537 } 510 }
538 511
539 if (params[0].GetType() == CJS_Value::VT_fxobject) { 512 if (params[0].GetType() == CJS_Value::VT_fxobject) {
540 v8::Local<v8::Object> pObj = params[0].ToV8Object(); 513 v8::Local<v8::Object> pObj = params[0].ToV8Object();
541 { 514 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
542 if (FXJS_GetObjDefnID(pObj) == 515 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
543 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) { 516 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
544 if (CJS_Object* pJSObj = params[0].ToCJSObject()) { 517 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
545 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) { 518 pTimer->KillJSTimer();
546 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
547 pTimer->KillJSTimer();
548 519
549 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) { 520 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
550 if (m_aTimer[i] == pTimer) { 521 if (m_aTimer[i] == pTimer) {
551 m_aTimer.RemoveAt(i); 522 m_aTimer.RemoveAt(i);
552 break; 523 break;
553 }
554 } 524 }
525 }
555 526
556 delete pTimer; 527 delete pTimer;
557 pTimerObj->SetTimer(NULL); 528 pTimerObj->SetTimer(NULL);
558 }
559 } 529 }
560 } 530 }
561 } 531 }
562 } 532 }
563 } 533 }
564 534
565 return TRUE; 535 return TRUE;
566 } 536 }
567 537
568 FX_BOOL app::execMenuItem(IFXJS_Context* cc, 538 FX_BOOL app::execMenuItem(IFXJS_Context* cc,
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 CFX_WideString& sError) { 818 CFX_WideString& sError) {
849 return FALSE; 819 return FALSE;
850 } 820 }
851 821
852 FX_BOOL app::execDialog(IFXJS_Context* cc, 822 FX_BOOL app::execDialog(IFXJS_Context* cc,
853 const CJS_Parameters& params, 823 const CJS_Parameters& params,
854 CJS_Value& vRet, 824 CJS_Value& vRet,
855 CFX_WideString& sError) { 825 CFX_WideString& sError) {
856 return TRUE; 826 return TRUE;
857 } 827 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/app.h ('k') | fpdfsdk/src/javascript/color.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698