Chromium Code Reviews| Index: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp |
| diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp |
| index 12e2a3946c91ad6e3daafceefd02536a33e272e3..865f0c157817dc221b466c7ff5d9a0a68dafca48 100644 |
| --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp |
| +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp |
| @@ -259,11 +259,9 @@ FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, |
| } |
| if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { |
| CPDF_Reference* pMetadata = |
| - (CPDF_Reference*)m_pDocument->GetRoot()->GetElement( |
| - FX_BSTRC("Metadata")); |
| - if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) { |
| + ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"))); |
| + if (pMetadata) |
| m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); |
| - } |
| } |
| return PDFPARSE_ERROR_SUCCESS; |
| } |
| @@ -277,12 +275,10 @@ FX_DWORD CPDF_Parser::SetEncryptHandler() { |
| if (pEncryptObj) { |
| if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { |
| SetEncryptDictionary(pEncryptDict); |
| - } else if (pEncryptObj->GetType() == PDFOBJ_REFERENCE) { |
| - pEncryptObj = m_pDocument->GetIndirectObject( |
| - ((CPDF_Reference*)pEncryptObj)->GetRefObjNum()); |
| - if (pEncryptObj) { |
| + } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { |
| + pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); |
| + if (pEncryptObj) |
| SetEncryptDictionary(pEncryptObj->GetDict()); |
| - } |
| } |
| } |
| if (m_bForceUseSecurityHandler) { |
| @@ -855,12 +851,12 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { |
| if (m_pTrailer) { |
| CPDF_Object* pRoot = |
| pTrailer->GetElement(FX_BSTRC("Root")); |
| - if (pRoot == NULL || |
| - (pRoot->GetType() == PDFOBJ_REFERENCE && |
| + CPDF_Reference* pRef = ToReference(pRoot); |
| + if (!pRoot || |
| + (pRef && |
| (FX_DWORD)m_CrossRef.GetSize() > |
| - ((CPDF_Reference*)pRoot)->GetRefObjNum() && |
| - m_CrossRef.GetAt(((CPDF_Reference*)pRoot) |
| - ->GetRefObjNum()) != 0)) { |
| + pRef->GetRefObjNum() && |
| + m_CrossRef.GetAt(pRef->GetRefObjNum()) != 0)) { |
| FX_POSITION pos = pTrailer->GetStartPos(); |
| while (pos) { |
| CFX_ByteString key; |
| @@ -1144,27 +1140,21 @@ CPDF_Array* CPDF_Parser::GetIDArray() { |
| if (!pID) |
| return nullptr; |
| - if (pID->GetType() == PDFOBJ_REFERENCE) { |
| - pID = ParseIndirectObject(NULL, ((CPDF_Reference*)pID)->GetRefObjNum()); |
| + if (CPDF_Reference* pRef = pID->AsReference()) { |
| + pID = ParseIndirectObject(nullptr, pRef->GetRefObjNum()); |
| m_pTrailer->SetAt(FX_BSTRC("ID"), pID); |
| } |
| return ToArray(pID); |
| } |
| FX_DWORD CPDF_Parser::GetRootObjNum() { |
| - CPDF_Object* pRef = |
| - m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : NULL; |
| - if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
| - return 0; |
| - } |
| - return ((CPDF_Reference*)pRef)->GetRefObjNum(); |
| + CPDF_Reference* pRef = ToReference( |
| + m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Root")) : nullptr); |
| + return pRef ? pRef->GetRefObjNum() : 0; |
| } |
| FX_DWORD CPDF_Parser::GetInfoObjNum() { |
| - CPDF_Object* pRef = |
| - m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) : NULL; |
| - if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
| - return 0; |
| - } |
| - return ((CPDF_Reference*)pRef)->GetRefObjNum(); |
| + CPDF_Reference* pRef = ToReference( |
| + m_pTrailer ? m_pTrailer->GetElement(FX_BSTRC("Info")) : nullptr); |
| + return pRef ? pRef->GetRefObjNum() : 0; |
| } |
| FX_BOOL CPDF_Parser::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) { |
| bForm = FALSE; |
| @@ -1637,11 +1627,9 @@ FX_DWORD CPDF_Parser::StartAsynParse(IFX_FileRead* pFileAccess, |
| } |
| } |
| if (m_pSecurityHandler && m_pSecurityHandler->IsMetadataEncrypted()) { |
| - CPDF_Object* pMetadata = |
| - m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")); |
| - if (pMetadata && pMetadata->GetType() == PDFOBJ_REFERENCE) { |
| - m_Syntax.m_MetadataObjnum = ((CPDF_Reference*)pMetadata)->GetRefObjNum(); |
| - } |
| + if (CPDF_Reference* pMetadata = ToReference( |
| + m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")))) |
| + m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); |
| } |
| return PDFPARSE_ERROR_SUCCESS; |
| } |
| @@ -2395,9 +2383,9 @@ CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, |
| FX_DWORD gennum) { |
| CPDF_Object* pLenObj = pDict->GetElement(FX_BSTRC("Length")); |
| FX_FILESIZE len = -1; |
| - if (pLenObj && ((pLenObj->GetType() != PDFOBJ_REFERENCE) || |
| - ((((CPDF_Reference*)pLenObj)->GetObjList()) && |
| - ((CPDF_Reference*)pLenObj)->GetRefObjNum() != objnum))) { |
| + CPDF_Reference* pLenObjRef = ToReference(pLenObj); |
| + if (pLenObj && ((!pLenObjRef || ((pLenObjRef->GetObjList()) && |
|
Lei Zhang
2015/10/22 21:26:51
There's some extra parenthesis in there? Consider
dsinclair
2015/10/26 13:55:45
Done.
|
| + pLenObjRef->GetRefObjNum() != objnum)))) { |
| len = pLenObj->GetInteger(); |
| } |
| // Locate the start of stream. |
| @@ -3083,7 +3071,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, |
| } |
| } break; |
| case PDFOBJ_REFERENCE: { |
| - CPDF_Reference* pRef = (CPDF_Reference*)pObj; |
| + CPDF_Reference* pRef = pObj->AsReference(); |
| FX_DWORD dwNum = pRef->GetRefObjNum(); |
| FX_FILESIZE offset; |
| FX_DWORD original_size = GetObjectSize(dwNum, offset); |
| @@ -3125,13 +3113,10 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array, |
| int32_t iSize = new_obj_array.GetSize(); |
| for (i = 0; i < iSize; ++i) { |
| CPDF_Object* pObj = (CPDF_Object*)new_obj_array[i]; |
| - int32_t type = pObj->GetType(); |
| - if (type == PDFOBJ_REFERENCE) { |
| - CPDF_Reference* pRef = (CPDF_Reference*)pObj; |
| + if (CPDF_Reference* pRef = pObj->AsReference()) { |
| FX_DWORD dwNum = pRef->GetRefObjNum(); |
| - if (!m_objnum_array.Find(dwNum)) { |
| + if (!m_objnum_array.Find(dwNum)) |
| ret_array.Add(pObj); |
| - } |
| } else { |
| ret_array.Add(pObj); |
| } |
| @@ -3399,37 +3384,36 @@ FX_BOOL CPDF_DataAvail::CheckRoot(IFX_DownloadHints* pHints) { |
| m_docStatus = PDF_DATAAVAIL_ERROR; |
| return FALSE; |
| } |
| - CPDF_Reference* pRef = (CPDF_Reference*)pDict->GetElement(FX_BSTRC("Pages")); |
| - if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
| + CPDF_Reference* pRef = ToReference(pDict->GetElement(FX_BSTRC("Pages"))); |
| + if (!pRef) { |
| m_docStatus = PDF_DATAAVAIL_ERROR; |
| return FALSE; |
| } |
| + |
| m_PagesObjNum = pRef->GetRefObjNum(); |
| CPDF_Reference* pAcroFormRef = |
| - (CPDF_Reference*)m_pRoot->GetDict()->GetElement(FX_BSTRC("AcroForm")); |
| - if (pAcroFormRef && pAcroFormRef->GetType() == PDFOBJ_REFERENCE) { |
| + ToReference(m_pRoot->GetDict()->GetElement(FX_BSTRC("AcroForm"))); |
| + if (pAcroFormRef) { |
| m_bHaveAcroForm = TRUE; |
| m_dwAcroFormObjNum = pAcroFormRef->GetRefObjNum(); |
| } |
| - if (m_dwInfoObjNum) { |
| + |
| + if (m_dwInfoObjNum) |
|
Lei Zhang
2015/10/22 21:26:51
braces
dsinclair
2015/10/26 13:55:45
Done.
|
| m_docStatus = PDF_DATAAVAIL_INFO; |
| - } else { |
| - if (m_bHaveAcroForm) { |
| - m_docStatus = PDF_DATAAVAIL_ACROFORM; |
| - } else { |
| - m_docStatus = PDF_DATAAVAIL_PAGETREE; |
| - } |
| - } |
| + else |
| + m_docStatus = |
| + m_bHaveAcroForm ? PDF_DATAAVAIL_ACROFORM : PDF_DATAAVAIL_PAGETREE; |
| return TRUE; |
| } |
| FX_BOOL CPDF_DataAvail::PreparePageItem() { |
| CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
| CPDF_Reference* pRef = |
| - pRoot ? (CPDF_Reference*)pRoot->GetElement(FX_BSTRC("Pages")) : NULL; |
| - if (pRef == NULL || pRef->GetType() != PDFOBJ_REFERENCE) { |
| + ToReference(pRoot ? pRoot->GetElement(FX_BSTRC("Pages")) : nullptr); |
| + if (!pRef) { |
| m_docStatus = PDF_DATAAVAIL_ERROR; |
| return FALSE; |
| } |
| + |
| m_PagesObjNum = pRef->GetRefObjNum(); |
| m_pCurrentParser = (CPDF_Parser*)m_pDocument->GetParser(); |
| m_docStatus = PDF_DATAAVAIL_PAGETREE; |
| @@ -3462,12 +3446,9 @@ FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) { |
| CPDF_Array* pArray = pObj->GetArray(); |
| if (pArray) { |
| int32_t iSize = pArray->GetCount(); |
| - CPDF_Object* pItem = NULL; |
| for (int32_t j = 0; j < iSize; ++j) { |
| - pItem = pArray->GetElement(j); |
| - if (pItem && pItem->GetType() == PDFOBJ_REFERENCE) { |
| - UnavailObjList.Add(((CPDF_Reference*)pItem)->GetRefObjNum()); |
| - } |
| + if (CPDF_Reference* pRef = ToReference(pArray->GetElement(j))) |
| + UnavailObjList.Add(pRef->GetRefObjNum()); |
| } |
| } |
| } |
| @@ -3523,16 +3504,14 @@ FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) { |
| } |
| switch (pKids->GetType()) { |
| case PDFOBJ_REFERENCE: { |
| - CPDF_Reference* pKid = (CPDF_Reference*)pKids; |
| + CPDF_Reference* pKid = pKids->AsReference(); |
|
Lei Zhang
2015/10/22 21:26:51
fold into next line?
dsinclair
2015/10/26 13:55:45
Done.
|
| m_PageObjList.Add(pKid->GetRefObjNum()); |
| } break; |
| case PDFOBJ_ARRAY: { |
| CPDF_Array* pKidsArray = pKids->AsArray(); |
| for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { |
| - CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i); |
| - if (pKid && pKid->GetType() == PDFOBJ_REFERENCE) { |
| - m_PageObjList.Add(((CPDF_Reference*)pKid)->GetRefObjNum()); |
| - } |
| + if (CPDF_Reference* pRef = ToReference(pKidsArray->GetElement(i))) |
| + m_PageObjList.Add(pRef->GetRefObjNum()); |
| } |
| } break; |
| default: |
| @@ -4031,7 +4010,7 @@ FX_BOOL CPDF_DataAvail::CheckTrailer(IFX_DownloadHints* pHints) { |
| CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); |
| CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt"); |
| - if (pEncrypt && pEncrypt->GetType() == PDFOBJ_REFERENCE) { |
| + if (ToReference(pEncrypt)) { |
| m_docStatus = PDF_DATAAVAIL_LOADALLFILE; |
| return TRUE; |
| } |
| @@ -4110,13 +4089,13 @@ FX_BOOL CPDF_DataAvail::CheckArrayPageNode(FX_DWORD dwPageNo, |
| pPageNode->m_type = PDF_PAGENODE_PAGES; |
| for (FX_DWORD i = 0; i < pArray->GetCount(); ++i) { |
| - CPDF_Object* pKid = (CPDF_Object*)pArray->GetElement(i); |
| - if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { |
| + CPDF_Reference* pKid = ToReference(pArray->GetElement(i)); |
| + if (!pKid) |
| continue; |
| - } |
| + |
| CPDF_PageNode* pNode = new CPDF_PageNode(); |
| pPageNode->m_childNode.Add(pNode); |
| - pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); |
| + pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| } |
| pPages->Release(); |
| return TRUE; |
| @@ -4160,7 +4139,7 @@ FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, |
| } |
| switch (pKids->GetType()) { |
| case PDFOBJ_REFERENCE: { |
| - CPDF_Reference* pKid = (CPDF_Reference*)pKids; |
| + CPDF_Reference* pKid = pKids->AsReference(); |
| CPDF_PageNode* pNode = new CPDF_PageNode(); |
| pPageNode->m_childNode.Add(pNode); |
| pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| @@ -4168,13 +4147,13 @@ FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(FX_DWORD dwPageNo, |
| case PDFOBJ_ARRAY: { |
| CPDF_Array* pKidsArray = pKids->AsArray(); |
| for (FX_DWORD i = 0; i < pKidsArray->GetCount(); ++i) { |
| - CPDF_Object* pKid = (CPDF_Object*)pKidsArray->GetElement(i); |
| - if (!pKid || pKid->GetType() != PDFOBJ_REFERENCE) { |
| + CPDF_Reference* pKid = ToReference(pKidsArray->GetElement(i)); |
| + if (!pKid) |
| continue; |
| - } |
| + |
| CPDF_PageNode* pNode = new CPDF_PageNode(); |
| pPageNode->m_childNode.Add(pNode); |
| - pNode->m_dwPageNo = ((CPDF_Reference*)pKid)->GetRefObjNum(); |
| + pNode->m_dwPageNo = pKid->GetRefObjNum(); |
| } |
| } break; |
| default: |