John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 7 | #ifndef FPDFSDK_SRC_JAVASCRIPT_GLOBAL_H_ |
| 8 | #define FPDFSDK_SRC_JAVASCRIPT_GLOBAL_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 10 | #include <map> |
| 11 | |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 12 | #include "JS_Define.h" |
| 13 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 14 | class CJS_GlobalData; |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 15 | class CJS_GlobalVariableArray; |
| 16 | class CJS_KeyValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 18 | struct JSGlobalData { |
| 19 | JSGlobalData() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 20 | nType = 0; |
| 21 | dData = 0; |
| 22 | bData = FALSE; |
| 23 | sData = ""; |
| 24 | bPersistent = FALSE; |
| 25 | bDeleted = FALSE; |
| 26 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 28 | ~JSGlobalData() { pData.Reset(); } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | int nType; // 0:int 1:bool 2:string 3:obj |
| 30 | double dData; |
| 31 | bool bData; |
| 32 | CFX_ByteString sData; |
| 33 | v8::Global<v8::Object> pData; |
| 34 | bool bPersistent; |
| 35 | bool bDeleted; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 38 | class JSGlobalAlternate : public CJS_EmbedObj { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | public: |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 40 | JSGlobalAlternate(CJS_Object* pJSObject); |
| 41 | ~JSGlobalAlternate() override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 42 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 43 | FX_BOOL setPersistent(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | const CJS_Parameters& params, |
| 45 | CJS_Value& vRet, |
| 46 | CFX_WideString& sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | FX_BOOL QueryProperty(const FX_WCHAR* propname); |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 48 | FX_BOOL DoProperty(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 49 | const FX_WCHAR* propname, |
| 50 | CJS_PropValue& vp, |
| 51 | CFX_WideString& sError); |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 52 | FX_BOOL DelProperty(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | const FX_WCHAR* propname, |
| 54 | CFX_WideString& sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | void Initial(CPDFDoc_Environment* pApp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | private: |
| 58 | void UpdateGlobalPersistentVariables(); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 59 | void CommitGlobalPersisitentVariables(IJS_Context* cc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | void DestroyGlobalPersisitentVariables(); |
| 61 | FX_BOOL SetGlobalVariables(const FX_CHAR* propname, |
| 62 | int nType, |
| 63 | double dData, |
| 64 | bool bData, |
| 65 | const CFX_ByteString& sData, |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 66 | v8::Local<v8::Object> pData, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | bool bDefaultPersistent); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 68 | void ObjectToArray(IJS_Context* cc, |
| 69 | v8::Local<v8::Object> pObj, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | CJS_GlobalVariableArray& array); |
| 71 | void PutObjectProperty(v8::Local<v8::Object> obj, CJS_KeyValue* pData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 72 | |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 73 | std::map<CFX_ByteString, JSGlobalData*> m_mapGlobal; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 74 | CFX_WideString m_sFilePath; |
| 75 | CJS_GlobalData* m_pGlobalData; |
| 76 | CPDFDoc_Environment* m_pApp; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | class CJS_Global : public CJS_Object { |
| 80 | public: |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 81 | explicit CJS_Global(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 82 | ~CJS_Global() override {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 83 | |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 84 | // CJS_Object |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 85 | FX_BOOL InitInstance(IJS_Context* cc) override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 86 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 87 | DECLARE_SPECIAL_JS_CLASS(); |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 88 | JS_SPECIAL_STATIC_METHOD(setPersistent, JSGlobalAlternate, global); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 91 | #endif // FPDFSDK_SRC_JAVASCRIPT_GLOBAL_H_ |