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