Chromium Code Reviews| 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 // FXJS_V8 is a layer that makes it easier to define native objects in V8, but | 7 // FXJS_V8 is a layer that makes it easier to define native objects in V8, but |
| 8 // has no knowledge of PDF-specific native objects. It could in theory be used | 8 // has no knowledge of PDF-specific native objects. It could in theory be used |
| 9 // to implement other sets of native objects. | 9 // to implement other sets of native objects. |
| 10 | 10 |
| 11 // PDFium code should include this file rather than including V8 headers | 11 // PDFium code should include this file rather than including V8 headers |
| 12 // directly. | 12 // directly. |
| 13 | 13 |
| 14 #ifndef FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ | 14 #ifndef FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
| 15 #define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ | 15 #define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
| 16 | 16 |
| 17 #include <v8.h> | 17 #include <v8.h> |
| 18 #include <v8-util.h> | |
| 18 | 19 |
| 19 #include <vector> | 20 #include <vector> |
| 20 | 21 |
| 21 #include "core/include/fxcrt/fx_string.h" | 22 #include "core/include/fxcrt/fx_string.h" |
| 22 | 23 |
| 23 class CFXJS_ObjDefinition; | 24 class CFXJS_ObjDefinition; |
| 24 | 25 |
| 25 // FXJS_V8 places no restrictions on these two classes; it merely passes them | 26 // FXJS_V8 places no restrictions on these two classes; it merely passes them |
| 26 // on to caller-provided methods. | 27 // on to caller-provided methods. |
| 27 class IJS_Context; // A description of the event that caused JS execution. | 28 class IJS_Context; // A description of the event that caused JS execution. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 38 FXJSOBJTYPE_STATIC, // Created by init and hung off of global object. | 39 FXJSOBJTYPE_STATIC, // Created by init and hung off of global object. |
| 39 FXJSOBJTYPE_GLOBAL, // The global object itself (may only appear once). | 40 FXJSOBJTYPE_GLOBAL, // The global object itself (may only appear once). |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 struct FXJSErr { | 43 struct FXJSErr { |
| 43 const wchar_t* message; | 44 const wchar_t* message; |
| 44 const wchar_t* srcline; | 45 const wchar_t* srcline; |
| 45 unsigned linnum; | 46 unsigned linnum; |
| 46 }; | 47 }; |
| 47 | 48 |
| 49 // Global week map to put the dynamic objects. | |
|
jun_fang
2016/01/26 05:18:58
nit: no 'the'
jun_fang
2016/01/26 05:18:58
weak?
| |
| 50 class V8TemplateMapTraits : public v8::StdMapTraits<void*, v8::Object> { | |
| 51 public: | |
| 52 typedef v8::GlobalValueMap<void*, v8::Object, V8TemplateMapTraits> MapType; | |
| 53 typedef void WeakCallbackDataType; | |
| 54 | |
| 55 static WeakCallbackDataType* WeakCallbackParameter( | |
| 56 MapType* map, | |
| 57 void* key, | |
| 58 const v8::Local<v8::Object>& value) { | |
| 59 return key; | |
| 60 } | |
| 61 static MapType* MapFromWeakCallbackInfo( | |
| 62 const v8::WeakCallbackInfo<WeakCallbackDataType>&); | |
| 63 | |
| 64 static void* KeyFromWeakCallbackInfo( | |
| 65 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) { | |
| 66 return data.GetParameter(); | |
| 67 } | |
| 68 static const v8::PersistentContainerCallbackType kCallbackType = | |
| 69 v8::kWeakWithInternalFields; | |
| 70 static void DisposeWeak( | |
| 71 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) {} | |
| 72 static void OnWeakCallback( | |
| 73 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) {} | |
| 74 static void Dispose(v8::Isolate* isolate, | |
| 75 v8::Global<v8::Object> value, | |
| 76 void* key); | |
| 77 static void DisposeCallbackData(WeakCallbackDataType* callbackData) {} | |
| 78 }; | |
| 79 | |
| 80 class V8TemplateMap { | |
| 81 public: | |
| 82 typedef v8::GlobalValueMap<void*, v8::Object, V8TemplateMapTraits> MapType; | |
| 83 | |
| 84 void set(void* key, v8::Local<v8::Object> handle) { | |
| 85 ASSERT(!m_map.Contains(key)); | |
| 86 m_map.Set(key, handle); | |
| 87 } | |
| 88 explicit V8TemplateMap(v8::Isolate* isolate) : m_map(isolate) {} | |
| 89 friend class V8TemplateMapTraits; | |
| 90 | |
| 91 private: | |
| 92 MapType m_map; | |
| 93 }; | |
| 94 | |
| 48 class FXJS_PerIsolateData { | 95 class FXJS_PerIsolateData { |
| 49 public: | 96 public: |
| 50 static void SetUp(v8::Isolate* pIsolate); | 97 static void SetUp(v8::Isolate* pIsolate); |
| 51 static FXJS_PerIsolateData* Get(v8::Isolate* pIsolate); | 98 static FXJS_PerIsolateData* Get(v8::Isolate* pIsolate); |
| 52 | 99 |
| 53 std::vector<CFXJS_ObjDefinition*> m_ObjectDefnArray; | 100 std::vector<CFXJS_ObjDefinition*> m_ObjectDefnArray; |
| 54 #ifdef PDF_ENABLE_XFA | 101 #ifdef PDF_ENABLE_XFA |
| 55 CFXJSE_RuntimeData* m_pFXJSERuntimeData; | 102 CFXJSE_RuntimeData* m_pFXJSERuntimeData; |
| 56 #endif // PDF_ENABLE_XFA | 103 #endif // PDF_ENABLE_XFA |
| 104 V8TemplateMap* m_pDynamicObjsMap; | |
| 105 void CreateDynamicObjsMap(v8::Isolate* pIsolate) { | |
| 106 m_pDynamicObjsMap = new V8TemplateMap(pIsolate); | |
| 107 } | |
| 108 void ReleaseDynamicObjsMap() { | |
| 109 if (m_pDynamicObjsMap) | |
|
jun_fang
2016/01/26 05:18:58
No need to test |m_pDynamicObjsMap| when we try to
| |
| 110 delete m_pDynamicObjsMap; | |
| 111 m_pDynamicObjsMap = nullptr; | |
| 112 } | |
| 57 | 113 |
| 58 protected: | 114 protected: |
| 59 #ifndef PDF_ENABLE_XFA | 115 #ifndef PDF_ENABLE_XFA |
| 60 FXJS_PerIsolateData() {} | 116 FXJS_PerIsolateData() {} |
|
jun_fang
2016/01/26 05:18:58
Should add |m_pDynamicObjsMap(nullptr)|?
| |
| 61 #else // PDF_ENABLE_XFA | 117 #else // PDF_ENABLE_XFA |
| 62 FXJS_PerIsolateData() : m_pFXJSERuntimeData(nullptr) {} | 118 FXJS_PerIsolateData() |
| 119 : m_pFXJSERuntimeData(nullptr), m_pDynamicObjsMap(nullptr) {} | |
| 63 #endif // PDF_ENABLE_XFA | 120 #endif // PDF_ENABLE_XFA |
| 64 }; | 121 }; |
| 65 | 122 |
| 66 extern const wchar_t kFXJSValueNameString[]; | 123 extern const wchar_t kFXJSValueNameString[]; |
| 67 extern const wchar_t kFXJSValueNameNumber[]; | 124 extern const wchar_t kFXJSValueNameNumber[]; |
| 68 extern const wchar_t kFXJSValueNameBoolean[]; | 125 extern const wchar_t kFXJSValueNameBoolean[]; |
| 69 extern const wchar_t kFXJSValueNameDate[]; | 126 extern const wchar_t kFXJSValueNameDate[]; |
| 70 extern const wchar_t kFXJSValueNameObject[]; | 127 extern const wchar_t kFXJSValueNameObject[]; |
| 71 extern const wchar_t kFXJSValueNameFxobj[]; | 128 extern const wchar_t kFXJSValueNameFxobj[]; |
| 72 extern const wchar_t kFXJSValueNameNull[]; | 129 extern const wchar_t kFXJSValueNameNull[]; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 #endif // PDF_ENABLE_XFA | 210 #endif // PDF_ENABLE_XFA |
| 154 | 211 |
| 155 // Called after FXJS_InitializeRuntime call made. | 212 // Called after FXJS_InitializeRuntime call made. |
| 156 int FXJS_Execute(v8::Isolate* pIsolate, | 213 int FXJS_Execute(v8::Isolate* pIsolate, |
| 157 IJS_Context* pJSContext, | 214 IJS_Context* pJSContext, |
| 158 const wchar_t* script, | 215 const wchar_t* script, |
| 159 FXJSErr* perror); | 216 FXJSErr* perror); |
| 160 | 217 |
| 161 v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, | 218 v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, |
| 162 IJS_Runtime* pJSContext, | 219 IJS_Runtime* pJSContext, |
| 163 int nObjDefnID); | 220 int nObjDefnID, |
| 221 FX_BOOL bStatic = FALSE); | |
| 164 v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate); | 222 v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate); |
| 165 int FXJS_GetObjDefnID(v8::Local<v8::Object> pObj); | 223 int FXJS_GetObjDefnID(v8::Local<v8::Object> pObj); |
| 166 const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj); | 224 const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj); |
| 167 | 225 |
| 168 void FXJS_SetPrivate(v8::Isolate* pIsolate, | 226 void FXJS_SetPrivate(v8::Isolate* pIsolate, |
| 169 v8::Local<v8::Object> pObj, | 227 v8::Local<v8::Object> pObj, |
| 170 void* p); | 228 void* p); |
| 171 void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj); | 229 void* FXJS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj); |
| 172 void FXJS_FreePrivate(void* p); | 230 void FXJS_FreePrivate(void* p); |
| 173 void FXJS_FreePrivate(v8::Local<v8::Object> pObj); | 231 void FXJS_FreePrivate(v8::Local<v8::Object> pObj); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 double FXJS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); | 297 double FXJS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue); |
| 240 v8::Local<v8::Object> FXJS_ToObject(v8::Isolate* pIsolate, | 298 v8::Local<v8::Object> FXJS_ToObject(v8::Isolate* pIsolate, |
| 241 v8::Local<v8::Value> pValue); | 299 v8::Local<v8::Value> pValue); |
| 242 CFX_WideString FXJS_ToString(v8::Isolate* pIsolate, | 300 CFX_WideString FXJS_ToString(v8::Isolate* pIsolate, |
| 243 v8::Local<v8::Value> pValue); | 301 v8::Local<v8::Value> pValue); |
| 244 v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate, | 302 v8::Local<v8::Array> FXJS_ToArray(v8::Isolate* pIsolate, |
| 245 v8::Local<v8::Value> pValue); | 303 v8::Local<v8::Value> pValue); |
| 246 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom); | 304 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom); |
| 247 | 305 |
| 248 #endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ | 306 #endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
| OLD | NEW |