Initial commit.
[pdfium.git] / fpdfsdk / include / javascript / global.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4  \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef _GLOBAL_H_\r
8 #define _GLOBAL_H_\r
9 \r
10 class CJS_GlobalData;\r
11 \r
12 struct js_global_data\r
13 {\r
14         js_global_data()\r
15         {\r
16                 nType = 0;\r
17                 dData = 0;\r
18                 bData = FALSE;\r
19                 sData = "";\r
20                 bPersistent = FALSE;\r
21                 bDeleted = FALSE;\r
22         }\r
23 \r
24         ~js_global_data()\r
25         {\r
26                 pData.Reset();\r
27         }\r
28         int                                     nType; //0:int 1:bool 2:string 3:obj\r
29         double                          dData;\r
30         bool                            bData;\r
31         CFX_ByteString          sData;\r
32         v8::Persistent<v8::Object>  pData;\r
33         bool                            bPersistent;\r
34         bool                            bDeleted;\r
35 };\r
36 \r
37 class global_alternate : public CJS_EmbedObj\r
38 {\r
39 public:\r
40         global_alternate(CJS_Object* pJSObject);\r
41         virtual ~global_alternate();\r
42 \r
43 public:\r
44         FX_BOOL                                         setPersistent(OBJ_METHOD_PARAMS);\r
45 \r
46 public:\r
47         FX_BOOL                                         QueryProperty(FX_LPCWSTR propname);\r
48         FX_BOOL                                         DoProperty(IFXJS_Context* cc, FX_LPCWSTR propname, CJS_PropValue & vp, JS_ErrorString & sError);\r
49         FX_BOOL                                         DelProperty(IFXJS_Context* cc, FX_LPCWSTR propname, JS_ErrorString & sError);\r
50 \r
51         void                                            Initial(CPDFDoc_Environment* pApp);\r
52 \r
53 private:\r
54         void                                            UpdateGlobalPersistentVariables();\r
55         void                                            CommitGlobalPersisitentVariables();\r
56         void                                            DestroyGlobalPersisitentVariables();\r
57         FX_BOOL                                         SetGlobalVariables(FX_LPCSTR propname, int nType, \r
58                                                                         double dData, bool bData, const CFX_ByteString& sData, JSObject pData, bool bDefaultPersistent);\r
59 \r
60         void                                            ObjectToArray(v8::Handle<v8::Object> pObj, CJS_GlobalVariableArray& array);\r
61         void                                            PutObjectProperty(v8::Handle<v8::Object> obj, CJS_KeyValue* pData);\r
62 \r
63 private:\r
64         CFX_MapByteStringToPtr          m_mapGlobal;\r
65         CFX_WideString                          m_sFilePath;\r
66         CJS_GlobalData*                         m_pGlobalData;\r
67         CPDFDoc_Environment*                            m_pApp;\r
68 };\r
69 \r
70 \r
71 class CJS_Global : public CJS_Object\r
72 {\r
73 public:\r
74         CJS_Global(JSFXObject pObject) : CJS_Object(pObject) {};\r
75         virtual ~CJS_Global(void){};\r
76 \r
77         virtual FX_BOOL InitInstance(IFXJS_Context* cc);        \r
78 \r
79         DECLARE_SPECIAL_JS_CLASS(CJS_Global);\r
80 \r
81         JS_SPECIAL_STATIC_METHOD(setPersistent, global_alternate, global);\r
82 \r
83 };\r
84 \r
85 #endif //_GLOBAL_H_\r