Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: fpdfsdk/javascript/Document.cpp

Issue 2431913003: Revert of Make Document::m_IconList a vector of IconElements. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/javascript/Document.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_Icons.push_back(IconElement(swIconName, static_cast<Icon*>(pEmbedObj))); 1259 m_IconList.push_back(std::unique_ptr<IconElement>(
1260 new IconElement(swIconName, (Icon*)pEmbedObj)));
1260 return TRUE; 1261 return TRUE;
1261 } 1262 }
1262 1263
1263 FX_BOOL Document::icons(IJS_Context* cc, 1264 FX_BOOL Document::icons(IJS_Context* cc,
1264 CJS_PropValue& vp, 1265 CJS_PropValue& vp,
1265 CFX_WideString& sError) { 1266 CFX_WideString& sError) {
1266 if (vp.IsSetting()) { 1267 if (vp.IsSetting()) {
1267 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); 1268 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
1268 return FALSE; 1269 return FALSE;
1269 } 1270 }
1270 1271
1271 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1272 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1272 if (m_Icons.empty()) { 1273 if (m_IconList.empty()) {
1273 vp.GetJSValue()->SetNull(pRuntime); 1274 vp.GetJSValue()->SetNull(pRuntime);
1274 return TRUE; 1275 return TRUE;
1275 } 1276 }
1276 1277
1277 CJS_Array Icons; 1278 CJS_Array Icons;
1278 1279
1279 int i = 0; 1280 int i = 0;
1280 for (const auto& element : m_Icons) { 1281 for (const auto& pIconElement : m_IconList) {
1281 v8::Local<v8::Object> pObj = 1282 v8::Local<v8::Object> pObj =
1282 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); 1283 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
1283 if (pObj.IsEmpty()) 1284 if (pObj.IsEmpty())
1284 return FALSE; 1285 return FALSE;
1285 1286
1286 CJS_Icon* pJS_Icon = 1287 CJS_Icon* pJS_Icon =
1287 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); 1288 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
1288 if (!pJS_Icon) 1289 if (!pJS_Icon)
1289 return FALSE; 1290 return FALSE;
1290 1291
1291 Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject()); 1292 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1292 if (!pIcon) 1293 if (!pIcon)
1293 return FALSE; 1294 return FALSE;
1294 1295
1295 pIcon->SetStream(element.IconStream->GetStream()); 1296 pIcon->SetStream(pIconElement->IconStream->GetStream());
1296 pIcon->SetIconName(element.IconName); 1297 pIcon->SetIconName(pIconElement->IconName);
1297 Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); 1298 Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon));
1298 } 1299 }
1299 1300
1300 vp << Icons; 1301 vp << Icons;
1301 return TRUE; 1302 return TRUE;
1302 } 1303 }
1303 1304
1304 FX_BOOL Document::getIcon(IJS_Context* cc, 1305 FX_BOOL Document::getIcon(IJS_Context* cc,
1305 const std::vector<CJS_Value>& params, 1306 const std::vector<CJS_Value>& params,
1306 CJS_Value& vRet, 1307 CJS_Value& vRet,
1307 CFX_WideString& sError) { 1308 CFX_WideString& sError) {
1308 if (params.size() != 1) { 1309 if (params.size() != 1) {
1309 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); 1310 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
1310 return FALSE; 1311 return FALSE;
1311 } 1312 }
1312 1313
1313 if (m_Icons.empty()) 1314 if (m_IconList.empty())
1314 return FALSE; 1315 return FALSE;
1315 1316
1316 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1317 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1317 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); 1318 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime);
1318 1319
1319 for (const auto& element : m_Icons) { 1320 for (const auto& pIconElement : m_IconList) {
1320 if (element.IconName != swIconName) 1321 if (pIconElement->IconName == swIconName) {
1321 continue; 1322 Icon* pRetIcon = pIconElement->IconStream;
1322 1323
1323 v8::Local<v8::Object> pObj = 1324 v8::Local<v8::Object> pObj =
1324 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); 1325 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
1325 if (pObj.IsEmpty()) 1326 if (pObj.IsEmpty())
1326 return FALSE; 1327 return FALSE;
1327 1328
1328 CJS_Icon* pJS_Icon = 1329 CJS_Icon* pJS_Icon =
1329 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); 1330 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
1330 if (!pJS_Icon) 1331 if (!pJS_Icon)
1331 return FALSE; 1332 return FALSE;
1332 1333
1333 Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject()); 1334 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1334 if (!pIcon) 1335 if (!pIcon)
1335 return FALSE; 1336 return FALSE;
1336 1337
1337 pIcon->SetIconName(swIconName); 1338 pIcon->SetIconName(swIconName);
1338 pIcon->SetStream(element.IconStream->GetStream()); 1339 pIcon->SetStream(pRetIcon->GetStream());
1339 vRet = CJS_Value(pRuntime, pJS_Icon); 1340 vRet = CJS_Value(pRuntime, pJS_Icon);
1340 return TRUE; 1341 return TRUE;
1342 }
1341 } 1343 }
1342 1344
1343 return FALSE; 1345 return FALSE;
1344 } 1346 }
1345 1347
1346 FX_BOOL Document::removeIcon(IJS_Context* cc, 1348 FX_BOOL Document::removeIcon(IJS_Context* cc,
1347 const std::vector<CJS_Value>& params, 1349 const std::vector<CJS_Value>& params,
1348 CJS_Value& vRet, 1350 CJS_Value& vRet,
1349 CFX_WideString& sError) { 1351 CFX_WideString& sError) {
1350 // Unsafe, no supported. 1352 // Unsafe, no supported.
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 } 1715 }
1714 } 1716 }
1715 1717
1716 for (const auto& pData : DelayDataForFieldAndControlIndex) 1718 for (const auto& pData : DelayDataForFieldAndControlIndex)
1717 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); 1719 Field::DoDelay(m_pFormFillEnv.Get(), pData.get());
1718 } 1720 }
1719 1721
1720 CJS_Document* Document::GetCJSDoc() const { 1722 CJS_Document* Document::GetCJSDoc() const {
1721 return static_cast<CJS_Document*>(m_pJSObject); 1723 return static_cast<CJS_Document*>(m_pJSObject);
1722 } 1724 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/Document.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698