Commit cdcaa4a7 authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Chromium LUCI CQ

Add PDF creation and modification dates to DocumentMetadata

Store the creation and modification dates as base::Time fields in
DocumentMetadata.

Bug: 93619
Change-Id: I34eedf5cf88dd102e492ed0451d3e4a4a7988cc6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2610626
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843376}
parent 42259e1c
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <string> #include <string>
#include "base/time/time.h"
namespace chrome_pdf { namespace chrome_pdf {
// These values are persisted to logs. Entries should not be renumbered and // These values are persisted to logs. Entries should not be renumbered and
...@@ -29,8 +31,7 @@ enum class PdfVersion { ...@@ -29,8 +31,7 @@ enum class PdfVersion {
// Document properties, including those specified in the document information // Document properties, including those specified in the document information
// dictionary (see section 14.3.3 "Document Information Dictionary" of the ISO // dictionary (see section 14.3.3 "Document Information Dictionary" of the ISO
// 32000-1 standard), as well as other properties about the file. // 32000-1 standard), as well as other properties about the file.
// TODO(crbug.com/93619): Finish adding information dictionary fields like // TODO(crbug.com/93619): Finish adding fields like `size_bytes` and
// `creation_date` and `mod_date`. Also add fields like `size_bytes` and
// `is_encrypted`. // `is_encrypted`.
struct DocumentMetadata { struct DocumentMetadata {
DocumentMetadata(); DocumentMetadata();
...@@ -62,6 +63,12 @@ struct DocumentMetadata { ...@@ -62,6 +63,12 @@ struct DocumentMetadata {
// If the document's format was not originally PDF, the name of the // If the document's format was not originally PDF, the name of the
// application that converted the document to PDF. // application that converted the document to PDF.
std::string producer; std::string producer;
// The date and time the document was created.
base::Time creation_date;
// The date and time the document was most recently modified
base::Time mod_date;
}; };
} // namespace chrome_pdf } // namespace chrome_pdf
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "pdf/draw_utils/shadow.h" #include "pdf/draw_utils/shadow.h"
#include "pdf/pdf_features.h" #include "pdf/pdf_features.h"
#include "pdf/pdf_transform.h" #include "pdf/pdf_transform.h"
#include "pdf/pdf_utils/dates.h"
#include "pdf/pdfium/pdfium_api_string_buffer_adapter.h" #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
#include "pdf/pdfium/pdfium_document.h" #include "pdf/pdfium/pdfium_document.h"
#include "pdf/pdfium/pdfium_mem_buffer_file_read.h" #include "pdf/pdfium/pdfium_mem_buffer_file_read.h"
...@@ -3960,6 +3961,9 @@ void PDFiumEngine::LoadDocumentMetadata() { ...@@ -3960,6 +3961,9 @@ void PDFiumEngine::LoadDocumentMetadata() {
doc_metadata_.keywords = GetTrimmedMetadataByField("Keywords"); doc_metadata_.keywords = GetTrimmedMetadataByField("Keywords");
doc_metadata_.creator = GetTrimmedMetadataByField("Creator"); doc_metadata_.creator = GetTrimmedMetadataByField("Creator");
doc_metadata_.producer = GetTrimmedMetadataByField("Producer"); doc_metadata_.producer = GetTrimmedMetadataByField("Producer");
doc_metadata_.creation_date =
ParsePdfDate(GetTrimmedMetadataByField("CreationDate"));
doc_metadata_.mod_date = ParsePdfDate(GetTrimmedMetadataByField("ModDate"));
} }
std::string PDFiumEngine::GetTrimmedMetadataByField( std::string PDFiumEngine::GetTrimmedMetadataByField(
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/time/time.h"
#include "pdf/document_attachment_info.h" #include "pdf/document_attachment_info.h"
#include "pdf/document_layout.h" #include "pdf/document_layout.h"
#include "pdf/document_metadata.h" #include "pdf/document_metadata.h"
...@@ -356,6 +357,16 @@ TEST_F(PDFiumEngineTest, GetDocumentMetadata) { ...@@ -356,6 +357,16 @@ TEST_F(PDFiumEngineTest, GetDocumentMetadata) {
EXPECT_EQ("testing,chromium,pdfium,document,info", doc_metadata.keywords); EXPECT_EQ("testing,chromium,pdfium,document,info", doc_metadata.keywords);
EXPECT_EQ("Your Preferred Text Editor", doc_metadata.creator); EXPECT_EQ("Your Preferred Text Editor", doc_metadata.creator);
EXPECT_EQ("fixup_pdf_template.py", doc_metadata.producer); EXPECT_EQ("fixup_pdf_template.py", doc_metadata.producer);
base::Time expected_creation_date;
ASSERT_TRUE(base::Time::FromUTCString("2020-02-05 15:39:12",
&expected_creation_date));
EXPECT_EQ(expected_creation_date, doc_metadata.creation_date);
base::Time expected_mod_date;
ASSERT_TRUE(
base::Time::FromUTCString("2020-02-06 09:42:34", &expected_mod_date));
EXPECT_EQ(expected_mod_date, doc_metadata.mod_date);
} }
TEST_F(PDFiumEngineTest, GetEmptyDocumentMetadata) { TEST_F(PDFiumEngineTest, GetEmptyDocumentMetadata) {
...@@ -374,6 +385,8 @@ TEST_F(PDFiumEngineTest, GetEmptyDocumentMetadata) { ...@@ -374,6 +385,8 @@ TEST_F(PDFiumEngineTest, GetEmptyDocumentMetadata) {
EXPECT_THAT(doc_metadata.keywords, IsEmpty()); EXPECT_THAT(doc_metadata.keywords, IsEmpty());
EXPECT_THAT(doc_metadata.creator, IsEmpty()); EXPECT_THAT(doc_metadata.creator, IsEmpty());
EXPECT_THAT(doc_metadata.producer, IsEmpty()); EXPECT_THAT(doc_metadata.producer, IsEmpty());
EXPECT_TRUE(doc_metadata.creation_date.is_null());
EXPECT_TRUE(doc_metadata.mod_date.is_null());
} }
TEST_F(PDFiumEngineTest, GetLinearizedDocumentMetadata) { TEST_F(PDFiumEngineTest, GetLinearizedDocumentMetadata) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment