diff options
author | Nicolas Pena <npm@chromium.org> | 2017-01-23 15:48:51 -0500 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-01-24 15:30:36 +0000 |
commit | a478dc5ca23b6f2f609b119cdc6b0336d1471d8c (patch) | |
tree | c57caac5f6341d4c340a6cf18802168b07e09eb1 | |
parent | 7e5fdd0b1a2ce17e89723fee3e58ae472e32461f (diff) | |
download | pdfium-a478dc5ca23b6f2f609b119cdc6b0336d1471d8c.tar.xz |
Fix CPDF_InterForm::CheckRequiredFields and its callers.
The method is used twice in fpdfsdk/cpdfsdk_interform.cpp and twice in
fpdfsdk/javascript/Document.cpp, but not in a compatible way. Changed
the method so that it now returns true when checks pass, which is the
more natural thing to do, considering the name of the method.
BUG=pdfium:659
Change-Id: Iacf3049f328df1d4db3fbfc995acf184230ebf48
Reviewed-on: https://pdfium-review.googlesource.com/2297
Commit-Queue: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | core/fpdfdoc/cpdf_formfield.cpp | 16 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_formfield.h | 4 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_interform.cpp | 12 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_interform.h | 5 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_interform.cpp | 4 |
5 files changed, 21 insertions, 20 deletions
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index b344327adc..b4aa90e2be 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp @@ -31,10 +31,6 @@ const int kFormListMultiSelect = 0x100; const int kFormComboEdit = 0x100; -const int kFormFieldReadOnly = 0x01; -const int kFormFieldRequired = 0x02; -const int kFormFieldNoExport = 0x04; - const int kFormRadioNoToggleOff = 0x100; const int kFormRadioUnison = 0x200; @@ -108,12 +104,12 @@ void CPDF_FormField::SyncFieldFlags() { ? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() : 0; m_Flags = 0; - if (flags & 1) - m_Flags |= kFormFieldReadOnly; - if (flags & 2) - m_Flags |= kFormFieldRequired; - if (flags & 4) - m_Flags |= kFormFieldNoExport; + if (flags & FORMFLAG_READONLY) + m_Flags |= FORMFLAG_READONLY; + if (flags & FORMFLAG_REQUIRED) + m_Flags |= FORMFLAG_REQUIRED; + if (flags & FORMFLAG_NOEXPORT) + m_Flags |= FORMFLAG_NOEXPORT; if (type_name == "Btn") { if (flags & 0x8000) { diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h index 9a1ddc4599..42608b1122 100644 --- a/core/fpdfdoc/cpdf_formfield.h +++ b/core/fpdfdoc/cpdf_formfield.h @@ -25,6 +25,10 @@ #define FIELDTYPE_TEXTFIELD 6 #define FIELDTYPE_SIGNATURE 7 +#define FORMFLAG_READONLY 0x01 +#define FORMFLAG_REQUIRED 0x02 +#define FORMFLAG_NOEXPORT 0x04 + class CPDF_Dictionary; class CPDF_Font; class CPDF_FormControl; diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index 6cffea6222..127e542227 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -1157,7 +1157,7 @@ CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField, return pControl; } -CPDF_FormField* CPDF_InterForm::CheckRequiredFields( +bool CPDF_InterForm::CheckRequiredFields( const std::vector<CPDF_FormField*>* fields, bool bIncludeOrExclude) const { size_t nCount = m_pFieldTree->m_Root.CountFields(); @@ -1173,7 +1173,7 @@ CPDF_FormField* CPDF_InterForm::CheckRequiredFields( } uint32_t dwFlags = pField->GetFieldFlags(); // TODO(thestig): Look up these magic numbers and add constants for them. - if (dwFlags & 0x04) + if (dwFlags & FORMFLAG_NOEXPORT) continue; bool bFind = true; @@ -1181,11 +1181,13 @@ CPDF_FormField* CPDF_InterForm::CheckRequiredFields( bFind = pdfium::ContainsValue(*fields, pField); if (bIncludeOrExclude == bFind) { CPDF_Dictionary* pFieldDict = pField->m_pDict; - if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringFor("V").IsEmpty()) - return pField; + if ((dwFlags & FORMFLAG_REQUIRED) != 0 && + pFieldDict->GetStringFor("V").IsEmpty()) { + return false; + } } } - return nullptr; + return true; } std::unique_ptr<CFDF_Document> CPDF_InterForm::ExportToFDF( diff --git a/core/fpdfdoc/cpdf_interform.h b/core/fpdfdoc/cpdf_interform.h index b846973435..a42c4cef84 100644 --- a/core/fpdfdoc/cpdf_interform.h +++ b/core/fpdfdoc/cpdf_interform.h @@ -69,9 +69,8 @@ class CPDF_InterForm { CPDF_DefaultAppearance GetDefaultAppearance() const; int GetFormAlignment() const; - CPDF_FormField* CheckRequiredFields( - const std::vector<CPDF_FormField*>* fields, - bool bIncludeOrExclude) const; + bool CheckRequiredFields(const std::vector<CPDF_FormField*>* fields, + bool bIncludeOrExclude) const; std::unique_ptr<CFDF_Document> ExportToFDF(const CFX_WideStringC& pdf_path, bool bSimpleFileSpec) const; diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index 7b7718030b..b22ccb1684 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -427,13 +427,13 @@ bool CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); if (!fields.empty()) { bool bIncludeOrExclude = !(dwFlags & 0x01); - if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) + if (!m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) return false; return SubmitFields(sDestination, fields, bIncludeOrExclude, false); } } - if (m_pInterForm->CheckRequiredFields(nullptr, true)) + if (!m_pInterForm->CheckRequiredFields(nullptr, true)) return false; return SubmitForm(sDestination, false); |