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 | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 7 | #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_GLOBAL_H_ |
| 8 | #define FPDFSDK_INCLUDE_JAVASCRIPT_GLOBAL_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 10 | #include "JS_Define.h" |
| 11 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 12 | class CJS_GlobalData; |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 13 | class CJS_GlobalVariableArray; |
| 14 | class CJS_KeyValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 15 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 16 | struct js_global_data { |
| 17 | js_global_data() { |
| 18 | nType = 0; |
| 19 | dData = 0; |
| 20 | bData = FALSE; |
| 21 | sData = ""; |
| 22 | bPersistent = FALSE; |
| 23 | bDeleted = FALSE; |
| 24 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | ~js_global_data() { pData.Reset(); } |
| 27 | int nType; // 0:int 1:bool 2:string 3:obj |
| 28 | double dData; |
| 29 | bool bData; |
| 30 | CFX_ByteString sData; |
| 31 | v8::Global<v8::Object> pData; |
| 32 | bool bPersistent; |
| 33 | bool bDeleted; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | class global_alternate : public CJS_EmbedObj { |
| 37 | public: |
| 38 | global_alternate(CJS_Object* pJSObject); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame^] | 39 | ~global_alternate() override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 40 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | public: |
| 42 | FX_BOOL setPersistent(IFXJS_Context* cc, |
| 43 | const CJS_Parameters& params, |
| 44 | CJS_Value& vRet, |
| 45 | CFX_WideString& sError); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | public: |
| 48 | FX_BOOL QueryProperty(const FX_WCHAR* propname); |
| 49 | FX_BOOL DoProperty(IFXJS_Context* cc, |
| 50 | const FX_WCHAR* propname, |
| 51 | CJS_PropValue& vp, |
| 52 | CFX_WideString& sError); |
| 53 | FX_BOOL DelProperty(IFXJS_Context* cc, |
| 54 | const FX_WCHAR* propname, |
| 55 | CFX_WideString& sError); |
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 | void Initial(CPDFDoc_Environment* pApp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 58 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 59 | private: |
| 60 | void UpdateGlobalPersistentVariables(); |
| 61 | void CommitGlobalPersisitentVariables(); |
| 62 | void DestroyGlobalPersisitentVariables(); |
| 63 | FX_BOOL SetGlobalVariables(const FX_CHAR* propname, |
| 64 | int nType, |
| 65 | double dData, |
| 66 | bool bData, |
| 67 | const CFX_ByteString& sData, |
| 68 | JSObject pData, |
| 69 | bool bDefaultPersistent); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 70 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | void ObjectToArray(v8::Local<v8::Object> pObj, |
| 72 | CJS_GlobalVariableArray& array); |
| 73 | void PutObjectProperty(v8::Local<v8::Object> obj, CJS_KeyValue* pData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 74 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | private: |
| 76 | CFX_MapByteStringToPtr m_mapGlobal; |
| 77 | CFX_WideString m_sFilePath; |
| 78 | CJS_GlobalData* m_pGlobalData; |
| 79 | CPDFDoc_Environment* m_pApp; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 82 | class CJS_Global : public CJS_Object { |
| 83 | public: |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame^] | 84 | explicit CJS_Global(JSFXObject pObject) : CJS_Object(pObject) {} |
| 85 | ~CJS_Global() override {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 86 | |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame^] | 87 | // CJS_Object |
| 88 | FX_BOOL InitInstance(IFXJS_Context* cc) override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 89 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | DECLARE_SPECIAL_JS_CLASS(CJS_Global); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 91 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | JS_SPECIAL_STATIC_METHOD(setPersistent, global_alternate, global); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 95 | #endif // FPDFSDK_INCLUDE_JAVASCRIPT_GLOBAL_H_ |