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

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

Issue 1799773002: Move fpdfsdk/src up to fpdfsdk/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 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
« no previous file with comments | « fpdfsdk/src/javascript/app.h ('k') | fpdfsdk/src/javascript/color.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "fpdfsdk/src/javascript/app.h"
8
9 #include <memory>
10 #include <vector>
11
12 #include "fpdfsdk/include/fsdk_mgr.h"
13 #include "fpdfsdk/include/javascript/IJavaScript.h"
14 #include "fpdfsdk/src/javascript/Document.h"
15 #include "fpdfsdk/src/javascript/JS_Context.h"
16 #include "fpdfsdk/src/javascript/JS_Define.h"
17 #include "fpdfsdk/src/javascript/JS_EventHandler.h"
18 #include "fpdfsdk/src/javascript/JS_Object.h"
19 #include "fpdfsdk/src/javascript/JS_Runtime.h"
20 #include "fpdfsdk/src/javascript/JS_Value.h"
21 #include "fpdfsdk/src/javascript/resource.h"
22
23 BEGIN_JS_STATIC_CONST(CJS_TimerObj)
24 END_JS_STATIC_CONST()
25
26 BEGIN_JS_STATIC_PROP(CJS_TimerObj)
27 END_JS_STATIC_PROP()
28
29 BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
30 END_JS_STATIC_METHOD()
31
32 IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
33
34 TimerObj::TimerObj(CJS_Object* pJSObject)
35 : CJS_EmbedObj(pJSObject), m_pTimer(NULL) {}
36
37 TimerObj::~TimerObj() {}
38
39 void TimerObj::SetTimer(CJS_Timer* pTimer) {
40 m_pTimer = pTimer;
41 }
42
43 CJS_Timer* TimerObj::GetTimer() const {
44 return m_pTimer;
45 }
46
47 #define JS_STR_VIEWERTYPE L"pdfium"
48 #define JS_STR_VIEWERVARIATION L"Full"
49 #define JS_STR_PLATFORM L"WIN"
50 #define JS_STR_LANGUANGE L"ENU"
51 #define JS_NUM_VIEWERVERSION 8
52 #ifdef PDF_ENABLE_XFA
53 #define JS_NUM_VIEWERVERSION_XFA 11
54 #endif // PDF_ENABLE_XFA
55 #define JS_NUM_FORMSVERSION 7
56
57 BEGIN_JS_STATIC_CONST(CJS_App)
58 END_JS_STATIC_CONST()
59
60 BEGIN_JS_STATIC_PROP(CJS_App)
61 JS_STATIC_PROP_ENTRY(activeDocs)
62 JS_STATIC_PROP_ENTRY(calculate)
63 JS_STATIC_PROP_ENTRY(formsVersion)
64 JS_STATIC_PROP_ENTRY(fs)
65 JS_STATIC_PROP_ENTRY(fullscreen)
66 JS_STATIC_PROP_ENTRY(language)
67 JS_STATIC_PROP_ENTRY(media)
68 JS_STATIC_PROP_ENTRY(platform)
69 JS_STATIC_PROP_ENTRY(runtimeHighlight)
70 JS_STATIC_PROP_ENTRY(viewerType)
71 JS_STATIC_PROP_ENTRY(viewerVariation)
72 JS_STATIC_PROP_ENTRY(viewerVersion)
73 END_JS_STATIC_PROP()
74
75 BEGIN_JS_STATIC_METHOD(CJS_App)
76 JS_STATIC_METHOD_ENTRY(alert)
77 JS_STATIC_METHOD_ENTRY(beep)
78 JS_STATIC_METHOD_ENTRY(browseForDoc)
79 JS_STATIC_METHOD_ENTRY(clearInterval)
80 JS_STATIC_METHOD_ENTRY(clearTimeOut)
81 JS_STATIC_METHOD_ENTRY(execDialog)
82 JS_STATIC_METHOD_ENTRY(execMenuItem)
83 JS_STATIC_METHOD_ENTRY(findComponent)
84 JS_STATIC_METHOD_ENTRY(goBack)
85 JS_STATIC_METHOD_ENTRY(goForward)
86 JS_STATIC_METHOD_ENTRY(launchURL)
87 JS_STATIC_METHOD_ENTRY(mailMsg)
88 JS_STATIC_METHOD_ENTRY(newFDF)
89 JS_STATIC_METHOD_ENTRY(newDoc)
90 JS_STATIC_METHOD_ENTRY(openDoc)
91 JS_STATIC_METHOD_ENTRY(openFDF)
92 JS_STATIC_METHOD_ENTRY(popUpMenuEx)
93 JS_STATIC_METHOD_ENTRY(popUpMenu)
94 JS_STATIC_METHOD_ENTRY(response)
95 JS_STATIC_METHOD_ENTRY(setInterval)
96 JS_STATIC_METHOD_ENTRY(setTimeOut)
97 END_JS_STATIC_METHOD()
98
99 IMPLEMENT_JS_CLASS(CJS_App, app)
100
101 app::app(CJS_Object* pJSObject)
102 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {}
103
104 app::~app() {
105 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++)
106 delete m_aTimer[i];
107
108 m_aTimer.RemoveAll();
109 }
110
111 FX_BOOL app::activeDocs(IJS_Context* cc,
112 CJS_PropValue& vp,
113 CFX_WideString& sError) {
114 if (!vp.IsGetting())
115 return FALSE;
116
117 CJS_Context* pContext = (CJS_Context*)cc;
118 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
119 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
120 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
121 CJS_Array aDocs(pRuntime);
122 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) {
123 CJS_Document* pJSDocument = NULL;
124 if (pDoc == pCurDoc) {
125 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate());
126 if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID)
127 pJSDocument =
128 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
129 } else {
130 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
131 pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID);
132 pJSDocument =
133 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
134 ASSERT(pJSDocument);
135 }
136 aDocs.SetElement(0, CJS_Value(pRuntime, pJSDocument));
137 }
138 if (aDocs.GetLength() > 0)
139 vp << aDocs;
140 else
141 vp.SetNull();
142
143 return TRUE;
144 }
145
146 FX_BOOL app::calculate(IJS_Context* cc,
147 CJS_PropValue& vp,
148 CFX_WideString& sError) {
149 if (vp.IsSetting()) {
150 bool bVP;
151 vp >> bVP;
152 m_bCalculate = (FX_BOOL)bVP;
153
154 CJS_Context* pContext = (CJS_Context*)cc;
155 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
156 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
157 CJS_Array aDocs(pRuntime);
158 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
159 pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate);
160 } else {
161 vp << (bool)m_bCalculate;
162 }
163 return TRUE;
164 }
165
166 FX_BOOL app::formsVersion(IJS_Context* cc,
167 CJS_PropValue& vp,
168 CFX_WideString& sError) {
169 if (vp.IsGetting()) {
170 vp << JS_NUM_FORMSVERSION;
171 return TRUE;
172 }
173
174 return FALSE;
175 }
176
177 FX_BOOL app::viewerType(IJS_Context* cc,
178 CJS_PropValue& vp,
179 CFX_WideString& sError) {
180 if (vp.IsGetting()) {
181 vp << JS_STR_VIEWERTYPE;
182 return TRUE;
183 }
184
185 return FALSE;
186 }
187
188 FX_BOOL app::viewerVariation(IJS_Context* cc,
189 CJS_PropValue& vp,
190 CFX_WideString& sError) {
191 if (vp.IsGetting()) {
192 vp << JS_STR_VIEWERVARIATION;
193 return TRUE;
194 }
195
196 return FALSE;
197 }
198
199 FX_BOOL app::viewerVersion(IJS_Context* cc,
200 CJS_PropValue& vp,
201 CFX_WideString& sError) {
202 if (!vp.IsGetting())
203 return FALSE;
204 #ifdef PDF_ENABLE_XFA
205 CJS_Context* pContext = (CJS_Context*)cc;
206 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
207 CPDFXFA_Document* pDoc = pCurDoc->GetXFADocument();
208 if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) {
209 vp << JS_NUM_VIEWERVERSION_XFA;
210 return TRUE;
211 }
212 #endif // PDF_ENABLE_XFA
213 vp << JS_NUM_VIEWERVERSION;
214 return TRUE;
215 }
216
217 FX_BOOL app::platform(IJS_Context* cc,
218 CJS_PropValue& vp,
219 CFX_WideString& sError) {
220 if (!vp.IsGetting())
221 return FALSE;
222 #ifdef PDF_ENABLE_XFA
223 CPDFDoc_Environment* pEnv =
224 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetReaderApp();
225 if (!pEnv)
226 return FALSE;
227 CFX_WideString platfrom = pEnv->FFI_GetPlatform();
228 if (!platfrom.IsEmpty()) {
229 vp << platfrom;
230 return TRUE;
231 }
232 #endif
233 vp << JS_STR_PLATFORM;
234 return TRUE;
235 }
236
237 FX_BOOL app::language(IJS_Context* cc,
238 CJS_PropValue& vp,
239 CFX_WideString& sError) {
240 if (!vp.IsGetting())
241 return FALSE;
242 #ifdef PDF_ENABLE_XFA
243 CPDFDoc_Environment* pEnv =
244 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetReaderApp();
245 if (!pEnv)
246 return FALSE;
247 CFX_WideString language = pEnv->FFI_GetLanguage();
248 if (!language.IsEmpty()) {
249 vp << language;
250 return TRUE;
251 }
252 #endif
253 vp << JS_STR_LANGUANGE;
254 return TRUE;
255 }
256
257 // creates a new fdf object that contains no data
258 // comment: need reader support
259 // note:
260 // CFDF_Document * CPDFDoc_Environment::NewFDF();
261 FX_BOOL app::newFDF(IJS_Context* cc,
262 const std::vector<CJS_Value>& params,
263 CJS_Value& vRet,
264 CFX_WideString& sError) {
265 return TRUE;
266 }
267 // opens a specified pdf document and returns its document object
268 // comment:need reader support
269 // note: as defined in js reference, the proto of this function's fourth
270 // parmeters, 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(IJS_Context* cc,
274 const std::vector<CJS_Value>& params,
275 CJS_Value& vRet,
276 CFX_WideString& sError) {
277 return TRUE;
278 }
279
280 FX_BOOL app::alert(IJS_Context* cc,
281 const std::vector<CJS_Value>& params,
282 CJS_Value& vRet,
283 CFX_WideString& sError) {
284 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
285 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
286 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams(
287 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
288
289 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
290 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
291 return FALSE;
292 }
293
294 CFX_WideString swMsg;
295 if (newParams[0].GetType() == CJS_Value::VT_object) {
296 CJS_Array carray(pRuntime);
297 if (newParams[0].ConvertToArray(carray)) {
298 swMsg = L"[";
299 CJS_Value element(pRuntime);
300 for (int i = 0; i < carray.GetLength(); ++i) {
301 if (i)
302 swMsg += L", ";
303 carray.GetElement(i, element);
304 swMsg += element.ToCFXWideString();
305 }
306 swMsg += L"]";
307 } else {
308 swMsg = newParams[0].ToCFXWideString();
309 }
310 } else {
311 swMsg = newParams[0].ToCFXWideString();
312 }
313
314 int iIcon = 0;
315 if (newParams[1].GetType() != CJS_Value::VT_unknown)
316 iIcon = newParams[1].ToInt();
317
318 int iType = 0;
319 if (newParams[2].GetType() != CJS_Value::VT_unknown)
320 iType = newParams[2].ToInt();
321
322 CFX_WideString swTitle;
323 if (newParams[3].GetType() != CJS_Value::VT_unknown)
324 swTitle = newParams[3].ToCFXWideString();
325 else
326 swTitle = JSGetStringFromID(pContext, IDS_STRING_JSALERT);
327
328 pRuntime->BeginBlock();
329 vRet = MsgBox(pRuntime->GetReaderApp(), swMsg.c_str(), swTitle.c_str(), iType,
330 iIcon);
331 pRuntime->EndBlock();
332 return TRUE;
333 }
334
335 FX_BOOL app::beep(IJS_Context* cc,
336 const std::vector<CJS_Value>& params,
337 CJS_Value& vRet,
338 CFX_WideString& sError) {
339 if (params.size() == 1) {
340 CJS_Context* pContext = (CJS_Context*)cc;
341 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
342 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
343 pEnv->JS_appBeep(params[0].ToInt());
344 return TRUE;
345 }
346
347 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
348 return FALSE;
349 }
350
351 FX_BOOL app::findComponent(IJS_Context* cc,
352 const std::vector<CJS_Value>& params,
353 CJS_Value& vRet,
354 CFX_WideString& sError) {
355 return TRUE;
356 }
357
358 FX_BOOL app::popUpMenuEx(IJS_Context* cc,
359 const std::vector<CJS_Value>& params,
360 CJS_Value& vRet,
361 CFX_WideString& sError) {
362 return FALSE;
363 }
364
365 FX_BOOL app::fs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
366 return FALSE;
367 }
368
369 FX_BOOL app::setInterval(IJS_Context* cc,
370 const std::vector<CJS_Value>& params,
371 CJS_Value& vRet,
372 CFX_WideString& sError) {
373 CJS_Context* pContext = (CJS_Context*)cc;
374 if (params.size() > 2 || params.size() == 0) {
375 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
376 return FALSE;
377 }
378
379 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
380 if (script.IsEmpty()) {
381 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
382 return TRUE;
383 }
384
385 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
386 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000;
387
388 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
389 ASSERT(pApp);
390 CJS_Timer* pTimer =
391 new CJS_Timer(this, pApp, pRuntime, 0, script, dwInterval, 0);
392 m_aTimer.Add(pTimer);
393
394 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
395 pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID);
396 CJS_TimerObj* pJS_TimerObj =
397 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
398 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
399 pTimerObj->SetTimer(pTimer);
400
401 vRet = pRetObj;
402 return TRUE;
403 }
404
405 FX_BOOL app::setTimeOut(IJS_Context* cc,
406 const std::vector<CJS_Value>& params,
407 CJS_Value& vRet,
408 CFX_WideString& sError) {
409 if (params.size() > 2 || params.size() == 0) {
410 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
411 return FALSE;
412 }
413
414 CJS_Context* pContext = (CJS_Context*)cc;
415 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
416
417 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
418 if (script.IsEmpty()) {
419 sError =
420 JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
421 return TRUE;
422 }
423
424 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
425
426 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
427 ASSERT(pApp);
428
429 CJS_Timer* pTimer =
430 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut);
431 m_aTimer.Add(pTimer);
432
433 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
434 pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID);
435 CJS_TimerObj* pJS_TimerObj =
436 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
437 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
438 pTimerObj->SetTimer(pTimer);
439
440 vRet = pRetObj;
441 return TRUE;
442 }
443
444 FX_BOOL app::clearTimeOut(IJS_Context* cc,
445 const std::vector<CJS_Value>& params,
446 CJS_Value& vRet,
447 CFX_WideString& sError) {
448 CJS_Context* pContext = (CJS_Context*)cc;
449 if (params.size() != 1) {
450 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
451 return FALSE;
452 }
453
454 if (params[0].GetType() == CJS_Value::VT_fxobject) {
455 v8::Local<v8::Object> pObj = params[0].ToV8Object();
456 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
457 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
458 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
459 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
460 pTimer->KillJSTimer();
461
462 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
463 if (m_aTimer[i] == pTimer) {
464 m_aTimer.RemoveAt(i);
465 break;
466 }
467 }
468
469 delete pTimer;
470 pTimerObj->SetTimer(NULL);
471 }
472 }
473 }
474 }
475 }
476
477 return TRUE;
478 }
479
480 FX_BOOL app::clearInterval(IJS_Context* cc,
481 const std::vector<CJS_Value>& params,
482 CJS_Value& vRet,
483 CFX_WideString& sError) {
484 CJS_Context* pContext = (CJS_Context*)cc;
485 if (params.size() != 1) {
486 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
487 return FALSE;
488 }
489
490 if (params[0].GetType() == CJS_Value::VT_fxobject) {
491 v8::Local<v8::Object> pObj = params[0].ToV8Object();
492 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
493 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
494 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
495 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
496 pTimer->KillJSTimer();
497
498 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
499 if (m_aTimer[i] == pTimer) {
500 m_aTimer.RemoveAt(i);
501 break;
502 }
503 }
504
505 delete pTimer;
506 pTimerObj->SetTimer(NULL);
507 }
508 }
509 }
510 }
511 }
512
513 return TRUE;
514 }
515
516 FX_BOOL app::execMenuItem(IJS_Context* cc,
517 const std::vector<CJS_Value>& params,
518 CJS_Value& vRet,
519 CFX_WideString& sError) {
520 return FALSE;
521 }
522
523 void app::TimerProc(CJS_Timer* pTimer) {
524 CJS_Runtime* pRuntime = pTimer->GetRuntime();
525
526 switch (pTimer->GetType()) {
527 case 0: // interval
528 if (pRuntime)
529 RunJsScript(pRuntime, pTimer->GetJScript());
530 break;
531 case 1:
532 if (pTimer->GetTimeOut() > 0) {
533 if (pRuntime)
534 RunJsScript(pRuntime, pTimer->GetJScript());
535 pTimer->KillJSTimer();
536 }
537 break;
538 }
539 }
540
541 void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
542 if (!pRuntime->IsBlocking()) {
543 IJS_Context* pContext = pRuntime->NewContext();
544 pContext->OnExternal_Exec();
545 CFX_WideString wtInfo;
546 pContext->RunScript(wsScript, &wtInfo);
547 pRuntime->ReleaseContext(pContext);
548 }
549 }
550
551 FX_BOOL app::goBack(IJS_Context* cc,
552 const std::vector<CJS_Value>& params,
553 CJS_Value& vRet,
554 CFX_WideString& sError) {
555 // Not supported.
556 return TRUE;
557 }
558
559 FX_BOOL app::goForward(IJS_Context* cc,
560 const std::vector<CJS_Value>& params,
561 CJS_Value& vRet,
562 CFX_WideString& sError) {
563 // Not supported.
564 return TRUE;
565 }
566
567 FX_BOOL app::mailMsg(IJS_Context* cc,
568 const std::vector<CJS_Value>& params,
569 CJS_Value& vRet,
570 CFX_WideString& sError) {
571 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
572 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
573 std::vector<CJS_Value> newParams =
574 JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc",
575 L"cBcc", L"cSubject", L"cMsg");
576
577 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
578 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
579 return FALSE;
580 }
581 bool bUI = newParams[0].ToBool();
582
583 CFX_WideString cTo;
584 if (newParams[1].GetType() != CJS_Value::VT_unknown) {
585 cTo = newParams[1].ToCFXWideString();
586 } else {
587 if (!bUI) {
588 // cTo parameter required when UI not invoked.
589 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
590 return FALSE;
591 }
592 }
593
594 CFX_WideString cCc;
595 if (newParams[2].GetType() != CJS_Value::VT_unknown)
596 cCc = newParams[2].ToCFXWideString();
597
598 CFX_WideString cBcc;
599 if (newParams[3].GetType() != CJS_Value::VT_unknown)
600 cBcc = newParams[3].ToCFXWideString();
601
602 CFX_WideString cSubject;
603 if (newParams[4].GetType() != CJS_Value::VT_unknown)
604 cSubject = newParams[4].ToCFXWideString();
605
606 CFX_WideString cMsg;
607 if (newParams[5].GetType() != CJS_Value::VT_unknown)
608 cMsg = newParams[5].ToCFXWideString();
609
610 pRuntime->BeginBlock();
611 pContext->GetReaderApp()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(),
612 cSubject.c_str(), cCc.c_str(),
613 cBcc.c_str(), cMsg.c_str());
614 pRuntime->EndBlock();
615 return TRUE;
616 }
617
618 FX_BOOL app::launchURL(IJS_Context* cc,
619 const std::vector<CJS_Value>& params,
620 CJS_Value& vRet,
621 CFX_WideString& sError) {
622 // Unsafe, not supported.
623 return TRUE;
624 }
625
626 FX_BOOL app::runtimeHighlight(IJS_Context* cc,
627 CJS_PropValue& vp,
628 CFX_WideString& sError) {
629 if (vp.IsSetting()) {
630 vp >> m_bRuntimeHighLight;
631 } else {
632 vp << m_bRuntimeHighLight;
633 }
634 return TRUE;
635 }
636
637 FX_BOOL app::fullscreen(IJS_Context* cc,
638 CJS_PropValue& vp,
639 CFX_WideString& sError) {
640 return FALSE;
641 }
642
643 FX_BOOL app::popUpMenu(IJS_Context* cc,
644 const std::vector<CJS_Value>& params,
645 CJS_Value& vRet,
646 CFX_WideString& sError) {
647 return FALSE;
648 }
649
650 FX_BOOL app::browseForDoc(IJS_Context* cc,
651 const std::vector<CJS_Value>& params,
652 CJS_Value& vRet,
653 CFX_WideString& sError) {
654 // Unsafe, not supported.
655 return TRUE;
656 }
657
658 CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) {
659 CFX_WideString sRet = L"/";
660
661 for (int i = 0, sz = sOldPath.GetLength(); i < sz; i++) {
662 wchar_t c = sOldPath.GetAt(i);
663 if (c == L':') {
664 } else {
665 if (c == L'\\') {
666 sRet += L"/";
667 } else {
668 sRet += c;
669 }
670 }
671 }
672
673 return sRet;
674 }
675
676 FX_BOOL app::newDoc(IJS_Context* cc,
677 const std::vector<CJS_Value>& params,
678 CJS_Value& vRet,
679 CFX_WideString& sError) {
680 return FALSE;
681 }
682
683 FX_BOOL app::openDoc(IJS_Context* cc,
684 const std::vector<CJS_Value>& params,
685 CJS_Value& vRet,
686 CFX_WideString& sError) {
687 return FALSE;
688 }
689
690 FX_BOOL app::response(IJS_Context* cc,
691 const std::vector<CJS_Value>& params,
692 CJS_Value& vRet,
693 CFX_WideString& sError) {
694 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
695 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
696 std::vector<CJS_Value> newParams =
697 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
698 L"cDefault", L"bPassword", L"cLabel");
699
700 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
701 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
702 return FALSE;
703 }
704 CFX_WideString swQuestion = newParams[0].ToCFXWideString();
705
706 CFX_WideString swTitle = L"PDF";
707 if (newParams[1].GetType() != CJS_Value::VT_unknown)
708 swTitle = newParams[1].ToCFXWideString();
709
710 CFX_WideString swDefault;
711 if (newParams[2].GetType() != CJS_Value::VT_unknown)
712 swDefault = newParams[2].ToCFXWideString();
713
714 bool bPassword = false;
715 if (newParams[3].GetType() != CJS_Value::VT_unknown)
716 bPassword = newParams[3].ToBool();
717
718 CFX_WideString swLabel;
719 if (newParams[4].GetType() != CJS_Value::VT_unknown)
720 swLabel = newParams[4].ToCFXWideString();
721
722 const int MAX_INPUT_BYTES = 2048;
723 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
724 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
725
726 int nLengthBytes = pContext->GetReaderApp()->JS_appResponse(
727 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
728 bPassword, pBuff.get(), MAX_INPUT_BYTES);
729
730 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
731 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG);
732 return FALSE;
733 }
734
735 vRet = CFX_WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.get()),
736 nLengthBytes / sizeof(uint16_t))
737 .c_str();
738 return TRUE;
739 }
740
741 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
742 return FALSE;
743 }
744
745 FX_BOOL app::execDialog(IJS_Context* cc,
746 const std::vector<CJS_Value>& params,
747 CJS_Value& vRet,
748 CFX_WideString& sError) {
749 return TRUE;
750 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/app.h ('k') | fpdfsdk/src/javascript/color.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698