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