blob: 369956749b8e6f341e4d8a2cc09f17712de62d17 [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 Sepez9a3f8122015-04-07 15:35:48 -070010#include "JS_Define.h"
11
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012class CJS_GlobalData;
Tom Sepez9a3f8122015-04-07 15:35:48 -070013class CJS_GlobalVariableArray;
14class CJS_KeyValue;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015
Nico Weber9d8ec5a2015-08-04 13:00:21 -070016struct js_global_data {
17 js_global_data() {
18 nType = 0;
19 dData = 0;
20 bData = FALSE;
21 sData = "";
22 bPersistent = FALSE;
23 bDeleted = FALSE;
24 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026 ~js_global_data() { pData.Reset(); }
27 int nType; // 0:int 1:bool 2:string 3:obj
28 double dData;
29 bool bData;
30 CFX_ByteString sData;
31 v8::Global<v8::Object> pData;
32 bool bPersistent;
33 bool bDeleted;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034};
35
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036class global_alternate : public CJS_EmbedObj {
37 public:
38 global_alternate(CJS_Object* pJSObject);
Lei Zhang2b1a2d52015-08-14 22:16:22 -070039 ~global_alternate() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070040
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 public:
42 FX_BOOL setPersistent(IFXJS_Context* cc,
43 const CJS_Parameters& params,
44 CJS_Value& vRet,
45 CFX_WideString& sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 public:
48 FX_BOOL QueryProperty(const FX_WCHAR* propname);
49 FX_BOOL DoProperty(IFXJS_Context* cc,
50 const FX_WCHAR* propname,
51 CJS_PropValue& vp,
52 CFX_WideString& sError);
53 FX_BOOL DelProperty(IFXJS_Context* cc,
54 const FX_WCHAR* propname,
55 CFX_WideString& sError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 void Initial(CPDFDoc_Environment* pApp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070058
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 private:
60 void UpdateGlobalPersistentVariables();
61 void CommitGlobalPersisitentVariables();
62 void DestroyGlobalPersisitentVariables();
63 FX_BOOL SetGlobalVariables(const FX_CHAR* propname,
64 int nType,
65 double dData,
66 bool bData,
67 const CFX_ByteString& sData,
68 JSObject pData,
69 bool bDefaultPersistent);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 void ObjectToArray(v8::Local<v8::Object> pObj,
72 CJS_GlobalVariableArray& array);
73 void PutObjectProperty(v8::Local<v8::Object> obj, CJS_KeyValue* pData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070074
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 private:
76 CFX_MapByteStringToPtr m_mapGlobal;
77 CFX_WideString m_sFilePath;
78 CJS_GlobalData* m_pGlobalData;
79 CPDFDoc_Environment* m_pApp;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080};
81
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082class CJS_Global : public CJS_Object {
83 public:
Lei Zhang2b1a2d52015-08-14 22:16:22 -070084 explicit CJS_Global(JSFXObject pObject) : CJS_Object(pObject) {}
85 ~CJS_Global() override {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086
Lei Zhang2b1a2d52015-08-14 22:16:22 -070087 // CJS_Object
88 FX_BOOL InitInstance(IFXJS_Context* cc) override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 DECLARE_SPECIAL_JS_CLASS(CJS_Global);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070091
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 JS_SPECIAL_STATIC_METHOD(setPersistent, global_alternate, global);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070093};
94
Tom Sepez19922bb2015-05-28 13:23:12 -070095#endif // FPDFSDK_INCLUDE_JAVASCRIPT_GLOBAL_H_