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