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

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

Issue 2262473002: Introduce pdfium::FakeUniquePtr for keys to sets of unique ptrs. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Poiner is spelt with a "t" Created 4 years, 4 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/javascript/app.h ('k') | third_party/base/stl_util.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 "fpdfsdk/javascript/app.h" 7 #include "fpdfsdk/javascript/app.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "fpdfsdk/include/cpdfsdk_interform.h" 12 #include "fpdfsdk/include/cpdfsdk_interform.h"
13 #include "fpdfsdk/include/fsdk_mgr.h" 13 #include "fpdfsdk/include/fsdk_mgr.h"
14 #include "fpdfsdk/javascript/Document.h" 14 #include "fpdfsdk/javascript/Document.h"
15 #include "fpdfsdk/javascript/JS_Define.h" 15 #include "fpdfsdk/javascript/JS_Define.h"
16 #include "fpdfsdk/javascript/JS_EventHandler.h" 16 #include "fpdfsdk/javascript/JS_EventHandler.h"
17 #include "fpdfsdk/javascript/JS_Object.h" 17 #include "fpdfsdk/javascript/JS_Object.h"
18 #include "fpdfsdk/javascript/JS_Value.h" 18 #include "fpdfsdk/javascript/JS_Value.h"
19 #include "fpdfsdk/javascript/cjs_context.h" 19 #include "fpdfsdk/javascript/cjs_context.h"
20 #include "fpdfsdk/javascript/cjs_runtime.h" 20 #include "fpdfsdk/javascript/cjs_runtime.h"
21 #include "fpdfsdk/javascript/resource.h" 21 #include "fpdfsdk/javascript/resource.h"
22 #include "third_party/base/stl_util.h"
22 23
23 class GlobalTimer : public CJS_Runtime::Observer { 24 class GlobalTimer : public CJS_Runtime::Observer {
24 public: 25 public:
25 GlobalTimer(app* pObj, 26 GlobalTimer(app* pObj,
26 CPDFDoc_Environment* pApp, 27 CPDFDoc_Environment* pApp,
27 CJS_Runtime* pRuntime, 28 CJS_Runtime* pRuntime,
28 int nType, 29 int nType,
29 const CFX_WideString& script, 30 const CFX_WideString& script,
30 uint32_t dwElapse, 31 uint32_t dwElapse,
31 uint32_t dwTimeOut); 32 uint32_t dwTimeOut);
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 CFX_WideString script = 504 CFX_WideString script =
504 params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L""; 505 params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L"";
505 if (script.IsEmpty()) { 506 if (script.IsEmpty()) {
506 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); 507 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
507 return TRUE; 508 return TRUE;
508 } 509 }
509 510
510 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; 511 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
511 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); 512 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
512 513
513 std::unique_ptr<GlobalTimer> timer( 514 GlobalTimer* timerRef =
514 new GlobalTimer(this, pApp, pRuntime, 0, script, dwInterval, 0)); 515 new GlobalTimer(this, pApp, pRuntime, 0, script, dwInterval, 0);
515 GlobalTimer* timerRef = timer.get(); 516 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
516 m_Timers[timerRef] = std::move(timer);
517 517
518 v8::Local<v8::Object> pRetObj = 518 v8::Local<v8::Object> pRetObj =
519 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); 519 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
520 CJS_TimerObj* pJS_TimerObj = 520 CJS_TimerObj* pJS_TimerObj =
521 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); 521 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
522 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); 522 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
523 pTimerObj->SetTimer(timerRef); 523 pTimerObj->SetTimer(timerRef);
524 524
525 vRet = CJS_Value(pRuntime, pRetObj); 525 vRet = CJS_Value(pRuntime, pRetObj);
526 return TRUE; 526 return TRUE;
(...skipping 13 matching lines...) Expand all
540 540
541 CFX_WideString script = params[0].ToCFXWideString(pRuntime); 541 CFX_WideString script = params[0].ToCFXWideString(pRuntime);
542 if (script.IsEmpty()) { 542 if (script.IsEmpty()) {
543 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); 543 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
544 return TRUE; 544 return TRUE;
545 } 545 }
546 546
547 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; 547 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
548 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); 548 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
549 549
550 std::unique_ptr<GlobalTimer> timer( 550 GlobalTimer* timerRef =
551 new GlobalTimer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut)); 551 new GlobalTimer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut);
552 GlobalTimer* timerRef = timer.get(); 552 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
553 m_Timers[timerRef] = std::move(timer);
554 553
555 v8::Local<v8::Object> pRetObj = 554 v8::Local<v8::Object> pRetObj =
556 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); 555 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
557 556
558 CJS_TimerObj* pJS_TimerObj = 557 CJS_TimerObj* pJS_TimerObj =
559 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); 558 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
560 559
561 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); 560 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
562 pTimerObj->SetTimer(timerRef); 561 pTimerObj->SetTimer(timerRef);
563 562
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 return FALSE; 618 return FALSE;
620 } 619 }
621 620
622 void app::TimerProc(GlobalTimer* pTimer) { 621 void app::TimerProc(GlobalTimer* pTimer) {
623 CJS_Runtime* pRuntime = pTimer->GetRuntime(); 622 CJS_Runtime* pRuntime = pTimer->GetRuntime();
624 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0)) 623 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0))
625 RunJsScript(pRuntime, pTimer->GetJScript()); 624 RunJsScript(pRuntime, pTimer->GetJScript());
626 } 625 }
627 626
628 void app::CancelProc(GlobalTimer* pTimer) { 627 void app::CancelProc(GlobalTimer* pTimer) {
629 m_Timers.erase(pTimer); 628 m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer));
630 } 629 }
631 630
632 void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) { 631 void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
633 if (!pRuntime->IsBlocking()) { 632 if (!pRuntime->IsBlocking()) {
634 IJS_Context* pContext = pRuntime->NewContext(); 633 IJS_Context* pContext = pRuntime->NewContext();
635 pContext->OnExternal_Exec(); 634 pContext->OnExternal_Exec();
636 CFX_WideString wtInfo; 635 CFX_WideString wtInfo;
637 pContext->RunScript(wsScript, &wtInfo); 636 pContext->RunScript(wsScript, &wtInfo);
638 pRuntime->ReleaseContext(pContext); 637 pRuntime->ReleaseContext(pContext);
639 } 638 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { 833 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
835 return FALSE; 834 return FALSE;
836 } 835 }
837 836
838 FX_BOOL app::execDialog(IJS_Context* cc, 837 FX_BOOL app::execDialog(IJS_Context* cc,
839 const std::vector<CJS_Value>& params, 838 const std::vector<CJS_Value>& params,
840 CJS_Value& vRet, 839 CJS_Value& vRet,
841 CFX_WideString& sError) { 840 CFX_WideString& sError) {
842 return TRUE; 841 return TRUE;
843 } 842 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/app.h ('k') | third_party/base/stl_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698