OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fpdfsdk/javascript/app.h" | 7 #include "fpdfsdk/javascript/app.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 FX_BOOL app::activeDocs(IJS_Context* cc, | 102 FX_BOOL app::activeDocs(IJS_Context* cc, |
103 CJS_PropValue& vp, | 103 CJS_PropValue& vp, |
104 CFX_WideString& sError) { | 104 CFX_WideString& sError) { |
105 if (!vp.IsGetting()) | 105 if (!vp.IsGetting()) |
106 return FALSE; | 106 return FALSE; |
107 | 107 |
108 CJS_Context* pContext = (CJS_Context*)cc; | 108 CJS_Context* pContext = (CJS_Context*)cc; |
109 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); | 109 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); |
110 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 110 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
111 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); | 111 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); |
112 CJS_Array aDocs(pRuntime); | 112 CJS_Array aDocs; |
113 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { | 113 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { |
114 CJS_Document* pJSDocument = nullptr; | 114 CJS_Document* pJSDocument = nullptr; |
115 if (pDoc == pCurDoc) { | 115 if (pDoc == pCurDoc) { |
116 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate()); | 116 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate()); |
117 if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) | 117 if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) |
118 pJSDocument = | 118 pJSDocument = |
119 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); | 119 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); |
120 } else { | 120 } else { |
121 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 121 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
122 pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID); | 122 pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID); |
123 pJSDocument = | 123 pJSDocument = |
124 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); | 124 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); |
125 ASSERT(pJSDocument); | 125 ASSERT(pJSDocument); |
126 } | 126 } |
127 aDocs.SetElement(0, CJS_Value(pRuntime, pJSDocument)); | 127 aDocs.SetElement(pRuntime->GetIsolate(), 0, |
| 128 CJS_Value(pRuntime, pJSDocument)); |
128 } | 129 } |
129 if (aDocs.GetLength() > 0) | 130 if (aDocs.GetLength() > 0) |
130 vp << aDocs; | 131 vp << aDocs; |
131 else | 132 else |
132 vp.SetNull(); | 133 vp.SetNull(); |
133 | 134 |
134 return TRUE; | 135 return TRUE; |
135 } | 136 } |
136 | 137 |
137 FX_BOOL app::calculate(IJS_Context* cc, | 138 FX_BOOL app::calculate(IJS_Context* cc, |
138 CJS_PropValue& vp, | 139 CJS_PropValue& vp, |
139 CFX_WideString& sError) { | 140 CFX_WideString& sError) { |
140 if (vp.IsSetting()) { | 141 if (vp.IsSetting()) { |
141 bool bVP; | 142 bool bVP; |
142 vp >> bVP; | 143 vp >> bVP; |
143 m_bCalculate = (FX_BOOL)bVP; | 144 m_bCalculate = (FX_BOOL)bVP; |
144 | 145 |
145 CJS_Context* pContext = (CJS_Context*)cc; | 146 CJS_Context* pContext = (CJS_Context*)cc; |
146 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); | 147 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); |
147 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
148 CJS_Array aDocs(pRuntime); | |
149 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) | 148 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) |
150 pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate); | 149 pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate); |
151 } else { | 150 } else { |
152 vp << (bool)m_bCalculate; | 151 vp << (bool)m_bCalculate; |
153 } | 152 } |
154 return TRUE; | 153 return TRUE; |
155 } | 154 } |
156 | 155 |
157 FX_BOOL app::formsVersion(IJS_Context* cc, | 156 FX_BOOL app::formsVersion(IJS_Context* cc, |
158 CJS_PropValue& vp, | 157 CJS_PropValue& vp, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams( | 276 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams( |
278 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); | 277 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); |
279 | 278 |
280 if (newParams[0].GetType() == CJS_Value::VT_unknown) { | 279 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
281 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 280 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
282 return FALSE; | 281 return FALSE; |
283 } | 282 } |
284 | 283 |
285 CFX_WideString swMsg; | 284 CFX_WideString swMsg; |
286 if (newParams[0].GetType() == CJS_Value::VT_object) { | 285 if (newParams[0].GetType() == CJS_Value::VT_object) { |
287 CJS_Array carray(pRuntime); | 286 CJS_Array carray; |
288 if (newParams[0].ConvertToArray(carray)) { | 287 if (newParams[0].ConvertToArray(carray)) { |
289 swMsg = L"["; | 288 swMsg = L"["; |
290 CJS_Value element(pRuntime); | 289 CJS_Value element(pRuntime); |
291 for (int i = 0; i < carray.GetLength(); ++i) { | 290 for (int i = 0; i < carray.GetLength(); ++i) { |
292 if (i) | 291 if (i) |
293 swMsg += L", "; | 292 swMsg += L", "; |
294 carray.GetElement(i, element); | 293 carray.GetElement(pRuntime->GetIsolate(), i, element); |
295 swMsg += element.ToCFXWideString(); | 294 swMsg += element.ToCFXWideString(); |
296 } | 295 } |
297 swMsg += L"]"; | 296 swMsg += L"]"; |
298 } else { | 297 } else { |
299 swMsg = newParams[0].ToCFXWideString(); | 298 swMsg = newParams[0].ToCFXWideString(); |
300 } | 299 } |
301 } else { | 300 } else { |
302 swMsg = newParams[0].ToCFXWideString(); | 301 swMsg = newParams[0].ToCFXWideString(); |
303 } | 302 } |
304 | 303 |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 697 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
699 return FALSE; | 698 return FALSE; |
700 } | 699 } |
701 | 700 |
702 FX_BOOL app::execDialog(IJS_Context* cc, | 701 FX_BOOL app::execDialog(IJS_Context* cc, |
703 const std::vector<CJS_Value>& params, | 702 const std::vector<CJS_Value>& params, |
704 CJS_Value& vRet, | 703 CJS_Value& vRet, |
705 CFX_WideString& sError) { | 704 CFX_WideString& sError) { |
706 return TRUE; | 705 return TRUE; |
707 } | 706 } |
OLD | NEW |