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