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