blob: 10300a25ab5607cbea7040006fe7e32337645307 [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
Tom Sepez19922bb2015-05-28 13:23:12 -07007#ifndef FPDFSDK_INCLUDE_JAVASCRIPT_GLOBAL_H_
8#define FPDFSDK_INCLUDE_JAVASCRIPT_GLOBAL_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Tom Sepez09d33bc2015-08-19 09:49:24 -070010#include <map>
11
Tom Sepez9a3f8122015-04-07 15:35:48 -070012#include "JS_Define.h"
13
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070014class CJS_GlobalData;
Tom Sepez9a3f8122015-04-07 15:35:48 -070015class CJS_GlobalVariableArray;
16class CJS_KeyValue;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017
Tom Sepez7dc5cc12015-08-17 12:15:26 -070018struct JSGlobalData {
19 JSGlobalData() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070020 nType = 0;
21 dData = 0;
22 bData = FALSE;
23 sData = "";
24 bPersistent = FALSE;
25 bDeleted = FALSE;
26 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027
Tom Sepez7dc5cc12015-08-17 12:15:26 -070028 ~JSGlobalData() { pData.Reset(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 int nType; // 0:int 1:bool 2:string 3:obj
30 double dData;
31 bool bData;
32 CFX_ByteString sData;
33 v8::Global<v8::Object> pData;
34 bool bPersistent;
35 bool bDeleted;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036};
37
Tom Sepez7dc5cc12015-08-17 12:15:26 -070038class JSGlobalAlternate : public CJS_EmbedObj {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039 public:
Tom Sepez7dc5cc12015-08-17 12:15:26 -070040 JSGlobalAlternate(CJS_Object* pJSObject);
41 ~JSGlobalAlternate() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 FX_BOOL setPersistent(IFXJS_Context* cc,
44 const CJS_Parameters& params,
45 CJS_Value& vRet,
46 CFX_WideString& sError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 FX_BOOL QueryProperty(const FX_WCHAR* propname);
48 FX_BOOL DoProperty(IFXJS_Context* cc,
49 const FX_WCHAR* propname,
50 CJS_PropValue& vp,
51 CFX_WideString& sError);
52 FX_BOOL DelProperty(IFXJS_Context* cc,
53 const FX_WCHAR* propname,
54 CFX_WideString& sError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 void Initial(CPDFDoc_Environment* pApp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 private:
58 void UpdateGlobalPersistentVariables();
59 void CommitGlobalPersisitentVariables();
60 void DestroyGlobalPersisitentVariables();
61 FX_BOOL SetGlobalVariables(const FX_CHAR* propname,
62 int nType,
63 double dData,
64 bool bData,
65 const CFX_ByteString& sData,
Tom Sepez808a99e2015-09-10 12:28:37 -070066 v8::Local<v8::Object> pData,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067 bool bDefaultPersistent);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 void ObjectToArray(v8::Local<v8::Object> pObj,
70 CJS_GlobalVariableArray& array);
71 void PutObjectProperty(v8::Local<v8::Object> obj, CJS_KeyValue* pData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073 private:
Tom Sepez09d33bc2015-08-19 09:49:24 -070074 std::map<CFX_ByteString, JSGlobalData*> m_mapGlobal;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 CFX_WideString m_sFilePath;
76 CJS_GlobalData* m_pGlobalData;
77 CPDFDoc_Environment* m_pApp;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078};
79
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080class CJS_Global : public CJS_Object {
81 public:
Tom Sepez808a99e2015-09-10 12:28:37 -070082 explicit CJS_Global(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
Lei Zhang2b1a2d52015-08-14 22:16:22 -070083 ~CJS_Global() override {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084
Lei Zhang2b1a2d52015-08-14 22:16:22 -070085 // CJS_Object
86 FX_BOOL InitInstance(IFXJS_Context* cc) override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 DECLARE_SPECIAL_JS_CLASS(CJS_Global);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089
Tom Sepez7dc5cc12015-08-17 12:15:26 -070090 JS_SPECIAL_STATIC_METHOD(setPersistent, JSGlobalAlternate, global);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070091};
92
Tom Sepez19922bb2015-05-28 13:23:12 -070093#endif // FPDFSDK_INCLUDE_JAVASCRIPT_GLOBAL_H_