| OLD | NEW |
| 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/fpdf_parser/include/ipdf_data_avail.h" | 7 #include "core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/cpdf_data_avail.h" | 9 #include "core/fpdfapi/fpdf_parser/cpdf_data_avail.h" |
| 10 #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.h" | 10 #include "core/fpdfapi/fpdf_parser/fpdf_parser_utility.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 FX_BOOL CPDF_DataAvail::IsObjectsAvail( | 135 FX_BOOL CPDF_DataAvail::IsObjectsAvail( |
| 136 CFX_ArrayTemplate<CPDF_Object*>& obj_array, | 136 CFX_ArrayTemplate<CPDF_Object*>& obj_array, |
| 137 FX_BOOL bParsePage, | 137 FX_BOOL bParsePage, |
| 138 IPDF_DataAvail::DownloadHints* pHints, | 138 IPDF_DataAvail::DownloadHints* pHints, |
| 139 CFX_ArrayTemplate<CPDF_Object*>& ret_array) { | 139 CFX_ArrayTemplate<CPDF_Object*>& ret_array) { |
| 140 if (!obj_array.GetSize()) | 140 if (!obj_array.GetSize()) |
| 141 return TRUE; | 141 return TRUE; |
| 142 | 142 |
| 143 uint32_t count = 0; | 143 uint32_t count = 0; |
| 144 CFX_ArrayTemplate<CPDF_Object*> new_obj_array; | 144 CFX_ArrayTemplate<CPDF_Object*> new_obj_array; |
| 145 int32_t i = 0; | 145 for (int i = 0; i < obj_array.GetSize(); i++) { |
| 146 for (i = 0; i < obj_array.GetSize(); i++) { | |
| 147 CPDF_Object* pObj = obj_array[i]; | 146 CPDF_Object* pObj = obj_array[i]; |
| 148 if (!pObj) | 147 if (!pObj) |
| 149 continue; | 148 continue; |
| 150 | 149 |
| 151 int32_t type = pObj->GetType(); | 150 int32_t type = pObj->GetType(); |
| 152 switch (type) { | 151 switch (type) { |
| 153 case CPDF_Object::ARRAY: { | 152 case CPDF_Object::ARRAY: { |
| 154 CPDF_Array* pArray = pObj->GetArray(); | 153 CPDF_Array* pArray = pObj->GetArray(); |
| 155 for (uint32_t k = 0; k < pArray->GetCount(); ++k) | 154 for (size_t k = 0; k < pArray->GetCount(); ++k) |
| 156 new_obj_array.Add(pArray->GetObjectAt(k)); | 155 new_obj_array.Add(pArray->GetObjectAt(k)); |
| 157 } break; | 156 } break; |
| 158 case CPDF_Object::STREAM: | 157 case CPDF_Object::STREAM: |
| 159 pObj = pObj->GetDict(); | 158 pObj = pObj->GetDict(); |
| 160 case CPDF_Object::DICTIONARY: { | 159 case CPDF_Object::DICTIONARY: { |
| 161 CPDF_Dictionary* pDict = pObj->GetDict(); | 160 CPDF_Dictionary* pDict = pObj->GetDict(); |
| 162 if (pDict && pDict->GetStringBy("Type") == "Page" && !bParsePage) | 161 if (pDict && pDict->GetStringBy("Type") == "Page" && !bParsePage) |
| 163 continue; | 162 continue; |
| 164 | 163 |
| 165 for (const auto& it : *pDict) { | 164 for (const auto& it : *pDict) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 186 CPDF_Object* pReferred = | 185 CPDF_Object* pReferred = |
| 187 m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); | 186 m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); |
| 188 if (pReferred) | 187 if (pReferred) |
| 189 new_obj_array.Add(pReferred); | 188 new_obj_array.Add(pReferred); |
| 190 } | 189 } |
| 191 } break; | 190 } break; |
| 192 } | 191 } |
| 193 } | 192 } |
| 194 | 193 |
| 195 if (count > 0) { | 194 if (count > 0) { |
| 196 int32_t iSize = new_obj_array.GetSize(); | 195 for (int i = 0; i < new_obj_array.GetSize(); ++i) { |
| 197 for (i = 0; i < iSize; ++i) { | |
| 198 CPDF_Object* pObj = new_obj_array[i]; | 196 CPDF_Object* pObj = new_obj_array[i]; |
| 199 if (CPDF_Reference* pRef = pObj->AsReference()) { | 197 if (CPDF_Reference* pRef = pObj->AsReference()) { |
| 200 uint32_t dwNum = pRef->GetRefObjNum(); | 198 uint32_t dwNum = pRef->GetRefObjNum(); |
| 201 if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) | 199 if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) |
| 202 ret_array.Add(pObj); | 200 ret_array.Add(pObj); |
| 203 } else { | 201 } else { |
| 204 ret_array.Add(pObj); | 202 ret_array.Add(pObj); |
| 205 } | 203 } |
| 206 } | 204 } |
| 207 return FALSE; | 205 return FALSE; |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist); | 504 CPDF_Object* pObj = GetObject(dwPageObjNum, pHints, &bExist); |
| 507 if (!pObj) { | 505 if (!pObj) { |
| 508 if (bExist) | 506 if (bExist) |
| 509 UnavailObjList.Add(dwPageObjNum); | 507 UnavailObjList.Add(dwPageObjNum); |
| 510 continue; | 508 continue; |
| 511 } | 509 } |
| 512 | 510 |
| 513 if (pObj->IsArray()) { | 511 if (pObj->IsArray()) { |
| 514 CPDF_Array* pArray = pObj->GetArray(); | 512 CPDF_Array* pArray = pObj->GetArray(); |
| 515 if (pArray) { | 513 if (pArray) { |
| 516 int32_t iSize = pArray->GetCount(); | 514 for (size_t j = 0; j < pArray->GetCount(); ++j) { |
| 517 for (int32_t j = 0; j < iSize; ++j) { | |
| 518 if (CPDF_Reference* pRef = ToReference(pArray->GetObjectAt(j))) | 515 if (CPDF_Reference* pRef = ToReference(pArray->GetObjectAt(j))) |
| 519 UnavailObjList.Add(pRef->GetRefObjNum()); | 516 UnavailObjList.Add(pRef->GetRefObjNum()); |
| 520 } | 517 } |
| 521 } | 518 } |
| 522 } | 519 } |
| 523 | 520 |
| 524 if (!pObj->IsDictionary()) { | 521 if (!pObj->IsDictionary()) { |
| 525 pObj->Release(); | 522 pObj->Release(); |
| 526 continue; | 523 continue; |
| 527 } | 524 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 CPDF_Object* pKids = pDict ? pDict->GetObjectBy("Kids") : NULL; | 573 CPDF_Object* pKids = pDict ? pDict->GetObjectBy("Kids") : NULL; |
| 577 if (!pKids) | 574 if (!pKids) |
| 578 return TRUE; | 575 return TRUE; |
| 579 | 576 |
| 580 switch (pKids->GetType()) { | 577 switch (pKids->GetType()) { |
| 581 case CPDF_Object::REFERENCE: | 578 case CPDF_Object::REFERENCE: |
| 582 m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); | 579 m_PageObjList.Add(pKids->AsReference()->GetRefObjNum()); |
| 583 break; | 580 break; |
| 584 case CPDF_Object::ARRAY: { | 581 case CPDF_Object::ARRAY: { |
| 585 CPDF_Array* pKidsArray = pKids->AsArray(); | 582 CPDF_Array* pKidsArray = pKids->AsArray(); |
| 586 for (uint32_t i = 0; i < pKidsArray->GetCount(); ++i) { | 583 for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { |
| 587 if (CPDF_Reference* pRef = ToReference(pKidsArray->GetObjectAt(i))) | 584 if (CPDF_Reference* pRef = ToReference(pKidsArray->GetObjectAt(i))) |
| 588 m_PageObjList.Add(pRef->GetRefObjNum()); | 585 m_PageObjList.Add(pRef->GetRefObjNum()); |
| 589 } | 586 } |
| 590 } break; | 587 } break; |
| 591 default: | 588 default: |
| 592 m_docStatus = PDF_DATAAVAIL_ERROR; | 589 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 593 return FALSE; | 590 return FALSE; |
| 594 } | 591 } |
| 595 return TRUE; | 592 return TRUE; |
| 596 } | 593 } |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 } | 1275 } |
| 1279 | 1276 |
| 1280 CPDF_Array* pArray = pPages->AsArray(); | 1277 CPDF_Array* pArray = pPages->AsArray(); |
| 1281 if (!pArray) { | 1278 if (!pArray) { |
| 1282 pPages->Release(); | 1279 pPages->Release(); |
| 1283 m_docStatus = PDF_DATAAVAIL_ERROR; | 1280 m_docStatus = PDF_DATAAVAIL_ERROR; |
| 1284 return FALSE; | 1281 return FALSE; |
| 1285 } | 1282 } |
| 1286 | 1283 |
| 1287 pPageNode->m_type = PDF_PAGENODE_PAGES; | 1284 pPageNode->m_type = PDF_PAGENODE_PAGES; |
| 1288 for (uint32_t i = 0; i < pArray->GetCount(); ++i) { | 1285 for (size_t i = 0; i < pArray->GetCount(); ++i) { |
| 1289 CPDF_Reference* pKid = ToReference(pArray->GetObjectAt(i)); | 1286 CPDF_Reference* pKid = ToReference(pArray->GetObjectAt(i)); |
| 1290 if (!pKid) | 1287 if (!pKid) |
| 1291 continue; | 1288 continue; |
| 1292 | 1289 |
| 1293 PageNode* pNode = new PageNode(); | 1290 PageNode* pNode = new PageNode(); |
| 1294 pPageNode->m_childNode.Add(pNode); | 1291 pPageNode->m_childNode.Add(pNode); |
| 1295 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1292 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| 1296 } | 1293 } |
| 1297 pPages->Release(); | 1294 pPages->Release(); |
| 1298 return TRUE; | 1295 return TRUE; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 | 1338 |
| 1342 switch (pKids->GetType()) { | 1339 switch (pKids->GetType()) { |
| 1343 case CPDF_Object::REFERENCE: { | 1340 case CPDF_Object::REFERENCE: { |
| 1344 CPDF_Reference* pKid = pKids->AsReference(); | 1341 CPDF_Reference* pKid = pKids->AsReference(); |
| 1345 PageNode* pNode = new PageNode(); | 1342 PageNode* pNode = new PageNode(); |
| 1346 pPageNode->m_childNode.Add(pNode); | 1343 pPageNode->m_childNode.Add(pNode); |
| 1347 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1344 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| 1348 } break; | 1345 } break; |
| 1349 case CPDF_Object::ARRAY: { | 1346 case CPDF_Object::ARRAY: { |
| 1350 CPDF_Array* pKidsArray = pKids->AsArray(); | 1347 CPDF_Array* pKidsArray = pKids->AsArray(); |
| 1351 for (uint32_t i = 0; i < pKidsArray->GetCount(); ++i) { | 1348 for (size_t i = 0; i < pKidsArray->GetCount(); ++i) { |
| 1352 CPDF_Reference* pKid = ToReference(pKidsArray->GetObjectAt(i)); | 1349 CPDF_Reference* pKid = ToReference(pKidsArray->GetObjectAt(i)); |
| 1353 if (!pKid) | 1350 if (!pKid) |
| 1354 continue; | 1351 continue; |
| 1355 | 1352 |
| 1356 PageNode* pNode = new PageNode(); | 1353 PageNode* pNode = new PageNode(); |
| 1357 pPageNode->m_childNode.Add(pNode); | 1354 pPageNode->m_childNode.Add(pNode); |
| 1358 pNode->m_dwPageNo = pKid->GetRefObjNum(); | 1355 pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| 1359 } | 1356 } |
| 1360 } break; | 1357 } break; |
| 1361 default: | 1358 default: |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1835 return FormAvailable; | 1832 return FormAvailable; |
| 1836 } | 1833 } |
| 1837 | 1834 |
| 1838 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} | 1835 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} |
| 1839 | 1836 |
| 1840 CPDF_DataAvail::PageNode::~PageNode() { | 1837 CPDF_DataAvail::PageNode::~PageNode() { |
| 1841 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) | 1838 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) |
| 1842 delete m_childNode[i]; | 1839 delete m_childNode[i]; |
| 1843 m_childNode.RemoveAll(); | 1840 m_childNode.RemoveAll(); |
| 1844 } | 1841 } |
| OLD | NEW |