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