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

Side by Side Diff: core/fpdfapi/parser/cpdf_data_avail.cpp

Issue 2611413002: Remove CFX_ArrayTemplate from fpdfapi (Closed)
Patch Set: Created 3 years, 11 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
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "core/fpdfapi/parser/cpdf_data_avail.h" 7 #include "core/fpdfapi/parser/cpdf_data_avail.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 446
447 bool CPDF_DataAvail::IsFirstCheck(uint32_t dwPage) { 447 bool CPDF_DataAvail::IsFirstCheck(uint32_t dwPage) {
448 return m_pageMapCheckState.insert(dwPage).second; 448 return m_pageMapCheckState.insert(dwPage).second;
449 } 449 }
450 450
451 void CPDF_DataAvail::ResetFirstCheck(uint32_t dwPage) { 451 void CPDF_DataAvail::ResetFirstCheck(uint32_t dwPage) {
452 m_pageMapCheckState.erase(dwPage); 452 m_pageMapCheckState.erase(dwPage);
453 } 453 }
454 454
455 bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) { 455 bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) {
456 uint32_t iPageObjs = m_PageObjList.GetSize(); 456 std::vector<uint32_t> UnavailObjList;
457 CFX_ArrayTemplate<uint32_t> UnavailObjList; 457 for (uint32_t dwPageObjNum : m_PageObjList) {
458 for (uint32_t i = 0; i < iPageObjs; ++i) { 458 bool bExists = false;
459 uint32_t dwPageObjNum = m_PageObjList.GetAt(i);
460 bool bExist = false;
461 std::unique_ptr<CPDF_Object> pObj = 459 std::unique_ptr<CPDF_Object> pObj =
462 GetObject(dwPageObjNum, pHints, &bExist); 460 GetObject(dwPageObjNum, pHints, &bExists);
463 if (!pObj) { 461 if (!pObj) {
464 if (bExist) 462 if (bExists)
465 UnavailObjList.Add(dwPageObjNum); 463 UnavailObjList.push_back(dwPageObjNum);
466 continue; 464 continue;
467 } 465 }
468
469 CPDF_Array* pArray = ToArray(pObj.get()); 466 CPDF_Array* pArray = ToArray(pObj.get());
470 if (pArray) { 467 if (pArray) {
471 for (const auto& pArrayObj : *pArray) { 468 for (const auto& pArrayObj : *pArray) {
472 if (CPDF_Reference* pRef = ToReference(pArrayObj.get())) 469 if (CPDF_Reference* pRef = ToReference(pArrayObj.get()))
473 UnavailObjList.Add(pRef->GetRefObjNum()); 470 UnavailObjList.push_back(pRef->GetRefObjNum());
474 } 471 }
475 } 472 }
476 if (!pObj->IsDictionary()) 473 if (!pObj->IsDictionary())
477 continue; 474 continue;
478 475
479 CFX_ByteString type = pObj->GetDict()->GetStringFor("Type"); 476 CFX_ByteString type = pObj->GetDict()->GetStringFor("Type");
480 if (type == "Pages") { 477 if (type == "Pages") {
481 m_PagesArray.push_back(std::move(pObj)); 478 m_PagesArray.push_back(std::move(pObj));
482 continue; 479 continue;
483 } 480 }
484 } 481 }
485 482 m_PageObjList.clear();
486 m_PageObjList.RemoveAll(); 483 if (!UnavailObjList.empty()) {
487 if (UnavailObjList.GetSize()) { 484 m_PageObjList = std::move(UnavailObjList);
488 m_PageObjList.Append(UnavailObjList);
489 return false; 485 return false;
490 } 486 }
491 487 size_t iPages = m_PagesArray.size();
492 uint32_t iPages = m_PagesArray.size(); 488 for (size_t i = 0; i < iPages; ++i) {
493 for (uint32_t i = 0; i < iPages; i++) {
494 std::unique_ptr<CPDF_Object> pPages = std::move(m_PagesArray[i]); 489 std::unique_ptr<CPDF_Object> pPages = std::move(m_PagesArray[i]);
495 if (pPages && !GetPageKids(m_pCurrentParser, pPages.get())) { 490 if (pPages && !GetPageKids(m_pCurrentParser, pPages.get())) {
496 m_PagesArray.clear(); 491 m_PagesArray.clear();
497 m_docStatus = PDF_DATAAVAIL_ERROR; 492 m_docStatus = PDF_DATAAVAIL_ERROR;
498 return false; 493 return false;
499 } 494 }
500 } 495 }
501 m_PagesArray.clear(); 496 m_PagesArray.clear();
502 if (!m_PageObjList.GetSize()) 497 if (m_PageObjList.empty())
503 m_docStatus = PDF_DATAAVAIL_DONE; 498 m_docStatus = PDF_DATAAVAIL_DONE;
504 499
505 return true; 500 return true;
506 } 501 }
507 502
508 bool CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) { 503 bool CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) {
509 if (!pParser) { 504 if (!pParser) {
510 m_docStatus = PDF_DATAAVAIL_ERROR; 505 m_docStatus = PDF_DATAAVAIL_ERROR;
511 return false; 506 return false;
512 } 507 }
513 508
514 CPDF_Dictionary* pDict = pPages->GetDict(); 509 CPDF_Dictionary* pDict = pPages->GetDict();
515 CPDF_Object* pKids = pDict ? pDict->GetObjectFor("Kids") : nullptr; 510 CPDF_Object* pKids = pDict ? pDict->GetObjectFor("Kids") : nullptr;
516 if (!pKids) 511 if (!pKids)
517 return true; 512 return true;
518 513
519 switch (pKids->GetType()) { 514 switch (pKids->GetType()) {
520 case CPDF_Object::REFERENCE: 515 case CPDF_Object::REFERENCE:
521 m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); 516 m_PageObjList.push_back(pKids->AsReference()->GetRefObjNum());
522 break; 517 break;
523 case CPDF_Object::ARRAY: { 518 case CPDF_Object::ARRAY: {
524 CPDF_Array* pKidsArray = pKids->AsArray(); 519 CPDF_Array* pKidsArray = pKids->AsArray();
525 for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { 520 for (size_t i = 0; i < pKidsArray->GetCount(); ++i) {
526 if (CPDF_Reference* pRef = ToReference(pKidsArray->GetObjectAt(i))) 521 if (CPDF_Reference* pRef = ToReference(pKidsArray->GetObjectAt(i)))
527 m_PageObjList.Add(pRef->GetRefObjNum()); 522 m_PageObjList.push_back(pRef->GetRefObjNum());
528 } 523 }
529 } break; 524 } break;
530 default: 525 default:
531 m_docStatus = PDF_DATAAVAIL_ERROR; 526 m_docStatus = PDF_DATAAVAIL_ERROR;
532 return false; 527 return false;
533 } 528 }
534 return true; 529 return true;
535 } 530 }
536 531
537 bool CPDF_DataAvail::CheckPages(DownloadHints* pHints) { 532 bool CPDF_DataAvail::CheckPages(DownloadHints* pHints) {
538 bool bExist = false; 533 bool bExists = false;
539 std::unique_ptr<CPDF_Object> pPages = 534 std::unique_ptr<CPDF_Object> pPages =
540 GetObject(m_PagesObjNum, pHints, &bExist); 535 GetObject(m_PagesObjNum, pHints, &bExists);
541 if (!bExist) { 536 if (!bExists) {
542 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; 537 m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
543 return true; 538 return true;
544 } 539 }
545 540
546 if (!pPages) { 541 if (!pPages) {
547 if (m_docStatus == PDF_DATAAVAIL_ERROR) { 542 if (m_docStatus == PDF_DATAAVAIL_ERROR) {
548 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; 543 m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
549 return true; 544 return true;
550 } 545 }
551 return false; 546 return false;
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 m_bCurPageDictLoadOK = true; 1109 m_bCurPageDictLoadOK = true;
1115 m_docStatus = PDF_DATAAVAIL_PAGE; 1110 m_docStatus = PDF_DATAAVAIL_PAGE;
1116 return true; 1111 return true;
1117 } 1112 }
1118 } 1113 }
1119 } 1114 }
1120 1115
1121 bool CPDF_DataAvail::CheckArrayPageNode(uint32_t dwPageNo, 1116 bool CPDF_DataAvail::CheckArrayPageNode(uint32_t dwPageNo,
1122 PageNode* pPageNode, 1117 PageNode* pPageNode,
1123 DownloadHints* pHints) { 1118 DownloadHints* pHints) {
1124 bool bExist = false; 1119 bool bExists = false;
1125 std::unique_ptr<CPDF_Object> pPages = GetObject(dwPageNo, pHints, &bExist); 1120 std::unique_ptr<CPDF_Object> pPages = GetObject(dwPageNo, pHints, &bExists);
1126 if (!bExist) { 1121 if (!bExists) {
1127 m_docStatus = PDF_DATAAVAIL_ERROR; 1122 m_docStatus = PDF_DATAAVAIL_ERROR;
1128 return false; 1123 return false;
1129 } 1124 }
1130 1125
1131 if (!pPages) { 1126 if (!pPages) {
1132 if (m_docStatus == PDF_DATAAVAIL_ERROR) { 1127 if (m_docStatus == PDF_DATAAVAIL_ERROR) {
1133 m_docStatus = PDF_DATAAVAIL_ERROR; 1128 m_docStatus = PDF_DATAAVAIL_ERROR;
1134 return false; 1129 return false;
1135 } 1130 }
1136 return false; 1131 return false;
(...skipping 14 matching lines...) Expand all
1151 auto pNode = pdfium::MakeUnique<PageNode>(); 1146 auto pNode = pdfium::MakeUnique<PageNode>();
1152 pNode->m_dwPageNo = pKid->GetRefObjNum(); 1147 pNode->m_dwPageNo = pKid->GetRefObjNum();
1153 pPageNode->m_ChildNodes.push_back(std::move(pNode)); 1148 pPageNode->m_ChildNodes.push_back(std::move(pNode));
1154 } 1149 }
1155 return true; 1150 return true;
1156 } 1151 }
1157 1152
1158 bool CPDF_DataAvail::CheckUnknownPageNode(uint32_t dwPageNo, 1153 bool CPDF_DataAvail::CheckUnknownPageNode(uint32_t dwPageNo,
1159 PageNode* pPageNode, 1154 PageNode* pPageNode,
1160 DownloadHints* pHints) { 1155 DownloadHints* pHints) {
1161 bool bExist = false; 1156 bool bExists = false;
1162 std::unique_ptr<CPDF_Object> pPage = GetObject(dwPageNo, pHints, &bExist); 1157 std::unique_ptr<CPDF_Object> pPage = GetObject(dwPageNo, pHints, &bExists);
1163 if (!bExist) { 1158 if (!bExists) {
1164 m_docStatus = PDF_DATAAVAIL_ERROR; 1159 m_docStatus = PDF_DATAAVAIL_ERROR;
1165 return false; 1160 return false;
1166 } 1161 }
1167 1162
1168 if (!pPage) { 1163 if (!pPage) {
1169 if (m_docStatus == PDF_DATAAVAIL_ERROR) 1164 if (m_docStatus == PDF_DATAAVAIL_ERROR)
1170 m_docStatus = PDF_DATAAVAIL_ERROR; 1165 m_docStatus = PDF_DATAAVAIL_ERROR;
1171 return false; 1166 return false;
1172 } 1167 }
1173 1168
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 } 1280 }
1286 if (m_PageNode.m_type == PDF_PAGENODE_PAGE) { 1281 if (m_PageNode.m_type == PDF_PAGENODE_PAGE) {
1287 m_docStatus = iPage == 0 ? PDF_DATAAVAIL_DONE : PDF_DATAAVAIL_ERROR; 1282 m_docStatus = iPage == 0 ? PDF_DATAAVAIL_DONE : PDF_DATAAVAIL_ERROR;
1288 return true; 1283 return true;
1289 } 1284 }
1290 int32_t iCount = -1; 1285 int32_t iCount = -1;
1291 return CheckPageNode(m_PageNode, iPage, iCount, pHints, 0); 1286 return CheckPageNode(m_PageNode, iPage, iCount, pHints, 0);
1292 } 1287 }
1293 1288
1294 bool CPDF_DataAvail::CheckPageCount(DownloadHints* pHints) { 1289 bool CPDF_DataAvail::CheckPageCount(DownloadHints* pHints) {
1295 bool bExist = false; 1290 bool bExists = false;
1296 std::unique_ptr<CPDF_Object> pPages = 1291 std::unique_ptr<CPDF_Object> pPages =
1297 GetObject(m_PagesObjNum, pHints, &bExist); 1292 GetObject(m_PagesObjNum, pHints, &bExists);
1298 if (!bExist) { 1293 if (!bExists) {
1299 m_docStatus = PDF_DATAAVAIL_ERROR; 1294 m_docStatus = PDF_DATAAVAIL_ERROR;
1300 return false; 1295 return false;
1301 } 1296 }
1302
1303 if (!pPages) 1297 if (!pPages)
1304 return false; 1298 return false;
1305 1299
1306 CPDF_Dictionary* pPagesDict = pPages->GetDict(); 1300 CPDF_Dictionary* pPagesDict = pPages->GetDict();
1307 if (!pPagesDict) { 1301 if (!pPagesDict) {
1308 m_docStatus = PDF_DATAAVAIL_ERROR; 1302 m_docStatus = PDF_DATAAVAIL_ERROR;
1309 return false; 1303 return false;
1310 } 1304 }
1311
1312 if (!pPagesDict->KeyExist("Kids")) 1305 if (!pPagesDict->KeyExist("Kids"))
1313 return true; 1306 return true;
1314 1307
1315 return pPagesDict->GetIntegerFor("Count") > 0; 1308 return pPagesDict->GetIntegerFor("Count") > 0;
1316 } 1309 }
1317 1310
1318 bool CPDF_DataAvail::LoadDocPages(DownloadHints* pHints) { 1311 bool CPDF_DataAvail::LoadDocPages(DownloadHints* pHints) {
1319 if (!CheckUnknownPageNode(m_PagesObjNum, &m_PageNode, pHints)) 1312 if (!CheckUnknownPageNode(m_PagesObjNum, &m_PageNode, pHints))
1320 return false; 1313 return false;
1321 1314
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 return false; 1687 return false;
1695 std::vector<CPDF_Object*> obj_array; 1688 std::vector<CPDF_Object*> obj_array;
1696 obj_array.push_back(pAcroForm); 1689 obj_array.push_back(pAcroForm);
1697 std::vector<CPDF_Object*> dummy; 1690 std::vector<CPDF_Object*> dummy;
1698 return AreObjectsAvailable(obj_array, true, nullptr, dummy); 1691 return AreObjectsAvailable(obj_array, true, nullptr, dummy);
1699 } 1692 }
1700 1693
1701 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} 1694 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {}
1702 1695
1703 CPDF_DataAvail::PageNode::~PageNode() {} 1696 CPDF_DataAvail::PageNode::~PageNode() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698