Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Side by Side Diff: fpdfsdk/src/javascript/app.cpp

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../third_party/base/nonstd_unique_ptr.h" 7 #include "../../../third_party/base/nonstd_unique_ptr.h"
8 #include "../../include/javascript/JavaScript.h" 8 #include "../../include/javascript/JavaScript.h"
9 #include "../../include/javascript/IJavaScript.h" 9 #include "../../include/javascript/IJavaScript.h"
10 #include "../../include/javascript/JS_Define.h" 10 #include "../../include/javascript/JS_Define.h"
11 #include "../../include/javascript/JS_Object.h" 11 #include "../../include/javascript/JS_Object.h"
12 #include "../../include/javascript/JS_Value.h" 12 #include "../../include/javascript/JS_Value.h"
13 #include "../../include/javascript/app.h" 13 #include "../../include/javascript/app.h"
14 #include "../../include/javascript/JS_EventHandler.h" 14 #include "../../include/javascript/JS_EventHandler.h"
15 #include "../../include/javascript/resource.h" 15 #include "../../include/javascript/resource.h"
16 #include "../../include/javascript/JS_Context.h" 16 #include "../../include/javascript/JS_Context.h"
17 #include "../../include/javascript/JS_Runtime.h" 17 #include "../../include/javascript/JS_Runtime.h"
18 #include "../../include/javascript/Document.h" 18 #include "../../include/javascript/Document.h"
19 19
20 static v8::Isolate* GetIsolate(IFXJS_Context* cc) {
21 CJS_Context* pContext = (CJS_Context*)cc;
22 ASSERT(pContext != NULL);
20 23
21 static v8::Isolate* GetIsolate(IFXJS_Context* cc) 24 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
22 { 25 ASSERT(pRuntime != NULL);
23 » CJS_Context* pContext = (CJS_Context *)cc;
24 » ASSERT(pContext != NULL);
25 26
26 » CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 27 return pRuntime->GetIsolate();
27 » ASSERT(pRuntime != NULL);
28
29 » return pRuntime->GetIsolate();
30 } 28 }
31 29
32 /* ---------------------------- TimerObj ---------------------------- */ 30 /* ---------------------------- TimerObj ---------------------------- */
33 31
34 BEGIN_JS_STATIC_CONST(CJS_TimerObj) 32 BEGIN_JS_STATIC_CONST(CJS_TimerObj)
35 END_JS_STATIC_CONST() 33 END_JS_STATIC_CONST()
36 34
37 BEGIN_JS_STATIC_PROP(CJS_TimerObj) 35 BEGIN_JS_STATIC_PROP(CJS_TimerObj)
38 END_JS_STATIC_PROP() 36 END_JS_STATIC_PROP()
39 37
40 BEGIN_JS_STATIC_METHOD(CJS_TimerObj) 38 BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
41 END_JS_STATIC_METHOD() 39 END_JS_STATIC_METHOD()
42 40
43 IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj) 41 IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
44 42
45 TimerObj::TimerObj(CJS_Object* pJSObject) 43 TimerObj::TimerObj(CJS_Object* pJSObject)
46 : CJS_EmbedObj(pJSObject), 44 : CJS_EmbedObj(pJSObject), m_pTimer(NULL) {}
47 m_pTimer(NULL)
48 {
49 45
46 TimerObj::~TimerObj() {}
47
48 void TimerObj::SetTimer(CJS_Timer* pTimer) {
49 m_pTimer = pTimer;
50 } 50 }
51 51
52 TimerObj::~TimerObj() 52 CJS_Timer* TimerObj::GetTimer() const {
53 { 53 return m_pTimer;
54 } 54 }
55 55
56 void TimerObj::SetTimer(CJS_Timer* pTimer) 56 #define JS_STR_VIEWERTYPE_READER L"Reader"
57 { 57 #define JS_STR_VIEWERTYPE_STANDARD L"Exchange"
58 » m_pTimer = pTimer; 58 #define JS_STR_VIEWERVARIATION L"Full"
59 } 59 #define JS_STR_PLATFORM L"WIN"
60 #define JS_STR_LANGUANGE L"ENU"
61 #define JS_STR_VIEWERVERSION 8
62 #define JS_NUM_FORMSVERSION 7
60 63
61 CJS_Timer* TimerObj::GetTimer() const 64 #define JS_FILEPATH_MAXLEN 2000
62 {
63 » return m_pTimer;
64 }
65
66 #define JS_STR_VIEWERTYPE_READER» » L"Reader"
67 #define JS_STR_VIEWERTYPE_STANDARD» » L"Exchange"
68 #define JS_STR_VIEWERVARIATION» » » L"Full"
69 #define JS_STR_PLATFORM»» » » » L"WIN"
70 #define JS_STR_LANGUANGE» » » » L"ENU"
71 #define JS_STR_VIEWERVERSION» » » 8
72 #define JS_NUM_FORMSVERSION» » » » 7
73
74 #define JS_FILEPATH_MAXLEN» » » » 2000
75 65
76 /* ---------------------------- app ---------------------------- */ 66 /* ---------------------------- app ---------------------------- */
77 67
78 BEGIN_JS_STATIC_CONST(CJS_App) 68 BEGIN_JS_STATIC_CONST(CJS_App)
79 END_JS_STATIC_CONST() 69 END_JS_STATIC_CONST()
80 70
81 BEGIN_JS_STATIC_PROP(CJS_App) 71 BEGIN_JS_STATIC_PROP(CJS_App)
82 » JS_STATIC_PROP_ENTRY(activeDocs) 72 JS_STATIC_PROP_ENTRY(activeDocs)
83 » JS_STATIC_PROP_ENTRY(calculate) 73 JS_STATIC_PROP_ENTRY(calculate)
84 » JS_STATIC_PROP_ENTRY(formsVersion) 74 JS_STATIC_PROP_ENTRY(formsVersion)
85 » JS_STATIC_PROP_ENTRY(fs) 75 JS_STATIC_PROP_ENTRY(fs)
86 » JS_STATIC_PROP_ENTRY(fullscreen) 76 JS_STATIC_PROP_ENTRY(fullscreen)
87 » JS_STATIC_PROP_ENTRY(language) 77 JS_STATIC_PROP_ENTRY(language)
88 » JS_STATIC_PROP_ENTRY(media) 78 JS_STATIC_PROP_ENTRY(media)
89 » JS_STATIC_PROP_ENTRY(platform) 79 JS_STATIC_PROP_ENTRY(platform)
90 » JS_STATIC_PROP_ENTRY(runtimeHighlight) 80 JS_STATIC_PROP_ENTRY(runtimeHighlight)
91 » JS_STATIC_PROP_ENTRY(viewerType) 81 JS_STATIC_PROP_ENTRY(viewerType)
92 » JS_STATIC_PROP_ENTRY(viewerVariation) 82 JS_STATIC_PROP_ENTRY(viewerVariation)
93 » JS_STATIC_PROP_ENTRY(viewerVersion) 83 JS_STATIC_PROP_ENTRY(viewerVersion)
94 END_JS_STATIC_PROP() 84 END_JS_STATIC_PROP()
95 85
96 BEGIN_JS_STATIC_METHOD(CJS_App) 86 BEGIN_JS_STATIC_METHOD(CJS_App)
97 » JS_STATIC_METHOD_ENTRY(alert) 87 JS_STATIC_METHOD_ENTRY(alert)
98 » JS_STATIC_METHOD_ENTRY(beep) 88 JS_STATIC_METHOD_ENTRY(beep)
99 » JS_STATIC_METHOD_ENTRY(browseForDoc) 89 JS_STATIC_METHOD_ENTRY(browseForDoc)
100 » JS_STATIC_METHOD_ENTRY(clearInterval) 90 JS_STATIC_METHOD_ENTRY(clearInterval)
101 » JS_STATIC_METHOD_ENTRY(clearTimeOut) 91 JS_STATIC_METHOD_ENTRY(clearTimeOut)
102 » JS_STATIC_METHOD_ENTRY(execDialog) 92 JS_STATIC_METHOD_ENTRY(execDialog)
103 » JS_STATIC_METHOD_ENTRY(execMenuItem) 93 JS_STATIC_METHOD_ENTRY(execMenuItem)
104 » JS_STATIC_METHOD_ENTRY(findComponent) 94 JS_STATIC_METHOD_ENTRY(findComponent)
105 » JS_STATIC_METHOD_ENTRY(goBack) 95 JS_STATIC_METHOD_ENTRY(goBack)
106 » JS_STATIC_METHOD_ENTRY(goForward) 96 JS_STATIC_METHOD_ENTRY(goForward)
107 » JS_STATIC_METHOD_ENTRY(launchURL) 97 JS_STATIC_METHOD_ENTRY(launchURL)
108 » JS_STATIC_METHOD_ENTRY(mailMsg) 98 JS_STATIC_METHOD_ENTRY(mailMsg)
109 » JS_STATIC_METHOD_ENTRY(newFDF) 99 JS_STATIC_METHOD_ENTRY(newFDF)
110 » JS_STATIC_METHOD_ENTRY(newDoc) 100 JS_STATIC_METHOD_ENTRY(newDoc)
111 » JS_STATIC_METHOD_ENTRY(openDoc) 101 JS_STATIC_METHOD_ENTRY(openDoc)
112 » JS_STATIC_METHOD_ENTRY(openFDF) 102 JS_STATIC_METHOD_ENTRY(openFDF)
113 » JS_STATIC_METHOD_ENTRY(popUpMenuEx) 103 JS_STATIC_METHOD_ENTRY(popUpMenuEx)
114 » JS_STATIC_METHOD_ENTRY(popUpMenu) 104 JS_STATIC_METHOD_ENTRY(popUpMenu)
115 » JS_STATIC_METHOD_ENTRY(response) 105 JS_STATIC_METHOD_ENTRY(response)
116 » JS_STATIC_METHOD_ENTRY(setInterval) 106 JS_STATIC_METHOD_ENTRY(setInterval)
117 » JS_STATIC_METHOD_ENTRY(setTimeOut) 107 JS_STATIC_METHOD_ENTRY(setTimeOut)
118 END_JS_STATIC_METHOD() 108 END_JS_STATIC_METHOD()
119 109
120 IMPLEMENT_JS_CLASS(CJS_App,app) 110 IMPLEMENT_JS_CLASS(CJS_App, app)
121 111
122 app::app(CJS_Object * pJSObject) 112 app::app(CJS_Object* pJSObject)
123 : CJS_EmbedObj(pJSObject), 113 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {}
124 m_bCalculate(true), 114
125 m_bRuntimeHighLight(false) 115 app::~app(void) {
126 { 116 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++)
127 } 117 delete m_aTimer[i];
128 118
129 app::~app(void) 119 m_aTimer.RemoveAll();
130 { 120 }
131 » for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++) 121
132 » » delete m_aTimer[i]; 122 FX_BOOL app::activeDocs(IFXJS_Context* cc,
133 123 CJS_PropValue& vp,
134 » m_aTimer.RemoveAll(); 124 CFX_WideString& sError) {
135 } 125 if (!vp.IsGetting())
136 126 return FALSE;
137 FX_BOOL app::activeDocs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE rror) 127
138 { 128 CJS_Context* pContext = (CJS_Context*)cc;
139 if (!vp.IsGetting()) 129 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
140 return FALSE; 130 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
141 131 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
142 CJS_Context* pContext = (CJS_Context *)cc; 132 CJS_Array aDocs(pRuntime->GetIsolate());
133 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) {
134 CJS_Document* pJSDocument = NULL;
135 if (pDoc == pCurDoc) {
136 JSFXObject pObj = JS_GetThisObj(*pRuntime);
137 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document"))
138 pJSDocument =
139 (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(), pObj);
140 } else {
141 JSFXObject pObj = JS_NewFxDynamicObj(
142 *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Document"));
143 pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(), pObj);
144 ASSERT(pJSDocument != NULL);
145 }
146 aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument));
147 }
148 if (aDocs.GetLength() > 0)
149 vp << aDocs;
150 else
151 vp.SetNull();
152
153 return TRUE;
154 }
155
156 FX_BOOL app::calculate(IFXJS_Context* cc,
157 CJS_PropValue& vp,
158 CFX_WideString& sError) {
159 if (vp.IsSetting()) {
160 bool bVP;
161 vp >> bVP;
162 m_bCalculate = (FX_BOOL)bVP;
163
164 CJS_Context* pContext = (CJS_Context*)cc;
143 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 165 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
144 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 166 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
145 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
146 CJS_Array aDocs(pRuntime->GetIsolate()); 167 CJS_Array aDocs(pRuntime->GetIsolate());
147 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) 168 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
169 pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate);
170 } else {
171 vp << (bool)m_bCalculate;
172 }
173 return TRUE;
174 }
175
176 FX_BOOL app::formsVersion(IFXJS_Context* cc,
177 CJS_PropValue& vp,
178 CFX_WideString& sError) {
179 if (vp.IsGetting()) {
180 vp << JS_NUM_FORMSVERSION;
181 return TRUE;
182 }
183
184 return FALSE;
185 }
186
187 FX_BOOL app::viewerType(IFXJS_Context* cc,
188 CJS_PropValue& vp,
189 CFX_WideString& sError) {
190 if (vp.IsGetting()) {
191 vp << L"unknown";
192 return TRUE;
193 }
194
195 return FALSE;
196 }
197
198 FX_BOOL app::viewerVariation(IFXJS_Context* cc,
199 CJS_PropValue& vp,
200 CFX_WideString& sError) {
201 if (vp.IsGetting()) {
202 vp << JS_STR_VIEWERVARIATION;
203 return TRUE;
204 }
205
206 return FALSE;
207 }
208
209 FX_BOOL app::viewerVersion(IFXJS_Context* cc,
210 CJS_PropValue& vp,
211 CFX_WideString& sError) {
212 if (vp.IsGetting()) {
213 vp << JS_STR_VIEWERVERSION;
214 return TRUE;
215 }
216
217 return FALSE;
218 }
219
220 FX_BOOL app::platform(IFXJS_Context* cc,
221 CJS_PropValue& vp,
222 CFX_WideString& sError) {
223 if (vp.IsGetting()) {
224 vp << JS_STR_PLATFORM;
225 return TRUE;
226 }
227
228 return FALSE;
229 }
230
231 FX_BOOL app::language(IFXJS_Context* cc,
232 CJS_PropValue& vp,
233 CFX_WideString& sError) {
234 if (vp.IsGetting()) {
235 vp << JS_STR_LANGUANGE;
236 return TRUE;
237 }
238
239 return FALSE;
240 }
241
242 // creates a new fdf object that contains no data
243 // comment: need reader support
244 // note:
245 // CFDF_Document * CPDFDoc_Environment::NewFDF();
246 FX_BOOL app::newFDF(IFXJS_Context* cc,
247 const CJS_Parameters& params,
248 CJS_Value& vRet,
249 CFX_WideString& sError) {
250 return TRUE;
251 }
252 // opens a specified pdf document and returns its document object
253 // comment:need reader support
254 // note: as defined in js reference, the proto of this function's fourth
255 // parmeters, how old an fdf document while do not show it.
256 // CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
257
258 FX_BOOL app::openFDF(IFXJS_Context* cc,
259 const CJS_Parameters& params,
260 CJS_Value& vRet,
261 CFX_WideString& sError) {
262 return TRUE;
263 }
264
265 FX_BOOL app::alert(IFXJS_Context* cc,
266 const CJS_Parameters& params,
267 CJS_Value& vRet,
268 CFX_WideString& sError) {
269 int iSize = params.size();
270 if (iSize < 1)
271 return FALSE;
272
273 CFX_WideString swMsg = L"";
274 CFX_WideString swTitle = L"";
275 int iIcon = 0;
276 int iType = 0;
277
278 v8::Isolate* isolate = GetIsolate(cc);
279
280 if (iSize == 1) {
281 if (params[0].GetType() == VT_object) {
282 JSObject pObj = params[0].ToV8Object();
283 {
284 v8::Local<v8::Value> pValue =
285 JS_GetObjectElement(isolate, pObj, L"cMsg");
286 swMsg = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString();
287
288 pValue = JS_GetObjectElement(isolate, pObj, L"cTitle");
289 swTitle = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString();
290
291 pValue = JS_GetObjectElement(isolate, pObj, L"nIcon");
292 iIcon = CJS_Value(isolate, pValue, VT_unknown).ToInt();
293
294 pValue = JS_GetObjectElement(isolate, pObj, L"nType");
295 iType = CJS_Value(isolate, pValue, VT_unknown).ToInt();
296 }
297
298 if (swMsg == L"") {
299 CJS_Array carray(isolate);
300 if (params[0].ConvertToArray(carray)) {
301 int iLenth = carray.GetLength();
302 CJS_Value* pValue = new CJS_Value(isolate);
303 // if (iLenth == 1)
304 // pValue = new
305 //CJS_Value(isolate);
306 // else if (iLenth > 1)
307 // pValue = new
308 //CJS_Value[iLenth];
309
310 for (int i = 0; i < iLenth; i++) {
311 carray.GetElement(i, *pValue);
312 swMsg += (*pValue).ToCFXWideString();
313 if (i < iLenth - 1)
314 swMsg += L", ";
315 }
316
317 delete pValue;
318 }
319 }
320
321 if (swTitle == L"")
322 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
323 } else if (params[0].GetType() == VT_boolean) {
324 FX_BOOL bGet = params[0].ToBool();
325 if (bGet)
326 swMsg = L"true";
327 else
328 swMsg = L"false";
329
330 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
331 } else {
332 swMsg = params[0].ToCFXWideString();
333 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
334 }
335 } else {
336 if (params[0].GetType() == VT_boolean) {
337 FX_BOOL bGet = params[0].ToBool();
338 if (bGet)
339 swMsg = L"true";
340 else
341 swMsg = L"false";
342 } else {
343 swMsg = params[0].ToCFXWideString();
344 }
345 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
346
347 for (int i = 1; i < iSize; i++) {
348 if (i == 1)
349 iIcon = params[i].ToInt();
350 if (i == 2)
351 iType = params[i].ToInt();
352 if (i == 3)
353 swTitle = params[i].ToCFXWideString();
354 }
355 }
356
357 CJS_Context* pContext = (CJS_Context*)cc;
358 ASSERT(pContext != NULL);
359 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
360 ASSERT(pRuntime != NULL);
361 pRuntime->BeginBlock();
362 vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc), swMsg.c_str(),
363 swTitle.c_str(), iType, iIcon);
364 pRuntime->EndBlock();
365
366 return TRUE;
367 }
368
369 FX_BOOL app::beep(IFXJS_Context* cc,
370 const CJS_Parameters& params,
371 CJS_Value& vRet,
372 CFX_WideString& sError) {
373 if (params.size() == 1) {
374 CJS_Context* pContext = (CJS_Context*)cc;
375 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
376 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
377 pEnv->JS_appBeep(params[0].ToInt());
378 return TRUE;
379 }
380
381 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
382 return FALSE;
383 }
384
385 FX_BOOL app::findComponent(IFXJS_Context* cc,
386 const CJS_Parameters& params,
387 CJS_Value& vRet,
388 CFX_WideString& sError) {
389 return TRUE;
390 }
391
392 FX_BOOL app::popUpMenuEx(IFXJS_Context* cc,
393 const CJS_Parameters& params,
394 CJS_Value& vRet,
395 CFX_WideString& sError) {
396 return FALSE;
397 }
398
399 FX_BOOL app::fs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
400 return FALSE;
401 }
402
403 FX_BOOL app::setInterval(IFXJS_Context* cc,
404 const CJS_Parameters& params,
405 CJS_Value& vRet,
406 CFX_WideString& sError) {
407 CJS_Context* pContext = (CJS_Context*)cc;
408 if (params.size() > 2 || params.size() == 0) {
409 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
410 return FALSE;
411 }
412
413 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
414 if (script.IsEmpty()) {
415 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
416 return TRUE;
417 }
418
419 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
420 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000;
421
422 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
423 ASSERT(pApp);
424 CJS_Timer* pTimer = new CJS_Timer(this, pApp);
425 m_aTimer.Add(pTimer);
426
427 pTimer->SetType(0);
428 pTimer->SetRuntime(pRuntime);
429 pTimer->SetJScript(script);
430 pTimer->SetTimeOut(0);
431 // pTimer->SetStartTime(GetTickCount());
432 pTimer->SetJSTimer(dwInterval);
433
434 JSFXObject pRetObj = JS_NewFxDynamicObj(
435 *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
436
437 CJS_TimerObj* pJS_TimerObj =
438 (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
439 ASSERT(pJS_TimerObj != NULL);
440
441 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
442 ASSERT(pTimerObj != NULL);
443
444 pTimerObj->SetTimer(pTimer);
445
446 vRet = pRetObj;
447
448 return TRUE;
449 }
450
451 FX_BOOL app::setTimeOut(IFXJS_Context* cc,
452 const CJS_Parameters& params,
453 CJS_Value& vRet,
454 CFX_WideString& sError) {
455 if (params.size() > 2 || params.size() == 0) {
456 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
457 return FALSE;
458 }
459
460 CJS_Context* pContext = (CJS_Context*)cc;
461 ASSERT(pContext != NULL);
462 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
463 ASSERT(pRuntime != NULL);
464
465 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
466 if (script.IsEmpty()) {
467 sError =
468 JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
469 return TRUE;
470 }
471
472 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
473
474 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
475 ASSERT(pApp);
476
477 CJS_Timer* pTimer = new CJS_Timer(this, pApp);
478 m_aTimer.Add(pTimer);
479
480 pTimer->SetType(1);
481 pTimer->SetRuntime(pRuntime);
482 pTimer->SetJScript(script);
483 pTimer->SetTimeOut(dwTimeOut);
484 pTimer->SetJSTimer(dwTimeOut);
485
486 JSFXObject pRetObj = JS_NewFxDynamicObj(
487 *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
488
489 CJS_TimerObj* pJS_TimerObj =
490 (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
491 ASSERT(pJS_TimerObj != NULL);
492
493 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
494 ASSERT(pTimerObj != NULL);
495
496 pTimerObj->SetTimer(pTimer);
497
498 vRet = pRetObj;
499
500 return TRUE;
501 }
502
503 FX_BOOL app::clearTimeOut(IFXJS_Context* cc,
504 const CJS_Parameters& params,
505 CJS_Value& vRet,
506 CFX_WideString& sError) {
507 CJS_Context* pContext = (CJS_Context*)cc;
508 ASSERT(pContext != NULL);
509 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
510 ASSERT(pRuntime != NULL);
511
512 if (params.size() != 1) {
513 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
514 return FALSE;
515 }
516
517 if (params[0].GetType() == VT_fxobject) {
518 JSFXObject pObj = params[0].ToV8Object();
148 { 519 {
149 CJS_Document* pJSDocument = NULL; 520 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) {
150 if (pDoc == pCurDoc) 521 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
151 { 522 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
152 JSFXObject pObj = JS_GetThisObj(*pRuntime); 523 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
153 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document") ) 524 pTimer->KillJSTimer();
154 pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate( ),pObj); 525
526 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
527 if (m_aTimer[i] == pTimer) {
528 m_aTimer.RemoveAt(i);
529 break;
530 }
531 }
532
533 delete pTimer;
534 pTimerObj->SetTimer(NULL);
535 }
536 }
155 } 537 }
156 else 538 }
157 { 539 }
158 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjD efnID(*pRuntime,L"Document")); 540 }
159 pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pO bj); 541
160 ASSERT(pJSDocument != NULL); 542 return TRUE;
543 }
544
545 FX_BOOL app::clearInterval(IFXJS_Context* cc,
546 const CJS_Parameters& params,
547 CJS_Value& vRet,
548 CFX_WideString& sError) {
549 CJS_Context* pContext = (CJS_Context*)cc;
550 ASSERT(pContext != NULL);
551 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
552 ASSERT(pRuntime != NULL);
553
554 if (params.size() != 1) {
555 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
556 return FALSE;
557 }
558
559 if (params[0].GetType() == VT_fxobject) {
560 JSFXObject pObj = params[0].ToV8Object();
561 {
562 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) {
563 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
564 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
565 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
566 pTimer->KillJSTimer();
567
568 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
569 if (m_aTimer[i] == pTimer) {
570 m_aTimer.RemoveAt(i);
571 break;
572 }
573 }
574
575 delete pTimer;
576 pTimerObj->SetTimer(NULL);
577 }
578 }
161 } 579 }
162 aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument)); 580 }
163 } 581 }
164 if (aDocs.GetLength() > 0) 582 }
165 vp << aDocs; 583
166 else 584 return TRUE;
167 vp.SetNull(); 585 }
168 586
169 return TRUE; 587 FX_BOOL app::execMenuItem(IFXJS_Context* cc,
170 } 588 const CJS_Parameters& params,
171 589 CJS_Value& vRet,
172 FX_BOOL app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr ror) 590 CFX_WideString& sError) {
173 { 591 return FALSE;
174 if (vp.IsSetting()) 592 }
175 { 593
176 bool bVP; 594 void app::TimerProc(CJS_Timer* pTimer) {
177 vp >> bVP; 595 ASSERT(pTimer != NULL);
178 m_bCalculate = (FX_BOOL)bVP; 596
179 597 switch (pTimer->GetType()) {
180 CJS_Context* pContext = (CJS_Context*)cc; 598 case 0: // interval
181 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 599 RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
182 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 600 break;
183 CJS_Array aDocs(pRuntime->GetIsolate()); 601 case 1:
184 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) 602 if (pTimer->GetTimeOut() > 0) {
185 pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalcul ate); 603 RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
186 } 604 pTimer->KillJSTimer();
187 else 605 }
188 { 606 break;
189 vp << (bool)m_bCalculate; 607 }
190 } 608 }
191 return TRUE; 609
192 } 610 void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
193 611 ASSERT(pRuntime != NULL);
194 FX_BOOL app::formsVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 612
195 { 613 if (!pRuntime->IsBlocking()) {
196 if (vp.IsGetting()) 614 IFXJS_Context* pContext = pRuntime->NewContext();
197 { 615 ASSERT(pContext != NULL);
198 vp << JS_NUM_FORMSVERSION; 616 pContext->OnExternal_Exec();
199 return TRUE; 617 CFX_WideString wtInfo;
200 } 618 pContext->RunScript(wsScript, wtInfo);
201 619 pRuntime->ReleaseContext(pContext);
202 return FALSE; 620 }
203 } 621 }
204 622
205 FX_BOOL app::viewerType(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE rror) 623 FX_BOOL app::goBack(IFXJS_Context* cc,
206 { 624 const CJS_Parameters& params,
207 if (vp.IsGetting()) 625 CJS_Value& vRet,
208 { 626 CFX_WideString& sError) {
209 vp << L"unknown";
210 return TRUE;
211 }
212
213 return FALSE;
214 }
215
216 FX_BOOL app::viewerVariation(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideStrin g& sError)
217 {
218 if (vp.IsGetting())
219 {
220 vp << JS_STR_VIEWERVARIATION;
221 return TRUE;
222 }
223
224 return FALSE;
225 }
226
227 FX_BOOL app::viewerVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
228 {
229 if (vp.IsGetting())
230 {
231 vp << JS_STR_VIEWERVERSION;
232 return TRUE;
233 }
234
235 return FALSE;
236 }
237
238 FX_BOOL app::platform(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sErr or)
239 {
240 if (vp.IsGetting())
241 {
242 vp << JS_STR_PLATFORM;
243 return TRUE;
244 }
245
246 return FALSE;
247 }
248
249 FX_BOOL app::language(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sErr or)
250 {
251 if (vp.IsGetting())
252 {
253 vp << JS_STR_LANGUANGE;
254 return TRUE;
255 }
256
257 return FALSE;
258 }
259
260 //creates a new fdf object that contains no data
261 //comment: need reader support
262 //note:
263 //CFDF_Document * CPDFDoc_Environment::NewFDF();
264 FX_BOOL app::newFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
265 {
266 return TRUE;
267 }
268 //opens a specified pdf document and returns its document object
269 //comment:need reader support
270 //note: as defined in js reference, the proto of this function's fourth parmeter s, how old an fdf document while do not show it.
271 //CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
272
273 FX_BOOL app::openFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
274 {
275 return TRUE;
276 }
277
278 FX_BOOL app::alert(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& v Ret, CFX_WideString& sError)
279 {
280 int iSize = params.size();
281 if (iSize < 1)
282 return FALSE;
283
284 CFX_WideString swMsg = L"";
285 CFX_WideString swTitle = L"";
286 int iIcon = 0;
287 int iType = 0;
288
289 v8::Isolate* isolate = GetIsolate(cc);
290
291 if (iSize == 1)
292 {
293 if (params[0].GetType() == VT_object)
294 {
295 JSObject pObj = params[0].ToV8Object();
296 {
297 v8::Local<v8::Value> pValue = JS_GetObjectElemen t(isolate, pObj, L"cMsg");
298 swMsg = CJS_Value(isolate, pValue, VT_unknown).T oCFXWideString();
299
300 pValue = JS_GetObjectElement(isolate, pObj, L"cT itle");
301 swTitle = CJS_Value(isolate, pValue, VT_unknown) .ToCFXWideString();
302
303 pValue = JS_GetObjectElement(isolate, pObj, L"nI con");
304 iIcon = CJS_Value(isolate, pValue, VT_unknown).T oInt();
305
306 pValue = JS_GetObjectElement(isolate, pObj, L"nT ype");
307 iType = CJS_Value(isolate, pValue, VT_unknown).T oInt();
308 }
309
310 if (swMsg == L"")
311 {
312 CJS_Array carray(isolate);
313 if (params[0].ConvertToArray(carray))
314 {
315 int iLenth = carray.GetLength();
316 CJS_Value* pValue = new CJS_Value(isolat e);
317 // if (iLenth == 1)
318 // pValue = new CJS_Value(isolate);
319 // else if (iLenth > 1)
320 // pValue = new CJS_Value[iLenth];
321
322 for(int i = 0; i < iLenth; i++)
323 {
324 carray.GetElement(i, *pValue);
325 swMsg += (*pValue).ToCFXWideStri ng();
326 if (i < iLenth - 1)
327 swMsg += L", ";
328 }
329
330 delete pValue;
331 }
332 }
333
334 if (swTitle == L"")
335 swTitle = JSGetStringFromID((CJS_Context*)cc, ID S_STRING_JSALERT);
336 }
337 else if (params[0].GetType() == VT_boolean)
338 {
339 FX_BOOL bGet = params[0].ToBool();
340 if (bGet)
341 swMsg = L"true";
342 else
343 swMsg = L"false";
344
345 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING _JSALERT);
346 }
347 else
348 {
349 swMsg = params[0].ToCFXWideString();
350 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING _JSALERT);
351 }
352 }
353 else
354 {
355 if (params[0].GetType() == VT_boolean)
356 {
357 FX_BOOL bGet = params[0].ToBool();
358 if (bGet)
359 swMsg = L"true";
360 else
361 swMsg = L"false";
362 }
363 else
364 {
365 swMsg = params[0].ToCFXWideString();
366 }
367 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT );
368
369 for(int i = 1;i<iSize;i++)
370 {
371 if (i == 1)
372 iIcon = params[i].ToInt();
373 if (i == 2)
374 iType = params[i].ToInt();
375 if (i == 3)
376 swTitle = params[i].ToCFXWideString();
377 }
378 }
379
380
381 CJS_Context* pContext = (CJS_Context*)cc;
382 ASSERT(pContext != NULL);
383 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
384 ASSERT(pRuntime != NULL);
385 pRuntime->BeginBlock();
386 vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc), swMsg.c_str() , swTitle.c_str(), iType, iIcon);
387 pRuntime->EndBlock();
388
389 return TRUE;
390 }
391
392
393 FX_BOOL app::beep(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vR et, CFX_WideString& sError)
394 {
395 if (params.size() == 1)
396 {
397 CJS_Context* pContext = (CJS_Context*)cc;
398 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
399 CPDFDoc_Environment * pEnv = pRuntime->GetReaderApp();
400 pEnv->JS_appBeep(params[0].ToInt());
401 return TRUE;
402 }
403
404 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
405 return FALSE;
406 }
407
408 FX_BOOL app::findComponent(IFXJS_Context* cc, const CJS_Parameters& params, CJS_ Value& vRet, CFX_WideString& sError)
409 {
410 return TRUE;
411 }
412
413 FX_BOOL app::popUpMenuEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va lue& vRet, CFX_WideString& sError)
414 {
415 return FALSE;
416 }
417
418 FX_BOOL app::fs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
419 {
420 return FALSE;
421 }
422
423 FX_BOOL app::setInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va lue& vRet, CFX_WideString& sError)
424 {
425 CJS_Context* pContext = (CJS_Context*)cc;
426 if (params.size() > 2 || params.size() == 0)
427 {
428 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
429 return FALSE;
430 }
431
432 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
433 if (script.IsEmpty())
434 {
435 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYST ROKE);
436 return TRUE;
437 }
438
439 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
440 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000;
441
442 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
443 ASSERT(pApp);
444 CJS_Timer* pTimer = new CJS_Timer(this, pApp);
445 m_aTimer.Add(pTimer);
446
447 pTimer->SetType(0);
448 pTimer->SetRuntime(pRuntime);
449 pTimer->SetJScript(script);
450 pTimer->SetTimeOut(0);
451 // pTimer->SetStartTime(GetTickCount());
452 pTimer->SetJSTimer(dwInterval);
453
454 JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDe fnID(*pRuntime, L"TimerObj"));
455
456 CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetI solate(),pRetObj);
457 ASSERT(pJS_TimerObj != NULL);
458
459 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
460 ASSERT(pTimerObj != NULL);
461
462 pTimerObj->SetTimer(pTimer);
463
464 vRet = pRetObj;
465
466 return TRUE;
467 }
468
469 FX_BOOL app::setTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Val ue& vRet, CFX_WideString& sError)
470 {
471 if (params.size() > 2 || params.size() == 0)
472 {
473 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAME RROR);
474 return FALSE;
475 }
476
477 CJS_Context* pContext = (CJS_Context*)cc;
478 ASSERT(pContext != NULL);
479 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
480 ASSERT(pRuntime != NULL);
481
482 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
483 if (script.IsEmpty())
484 {
485 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMB ER_KEYSTROKE);
486 return TRUE;
487 }
488
489 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
490
491 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
492 ASSERT(pApp);
493
494 CJS_Timer* pTimer = new CJS_Timer(this, pApp);
495 m_aTimer.Add(pTimer);
496
497 pTimer->SetType(1);
498 pTimer->SetRuntime(pRuntime);
499 pTimer->SetJScript(script);
500 pTimer->SetTimeOut(dwTimeOut);
501 pTimer->SetJSTimer(dwTimeOut);
502
503 JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDe fnID(*pRuntime, L"TimerObj"));
504
505 CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetI solate(),pRetObj);
506 ASSERT(pJS_TimerObj != NULL);
507
508 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
509 ASSERT(pTimerObj != NULL);
510
511 pTimerObj->SetTimer(pTimer);
512
513 vRet = pRetObj;
514
515 return TRUE;
516 }
517
518 FX_BOOL app::clearTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError)
519 {
520 CJS_Context* pContext = (CJS_Context*)cc;
521 ASSERT(pContext != NULL);
522 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
523 ASSERT(pRuntime != NULL);
524
525 if (params.size() != 1)
526 {
527 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAME RROR);
528 return FALSE;
529 }
530
531 if (params[0].GetType() == VT_fxobject)
532 {
533 JSFXObject pObj = params[0].ToV8Object();
534 {
535 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
536 {
537 if (CJS_Object* pJSObj = params[0].ToCJSObject() )
538 {
539 if (TimerObj* pTimerObj = (TimerObj*)pJS Obj->GetEmbedObject())
540 {
541 if (CJS_Timer* pTimer = pTimerOb j->GetTimer())
542 {
543 pTimer->KillJSTimer();
544
545 for (int i=0,sz=m_aTimer .GetSize(); i<sz; i++)
546 {
547 if (m_aTimer[i] == pTimer)
548 {
549 m_aTimer .RemoveAt(i);
550 break;
551 }
552 }
553
554 delete pTimer;
555 pTimerObj->SetTimer(NULL );
556 }
557 }
558 }
559 }
560 }
561 }
562
563 return TRUE;
564 }
565
566 FX_BOOL app::clearInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_ Value& vRet, CFX_WideString& sError)
567 {
568 CJS_Context* pContext = (CJS_Context*)cc;
569 ASSERT(pContext != NULL);
570 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
571 ASSERT(pRuntime != NULL);
572
573 if (params.size() != 1)
574 {
575 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAME RROR);
576 return FALSE;
577 }
578
579 if (params[0].GetType() == VT_fxobject)
580 {
581 JSFXObject pObj = params[0].ToV8Object();
582 {
583 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
584 {
585 if (CJS_Object* pJSObj = params[0].ToCJSObject() )
586 {
587 if (TimerObj* pTimerObj = (TimerObj*)pJS Obj->GetEmbedObject())
588 {
589 if (CJS_Timer* pTimer = pTimerOb j->GetTimer())
590 {
591 pTimer->KillJSTimer();
592
593 for (int i=0,sz=m_aTimer .GetSize(); i<sz; i++)
594 {
595 if (m_aTimer[i] == pTimer)
596 {
597 m_aTimer .RemoveAt(i);
598 break;
599 }
600 }
601
602 delete pTimer;
603 pTimerObj->SetTimer(NULL );
604 }
605 }
606 }
607 }
608 }
609 }
610
611 return TRUE;
612 }
613
614 FX_BOOL app::execMenuItem(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError)
615 {
616 return FALSE;
617 }
618
619 void app::TimerProc(CJS_Timer* pTimer)
620 {
621 ASSERT(pTimer != NULL);
622
623 switch (pTimer->GetType())
624 {
625 case 0: //interval
626 RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
627 break;
628 case 1:
629 if (pTimer->GetTimeOut() > 0)
630 {
631 RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
632 pTimer->KillJSTimer();
633 }
634 break;
635 }
636
637 }
638
639 void app::RunJsScript(CJS_Runtime* pRuntime,const CFX_WideString& wsScript)
640 {
641 ASSERT(pRuntime != NULL);
642
643 if (!pRuntime->IsBlocking())
644 {
645 IFXJS_Context* pContext = pRuntime->NewContext();
646 ASSERT(pContext != NULL);
647 pContext->OnExternal_Exec();
648 CFX_WideString wtInfo;
649 pContext->RunScript(wsScript,wtInfo);
650 pRuntime->ReleaseContext(pContext);
651 }
652 }
653
654 FX_BOOL app::goBack(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
655 {
656 // Not supported. 627 // Not supported.
657 return TRUE; 628 return TRUE;
658 } 629 }
659 630
660 FX_BOOL app::goForward(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError) 631 FX_BOOL app::goForward(IFXJS_Context* cc,
661 { 632 const CJS_Parameters& params,
633 CJS_Value& vRet,
634 CFX_WideString& sError) {
662 // Not supported. 635 // Not supported.
663 return TRUE; 636 return TRUE;
664 } 637 }
665 638
666 FX_BOOL app::mailMsg(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) 639 FX_BOOL app::mailMsg(IFXJS_Context* cc,
667 { 640 const CJS_Parameters& params,
668 » CJS_Context* pContext = (CJS_Context*)cc; 641 CJS_Value& vRet,
669 » v8::Isolate* isolate = GetIsolate(cc); 642 CFX_WideString& sError) {
670 643 CJS_Context* pContext = (CJS_Context*)cc;
671 » FX_BOOL bUI = TRUE; 644 v8::Isolate* isolate = GetIsolate(cc);
672 » CFX_WideString cTo = L""; 645
673 » CFX_WideString cCc = L""; 646 FX_BOOL bUI = TRUE;
674 » CFX_WideString cBcc = L""; 647 CFX_WideString cTo = L"";
675 » CFX_WideString cSubject = L""; 648 CFX_WideString cCc = L"";
676 » CFX_WideString cMsg = L""; 649 CFX_WideString cBcc = L"";
677 650 CFX_WideString cSubject = L"";
678 » if (params.size() < 1) 651 CFX_WideString cMsg = L"";
679 » » return FALSE; 652
680 653 if (params.size() < 1)
681 » if (params[0].GetType() == VT_object) 654 return FALSE;
682 » { 655
683 » » JSObject pObj = params[0].ToV8Object(); 656 if (params[0].GetType() == VT_object) {
684 657 JSObject pObj = params[0].ToV8Object();
685 » » v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI"); 658
686 » » bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool( ); 659 v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI");
687 660 bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
688 » » pValue = JS_GetObjectElement(isolate, pObj, L"cTo"); 661
689 » » cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWi deString(); 662 pValue = JS_GetObjectElement(isolate, pObj, L"cTo");
690 663 cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
691 » » pValue = JS_GetObjectElement(isolate, pObj, L"cCc"); 664
692 » » cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWi deString(); 665 pValue = JS_GetObjectElement(isolate, pObj, L"cCc");
693 666 cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
694 » » pValue = JS_GetObjectElement(isolate, pObj, L"cBcc"); 667
695 » » cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXW ideString(); 668 pValue = JS_GetObjectElement(isolate, pObj, L"cBcc");
696 669 cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
697 » » pValue = JS_GetObjectElement(isolate, pObj, L"cSubject"); 670
698 » » cSubject = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).To CFXWideString(); 671 pValue = JS_GetObjectElement(isolate, pObj, L"cSubject");
699 672 cSubject =
700 » » pValue = JS_GetObjectElement(isolate, pObj, L"cMsg"); 673 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
701 » » cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXW ideString(); 674
702 » } else { 675 pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
703 » » if (params.size() < 2) 676 cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
704 » » » return FALSE; 677 } else {
705 678 if (params.size() < 2)
706 » » bUI = params[0].ToBool(); 679 return FALSE;
707 » » cTo = params[1].ToCFXWideString(); 680
708 681 bUI = params[0].ToBool();
709 » » if (params.size() >= 3) 682 cTo = params[1].ToCFXWideString();
710 » » » cCc = params[2].ToCFXWideString(); 683
711 » » if (params.size() >= 4) 684 if (params.size() >= 3)
712 » » » cBcc = params[3].ToCFXWideString(); 685 cCc = params[2].ToCFXWideString();
713 » » if (params.size() >= 5) 686 if (params.size() >= 4)
714 » » » cSubject = params[4].ToCFXWideString(); 687 cBcc = params[3].ToCFXWideString();
715 » » if (params.size() >= 6) 688 if (params.size() >= 5)
716 » » » cMsg = params[5].ToCFXWideString(); 689 cSubject = params[4].ToCFXWideString();
717 » } 690 if (params.size() >= 6)
718 691 cMsg = params[5].ToCFXWideString();
719 » CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 692 }
720 » ASSERT(pRuntime != NULL); 693
721 694 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
722 » CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 695 ASSERT(pRuntime != NULL);
723 » ASSERT(pApp != NULL); 696
724 697 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
725 » pRuntime->BeginBlock(); 698 ASSERT(pApp != NULL);
726 » pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_ str(), cBcc.c_str(), cMsg.c_str()); 699
727 » pRuntime->EndBlock(); 700 pRuntime->BeginBlock();
728 701 pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(),
729 » return FALSE; 702 cBcc.c_str(), cMsg.c_str());
730 } 703 pRuntime->EndBlock();
731 704
732 FX_BOOL app::launchURL(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError) 705 return FALSE;
733 { 706 }
707
708 FX_BOOL app::launchURL(IFXJS_Context* cc,
709 const CJS_Parameters& params,
710 CJS_Value& vRet,
711 CFX_WideString& sError) {
734 // Unsafe, not supported. 712 // Unsafe, not supported.
735 return TRUE; 713 return TRUE;
736 } 714 }
737 715
738 FX_BOOL app::runtimeHighlight(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideStri ng& sError) 716 FX_BOOL app::runtimeHighlight(IFXJS_Context* cc,
739 { 717 CJS_PropValue& vp,
740 » if (vp.IsSetting()) 718 CFX_WideString& sError) {
741 » { 719 if (vp.IsSetting()) {
742 » » vp>>m_bRuntimeHighLight; 720 vp >> m_bRuntimeHighLight;
743 » } 721 } else {
744 » else 722 vp << m_bRuntimeHighLight;
745 » { 723 }
746 » » vp<<m_bRuntimeHighLight; 724
747 » } 725 return TRUE;
748 726 }
749 » return TRUE; 727
750 } 728 FX_BOOL app::fullscreen(IFXJS_Context* cc,
751 729 CJS_PropValue& vp,
752 FX_BOOL app::fullscreen(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sE rror) 730 CFX_WideString& sError) {
753 { 731 return FALSE;
754 » return FALSE; 732 }
755 } 733
756 734 FX_BOOL app::popUpMenu(IFXJS_Context* cc,
757 FX_BOOL app::popUpMenu(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError) 735 const CJS_Parameters& params,
758 { 736 CJS_Value& vRet,
759 » return FALSE; 737 CFX_WideString& sError) {
760 } 738 return FALSE;
761 739 }
762 740
763 FX_BOOL app::browseForDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError) 741 FX_BOOL app::browseForDoc(IFXJS_Context* cc,
764 { 742 const CJS_Parameters& params,
743 CJS_Value& vRet,
744 CFX_WideString& sError) {
765 // Unsafe, not supported. 745 // Unsafe, not supported.
766 return TRUE; 746 return TRUE;
767 } 747 }
768 748
769 CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) 749 CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) {
770 { 750 CFX_WideString sRet = L"/";
771 » CFX_WideString sRet = L"/"; 751
772 752 for (int i = 0, sz = sOldPath.GetLength(); i < sz; i++) {
773 » for (int i=0,sz=sOldPath.GetLength(); i<sz; i++) 753 wchar_t c = sOldPath.GetAt(i);
774 » { 754 if (c == L':') {
775 » » wchar_t c = sOldPath.GetAt(i); 755 } else {
776 » » if (c == L':') 756 if (c == L'\\') {
777 » » { 757 sRet += L"/";
778 » » } 758 } else {
779 » » else 759 sRet += c;
780 » » { 760 }
781 » » » if (c == L'\\')
782 » » » {
783 » » » » sRet += L"/";
784 » » » }
785 » » » else
786 » » » {
787 » » » » sRet += c;
788 » » » }
789 » » }
790 » }
791
792 » return sRet;
793 }
794
795 FX_BOOL app::newDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
796 {
797 » return FALSE;
798 }
799
800 FX_BOOL app::openDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
801 {
802 » return FALSE;
803 }
804
805 FX_BOOL app::response(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value & vRet, CFX_WideString& sError)
806 {
807 » CFX_WideString swQuestion = L"";
808 » CFX_WideString swLabel = L"";
809 » CFX_WideString swTitle = L"PDF";
810 » CFX_WideString swDefault = L"";
811 » bool bPassWord = false;
812
813 » v8::Isolate* isolate = GetIsolate(cc);
814
815 » int iLength = params.size();
816 » if (iLength > 0 && params[0].GetType() == VT_object)
817 » {
818 » » JSObject pObj = params[0].ToV8Object();
819 » » v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L "cQuestion");
820 » » swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).To CFXWideString();
821
822 » » pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
823 » » swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFX WideString();
824
825 » » pValue = JS_GetObjectElement(isolate,pObj,L"cDefault");
826 » » swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToC FXWideString();
827
828 » » pValue = JS_GetObjectElement(isolate,pObj,L"cLabel");
829 » » swLabel = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFX WideString();
830
831 » » pValue = JS_GetObjectElement(isolate,pObj,L"bPassword");
832 » » bPassWord = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToB ool();
833 » }
834 » else
835 » {
836 » » switch(iLength)
837 » » {
838 » » case 5:
839 » » » swLabel = params[4].ToCFXWideString();
840 » » » // FALLTHROUGH
841 » » case 4:
842 » » » bPassWord = params[3].ToBool();
843 » » » // FALLTHROUGH
844 » » case 3:
845 » » » swDefault = params[2].ToCFXWideString();
846 » » » // FALLTHROUGH
847 » » case 2:
848 » » » swTitle = params[1].ToCFXWideString();
849 » » » // FALLTHROUGH
850 » » case 1:
851 » » » swQuestion = params[0].ToCFXWideString();
852 » » » // FALLTHROUGH
853 » » default:
854 » » » break;
855 » » }
856 » }
857
858 » CJS_Context* pContext = (CJS_Context *)cc;
859 » ASSERT(pContext != NULL);
860
861 » CPDFDoc_Environment* pApp = pContext->GetReaderApp();
862 » ASSERT(pApp != NULL);
863
864 const int MAX_INPUT_BYTES = 2048;
865 nonstd::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
866 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
867 int nLengthBytes = pApp->JS_appResponse(swQuestion.c_str(),
868 swTitle.c_str(),
869 swDefault.c_str(),
870 swLabel.c_str(),
871 bPassWord,
872 pBuff.get(),
873 MAX_INPUT_BYTES);
874 if (nLengthBytes <= 0) {
875 vRet.SetNull();
876 return FALSE;
877 } 761 }
878 nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES); 762 }
879 763
880 CFX_WideString ret_string = 764 return sRet;
881 CFX_WideString::FromUTF16LE((unsigned short*)pBuff.get(), 765 }
882 nLengthBytes / sizeof(unsigned short)); 766
883 vRet = ret_string.c_str(); 767 FX_BOOL app::newDoc(IFXJS_Context* cc,
884 return TRUE; 768 const CJS_Parameters& params,
885 } 769 CJS_Value& vRet,
886 770 CFX_WideString& sError) {
887 FX_BOOL app::media(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) 771 return FALSE;
888 { 772 }
889 » return FALSE; 773
890 } 774 FX_BOOL app::openDoc(IFXJS_Context* cc,
891 775 const CJS_Parameters& params,
892 FX_BOOL app::execDialog(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Val ue& vRet, CFX_WideString& sError) 776 CJS_Value& vRet,
893 { 777 CFX_WideString& sError) {
894 » return TRUE; 778 return FALSE;
895 } 779 }
780
781 FX_BOOL app::response(IFXJS_Context* cc,
782 const CJS_Parameters& params,
783 CJS_Value& vRet,
784 CFX_WideString& sError) {
785 CFX_WideString swQuestion = L"";
786 CFX_WideString swLabel = L"";
787 CFX_WideString swTitle = L"PDF";
788 CFX_WideString swDefault = L"";
789 bool bPassWord = false;
790
791 v8::Isolate* isolate = GetIsolate(cc);
792
793 int iLength = params.size();
794 if (iLength > 0 && params[0].GetType() == VT_object) {
795 JSObject pObj = params[0].ToV8Object();
796 v8::Local<v8::Value> pValue =
797 JS_GetObjectElement(isolate, pObj, L"cQuestion");
798 swQuestion =
799 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
800
801 pValue = JS_GetObjectElement(isolate, pObj, L"cTitle");
802 swTitle =
803 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
804
805 pValue = JS_GetObjectElement(isolate, pObj, L"cDefault");
806 swDefault =
807 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
808
809 pValue = JS_GetObjectElement(isolate, pObj, L"cLabel");
810 swLabel =
811 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
812
813 pValue = JS_GetObjectElement(isolate, pObj, L"bPassword");
814 bPassWord = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
815 } else {
816 switch (iLength) {
817 case 5:
818 swLabel = params[4].ToCFXWideString();
819 // FALLTHROUGH
820 case 4:
821 bPassWord = params[3].ToBool();
822 // FALLTHROUGH
823 case 3:
824 swDefault = params[2].ToCFXWideString();
825 // FALLTHROUGH
826 case 2:
827 swTitle = params[1].ToCFXWideString();
828 // FALLTHROUGH
829 case 1:
830 swQuestion = params[0].ToCFXWideString();
831 // FALLTHROUGH
832 default:
833 break;
834 }
835 }
836
837 CJS_Context* pContext = (CJS_Context*)cc;
838 ASSERT(pContext != NULL);
839
840 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
841 ASSERT(pApp != NULL);
842
843 const int MAX_INPUT_BYTES = 2048;
844 nonstd::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
845 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
846 int nLengthBytes = pApp->JS_appResponse(
847 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
848 bPassWord, pBuff.get(), MAX_INPUT_BYTES);
849 if (nLengthBytes <= 0) {
850 vRet.SetNull();
851 return FALSE;
852 }
853 nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES);
854
855 CFX_WideString ret_string = CFX_WideString::FromUTF16LE(
856 (unsigned short*)pBuff.get(), nLengthBytes / sizeof(unsigned short));
857 vRet = ret_string.c_str();
858 return TRUE;
859 }
860
861 FX_BOOL app::media(IFXJS_Context* cc,
862 CJS_PropValue& vp,
863 CFX_WideString& sError) {
864 return FALSE;
865 }
866
867 FX_BOOL app::execDialog(IFXJS_Context* cc,
868 const CJS_Parameters& params,
869 CJS_Value& vRet,
870 CFX_WideString& sError) {
871 return TRUE;
872 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698