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 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 7 | #ifndef FPDFSDK_JAVASCRIPT_GLOBAL_H_ |
| 8 | #define FPDFSDK_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> |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 11 | #include <vector> |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 12 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 13 | #include "fpdfsdk/javascript/JS_Define.h" |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 14 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 15 | class CJS_GlobalData; |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 16 | class CJS_GlobalVariableArray; |
| 17 | class CJS_KeyValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 18 | |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 19 | struct JSGlobalData { |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame^] | 20 | JSGlobalData(); |
| 21 | ~JSGlobalData(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 22 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 23 | int nType; // 0:int 1:bool 2:string 3:obj |
| 24 | double dData; |
| 25 | bool bData; |
| 26 | CFX_ByteString sData; |
| 27 | v8::Global<v8::Object> pData; |
| 28 | bool bPersistent; |
| 29 | bool bDeleted; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 32 | class JSGlobalAlternate : public CJS_EmbedObj { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | public: |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 34 | JSGlobalAlternate(CJS_Object* pJSObject); |
| 35 | ~JSGlobalAlternate() override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 37 | FX_BOOL setPersistent(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 38 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | CJS_Value& vRet, |
| 40 | CFX_WideString& sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | FX_BOOL QueryProperty(const FX_WCHAR* propname); |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 42 | FX_BOOL DoProperty(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 43 | const FX_WCHAR* propname, |
| 44 | CJS_PropValue& vp, |
| 45 | CFX_WideString& sError); |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 46 | FX_BOOL DelProperty(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | const FX_WCHAR* propname, |
| 48 | CFX_WideString& sError); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 49 | void Initial(CPDFDoc_Environment* pApp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | private: |
| 52 | void UpdateGlobalPersistentVariables(); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 53 | void CommitGlobalPersisitentVariables(IJS_Context* cc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 54 | void DestroyGlobalPersisitentVariables(); |
tsepez | 24a4888 | 2016-04-11 15:18:40 -0700 | [diff] [blame] | 55 | FX_BOOL SetGlobalVariables(const CFX_ByteString& propname, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 56 | int nType, |
| 57 | double dData, |
| 58 | bool bData, |
| 59 | const CFX_ByteString& sData, |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 60 | v8::Local<v8::Object> pData, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 61 | bool bDefaultPersistent); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 62 | void ObjectToArray(IJS_Context* cc, |
| 63 | v8::Local<v8::Object> pObj, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | 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 | |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 67 | std::map<CFX_ByteString, JSGlobalData*> m_mapGlobal; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | CFX_WideString m_sFilePath; |
| 69 | CJS_GlobalData* m_pGlobalData; |
| 70 | CPDFDoc_Environment* m_pApp; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | class CJS_Global : public CJS_Object { |
| 74 | public: |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 75 | explicit CJS_Global(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 76 | ~CJS_Global() override {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 77 | |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 78 | // CJS_Object |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 79 | void InitInstance(IJS_Runtime* pIRuntime) override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 80 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 81 | DECLARE_SPECIAL_JS_CLASS(); |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 82 | JS_SPECIAL_STATIC_METHOD(setPersistent, JSGlobalAlternate, global); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 85 | #endif // FPDFSDK_JAVASCRIPT_GLOBAL_H_ |