Remove "using namespace v8" in header. This allows us to turn all warnings into error...
[pdfium.git] / fpdfsdk / src / javascript / JS_Object.cpp
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 #include "../../include/javascript/JavaScript.h"\r
8 #include "../../include/javascript/IJavaScript.h"\r
9 #include "../../include/javascript/JS_Define.h"\r
10 #include "../../include/javascript/JS_Object.h"\r
11 // #include "../../include/javascript/JS_MsgBox.h"\r
12 // #include "../../include/javascript/JS_ResMgr.h"\r
13 #include "../../include/javascript/JS_Context.h"\r
14 \r
15 int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)\r
16 {\r
17         int nRet = 0;\r
18 \r
19         if(pApp)\r
20         {\r
21                 CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();\r
22                 if(pDoc)\r
23                         pDoc->KillFocusAnnot();\r
24                 nRet = pApp->JS_appAlert(swMsg, swTitle, nType, nIcon);\r
25         }\r
26 \r
27         return nRet;\r
28 }\r
29 \r
30 CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc)\r
31 {\r
32         if (CJS_Context* pContext = (CJS_Context *)cc)\r
33         {\r
34                 if (pContext->GetReaderDocument())\r
35                         return NULL;\r
36         }\r
37         return NULL;\r
38 }\r
39 \r
40 /* ---------------------------------  CJS_EmbedObj --------------------------------- */\r
41 \r
42 CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : \r
43         m_pJSObject(pJSObject)\r
44 {\r
45 }\r
46 \r
47 CJS_EmbedObj::~CJS_EmbedObj()\r
48 {\r
49         m_pJSObject = NULL;\r
50 \r
51 }\r
52 \r
53 CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc)\r
54 {\r
55         return FXJS_GetPageView(cc);\r
56 }\r
57 \r
58 int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,FX_LPCWSTR swMsg,FX_LPCWSTR swTitle,FX_UINT nType,FX_UINT nIcon)\r
59 {\r
60         return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);\r
61 }\r
62 \r
63 void CJS_EmbedObj::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)\r
64 {\r
65         CJS_Object::Alert(pContext, swMsg);\r
66 }\r
67 \r
68 CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment * pApp,FX_UINT nElapse)\r
69 {\r
70         CJS_Timer* pTimer = new CJS_Timer(this,pApp);\r
71         pTimer->SetJSTimer(nElapse);\r
72         \r
73         return pTimer;\r
74 }\r
75 \r
76 void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer)\r
77 {\r
78         ASSERT(pTimer != NULL);\r
79         pTimer->KillJSTimer();\r
80         delete pTimer;\r
81 }\r
82 \r
83 FX_BOOL CJS_EmbedObj::IsSafeMode(IFXJS_Context* cc)\r
84 {\r
85         ASSERT(cc != NULL);\r
86 \r
87         return TRUE;\r
88 }\r
89 \r
90 /* ---------------------------------  CJS_Object --------------------------------- */\r
91 void  FreeObject(const v8::WeakCallbackData<v8::Object, CJS_Object>& data)\r
92 {\r
93         CJS_Object* pJSObj  = data.GetParameter();\r
94         if(pJSObj)\r
95         {\r
96                 pJSObj->ExitInstance();\r
97                 delete pJSObj;\r
98         }\r
99         v8::Local<v8::Object> obj = data.GetValue();\r
100         JS_FreePrivate(obj);\r
101 }\r
102 \r
103 CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL)\r
104 {\r
105         v8::Local<v8::Context> context = pObject->CreationContext();\r
106         m_pIsolate = context->GetIsolate();\r
107         m_pObject.Reset(m_pIsolate, pObject);\r
108 };\r
109 \r
110 CJS_Object::~CJS_Object(void)\r
111 {\r
112         delete m_pEmbedObj;\r
113         m_pEmbedObj = NULL;\r
114 \r
115         m_pObject.Reset();\r
116 };\r
117 \r
118 void    CJS_Object::MakeWeak()\r
119 {\r
120         m_pObject.SetWeak(this, FreeObject);\r
121 }\r
122 \r
123 CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc)\r
124 {\r
125         return FXJS_GetPageView(cc);\r
126 }\r
127 \r
128 int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)\r
129 {\r
130         return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);\r
131 }\r
132 \r
133 void CJS_Object::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)\r
134 {\r
135         ASSERT(pContext != NULL);\r
136 \r
137         if (pContext->IsMsgBoxEnabled())\r
138         {\r
139                 CPDFDoc_Environment* pApp = pContext->GetReaderApp();\r
140                 if(pApp)\r
141                         pApp->JS_appAlert(swMsg, NULL, 0, 3);\r
142         }\r
143 }\r
144 \r
145 \r