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 | |
Dan Sinclair | 4b172c4 | 2017-10-23 11:22:31 -0400 | [diff] [blame] | 140 | IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj, TimerObj) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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 | |
Dan Sinclair | 4b172c4 | 2017-10-23 11:22:31 -0400 | [diff] [blame] | 203 | IMPLEMENT_JS_CLASS(CJS_App, 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; |
Dan Sinclair | 1d8d9ac | 2017-10-24 11:23:25 -0400 | [diff] [blame] | 220 | aDocs.SetElement( |
| 221 | pRuntime, 0, |
| 222 | pJSDocument ? CJS_Value(pJSDocument->ToV8Object()) : CJS_Value()); |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 223 | if (aDocs.GetLength(pRuntime) > 0) { |
| 224 | if (aDocs.ToV8Value().IsEmpty()) |
| 225 | vp->Set(pRuntime->NewArray()); |
| 226 | else |
| 227 | vp->Set(aDocs.ToV8Value()); |
| 228 | } else { |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 229 | vp->Set(pRuntime->NewNull()); |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 230 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 231 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 232 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 233 | } |
| 234 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 235 | bool app::set_active_docs(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 236 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 237 | WideString* sError) { |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | bool app::get_calculate(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 242 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 243 | WideString* sError) { |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 244 | vp->Set(pRuntime->NewBoolean(m_bCalculate)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 245 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 246 | } |
| 247 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 248 | bool app::set_calculate(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 249 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 250 | WideString* sError) { |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 251 | m_bCalculate = pRuntime->ToBoolean(vp.ToV8Value()); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 252 | pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(m_bCalculate); |
| 253 | return true; |
| 254 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 255 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 256 | bool app::get_forms_version(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 257 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 258 | WideString* sError) { |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 259 | vp->Set(pRuntime->NewNumber(JS_NUM_FORMSVERSION)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 260 | return true; |
| 261 | } |
| 262 | |
| 263 | bool app::set_forms_version(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 264 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 265 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 266 | return false; |
| 267 | } |
| 268 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 269 | bool app::get_viewer_type(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 270 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 271 | WideString* sError) { |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 272 | vp->Set(pRuntime->NewString(JS_STR_VIEWERTYPE)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 273 | return true; |
| 274 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 275 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 276 | bool app::set_viewer_type(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 277 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 278 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 279 | return false; |
| 280 | } |
| 281 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 282 | bool app::get_viewer_variation(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 283 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 284 | WideString* sError) { |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 285 | vp->Set(pRuntime->NewString(JS_STR_VIEWERVARIATION)); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 286 | return true; |
| 287 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 288 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 289 | bool app::set_viewer_variation(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 290 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 291 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 292 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 293 | } |
| 294 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 295 | bool app::get_viewer_version(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 296 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 297 | WideString* sError) { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 298 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 299 | CPDFXFA_Context* pXFAContext = pRuntime->GetFormFillEnv()->GetXFAContext(); |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 300 | if (pXFAContext->ContainsXFAForm()) { |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 301 | vp->Set(pRuntime->NewNumber(JS_NUM_VIEWERVERSION_XFA)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 302 | return true; |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 303 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 304 | #endif // PDF_ENABLE_XFA |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 305 | vp->Set(pRuntime->NewNumber(JS_NUM_VIEWERVERSION)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 306 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 307 | } |
| 308 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 309 | bool app::set_viewer_version(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 310 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 311 | WideString* sError) { |
| 312 | return false; |
| 313 | } |
| 314 | |
| 315 | bool app::get_platform(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 316 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 317 | WideString* sError) { |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 318 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 319 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 320 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 321 | return false; |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 322 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 323 | WideString platfrom = pFormFillEnv->GetPlatform(); |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 324 | if (!platfrom.IsEmpty()) { |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 325 | vp->Set(pRuntime->NewString(platfrom.c_str())); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 326 | return true; |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 327 | } |
| 328 | #endif |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 329 | vp->Set(pRuntime->NewString(JS_STR_PLATFORM)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 330 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 331 | } |
| 332 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 333 | bool app::set_platform(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 334 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 335 | WideString* sError) { |
| 336 | return false; |
| 337 | } |
| 338 | |
| 339 | bool app::get_language(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 340 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 341 | WideString* sError) { |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 342 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 343 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 344 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 345 | return false; |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 346 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 347 | WideString language = pFormFillEnv->GetLanguage(); |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 348 | if (!language.IsEmpty()) { |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 349 | vp->Set(pRuntime->NewString(language.c_str())); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 350 | return true; |
Tom Sepez | 4d6fa83 | 2015-12-08 11:31:59 -0800 | [diff] [blame] | 351 | } |
| 352 | #endif |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 353 | vp->Set(pRuntime->NewString(JS_STR_LANGUAGE)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 354 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 355 | } |
| 356 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 357 | bool app::set_language(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 358 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 359 | WideString* sError) { |
| 360 | return false; |
| 361 | } |
| 362 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 363 | // creates a new fdf object that contains no data |
| 364 | // comment: need reader support |
| 365 | // note: |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 366 | // CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF(); |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 367 | bool app::newFDF(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 368 | const std::vector<CJS_Value>& params, |
| 369 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 370 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 371 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 372 | } |
| 373 | // opens a specified pdf document and returns its document object |
| 374 | // comment:need reader support |
| 375 | // note: as defined in js reference, the proto of this function's fourth |
| 376 | // parmeters, how old an fdf document while do not show it. |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 377 | // CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool |
| 378 | // bUserConv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 379 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 380 | bool app::openFDF(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 381 | const std::vector<CJS_Value>& params, |
| 382 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 383 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 384 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 387 | bool app::alert(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 388 | const std::vector<CJS_Value>& params, |
| 389 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 390 | WideString& sError) { |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 391 | std::vector<CJS_Value> newParams = ExpandKeywordParams( |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 392 | pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 393 | |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 394 | if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 395 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 396 | return false; |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 397 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 398 | |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 399 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); |
| 400 | if (!pFormFillEnv) { |
Dan Sinclair | 1d8d9ac | 2017-10-24 11:23:25 -0400 | [diff] [blame] | 401 | vRet = CJS_Value(pRuntime->NewNumber(0)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 402 | return true; |
tsepez | e1e7bd0 | 2016-08-08 13:03:16 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 405 | WideString swMsg; |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 406 | if (newParams[0].GetType() == CJS_Value::VT_object) { |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 407 | if (newParams[0].IsArrayObject()) { |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 408 | CJS_Array carray(pRuntime->ToArray(newParams[0].ToV8Value())); |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 409 | swMsg = L"["; |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 410 | for (int i = 0; i < carray.GetLength(pRuntime); ++i) { |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 411 | if (i) |
| 412 | swMsg += L", "; |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 413 | |
| 414 | CJS_Value element(carray.GetElement(pRuntime, i)); |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 415 | swMsg += pRuntime->ToWideString(element.ToV8Value()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 416 | } |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 417 | swMsg += L"]"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 418 | } else { |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 419 | swMsg = pRuntime->ToWideString(newParams[0].ToV8Value()); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 420 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 421 | } else { |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 422 | swMsg = pRuntime->ToWideString(newParams[0].ToV8Value()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 425 | int iIcon = 0; |
| 426 | if (newParams[1].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 427 | iIcon = pRuntime->ToInt32(newParams[1].ToV8Value()); |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 428 | |
| 429 | int iType = 0; |
| 430 | if (newParams[2].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 431 | iType = pRuntime->ToInt32(newParams[2].ToV8Value()); |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 432 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 433 | WideString swTitle; |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 434 | if (newParams[3].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 435 | swTitle = pRuntime->ToWideString(newParams[3].ToV8Value()); |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 436 | else |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 437 | swTitle = JSGetStringFromID(IDS_STRING_JSALERT); |
Tom Sepez | bd93257 | 2016-01-29 09:10:41 -0800 | [diff] [blame] | 438 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 439 | pRuntime->BeginBlock(); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 440 | pFormFillEnv->KillFocusAnnot(0); |
tsepez | e1e7bd0 | 2016-08-08 13:03:16 -0700 | [diff] [blame] | 441 | |
Dan Sinclair | 1d8d9ac | 2017-10-24 11:23:25 -0400 | [diff] [blame] | 442 | vRet = CJS_Value(pRuntime->NewNumber( |
| 443 | pFormFillEnv->JS_appAlert(swMsg.c_str(), swTitle.c_str(), iType, iIcon))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 444 | pRuntime->EndBlock(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 445 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 448 | bool app::beep(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 449 | const std::vector<CJS_Value>& params, |
| 450 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 451 | WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 452 | if (params.size() == 1) { |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 453 | pRuntime->GetFormFillEnv()->JS_appBeep( |
| 454 | pRuntime->ToInt32(params[0].ToV8Value())); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 455 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | } |
| 457 | |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 458 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 459 | return false; |
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::findComponent(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 true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 469 | bool app::popUpMenuEx(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 470 | const std::vector<CJS_Value>& params, |
| 471 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 472 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 473 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 476 | bool app::get_fs(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 477 | return false; |
| 478 | } |
| 479 | |
| 480 | bool app::set_fs(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 481 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 482 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 483 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 486 | bool app::setInterval(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 487 | const std::vector<CJS_Value>& params, |
| 488 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 489 | WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 490 | if (params.size() > 2 || params.size() == 0) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 491 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 492 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 493 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 494 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 495 | WideString script = |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 496 | params.size() > 0 ? pRuntime->ToWideString(params[0].ToV8Value()) : L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 497 | if (script.IsEmpty()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 498 | sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 499 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 502 | uint32_t dwInterval = |
| 503 | params.size() > 1 ? pRuntime->ToInt32(params[1].ToV8Value()) : 1000; |
dsinclair | 2eb7c7d | 2016-08-18 09:58:19 -0700 | [diff] [blame] | 504 | |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 505 | GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(), |
| 506 | pRuntime, 0, script, dwInterval, 0); |
tsepez | a752edf | 2016-08-19 14:57:42 -0700 | [diff] [blame] | 507 | m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 508 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 509 | v8::Local<v8::Object> pRetObj = |
| 510 | pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); |
Tom Sepez | c5a1472 | 2017-02-24 15:31:12 -0800 | [diff] [blame] | 511 | if (pRetObj.IsEmpty()) |
| 512 | return false; |
| 513 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 514 | CJS_TimerObj* pJS_TimerObj = |
| 515 | static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 516 | TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); |
dsinclair | 2eb7c7d | 2016-08-18 09:58:19 -0700 | [diff] [blame] | 517 | pTimerObj->SetTimer(timerRef); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 518 | |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 519 | vRet = CJS_Value(pRetObj); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 520 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 523 | bool app::setTimeOut(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 524 | const std::vector<CJS_Value>& params, |
| 525 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 526 | WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 527 | if (params.size() > 2 || params.size() == 0) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 528 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 529 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 530 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 531 | |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 532 | WideString script = pRuntime->ToWideString(params[0].ToV8Value()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 533 | if (script.IsEmpty()) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 534 | sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 535 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 538 | uint32_t dwTimeOut = |
| 539 | params.size() > 1 ? pRuntime->ToInt32(params[1].ToV8Value()) : 1000; |
tsepez | a752edf | 2016-08-19 14:57:42 -0700 | [diff] [blame] | 540 | GlobalTimer* timerRef = |
dsinclair | 82e1767 | 2016-10-11 12:38:01 -0700 | [diff] [blame] | 541 | new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script, |
| 542 | dwTimeOut, dwTimeOut); |
tsepez | a752edf | 2016-08-19 14:57:42 -0700 | [diff] [blame] | 543 | m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 544 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 545 | v8::Local<v8::Object> pRetObj = |
| 546 | pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); |
Tom Sepez | c5a1472 | 2017-02-24 15:31:12 -0800 | [diff] [blame] | 547 | if (pRetObj.IsEmpty()) |
| 548 | return false; |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 549 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 550 | CJS_TimerObj* pJS_TimerObj = |
| 551 | static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 552 | TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); |
dsinclair | 2eb7c7d | 2016-08-18 09:58:19 -0700 | [diff] [blame] | 553 | pTimerObj->SetTimer(timerRef); |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 554 | vRet = CJS_Value(pRetObj); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 555 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 558 | bool app::clearTimeOut(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 559 | const std::vector<CJS_Value>& params, |
| 560 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 561 | WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 562 | if (params.size() != 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 563 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 564 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 567 | app::ClearTimerCommon(pRuntime, params[0]); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 568 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 571 | bool app::clearInterval(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 572 | const std::vector<CJS_Value>& params, |
| 573 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 574 | WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 575 | if (params.size() != 1) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 576 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 577 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 580 | app::ClearTimerCommon(pRuntime, params[0]); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 581 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 582 | } |
| 583 | |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 584 | void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) { |
tsepez | 40faa79 | 2016-07-15 17:58:02 -0700 | [diff] [blame] | 585 | if (param.GetType() != CJS_Value::VT_object) |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 586 | return; |
| 587 | |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 588 | v8::Local<v8::Object> pObj = pRuntime->ToObject(param.ToV8Value()); |
tsepez | b469424 | 2016-08-15 16:44:55 -0700 | [diff] [blame] | 589 | if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 590 | return; |
| 591 | |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 592 | CJS_Object* pJSObj = |
| 593 | static_cast<CJS_Object*>(pRuntime->GetObjectPrivate(pObj)); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 594 | if (!pJSObj) |
| 595 | return; |
| 596 | |
| 597 | TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject()); |
| 598 | if (!pTimerObj) |
| 599 | return; |
| 600 | |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 601 | GlobalTimer::Cancel(pTimerObj->GetTimerID()); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 604 | bool app::execMenuItem(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 605 | const std::vector<CJS_Value>& params, |
| 606 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 607 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 608 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 609 | } |
| 610 | |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 611 | void app::TimerProc(GlobalTimer* pTimer) { |
Lei Zhang | 2d5a0e1 | 2015-10-05 17:00:03 -0700 | [diff] [blame] | 612 | CJS_Runtime* pRuntime = pTimer->GetRuntime(); |
tsepez | 8ca63de | 2016-08-05 17:12:27 -0700 | [diff] [blame] | 613 | if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0)) |
| 614 | RunJsScript(pRuntime, pTimer->GetJScript()); |
| 615 | } |
Lei Zhang | 2d5a0e1 | 2015-10-05 17:00:03 -0700 | [diff] [blame] | 616 | |
tsepez | e3ff76b | 2016-08-08 11:58:47 -0700 | [diff] [blame] | 617 | void app::CancelProc(GlobalTimer* pTimer) { |
tsepez | a752edf | 2016-08-19 14:57:42 -0700 | [diff] [blame] | 618 | m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 621 | void app::RunJsScript(CJS_Runtime* pRuntime, const WideString& wsScript) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 622 | if (!pRuntime->IsBlocking()) { |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 623 | IJS_EventContext* pContext = pRuntime->NewEventContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 624 | pContext->OnExternal_Exec(); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 625 | WideString wtInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 626 | pContext->RunScript(wsScript, &wtInfo); |
Tom Sepez | d6ae2af | 2017-02-16 11:49:55 -0800 | [diff] [blame] | 627 | pRuntime->ReleaseEventContext(pContext); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 628 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 631 | bool app::goBack(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 632 | const std::vector<CJS_Value>& params, |
| 633 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 634 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 635 | // Not supported. |
| 636 | return true; |
| 637 | } |
| 638 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 639 | bool app::goForward(CJS_Runtime* pRuntime, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 640 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 641 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 642 | WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 643 | // Not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 644 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 647 | bool app::mailMsg(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 648 | const std::vector<CJS_Value>& params, |
| 649 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 650 | WideString& sError) { |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 651 | std::vector<CJS_Value> newParams = |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 652 | ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", L"cBcc", |
| 653 | L"cSubject", L"cMsg"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 654 | |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 655 | if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 656 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 657 | return false; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 658 | } |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 659 | bool bUI = pRuntime->ToBoolean(newParams[0].ToV8Value()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 660 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 661 | WideString cTo; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 662 | if (newParams[1].GetType() != CJS_Value::VT_unknown) { |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 663 | cTo = pRuntime->ToWideString(newParams[1].ToV8Value()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 664 | } else { |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 665 | if (!bUI) { |
| 666 | // cTo parameter required when UI not invoked. |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 667 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 668 | return false; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 669 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 670 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 671 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 672 | WideString cCc; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 673 | if (newParams[2].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 674 | cCc = pRuntime->ToWideString(newParams[2].ToV8Value()); |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 675 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 676 | WideString cBcc; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 677 | if (newParams[3].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 678 | cBcc = pRuntime->ToWideString(newParams[3].ToV8Value()); |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 679 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 680 | WideString cSubject; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 681 | if (newParams[4].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 682 | cSubject = pRuntime->ToWideString(newParams[4].ToV8Value()); |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 683 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 684 | WideString cMsg; |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 685 | if (newParams[5].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 686 | cMsg = pRuntime->ToWideString(newParams[5].ToV8Value()); |
Tom Sepez | e5fbd7a | 2016-01-29 17:05:08 -0800 | [diff] [blame] | 687 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 688 | pRuntime->BeginBlock(); |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 689 | pRuntime->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), |
dsinclair | 4526faf | 2016-10-11 10:54:49 -0700 | [diff] [blame] | 690 | cSubject.c_str(), cCc.c_str(), |
| 691 | cBcc.c_str(), cMsg.c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 692 | pRuntime->EndBlock(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 693 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 696 | bool app::launchURL(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 697 | const std::vector<CJS_Value>& params, |
| 698 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 699 | WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 700 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 701 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 702 | } |
| 703 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 704 | bool app::get_runtime_highlight(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 705 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 706 | WideString* sError) { |
Dan Sinclair | e497492 | 2017-10-24 09:36:16 -0400 | [diff] [blame] | 707 | vp->Set(pRuntime->NewBoolean(m_bRuntimeHighLight)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 708 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 709 | } |
| 710 | |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 711 | bool app::set_runtime_highlight(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 712 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 713 | WideString* sError) { |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 714 | m_bRuntimeHighLight = pRuntime->ToBoolean(vp.ToV8Value()); |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 715 | return true; |
| 716 | } |
| 717 | |
| 718 | bool app::get_fullscreen(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 719 | CJS_Value* vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 720 | WideString* sError) { |
| 721 | return false; |
| 722 | } |
| 723 | |
| 724 | bool app::set_fullscreen(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 725 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 726 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 727 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 730 | bool app::popUpMenu(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 731 | const std::vector<CJS_Value>& params, |
| 732 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 733 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 734 | return false; |
| 735 | } |
| 736 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 737 | bool app::browseForDoc(CJS_Runtime* pRuntime, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 738 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 739 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 740 | WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 741 | // Unsafe, not supported. |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 742 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 745 | WideString app::SysPathToPDFPath(const WideString& sOldPath) { |
| 746 | WideString sRet = L"/"; |
Tom Sepez | 3c3e271 | 2017-04-17 15:38:19 -0700 | [diff] [blame] | 747 | for (const wchar_t& c : sOldPath) { |
| 748 | if (c != L':') |
| 749 | sRet += (c == L'\\') ? L'/' : c; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 750 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 751 | return sRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 754 | bool app::newDoc(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 755 | const std::vector<CJS_Value>& params, |
| 756 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 757 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 758 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 761 | bool app::openDoc(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 762 | const std::vector<CJS_Value>& params, |
| 763 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 764 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 765 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 768 | bool app::response(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 769 | const std::vector<CJS_Value>& params, |
| 770 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 771 | WideString& sError) { |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 772 | std::vector<CJS_Value> newParams = |
Dan Sinclair | c970895 | 2017-10-23 09:40:59 -0400 | [diff] [blame] | 773 | ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", |
| 774 | L"cDefault", L"bPassword", L"cLabel"); |
Tom Sepez | 621d4de | 2014-07-29 14:01:21 -0700 | [diff] [blame] | 775 | |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 776 | if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 777 | sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 778 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 779 | } |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 780 | WideString swQuestion = pRuntime->ToWideString(newParams[0].ToV8Value()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 781 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 782 | WideString swTitle = L"PDF"; |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 783 | if (newParams[1].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 784 | swTitle = pRuntime->ToWideString(newParams[1].ToV8Value()); |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 785 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 786 | WideString swDefault; |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 787 | if (newParams[2].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 788 | swDefault = pRuntime->ToWideString(newParams[2].ToV8Value()); |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 789 | |
| 790 | bool bPassword = false; |
| 791 | if (newParams[3].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 792 | bPassword = pRuntime->ToBoolean(newParams[3].ToV8Value()); |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 793 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 794 | WideString swLabel; |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 795 | if (newParams[4].GetType() != CJS_Value::VT_unknown) |
Dan Sinclair | 1b2a18e | 2017-10-24 13:56:29 -0400 | [diff] [blame^] | 796 | swLabel = pRuntime->ToWideString(newParams[4].ToV8Value()); |
Tom Sepez | 621d4de | 2014-07-29 14:01:21 -0700 | [diff] [blame] | 797 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 798 | const int MAX_INPUT_BYTES = 2048; |
Tom Sepez | d7188f7 | 2017-05-02 15:10:58 -0700 | [diff] [blame] | 799 | std::vector<uint8_t> pBuff(MAX_INPUT_BYTES + 2); |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 800 | int nLengthBytes = pRuntime->GetFormFillEnv()->JS_appResponse( |
Lei Zhang | db5256f | 2015-10-02 10:11:43 -0700 | [diff] [blame] | 801 | swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), |
Tom Sepez | d7188f7 | 2017-05-02 15:10:58 -0700 | [diff] [blame] | 802 | bPassword, pBuff.data(), MAX_INPUT_BYTES); |
Tom Sepez | 58fb36a | 2016-02-01 10:32:14 -0800 | [diff] [blame] | 803 | |
| 804 | if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) { |
tsepez | cd5dc85 | 2016-09-08 11:23:24 -0700 | [diff] [blame] | 805 | sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 806 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 807 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 808 | |
Dan Sinclair | 1d8d9ac | 2017-10-24 11:23:25 -0400 | [diff] [blame] | 809 | vRet = CJS_Value(pRuntime->NewString( |
| 810 | WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()), |
| 811 | nLengthBytes / sizeof(uint16_t)) |
| 812 | .c_str())); |
tsepez | f3dc8c6 | 2016-08-10 06:29:29 -0700 | [diff] [blame] | 813 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 814 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 817 | bool app::get_media(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) { |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 818 | return false; |
| 819 | } |
| 820 | |
| 821 | bool app::set_media(CJS_Runtime* pRuntime, |
Dan Sinclair | 33d13f2 | 2017-10-23 09:44:30 -0400 | [diff] [blame] | 822 | const CJS_Value& vp, |
dan sinclair | cbe23db | 2017-10-19 14:29:33 -0400 | [diff] [blame] | 823 | WideString* sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 824 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 825 | } |
| 826 | |
Tom Sepez | b1670b5 | 2017-02-16 17:01:00 -0800 | [diff] [blame] | 827 | bool app::execDialog(CJS_Runtime* pRuntime, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 828 | const std::vector<CJS_Value>& params, |
| 829 | CJS_Value& vRet, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 830 | WideString& sError) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 831 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 832 | } |