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