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