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> |
Tom Sepez | a775723 | 2017-04-18 11:10:39 -0700 | [diff] [blame] | 11 | #include <memory> |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 12 | #include <vector> |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 13 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 14 | #include "fpdfsdk/javascript/JS_Define.h" |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 15 | #include "fpdfsdk/javascript/JS_KeyValue.h" |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 16 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | class CJS_GlobalData; |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 18 | class CJS_GlobalVariableArray; |
| 19 | class CJS_KeyValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 20 | |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 21 | struct JSGlobalData { |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 22 | JSGlobalData(); |
| 23 | ~JSGlobalData(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 24 | |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 25 | JS_GlobalDataType nType; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | double dData; |
| 27 | bool bData; |
| 28 | CFX_ByteString sData; |
| 29 | v8::Global<v8::Object> pData; |
| 30 | bool bPersistent; |
| 31 | bool bDeleted; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 34 | class JSGlobalAlternate : public CJS_EmbedObj { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 35 | public: |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 36 | explicit JSGlobalAlternate(CJS_Object* pJSObject); |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 37 | ~JSGlobalAlternate() override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 39 | bool setPersistent(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 40 | const std::vector<CJS_Value>& params, |
| 41 | CJS_Value& vRet, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 42 | CFX_WideString& sError); |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 43 | bool QueryProperty(const wchar_t* propname); |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 44 | bool DoProperty(CJS_Runtime* pRuntime, |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 45 | const wchar_t* propname, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 46 | CJS_PropValue& vp, |
| 47 | CFX_WideString& sError); |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 48 | bool DelProperty(CJS_Runtime* pRuntime, |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 49 | const wchar_t* propname, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 50 | CFX_WideString& sError); |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 51 | void Initial(CPDFSDK_FormFillEnvironment* pFormFillEnv); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 52 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | private: |
| 54 | void UpdateGlobalPersistentVariables(); |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 55 | void CommitGlobalPersisitentVariables(CJS_Runtime* pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 56 | void DestroyGlobalPersisitentVariables(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 57 | bool SetGlobalVariables(const CFX_ByteString& propname, |
| 58 | JS_GlobalDataType nType, |
| 59 | double dData, |
| 60 | bool bData, |
| 61 | const CFX_ByteString& sData, |
| 62 | v8::Local<v8::Object> pData, |
| 63 | bool bDefaultPersistent); |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 64 | void ObjectToArray(CJS_Runtime* pRuntime, |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 65 | v8::Local<v8::Object> pObj, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 66 | CJS_GlobalVariableArray& array); |
| 67 | void PutObjectProperty(v8::Local<v8::Object> obj, CJS_KeyValue* pData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | |
Tom Sepez | a775723 | 2017-04-18 11:10:39 -0700 | [diff] [blame] | 69 | std::map<CFX_ByteString, std::unique_ptr<JSGlobalData>> m_MapGlobal; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | CFX_WideString m_sFilePath; |
| 71 | CJS_GlobalData* m_pGlobalData; |
Tom Sepez | 77f6d0f | 2017-02-23 12:14:10 -0800 | [diff] [blame] | 72 | CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | class CJS_Global : public CJS_Object { |
| 76 | public: |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 77 | explicit CJS_Global(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 78 | ~CJS_Global() override {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 79 | |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 80 | // CJS_Object |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 81 | void InitInstance(IJS_Runtime* pIRuntime) override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 82 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 83 | DECLARE_SPECIAL_JS_CLASS(); |
Tom Sepez | 7dc5cc1 | 2015-08-17 12:15:26 -0700 | [diff] [blame] | 84 | JS_SPECIAL_STATIC_METHOD(setPersistent, JSGlobalAlternate, global); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 87 | #endif // FPDFSDK_JAVASCRIPT_GLOBAL_H_ |