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/Document.h" | 7 #include "fpdfsdk/javascript/Document.h" |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "fpdfsdk/javascript/Icon.h" | 26 #include "fpdfsdk/javascript/Icon.h" |
27 #include "fpdfsdk/javascript/JS_Define.h" | 27 #include "fpdfsdk/javascript/JS_Define.h" |
28 #include "fpdfsdk/javascript/JS_EventHandler.h" | 28 #include "fpdfsdk/javascript/JS_EventHandler.h" |
29 #include "fpdfsdk/javascript/JS_Object.h" | 29 #include "fpdfsdk/javascript/JS_Object.h" |
30 #include "fpdfsdk/javascript/JS_Value.h" | 30 #include "fpdfsdk/javascript/JS_Value.h" |
31 #include "fpdfsdk/javascript/app.h" | 31 #include "fpdfsdk/javascript/app.h" |
32 #include "fpdfsdk/javascript/cjs_context.h" | 32 #include "fpdfsdk/javascript/cjs_context.h" |
33 #include "fpdfsdk/javascript/cjs_runtime.h" | 33 #include "fpdfsdk/javascript/cjs_runtime.h" |
34 #include "fpdfsdk/javascript/resource.h" | 34 #include "fpdfsdk/javascript/resource.h" |
35 #include "third_party/base/numerics/safe_math.h" | 35 #include "third_party/base/numerics/safe_math.h" |
| 36 #include "third_party/base/ptr_util.h" |
36 | 37 |
37 BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj) | 38 BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj) |
38 END_JS_STATIC_CONST() | 39 END_JS_STATIC_CONST() |
39 | 40 |
40 BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj) | 41 BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj) |
41 END_JS_STATIC_PROP() | 42 END_JS_STATIC_PROP() |
42 | 43 |
43 BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj) | 44 BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj) |
44 END_JS_STATIC_METHOD() | 45 END_JS_STATIC_METHOD() |
45 | 46 |
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); | 1250 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
1250 return FALSE; | 1251 return FALSE; |
1251 } | 1252 } |
1252 | 1253 |
1253 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); | 1254 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); |
1254 if (!pEmbedObj) { | 1255 if (!pEmbedObj) { |
1255 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); | 1256 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
1256 return FALSE; | 1257 return FALSE; |
1257 } | 1258 } |
1258 | 1259 |
1259 m_IconList.push_back(std::unique_ptr<IconElement>( | 1260 m_Icons.push_back(pdfium::MakeUnique<IconElement>( |
1260 new IconElement(swIconName, (Icon*)pEmbedObj))); | 1261 swIconName, static_cast<Icon*>(pEmbedObj))); |
1261 return TRUE; | 1262 return TRUE; |
1262 } | 1263 } |
1263 | 1264 |
1264 FX_BOOL Document::icons(IJS_Context* cc, | 1265 FX_BOOL Document::icons(IJS_Context* cc, |
1265 CJS_PropValue& vp, | 1266 CJS_PropValue& vp, |
1266 CFX_WideString& sError) { | 1267 CFX_WideString& sError) { |
1267 if (vp.IsSetting()) { | 1268 if (vp.IsSetting()) { |
1268 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 1269 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
1269 return FALSE; | 1270 return FALSE; |
1270 } | 1271 } |
1271 | 1272 |
1272 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1273 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1273 if (m_IconList.empty()) { | 1274 if (m_Icons.empty()) { |
1274 vp.GetJSValue()->SetNull(pRuntime); | 1275 vp.GetJSValue()->SetNull(pRuntime); |
1275 return TRUE; | 1276 return TRUE; |
1276 } | 1277 } |
1277 | 1278 |
1278 CJS_Array Icons; | 1279 CJS_Array Icons; |
1279 | 1280 |
1280 int i = 0; | 1281 int i = 0; |
1281 for (const auto& pIconElement : m_IconList) { | 1282 for (const auto& pIconElement : m_Icons) { |
1282 v8::Local<v8::Object> pObj = | 1283 v8::Local<v8::Object> pObj = |
1283 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); | 1284 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
1284 if (pObj.IsEmpty()) | 1285 if (pObj.IsEmpty()) |
1285 return FALSE; | 1286 return FALSE; |
1286 | 1287 |
1287 CJS_Icon* pJS_Icon = | 1288 CJS_Icon* pJS_Icon = |
1288 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); | 1289 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
1289 if (!pJS_Icon) | 1290 if (!pJS_Icon) |
1290 return FALSE; | 1291 return FALSE; |
1291 | 1292 |
1292 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 1293 Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject()); |
1293 if (!pIcon) | 1294 if (!pIcon) |
1294 return FALSE; | 1295 return FALSE; |
1295 | 1296 |
1296 pIcon->SetStream(pIconElement->IconStream->GetStream()); | 1297 pIcon->SetStream(pIconElement->IconStream->GetStream()); |
1297 pIcon->SetIconName(pIconElement->IconName); | 1298 pIcon->SetIconName(pIconElement->IconName); |
1298 Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); | 1299 Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); |
1299 } | 1300 } |
1300 | 1301 |
1301 vp << Icons; | 1302 vp << Icons; |
1302 return TRUE; | 1303 return TRUE; |
1303 } | 1304 } |
1304 | 1305 |
1305 FX_BOOL Document::getIcon(IJS_Context* cc, | 1306 FX_BOOL Document::getIcon(IJS_Context* cc, |
1306 const std::vector<CJS_Value>& params, | 1307 const std::vector<CJS_Value>& params, |
1307 CJS_Value& vRet, | 1308 CJS_Value& vRet, |
1308 CFX_WideString& sError) { | 1309 CFX_WideString& sError) { |
1309 if (params.size() != 1) { | 1310 if (params.size() != 1) { |
1310 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1311 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1311 return FALSE; | 1312 return FALSE; |
1312 } | 1313 } |
1313 | 1314 |
1314 if (m_IconList.empty()) | 1315 if (m_Icons.empty()) |
1315 return FALSE; | 1316 return FALSE; |
1316 | 1317 |
1317 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1318 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1318 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); | 1319 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
1319 | 1320 |
1320 for (const auto& pIconElement : m_IconList) { | 1321 for (const auto& pIconElement : m_Icons) { |
1321 if (pIconElement->IconName == swIconName) { | 1322 if (pIconElement->IconName != swIconName) |
1322 Icon* pRetIcon = pIconElement->IconStream; | 1323 continue; |
1323 | 1324 |
1324 v8::Local<v8::Object> pObj = | 1325 v8::Local<v8::Object> pObj = |
1325 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); | 1326 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
1326 if (pObj.IsEmpty()) | 1327 if (pObj.IsEmpty()) |
1327 return FALSE; | 1328 return FALSE; |
1328 | 1329 |
1329 CJS_Icon* pJS_Icon = | 1330 CJS_Icon* pJS_Icon = |
1330 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); | 1331 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
1331 if (!pJS_Icon) | 1332 if (!pJS_Icon) |
1332 return FALSE; | 1333 return FALSE; |
1333 | 1334 |
1334 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 1335 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
1335 if (!pIcon) | 1336 if (!pIcon) |
1336 return FALSE; | 1337 return FALSE; |
1337 | 1338 |
1338 pIcon->SetIconName(swIconName); | 1339 pIcon->SetIconName(swIconName); |
1339 pIcon->SetStream(pRetIcon->GetStream()); | 1340 pIcon->SetStream(pIconElement->IconStream->GetStream()); |
1340 vRet = CJS_Value(pRuntime, pJS_Icon); | 1341 |
1341 return TRUE; | 1342 vRet = CJS_Value(pRuntime, pJS_Icon); |
1342 } | 1343 return TRUE; |
1343 } | 1344 } |
1344 | 1345 |
1345 return FALSE; | 1346 return FALSE; |
1346 } | 1347 } |
1347 | 1348 |
1348 FX_BOOL Document::removeIcon(IJS_Context* cc, | 1349 FX_BOOL Document::removeIcon(IJS_Context* cc, |
1349 const std::vector<CJS_Value>& params, | 1350 const std::vector<CJS_Value>& params, |
1350 CJS_Value& vRet, | 1351 CJS_Value& vRet, |
1351 CFX_WideString& sError) { | 1352 CFX_WideString& sError) { |
1352 // Unsafe, no supported. | 1353 // Unsafe, no supported. |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 } | 1716 } |
1716 } | 1717 } |
1717 | 1718 |
1718 for (const auto& pData : DelayDataForFieldAndControlIndex) | 1719 for (const auto& pData : DelayDataForFieldAndControlIndex) |
1719 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); | 1720 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); |
1720 } | 1721 } |
1721 | 1722 |
1722 CJS_Document* Document::GetCJSDoc() const { | 1723 CJS_Document* Document::GetCJSDoc() const { |
1723 return static_cast<CJS_Document*>(m_pJSObject); | 1724 return static_cast<CJS_Document*>(m_pJSObject); |
1724 } | 1725 } |
OLD | NEW |