blob: eca9aa12d1a8fdbde971f9a7c6df75df32651cc2 [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"
Tom Sepez9a3f8122015-04-07 15:35:48 -070014
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015class CJS_GlobalData;
Tom Sepez9a3f8122015-04-07 15:35:48 -070016class CJS_GlobalVariableArray;
17class CJS_KeyValue;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018
Tom Sepez7dc5cc12015-08-17 12:15:26 -070019struct JSGlobalData {
weili625ad662016-06-15 11:21:33 -070020 JSGlobalData();
21 ~JSGlobalData();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023 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-Malek3f3b45c2014-05-23 17:28:10 -070030};
31
Tom Sepez7dc5cc12015-08-17 12:15:26 -070032class JSGlobalAlternate : public CJS_EmbedObj {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033 public:
Tom Sepez7dc5cc12015-08-17 12:15:26 -070034 JSGlobalAlternate(CJS_Object* pJSObject);
35 ~JSGlobalAlternate() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036
Tom Sepezba038bc2015-10-08 12:03:00 -070037 FX_BOOL setPersistent(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -080038 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039 CJS_Value& vRet,
40 CFX_WideString& sError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 FX_BOOL QueryProperty(const FX_WCHAR* propname);
Tom Sepezba038bc2015-10-08 12:03:00 -070042 FX_BOOL DoProperty(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 const FX_WCHAR* propname,
44 CJS_PropValue& vp,
45 CFX_WideString& sError);
Tom Sepezba038bc2015-10-08 12:03:00 -070046 FX_BOOL DelProperty(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 const FX_WCHAR* propname,
48 CFX_WideString& sError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 void Initial(CPDFDoc_Environment* pApp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051 private:
52 void UpdateGlobalPersistentVariables();
Tom Sepez67fd5df2015-10-08 12:24:19 -070053 void CommitGlobalPersisitentVariables(IJS_Context* cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 void DestroyGlobalPersisitentVariables();
tsepez24a48882016-04-11 15:18:40 -070055 FX_BOOL SetGlobalVariables(const CFX_ByteString& propname,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056 int nType,
57 double dData,
58 bool bData,
59 const CFX_ByteString& sData,
Tom Sepez808a99e2015-09-10 12:28:37 -070060 v8::Local<v8::Object> pData,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061 bool bDefaultPersistent);
Tom Sepez67fd5df2015-10-08 12:24:19 -070062 void ObjectToArray(IJS_Context* cc,
63 v8::Local<v8::Object> pObj,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 CJS_GlobalVariableArray& array);
65 void PutObjectProperty(v8::Local<v8::Object> obj, CJS_KeyValue* pData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070066
Tom Sepez09d33bc2015-08-19 09:49:24 -070067 std::map<CFX_ByteString, JSGlobalData*> m_mapGlobal;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 CFX_WideString m_sFilePath;
69 CJS_GlobalData* m_pGlobalData;
70 CPDFDoc_Environment* m_pApp;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071};
72
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073class CJS_Global : public CJS_Object {
74 public:
Tom Sepez808a99e2015-09-10 12:28:37 -070075 explicit CJS_Global(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
Lei Zhang2b1a2d52015-08-14 22:16:22 -070076 ~CJS_Global() override {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077
Lei Zhang2b1a2d52015-08-14 22:16:22 -070078 // CJS_Object
Tom Sepez33420902015-10-13 15:00:10 -070079 void InitInstance(IJS_Runtime* pIRuntime) override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080
Tom Sepezcd56a7d2015-10-06 11:45:28 -070081 DECLARE_SPECIAL_JS_CLASS();
Tom Sepez7dc5cc12015-08-17 12:15:26 -070082 JS_SPECIAL_STATIC_METHOD(setPersistent, JSGlobalAlternate, global);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070083};
84
Dan Sinclairf766ad22016-03-14 13:51:24 -040085#endif // FPDFSDK_JAVASCRIPT_GLOBAL_H_