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