diff options
author | Lei Zhang <thestig@chromium.org> | 2016-01-13 12:02:09 -0800 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2016-01-13 12:02:09 -0800 |
commit | 5da3cab4f2d9e97eb84483fc0ec13ead2a48e443 (patch) | |
tree | d3e31af684cad2a5b24d9fe8f1eec9800768a214 /core | |
parent | 2e535df617e1a3309a1725c143247302da18a728 (diff) | |
download | pdfium-5da3cab4f2d9e97eb84483fc0ec13ead2a48e443.tar.xz |
Merge to XFA: Use the compiler to type check DocAvailStatus return values.
TBR=jun_fang@foxitsoftware.com
Review URL: https://codereview.chromium.org/1575363007 .
(cherry picked from commit 2fa5c7a8b6602bb2fe1df7cd09b12de666ca8a0a)
Review URL: https://codereview.chromium.org/1585773002 .
Diffstat (limited to 'core')
-rw-r--r-- | core/include/fpdfapi/fpdf_parser.h | 4 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 85 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/parser_int.h | 3 |
3 files changed, 49 insertions, 43 deletions
diff --git a/core/include/fpdfapi/fpdf_parser.h b/core/include/fpdfapi/fpdf_parser.h index 32c1982907..84eacf6bf5 100644 --- a/core/include/fpdfapi/fpdf_parser.h +++ b/core/include/fpdfapi/fpdf_parser.h @@ -905,7 +905,7 @@ class IPDF_DataAvail { virtual DocAvailStatus IsDocAvail(IFX_DownloadHints* pHints) = 0; virtual void SetDocument(CPDF_Document* pDoc) = 0; - virtual int IsPageAvail(int iPage, IFX_DownloadHints* pHints) = 0; + virtual DocAvailStatus IsPageAvail(int iPage, IFX_DownloadHints* pHints) = 0; virtual FX_BOOL IsLinearized() = 0; virtual DocFormStatus IsFormAvail(IFX_DownloadHints* pHints) = 0; virtual DocLinearizationStatus IsLinearizedPDF() = 0; @@ -943,7 +943,7 @@ enum PDF_DATAAVAIL_STATUS { PDF_DATAAVAIL_CROSSREF_ITEM, PDF_DATAAVAIL_CROSSREF_STREAM, PDF_DATAAVAIL_TRAILER, - PDF_DATAAVAIL_LOADALLCRSOSSREF, + PDF_DATAAVAIL_LOADALLCROSSREF, PDF_DATAAVAIL_ROOT, PDF_DATAAVAIL_INFO, PDF_DATAAVAIL_ACROFORM, diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index 777d14cf7e..641e1e18ff 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -2716,7 +2716,7 @@ class CPDF_DataAvail final : public IPDF_DataAvail { // IPDF_DataAvail: DocAvailStatus IsDocAvail(IFX_DownloadHints* pHints) override; void SetDocument(CPDF_Document* pDoc) override; - int IsPageAvail(int iPage, IFX_DownloadHints* pHints) override; + DocAvailStatus IsPageAvail(int iPage, IFX_DownloadHints* pHints) override; DocFormStatus IsFormAvail(IFX_DownloadHints* pHints) override; DocLinearizationStatus IsLinearizedPDF() override; FX_BOOL IsLinearized() override { return m_bLinearized; } @@ -2775,10 +2775,10 @@ class CPDF_DataAvail final : public IPDF_DataAvail { FX_BOOL LoadPages(IFX_DownloadHints* pHints); FX_BOOL LoadAllXref(IFX_DownloadHints* pHints); FX_BOOL LoadAllFile(IFX_DownloadHints* pHints); - int32_t CheckLinearizedData(IFX_DownloadHints* pHints); + DocAvailStatus CheckLinearizedData(IFX_DownloadHints* pHints); FX_BOOL CheckPageAnnots(int iPage, IFX_DownloadHints* pHints); - FX_BOOL CheckLinearizedFirstPage(int iPage, IFX_DownloadHints* pHints); + DocAvailStatus CheckLinearizedFirstPage(int iPage, IFX_DownloadHints* pHints); FX_BOOL HaveResourceAncestor(CPDF_Dictionary* pDict); FX_BOOL CheckPage(int32_t iPage, IFX_DownloadHints* pHints); FX_BOOL LoadDocPages(IFX_DownloadHints* pHints); @@ -3184,7 +3184,7 @@ FX_BOOL CPDF_DataAvail::CheckDocStatus(IFX_DownloadHints* pHints) { return CheckTrailer(pHints); case PDF_DATAAVAIL_TRAILER_APPEND: return CheckTrailerAppend(pHints); - case PDF_DATAAVAIL_LOADALLCRSOSSREF: + case PDF_DATAAVAIL_LOADALLCROSSREF: return LoadAllXref(pHints); case PDF_DATAAVAIL_LOADALLFILE: return LoadAllFile(pHints); @@ -3928,7 +3928,7 @@ FX_BOOL CPDF_DataAvail::CheckAllCrossRefStream(IFX_DownloadHints* pHints) { int32_t nRet = CheckCrossRefStream(pHints, xref_offset); if (nRet == 1) { if (!xref_offset) { - m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; + m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; } else { m_dwCurrentXRefSteam = xref_offset; m_Pos = xref_offset; @@ -3984,7 +3984,7 @@ FX_BOOL CPDF_DataAvail::CheckTrailerAppend(IFX_DownloadHints* pHints) { SetStartOffset(m_dwPrevXRefOffset); m_docStatus = PDF_DATAAVAIL_CROSSREF; } else { - m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; + m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; } return TRUE; } @@ -4294,7 +4294,8 @@ FX_BOOL CPDF_DataAvail::LoadPages(IFX_DownloadHints* pHints) { m_pDocument->LoadPages(); return FALSE; } -int CPDF_DataAvail::CheckLinearizedData(IFX_DownloadHints* pHints) { +IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedData( + IFX_DownloadHints* pHints) { if (m_bLinearedDataOK) { return DataAvailable; } @@ -4353,20 +4354,20 @@ FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, } return bRet; } -FX_BOOL CPDF_DataAvail::CheckLinearizedFirstPage(int32_t iPage, - IFX_DownloadHints* pHints) { +IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckLinearizedFirstPage( + int32_t iPage, + IFX_DownloadHints* pHints) { if (!m_bAnnotsLoad) { if (!CheckPageAnnots(iPage, pHints)) { - return FALSE; + return DataNotAvailable; } m_bAnnotsLoad = TRUE; } - if (m_bAnnotsLoad) { - if (!CheckLinearizedData(pHints)) - return FALSE; - } - m_bPageLoadedOK = FALSE; - return TRUE; + + DocAvailStatus nRet = CheckLinearizedData(pHints); + if (nRet == DataAvailable) + m_bPageLoadedOK = FALSE; + return nRet; } FX_BOOL CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary* pDict) { CFX_AutoRestorer<int> restorer(&s_CurrentDataAvailRecursionDepth); @@ -4388,7 +4389,9 @@ FX_BOOL CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary* pDict) { } return HaveResourceAncestor(pParentDict); } -int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { +IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( + int32_t iPage, + IFX_DownloadHints* pHints) { if (!m_pDocument) { return DataError; } @@ -4405,12 +4408,12 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { if (m_bLinearized) { if ((FX_DWORD)iPage == m_dwFirstPageNo) { - if (!CheckLinearizedFirstPage(iPage, pHints)) - return DataNotAvailable; - m_pagesLoadState.insert(iPage); - return DataAvailable; + DocAvailStatus nRet = CheckLinearizedFirstPage(iPage, pHints); + if (nRet == DataAvailable) + m_pagesLoadState.insert(iPage); + return nRet; } - int32_t nResult = CheckLinearizedData(pHints); + DocAvailStatus nResult = CheckLinearizedData(pHints); if (nResult != DataAvailable) { return nResult; } @@ -4464,33 +4467,30 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { CFX_ArrayTemplate<CPDF_Object*> obj_array; obj_array.Add(m_pPageDict); FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); - if (bRet) { - m_objs_array.RemoveAll(); - m_bPageLoadedOK = TRUE; - } else { - return bRet; - } + if (!bRet) + return DataNotAvailable; + + m_objs_array.RemoveAll(); } else { CFX_ArrayTemplate<CPDF_Object*> new_objs_array; FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); m_objs_array.RemoveAll(); - if (bRet) { - m_bPageLoadedOK = TRUE; - } else { + if (!bRet) { m_objs_array.Append(new_objs_array); return DataNotAvailable; } } + m_bPageLoadedOK = TRUE; } - if (m_bPageLoadedOK) { - if (!m_bAnnotsLoad) { - if (!CheckPageAnnots(iPage, pHints)) { - return DataNotAvailable; - } - m_bAnnotsLoad = TRUE; + + if (!m_bAnnotsLoad) { + if (!CheckPageAnnots(iPage, pHints)) { + return DataNotAvailable; } + m_bAnnotsLoad = TRUE; } + if (m_pPageDict && !m_bNeedDownLoadResource) { m_pPageResource = m_pPageDict->GetElement("Resources"); if (!m_pPageResource) { @@ -4592,9 +4592,12 @@ IPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail( if (!pAcroForm) { return FormNotExist; } - if (!CheckLinearizedData(pHints)) { + DocAvailStatus nDocStatus = CheckLinearizedData(pHints); + if (nDocStatus == DataError) + return FormError; + if (nDocStatus == DataNotAvailable) return FormNotAvailable; - } + if (!m_objs_array.GetSize()) { m_objs_array.Add(pAcroForm->GetDict()); } @@ -4899,7 +4902,9 @@ FX_BOOL CPDF_HintTables::GetPagePos(int index, } return TRUE; } -int32_t CPDF_HintTables::CheckPage(int index, IFX_DownloadHints* pHints) { +IPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( + int index, + IFX_DownloadHints* pHints) { if (!m_pLinearizedDict || !pHints) return IPDF_DataAvail::DataError; CPDF_Object* pFirstAvailPage = m_pLinearizedDict->GetElementValue("P"); diff --git a/core/src/fpdfapi/fpdf_parser/parser_int.h b/core/src/fpdfapi/fpdf_parser/parser_int.h index c7f240384f..70b5fcf870 100644 --- a/core/src/fpdfapi/fpdf_parser/parser_int.h +++ b/core/src/fpdfapi/fpdf_parser/parser_int.h @@ -29,7 +29,8 @@ class CPDF_HintTables { FX_FILESIZE& szPageStartPos, FX_FILESIZE& szPageLength, FX_DWORD& dwObjNum); - FX_BOOL CheckPage(int index, IFX_DownloadHints* pHints); + IPDF_DataAvail::DocAvailStatus CheckPage(int index, + IFX_DownloadHints* pHints); FX_BOOL LoadHintStream(CPDF_Stream* pHintStream); protected: |