blob: 9a6568bc27ca53da576877d29ba7a32b4f8de63b [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>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050011#include <vector>
Tom Sepez09d33bc2015-08-19 09:49:24 -070012
Dan Sinclairf766ad22016-03-14 13:51:24 -040013#include "fpdfsdk/javascript/JS_Define.h"
weili47228ac2016-07-20 10:35:31 -070014#include "fpdfsdk/javascript/JS_KeyValue.h"
Tom Sepez9a3f8122015-04-07 15:35:48 -070015
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070016class CJS_GlobalData;
Tom Sepez9a3f8122015-04-07 15:35:48 -070017class CJS_GlobalVariableArray;
18class CJS_KeyValue;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019
Tom Sepez7dc5cc12015-08-17 12:15:26 -070020struct JSGlobalData {
weili625ad662016-06-15 11:21:33 -070021 JSGlobalData();
22 ~JSGlobalData();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023
weili47228ac2016-07-20 10:35:31 -070024 JS_GlobalDataType nType;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070025 double dData;
26 bool bData;
27 CFX_ByteString sData;
28 v8::Global<v8::Object> pData;
29 bool bPersistent;
30 bool bDeleted;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031};
32
Tom Sepez7dc5cc12015-08-17 12:15:26 -070033class JSGlobalAlternate : public CJS_EmbedObj {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034 public:
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050035 explicit JSGlobalAlternate(CJS_Object* pJSObject);
Tom Sepez7dc5cc12015-08-17 12:15:26 -070036 ~JSGlobalAlternate() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037
tsepez4cf55152016-11-02 14:37:54 -070038 bool setPersistent(IJS_Context* cc,
39 const std::vector<CJS_Value>& params,
40 CJS_Value& vRet,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 CFX_WideString& sError);
tsepez4cf55152016-11-02 14:37:54 -070042 bool QueryProperty(const FX_WCHAR* propname);
43 bool DoProperty(IJS_Context* cc,
44 const FX_WCHAR* propname,
45 CJS_PropValue& vp,
46 CFX_WideString& sError);
47 bool DelProperty(IJS_Context* cc,
48 const FX_WCHAR* propname,
49 CFX_WideString& sError);
dsinclair8779fa82016-10-12 12:05:44 -070050 void Initial(CPDFSDK_FormFillEnvironment* pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070051
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052 private:
53 void UpdateGlobalPersistentVariables();
Tom Sepez67fd5df2015-10-08 12:24:19 -070054 void CommitGlobalPersisitentVariables(IJS_Context* cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 void DestroyGlobalPersisitentVariables();
tsepez4cf55152016-11-02 14:37:54 -070056 bool SetGlobalVariables(const CFX_ByteString& propname,
57 JS_GlobalDataType nType,
58 double dData,
59 bool bData,
60 const CFX_ByteString& sData,
61 v8::Local<v8::Object> pData,
62 bool bDefaultPersistent);
Tom Sepez67fd5df2015-10-08 12:24:19 -070063 void ObjectToArray(IJS_Context* cc,
64 v8::Local<v8::Object> pObj,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065 CJS_GlobalVariableArray& array);
66 void PutObjectProperty(v8::Local<v8::Object> obj, CJS_KeyValue* pData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070067
Tom Sepez09d33bc2015-08-19 09:49:24 -070068 std::map<CFX_ByteString, JSGlobalData*> m_mapGlobal;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 CFX_WideString m_sFilePath;
70 CJS_GlobalData* m_pGlobalData;
dsinclair8779fa82016-10-12 12:05:44 -070071 CPDFSDK_FormFillEnvironment* m_pFormFillEnv;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072};
73
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074class CJS_Global : public CJS_Object {
75 public:
Tom Sepez808a99e2015-09-10 12:28:37 -070076 explicit CJS_Global(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
Lei Zhang2b1a2d52015-08-14 22:16:22 -070077 ~CJS_Global() override {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078
Lei Zhang2b1a2d52015-08-14 22:16:22 -070079 // CJS_Object
Tom Sepez33420902015-10-13 15:00:10 -070080 void InitInstance(IJS_Runtime* pIRuntime) override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081
Tom Sepezcd56a7d2015-10-06 11:45:28 -070082 DECLARE_SPECIAL_JS_CLASS();
Tom Sepez7dc5cc12015-08-17 12:15:26 -070083 JS_SPECIAL_STATIC_METHOD(setPersistent, JSGlobalAlternate, global);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084};
85
Dan Sinclairf766ad22016-03-14 13:51:24 -040086#endif // FPDFSDK_JAVASCRIPT_GLOBAL_H_