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 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); | 1249 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
1250 return FALSE; | 1250 return FALSE; |
1251 } | 1251 } |
1252 | 1252 |
1253 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); | 1253 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); |
1254 if (!pEmbedObj) { | 1254 if (!pEmbedObj) { |
1255 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); | 1255 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
1256 return FALSE; | 1256 return FALSE; |
1257 } | 1257 } |
1258 | 1258 |
1259 m_IconList.push_back(std::unique_ptr<IconElement>( | 1259 m_Icons.push_back(IconElement(swIconName, static_cast<Icon*>(pEmbedObj))); |
1260 new IconElement(swIconName, (Icon*)pEmbedObj))); | |
1261 return TRUE; | 1260 return TRUE; |
1262 } | 1261 } |
1263 | 1262 |
1264 FX_BOOL Document::icons(IJS_Context* cc, | 1263 FX_BOOL Document::icons(IJS_Context* cc, |
1265 CJS_PropValue& vp, | 1264 CJS_PropValue& vp, |
1266 CFX_WideString& sError) { | 1265 CFX_WideString& sError) { |
1267 if (vp.IsSetting()) { | 1266 if (vp.IsSetting()) { |
1268 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 1267 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
1269 return FALSE; | 1268 return FALSE; |
1270 } | 1269 } |
1271 | 1270 |
1272 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1271 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1273 if (m_IconList.empty()) { | 1272 if (m_Icons.empty()) { |
1274 vp.GetJSValue()->SetNull(pRuntime); | 1273 vp.GetJSValue()->SetNull(pRuntime); |
1275 return TRUE; | 1274 return TRUE; |
1276 } | 1275 } |
1277 | 1276 |
1278 CJS_Array Icons; | 1277 CJS_Array Icons; |
1279 | 1278 |
1280 int i = 0; | 1279 int i = 0; |
1281 for (const auto& pIconElement : m_IconList) { | 1280 for (const auto& element : m_Icons) { |
1282 v8::Local<v8::Object> pObj = | 1281 v8::Local<v8::Object> pObj = |
1283 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); | 1282 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
1284 if (pObj.IsEmpty()) | 1283 if (pObj.IsEmpty()) |
1285 return FALSE; | 1284 return FALSE; |
1286 | 1285 |
1287 CJS_Icon* pJS_Icon = | 1286 CJS_Icon* pJS_Icon = |
1288 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); | 1287 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
1289 if (!pJS_Icon) | 1288 if (!pJS_Icon) |
1290 return FALSE; | 1289 return FALSE; |
1291 | 1290 |
1292 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 1291 Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject()); |
1293 if (!pIcon) | 1292 if (!pIcon) |
1294 return FALSE; | 1293 return FALSE; |
1295 | 1294 |
1296 pIcon->SetStream(pIconElement->IconStream->GetStream()); | 1295 pIcon->SetStream(element.IconStream->GetStream()); |
1297 pIcon->SetIconName(pIconElement->IconName); | 1296 pIcon->SetIconName(element.IconName); |
1298 Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); | 1297 Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); |
1299 } | 1298 } |
1300 | 1299 |
1301 vp << Icons; | 1300 vp << Icons; |
1302 return TRUE; | 1301 return TRUE; |
1303 } | 1302 } |
1304 | 1303 |
1305 FX_BOOL Document::getIcon(IJS_Context* cc, | 1304 FX_BOOL Document::getIcon(IJS_Context* cc, |
1306 const std::vector<CJS_Value>& params, | 1305 const std::vector<CJS_Value>& params, |
1307 CJS_Value& vRet, | 1306 CJS_Value& vRet, |
1308 CFX_WideString& sError) { | 1307 CFX_WideString& sError) { |
1309 if (params.size() != 1) { | 1308 if (params.size() != 1) { |
1310 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1309 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1311 return FALSE; | 1310 return FALSE; |
1312 } | 1311 } |
1313 | 1312 |
1314 if (m_IconList.empty()) | 1313 if (m_Icons.empty()) |
1315 return FALSE; | 1314 return FALSE; |
1316 | 1315 |
1317 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1316 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1318 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); | 1317 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
1319 | 1318 |
1320 for (const auto& pIconElement : m_IconList) { | 1319 for (const auto& element : m_Icons) { |
1321 if (pIconElement->IconName == swIconName) { | 1320 if (element.IconName != swIconName) |
1322 Icon* pRetIcon = pIconElement->IconStream; | 1321 continue; |
1323 | 1322 |
1324 v8::Local<v8::Object> pObj = | 1323 v8::Local<v8::Object> pObj = |
1325 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); | 1324 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
1326 if (pObj.IsEmpty()) | 1325 if (pObj.IsEmpty()) |
1327 return FALSE; | 1326 return FALSE; |
1328 | 1327 |
1329 CJS_Icon* pJS_Icon = | 1328 CJS_Icon* pJS_Icon = |
1330 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); | 1329 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
1331 if (!pJS_Icon) | 1330 if (!pJS_Icon) |
1332 return FALSE; | 1331 return FALSE; |
1333 | 1332 |
1334 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 1333 Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject()); |
1335 if (!pIcon) | 1334 if (!pIcon) |
1336 return FALSE; | 1335 return FALSE; |
1337 | 1336 |
1338 pIcon->SetIconName(swIconName); | 1337 pIcon->SetIconName(swIconName); |
1339 pIcon->SetStream(pRetIcon->GetStream()); | 1338 pIcon->SetStream(element.IconStream->GetStream()); |
1340 vRet = CJS_Value(pRuntime, pJS_Icon); | 1339 vRet = CJS_Value(pRuntime, pJS_Icon); |
1341 return TRUE; | 1340 return TRUE; |
1342 } | |
1343 } | 1341 } |
1344 | 1342 |
1345 return FALSE; | 1343 return FALSE; |
1346 } | 1344 } |
1347 | 1345 |
1348 FX_BOOL Document::removeIcon(IJS_Context* cc, | 1346 FX_BOOL Document::removeIcon(IJS_Context* cc, |
1349 const std::vector<CJS_Value>& params, | 1347 const std::vector<CJS_Value>& params, |
1350 CJS_Value& vRet, | 1348 CJS_Value& vRet, |
1351 CFX_WideString& sError) { | 1349 CFX_WideString& sError) { |
1352 // Unsafe, no supported. | 1350 // Unsafe, no supported. |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 } | 1713 } |
1716 } | 1714 } |
1717 | 1715 |
1718 for (const auto& pData : DelayDataForFieldAndControlIndex) | 1716 for (const auto& pData : DelayDataForFieldAndControlIndex) |
1719 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); | 1717 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); |
1720 } | 1718 } |
1721 | 1719 |
1722 CJS_Document* Document::GetCJSDoc() const { | 1720 CJS_Document* Document::GetCJSDoc() const { |
1723 return static_cast<CJS_Document*>(m_pJSObject); | 1721 return static_cast<CJS_Document*>(m_pJSObject); |
1724 } | 1722 } |
OLD | NEW |