blob: 364313c972a0f24b5640b5c553e2c715ae09aba0 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairf766ad22016-03-14 13:51:24 -04007#ifndef FPDFSDK_JAVASCRIPT_GLOBAL_H_
8#define FPDFSDK_JAVASCRIPT_GLOBAL_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Tom Sepez09d33bc2015-08-19 09:49:24 -070010#include <map>
Tom Sepeza7757232017-04-18 11:10:39 -070011#include <memory>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050012#include <vector>
Tom Sepez09d33bc2015-08-19 09:49:24 -070013
Dan Sinclairf766ad22016-03-14 13:51:24 -040014#include "fpdfsdk/javascript/JS_Define.h"
weili47228ac2016-07-20 10:35:31 -070015#include "fpdfsdk/javascript/JS_KeyValue.h"
Tom Sepez9a3f8122015-04-07 15:35:48 -070016
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017class CJS_GlobalData;
Tom Sepez9a3f8122015-04-07 15:35:48 -070018class CJS_GlobalVariableArray;
19class CJS_KeyValue;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Tom Sepez7dc5cc12015-08-17 12:15:26 -070021struct JSGlobalData {
weili625ad662016-06-15 11:21:33 -070022 JSGlobalData();
23 ~JSGlobalData();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024
weili47228ac2016-07-20 10:35:31 -070025 JS_GlobalDataType nType;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026 double dData;
27 bool bData;
28 CFX_ByteString sData;
29 v8::Global<v8::Object> pData;
30 bool bPersistent;
31 bool bDeleted;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032};
33
Tom Sepez7dc5cc12015-08-17 12:15:26 -070034class JSGlobalAlternate : public CJS_EmbedObj {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035 public:
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050036 explicit JSGlobalAlternate(CJS_Object* pJSObject);
Tom Sepez7dc5cc12015-08-17 12:15:26 -070037 ~JSGlobalAlternate() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038
Tom Sepezb1670b52017-02-16 17:01:00 -080039 bool setPersistent(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -070040 const std::vector<CJS_Value>& params,
41 CJS_Value& vRet,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042 CFX_WideString& sError);
Dan Sinclair812e96c2017-03-13 16:43:37 -040043 bool QueryProperty(const wchar_t* propname);
Tom Sepezb1670b52017-02-16 17:01:00 -080044 bool DoProperty(CJS_Runtime* pRuntime,
Dan Sinclair812e96c2017-03-13 16:43:37 -040045 const wchar_t* propname,
tsepez4cf55152016-11-02 14:37:54 -070046 CJS_PropValue& vp,
47 CFX_WideString& sError);
Tom Sepezb1670b52017-02-16 17:01:00 -080048 bool DelProperty(CJS_Runtime* pRuntime,
Dan Sinclair812e96c2017-03-13 16:43:37 -040049 const wchar_t* propname,
tsepez4cf55152016-11-02 14:37:54 -070050 CFX_WideString& sError);
dsinclair8779fa82016-10-12 12:05:44 -070051 void Initial(CPDFSDK_FormFillEnvironment* pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 private:
54 void UpdateGlobalPersistentVariables();
Tom Sepezb1670b52017-02-16 17:01:00 -080055 void CommitGlobalPersisitentVariables(CJS_Runtime* pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056 void DestroyGlobalPersisitentVariables();
tsepez4cf55152016-11-02 14:37:54 -070057 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 Sepezb1670b52017-02-16 17:01:00 -080064 void ObjectToArray(CJS_Runtime* pRuntime,
Tom Sepez67fd5df2015-10-08 12:24:19 -070065 v8::Local<v8::Object> pObj,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 CJS_GlobalVariableArray& array);
67 void PutObjectProperty(v8::Local<v8::Object> obj, CJS_KeyValue* pData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068
Tom Sepeza7757232017-04-18 11:10:39 -070069 std::map<CFX_ByteString, std::unique_ptr<JSGlobalData>> m_MapGlobal;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070070 CFX_WideString m_sFilePath;
71 CJS_GlobalData* m_pGlobalData;
Tom Sepez77f6d0f2017-02-23 12:14:10 -080072 CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073};
74
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075class CJS_Global : public CJS_Object {
76 public:
Tom Sepez808a99e2015-09-10 12:28:37 -070077 explicit CJS_Global(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
Lei Zhang2b1a2d52015-08-14 22:16:22 -070078 ~CJS_Global() override {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070079
Lei Zhang2b1a2d52015-08-14 22:16:22 -070080 // CJS_Object
Tom Sepez33420902015-10-13 15:00:10 -070081 void InitInstance(IJS_Runtime* pIRuntime) override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070082
Tom Sepezcd56a7d2015-10-06 11:45:28 -070083 DECLARE_SPECIAL_JS_CLASS();
Tom Sepez7dc5cc12015-08-17 12:15:26 -070084 JS_SPECIAL_STATIC_METHOD(setPersistent, JSGlobalAlternate, global);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085};
86
Dan Sinclairf766ad22016-03-14 13:51:24 -040087#endif // FPDFSDK_JAVASCRIPT_GLOBAL_H_