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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 1419373005: Make checkdeps --resolve-dotdot succeed. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 1 month 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 | « core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp ('k') | fpdfsdk/DEPS » ('j') | 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 <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 2660 matching lines...) Expand 10 before | Expand all | Expand 10 after
2671 } 2671 }
2672 } 2672 }
2673 2673
2674 class CPDF_DataAvail final : public IPDF_DataAvail { 2674 class CPDF_DataAvail final : public IPDF_DataAvail {
2675 public: 2675 public:
2676 CPDF_DataAvail(IFX_FileAvail* pFileAvail, 2676 CPDF_DataAvail(IFX_FileAvail* pFileAvail,
2677 IFX_FileRead* pFileRead, 2677 IFX_FileRead* pFileRead,
2678 FX_BOOL bSupportHintTable); 2678 FX_BOOL bSupportHintTable);
2679 ~CPDF_DataAvail() override; 2679 ~CPDF_DataAvail() override;
2680 2680
2681 int IsDocAvail(IFX_DownloadHints* pHints) override; 2681 // IPDF_DataAvail:
2682 DocAvailStatus IsDocAvail(IFX_DownloadHints* pHints) override;
2683 void SetDocument(CPDF_Document* pDoc) override;
2684 int IsPageAvail(int iPage, IFX_DownloadHints* pHints) override;
2685 DocFormStatus IsFormAvail(IFX_DownloadHints* pHints) override;
2686 DocLinearizationStatus IsLinearizedPDF() override;
2687 FX_BOOL IsLinearized() override { return m_bLinearized; }
2688 void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, FX_DWORD* pSize) override;
2682 2689
2683 void SetDocument(CPDF_Document* pDoc) override;
2684
2685 int IsPageAvail(int iPage, IFX_DownloadHints* pHints) override;
2686
2687 int IsFormAvail(IFX_DownloadHints* pHints) override;
2688
2689 int IsLinearizedPDF() override;
2690
2691 FX_BOOL IsLinearized() override { return m_bLinearized; }
2692
2693 void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, FX_DWORD* pSize) override;
2694 int GetPageCount() const; 2690 int GetPageCount() const;
2695 CPDF_Dictionary* GetPage(int index); 2691 CPDF_Dictionary* GetPage(int index);
2696 2692
2697 friend class CPDF_HintTables; 2693 friend class CPDF_HintTables;
2698 2694
2699 protected: 2695 protected:
2700 static const int kMaxDataAvailRecursionDepth = 64; 2696 static const int kMaxDataAvailRecursionDepth = 64;
2701 static int s_CurrentDataAvailRecursionDepth; 2697 static int s_CurrentDataAvailRecursionDepth;
2702 static const int kMaxPageRecursionDepth = 1024; 2698 static const int kMaxPageRecursionDepth = 1024;
2703 2699
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
3073 } else { 3069 } else {
3074 ret_array.Add(pObj); 3070 ret_array.Add(pObj);
3075 } 3071 }
3076 } 3072 }
3077 return FALSE; 3073 return FALSE;
3078 } 3074 }
3079 obj_array.RemoveAll(); 3075 obj_array.RemoveAll();
3080 obj_array.Append(new_obj_array); 3076 obj_array.Append(new_obj_array);
3081 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); 3077 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array);
3082 } 3078 }
3083 int CPDF_DataAvail::IsDocAvail(IFX_DownloadHints* pHints) { 3079
3080 IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail(
3081 IFX_DownloadHints* pHints) {
3084 if (!m_dwFileLen && m_pFileRead) { 3082 if (!m_dwFileLen && m_pFileRead) {
3085 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize(); 3083 m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize();
3086 if (!m_dwFileLen) { 3084 if (!m_dwFileLen) {
3087 return PDF_DATA_ERROR; 3085 return DataError;
3088 } 3086 }
3089 } 3087 }
3090 while (!m_bDocAvail) { 3088 while (!m_bDocAvail) {
3091 if (!CheckDocStatus(pHints)) { 3089 if (!CheckDocStatus(pHints)) {
3092 return PDF_DATA_NOTAVAIL; 3090 return DataNotAvailable;
3093 } 3091 }
3094 } 3092 }
3095 return PDF_DATA_AVAIL; 3093 return DataAvailable;
3096 } 3094 }
3095
3097 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) { 3096 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) {
3098 if (!m_objs_array.GetSize()) { 3097 if (!m_objs_array.GetSize()) {
3099 m_objs_array.RemoveAll(); 3098 m_objs_array.RemoveAll();
3100 m_objnum_array.RemoveAll(); 3099 m_objnum_array.RemoveAll();
3101 CFX_PtrArray obj_array; 3100 CFX_PtrArray obj_array;
3102 obj_array.Append(m_arrayAcroforms); 3101 obj_array.Append(m_arrayAcroforms);
3103 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); 3102 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array);
3104 if (bRet) { 3103 if (bRet) {
3105 m_objs_array.RemoveAll(); 3104 m_objs_array.RemoveAll();
3106 } 3105 }
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
3637 FX_DWORD gennum = FXSYS_atoi(word); 3636 FX_DWORD gennum = FXSYS_atoi(word);
3638 if (m_syntaxParser.GetKeyword() != FX_BSTRC("obj")) { 3637 if (m_syntaxParser.GetKeyword() != FX_BSTRC("obj")) {
3639 m_syntaxParser.RestorePos(SavedPos); 3638 m_syntaxParser.RestorePos(SavedPos);
3640 return NULL; 3639 return NULL;
3641 } 3640 }
3642 CPDF_Object* pObj = 3641 CPDF_Object* pObj =
3643 m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, 0); 3642 m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, 0);
3644 m_syntaxParser.RestorePos(SavedPos); 3643 m_syntaxParser.RestorePos(SavedPos);
3645 return pObj; 3644 return pObj;
3646 } 3645 }
3647 int CPDF_DataAvail::IsLinearizedPDF() { 3646 IPDF_DataAvail::DocLinearizationStatus CPDF_DataAvail::IsLinearizedPDF() {
3648 FX_DWORD req_size = 1024; 3647 FX_DWORD req_size = 1024;
3649 if (!m_pFileAvail->IsDataAvail(0, req_size)) { 3648 if (!m_pFileAvail->IsDataAvail(0, req_size)) {
3650 return PDF_LINEARIZATION_UNKNOWN; 3649 return LinearizationUnknown;
3651 } 3650 }
3652 if (!m_pFileRead) { 3651 if (!m_pFileRead) {
3653 return PDF_NOT_LINEARIZED; 3652 return NotLinearized;
3654 } 3653 }
3655 FX_FILESIZE dwSize = m_pFileRead->GetSize(); 3654 FX_FILESIZE dwSize = m_pFileRead->GetSize();
3656 if (dwSize < (FX_FILESIZE)req_size) { 3655 if (dwSize < (FX_FILESIZE)req_size) {
3657 return PDF_LINEARIZATION_UNKNOWN; 3656 return LinearizationUnknown;
3658 } 3657 }
3659 uint8_t buffer[1024]; 3658 uint8_t buffer[1024];
3660 m_pFileRead->ReadBlock(buffer, 0, req_size); 3659 m_pFileRead->ReadBlock(buffer, 0, req_size);
3661 if (IsLinearizedFile(buffer, req_size)) { 3660 if (IsLinearizedFile(buffer, req_size)) {
3662 return PDF_LINEARIZED; 3661 return Linearized;
3663 } 3662 }
3664 return PDF_NOT_LINEARIZED; 3663 return NotLinearized;
3665 } 3664 }
3666 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) { 3665 FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) {
3667 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE)); 3666 ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE));
3668 int32_t offset = GetHeaderOffset(file.get()); 3667 int32_t offset = GetHeaderOffset(file.get());
3669 if (offset == -1) { 3668 if (offset == -1) {
3670 m_docStatus = PDF_DATAAVAIL_ERROR; 3669 m_docStatus = PDF_DATAAVAIL_ERROR;
3671 return FALSE; 3670 return FALSE;
3672 } 3671 }
3673 m_dwHeaderOffset = offset; 3672 m_dwHeaderOffset = offset;
3674 m_syntaxParser.InitParser(file.get(), offset); 3673 m_syntaxParser.InitParser(file.get(), offset);
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
4271 } 4270 }
4272 } 4271 }
4273 if (m_bPagesLoad) { 4272 if (m_bPagesLoad) {
4274 return TRUE; 4273 return TRUE;
4275 } 4274 }
4276 m_pDocument->LoadPages(); 4275 m_pDocument->LoadPages();
4277 return FALSE; 4276 return FALSE;
4278 } 4277 }
4279 int CPDF_DataAvail::CheckLinearizedData(IFX_DownloadHints* pHints) { 4278 int CPDF_DataAvail::CheckLinearizedData(IFX_DownloadHints* pHints) {
4280 if (m_bLinearedDataOK) { 4279 if (m_bLinearedDataOK) {
4281 return PDF_DATA_AVAIL; 4280 return DataAvailable;
4282 } 4281 }
4283 4282
4284 if (!m_bMainXRefLoadTried) { 4283 if (!m_bMainXRefLoadTried) {
4285 FX_SAFE_DWORD data_size = m_dwFileLen; 4284 FX_SAFE_DWORD data_size = m_dwFileLen;
4286 data_size -= m_dwLastXRefOffset; 4285 data_size -= m_dwLastXRefOffset;
4287 if (!data_size.IsValid()) { 4286 if (!data_size.IsValid()) {
4288 return PDF_DATA_ERROR; 4287 return DataError;
4289 } 4288 }
4290 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset, 4289 if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset,
4291 data_size.ValueOrDie())) { 4290 data_size.ValueOrDie())) {
4292 pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie()); 4291 pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie());
4293 return PDF_DATA_NOTAVAIL; 4292 return DataNotAvailable;
4294 } 4293 }
4295 FX_DWORD dwRet = (m_pDocument->GetParser())->LoadLinearizedMainXRefTable(); 4294 FX_DWORD dwRet = (m_pDocument->GetParser())->LoadLinearizedMainXRefTable();
4296 m_bMainXRefLoadTried = TRUE; 4295 m_bMainXRefLoadTried = TRUE;
4297 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 4296 if (dwRet != PDFPARSE_ERROR_SUCCESS) {
4298 return PDF_DATA_ERROR; 4297 return DataError;
4299 } 4298 }
4300 if (!PreparePageItem()) { 4299 if (!PreparePageItem()) {
4301 return PDF_DATA_NOTAVAIL; 4300 return DataNotAvailable;
4302 } 4301 }
4303 m_bMainXRefLoadedOK = TRUE; 4302 m_bMainXRefLoadedOK = TRUE;
4304 m_bLinearedDataOK = TRUE; 4303 m_bLinearedDataOK = TRUE;
4305 } 4304 }
4306 4305
4307 return m_bLinearedDataOK ? PDF_DATA_AVAIL : PDF_DATA_NOTAVAIL; 4306 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable;
4308 } 4307 }
4309 FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, 4308 FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage,
4310 IFX_DownloadHints* pHints) { 4309 IFX_DownloadHints* pHints) {
4311 if (!m_objs_array.GetSize()) { 4310 if (!m_objs_array.GetSize()) {
4312 m_objs_array.RemoveAll(); 4311 m_objs_array.RemoveAll();
4313 m_objnum_array.RemoveAll(); 4312 m_objnum_array.RemoveAll();
4314 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(iPage); 4313 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(iPage);
4315 if (!pPageDict) { 4314 if (!pPageDict) {
4316 return TRUE; 4315 return TRUE;
4317 } 4316 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4365 } 4364 }
4366 CPDF_Object* pRet = pParentDict->GetElement("Resources"); 4365 CPDF_Object* pRet = pParentDict->GetElement("Resources");
4367 if (pRet) { 4366 if (pRet) {
4368 m_pPageResource = pRet; 4367 m_pPageResource = pRet;
4369 return TRUE; 4368 return TRUE;
4370 } 4369 }
4371 return HaveResourceAncestor(pParentDict); 4370 return HaveResourceAncestor(pParentDict);
4372 } 4371 }
4373 int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { 4372 int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
4374 if (!m_pDocument) { 4373 if (!m_pDocument) {
4375 return PDF_DATA_ERROR; 4374 return DataError;
4376 } 4375 }
4377 if (IsFirstCheck(iPage)) { 4376 if (IsFirstCheck(iPage)) {
4378 m_bCurPageDictLoadOK = FALSE; 4377 m_bCurPageDictLoadOK = FALSE;
4379 m_bPageLoadedOK = FALSE; 4378 m_bPageLoadedOK = FALSE;
4380 m_bAnnotsLoad = FALSE; 4379 m_bAnnotsLoad = FALSE;
4381 m_bNeedDownLoadResource = FALSE; 4380 m_bNeedDownLoadResource = FALSE;
4382 m_objs_array.RemoveAll(); 4381 m_objs_array.RemoveAll();
4383 m_objnum_array.RemoveAll(); 4382 m_objnum_array.RemoveAll();
4384 } 4383 }
4385 if (m_pagesLoadState.find(iPage) != m_pagesLoadState.end()) { 4384 if (m_pagesLoadState.find(iPage) != m_pagesLoadState.end()) {
4386 return PDF_DATA_AVAIL; 4385 return DataAvailable;
4387 } 4386 }
4388 if (m_bLinearized) { 4387 if (m_bLinearized) {
4389 if ((FX_DWORD)iPage == m_dwFirstPageNo) { 4388 if ((FX_DWORD)iPage == m_dwFirstPageNo) {
4390 m_pagesLoadState.insert(iPage); 4389 m_pagesLoadState.insert(iPage);
4391 return PDF_DATA_AVAIL; 4390 return DataAvailable;
4392 } 4391 }
4393 int32_t nResult = CheckLinearizedData(pHints); 4392 int32_t nResult = CheckLinearizedData(pHints);
4394 if (nResult != PDF_DATA_AVAIL) { 4393 if (nResult != DataAvailable) {
4395 return nResult; 4394 return nResult;
4396 } 4395 }
4397 if (m_pHintTables) { 4396 if (m_pHintTables) {
4398 nResult = m_pHintTables->CheckPage(iPage, pHints); 4397 nResult = m_pHintTables->CheckPage(iPage, pHints);
4399 if (nResult != PDF_DATA_AVAIL) 4398 if (nResult != DataAvailable)
4400 return nResult; 4399 return nResult;
4401 m_pagesLoadState.insert(iPage); 4400 m_pagesLoadState.insert(iPage);
4402 return PDF_DATA_AVAIL; 4401 return DataAvailable;
4403 } 4402 }
4404 if (m_bMainXRefLoadedOK) { 4403 if (m_bMainXRefLoadedOK) {
4405 if (m_bTotalLoadPageTree) { 4404 if (m_bTotalLoadPageTree) {
4406 if (!LoadPages(pHints)) { 4405 if (!LoadPages(pHints)) {
4407 return PDF_DATA_NOTAVAIL; 4406 return DataNotAvailable;
4408 } 4407 }
4409 } else { 4408 } else {
4410 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) { 4409 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) {
4411 return PDF_DATA_NOTAVAIL; 4410 return DataNotAvailable;
4412 } 4411 }
4413 } 4412 }
4414 } else { 4413 } else {
4415 if (!LoadAllFile(pHints)) { 4414 if (!LoadAllFile(pHints)) {
4416 return PDF_DATA_NOTAVAIL; 4415 return DataNotAvailable;
4417 } 4416 }
4418 ((CPDF_Parser*)m_pDocument->GetParser())->RebuildCrossRef(); 4417 ((CPDF_Parser*)m_pDocument->GetParser())->RebuildCrossRef();
4419 ResetFirstCheck(iPage); 4418 ResetFirstCheck(iPage);
4420 return PDF_DATA_AVAIL; 4419 return DataAvailable;
4421 } 4420 }
4422 } else { 4421 } else {
4423 if (!m_bTotalLoadPageTree) { 4422 if (!m_bTotalLoadPageTree) {
4424 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) { 4423 if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) {
4425 return PDF_DATA_NOTAVAIL; 4424 return DataNotAvailable;
4426 } 4425 }
4427 } 4426 }
4428 } 4427 }
4429 if (m_bHaveAcroForm && !m_bAcroFormLoad) { 4428 if (m_bHaveAcroForm && !m_bAcroFormLoad) {
4430 if (!CheckAcroFormSubObject(pHints)) { 4429 if (!CheckAcroFormSubObject(pHints)) {
4431 return PDF_DATA_NOTAVAIL; 4430 return DataNotAvailable;
4432 } 4431 }
4433 m_bAcroFormLoad = TRUE; 4432 m_bAcroFormLoad = TRUE;
4434 } 4433 }
4435 if (!m_bPageLoadedOK) { 4434 if (!m_bPageLoadedOK) {
4436 if (!m_objs_array.GetSize()) { 4435 if (!m_objs_array.GetSize()) {
4437 m_objs_array.RemoveAll(); 4436 m_objs_array.RemoveAll();
4438 m_objnum_array.RemoveAll(); 4437 m_objnum_array.RemoveAll();
4439 m_pPageDict = m_pDocument->GetPage(iPage); 4438 m_pPageDict = m_pDocument->GetPage(iPage);
4440 if (!m_pPageDict) { 4439 if (!m_pPageDict) {
4441 ResetFirstCheck(iPage); 4440 ResetFirstCheck(iPage);
4442 return PDF_DATA_AVAIL; 4441 return DataAvailable;
4443 } 4442 }
4444 CFX_PtrArray obj_array; 4443 CFX_PtrArray obj_array;
4445 obj_array.Add(m_pPageDict); 4444 obj_array.Add(m_pPageDict);
4446 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); 4445 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array);
4447 if (bRet) { 4446 if (bRet) {
4448 m_objs_array.RemoveAll(); 4447 m_objs_array.RemoveAll();
4449 m_bPageLoadedOK = TRUE; 4448 m_bPageLoadedOK = TRUE;
4450 } else { 4449 } else {
4451 return bRet; 4450 return bRet;
4452 } 4451 }
4453 } else { 4452 } else {
4454 CFX_PtrArray new_objs_array; 4453 CFX_PtrArray new_objs_array;
4455 FX_BOOL bRet = 4454 FX_BOOL bRet =
4456 IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); 4455 IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
4457 m_objs_array.RemoveAll(); 4456 m_objs_array.RemoveAll();
4458 if (bRet) { 4457 if (bRet) {
4459 m_bPageLoadedOK = TRUE; 4458 m_bPageLoadedOK = TRUE;
4460 } else { 4459 } else {
4461 m_objs_array.Append(new_objs_array); 4460 m_objs_array.Append(new_objs_array);
4462 return PDF_DATA_NOTAVAIL; 4461 return DataNotAvailable;
4463 } 4462 }
4464 } 4463 }
4465 } 4464 }
4466 if (m_bPageLoadedOK) { 4465 if (m_bPageLoadedOK) {
4467 if (!m_bAnnotsLoad) { 4466 if (!m_bAnnotsLoad) {
4468 if (!CheckPageAnnots(iPage, pHints)) { 4467 if (!CheckPageAnnots(iPage, pHints)) {
4469 return PDF_DATA_NOTAVAIL; 4468 return DataNotAvailable;
4470 } 4469 }
4471 m_bAnnotsLoad = TRUE; 4470 m_bAnnotsLoad = TRUE;
4472 } 4471 }
4473 } 4472 }
4474 if (m_pPageDict && !m_bNeedDownLoadResource) { 4473 if (m_pPageDict && !m_bNeedDownLoadResource) {
4475 m_pPageResource = m_pPageDict->GetElement("Resources"); 4474 m_pPageResource = m_pPageDict->GetElement("Resources");
4476 if (!m_pPageResource) { 4475 if (!m_pPageResource) {
4477 m_bNeedDownLoadResource = HaveResourceAncestor(m_pPageDict); 4476 m_bNeedDownLoadResource = HaveResourceAncestor(m_pPageDict);
4478 } else { 4477 } else {
4479 m_bNeedDownLoadResource = TRUE; 4478 m_bNeedDownLoadResource = TRUE;
4480 } 4479 }
4481 } 4480 }
4482 if (m_bNeedDownLoadResource) { 4481 if (m_bNeedDownLoadResource) {
4483 FX_BOOL bRet = CheckResources(pHints); 4482 FX_BOOL bRet = CheckResources(pHints);
4484 if (!bRet) { 4483 if (!bRet) {
4485 return PDF_DATA_NOTAVAIL; 4484 return DataNotAvailable;
4486 } 4485 }
4487 m_bNeedDownLoadResource = FALSE; 4486 m_bNeedDownLoadResource = FALSE;
4488 } 4487 }
4489 m_bPageLoadedOK = FALSE; 4488 m_bPageLoadedOK = FALSE;
4490 m_bAnnotsLoad = FALSE; 4489 m_bAnnotsLoad = FALSE;
4491 m_bCurPageDictLoadOK = FALSE; 4490 m_bCurPageDictLoadOK = FALSE;
4492 ResetFirstCheck(iPage); 4491 ResetFirstCheck(iPage);
4493 m_pagesLoadState.insert(iPage); 4492 m_pagesLoadState.insert(iPage);
4494 return PDF_DATA_AVAIL; 4493 return DataAvailable;
4495 } 4494 }
4496 FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) { 4495 FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) {
4497 if (!m_objs_array.GetSize()) { 4496 if (!m_objs_array.GetSize()) {
4498 m_objs_array.RemoveAll(); 4497 m_objs_array.RemoveAll();
4499 CFX_PtrArray obj_array; 4498 CFX_PtrArray obj_array;
4500 obj_array.Add(m_pPageResource); 4499 obj_array.Add(m_pPageResource);
4501 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); 4500 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array);
4502 if (bRet) { 4501 if (bRet) {
4503 m_objs_array.RemoveAll(); 4502 m_objs_array.RemoveAll();
4504 } 4503 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
4550 CPDF_Object* pPageDict = ParseIndirectObjectAt(0, dwObjNum, m_pDocument); 4549 CPDF_Object* pPageDict = ParseIndirectObjectAt(0, dwObjNum, m_pDocument);
4551 if (!pPageDict) { 4550 if (!pPageDict) {
4552 return nullptr; 4551 return nullptr;
4553 } 4552 }
4554 m_pDocument->InsertIndirectObject(dwObjNum, pPageDict); 4553 m_pDocument->InsertIndirectObject(dwObjNum, pPageDict);
4555 return pPageDict->GetDict(); 4554 return pPageDict->GetDict();
4556 } 4555 }
4557 } 4556 }
4558 return m_pDocument->GetPage(index); 4557 return m_pDocument->GetPage(index);
4559 } 4558 }
4560 int CPDF_DataAvail::IsFormAvail(IFX_DownloadHints* pHints) { 4559 IPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail(
4560 IFX_DownloadHints* pHints) {
4561 if (!m_pDocument) { 4561 if (!m_pDocument) {
4562 return PDF_FORM_AVAIL; 4562 return FormAvailable;
4563 } 4563 }
4564 if (!m_bLinearizedFormParamLoad) { 4564 if (!m_bLinearizedFormParamLoad) {
4565 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); 4565 CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
4566 if (!pRoot) { 4566 if (!pRoot) {
4567 return PDF_FORM_AVAIL; 4567 return FormAvailable;
4568 } 4568 }
4569 CPDF_Object* pAcroForm = pRoot->GetElement(FX_BSTRC("AcroForm")); 4569 CPDF_Object* pAcroForm = pRoot->GetElement(FX_BSTRC("AcroForm"));
4570 if (!pAcroForm) { 4570 if (!pAcroForm) {
4571 return PDF_FORM_NOTEXIST; 4571 return FormNotExist;
4572 } 4572 }
4573 if (!CheckLinearizedData(pHints)) { 4573 if (!CheckLinearizedData(pHints)) {
4574 return PDF_FORM_NOTAVAIL; 4574 return FormNotAvailable;
4575 } 4575 }
4576 if (!m_objs_array.GetSize()) { 4576 if (!m_objs_array.GetSize()) {
4577 m_objs_array.Add(pAcroForm->GetDict()); 4577 m_objs_array.Add(pAcroForm->GetDict());
4578 } 4578 }
4579 m_bLinearizedFormParamLoad = TRUE; 4579 m_bLinearizedFormParamLoad = TRUE;
4580 } 4580 }
4581 CFX_PtrArray new_objs_array; 4581 CFX_PtrArray new_objs_array;
4582 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); 4582 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
4583 m_objs_array.RemoveAll(); 4583 m_objs_array.RemoveAll();
4584 if (!bRet) { 4584 if (!bRet) {
4585 m_objs_array.Append(new_objs_array); 4585 m_objs_array.Append(new_objs_array);
4586 return PDF_FORM_NOTAVAIL; 4586 return FormNotAvailable;
4587 } 4587 }
4588 return PDF_FORM_AVAIL; 4588 return FormAvailable;
4589 } 4589 }
4590 void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum) { 4590 void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum) {
4591 int32_t iNext = 0; 4591 int32_t iNext = 0;
4592 if (BinarySearch(dwObjNum, iNext)) { 4592 if (BinarySearch(dwObjNum, iNext)) {
4593 return; 4593 return;
4594 } 4594 }
4595 m_number_array.InsertAt(iNext, dwObjNum); 4595 m_number_array.InsertAt(iNext, dwObjNum);
4596 } 4596 }
4597 FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) { 4597 FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) {
4598 int32_t iNext = 0; 4598 int32_t iNext = 0;
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
4862 dwObjNum = 1; 4862 dwObjNum = 1;
4863 for (int i = 0; i < index; ++i) { 4863 for (int i = 0; i < index; ++i) {
4864 if (i == nFirstPageNum) 4864 if (i == nFirstPageNum)
4865 continue; 4865 continue;
4866 dwObjNum += m_dwDeltaNObjsArray[i]; 4866 dwObjNum += m_dwDeltaNObjsArray[i];
4867 } 4867 }
4868 return TRUE; 4868 return TRUE;
4869 } 4869 }
4870 int32_t CPDF_HintTables::CheckPage(int index, IFX_DownloadHints* pHints) { 4870 int32_t CPDF_HintTables::CheckPage(int index, IFX_DownloadHints* pHints) {
4871 if (!m_pLinearizedDict || !pHints) 4871 if (!m_pLinearizedDict || !pHints)
4872 return PDF_DATA_ERROR; 4872 return IPDF_DataAvail::DataError;
4873 CPDF_Object* pFirstAvailPage = 4873 CPDF_Object* pFirstAvailPage =
4874 m_pLinearizedDict->GetElementValue(FX_BSTRC("P")); 4874 m_pLinearizedDict->GetElementValue(FX_BSTRC("P"));
4875 int nFirstAvailPage = pFirstAvailPage ? pFirstAvailPage->GetInteger() : 0; 4875 int nFirstAvailPage = pFirstAvailPage ? pFirstAvailPage->GetInteger() : 0;
4876 if (index == nFirstAvailPage) 4876 if (index == nFirstAvailPage)
4877 return PDF_DATA_AVAIL; 4877 return IPDF_DataAvail::DataAvailable;
4878 FX_DWORD dwLength = GetItemLength(index, m_szPageOffsetArray); 4878 FX_DWORD dwLength = GetItemLength(index, m_szPageOffsetArray);
4879 if (!dwLength || 4879 if (!dwLength ||
4880 !m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, 4880 !m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength,
4881 pHints)) { 4881 pHints)) {
4882 return PDF_DATA_NOTAVAIL; 4882 return IPDF_DataAvail::DataNotAvailable;
4883 } 4883 }
4884 // Download data of shared objects in the page. 4884 // Download data of shared objects in the page.
4885 FX_DWORD offset = 0; 4885 FX_DWORD offset = 0;
4886 for (int i = 0; i < index; ++i) { 4886 for (int i = 0; i < index; ++i) {
4887 offset += m_dwNSharedObjsArray[i]; 4887 offset += m_dwNSharedObjsArray[i];
4888 } 4888 }
4889 CPDF_Object* pFirstPageObj = 4889 CPDF_Object* pFirstPageObj =
4890 m_pLinearizedDict->GetElementValue(FX_BSTRC("O")); 4890 m_pLinearizedDict->GetElementValue(FX_BSTRC("O"));
4891 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1; 4891 int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1;
4892 if (nFirstPageObjNum < 0) 4892 if (nFirstPageObjNum < 0)
4893 return FALSE; 4893 return FALSE; // TODO(thestig): Fix this and the return type.
4894 FX_DWORD dwIndex = 0; 4894 FX_DWORD dwIndex = 0;
4895 FX_DWORD dwObjNum = 0; 4895 FX_DWORD dwObjNum = 0;
4896 for (int j = 0; j < m_dwNSharedObjsArray[index]; ++j) { 4896 for (int j = 0; j < m_dwNSharedObjsArray[index]; ++j) {
4897 dwIndex = m_dwIdentifierArray[offset + j]; 4897 dwIndex = m_dwIdentifierArray[offset + j];
4898 dwObjNum = m_dwSharedObjNumArray[dwIndex]; 4898 dwObjNum = m_dwSharedObjNumArray[dwIndex];
4899 if (dwObjNum >= nFirstPageObjNum && 4899 if (dwObjNum >= nFirstPageObjNum &&
4900 dwObjNum < nFirstPageObjNum + m_nFirstPageSharedObjs) { 4900 dwObjNum < nFirstPageObjNum + m_nFirstPageSharedObjs) {
4901 continue; 4901 continue;
4902 } 4902 }
4903 dwLength = GetItemLength(dwIndex, m_szSharedObjOffsetArray); 4903 dwLength = GetItemLength(dwIndex, m_szSharedObjOffsetArray);
4904 if (!dwLength || 4904 if (!dwLength ||
4905 !m_pDataAvail->IsDataAvail(m_szSharedObjOffsetArray[dwIndex], dwLength, 4905 !m_pDataAvail->IsDataAvail(m_szSharedObjOffsetArray[dwIndex], dwLength,
4906 pHints)) { 4906 pHints)) {
4907 return PDF_DATA_NOTAVAIL; 4907 return IPDF_DataAvail::DataNotAvailable;
4908 } 4908 }
4909 } 4909 }
4910 return PDF_DATA_AVAIL; 4910 return IPDF_DataAvail::DataAvailable;
4911 } 4911 }
4912 FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { 4912 FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) {
4913 if (!pHintStream || !m_pLinearizedDict) 4913 if (!pHintStream || !m_pLinearizedDict)
4914 return FALSE; 4914 return FALSE;
4915 CPDF_Dictionary* pDict = pHintStream->GetDict(); 4915 CPDF_Dictionary* pDict = pHintStream->GetDict();
4916 CPDF_Object* pOffset = pDict ? pDict->GetElement(FX_BSTRC("S")) : nullptr; 4916 CPDF_Object* pOffset = pDict ? pDict->GetElement(FX_BSTRC("S")) : nullptr;
4917 if (!pOffset || pOffset->GetType() != PDFOBJ_NUMBER) 4917 if (!pOffset || pOffset->GetType() != PDFOBJ_NUMBER)
4918 return FALSE; 4918 return FALSE;
4919 CPDF_StreamAcc acc; 4919 CPDF_StreamAcc acc;
4920 acc.LoadAllData(pHintStream); 4920 acc.LoadAllData(pHintStream);
(...skipping 25 matching lines...) Expand all
4946 if (!m_pLinearizedDict) 4946 if (!m_pLinearizedDict)
4947 return -1; 4947 return -1;
4948 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); 4948 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H"));
4949 if (!pRange) 4949 if (!pRange)
4950 return -1; 4950 return -1;
4951 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 4951 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
4952 if (!pStreamLen) 4952 if (!pStreamLen)
4953 return -1; 4953 return -1;
4954 return pStreamLen->GetInteger(); 4954 return pStreamLen->GetInteger();
4955 } 4955 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_embeddertest.cpp ('k') | fpdfsdk/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698