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

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

Issue 1352393003: Use std::set<> to track active event handlers. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Simpler set manipulations Created 5 years, 3 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/include/javascript/JS_Runtime.h ('k') | fpdfsdk/src/javascript/JS_Runtime.cpp » ('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 "../../include/javascript/IJavaScript.h" 7 #include "../../include/javascript/IJavaScript.h"
8 #include "../../include/javascript/JS_Context.h" 8 #include "../../include/javascript/JS_Context.h"
9 #include "../../include/javascript/JS_EventHandler.h" 9 #include "../../include/javascript/JS_EventHandler.h"
10 #include "../../include/javascript/JS_Runtime.h" 10 #include "../../include/javascript/JS_Runtime.h"
(...skipping 28 matching lines...) Expand all
39 v8::Local<v8::Context> context = m_pRuntime->NewJSContext(); 39 v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
40 v8::Context::Scope context_scope(context); 40 v8::Context::Scope context_scope(context);
41 41
42 if (m_bBusy) { 42 if (m_bBusy) {
43 info = JSGetStringFromID(this, IDS_STRING_JSBUSY); 43 info = JSGetStringFromID(this, IDS_STRING_JSBUSY);
44 return FALSE; 44 return FALSE;
45 } 45 }
46 m_bBusy = TRUE; 46 m_bBusy = TRUE;
47 47
48 ASSERT(m_pEventHandler->IsValid()); 48 ASSERT(m_pEventHandler->IsValid());
49 if (!m_pRuntime->AddEventToLoop(m_pEventHandler->TargetName(), 49 CJS_Runtime::FieldEvent event(m_pEventHandler->TargetName(),
50 m_pEventHandler->EventType())) { 50 m_pEventHandler->EventType());
51 if (!m_pRuntime->AddEventToSet(event)) {
51 info = JSGetStringFromID(this, IDS_STRING_JSEVENT); 52 info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
52 return FALSE; 53 return FALSE;
53 } 54 }
54 55
55 FXJSErr error = {NULL, NULL, 0}; 56 FXJSErr error = {NULL, NULL, 0};
56 int nRet = 0; 57 int nRet = 0;
57 if (script.GetLength() > 0) { 58 if (script.GetLength() > 0) {
58 nRet = FXJS_Execute(m_pRuntime->GetIsolate(), this, script.c_str(), 59 nRet = FXJS_Execute(m_pRuntime->GetIsolate(), this, script.c_str(),
59 script.GetLength(), &error); 60 script.GetLength(), &error);
60 } 61 }
61 62
62 if (nRet < 0) { 63 if (nRet < 0) {
63 CFX_WideString sLine; 64 CFX_WideString sLine;
64 sLine.Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline, 65 sLine.Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline,
65 error.message); 66 error.message);
66 info += sLine; 67 info += sLine;
67 } else { 68 } else {
68 info = JSGetStringFromID(this, IDS_STRING_RUN); 69 info = JSGetStringFromID(this, IDS_STRING_RUN);
69 } 70 }
70 71
71 m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(), 72 m_pRuntime->RemoveEventFromSet(event);
72 m_pEventHandler->EventType());
73
74 m_pEventHandler->Destroy(); 73 m_pEventHandler->Destroy();
75 m_bBusy = FALSE; 74 m_bBusy = FALSE;
76 75
77 return nRet >= 0; 76 return nRet >= 0;
78 } 77 }
79 78
80 void CJS_Context::OnApp_Init() { 79 void CJS_Context::OnApp_Init() {
81 m_pEventHandler->OnApp_Init(); 80 m_pEventHandler->OnApp_Init();
82 } 81 }
83 82
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 278 }
280 279
281 void CJS_Context::OnBatchExec(CPDFSDK_Document* pTarget) { 280 void CJS_Context::OnBatchExec(CPDFSDK_Document* pTarget) {
282 m_pEventHandler->OnBatchExec(pTarget); 281 m_pEventHandler->OnBatchExec(pTarget);
283 } 282 }
284 283
285 void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget, 284 void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget,
286 const CFX_WideString& strTargetName) { 285 const CFX_WideString& strTargetName) {
287 m_pEventHandler->OnMenu_Exec(pTarget, strTargetName); 286 m_pEventHandler->OnMenu_Exec(pTarget, strTargetName);
288 } 287 }
OLDNEW
« no previous file with comments | « fpdfsdk/include/javascript/JS_Runtime.h ('k') | fpdfsdk/src/javascript/JS_Runtime.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698