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

PDF Viewer Update: Show some basic properties

Setup the frontend pipeline for showing document properties and show
some basic ones for now, including:
- Title
- Author
- Subject
- Application
- PDF Producer

Reshape the 'metadata' message to have a `DocumentMetadata` object in
its 'metadataData' field, which can be directly passed to the
`ViewerPropertiesDialogElement` without further processing on the
frontend.

Bug: 93619
Change-Id: Iffb8691f443781a700fc06a439506dd546f46865
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2610048
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841726}
parent 22380783
......@@ -918,7 +918,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionJSUpdatesEnabledTest, ViewerPdfSidenav) {
IN_PROC_BROWSER_TEST_F(PDFExtensionJSUpdatesEnabledTest,
ViewerPropertiesDialogTest) {
RunTestsInJsModule("viewer_properties_dialog_test.js", "test.pdf");
RunTestsInJsModule("viewer_properties_dialog_test.js", "document_info.pdf");
}
IN_PROC_BROWSER_TEST_F(PDFExtensionJSUpdatesEnabledTest, ViewerThumbnailBar) {
......
......@@ -17,6 +17,18 @@ export const DisplayAnnotationsAction = {
HIDE_ANNOTATIONS: 'hide-annotations',
};
/**
* @typedef {{
* title: string,
* author: string,
* subject: string,
* creator: string,
* producer: string,
* canSerializeDocument: boolean,
* }}
*/
export let DocumentMetadata;
/**
* Enumeration of page fitting types.
* @enum {string}
......
......@@ -157,6 +157,7 @@ js_library("viewer-pen-options") {
js_library("viewer-properties-dialog") {
deps = [
"..:constants",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog.m",
]
......
......@@ -46,15 +46,21 @@
</tr>
<tr>
<td class="name">$i18n{propertiesTitle}</td>
<td class="value" id="title">-</td>
<td class="value" id="title">
[[getOrPlaceholder_(documentMetadata.title)]]
</td>
</tr>
<tr>
<td class="name">$i18n{propertiesAuthor}</td>
<td class="value" id="author">-</td>
<td class="value" id="author">
[[getOrPlaceholder_(documentMetadata.author)]]
</td>
</tr>
<tr>
<td class="name">$i18n{propertiesSubject}</td>
<td class="value" id="subject">-</td>
<td class="value" id="subject">
[[getOrPlaceholder_(documentMetadata.subject)]]
</td>
</tr>
<tr>
<td class="name">$i18n{propertiesKeywords}</td>
......@@ -70,11 +76,15 @@
</tr>
<tr class="break">
<td class="name">$i18n{propertiesApplication}</td>
<td class="value" id="application">-</td>
<td class="value" id="application">
[[getOrPlaceholder_(documentMetadata.creator)]]
</td>
</tr>
<tr>
<td class="name">$i18n{propertiesPdfProducer}</td>
<td class="value" id="pdf-producer">-</td>
<td class="value" id="pdf-producer">
[[getOrPlaceholder_(documentMetadata.producer)]]
</td>
</tr>
<tr>
<td class="name">$i18n{propertiesPdfVersion}</td>
......
......@@ -8,6 +8,8 @@ import 'chrome://resources/cr_elements/shared_vars_css.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {DocumentMetadata} from '../constants.js';
export class ViewerPropertiesDialogElement extends PolymerElement {
static get is() {
return 'viewer-properties-dialog';
......@@ -17,6 +19,13 @@ export class ViewerPropertiesDialogElement extends PolymerElement {
return html`{__html_template__}`;
}
static get properties() {
return {
/** @type {!DocumentMetadata} */
documentMetadata: Object,
};
}
/**
* @return {!CrDialogElement}
* @private
......@@ -26,6 +35,15 @@ export class ViewerPropertiesDialogElement extends PolymerElement {
this.shadowRoot.querySelector('cr-dialog'));
}
/**
* @param {string} value
* @return {string}
* @private
*/
getOrPlaceholder_(value) {
return value || '-';
}
/** @private */
onClickClose_() {
this.getDialog_().close();
......
......@@ -226,6 +226,7 @@
<template is="dom-if" if="[[showPropertiesDialog_]]" restamp>
<viewer-properties-dialog id="properties-dialog"
document-metadata="[[documentMetadata_]]"
on-close="onPropertiesDialogClose_">
</viewer-properties-dialog>
</template>
......
......@@ -24,7 +24,7 @@ import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.
import {Bookmark} from './bookmark_type.js';
import {BrowserApi} from './browser_api.js';
import {Attachment, FittingType, Point, SaveRequestType} from './constants.js';
import {Attachment, DocumentMetadata, FittingType, Point, SaveRequestType} from './constants.js';
import {PluginController} from './controller.js';
import {ViewerPdfSidenavElement} from './elements/viewer-pdf-sidenav.js';
import {ViewerPdfToolbarNewElement} from './elements/viewer-pdf-toolbar-new.js';
......@@ -62,15 +62,6 @@ let EmailMessageData;
*/
let NavigateMessageData;
/**
* @typedef {{
* type: string,
* title: string,
* canSerializeDocument: boolean,
* }}
*/
let MetadataMessageData;
/**
* @typedef {{
* type: string,
......@@ -184,6 +175,12 @@ export class PDFViewerElement extends PDFViewerBaseElement {
value: false,
},
/** @private {!DocumentMetadata} */
documentMetadata_: {
type: Object,
value: () => {},
},
/** @private */
hadPassword_: {
type: Boolean,
......@@ -940,7 +937,9 @@ export class PDFViewerElement extends PDFViewerBaseElement {
destinationData.zoom);
return;
case 'metadata':
this.setDocumentMetadata_(/** @type {!MetadataMessageData} */ (data));
this.setDocumentMetadata_(
/** @type {{ metadataData: !DocumentMetadata }} */ (data)
.metadataData);
return;
case 'setIsEditing':
// Editing mode can only be entered once, and cannot be exited.
......@@ -1056,13 +1055,15 @@ export class PDFViewerElement extends PDFViewerBaseElement {
/**
* Sets document metadata from the current controller.
* @param {!MetadataMessageData} metadata
* @param {!DocumentMetadata} metadata
* @private
*/
setDocumentMetadata_(metadata) {
this.title_ = metadata.title || getFilenameFromURL(this.originalUrl);
this.documentMetadata_ = metadata;
this.title_ =
this.documentMetadata_.title || getFilenameFromURL(this.originalUrl);
document.title = this.title_;
this.canSerializeDocument_ = metadata.canSerializeDocument;
this.canSerializeDocument_ = this.documentMetadata_.canSerializeDocument;
}
/**
......
{{header}}
{{object 1 0}} <<
/Type /Catalog
/Pages 2 0 R
>>
endobj
{{object 2 0}} <<
/Type /Pages
/MediaBox [ 0 0 200 200 ]
/Count 1
/Kids [ 3 0 R ]
>>
endobj
{{object 3 0}} <<
/Type /Page
/Parent 2 0 R
>>
endobj
{{object 4 0}} <<
/Author (Chromium Authors)
/CreationDate (D:20200205153912+00'00' )
/Creator (Your Preferred Text Editor)
/Keywords (testing,chromium,pdfium,document,info)
/ModDate (D:20200206094234+00'00')
/Producer (fixup_pdf_template.py)
/Subject (Testing)
/Title ( Sample PDF Document Info )
>>
endobj
{{xref}}
trailer <<
/Info 4 0 R
/Root 1 0 R
{{trailersize}}
>>
{{startxref}}
%%EOF
This diff was suppressed by a .gitattributes entry.
......@@ -33,10 +33,41 @@ function getPropertiesDialog() {
viewer.shadowRoot.querySelector('#properties-dialog'));
}
/**
* @param {string} field
* @param {string} expectedValue
*/
function assertField(field, expectedValue) {
const actualValue = getPropertiesDialog()
.shadowRoot.querySelector(`#${field}`)
.textContent.trim();
chrome.test.assertEq(expectedValue, actualValue);
}
const tests = [
async function testPropertiesDialog() {
await ensurePropertiesDialogOpen();
// TODO(crbug.com/93169): None of the following expected values should be
// '-' when support for every property is implemented.
[['file-name', '-'],
['file-size', '-'],
['title', 'Sample PDF Document Info'],
['author', 'Chromium Authors'],
['subject', 'Testing'],
['keywords', '-'],
['created', '-'],
['modified', '-'],
['application', 'Your Preferred Text Editor'],
['pdf-producer', 'fixup_pdf_template.py'],
['pdf-version', '-'],
['page-count', '-'],
['page-size', '-'],
['fast-web-view', '-'],
].forEach(([field, expectedValue]) => assertField(field, expectedValue));
await ensurePropertiesDialogClose();
chrome.test.succeed();
},
];
......
......@@ -129,7 +129,12 @@ constexpr char kJSBookmarksType[] = "bookmarks";
constexpr char kJSBookmarksData[] = "bookmarksData";
// Metadata (Plugin -> Page)
constexpr char kJSMetadataType[] = "metadata";
constexpr char kJSMetadataData[] = "metadataData";
constexpr char kJSTitle[] = "title";
constexpr char kJSAuthor[] = "author";
constexpr char kJSSubject[] = "subject";
constexpr char kJSCreator[] = "creator";
constexpr char kJSProducer[] = "producer";
constexpr char kJSCanSerializeDocument[] = "canSerializeDocument";
// Get password (Plugin -> Page)
constexpr char kJSGetPasswordType[] = "getPassword";
......@@ -2373,14 +2378,31 @@ void OutOfProcessInstance::SendMetadata() {
pp::VarDictionary metadata_message;
metadata_message.Set(pp::Var(kType), pp::Var(kJSMetadataType));
const std::string& title = engine()->GetDocumentMetadata().title;
if (!title.empty())
metadata_message.Set(pp::Var(kJSTitle), pp::Var(title));
const DocumentMetadata& document_metadata = engine()->GetDocumentMetadata();
pp::VarDictionary metadata_data;
metadata_message.Set(
if (!document_metadata.title.empty())
metadata_data.Set(pp::Var(kJSTitle), pp::Var(document_metadata.title));
if (!document_metadata.author.empty())
metadata_data.Set(pp::Var(kJSAuthor), pp::Var(document_metadata.author));
if (!document_metadata.subject.empty())
metadata_data.Set(pp::Var(kJSSubject), pp::Var(document_metadata.subject));
if (!document_metadata.creator.empty())
metadata_data.Set(pp::Var(kJSCreator), pp::Var(document_metadata.creator));
if (!document_metadata.producer.empty()) {
metadata_data.Set(pp::Var(kJSProducer),
pp::Var(document_metadata.producer));
}
metadata_data.Set(
pp::Var(kJSCanSerializeDocument),
pp::Var(IsSaveDataSizeValid(engine()->GetLoadedByteSize())));
metadata_message.Set(pp::Var(kJSMetadataData), metadata_data);
PostMessage(metadata_message);
}
......
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