summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-11-20 14:55:19 -0800
committerTom Sepez <tsepez@chromium.org>2015-11-20 14:55:19 -0800
commit87d7b4fc58b4ec5fe097de5862490c5720c3ec09 (patch)
treed1f71eee62f3a2c602a29c3fa95dece9d668d72d /core/src/fpdfapi/fpdf_parser
parentb8ec0a3405c6f184e4b9811870081295cae078c9 (diff)
downloadpdfium-87d7b4fc58b4ec5fe097de5862490c5720c3ec09.tar.xz
Make XFA core/ look like master (part N).
R=thestig@chromium.org Review URL: https://codereview.chromium.org/1463173003 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp103
1 files changed, 54 insertions, 49 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index b55ce64a23..2105635687 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -2680,13 +2680,14 @@ class CPDF_DataAvail final : public IPDF_DataAvail {
~CPDF_DataAvail() override;
// IPDF_DataAvail:
- int IsDocAvail(IFX_DownloadHints* pHints) override;
+ DocAvailStatus IsDocAvail(IFX_DownloadHints* pHints) override;
void SetDocument(CPDF_Document* pDoc) override;
int IsPageAvail(int iPage, IFX_DownloadHints* pHints) override;
- int IsFormAvail(IFX_DownloadHints* pHints) override;
- int IsLinearizedPDF() override;
+ DocFormStatus IsFormAvail(IFX_DownloadHints* pHints) override;
+ DocLinearizationStatus IsLinearizedPDF() override;
FX_BOOL IsLinearized() override { return m_bLinearized; }
void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, FX_DWORD* pSize) override;
+
int GetPageCount() const;
CPDF_Dictionary* GetPage(int index);
@@ -3076,20 +3077,23 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array,
obj_array.Append(new_obj_array);
return IsObjectsAvail(obj_array, FALSE, pHints, ret_array);
}
-int CPDF_DataAvail::IsDocAvail(IFX_DownloadHints* pHints) {
+
+IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail(
+ IFX_DownloadHints* pHints) {
if (!m_dwFileLen && m_pFileRead) {
m_dwFileLen = (FX_DWORD)m_pFileRead->GetSize();
if (!m_dwFileLen) {
- return PDF_DATA_ERROR;
+ return DataError;
}
}
while (!m_bDocAvail) {
if (!CheckDocStatus(pHints)) {
- return PDF_DATA_NOTAVAIL;
+ return DataNotAvailable;
}
}
- return PDF_DATA_AVAIL;
+ return DataAvailable;
}
+
FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) {
if (!m_objs_array.GetSize()) {
m_objs_array.RemoveAll();
@@ -3640,24 +3644,24 @@ CPDF_Object* CPDF_DataAvail::ParseIndirectObjectAt(
m_syntaxParser.RestorePos(SavedPos);
return pObj;
}
-int CPDF_DataAvail::IsLinearizedPDF() {
+IPDF_DataAvail::DocLinearizationStatus CPDF_DataAvail::IsLinearizedPDF() {
FX_DWORD req_size = 1024;
if (!m_pFileAvail->IsDataAvail(0, req_size)) {
- return PDF_LINEARIZATION_UNKNOWN;
+ return LinearizationUnknown;
}
if (!m_pFileRead) {
- return PDF_NOT_LINEARIZED;
+ return NotLinearized;
}
FX_FILESIZE dwSize = m_pFileRead->GetSize();
if (dwSize < (FX_FILESIZE)req_size) {
- return PDF_LINEARIZATION_UNKNOWN;
+ return LinearizationUnknown;
}
uint8_t buffer[1024];
m_pFileRead->ReadBlock(buffer, 0, req_size);
if (IsLinearizedFile(buffer, req_size)) {
- return PDF_LINEARIZED;
+ return Linearized;
}
- return PDF_NOT_LINEARIZED;
+ return NotLinearized;
}
FX_BOOL CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, FX_DWORD dwLen) {
ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, FALSE));
@@ -4274,33 +4278,33 @@ FX_BOOL CPDF_DataAvail::LoadPages(IFX_DownloadHints* pHints) {
}
int CPDF_DataAvail::CheckLinearizedData(IFX_DownloadHints* pHints) {
if (m_bLinearedDataOK) {
- return PDF_DATA_AVAIL;
+ return DataAvailable;
}
if (!m_bMainXRefLoadTried) {
FX_SAFE_DWORD data_size = m_dwFileLen;
data_size -= m_dwLastXRefOffset;
if (!data_size.IsValid()) {
- return PDF_DATA_ERROR;
+ return DataError;
}
if (!m_pFileAvail->IsDataAvail(m_dwLastXRefOffset,
data_size.ValueOrDie())) {
pHints->AddSegment(m_dwLastXRefOffset, data_size.ValueOrDie());
- return PDF_DATA_NOTAVAIL;
+ return DataNotAvailable;
}
FX_DWORD dwRet = (m_pDocument->GetParser())->LoadLinearizedMainXRefTable();
m_bMainXRefLoadTried = TRUE;
if (dwRet != PDFPARSE_ERROR_SUCCESS) {
- return PDF_DATA_ERROR;
+ return DataError;
}
if (!PreparePageItem()) {
- return PDF_DATA_NOTAVAIL;
+ return DataNotAvailable;
}
m_bMainXRefLoadedOK = TRUE;
m_bLinearedDataOK = TRUE;
}
- return m_bLinearedDataOK ? PDF_DATA_AVAIL : PDF_DATA_NOTAVAIL;
+ return m_bLinearedDataOK ? DataAvailable : DataNotAvailable;
}
FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage,
IFX_DownloadHints* pHints) {
@@ -4368,7 +4372,7 @@ FX_BOOL CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary* pDict) {
}
int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
if (!m_pDocument) {
- return PDF_DATA_ERROR;
+ return DataError;
}
if (IsFirstCheck(iPage)) {
m_bCurPageDictLoadOK = FALSE;
@@ -4379,52 +4383,52 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
m_objnum_array.RemoveAll();
}
if (m_pagesLoadState.find(iPage) != m_pagesLoadState.end()) {
- return PDF_DATA_AVAIL;
+ return DataAvailable;
}
if (m_bLinearized) {
if ((FX_DWORD)iPage == m_dwFirstPageNo) {
m_pagesLoadState.insert(iPage);
- return PDF_DATA_AVAIL;
+ return DataAvailable;
}
int32_t nResult = CheckLinearizedData(pHints);
- if (nResult != PDF_DATA_AVAIL) {
+ if (nResult != DataAvailable) {
return nResult;
}
if (m_pHintTables) {
nResult = m_pHintTables->CheckPage(iPage, pHints);
- if (nResult != PDF_DATA_AVAIL)
+ if (nResult != DataAvailable)
return nResult;
m_pagesLoadState.insert(iPage);
- return PDF_DATA_AVAIL;
+ return DataAvailable;
}
if (m_bMainXRefLoadedOK) {
if (m_bTotalLoadPageTree) {
if (!LoadPages(pHints)) {
- return PDF_DATA_NOTAVAIL;
+ return DataNotAvailable;
}
} else {
if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) {
- return PDF_DATA_NOTAVAIL;
+ return DataNotAvailable;
}
}
} else {
if (!LoadAllFile(pHints)) {
- return PDF_DATA_NOTAVAIL;
+ return DataNotAvailable;
}
((CPDF_Parser*)m_pDocument->GetParser())->RebuildCrossRef();
ResetFirstCheck(iPage);
- return PDF_DATA_AVAIL;
+ return DataAvailable;
}
} else {
if (!m_bTotalLoadPageTree) {
if (!m_bCurPageDictLoadOK && !CheckPage(iPage, pHints)) {
- return PDF_DATA_NOTAVAIL;
+ return DataNotAvailable;
}
}
}
if (m_bHaveAcroForm && !m_bAcroFormLoad) {
if (!CheckAcroFormSubObject(pHints)) {
- return PDF_DATA_NOTAVAIL;
+ return DataNotAvailable;
}
m_bAcroFormLoad = TRUE;
}
@@ -4435,7 +4439,7 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
m_pPageDict = m_pDocument->GetPage(iPage);
if (!m_pPageDict) {
ResetFirstCheck(iPage);
- return PDF_DATA_AVAIL;
+ return DataAvailable;
}
CFX_PtrArray obj_array;
obj_array.Add(m_pPageDict);
@@ -4455,14 +4459,14 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
m_bPageLoadedOK = TRUE;
} else {
m_objs_array.Append(new_objs_array);
- return PDF_DATA_NOTAVAIL;
+ return DataNotAvailable;
}
}
}
if (m_bPageLoadedOK) {
if (!m_bAnnotsLoad) {
if (!CheckPageAnnots(iPage, pHints)) {
- return PDF_DATA_NOTAVAIL;
+ return DataNotAvailable;
}
m_bAnnotsLoad = TRUE;
}
@@ -4478,7 +4482,7 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
if (m_bNeedDownLoadResource) {
FX_BOOL bRet = CheckResources(pHints);
if (!bRet) {
- return PDF_DATA_NOTAVAIL;
+ return DataNotAvailable;
}
m_bNeedDownLoadResource = FALSE;
}
@@ -4487,7 +4491,7 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
m_bCurPageDictLoadOK = FALSE;
ResetFirstCheck(iPage);
m_pagesLoadState.insert(iPage);
- return PDF_DATA_AVAIL;
+ return DataAvailable;
}
FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) {
if (!m_objs_array.GetSize()) {
@@ -4553,21 +4557,22 @@ CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) {
}
return m_pDocument->GetPage(index);
}
-int CPDF_DataAvail::IsFormAvail(IFX_DownloadHints* pHints) {
+IPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail(
+ IFX_DownloadHints* pHints) {
if (!m_pDocument) {
- return PDF_FORM_AVAIL;
+ return FormAvailable;
}
if (!m_bLinearizedFormParamLoad) {
CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
if (!pRoot) {
- return PDF_FORM_AVAIL;
+ return FormAvailable;
}
CPDF_Object* pAcroForm = pRoot->GetElement(FX_BSTRC("AcroForm"));
if (!pAcroForm) {
- return PDF_FORM_NOTEXIST;
+ return FormNotExist;
}
if (!CheckLinearizedData(pHints)) {
- return PDF_FORM_NOTAVAIL;
+ return FormNotAvailable;
}
if (!m_objs_array.GetSize()) {
m_objs_array.Add(pAcroForm->GetDict());
@@ -4579,9 +4584,9 @@ int CPDF_DataAvail::IsFormAvail(IFX_DownloadHints* pHints) {
m_objs_array.RemoveAll();
if (!bRet) {
m_objs_array.Append(new_objs_array);
- return PDF_FORM_NOTAVAIL;
+ return FormNotAvailable;
}
- return PDF_FORM_AVAIL;
+ return FormAvailable;
}
void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum) {
int32_t iNext = 0;
@@ -4865,17 +4870,17 @@ FX_BOOL CPDF_HintTables::GetPagePos(int index,
}
int32_t CPDF_HintTables::CheckPage(int index, IFX_DownloadHints* pHints) {
if (!m_pLinearizedDict || !pHints)
- return PDF_DATA_ERROR;
+ return IPDF_DataAvail::DataError;
CPDF_Object* pFirstAvailPage =
m_pLinearizedDict->GetElementValue(FX_BSTRC("P"));
int nFirstAvailPage = pFirstAvailPage ? pFirstAvailPage->GetInteger() : 0;
if (index == nFirstAvailPage)
- return PDF_DATA_AVAIL;
+ return IPDF_DataAvail::DataAvailable;
FX_DWORD dwLength = GetItemLength(index, m_szPageOffsetArray);
if (!dwLength ||
!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength,
pHints)) {
- return PDF_DATA_NOTAVAIL;
+ return IPDF_DataAvail::DataNotAvailable;
}
// Download data of shared objects in the page.
FX_DWORD offset = 0;
@@ -4886,7 +4891,7 @@ int32_t CPDF_HintTables::CheckPage(int index, IFX_DownloadHints* pHints) {
m_pLinearizedDict->GetElementValue(FX_BSTRC("O"));
int nFirstPageObjNum = pFirstPageObj ? pFirstPageObj->GetInteger() : -1;
if (nFirstPageObjNum < 0)
- return FALSE;
+ return FALSE; // TODO(thestig): Fix this and the return type.
FX_DWORD dwIndex = 0;
FX_DWORD dwObjNum = 0;
for (int j = 0; j < m_dwNSharedObjsArray[index]; ++j) {
@@ -4900,10 +4905,10 @@ int32_t CPDF_HintTables::CheckPage(int index, IFX_DownloadHints* pHints) {
if (!dwLength ||
!m_pDataAvail->IsDataAvail(m_szSharedObjOffsetArray[dwIndex], dwLength,
pHints)) {
- return PDF_DATA_NOTAVAIL;
+ return IPDF_DataAvail::DataNotAvailable;
}
}
- return PDF_DATA_AVAIL;
+ return IPDF_DataAvail::DataAvailable;
}
FX_BOOL CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) {
if (!pHintStream || !m_pLinearizedDict)