OLD | NEW |
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 22 matching lines...) Expand all Loading... |
33 | 33 |
34 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime
(CPDFDoc_Environment* pApp) | 34 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime
(CPDFDoc_Environment* pApp) |
35 { | 35 { |
36 if (!m_bInit) | 36 if (!m_bInit) |
37 { | 37 { |
38 unsigned int embedderDataSlot = 0; | 38 unsigned int embedderDataSlot = 0; |
39 if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { | 39 if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { |
40 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatfor
m->m_v8EmbedderSlot; | 40 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatfor
m->m_v8EmbedderSlot; |
41 } | 41 } |
42 JS_Initial(embedderDataSlot); | 42 JS_Initial(embedderDataSlot); |
43 » » m_bInit = TRUE; | 43 » » m_bInit = true; |
44 } | 44 } |
45 return new CJS_Runtime(pApp); | 45 return new CJS_Runtime(pApp); |
46 } | 46 } |
47 void CJS_RuntimeFactory::AddR
ef() | 47 void CJS_RuntimeFactory::AddR
ef() |
48 { | 48 { |
49 //to do.Should be implemented as atom manipulation. | 49 //to do.Should be implemented as atom manipulation. |
50 m_nRef++; | 50 m_nRef++; |
51 } | 51 } |
52 void CJS_RuntimeFactory::Rele
ase() | 52 void CJS_RuntimeFactory::Rele
ase() |
53 { | 53 { |
54 if(m_bInit) | 54 if(m_bInit) |
55 { | 55 { |
56 //to do.Should be implemented as atom manipulation. | 56 //to do.Should be implemented as atom manipulation. |
57 if (--m_nRef == 0) | 57 if (--m_nRef == 0) |
58 { | 58 { |
59 JS_Release(); | 59 JS_Release(); |
60 ReleaseGlobalData(); | 60 ReleaseGlobalData(); |
61 » » » m_bInit = FALSE; | 61 » » » m_bInit = false; |
62 } | 62 } |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 void CJS_RuntimeFactory::Dele
teJSRuntime(IFXJS_Runtime* pRuntime) | 66 void CJS_RuntimeFactory::Dele
teJSRuntime(IFXJS_Runtime* pRuntime) |
67 { | 67 { |
68 delete (CJS_Runtime*)pRuntime; | 68 delete (CJS_Runtime*)pRuntime; |
69 } | 69 } |
70 | 70 |
71 CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp) | 71 CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { | 105 void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { |
106 free(data); | 106 free(data); |
107 } | 107 } |
108 | 108 |
109 /* ------------------------------ CJS_Runtime ------------------------------ */ | 109 /* ------------------------------ CJS_Runtime ------------------------------ */ |
110 | 110 |
111 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) : | 111 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) : |
112 m_pApp(pApp), | 112 m_pApp(pApp), |
113 m_pDocument(NULL), | 113 m_pDocument(NULL), |
114 » m_bBlocking(FALSE), | 114 » m_bBlocking(false), |
115 » m_bRegistered(FALSE), | 115 » m_bRegistered(false), |
116 m_pFieldEventPath(NULL), | 116 m_pFieldEventPath(NULL), |
117 m_isolate(NULL) | 117 m_isolate(NULL) |
118 { | 118 { |
119 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { | 119 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { |
120 m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillIn
fo()->m_pJsPlatform->m_isolate); | 120 m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillIn
fo()->m_pJsPlatform->m_isolate); |
121 } | 121 } |
122 if (!m_isolate) { | 122 if (!m_isolate) { |
123 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); | 123 m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); |
124 | 124 |
125 v8::Isolate::CreateParams params; | 125 v8::Isolate::CreateParams params; |
(...skipping 21 matching lines...) Expand all Loading... |
147 | 147 |
148 m_pApp = NULL; | 148 m_pApp = NULL; |
149 m_pDocument = NULL; | 149 m_pDocument = NULL; |
150 m_pFieldEventPath = NULL; | 150 m_pFieldEventPath = NULL; |
151 m_context.Reset(); | 151 m_context.Reset(); |
152 | 152 |
153 //m_isolate->Exit(); | 153 //m_isolate->Exit(); |
154 m_isolate->Dispose(); | 154 m_isolate->Dispose(); |
155 } | 155 } |
156 | 156 |
157 FX_BOOL CJS_Runtime::InitJSObjects() | 157 bool CJS_Runtime::InitJSObjects() |
158 { | 158 { |
159 v8::Isolate::Scope isolate_scope(GetIsolate()); | 159 v8::Isolate::Scope isolate_scope(GetIsolate()); |
160 v8::HandleScope handle_scope(GetIsolate()); | 160 v8::HandleScope handle_scope(GetIsolate()); |
161 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); | 161 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); |
162 v8::Context::Scope context_scope(context); | 162 v8::Context::Scope context_scope(context); |
163 //0 - 8 | 163 //0 - 8 |
164 » if (CJS_Border::Init(*this, JS_STATIC) < 0) return FALSE; | 164 » if (CJS_Border::Init(*this, JS_STATIC) < 0) return false; |
165 » if (CJS_Display::Init(*this, JS_STATIC) < 0) return FALSE; | 165 » if (CJS_Display::Init(*this, JS_STATIC) < 0) return false; |
166 » if (CJS_Font::Init(*this, JS_STATIC) < 0) return FALSE; | 166 » if (CJS_Font::Init(*this, JS_STATIC) < 0) return false; |
167 » if (CJS_Highlight::Init(*this, JS_STATIC) < 0) return FALSE; | 167 » if (CJS_Highlight::Init(*this, JS_STATIC) < 0) return false; |
168 » if (CJS_Position::Init(*this, JS_STATIC) < 0) return FALSE; | 168 » if (CJS_Position::Init(*this, JS_STATIC) < 0) return false; |
169 » if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) return FALSE; | 169 » if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) return false; |
170 » if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) return FALSE; | 170 » if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) return false; |
171 » if (CJS_Style::Init(*this, JS_STATIC) < 0) return FALSE; | 171 » if (CJS_Style::Init(*this, JS_STATIC) < 0) return false; |
172 » if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) return FALSE; | 172 » if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) return false; |
173 | 173 |
174 //9 - 11 | 174 //9 - 11 |
175 » if (CJS_App::Init(*this, JS_STATIC) < 0) return FALSE; | 175 » if (CJS_App::Init(*this, JS_STATIC) < 0) return false; |
176 » if (CJS_Color::Init(*this, JS_STATIC) < 0) return FALSE; | 176 » if (CJS_Color::Init(*this, JS_STATIC) < 0) return false; |
177 » if (CJS_Console::Init(*this, JS_STATIC) < 0) return FALSE; | 177 » if (CJS_Console::Init(*this, JS_STATIC) < 0) return false; |
178 | 178 |
179 //12 - 14 | 179 //12 - 14 |
180 » if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) return FALSE; | 180 » if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) return false; |
181 » if (CJS_Event::Init(*this, JS_STATIC) < 0) return FALSE; | 181 » if (CJS_Event::Init(*this, JS_STATIC) < 0) return false; |
182 » if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) return FALSE; | 182 » if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) return false; |
183 | 183 |
184 //15 - 17 | 184 //15 - 17 |
185 » if (CJS_Global::Init(*this, JS_STATIC) < 0) return FALSE; | 185 » if (CJS_Global::Init(*this, JS_STATIC) < 0) return false; |
186 » if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) return FALSE; | 186 » if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) return false; |
187 » if (CJS_Util::Init(*this, JS_STATIC) < 0) return FALSE; | 187 » if (CJS_Util::Init(*this, JS_STATIC) < 0) return false; |
188 | 188 |
189 » if (CJS_PublicMethods::Init(*this) < 0) return FALSE; | 189 » if (CJS_PublicMethods::Init(*this) < 0) return false; |
190 » if (CJS_GlobalConsts::Init(*this) < 0) return FALSE; | 190 » if (CJS_GlobalConsts::Init(*this) < 0) return false; |
191 » if (CJS_GlobalArrays::Init(*this) < 0) return FALSE; | 191 » if (CJS_GlobalArrays::Init(*this) < 0) return false; |
192 | 192 |
193 » if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) return FALSE; | 193 » if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) return false; |
194 » if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) <0) return FALSE; | 194 » if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) <0) return false; |
195 | 195 |
196 » return TRUE; | 196 » return true; |
197 } | 197 } |
198 | 198 |
199 IFXJS_Context* CJS_Runtime::NewContext() | 199 IFXJS_Context* CJS_Runtime::NewContext() |
200 { | 200 { |
201 CJS_Context * p = new CJS_Context(this); | 201 CJS_Context * p = new CJS_Context(this); |
202 m_ContextArray.Add(p); | 202 m_ContextArray.Add(p); |
203 return p; | 203 return p; |
204 } | 204 } |
205 | 205 |
206 void CJS_Runtime::ReleaseContext(IFXJS_Context * pContext) | 206 void CJS_Runtime::ReleaseContext(IFXJS_Context * pContext) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 252 } |
253 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document")
); | 253 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document")
); |
254 } | 254 } |
255 else | 255 else |
256 { | 256 { |
257 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app")); | 257 JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app")); |
258 } | 258 } |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 FX_BOOL»CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_
T eEventType) | 262 bool» CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_
T eEventType) |
263 { | 263 { |
264 if (m_pFieldEventPath == NULL) | 264 if (m_pFieldEventPath == NULL) |
265 { | 265 { |
266 m_pFieldEventPath = new CJS_FieldEvent; | 266 m_pFieldEventPath = new CJS_FieldEvent; |
267 m_pFieldEventPath->sTargetName = sTargetName; | 267 m_pFieldEventPath->sTargetName = sTargetName; |
268 m_pFieldEventPath->eEventType = eEventType; | 268 m_pFieldEventPath->eEventType = eEventType; |
269 m_pFieldEventPath->pNext = NULL; | 269 m_pFieldEventPath->pNext = NULL; |
270 | 270 |
271 » » return TRUE; | 271 » » return true; |
272 } | 272 } |
273 | 273 |
274 //to search | 274 //to search |
275 CJS_FieldEvent* p = m_pFieldEventPath; | 275 CJS_FieldEvent* p = m_pFieldEventPath; |
276 CJS_FieldEvent* pLast = m_pFieldEventPath; | 276 CJS_FieldEvent* pLast = m_pFieldEventPath; |
277 while (p) | 277 while (p) |
278 { | 278 { |
279 if (p->eEventType == eEventType && p->sTargetName == sTargetName
) | 279 if (p->eEventType == eEventType && p->sTargetName == sTargetName
) |
280 » » » return FALSE; | 280 » » » return false; |
281 | 281 |
282 pLast = p; | 282 pLast = p; |
283 p = p->pNext; | 283 p = p->pNext; |
284 } | 284 } |
285 | 285 |
286 //to add | 286 //to add |
287 CJS_FieldEvent* pNew = new CJS_FieldEvent; | 287 CJS_FieldEvent* pNew = new CJS_FieldEvent; |
288 pNew->sTargetName = sTargetName; | 288 pNew->sTargetName = sTargetName; |
289 pNew->eEventType = eEventType; | 289 pNew->eEventType = eEventType; |
290 pNew->pNext = NULL; | 290 pNew->pNext = NULL; |
291 | 291 |
292 pLast->pNext = pNew; | 292 pLast->pNext = pNew; |
293 | 293 |
294 » return TRUE; | 294 » return true; |
295 } | 295 } |
296 | 296 |
297 void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_
T eEventType) | 297 void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_
T eEventType) |
298 { | 298 { |
299 » FX_BOOL bFind = FALSE; | 299 » bool bFind = false; |
300 | 300 |
301 CJS_FieldEvent* p = m_pFieldEventPath; | 301 CJS_FieldEvent* p = m_pFieldEventPath; |
302 CJS_FieldEvent* pLast = NULL; | 302 CJS_FieldEvent* pLast = NULL; |
303 while (p) | 303 while (p) |
304 { | 304 { |
305 if (p->eEventType == eEventType && p->sTargetName == sTargetName
) | 305 if (p->eEventType == eEventType && p->sTargetName == sTargetName
) |
306 { | 306 { |
307 » » » bFind = TRUE; | 307 » » » bFind = true; |
308 break; | 308 break; |
309 } | 309 } |
310 | 310 |
311 pLast = p; | 311 pLast = p; |
312 p = p->pNext; | 312 p = p->pNext; |
313 } | 313 } |
314 | 314 |
315 if (bFind) | 315 if (bFind) |
316 { | 316 { |
317 RemoveEventsInLoop(p); | 317 RemoveEventsInLoop(p); |
(...skipping 23 matching lines...) Expand all Loading... |
341 { | 341 { |
342 return v8::Local<v8::Context>::New(m_isolate, m_context); | 342 return v8::Local<v8::Context>::New(m_isolate, m_context); |
343 } | 343 } |
344 | 344 |
345 CFX_WideString ChangeObjName(const CFX_WideString& str) | 345 CFX_WideString ChangeObjName(const CFX_WideString& str) |
346 { | 346 { |
347 CFX_WideString sRet = str; | 347 CFX_WideString sRet = str; |
348 sRet.Replace(L"_", L"."); | 348 sRet.Replace(L"_", L"."); |
349 return sRet; | 349 return sRet; |
350 } | 350 } |
OLD | NEW |