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

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

Issue 1384883002: CJS_Timer should observe CJS_Runtime destruction. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: 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/JS_Runtime.cpp ('k') | no next file » | 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 "../../../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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 if (script.IsEmpty()) { 401 if (script.IsEmpty()) {
402 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); 402 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
403 return TRUE; 403 return TRUE;
404 } 404 }
405 405
406 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 406 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
407 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000; 407 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000;
408 408
409 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); 409 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
410 ASSERT(pApp); 410 ASSERT(pApp);
411 CJS_Timer* pTimer = new CJS_Timer(this, pApp); 411 CJS_Timer* pTimer =
412 new CJS_Timer(this, pApp, pRuntime, 0, script, dwInterval, 0);
412 m_aTimer.Add(pTimer); 413 m_aTimer.Add(pTimer);
413 414
414 pTimer->SetType(0);
415 pTimer->SetRuntime(pRuntime);
416 pTimer->SetJScript(script);
417 pTimer->SetTimeOut(0);
418 // pTimer->SetStartTime(GetTickCount());
419 pTimer->SetJSTimer(dwInterval);
420
421 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( 415 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
422 pRuntime->GetIsolate(), pContext, 416 pRuntime->GetIsolate(), pContext,
423 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")); 417 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
424 418
425 CJS_TimerObj* pJS_TimerObj = 419 CJS_TimerObj* pJS_TimerObj =
426 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); 420 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
427 ASSERT(pJS_TimerObj != NULL); 421 ASSERT(pJS_TimerObj != NULL);
428 422
429 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); 423 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
430 ASSERT(pTimerObj != NULL); 424 ASSERT(pTimerObj != NULL);
(...skipping 24 matching lines...) Expand all
455 sError = 449 sError =
456 JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE); 450 JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
457 return TRUE; 451 return TRUE;
458 } 452 }
459 453
460 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000; 454 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
461 455
462 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); 456 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
463 ASSERT(pApp); 457 ASSERT(pApp);
464 458
465 CJS_Timer* pTimer = new CJS_Timer(this, pApp); 459 CJS_Timer* pTimer =
460 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut);
466 m_aTimer.Add(pTimer); 461 m_aTimer.Add(pTimer);
467 462
468 pTimer->SetType(1);
469 pTimer->SetRuntime(pRuntime);
470 pTimer->SetJScript(script);
471 pTimer->SetTimeOut(dwTimeOut);
472 pTimer->SetJSTimer(dwTimeOut);
473
474 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( 463 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
475 pRuntime->GetIsolate(), pContext, 464 pRuntime->GetIsolate(), pContext,
476 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")); 465 FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
477 466
478 CJS_TimerObj* pJS_TimerObj = 467 CJS_TimerObj* pJS_TimerObj =
479 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj); 468 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
480 ASSERT(pJS_TimerObj != NULL); 469 ASSERT(pJS_TimerObj != NULL);
481 470
482 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject(); 471 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
483 ASSERT(pTimerObj != NULL); 472 ASSERT(pTimerObj != NULL);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 FX_BOOL app::execMenuItem(IFXJS_Context* cc, 567 FX_BOOL app::execMenuItem(IFXJS_Context* cc,
579 const CJS_Parameters& params, 568 const CJS_Parameters& params,
580 CJS_Value& vRet, 569 CJS_Value& vRet,
581 CFX_WideString& sError) { 570 CFX_WideString& sError) {
582 return FALSE; 571 return FALSE;
583 } 572 }
584 573
585 void app::TimerProc(CJS_Timer* pTimer) { 574 void app::TimerProc(CJS_Timer* pTimer) {
586 ASSERT(pTimer != NULL); 575 ASSERT(pTimer != NULL);
587 576
577 CJS_Runtime* pRuntime = pTimer->GetRuntime();
578
588 switch (pTimer->GetType()) { 579 switch (pTimer->GetType()) {
589 case 0: // interval 580 case 0: // interval
590 RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript()); 581 if (pRuntime)
582 RunJsScript(pRuntime, pTimer->GetJScript());
591 break; 583 break;
592 case 1: 584 case 1:
593 if (pTimer->GetTimeOut() > 0) { 585 if (pTimer->GetTimeOut() > 0) {
594 RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript()); 586 if (pRuntime)
587 RunJsScript(pRuntime, pTimer->GetJScript());
595 pTimer->KillJSTimer(); 588 pTimer->KillJSTimer();
596 } 589 }
597 break; 590 break;
598 } 591 }
599 } 592 }
600 593
601 void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) { 594 void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
602 ASSERT(pRuntime != NULL); 595 ASSERT(pRuntime != NULL);
603 596
604 if (!pRuntime->IsBlocking()) { 597 if (!pRuntime->IsBlocking()) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 CFX_WideString& sError) { 847 CFX_WideString& sError) {
855 return FALSE; 848 return FALSE;
856 } 849 }
857 850
858 FX_BOOL app::execDialog(IFXJS_Context* cc, 851 FX_BOOL app::execDialog(IFXJS_Context* cc,
859 const CJS_Parameters& params, 852 const CJS_Parameters& params,
860 CJS_Value& vRet, 853 CJS_Value& vRet,
861 CFX_WideString& sError) { 854 CFX_WideString& sError) {
862 return TRUE; 855 return TRUE;
863 } 856 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Runtime.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698