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

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

Issue 1352393003: Use std::set<> to track active event handlers. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@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
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/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.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 15 matching lines...) Expand all
26 #include "../../include/javascript/JS_GlobalData.h" 26 #include "../../include/javascript/JS_GlobalData.h"
27 #include "../../include/javascript/global.h" 27 #include "../../include/javascript/global.h"
28 #include "../../include/javascript/console.h" 28 #include "../../include/javascript/console.h"
29 29
30 /* ------------------------------ CJS_Runtime ------------------------------ */ 30 /* ------------------------------ CJS_Runtime ------------------------------ */
31 31
32 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) 32 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
33 : m_pApp(pApp), 33 : m_pApp(pApp),
34 m_pDocument(NULL), 34 m_pDocument(NULL),
35 m_bBlocking(FALSE), 35 m_bBlocking(FALSE),
36 m_pFieldEventPath(NULL),
37 m_isolate(NULL), 36 m_isolate(NULL),
38 m_isolateManaged(false) { 37 m_isolateManaged(false) {
39 unsigned int embedderDataSlot = 0; 38 unsigned int embedderDataSlot = 0;
40 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { 39 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
41 m_isolate = reinterpret_cast<v8::Isolate*>( 40 m_isolate = reinterpret_cast<v8::Isolate*>(
42 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); 41 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate);
43 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; 42 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot;
44 } 43 }
45 if (!m_isolate) { 44 if (!m_isolate) {
46 m_pArrayBufferAllocator.reset(new FXJS_ArrayBufferAllocator()); 45 m_pArrayBufferAllocator.reset(new FXJS_ArrayBufferAllocator());
(...skipping 11 matching lines...) Expand all
58 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); 57 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context);
59 ReleaseContext(pContext); 58 ReleaseContext(pContext);
60 } 59 }
61 60
62 CJS_Runtime::~CJS_Runtime() { 61 CJS_Runtime::~CJS_Runtime() {
63 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) 62 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++)
64 delete m_ContextArray.GetAt(i); 63 delete m_ContextArray.GetAt(i);
65 64
66 m_ContextArray.RemoveAll(); 65 m_ContextArray.RemoveAll();
67 FXJS_ReleaseRuntime(GetIsolate(), m_context); 66 FXJS_ReleaseRuntime(GetIsolate(), m_context);
68 RemoveEventsInLoop(m_pFieldEventPath);
69 67
70 m_pApp = NULL; 68 m_pApp = NULL;
71 m_pDocument = NULL; 69 m_pDocument = NULL;
72 m_pFieldEventPath = NULL;
73 m_context.Reset(); 70 m_context.Reset();
74 71
75 if (m_isolateManaged) 72 if (m_isolateManaged)
76 m_isolate->Dispose(); 73 m_isolate->Dispose();
77 } 74 }
78 75
79 void CJS_Runtime::DefineJSObjects() { 76 void CJS_Runtime::DefineJSObjects() {
80 v8::Isolate::Scope isolate_scope(GetIsolate()); 77 v8::Isolate::Scope isolate_scope(GetIsolate());
81 v8::HandleScope handle_scope(GetIsolate()); 78 v8::HandleScope handle_scope(GetIsolate());
82 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); 79 v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { 162 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) {
166 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) 163 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject())
167 pDocument->AttachDoc(pReaderDoc); 164 pDocument->AttachDoc(pReaderDoc);
168 } 165 }
169 } 166 }
170 } 167 }
171 } 168 }
172 } 169 }
173 } 170 }
174 171
175 FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, 172 FX_BOOL CJS_Runtime::AddEventToSet(const FieldEvent& event) {
176 JS_EVENT_T eEventType) { 173 if (m_FieldEventSet.find(event) != m_FieldEventSet.end())
Lei Zhang 2015/09/22 22:20:50 Alternatively, you can skip this and just insert()
Tom Sepez 2015/09/22 22:32:46 Done.
177 if (m_pFieldEventPath == NULL) { 174 return FALSE;
178 m_pFieldEventPath = new CJS_FieldEvent;
179 m_pFieldEventPath->sTargetName = sTargetName;
180 m_pFieldEventPath->eEventType = eEventType;
181 m_pFieldEventPath->pNext = NULL;
182 175
183 return TRUE; 176 m_FieldEventSet.insert(event);
184 }
185
186 // to search
187 CJS_FieldEvent* p = m_pFieldEventPath;
188 CJS_FieldEvent* pLast = m_pFieldEventPath;
189 while (p) {
190 if (p->eEventType == eEventType && p->sTargetName == sTargetName)
191 return FALSE;
192
193 pLast = p;
194 p = p->pNext;
195 }
196
197 // to add
198 CJS_FieldEvent* pNew = new CJS_FieldEvent;
199 pNew->sTargetName = sTargetName;
200 pNew->eEventType = eEventType;
201 pNew->pNext = NULL;
202
203 pLast->pNext = pNew;
204
205 return TRUE; 177 return TRUE;
206 } 178 }
207 179
208 void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, 180 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) {
209 JS_EVENT_T eEventType) { 181 auto iter = m_FieldEventSet.find(event);
210 FX_BOOL bFind = FALSE; 182 if (iter != m_FieldEventSet.end())
211 183 m_FieldEventSet.erase(iter);
Lei Zhang 2015/09/22 22:20:50 Similarly, just erase |event| and it'll do a find(
Tom Sepez 2015/09/22 22:32:46 Done.
212 CJS_FieldEvent* p = m_pFieldEventPath;
213 CJS_FieldEvent* pLast = NULL;
214 while (p) {
215 if (p->eEventType == eEventType && p->sTargetName == sTargetName) {
216 bFind = TRUE;
217 break;
218 }
219
220 pLast = p;
221 p = p->pNext;
222 }
223
224 if (bFind) {
225 RemoveEventsInLoop(p);
226
227 if (p == m_pFieldEventPath)
228 m_pFieldEventPath = NULL;
229
230 if (pLast)
231 pLast->pNext = NULL;
232 }
233 }
234
235 void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart) {
236 CJS_FieldEvent* p = pStart;
237
238 while (p) {
239 CJS_FieldEvent* pOld = p;
240 p = pOld->pNext;
241
242 delete pOld;
243 }
244 } 184 }
245 185
246 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { 186 v8::Local<v8::Context> CJS_Runtime::NewJSContext() {
247 return v8::Local<v8::Context>::New(m_isolate, m_context); 187 return v8::Local<v8::Context>::New(m_isolate, m_context);
248 } 188 }
249 189
250 CFX_WideString ChangeObjName(const CFX_WideString& str) { 190 CFX_WideString ChangeObjName(const CFX_WideString& str) {
251 CFX_WideString sRet = str; 191 CFX_WideString sRet = str;
252 sRet.Replace(L"_", L"."); 192 sRet.Replace(L"_", L".");
253 return sRet; 193 return sRet;
254 } 194 }
OLDNEW
« fpdfsdk/include/javascript/JS_Runtime.h ('K') | « fpdfsdk/src/javascript/JS_Context.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698