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

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

Issue 1365503003: Merge to XFA: Use std::set<> to track active event handlers. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Blown merge. 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_Context.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 "../../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 18 matching lines...) Expand all
29 #include "../../include/fpdfxfa/fpdfxfa_app.h" 29 #include "../../include/fpdfxfa/fpdfxfa_app.h"
30 #include "../../../xfa/src/fxjse/src/value.h" 30 #include "../../../xfa/src/fxjse/src/value.h"
31 31
32 /* ------------------------------ CJS_Runtime ------------------------------ */ 32 /* ------------------------------ CJS_Runtime ------------------------------ */
33 v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(v8::Isolate* pIsolate); 33 v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(v8::Isolate* pIsolate);
34 34
35 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) 35 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
36 : m_pApp(pApp), 36 : m_pApp(pApp),
37 m_pDocument(NULL), 37 m_pDocument(NULL),
38 m_bBlocking(FALSE), 38 m_bBlocking(FALSE),
39 m_pFieldEventPath(NULL),
40 m_isolate(NULL), 39 m_isolate(NULL),
41 m_isolateManaged(false) { 40 m_isolateManaged(false) {
42 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { 41 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
43 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. 42 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate.
44 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime(); 43 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime();
45 } else if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { 44 } else if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
46 m_isolate = reinterpret_cast<v8::Isolate*>( 45 m_isolate = reinterpret_cast<v8::Isolate*>(
47 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); 46 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate);
48 } 47 }
49 if (!m_isolate) { 48 if (!m_isolate) {
(...skipping 27 matching lines...) Expand all
77 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); 76 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context);
78 ReleaseContext(pContext); 77 ReleaseContext(pContext);
79 } 78 }
80 79
81 CJS_Runtime::~CJS_Runtime() { 80 CJS_Runtime::~CJS_Runtime() {
82 int size = m_ContextArray.GetSize(); 81 int size = m_ContextArray.GetSize();
83 for (int i = 0; i < size; i++) 82 for (int i = 0; i < size; i++)
84 delete m_ContextArray.GetAt(i); 83 delete m_ContextArray.GetAt(i);
85 84
86 m_ContextArray.RemoveAll(); 85 m_ContextArray.RemoveAll();
87 RemoveEventsInLoop(m_pFieldEventPath);
88 86
89 m_pApp = NULL; 87 m_pApp = NULL;
90 m_pDocument = NULL; 88 m_pDocument = NULL;
91 m_pFieldEventPath = NULL;
92 m_context.Reset(); 89 m_context.Reset();
93 90
94 if (m_isolateManaged) 91 if (m_isolateManaged)
95 m_isolate->Dispose(); 92 m_isolate->Dispose();
96 m_isolate = NULL; 93 m_isolate = NULL;
97 } 94 }
98 95
99 void CJS_Runtime::DefineJSObjects() { 96 void CJS_Runtime::DefineJSObjects() {
100 v8::Isolate::Scope isolate_scope(GetIsolate()); 97 v8::Isolate::Scope isolate_scope(GetIsolate());
101 v8::Locker locker(GetIsolate()); 98 v8::Locker locker(GetIsolate());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { 184 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) {
188 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) 185 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject())
189 pDocument->AttachDoc(pReaderDoc); 186 pDocument->AttachDoc(pReaderDoc);
190 } 187 }
191 } 188 }
192 } 189 }
193 } 190 }
194 } 191 }
195 } 192 }
196 193
197 FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, 194 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) {
198 JS_EVENT_T eEventType) { 195 return m_FieldEventSet.insert(event).second;
199 if (m_pFieldEventPath == NULL) {
200 m_pFieldEventPath = new CJS_FieldEvent;
201 m_pFieldEventPath->sTargetName = sTargetName;
202 m_pFieldEventPath->eEventType = eEventType;
203 m_pFieldEventPath->pNext = NULL;
204
205 return TRUE;
206 }
207
208 // to search
209 CJS_FieldEvent* p = m_pFieldEventPath;
210 CJS_FieldEvent* pLast = m_pFieldEventPath;
211 while (p) {
212 if (p->eEventType == eEventType && p->sTargetName == sTargetName)
213 return FALSE;
214
215 pLast = p;
216 p = p->pNext;
217 }
218
219 // to add
220 CJS_FieldEvent* pNew = new CJS_FieldEvent;
221 pNew->sTargetName = sTargetName;
222 pNew->eEventType = eEventType;
223 pNew->pNext = NULL;
224
225 pLast->pNext = pNew;
226
227 return TRUE;
228 } 196 }
229 197
230 void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, 198 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) {
231 JS_EVENT_T eEventType) { 199 m_FieldEventSet.erase(event);
232 FX_BOOL bFind = FALSE;
233
234 CJS_FieldEvent* p = m_pFieldEventPath;
235 CJS_FieldEvent* pLast = NULL;
236 while (p) {
237 if (p->eEventType == eEventType && p->sTargetName == sTargetName) {
238 bFind = TRUE;
239 break;
240 }
241
242 pLast = p;
243 p = p->pNext;
244 }
245
246 if (bFind) {
247 RemoveEventsInLoop(p);
248
249 if (p == m_pFieldEventPath)
250 m_pFieldEventPath = NULL;
251
252 if (pLast)
253 pLast->pNext = NULL;
254 }
255 }
256
257 void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart) {
258 CJS_FieldEvent* p = pStart;
259
260 while (p) {
261 CJS_FieldEvent* pOld = p;
262 p = pOld->pNext;
263
264 delete pOld;
265 }
266 } 200 }
267 201
268 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { 202 v8::Local<v8::Context> CJS_Runtime::NewJSContext() {
269 return v8::Local<v8::Context>::New(m_isolate, m_context); 203 return v8::Local<v8::Context>::New(m_isolate, m_context);
270 } 204 }
271 205
272 CFX_WideString ChangeObjName(const CFX_WideString& str) { 206 CFX_WideString ChangeObjName(const CFX_WideString& str) {
273 CFX_WideString sRet = str; 207 CFX_WideString sRet = str;
274 sRet.Replace(L"_", L"."); 208 sRet.Replace(L"_", L".");
275 return sRet; 209 return sRet;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // v8::Local<v8::Context>::New(GetIsolate(), m_context); 250 // v8::Local<v8::Context>::New(GetIsolate(), m_context);
317 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New( 251 v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(
318 GetIsolate(), ((CFXJSE_Value*)hValue)->DirectGetValue()); 252 GetIsolate(), ((CFXJSE_Value*)hValue)->DirectGetValue());
319 context->Global()->Set( 253 context->Global()->Set(
320 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, 254 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString,
321 utf8Name.GetLength()), 255 utf8Name.GetLength()),
322 propvalue); 256 propvalue);
323 257
324 return TRUE; 258 return TRUE;
325 } 259 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Context.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698