diff options
author | tonikitoo <tonikitoo@igalia.com> | 2016-08-02 11:52:28 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-02 11:52:28 -0700 |
commit | ea3ff9eaaa508b9cbc7f52bc92d189eacbc7a935 (patch) | |
tree | 286510e2a2aae68e7c1495d7cbed0b6880a805ba | |
parent | 6faf9f9508b858e27fde9a7f75ff6962048326ca (diff) | |
download | pdfium-chromium/2818.tar.xz |
Introduce ::getPropertyInternal method to avoid duplicationchromium/2819chromium/2818chromium/2817
Document.cpp implements "getter" methods for some of the
Document object properties.
Some of the body of such methods are identical.
Patch introduces a ::getPropertyInternal private method
that gets rid of this duplication.
Namely the following properties' getters are cleaned up:
- "author", "creationDate", "creator", "keywords",
- "modDate", "producer", "subject" and "title"
No behavior change.
Review-Url: https://codereview.chromium.org/2202283002
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 141 | ||||
-rw-r--r-- | fpdfsdk/javascript/Document.h | 5 |
3 files changed, 27 insertions, 120 deletions
@@ -9,6 +9,7 @@ # See python fnmatch module documentation for more information. Andrey Khalyavin <halyavin@chromium.org> +Antonio Gomes <tonikitoo@igalia.com> Brett Wilson <brettw@chromium.org> Bruce Dawson <brucedawson@chromium.org> Chery Cherian <cherycherian@gmail.com> diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index 56b0b8479f..a4c639f4f1 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -714,23 +714,7 @@ FX_BOOL Document::mailDoc(IJS_Context* cc, FX_BOOL Document::author(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); - if (!pDictionary) - return FALSE; - - if (vp.IsGetting()) { - vp << pDictionary->GetUnicodeTextBy("Author"); - return TRUE; - } else { - if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) - return FALSE; - - CFX_WideString csAuthor; - vp >> csAuthor; - pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor)); - m_pDocument->SetChangeMark(); - return TRUE; - } + return getPropertyInternal(cc, vp, "Author", sError); } FX_BOOL Document::info(IJS_Context* cc, @@ -785,46 +769,38 @@ FX_BOOL Document::info(IJS_Context* cc, return TRUE; } -FX_BOOL Document::creationDate(IJS_Context* cc, - CJS_PropValue& vp, - CFX_WideString& sError) { +FX_BOOL Document::getPropertyInternal(IJS_Context* cc, + CJS_PropValue& vp, + const CFX_ByteString& propName, + CFX_WideString& sError) { CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); if (!pDictionary) return FALSE; if (vp.IsGetting()) { - vp << pDictionary->GetUnicodeTextBy("CreationDate"); + vp << pDictionary->GetUnicodeTextBy(propName); } else { if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; - CFX_WideString csCreationDate; - vp >> csCreationDate; - pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate)); + CFX_WideString csProperty; + vp >> csProperty; + pDictionary->SetAtString(propName, PDF_EncodeText(csProperty)); m_pDocument->SetChangeMark(); } return TRUE; } +FX_BOOL Document::creationDate(IJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return getPropertyInternal(cc, vp, "CreationDate", sError); +} + FX_BOOL Document::creator(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); - if (!pDictionary) - return FALSE; - - if (vp.IsGetting()) { - vp << pDictionary->GetUnicodeTextBy("Creator"); - } else { - if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) - return FALSE; - - CFX_WideString csCreator; - vp >> csCreator; - pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator)); - m_pDocument->SetChangeMark(); - } - return TRUE; + return getPropertyInternal(cc, vp, "Creator", sError); } FX_BOOL Document::delay(IJS_Context* cc, @@ -852,85 +828,25 @@ FX_BOOL Document::delay(IJS_Context* cc, FX_BOOL Document::keywords(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); - if (!pDictionary) - return FALSE; - - if (vp.IsGetting()) { - vp << pDictionary->GetUnicodeTextBy("Keywords"); - } else { - if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) - return FALSE; - - CFX_WideString csKeywords; - vp >> csKeywords; - pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords)); - m_pDocument->SetChangeMark(); - } - return TRUE; + return getPropertyInternal(cc, vp, "Keywords", sError); } FX_BOOL Document::modDate(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); - if (!pDictionary) - return FALSE; - - if (vp.IsGetting()) { - vp << pDictionary->GetUnicodeTextBy("ModDate"); - } else { - if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) - return FALSE; - - CFX_WideString csmodDate; - vp >> csmodDate; - pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate)); - m_pDocument->SetChangeMark(); - } - return TRUE; + return getPropertyInternal(cc, vp, "ModDate", sError); } FX_BOOL Document::producer(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); - if (!pDictionary) - return FALSE; - - if (vp.IsGetting()) { - vp << pDictionary->GetUnicodeTextBy("Producer"); - } else { - if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) - return FALSE; - - CFX_WideString csproducer; - vp >> csproducer; - pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer)); - m_pDocument->SetChangeMark(); - } - return TRUE; + return getPropertyInternal(cc, vp, "Producer", sError); } FX_BOOL Document::subject(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); - if (!pDictionary) - return FALSE; - - if (vp.IsGetting()) { - vp << pDictionary->GetUnicodeTextBy("Subject"); - } else { - if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) - return FALSE; - - CFX_WideString cssubject; - vp >> cssubject; - pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject)); - m_pDocument->SetChangeMark(); - } - return TRUE; + return getPropertyInternal(cc, vp, "Subject", sError); } FX_BOOL Document::title(IJS_Context* cc, @@ -939,22 +855,7 @@ FX_BOOL Document::title(IJS_Context* cc, if (!m_pDocument || !m_pDocument->GetUnderlyingDocument()) return FALSE; - CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); - if (!pDictionary) - return FALSE; - - if (vp.IsGetting()) { - vp << pDictionary->GetUnicodeTextBy("Title"); - } else { - if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) - return FALSE; - - CFX_WideString cstitle; - vp >> cstitle; - pDictionary->SetAtString("Title", PDF_EncodeText(cstitle)); - m_pDocument->SetChangeMark(); - } - return TRUE; + return getPropertyInternal(cc, vp, "Title", sError); } FX_BOOL Document::numPages(IJS_Context* cc, diff --git a/fpdfsdk/javascript/Document.h b/fpdfsdk/javascript/Document.h index c0ef840d4a..7e5d6dfe8a 100644 --- a/fpdfsdk/javascript/Document.h +++ b/fpdfsdk/javascript/Document.h @@ -272,6 +272,11 @@ class Document : public CJS_EmbedObj { int CountWords(CPDF_TextObject* pTextObj); CFX_WideString GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex); + FX_BOOL getPropertyInternal(IJS_Context* cc, + CJS_PropValue& vp, + const CFX_ByteString& propName, + CFX_WideString& sError); + v8::Isolate* m_isolate; std::list<std::unique_ptr<IconElement>> m_IconList; CPDFSDK_Document* m_pDocument; |