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/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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 m_pAcroForm = nullptr; | 73 m_pAcroForm = nullptr; |
74 m_pPageDict = nullptr; | 74 m_pPageDict = nullptr; |
75 m_pPageResource = nullptr; | 75 m_pPageResource = nullptr; |
76 m_docStatus = PDF_DATAAVAIL_HEADER; | 76 m_docStatus = PDF_DATAAVAIL_HEADER; |
77 m_parser.m_bOwnFileRead = false; | 77 m_parser.m_bOwnFileRead = false; |
78 m_bTotalLoadPageTree = FALSE; | 78 m_bTotalLoadPageTree = FALSE; |
79 m_bCurPageDictLoadOK = FALSE; | 79 m_bCurPageDictLoadOK = FALSE; |
80 m_bLinearedDataOK = FALSE; | 80 m_bLinearedDataOK = FALSE; |
81 m_bSupportHintTable = bSupportHintTable; | 81 m_bSupportHintTable = bSupportHintTable; |
82 } | 82 } |
| 83 |
83 CPDF_DataAvail::~CPDF_DataAvail() { | 84 CPDF_DataAvail::~CPDF_DataAvail() { |
84 m_pHintTables.reset(); | 85 m_pHintTables.reset(); |
85 if (m_pLinearized) | 86 if (m_pLinearized) |
86 m_pLinearized->Release(); | 87 m_pLinearized->Release(); |
87 | 88 |
88 if (m_pRoot) | 89 if (m_pRoot) |
89 m_pRoot->Release(); | 90 m_pRoot->Release(); |
90 | 91 |
91 if (m_pTrailer) | 92 if (m_pTrailer) |
92 m_pTrailer->Release(); | 93 m_pTrailer->Release(); |
93 | 94 |
94 int iSize = m_arrayAcroforms.GetSize(); | 95 for (CPDF_Object* pObject : m_arrayAcroforms) |
95 for (int i = 0; i < iSize; ++i) | 96 pObject->Release(); |
96 m_arrayAcroforms.GetAt(i)->Release(); | |
97 } | 97 } |
98 | 98 |
99 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { | 99 void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) { |
100 m_pDocument = pDoc; | 100 m_pDocument = pDoc; |
101 } | 101 } |
102 | 102 |
103 uint32_t CPDF_DataAvail::GetObjectSize(uint32_t objnum, FX_FILESIZE& offset) { | 103 uint32_t CPDF_DataAvail::GetObjectSize(uint32_t objnum, FX_FILESIZE& offset) { |
104 CPDF_Parser* pParser = m_pDocument->GetParser(); | 104 CPDF_Parser* pParser = m_pDocument->GetParser(); |
105 if (!pParser || !pParser->IsValidObjectNumber(objnum)) | 105 if (!pParser || !pParser->IsValidObjectNumber(objnum)) |
106 return 0; | 106 return 0; |
(...skipping 11 matching lines...) Expand all Loading... |
118 return 0; | 118 return 0; |
119 | 119 |
120 auto it = pParser->m_SortedOffset.find(offset); | 120 auto it = pParser->m_SortedOffset.find(offset); |
121 if (it == pParser->m_SortedOffset.end() || | 121 if (it == pParser->m_SortedOffset.end() || |
122 ++it == pParser->m_SortedOffset.end()) { | 122 ++it == pParser->m_SortedOffset.end()) { |
123 return 0; | 123 return 0; |
124 } | 124 } |
125 return *it - offset; | 125 return *it - offset; |
126 } | 126 } |
127 | 127 |
128 FX_BOOL CPDF_DataAvail::IsObjectsAvail( | 128 FX_BOOL CPDF_DataAvail::IsObjectsAvail(std::vector<CPDF_Object*>& obj_array, |
129 CFX_ArrayTemplate<CPDF_Object*>& obj_array, | 129 FX_BOOL bParsePage, |
130 FX_BOOL bParsePage, | 130 DownloadHints* pHints, |
131 DownloadHints* pHints, | 131 std::vector<CPDF_Object*>& ret_array) { |
132 CFX_ArrayTemplate<CPDF_Object*>& ret_array) { | 132 if (obj_array.empty()) |
133 if (!obj_array.GetSize()) | |
134 return TRUE; | 133 return TRUE; |
135 | 134 |
136 uint32_t count = 0; | 135 uint32_t count = 0; |
137 CFX_ArrayTemplate<CPDF_Object*> new_obj_array; | 136 std::vector<CPDF_Object*> new_obj_array; |
138 for (int i = 0; i < obj_array.GetSize(); i++) { | 137 for (CPDF_Object* pObj : obj_array) { |
139 CPDF_Object* pObj = obj_array[i]; | |
140 if (!pObj) | 138 if (!pObj) |
141 continue; | 139 continue; |
142 | 140 |
143 int32_t type = pObj->GetType(); | 141 int32_t type = pObj->GetType(); |
144 switch (type) { | 142 switch (type) { |
145 case CPDF_Object::ARRAY: { | 143 case CPDF_Object::ARRAY: { |
146 CPDF_Array* pArray = pObj->AsArray(); | 144 CPDF_Array* pArray = pObj->AsArray(); |
147 for (size_t k = 0; k < pArray->GetCount(); ++k) | 145 for (size_t k = 0; k < pArray->GetCount(); ++k) |
148 new_obj_array.Add(pArray->GetObjectAt(k)); | 146 new_obj_array.push_back(pArray->GetObjectAt(k)); |
149 } break; | 147 } break; |
150 case CPDF_Object::STREAM: | 148 case CPDF_Object::STREAM: |
151 pObj = pObj->GetDict(); | 149 pObj = pObj->GetDict(); |
152 case CPDF_Object::DICTIONARY: { | 150 case CPDF_Object::DICTIONARY: { |
153 CPDF_Dictionary* pDict = pObj->GetDict(); | 151 CPDF_Dictionary* pDict = pObj->GetDict(); |
154 if (pDict && pDict->GetStringFor("Type") == "Page" && !bParsePage) | 152 if (pDict && pDict->GetStringFor("Type") == "Page" && !bParsePage) |
155 continue; | 153 continue; |
156 | 154 |
157 for (const auto& it : *pDict) { | 155 for (const auto& it : *pDict) { |
158 const CFX_ByteString& key = it.first; | 156 const CFX_ByteString& key = it.first; |
159 CPDF_Object* value = it.second; | 157 CPDF_Object* value = it.second; |
160 if (key != "Parent") | 158 if (key != "Parent") |
161 new_obj_array.Add(value); | 159 new_obj_array.push_back(value); |
162 } | 160 } |
163 } break; | 161 } break; |
164 case CPDF_Object::REFERENCE: { | 162 case CPDF_Object::REFERENCE: { |
165 CPDF_Reference* pRef = pObj->AsReference(); | 163 CPDF_Reference* pRef = pObj->AsReference(); |
166 uint32_t dwNum = pRef->GetRefObjNum(); | 164 uint32_t dwNum = pRef->GetRefObjNum(); |
167 | 165 |
168 FX_FILESIZE offset; | 166 FX_FILESIZE offset; |
169 uint32_t size = GetObjectSize(dwNum, offset); | 167 uint32_t size = GetObjectSize(dwNum, offset); |
170 if (size == 0 || offset < 0 || offset >= m_dwFileLen) | 168 if (size == 0 || offset < 0 || offset >= m_dwFileLen) |
171 break; | 169 break; |
172 | 170 |
173 if (!IsDataAvail(offset, size, pHints)) { | 171 if (!IsDataAvail(offset, size, pHints)) { |
174 ret_array.Add(pObj); | 172 ret_array.push_back(pObj); |
175 count++; | 173 count++; |
176 } else if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) { | 174 } else if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) { |
177 m_ObjectSet.insert(dwNum); | 175 m_ObjectSet.insert(dwNum); |
178 CPDF_Object* pReferred = | 176 CPDF_Object* pReferred = |
179 m_pDocument->GetOrParseIndirectObject(pRef->GetRefObjNum()); | 177 m_pDocument->GetOrParseIndirectObject(pRef->GetRefObjNum()); |
180 if (pReferred) | 178 if (pReferred) |
181 new_obj_array.Add(pReferred); | 179 new_obj_array.push_back(pReferred); |
182 } | 180 } |
183 } break; | 181 } break; |
184 } | 182 } |
185 } | 183 } |
186 | 184 |
187 if (count > 0) { | 185 if (count > 0) { |
188 for (int i = 0; i < new_obj_array.GetSize(); ++i) { | 186 for (CPDF_Object* pObj : new_obj_array) { |
189 CPDF_Object* pObj = new_obj_array[i]; | 187 CPDF_Reference* pRef = pObj->AsReference(); |
190 if (CPDF_Reference* pRef = pObj->AsReference()) { | 188 if (pRef && pdfium::ContainsKey(m_ObjectSet, pRef->GetRefObjNum())) |
191 uint32_t dwNum = pRef->GetRefObjNum(); | 189 continue; |
192 if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) | 190 ret_array.push_back(pObj); |
193 ret_array.Add(pObj); | |
194 } else { | |
195 ret_array.Add(pObj); | |
196 } | |
197 } | 191 } |
198 return FALSE; | 192 return FALSE; |
199 } | 193 } |
200 | 194 |
201 obj_array.RemoveAll(); | 195 obj_array = new_obj_array; |
202 obj_array.Append(new_obj_array); | |
203 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); | 196 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); |
204 } | 197 } |
205 | 198 |
206 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( | 199 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( |
207 DownloadHints* pHints) { | 200 DownloadHints* pHints) { |
208 if (!m_dwFileLen && m_pFileRead) { | 201 if (!m_dwFileLen && m_pFileRead) { |
209 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); | 202 m_dwFileLen = (uint32_t)m_pFileRead->GetSize(); |
210 if (!m_dwFileLen) | 203 if (!m_dwFileLen) |
211 return DataError; | 204 return DataError; |
212 } | 205 } |
213 | 206 |
214 while (!m_bDocAvail) { | 207 while (!m_bDocAvail) { |
215 if (!CheckDocStatus(pHints)) | 208 if (!CheckDocStatus(pHints)) |
216 return DataNotAvailable; | 209 return DataNotAvailable; |
217 } | 210 } |
218 | 211 |
219 return DataAvailable; | 212 return DataAvailable; |
220 } | 213 } |
221 | 214 |
222 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(DownloadHints* pHints) { | 215 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(DownloadHints* pHints) { |
223 if (!m_objs_array.GetSize()) { | 216 if (!m_objs_array.empty()) { |
224 m_objs_array.RemoveAll(); | 217 m_objs_array.clear(); |
225 m_ObjectSet.clear(); | 218 m_ObjectSet.clear(); |
226 CFX_ArrayTemplate<CPDF_Object*> obj_array; | 219 std::vector<CPDF_Object*> obj_array = m_arrayAcroforms; |
227 obj_array.Append(m_arrayAcroforms); | 220 if (!IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array)) |
228 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 221 return FALSE; |
229 if (bRet) | 222 |
230 m_objs_array.RemoveAll(); | 223 m_objs_array.clear(); |
231 return bRet; | 224 return TRUE; |
232 } | 225 } |
233 | 226 |
234 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; | 227 std::vector<CPDF_Object*> new_objs_array; |
235 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 228 if (!IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array)) { |
236 if (bRet) { | 229 m_objs_array = new_objs_array; |
237 int32_t iSize = m_arrayAcroforms.GetSize(); | 230 return FALSE; |
238 for (int32_t i = 0; i < iSize; ++i) { | |
239 m_arrayAcroforms.GetAt(i)->Release(); | |
240 } | |
241 m_arrayAcroforms.RemoveAll(); | |
242 } else { | |
243 m_objs_array.RemoveAll(); | |
244 m_objs_array.Append(new_objs_array); | |
245 } | 231 } |
246 return bRet; | 232 |
| 233 for (CPDF_Object* pObject : m_arrayAcroforms) |
| 234 pObject->Release(); |
| 235 |
| 236 m_arrayAcroforms.clear(); |
| 237 return TRUE; |
247 } | 238 } |
248 | 239 |
249 FX_BOOL CPDF_DataAvail::CheckAcroForm(DownloadHints* pHints) { | 240 FX_BOOL CPDF_DataAvail::CheckAcroForm(DownloadHints* pHints) { |
250 FX_BOOL bExist = FALSE; | 241 FX_BOOL bExist = FALSE; |
251 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); | 242 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); |
252 if (!bExist) { | 243 if (!bExist) { |
253 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 244 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
254 return TRUE; | 245 return TRUE; |
255 } | 246 } |
256 | 247 |
257 if (!m_pAcroForm) { | 248 if (!m_pAcroForm) { |
258 if (m_docStatus == PDF_DATAAVAIL_ERROR) { | 249 if (m_docStatus == PDF_DATAAVAIL_ERROR) { |
259 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 250 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
260 return TRUE; | 251 return TRUE; |
261 } | 252 } |
262 return FALSE; | 253 return FALSE; |
263 } | 254 } |
264 | 255 |
265 m_arrayAcroforms.Add(m_pAcroForm); | 256 m_arrayAcroforms.push_back(m_pAcroForm); |
266 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 257 m_docStatus = PDF_DATAAVAIL_PAGETREE; |
267 return TRUE; | 258 return TRUE; |
268 } | 259 } |
269 | 260 |
270 FX_BOOL CPDF_DataAvail::CheckDocStatus(DownloadHints* pHints) { | 261 FX_BOOL CPDF_DataAvail::CheckDocStatus(DownloadHints* pHints) { |
271 switch (m_docStatus) { | 262 switch (m_docStatus) { |
272 case PDF_DATAAVAIL_HEADER: | 263 case PDF_DATAAVAIL_HEADER: |
273 return CheckHeader(pHints); | 264 return CheckHeader(pHints); |
274 case PDF_DATAAVAIL_FIRSTPAGE: | 265 case PDF_DATAAVAIL_FIRSTPAGE: |
275 case PDF_DATAAVAIL_FIRSTPAGE_PREPARE: | 266 case PDF_DATAAVAIL_FIRSTPAGE_PREPARE: |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 } | 499 } |
509 } | 500 } |
510 | 501 |
511 if (!pObj->IsDictionary()) { | 502 if (!pObj->IsDictionary()) { |
512 pObj->Release(); | 503 pObj->Release(); |
513 continue; | 504 continue; |
514 } | 505 } |
515 | 506 |
516 CFX_ByteString type = pObj->GetDict()->GetStringFor("Type"); | 507 CFX_ByteString type = pObj->GetDict()->GetStringFor("Type"); |
517 if (type == "Pages") { | 508 if (type == "Pages") { |
518 m_PagesArray.Add(pObj); | 509 m_PagesArray.push_back(pObj); |
519 continue; | 510 continue; |
520 } | 511 } |
521 pObj->Release(); | 512 pObj->Release(); |
522 } | 513 } |
523 | 514 |
524 m_PageObjList.RemoveAll(); | 515 m_PageObjList.RemoveAll(); |
525 if (UnavailObjList.GetSize()) { | 516 if (UnavailObjList.GetSize()) { |
526 m_PageObjList.Append(UnavailObjList); | 517 m_PageObjList.Append(UnavailObjList); |
527 return FALSE; | 518 return FALSE; |
528 } | 519 } |
529 | 520 |
530 uint32_t iPages = m_PagesArray.GetSize(); | 521 uint32_t iPages = m_PagesArray.size(); |
531 for (uint32_t i = 0; i < iPages; i++) { | 522 for (uint32_t i = 0; i < iPages; i++) { |
532 CPDF_Object* pPages = m_PagesArray.GetAt(i); | 523 CPDF_Object* pPages = m_PagesArray[i]; |
533 if (!pPages) | 524 if (!pPages) |
534 continue; | 525 continue; |
535 | 526 |
536 if (!GetPageKids(m_pCurrentParser, pPages)) { | 527 if (!GetPageKids(m_pCurrentParser, pPages)) { |
537 pPages->Release(); | 528 pPages->Release(); |
538 while (++i < iPages) { | 529 while (++i < iPages) |
539 pPages = m_PagesArray.GetAt(i); | 530 m_PagesArray[i]->Release(); |
540 pPages->Release(); | |
541 } | |
542 m_PagesArray.RemoveAll(); | |
543 | 531 |
| 532 m_PagesArray.clear(); |
544 m_docStatus = PDF_DATAAVAIL_ERROR; | 533 m_docStatus = PDF_DATAAVAIL_ERROR; |
545 return FALSE; | 534 return FALSE; |
546 } | 535 } |
547 pPages->Release(); | 536 pPages->Release(); |
548 } | 537 } |
549 | 538 |
550 m_PagesArray.RemoveAll(); | 539 m_PagesArray.clear(); |
551 if (!m_PageObjList.GetSize()) | 540 if (!m_PageObjList.GetSize()) |
552 m_docStatus = PDF_DATAAVAIL_DONE; | 541 m_docStatus = PDF_DATAAVAIL_DONE; |
553 return TRUE; | 542 return TRUE; |
554 } | 543 } |
555 | 544 |
556 FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) { | 545 FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) { |
557 if (!pParser) { | 546 if (!pParser) { |
558 m_docStatus = PDF_DATAAVAIL_ERROR; | 547 m_docStatus = PDF_DATAAVAIL_ERROR; |
559 return FALSE; | 548 return FALSE; |
560 } | 549 } |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1528 | 1517 |
1529 m_bMainXRefLoadedOK = TRUE; | 1518 m_bMainXRefLoadedOK = TRUE; |
1530 m_bLinearedDataOK = TRUE; | 1519 m_bLinearedDataOK = TRUE; |
1531 } | 1520 } |
1532 | 1521 |
1533 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable; | 1522 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable; |
1534 } | 1523 } |
1535 | 1524 |
1536 FX_BOOL CPDF_DataAvail::CheckPageAnnots(uint32_t dwPage, | 1525 FX_BOOL CPDF_DataAvail::CheckPageAnnots(uint32_t dwPage, |
1537 DownloadHints* pHints) { | 1526 DownloadHints* pHints) { |
1538 if (!m_objs_array.GetSize()) { | 1527 if (m_objs_array.empty()) { |
1539 m_objs_array.RemoveAll(); | |
1540 m_ObjectSet.clear(); | 1528 m_ObjectSet.clear(); |
1541 | 1529 |
1542 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); | 1530 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); |
1543 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); | 1531 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); |
1544 if (!pPageDict) | 1532 if (!pPageDict) |
1545 return TRUE; | 1533 return TRUE; |
1546 | 1534 |
1547 CPDF_Object* pAnnots = pPageDict->GetObjectFor("Annots"); | 1535 CPDF_Object* pAnnots = pPageDict->GetObjectFor("Annots"); |
1548 if (!pAnnots) | 1536 if (!pAnnots) |
1549 return TRUE; | 1537 return TRUE; |
1550 | 1538 |
1551 CFX_ArrayTemplate<CPDF_Object*> obj_array; | 1539 std::vector<CPDF_Object*> obj_array; |
1552 obj_array.Add(pAnnots); | 1540 obj_array.push_back(pAnnots); |
| 1541 if (!IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array)) |
| 1542 return FALSE; |
1553 | 1543 |
1554 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 1544 m_objs_array.clear(); |
1555 if (bRet) | 1545 return TRUE; |
1556 m_objs_array.RemoveAll(); | |
1557 | |
1558 return bRet; | |
1559 } | 1546 } |
1560 | 1547 |
1561 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; | 1548 std::vector<CPDF_Object*> new_objs_array; |
1562 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 1549 if (!IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array)) { |
1563 m_objs_array.RemoveAll(); | 1550 m_objs_array = new_objs_array; |
1564 if (!bRet) | 1551 return FALSE; |
1565 m_objs_array.Append(new_objs_array); | 1552 } |
1566 | 1553 m_objs_array.clear(); |
1567 return bRet; | 1554 return TRUE; |
1568 } | 1555 } |
1569 | 1556 |
1570 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedFirstPage( | 1557 CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedFirstPage( |
1571 uint32_t dwPage, | 1558 uint32_t dwPage, |
1572 DownloadHints* pHints) { | 1559 DownloadHints* pHints) { |
1573 if (!m_bAnnotsLoad) { | 1560 if (!m_bAnnotsLoad) { |
1574 if (!CheckPageAnnots(dwPage, pHints)) | 1561 if (!CheckPageAnnots(dwPage, pHints)) |
1575 return DataNotAvailable; | 1562 return DataNotAvailable; |
1576 m_bAnnotsLoad = TRUE; | 1563 m_bAnnotsLoad = TRUE; |
1577 } | 1564 } |
(...skipping 30 matching lines...) Expand all Loading... |
1608 uint32_t dwPage, | 1595 uint32_t dwPage, |
1609 DownloadHints* pHints) { | 1596 DownloadHints* pHints) { |
1610 if (!m_pDocument) | 1597 if (!m_pDocument) |
1611 return DataError; | 1598 return DataError; |
1612 | 1599 |
1613 if (IsFirstCheck(dwPage)) { | 1600 if (IsFirstCheck(dwPage)) { |
1614 m_bCurPageDictLoadOK = FALSE; | 1601 m_bCurPageDictLoadOK = FALSE; |
1615 m_bPageLoadedOK = FALSE; | 1602 m_bPageLoadedOK = FALSE; |
1616 m_bAnnotsLoad = FALSE; | 1603 m_bAnnotsLoad = FALSE; |
1617 m_bNeedDownLoadResource = FALSE; | 1604 m_bNeedDownLoadResource = FALSE; |
1618 m_objs_array.RemoveAll(); | 1605 m_objs_array.clear(); |
1619 m_ObjectSet.clear(); | 1606 m_ObjectSet.clear(); |
1620 } | 1607 } |
1621 | 1608 |
1622 if (pdfium::ContainsKey(m_pagesLoadState, dwPage)) | 1609 if (pdfium::ContainsKey(m_pagesLoadState, dwPage)) |
1623 return DataAvailable; | 1610 return DataAvailable; |
1624 | 1611 |
1625 if (m_bLinearized) { | 1612 if (m_bLinearized) { |
1626 if (dwPage == m_dwFirstPageNo) { | 1613 if (dwPage == m_dwFirstPageNo) { |
1627 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints); | 1614 DocAvailStatus nRet = CheckLinearizedFirstPage(dwPage, pHints); |
1628 if (nRet == DataAvailable) | 1615 if (nRet == DataAvailable) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1664 } | 1651 } |
1665 } | 1652 } |
1666 | 1653 |
1667 if (m_bHaveAcroForm && !m_bAcroFormLoad) { | 1654 if (m_bHaveAcroForm && !m_bAcroFormLoad) { |
1668 if (!CheckAcroFormSubObject(pHints)) | 1655 if (!CheckAcroFormSubObject(pHints)) |
1669 return DataNotAvailable; | 1656 return DataNotAvailable; |
1670 m_bAcroFormLoad = TRUE; | 1657 m_bAcroFormLoad = TRUE; |
1671 } | 1658 } |
1672 | 1659 |
1673 if (!m_bPageLoadedOK) { | 1660 if (!m_bPageLoadedOK) { |
1674 if (!m_objs_array.GetSize()) { | 1661 if (m_objs_array.empty()) { |
1675 m_objs_array.RemoveAll(); | |
1676 m_ObjectSet.clear(); | 1662 m_ObjectSet.clear(); |
1677 | 1663 |
1678 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); | 1664 FX_SAFE_INT32 safePage = pdfium::base::checked_cast<int32_t>(dwPage); |
1679 m_pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); | 1665 m_pPageDict = m_pDocument->GetPage(safePage.ValueOrDie()); |
1680 if (!m_pPageDict) { | 1666 if (!m_pPageDict) { |
1681 ResetFirstCheck(dwPage); | 1667 ResetFirstCheck(dwPage); |
1682 return DataAvailable; | 1668 return DataAvailable; |
1683 } | 1669 } |
1684 | 1670 |
1685 CFX_ArrayTemplate<CPDF_Object*> obj_array; | 1671 std::vector<CPDF_Object*> obj_array; |
1686 obj_array.Add(m_pPageDict); | 1672 obj_array.push_back(m_pPageDict); |
1687 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); | 1673 if (!IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array)) |
1688 if (!bRet) | |
1689 return DataNotAvailable; | 1674 return DataNotAvailable; |
1690 | 1675 |
1691 m_objs_array.RemoveAll(); | 1676 m_objs_array.clear(); |
1692 } else { | 1677 } else { |
1693 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; | 1678 std::vector<CPDF_Object*> new_objs_array; |
1694 FX_BOOL bRet = | 1679 if (!IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array)) { |
1695 IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 1680 m_objs_array = new_objs_array; |
1696 | |
1697 m_objs_array.RemoveAll(); | |
1698 if (!bRet) { | |
1699 m_objs_array.Append(new_objs_array); | |
1700 return DataNotAvailable; | 1681 return DataNotAvailable; |
1701 } | 1682 } |
1702 } | 1683 } |
| 1684 m_objs_array.clear(); |
1703 m_bPageLoadedOK = TRUE; | 1685 m_bPageLoadedOK = TRUE; |
1704 } | 1686 } |
1705 | 1687 |
1706 if (!m_bAnnotsLoad) { | 1688 if (!m_bAnnotsLoad) { |
1707 if (!CheckPageAnnots(dwPage, pHints)) | 1689 if (!CheckPageAnnots(dwPage, pHints)) |
1708 return DataNotAvailable; | 1690 return DataNotAvailable; |
1709 m_bAnnotsLoad = TRUE; | 1691 m_bAnnotsLoad = TRUE; |
1710 } | 1692 } |
1711 | 1693 |
1712 if (m_pPageDict && !m_bNeedDownLoadResource) { | 1694 if (m_pPageDict && !m_bNeedDownLoadResource) { |
(...skipping 11 matching lines...) Expand all Loading... |
1724 m_bPageLoadedOK = FALSE; | 1706 m_bPageLoadedOK = FALSE; |
1725 m_bAnnotsLoad = FALSE; | 1707 m_bAnnotsLoad = FALSE; |
1726 m_bCurPageDictLoadOK = FALSE; | 1708 m_bCurPageDictLoadOK = FALSE; |
1727 | 1709 |
1728 ResetFirstCheck(dwPage); | 1710 ResetFirstCheck(dwPage); |
1729 m_pagesLoadState.insert(dwPage); | 1711 m_pagesLoadState.insert(dwPage); |
1730 return DataAvailable; | 1712 return DataAvailable; |
1731 } | 1713 } |
1732 | 1714 |
1733 FX_BOOL CPDF_DataAvail::CheckResources(DownloadHints* pHints) { | 1715 FX_BOOL CPDF_DataAvail::CheckResources(DownloadHints* pHints) { |
1734 if (!m_objs_array.GetSize()) { | 1716 if (m_objs_array.empty()) { |
1735 m_objs_array.RemoveAll(); | 1717 std::vector<CPDF_Object*> obj_array; |
1736 CFX_ArrayTemplate<CPDF_Object*> obj_array; | 1718 obj_array.push_back(m_pPageResource); |
1737 obj_array.Add(m_pPageResource); | 1719 if (!IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array)) |
| 1720 return FALSE; |
1738 | 1721 |
1739 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); | 1722 m_objs_array.clear(); |
1740 if (bRet) | 1723 return TRUE; |
1741 m_objs_array.RemoveAll(); | |
1742 return bRet; | |
1743 } | 1724 } |
1744 | 1725 std::vector<CPDF_Object*> new_objs_array; |
1745 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; | 1726 if (!IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array)) { |
1746 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 1727 m_objs_array = new_objs_array; |
1747 m_objs_array.RemoveAll(); | 1728 return FALSE; |
1748 if (!bRet) | 1729 } |
1749 m_objs_array.Append(new_objs_array); | 1730 m_objs_array.clear(); |
1750 return bRet; | 1731 return TRUE; |
1751 } | 1732 } |
1752 | 1733 |
1753 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, | 1734 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, |
1754 uint32_t* pSize) { | 1735 uint32_t* pSize) { |
1755 if (pPos) | 1736 if (pPos) |
1756 *pPos = m_dwLastXRefOffset; | 1737 *pPos = m_dwLastXRefOffset; |
1757 if (pSize) | 1738 if (pSize) |
1758 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); | 1739 *pSize = (uint32_t)(m_dwFileLen - m_dwLastXRefOffset); |
1759 } | 1740 } |
1760 | 1741 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1813 CPDF_Object* pAcroForm = pRoot->GetObjectFor("AcroForm"); | 1794 CPDF_Object* pAcroForm = pRoot->GetObjectFor("AcroForm"); |
1814 if (!pAcroForm) | 1795 if (!pAcroForm) |
1815 return FormNotExist; | 1796 return FormNotExist; |
1816 | 1797 |
1817 DocAvailStatus nDocStatus = CheckLinearizedData(pHints); | 1798 DocAvailStatus nDocStatus = CheckLinearizedData(pHints); |
1818 if (nDocStatus == DataError) | 1799 if (nDocStatus == DataError) |
1819 return FormError; | 1800 return FormError; |
1820 if (nDocStatus == DataNotAvailable) | 1801 if (nDocStatus == DataNotAvailable) |
1821 return FormNotAvailable; | 1802 return FormNotAvailable; |
1822 | 1803 |
1823 if (!m_objs_array.GetSize()) | 1804 if (m_objs_array.empty()) |
1824 m_objs_array.Add(pAcroForm->GetDict()); | 1805 m_objs_array.push_back(pAcroForm->GetDict()); |
1825 m_bLinearizedFormParamLoad = TRUE; | 1806 m_bLinearizedFormParamLoad = TRUE; |
1826 } | 1807 } |
1827 | 1808 |
1828 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; | 1809 std::vector<CPDF_Object*> new_objs_array; |
1829 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 1810 if (!IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array)) { |
1830 m_objs_array.RemoveAll(); | 1811 m_objs_array = new_objs_array; |
1831 if (!bRet) { | |
1832 m_objs_array.Append(new_objs_array); | |
1833 return FormNotAvailable; | 1812 return FormNotAvailable; |
1834 } | 1813 } |
| 1814 |
| 1815 m_objs_array.clear(); |
1835 return FormAvailable; | 1816 return FormAvailable; |
1836 } | 1817 } |
1837 | 1818 |
1838 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} | 1819 CPDF_DataAvail::PageNode::PageNode() : m_type(PDF_PAGENODE_UNKNOWN) {} |
1839 | 1820 |
1840 CPDF_DataAvail::PageNode::~PageNode() { | 1821 CPDF_DataAvail::PageNode::~PageNode() { |
1841 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) | 1822 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) |
1842 delete m_childNode[i]; | 1823 delete m_childNode[i]; |
1843 m_childNode.RemoveAll(); | 1824 m_childNode.RemoveAll(); |
1844 } | 1825 } |
OLD | NEW |