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 "JS_Runtime.h" | 7 #include "JS_Runtime.h" |
8 | 8 |
9 #include "../../../xfa/src/fxjse/src/value.h" | 9 #include "../../../xfa/src/fxjse/src/value.h" |
10 #include "../../include/fpdfxfa/fpdfxfa_app.h" | 10 #include "../../include/fpdfxfa/fpdfxfa_app.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) | 39 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) |
40 : m_pApp(pApp), | 40 : m_pApp(pApp), |
41 m_pDocument(NULL), | 41 m_pDocument(NULL), |
42 m_bBlocking(FALSE), | 42 m_bBlocking(FALSE), |
43 m_isolate(NULL), | 43 m_isolate(NULL), |
44 m_isolateManaged(false) { | 44 m_isolateManaged(false) { |
45 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { | 45 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { |
46 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. | 46 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. |
47 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime(); | 47 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime(); |
48 } else if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { | 48 } else { |
49 m_isolate = reinterpret_cast<v8::Isolate*>( | 49 IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; |
50 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); | 50 if (pPlatform->version <= 2) { |
51 } | 51 unsigned int embedderDataSlot = 0; |
52 if (!m_isolate) { | 52 v8::Isolate* pExternalIsolate = nullptr; |
53 m_pArrayBufferAllocator.reset(new FXJS_ArrayBufferAllocator()); | 53 if (pPlatform->version == 2) { |
54 | 54 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); |
55 v8::Isolate::CreateParams params; | 55 embedderDataSlot = pPlatform->m_v8EmbedderSlot; |
56 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); | 56 } |
57 m_isolate = v8::Isolate::New(params); | 57 FXJS_Initialize(embedderDataSlot, pExternalIsolate); |
58 m_isolateManaged = true; | 58 } |
| 59 m_isolateManaged = FXJS_GetIsolate(&m_isolate); |
59 } | 60 } |
60 | 61 |
61 v8::Isolate* isolate = m_isolate; | 62 v8::Isolate* isolate = m_isolate; |
62 v8::Isolate::Scope isolate_scope(isolate); | 63 v8::Isolate::Scope isolate_scope(isolate); |
63 v8::Locker locker(isolate); | 64 v8::Locker locker(isolate); |
64 v8::HandleScope handle_scope(isolate); | 65 v8::HandleScope handle_scope(isolate); |
65 if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) { | 66 if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) { |
66 CJS_Context* pContext = (CJS_Context*)NewContext(); | 67 CJS_Context* pContext = (CJS_Context*)NewContext(); |
67 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); | 68 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); |
68 ReleaseContext(pContext); | 69 ReleaseContext(pContext); |
69 return; | 70 return; |
70 } | 71 } |
71 | 72 |
72 unsigned int embedderDataSlot = 0; | |
73 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) | |
74 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; | |
75 FXJS_Initialize(embedderDataSlot); | |
76 DefineJSObjects(); | 73 DefineJSObjects(); |
77 CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE); | 74 CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE); |
78 | 75 |
79 CJS_Context* pContext = (CJS_Context*)NewContext(); | 76 CJS_Context* pContext = (CJS_Context*)NewContext(); |
80 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); | 77 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); |
81 ReleaseContext(pContext); | 78 ReleaseContext(pContext); |
82 } | 79 } |
83 | 80 |
84 CJS_Runtime::~CJS_Runtime() { | 81 CJS_Runtime::~CJS_Runtime() { |
85 for (auto* obs : m_observers) | 82 for (auto* obs : m_observers) |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 263 |
267 void CJS_Runtime::AddObserver(Observer* observer) { | 264 void CJS_Runtime::AddObserver(Observer* observer) { |
268 ASSERT(m_observers.find(observer) == m_observers.end()); | 265 ASSERT(m_observers.find(observer) == m_observers.end()); |
269 m_observers.insert(observer); | 266 m_observers.insert(observer); |
270 } | 267 } |
271 | 268 |
272 void CJS_Runtime::RemoveObserver(Observer* observer) { | 269 void CJS_Runtime::RemoveObserver(Observer* observer) { |
273 ASSERT(m_observers.find(observer) != m_observers.end()); | 270 ASSERT(m_observers.find(observer) != m_observers.end()); |
274 m_observers.erase(observer); | 271 m_observers.erase(observer); |
275 } | 272 } |
OLD | NEW |