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 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 9 | #include <map> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 10 | #include <memory> |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 11 | #include <vector> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 12 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 13 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 14 | #include "fpdfsdk/cpdfsdk_interform.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 15 | #include "fpdfsdk/javascript/Document.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 16 | #include "fpdfsdk/javascript/JS_Define.h" |
| 17 | #include "fpdfsdk/javascript/JS_EventHandler.h" |
| 18 | #include "fpdfsdk/javascript/JS_Object.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 19 | #include "fpdfsdk/javascript/JS_Value.h" |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 20 | #include "fpdfsdk/javascript/cjs_event_context.h" |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/javascript/cjs_runtime.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 22 | #include "fpdfsdk/javascript/resource.h" |
tsepez | a752edf | 2016-08-19 14:57:42 -0700 | [diff] [blame] | 23 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 24 | |
tsepez | 1c62054 | 2016-09-12 09:47:52 -0700 | [diff] [blame] | 25 | class GlobalTimer { |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 26 | public: |
| 27 | GlobalTimer(app* pObj, |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 28 | CPDFSDK_FormFillEnvironment* pFormFillEnv, |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 29 | CJS_Runtime* pRuntime, |
| 30 | int nType, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 31 | const WideString& script, |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 32 | uint32_t dwElapse, |
| 33 | uint32_t dwTimeOut); |
tsepez | 8832fbf | 2016-09-08 10:25:55 -0700 | [diff] [blame] | 34 | ~GlobalTimer(); |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 35 | |
| 36 | static void Trigger(int nTimerID); |
| 37 | static void Cancel(int nTimerID); |
| 38 | |
| 39 | bool IsOneShot() const { return m_nType == 1; } |
| 40 | uint32_t GetTimeOut() const { return m_dwTimeOut; } |
| 41 | int GetTimerID() const { return m_nTimerID; } |
tsepez | 1c62054 | 2016-09-12 09:47:52 -0700 | [diff] [blame] | 42 | CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); } |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 43 | WideString GetJScript() const { return m_swJScript; } |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 44 | |
| 45 | private: |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 46 | using TimerMap = std::map<uint32_t, GlobalTimer*>; |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 47 | static TimerMap* GetGlobalTimerMap(); |
| 48 | |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 49 | uint32_t m_nTimerID; |
| 50 | app* const m_pEmbedObj; |
| 51 | bool m_bProcessing; |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 52 | |
| 53 | // data |
| 54 | const int m_nType; // 0:Interval; 1:TimeOut |
| 55 | const uint32_t m_dwTimeOut; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 56 | const WideString m_swJScript; |
tsepez | 1c62054 | 2016-09-12 09:47:52 -0700 | [diff] [blame] | 57 | CJS_Runtime::ObservedPtr m_pRuntime; |
Tom Sepez | 77f6d0f | 2017-02-23 12:14:10 -0800 | [diff] [blame] | 58 | CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv; |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | GlobalTimer::GlobalTimer(app* pObj, |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 62 | CPDFSDK_FormFillEnvironment* pFormFillEnv, |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 63 | CJS_Runtime* pRuntime, |
| 64 | int nType, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 65 | const WideString& script, |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 66 | uint32_t dwElapse, |
| 67 | uint32_t dwTimeOut) |
| 68 | : m_nTimerID(0), |
| 69 | m_pEmbedObj(pObj), |
| 70 | m_bProcessing(false), |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 71 | m_nType(nType), |
| 72 | m_dwTimeOut(dwTimeOut), |
| 73 | m_swJScript(script), |
| 74 | m_pRuntime(pRuntime), |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 75 | m_pFormFillEnv(pFormFillEnv) { |
| 76 | CFX_SystemHandler* pHandler = m_pFormFillEnv->GetSysHandler(); |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 77 | m_nTimerID = pHandler->SetTimer(dwElapse, Trigger); |
tsepez | 6cf5eca | 2017-01-12 11:21:12 -0800 | [diff] [blame] | 78 | if (m_nTimerID) |
| 79 | (*GetGlobalTimerMap())[m_nTimerID] = this; |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | GlobalTimer::~GlobalTimer() { |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 83 | if (!m_nTimerID) |
| 84 | return; |
| 85 | |
tsepez | 8832fbf | 2016-09-08 10:25:55 -0700 | [diff] [blame] | 86 | if (GetRuntime()) |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 87 | m_pFormFillEnv->GetSysHandler()->KillTimer(m_nTimerID); |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 88 | |
| 89 | GetGlobalTimerMap()->erase(m_nTimerID); |
| 90 | } |
| 91 | |
| 92 | // static |
| 93 | void GlobalTimer::Trigger(int nTimerID) { |
| 94 | auto it = GetGlobalTimerMap()->find(nTimerID); |
| 95 | if (it == GetGlobalTimerMap()->end()) |
| 96 | return; |
| 97 | |
| 98 | GlobalTimer* pTimer = it->second; |
| 99 | if (pTimer->m_bProcessing) |
| 100 | return; |
| 101 | |
| 102 | pTimer->m_bProcessing = true; |
| 103 | if (pTimer->m_pEmbedObj) |
| 104 | pTimer->m_pEmbedObj->TimerProc(pTimer); |
| 105 | |
| 106 | // Timer proc may have destroyed timer, find it again. |
| 107 | it = GetGlobalTimerMap()->find(nTimerID); |
| 108 | if (it == GetGlobalTimerMap()->end()) |
| 109 | return; |
| 110 | |
| 111 | pTimer = it->second; |
| 112 | pTimer->m_bProcessing = false; |
| 113 | if (pTimer->IsOneShot()) |
| 114 | pTimer->m_pEmbedObj->CancelProc(pTimer); |
| 115 | } |
| 116 | |
| 117 | // static |
| 118 | void GlobalTimer::Cancel(int nTimerID) { |
| 119 | auto it = GetGlobalTimerMap()->find(nTimerID); |
| 120 | if (it == GetGlobalTimerMap()->end()) |
| 121 | return; |
| 122 | |
| 123 | GlobalTimer* pTimer = it->second; |
| 124 | pTimer->m_pEmbedObj->CancelProc(pTimer); |
| 125 | } |
| 126 | |
| 127 | // static |
| 128 | GlobalTimer::TimerMap* GlobalTimer::GetGlobalTimerMap() { |
| 129 | // Leak the timer array at shutdown. |
| 130 | static auto* s_TimerMap = new TimerMap; |
| 131 | return s_TimerMap; |
| 132 | } |
| 133 | |
Tom Sepez | 04557b8 | 2017-02-16 09:43:10 -0800 | [diff] [blame] | 134 | JSConstSpec CJS_TimerObj::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 135 | |
Tom Sepez | 04557b8 | 2017-02-16 09:43:10 -0800 | [diff] [blame] | 136 | JSPropertySpec CJS_TimerObj::PropertySpecs[] = {{0, 0, 0}}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 137 | |
Tom Sepez | 04557b8 | 2017-02-16 09:43:10 -0800 | [diff] [blame] | 138 | JSMethodSpec CJS_TimerObj::MethodSpecs[] = {{0, 0}}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 139 | |
| 140 | IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj) |
| 141 | |
| 142 | TimerObj::TimerObj(CJS_Object* pJSObject) |
tsepez | 8ca63de | 2016-08-05 17:12:27 -0700 | [diff] [blame] | 143 | : CJS_EmbedObj(pJSObject), m_nTimerID(0) {} |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 144 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | TimerObj::~TimerObj() {} |
| 146 | |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 147 | void TimerObj::SetTimer(GlobalTimer* pTimer) { |
tsepez | 8ca63de | 2016-08-05 17:12:27 -0700 | [diff] [blame] | 148 | m_nTimerID = pTimer->GetTimerID(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Tom Sepez | d6278ba | 2015-09-08 16:34:37 -0700 | [diff] [blame] | 151 | #define JS_STR_VIEWERTYPE L"pdfium" |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 152 | #define JS_STR_VIEWERVARIATION L"Full" |
| 153 | #define JS_STR_PLATFORM L"WIN" |
dsinclair | f51e4dc | 2016-10-13 07:43:19 -0700 | [diff] [blame] | 154 | #define JS_STR_LANGUAGE L"ENU" |
Tom Sepez | d6278ba | 2015-09-08 16:34:37 -0700 | [diff] [blame] | 155 | #define JS_NUM_VIEWERVERSION 8 |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 156 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | d6278ba | 2015-09-08 16:34:37 -0700 | [diff] [blame] | 157 | #define JS_NUM_VIEWERVERSION_XFA 11 |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 158 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 159 | #define JS_NUM_FORMSVERSION 7 |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 160 | |
Tom Sepez | 04557b8 | 2017-02-16 09:43:10 -0800 | [diff] [blame] | 161 | JSConstSpec CJS_App::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 162 | |
Tom Sepez | 04557b8 | 2017-02-16 09:43:10 -0800 | [diff] [blame] | 163 | JSPropertySpec CJS_App::PropertySpecs[] = { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 164 | {"activeDocs", get_active_docs_static, set_active_docs_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 165 | {"calculate", get_calculate_static, set_calculate_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 166 | {"formsVersion", get_forms_version_static, set_forms_version_static}, |
Tom Sepez | 4d5b8c5 | 2017-02-21 15:17:07 -0800 | [diff] [blame] | 167 | {"fs", get_fs_static, set_fs_static}, |
| 168 | {"fullscreen", get_fullscreen_static, set_fullscreen_static}, |
| 169 | {"language", get_language_static, set_language_static}, |
| 170 | {"media", get_media_static, set_media_static}, |
| 171 | {"platform", get_platform_static, set_platform_static}, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 172 | {"runtimeHighlight", get_runtime_highlight_static, |
| 173 | set_runtime_highlight_static}, |
| 174 | {"viewerType", get_viewer_type_static, set_viewer_type_static}, |
| 175 | {"viewerVariation", get_viewer_variation_static, |
| 176 | set_viewer_variation_static}, |
| 177 | {"viewerVersion", get_viewer_version_static, set_viewer_version_static}, |
Tom Sepez | 04557b8 | 2017-02-16 09:43:10 -0800 | [diff] [blame] | 178 | {0, 0, 0}}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 179 | |
Tom Sepez | 9b99b63 | 2017-02-21 15:05:57 -0800 | [diff] [blame] | 180 | JSMethodSpec CJS_App::MethodSpecs[] = {{"alert", alert_static}, |
| 181 | {"beep", beep_static}, |
| 182 | {"browseForDoc", browseForDoc_static}, |
| 183 | {"clearInterval", clearInterval_static}, |
| 184 | {"clearTimeOut", clearTimeOut_static}, |
| 185 | {"execDialog", execDialog_static}, |
| 186 | {"execMenuItem", execMenuItem_static}, |
| 187 | {"findComponent", findComponent_static}, |
| 188 | {"goBack", goBack_static}, |
| 189 | {"goForward", goForward_static}, |
| 190 | {"launchURL", launchURL_static}, |
| 191 | {"mailMsg", mailMsg_static}, |
| 192 | {"newFDF", newFDF_static}, |
| 193 | {"newDoc", newDoc_static}, |
| 194 | {"openDoc", openDoc_static}, |
| 195 | {"openFDF", openFDF_static}, |
| 196 | {"popUpMenuEx", popUpMenuEx_static}, |
| 197 | {"popUpMenu", popUpMenu_static}, |
| 198 | {"response", response_static}, |
| 199 | {"setInterval", setInterval_static}, |
| 200 | {"setTimeOut", setTimeOut_static}, |
Tom Sepez | 04557b8 | 2017-02-16 09:43:10 -0800 | [diff] [blame] | 201 | {0, 0}}; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 202 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | IMPLEMENT_JS_CLASS(CJS_App, app) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 204 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | app::app(CJS_Object* pJSObject) |
| 206 | : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {} |
| 207 | |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 208 | app::~app() { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 209 | } |
| 210 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 211 | bool app::get_active_docs(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 212 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 213 | WideString* sError) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 214 | CJS_Document* pJSDocument = nullptr; |
| 215 | v8::Local<v8::Object> pObj = pRuntime->GetThisObj(); |
Tom Sepez | c5a1472 | 2017-02-24 15:31:12 -0800 | [diff] [blame] | 216 | if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 217 | pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj)); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 218 | |
| 219 | CJS_Array aDocs; |
| 220 | aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument)); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 221 | if (aDocs.GetLength(pRuntime) > 0) |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 222 | vp->Set(pRuntime, aDocs); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 223 | else |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 224 | vp->SetNull(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 225 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 226 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 227 | } |
| 228 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 229 | bool app::set_active_docs(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 230 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 231 | WideString* sError) { |
| 232 | return false; |
| 233 | } |
| 234 | |
| 235 | bool app::get_calculate(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 236 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 237 | WideString* sError) { |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 238 | vp->Set(pRuntime, m_bCalculate); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 239 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 240 | } |
| 241 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 242 | bool app::set_calculate(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 243 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 244 | WideString* sError) { |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 245 | m_bCalculate = vp.ToBool(pRuntime); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 246 | pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(m_bCalculate); |
| 247 | return true; |
| 248 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 249 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 250 | bool app::get_forms_version(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 251 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 252 | WideString* sError) { |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 253 | vp->Set(pRuntime, JS_NUM_FORMSVERSION); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 254 | return true; |
| 255 | } |
| 256 | |
| 257 | bool app::set_forms_version(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 258 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 259 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 260 | return false; |
| 261 | } |
| 262 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 263 | bool app::get_viewer_type(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 264 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 265 | WideString* sError) { |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 266 | vp->Set(pRuntime, JS_STR_VIEWERTYPE); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 267 | return true; |
| 268 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 269 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 270 | bool app::set_viewer_type(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 271 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 272 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 273 | return false; |
| 274 | } |
| 275 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 276 | bool app::get_viewer_variation(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 277 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 278 | WideString* sError) { |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 279 | vp->Set(pRuntime, JS_STR_VIEWERVARIATION); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 280 | return true; |
| 281 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 282 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 283 | bool app::set_viewer_variation(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 284 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 285 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 286 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 287 | } |
| 288 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 289 | bool app::get_viewer_version(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 290 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 291 | WideString* sError) { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 292 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 293 | CPDFXFA_Context* pXFAContext = pRuntime->GetFormFillEnv()->GetXFAContext(); |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 294 | if (pXFAContext->ContainsXFAForm()) { |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 295 | vp->Set(pRuntime, JS_NUM_VIEWERVERSION_XFA); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 296 | return true; |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 297 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 298 | #endif // PDF_ENABLE_XFA |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 299 | vp->Set(pRuntime, JS_NUM_VIEWERVERSION); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 300 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | } |
| 302 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 303 | bool app::set_viewer_version(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 304 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 305 | WideString* sError) { |
| 306 | return false; |
| 307 | } |
| 308 | |
| 309 | bool app::get_platform(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 310 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 311 | WideString* sError) { |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 312 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 313 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 314 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 315 | return false; |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 316 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 317 | WideString platfrom = pFormFillEnv->GetPlatform(); |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 318 | if (!platfrom.IsEmpty()) { |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 319 | vp->Set(pRuntime, platfrom); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 320 | return true; |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 321 | } |
| 322 | #endif |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 323 | vp->Set(pRuntime, JS_STR_PLATFORM); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 324 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 325 | } |
| 326 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 327 | bool app::set_platform(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 328 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 329 | WideString* sError) { |
| 330 | return false; |
| 331 | } |
| 332 | |
| 333 | bool app::get_language(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 334 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 335 | WideString* sError) { |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 336 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 337 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 338 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 339 | return false; |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 340 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 341 | WideString language = pFormFillEnv->GetLanguage(); |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 342 | if (!language.IsEmpty()) { |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 343 | vp->Set(pRuntime, language); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 344 | return true; |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 345 | } |
| 346 | #endif |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 347 | vp->Set(pRuntime, JS_STR_LANGUAGE); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 348 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 349 | } |
| 350 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 351 | bool app::set_language(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 352 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 353 | WideString* sError) { |
| 354 | return false; |
| 355 | } |
| 356 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 357 | // creates a new fdf object that contains no data |
| 358 | // comment: need reader support |
| 359 | // note: |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 360 | // CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF(); |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 361 | bool app::newFDF(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 362 | const std::vector<CJS_Value>& params, |
| 363 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 364 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 365 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 366 | } |
| 367 | // opens a specified pdf document and returns its document object |
| 368 | // comment:need reader support |
| 369 | // note: as defined in js reference, the proto of this function's fourth |
| 370 | // parmeters, how old an fdf document while do not show it. |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 371 | // CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool |
| 372 | // bUserConv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 373 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 374 | bool app::openFDF(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 375 | const std::vector<CJS_Value>& params, |
| 376 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 377 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 378 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 381 | bool app::alert(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 382 | const std::vector<CJS_Value>& params, |
| 383 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 384 | WideString& sError) { |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 385 | std::vector<CJS_Value> newParams = ExpandKeywordParams( |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 386 | pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 387 | |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 388 | if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 389 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 390 | return false; |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 391 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 392 | |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 393 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); |
| 394 | if (!pFormFillEnv) { |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 395 | vRet = CJS_Value(pRuntime, 0); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 396 | return true; |
tsepez | e1e7bd0 | 2016-08-08 13:03:16 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 399 | WideString swMsg; |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 400 | if (newParams[0].GetType() == CJS_Value::VT_object) { |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 401 | if (newParams[0].IsArrayObject()) { |
| 402 | CJS_Array carray = newParams[0].ToArray(pRuntime); |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 403 | swMsg = L"["; |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 404 | for (int i = 0; i < carray.GetLength(pRuntime); ++i) { |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 405 | if (i) |
| 406 | swMsg += L", "; |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 407 | |
| 408 | CJS_Value element(carray.GetElement(pRuntime, i)); |
| 409 | swMsg += element.ToWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 410 | } |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 411 | swMsg += L"]"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 412 | } else { |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 413 | swMsg = newParams[0].ToWideString(pRuntime); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 414 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 415 | } else { |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 416 | swMsg = newParams[0].ToWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 419 | int iIcon = 0; |
| 420 | if (newParams[1].GetType() != CJS_Value::VT_unknown) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 421 | iIcon = newParams[1].ToInt(pRuntime); |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 422 | |
| 423 | int iType = 0; |
| 424 | if (newParams[2].GetType() != CJS_Value::VT_unknown) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 425 | iType = newParams[2].ToInt(pRuntime); |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 426 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 427 | WideString swTitle; |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 428 | if (newParams[3].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 429 | swTitle = newParams[3].ToWideString(pRuntime); |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 430 | else |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 431 | swTitle = JSGetStringFromID(IDS_STRING_JSALERT); |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 432 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 433 | pRuntime->BeginBlock(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 434 | pFormFillEnv->KillFocusAnnot(0); |
tsepez | e1e7bd0 | 2016-08-08 13:03:16 -0700 | [diff] [blame] | 435 | |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 436 | vRet = CJS_Value(pRuntime, pFormFillEnv->JS_appAlert( |
| 437 | swMsg.c_str(), swTitle.c_str(), iType, iIcon)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 438 | pRuntime->EndBlock(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 439 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 442 | bool app::beep(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 443 | const std::vector<CJS_Value>& params, |
| 444 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 445 | WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 446 | if (params.size() == 1) { |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 447 | pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 448 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 449 | } |
| 450 | |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 451 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 452 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 455 | bool app::findComponent(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 456 | const std::vector<CJS_Value>& params, |
| 457 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 458 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 459 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 462 | bool app::popUpMenuEx(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 463 | const std::vector<CJS_Value>& params, |
| 464 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 465 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 466 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 469 | bool app::get_fs(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 470 | return false; |
| 471 | } |
| 472 | |
| 473 | bool app::set_fs(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 474 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 475 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 476 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 479 | bool app::setInterval(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 480 | const std::vector<CJS_Value>& params, |
| 481 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 482 | WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 483 | if (params.size() > 2 || params.size() == 0) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 484 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 485 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 486 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 487 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 488 | WideString script = |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 489 | params.size() > 0 ? params[0].ToWideString(pRuntime) : L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 490 | if (script.IsEmpty()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 491 | sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 492 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 493 | } |
| 494 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 495 | uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; |
dsinclair | 2eb7c7d | 2016-08-18 09:58:19 -0700 | [diff] [blame] | 496 | |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 497 | GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(), |
| 498 | pRuntime, 0, script, dwInterval, 0); |
tsepez | a752edf | 2016-08-19 14:57:42 -0700 | [diff] [blame] | 499 | m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 500 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 501 | v8::Local<v8::Object> pRetObj = |
| 502 | pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); |
Tom Sepez | c5a1472 | 2017-02-24 15:31:12 -0800 | [diff] [blame] | 503 | if (pRetObj.IsEmpty()) |
| 504 | return false; |
| 505 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 506 | CJS_TimerObj* pJS_TimerObj = |
| 507 | static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 508 | TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); |
dsinclair | 2eb7c7d | 2016-08-18 09:58:19 -0700 | [diff] [blame] | 509 | pTimerObj->SetTimer(timerRef); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 510 | |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 511 | vRet = CJS_Value(pRuntime, pRetObj); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 512 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 515 | bool app::setTimeOut(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 516 | const std::vector<CJS_Value>& params, |
| 517 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 518 | WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 519 | if (params.size() > 2 || params.size() == 0) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 520 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 521 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 522 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 523 | |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 524 | WideString script = params[0].ToWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 525 | if (script.IsEmpty()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 526 | sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 527 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | } |
| 529 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 530 | uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; |
tsepez | a752edf | 2016-08-19 14:57:42 -0700 | [diff] [blame] | 531 | GlobalTimer* timerRef = |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 532 | new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script, |
| 533 | dwTimeOut, dwTimeOut); |
tsepez | a752edf | 2016-08-19 14:57:42 -0700 | [diff] [blame] | 534 | m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 535 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 536 | v8::Local<v8::Object> pRetObj = |
| 537 | pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); |
Tom Sepez | c5a1472 | 2017-02-24 15:31:12 -0800 | [diff] [blame] | 538 | if (pRetObj.IsEmpty()) |
| 539 | return false; |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 540 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 541 | CJS_TimerObj* pJS_TimerObj = |
| 542 | static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 543 | TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); |
dsinclair | 2eb7c7d | 2016-08-18 09:58:19 -0700 | [diff] [blame] | 544 | pTimerObj->SetTimer(timerRef); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 545 | vRet = CJS_Value(pRuntime, pRetObj); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 546 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 549 | bool app::clearTimeOut(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 550 | const std::vector<CJS_Value>& params, |
| 551 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 552 | WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 553 | if (params.size() != 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 554 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 555 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 558 | app::ClearTimerCommon(pRuntime, params[0]); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 559 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 562 | bool app::clearInterval(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 563 | const std::vector<CJS_Value>& params, |
| 564 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 565 | WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 566 | if (params.size() != 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 567 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 568 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 571 | app::ClearTimerCommon(pRuntime, params[0]); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 572 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 573 | } |
| 574 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 575 | void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) { |
tsepez | 40faa79 | 2016-07-15 17:58:02 -0700 | [diff] [blame] | 576 | if (param.GetType() != CJS_Value::VT_object) |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 577 | return; |
| 578 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 579 | v8::Local<v8::Object> pObj = param.ToV8Object(pRuntime); |
| 580 | if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 581 | return; |
| 582 | |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 583 | CJS_Object* pJSObj = param.ToObject(pRuntime); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 584 | if (!pJSObj) |
| 585 | return; |
| 586 | |
| 587 | TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject()); |
| 588 | if (!pTimerObj) |
| 589 | return; |
| 590 | |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 591 | GlobalTimer::Cancel(pTimerObj->GetTimerID()); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 594 | bool app::execMenuItem(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 595 | const std::vector<CJS_Value>& params, |
| 596 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 597 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 598 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 599 | } |
| 600 | |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 601 | void app::TimerProc(GlobalTimer* pTimer) { |
Lei Zhang | 2d5a0e1 | 2015-10-05 17:00:03 -0700 | [diff] [blame] | 602 | CJS_Runtime* pRuntime = pTimer->GetRuntime(); |
tsepez | 8ca63de | 2016-08-05 17:12:27 -0700 | [diff] [blame] | 603 | if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0)) |
| 604 | RunJsScript(pRuntime, pTimer->GetJScript()); |
| 605 | } |
Lei Zhang | 2d5a0e1 | 2015-10-05 17:00:03 -0700 | [diff] [blame] | 606 | |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 607 | void app::CancelProc(GlobalTimer* pTimer) { |
tsepez | a752edf | 2016-08-19 14:57:42 -0700 | [diff] [blame] | 608 | m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 611 | void app::RunJsScript(CJS_Runtime* pRuntime, const WideString& wsScript) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 612 | if (!pRuntime->IsBlocking()) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 613 | IJS_EventContext* pContext = pRuntime->NewEventContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | pContext->OnExternal_Exec(); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 615 | WideString wtInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 616 | pContext->RunScript(wsScript, &wtInfo); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 617 | pRuntime->ReleaseEventContext(pContext); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 618 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 621 | bool app::goBack(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 622 | const std::vector<CJS_Value>& params, |
| 623 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 624 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 625 | // Not supported. |
| 626 | return true; |
| 627 | } |
| 628 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 629 | bool app::goForward(CJS_Runtime* pRuntime, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 630 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 631 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 632 | WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 633 | // Not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 634 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 637 | bool app::mailMsg(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 638 | const std::vector<CJS_Value>& params, |
| 639 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 640 | WideString& sError) { |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 641 | std::vector<CJS_Value> newParams = |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 642 | ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", L"cBcc", |
| 643 | L"cSubject", L"cMsg"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 644 | |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 645 | if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 646 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 647 | return false; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 648 | } |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 649 | bool bUI = newParams[0].ToBool(pRuntime); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 650 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 651 | WideString cTo; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 652 | if (newParams[1].GetType() != CJS_Value::VT_unknown) { |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 653 | cTo = newParams[1].ToWideString(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 654 | } else { |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 655 | if (!bUI) { |
| 656 | // cTo parameter required when UI not invoked. |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 657 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 658 | return false; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 659 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 660 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 661 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 662 | WideString cCc; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 663 | if (newParams[2].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 664 | cCc = newParams[2].ToWideString(pRuntime); |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 665 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 666 | WideString cBcc; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 667 | if (newParams[3].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 668 | cBcc = newParams[3].ToWideString(pRuntime); |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 669 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 670 | WideString cSubject; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 671 | if (newParams[4].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 672 | cSubject = newParams[4].ToWideString(pRuntime); |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 673 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 674 | WideString cMsg; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 675 | if (newParams[5].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 676 | cMsg = newParams[5].ToWideString(pRuntime); |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 677 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 678 | pRuntime->BeginBlock(); |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 679 | pRuntime->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), |
dsinclair | 4526faf | 2016-10-11 10:54:49 -0700 | [diff] [blame] | 680 | cSubject.c_str(), cCc.c_str(), |
| 681 | cBcc.c_str(), cMsg.c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 682 | pRuntime->EndBlock(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 683 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 686 | bool app::launchURL(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 687 | const std::vector<CJS_Value>& params, |
| 688 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 689 | WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 690 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 691 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 692 | } |
| 693 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 694 | bool app::get_runtime_highlight(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 695 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 696 | WideString* sError) { |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 697 | vp->Set(pRuntime, m_bRuntimeHighLight); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 698 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 699 | } |
| 700 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 701 | bool app::set_runtime_highlight(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 702 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 703 | WideString* sError) { |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 704 | m_bRuntimeHighLight = vp.ToBool(pRuntime); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 705 | return true; |
| 706 | } |
| 707 | |
| 708 | bool app::get_fullscreen(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 709 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 710 | WideString* sError) { |
| 711 | return false; |
| 712 | } |
| 713 | |
| 714 | bool app::set_fullscreen(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 715 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 716 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 717 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 720 | bool app::popUpMenu(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 721 | const std::vector<CJS_Value>& params, |
| 722 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 723 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 724 | return false; |
| 725 | } |
| 726 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 727 | bool app::browseForDoc(CJS_Runtime* pRuntime, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 728 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 729 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 730 | WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 731 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 732 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 735 | WideString app::SysPathToPDFPath(const WideString& sOldPath) { |
| 736 | WideString sRet = L"/"; |
Tom Sepez | 3c3e271 | 2017-04-17 15:38:19 -0700 | [diff] [blame] | 737 | for (const wchar_t& c : sOldPath) { |
| 738 | if (c != L':') |
| 739 | sRet += (c == L'\\') ? L'/' : c; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 740 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 741 | return sRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 744 | bool app::newDoc(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 745 | const std::vector<CJS_Value>& params, |
| 746 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 747 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 748 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 751 | bool app::openDoc(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 752 | const std::vector<CJS_Value>& params, |
| 753 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 754 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 755 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 758 | bool app::response(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 759 | const std::vector<CJS_Value>& params, |
| 760 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 761 | WideString& sError) { |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 762 | std::vector<CJS_Value> newParams = |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 763 | ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", |
| 764 | L"cDefault", L"bPassword", L"cLabel"); |
Tom Sepez | 621d4de | 2014-07-29 14:01:21 -0700 | [diff] [blame] | 765 | |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 766 | if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 767 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 768 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 769 | } |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 770 | WideString swQuestion = newParams[0].ToWideString(pRuntime); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 771 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 772 | WideString swTitle = L"PDF"; |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 773 | if (newParams[1].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 774 | swTitle = newParams[1].ToWideString(pRuntime); |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 775 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 776 | WideString swDefault; |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 777 | if (newParams[2].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 778 | swDefault = newParams[2].ToWideString(pRuntime); |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 779 | |
| 780 | bool bPassword = false; |
| 781 | if (newParams[3].GetType() != CJS_Value::VT_unknown) |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 782 | bPassword = newParams[3].ToBool(pRuntime); |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 783 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 784 | WideString swLabel; |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 785 | if (newParams[4].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 786 | swLabel = newParams[4].ToWideString(pRuntime); |
Tom Sepez | 621d4de | 2014-07-29 14:01:21 -0700 | [diff] [blame] | 787 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 788 | const int MAX_INPUT_BYTES = 2048; |
Tom Sepez | d7188f7 | 2017-05-02 15:10:58 -0700 | [diff] [blame] | 789 | std::vector<uint8_t> pBuff(MAX_INPUT_BYTES + 2); |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 790 | int nLengthBytes = pRuntime->GetFormFillEnv()->JS_appResponse( |
Lei Zhang | db5256f | 2015-10-02 10:11:43 -0700 | [diff] [blame] | 791 | swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), |
Tom Sepez | d7188f7 | 2017-05-02 15:10:58 -0700 | [diff] [blame] | 792 | bPassword, pBuff.data(), MAX_INPUT_BYTES); |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 793 | |
| 794 | if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 795 | sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 796 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 797 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 798 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 799 | vRet = CJS_Value(pRuntime, WideString::FromUTF16LE( |
Tom Sepez | d7188f7 | 2017-05-02 15:10:58 -0700 | [diff] [blame] | 800 | reinterpret_cast<uint16_t*>(pBuff.data()), |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 801 | nLengthBytes / sizeof(uint16_t)) |
| 802 | .c_str()); |
| 803 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 804 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 807 | bool app::get_media(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 808 | return false; |
| 809 | } |
| 810 | |
| 811 | bool app::set_media(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame^] | 812 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 813 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 814 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 817 | bool app::execDialog(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 818 | const std::vector<CJS_Value>& params, |
| 819 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 820 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 821 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 822 | } |