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