| 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 21 matching lines...) Expand all Loading... |
| 32 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp) { | 32 IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp) { |
| 33 m_bInit = true; | 33 m_bInit = true; |
| 34 return new CJS_Runtime(pApp); | 34 return new CJS_Runtime(pApp); |
| 35 } | 35 } |
| 36 void CJS_RuntimeFactory::AddRef() { | 36 void CJS_RuntimeFactory::AddRef() { |
| 37 m_nRef++; | 37 m_nRef++; |
| 38 } | 38 } |
| 39 void CJS_RuntimeFactory::Release() { | 39 void CJS_RuntimeFactory::Release() { |
| 40 if (m_bInit) { | 40 if (m_bInit) { |
| 41 if (--m_nRef == 0) { | 41 if (--m_nRef == 0) { |
| 42 JS_Release(); | 42 FXJS_Release(); |
| 43 m_bInit = FALSE; | 43 m_bInit = FALSE; |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) { | 48 void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) { |
| 49 delete (CJS_Runtime*)pRuntime; | 49 delete (CJS_Runtime*)pRuntime; |
| 50 } | 50 } |
| 51 | 51 |
| 52 /* ------------------------------ CJS_Runtime ------------------------------ */ | 52 /* ------------------------------ CJS_Runtime ------------------------------ */ |
| 53 | 53 |
| 54 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) | 54 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) |
| 55 : m_pApp(pApp), | 55 : m_pApp(pApp), |
| 56 m_pDocument(NULL), | 56 m_pDocument(NULL), |
| 57 m_bBlocking(FALSE), | 57 m_bBlocking(FALSE), |
| 58 m_pFieldEventPath(NULL), | 58 m_pFieldEventPath(NULL), |
| 59 m_isolate(NULL), | 59 m_isolate(NULL), |
| 60 m_isolateManaged(false) { | 60 m_isolateManaged(false) { |
| 61 unsigned int embedderDataSlot = 0; | 61 unsigned int embedderDataSlot = 0; |
| 62 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { | 62 if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { |
| 63 m_isolate = reinterpret_cast<v8::Isolate*>( | 63 m_isolate = reinterpret_cast<v8::Isolate*>( |
| 64 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); | 64 m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); |
| 65 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; | 65 embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; |
| 66 } | 66 } |
| 67 if (!m_isolate) { | 67 if (!m_isolate) { |
| 68 m_pArrayBufferAllocator.reset(new JS_ArrayBufferAllocator()); | 68 m_pArrayBufferAllocator.reset(new FXJS_ArrayBufferAllocator()); |
| 69 | 69 |
| 70 v8::Isolate::CreateParams params; | 70 v8::Isolate::CreateParams params; |
| 71 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); | 71 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); |
| 72 m_isolate = v8::Isolate::New(params); | 72 m_isolate = v8::Isolate::New(params); |
| 73 m_isolateManaged = true; | 73 m_isolateManaged = true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 JS_Initialize(embedderDataSlot); | 76 FXJS_Initialize(embedderDataSlot); |
| 77 DefineJSObjects(); | 77 DefineJSObjects(); |
| 78 | 78 |
| 79 CJS_Context* pContext = (CJS_Context*)NewContext(); | 79 CJS_Context* pContext = (CJS_Context*)NewContext(); |
| 80 JS_InitializeRuntime(GetIsolate(), this, pContext, m_context); | 80 FXJS_InitializeRuntime(GetIsolate(), this, pContext, m_context); |
| 81 ReleaseContext(pContext); | 81 ReleaseContext(pContext); |
| 82 } | 82 } |
| 83 | 83 |
| 84 CJS_Runtime::~CJS_Runtime() { | 84 CJS_Runtime::~CJS_Runtime() { |
| 85 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) | 85 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) |
| 86 delete m_ContextArray.GetAt(i); | 86 delete m_ContextArray.GetAt(i); |
| 87 | 87 |
| 88 m_ContextArray.RemoveAll(); | 88 m_ContextArray.RemoveAll(); |
| 89 JS_ReleaseRuntime(GetIsolate(), m_context); | 89 FXJS_ReleaseRuntime(GetIsolate(), m_context); |
| 90 RemoveEventsInLoop(m_pFieldEventPath); | 90 RemoveEventsInLoop(m_pFieldEventPath); |
| 91 | 91 |
| 92 m_pApp = NULL; | 92 m_pApp = NULL; |
| 93 m_pDocument = NULL; | 93 m_pDocument = NULL; |
| 94 m_pFieldEventPath = NULL; | 94 m_pFieldEventPath = NULL; |
| 95 m_context.Reset(); | 95 m_context.Reset(); |
| 96 | 96 |
| 97 if (m_isolateManaged) | 97 if (m_isolateManaged) |
| 98 m_isolate->Dispose(); | 98 m_isolate->Dispose(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void CJS_Runtime::DefineJSObjects() { | 101 void CJS_Runtime::DefineJSObjects() { |
| 102 v8::Isolate::Scope isolate_scope(GetIsolate()); | 102 v8::Isolate::Scope isolate_scope(GetIsolate()); |
| 103 v8::HandleScope handle_scope(GetIsolate()); | 103 v8::HandleScope handle_scope(GetIsolate()); |
| 104 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); | 104 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); |
| 105 v8::Context::Scope context_scope(context); | 105 v8::Context::Scope context_scope(context); |
| 106 | 106 |
| 107 // The call order determines the "ObjDefID" assigned to each class. | 107 // The call order determines the "ObjDefID" assigned to each class. |
| 108 // ObjDefIDs 0 - 2 | 108 // ObjDefIDs 0 - 2 |
| 109 CJS_Border::DefineJSObjects(GetIsolate(), JS_STATIC); | 109 CJS_Border::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 110 CJS_Display::DefineJSObjects(GetIsolate(), JS_STATIC); | 110 CJS_Display::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 111 CJS_Font::DefineJSObjects(GetIsolate(), JS_STATIC); | 111 CJS_Font::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 112 | 112 |
| 113 // ObjDefIDs 3 - 5 | 113 // ObjDefIDs 3 - 5 |
| 114 CJS_Highlight::DefineJSObjects(GetIsolate(), JS_STATIC); | 114 CJS_Highlight::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 115 CJS_Position::DefineJSObjects(GetIsolate(), JS_STATIC); | 115 CJS_Position::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 116 CJS_ScaleHow::DefineJSObjects(GetIsolate(), JS_STATIC); | 116 CJS_ScaleHow::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 117 | 117 |
| 118 // ObjDefIDs 6 - 8 | 118 // ObjDefIDs 6 - 8 |
| 119 CJS_ScaleWhen::DefineJSObjects(GetIsolate(), JS_STATIC); | 119 CJS_ScaleWhen::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 120 CJS_Style::DefineJSObjects(GetIsolate(), JS_STATIC); | 120 CJS_Style::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 121 CJS_Zoomtype::DefineJSObjects(GetIsolate(), JS_STATIC); | 121 CJS_Zoomtype::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 122 | 122 |
| 123 // ObjDefIDs 9 - 11 | 123 // ObjDefIDs 9 - 11 |
| 124 CJS_App::DefineJSObjects(GetIsolate(), JS_STATIC); | 124 CJS_App::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 125 CJS_Color::DefineJSObjects(GetIsolate(), JS_STATIC); | 125 CJS_Color::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 126 CJS_Console::DefineJSObjects(GetIsolate(), JS_STATIC); | 126 CJS_Console::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 127 | 127 |
| 128 // ObjDefIDs 12 - 14 | 128 // ObjDefIDs 12 - 14 |
| 129 CJS_Document::DefineJSObjects(GetIsolate(), JS_DYNAMIC); | 129 CJS_Document::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC); |
| 130 CJS_Event::DefineJSObjects(GetIsolate(), JS_STATIC); | 130 CJS_Event::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 131 CJS_Field::DefineJSObjects(GetIsolate(), JS_DYNAMIC); | 131 CJS_Field::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC); |
| 132 | 132 |
| 133 // ObjDefIDs 15 - 17 | 133 // ObjDefIDs 15 - 17 |
| 134 CJS_Global::DefineJSObjects(GetIsolate(), JS_STATIC); | 134 CJS_Global::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 135 CJS_Icon::DefineJSObjects(GetIsolate(), JS_DYNAMIC); | 135 CJS_Icon::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC); |
| 136 CJS_Util::DefineJSObjects(GetIsolate(), JS_STATIC); | 136 CJS_Util::DefineJSObjects(GetIsolate(), FXJS_STATIC); |
| 137 | 137 |
| 138 // ObjDefIDs 18 - 20 (these can't fail, return void). | 138 // ObjDefIDs 18 - 20 (these can't fail, return void). |
| 139 CJS_PublicMethods::DefineJSObjects(GetIsolate()); | 139 CJS_PublicMethods::DefineJSObjects(GetIsolate()); |
| 140 CJS_GlobalConsts::DefineJSObjects(GetIsolate()); | 140 CJS_GlobalConsts::DefineJSObjects(GetIsolate()); |
| 141 CJS_GlobalArrays::DefineJSObjects(GetIsolate()); | 141 CJS_GlobalArrays::DefineJSObjects(GetIsolate()); |
| 142 | 142 |
| 143 // ObjDefIDs 21 - 22. | 143 // ObjDefIDs 21 - 22. |
| 144 CJS_TimerObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC); | 144 CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC); |
| 145 CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC); | 145 CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC); |
| 146 } | 146 } |
| 147 | 147 |
| 148 IFXJS_Context* CJS_Runtime::NewContext() { | 148 IFXJS_Context* CJS_Runtime::NewContext() { |
| 149 CJS_Context* p = new CJS_Context(this); | 149 CJS_Context* p = new CJS_Context(this); |
| 150 m_ContextArray.Add(p); | 150 m_ContextArray.Add(p); |
| 151 return p; | 151 return p; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void CJS_Runtime::ReleaseContext(IFXJS_Context* pContext) { | 154 void CJS_Runtime::ReleaseContext(IFXJS_Context* pContext) { |
| 155 CJS_Context* pJSContext = (CJS_Context*)pContext; | 155 CJS_Context* pJSContext = (CJS_Context*)pContext; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 172 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { | 172 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { |
| 173 if (m_pDocument != pReaderDoc) { | 173 if (m_pDocument != pReaderDoc) { |
| 174 v8::Isolate::Scope isolate_scope(m_isolate); | 174 v8::Isolate::Scope isolate_scope(m_isolate); |
| 175 v8::HandleScope handle_scope(m_isolate); | 175 v8::HandleScope handle_scope(m_isolate); |
| 176 v8::Local<v8::Context> context = | 176 v8::Local<v8::Context> context = |
| 177 v8::Local<v8::Context>::New(m_isolate, m_context); | 177 v8::Local<v8::Context>::New(m_isolate, m_context); |
| 178 v8::Context::Scope context_scope(context); | 178 v8::Context::Scope context_scope(context); |
| 179 | 179 |
| 180 m_pDocument = pReaderDoc; | 180 m_pDocument = pReaderDoc; |
| 181 if (pReaderDoc) { | 181 if (pReaderDoc) { |
| 182 v8::Local<v8::Object> pThis = JS_GetThisObj(GetIsolate()); | 182 v8::Local<v8::Object> pThis = FXJS_GetThisObj(GetIsolate()); |
| 183 if (!pThis.IsEmpty()) { | 183 if (!pThis.IsEmpty()) { |
| 184 if (JS_GetObjDefnID(pThis) == | 184 if (FXJS_GetObjDefnID(pThis) == |
| 185 JS_GetObjDefnID(GetIsolate(), L"Document")) { | 185 FXJS_GetObjDefnID(GetIsolate(), L"Document")) { |
| 186 if (CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pThis)) { | 186 if (CJS_Document* pJSDocument = |
| 187 (CJS_Document*)FXJS_GetPrivate(pThis)) { |
| 187 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) | 188 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) |
| 188 pDocument->AttachDoc(pReaderDoc); | 189 pDocument->AttachDoc(pReaderDoc); |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 } | 192 } |
| 192 } | 193 } |
| 193 } | 194 } |
| 194 } | 195 } |
| 195 | 196 |
| 196 FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, | 197 FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 267 |
| 267 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { | 268 v8::Local<v8::Context> CJS_Runtime::NewJSContext() { |
| 268 return v8::Local<v8::Context>::New(m_isolate, m_context); | 269 return v8::Local<v8::Context>::New(m_isolate, m_context); |
| 269 } | 270 } |
| 270 | 271 |
| 271 CFX_WideString ChangeObjName(const CFX_WideString& str) { | 272 CFX_WideString ChangeObjName(const CFX_WideString& str) { |
| 272 CFX_WideString sRet = str; | 273 CFX_WideString sRet = str; |
| 273 sRet.Replace(L"_", L"."); | 274 sRet.Replace(L"_", L"."); |
| 274 return sRet; | 275 return sRet; |
| 275 } | 276 } |
| OLD | NEW |