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) { ...@@ -918,7 +918,7 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionJSUpdatesEnabledTest, ViewerPdfSidenav) {
IN_PROC_BROWSER_TEST_F(PDFExtensionJSUpdatesEnabledTest, IN_PROC_BROWSER_TEST_F(PDFExtensionJSUpdatesEnabledTest,
ViewerPropertiesDialogTest) { 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) { IN_PROC_BROWSER_TEST_F(PDFExtensionJSUpdatesEnabledTest, ViewerThumbnailBar) {
......
...@@ -17,6 +17,18 @@ export const DisplayAnnotationsAction = { ...@@ -17,6 +17,18 @@ export const DisplayAnnotationsAction = {
HIDE_ANNOTATIONS: 'hide-annotations', 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. * Enumeration of page fitting types.
* @enum {string} * @enum {string}
......
...@@ -157,6 +157,7 @@ js_library("viewer-pen-options") { ...@@ -157,6 +157,7 @@ js_library("viewer-pen-options") {
js_library("viewer-properties-dialog") { js_library("viewer-properties-dialog") {
deps = [ deps = [
"..:constants",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled", "//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog.m", "//ui/webui/resources/cr_elements/cr_dialog:cr_dialog.m",
] ]
......
...@@ -46,15 +46,21 @@ ...@@ -46,15 +46,21 @@
</tr> </tr>
<tr> <tr>
<td class="name">$i18n{propertiesTitle}</td> <td class="name">$i18n{propertiesTitle}</td>
<td class="value" id="title">-</td> <td class="value" id="title">
[[getOrPlaceholder_(documentMetadata.title)]]
</td>
</tr> </tr>
<tr> <tr>
<td class="name">$i18n{propertiesAuthor}</td> <td class="name">$i18n{propertiesAuthor}</td>
<td class="value" id="author">-</td> <td class="value" id="author">
[[getOrPlaceholder_(documentMetadata.author)]]
</td>
</tr> </tr>
<tr> <tr>
<td class="name">$i18n{propertiesSubject}</td> <td class="name">$i18n{propertiesSubject}</td>
<td class="value" id="subject">-</td> <td class="value" id="subject">
[[getOrPlaceholder_(documentMetadata.subject)]]
</td>
</tr> </tr>
<tr> <tr>
<td class="name">$i18n{propertiesKeywords}</td> <td class="name">$i18n{propertiesKeywords}</td>
...@@ -70,11 +76,15 @@ ...@@ -70,11 +76,15 @@
</tr> </tr>
<tr class="break"> <tr class="break">
<td class="name">$i18n{propertiesApplication}</td> <td class="name">$i18n{propertiesApplication}</td>
<td class="value" id="application">-</td> <td class="value" id="application">
[[getOrPlaceholder_(documentMetadata.creator)]]
</td>
</tr> </tr>
<tr> <tr>
<td class="name">$i18n{propertiesPdfProducer}</td> <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>
<tr> <tr>
<td class="name">$i18n{propertiesPdfVersion}</td> <td class="name">$i18n{propertiesPdfVersion}</td>
......
...@@ -8,6 +8,8 @@ import 'chrome://resources/cr_elements/shared_vars_css.m.js'; ...@@ -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 {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {DocumentMetadata} from '../constants.js';
export class ViewerPropertiesDialogElement extends PolymerElement { export class ViewerPropertiesDialogElement extends PolymerElement {
static get is() { static get is() {
return 'viewer-properties-dialog'; return 'viewer-properties-dialog';
...@@ -17,6 +19,13 @@ export class ViewerPropertiesDialogElement extends PolymerElement { ...@@ -17,6 +19,13 @@ export class ViewerPropertiesDialogElement extends PolymerElement {
return html`{__html_template__}`; return html`{__html_template__}`;
} }
static get properties() {
return {
/** @type {!DocumentMetadata} */
documentMetadata: Object,
};
}
/** /**
* @return {!CrDialogElement} * @return {!CrDialogElement}
* @private * @private
...@@ -26,6 +35,15 @@ export class ViewerPropertiesDialogElement extends PolymerElement { ...@@ -26,6 +35,15 @@ export class ViewerPropertiesDialogElement extends PolymerElement {
this.shadowRoot.querySelector('cr-dialog')); this.shadowRoot.querySelector('cr-dialog'));
} }
/**
* @param {string} value
* @return {string}
* @private
*/
getOrPlaceholder_(value) {
return value || '-';
}
/** @private */ /** @private */
onClickClose_() { onClickClose_() {
this.getDialog_().close(); this.getDialog_().close();
......
...@@ -226,6 +226,7 @@ ...@@ -226,6 +226,7 @@
<template is="dom-if" if="[[showPropertiesDialog_]]" restamp> <template is="dom-if" if="[[showPropertiesDialog_]]" restamp>
<viewer-properties-dialog id="properties-dialog" <viewer-properties-dialog id="properties-dialog"
document-metadata="[[documentMetadata_]]"
on-close="onPropertiesDialogClose_"> on-close="onPropertiesDialogClose_">
</viewer-properties-dialog> </viewer-properties-dialog>
</template> </template>
......
...@@ -24,7 +24,7 @@ import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min. ...@@ -24,7 +24,7 @@ import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.
import {Bookmark} from './bookmark_type.js'; import {Bookmark} from './bookmark_type.js';
import {BrowserApi} from './browser_api.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 {PluginController} from './controller.js';
import {ViewerPdfSidenavElement} from './elements/viewer-pdf-sidenav.js'; import {ViewerPdfSidenavElement} from './elements/viewer-pdf-sidenav.js';
import {ViewerPdfToolbarNewElement} from './elements/viewer-pdf-toolbar-new.js'; import {ViewerPdfToolbarNewElement} from './elements/viewer-pdf-toolbar-new.js';
...@@ -62,15 +62,6 @@ let EmailMessageData; ...@@ -62,15 +62,6 @@ let EmailMessageData;
*/ */
let NavigateMessageData; let NavigateMessageData;
/**
* @typedef {{
* type: string,
* title: string,
* canSerializeDocument: boolean,
* }}
*/
let MetadataMessageData;
/** /**
* @typedef {{ * @typedef {{
* type: string, * type: string,
...@@ -184,6 +175,12 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -184,6 +175,12 @@ export class PDFViewerElement extends PDFViewerBaseElement {
value: false, value: false,
}, },
/** @private {!DocumentMetadata} */
documentMetadata_: {
type: Object,
value: () => {},
},
/** @private */ /** @private */
hadPassword_: { hadPassword_: {
type: Boolean, type: Boolean,
...@@ -940,7 +937,9 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -940,7 +937,9 @@ export class PDFViewerElement extends PDFViewerBaseElement {
destinationData.zoom); destinationData.zoom);
return; return;
case 'metadata': case 'metadata':
this.setDocumentMetadata_(/** @type {!MetadataMessageData} */ (data)); this.setDocumentMetadata_(
/** @type {{ metadataData: !DocumentMetadata }} */ (data)
.metadataData);
return; return;
case 'setIsEditing': case 'setIsEditing':
// Editing mode can only be entered once, and cannot be exited. // Editing mode can only be entered once, and cannot be exited.
...@@ -1056,13 +1055,15 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -1056,13 +1055,15 @@ export class PDFViewerElement extends PDFViewerBaseElement {
/** /**
* Sets document metadata from the current controller. * Sets document metadata from the current controller.
* @param {!MetadataMessageData} metadata * @param {!DocumentMetadata} metadata
* @private * @private
*/ */
setDocumentMetadata_(metadata) { setDocumentMetadata_(metadata) {
this.title_ = metadata.title || getFilenameFromURL(this.originalUrl); this.documentMetadata_ = metadata;
this.title_ =
this.documentMetadata_.title || getFilenameFromURL(this.originalUrl);
document.title = this.title_; 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() { ...@@ -33,10 +33,41 @@ function getPropertiesDialog() {
viewer.shadowRoot.querySelector('#properties-dialog')); 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 = [ const tests = [
async function testPropertiesDialog() { async function testPropertiesDialog() {
await ensurePropertiesDialogOpen(); 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(); await ensurePropertiesDialogClose();
chrome.test.succeed(); chrome.test.succeed();
}, },
]; ];
......
...@@ -129,7 +129,12 @@ constexpr char kJSBookmarksType[] = "bookmarks"; ...@@ -129,7 +129,12 @@ constexpr char kJSBookmarksType[] = "bookmarks";
constexpr char kJSBookmarksData[] = "bookmarksData"; constexpr char kJSBookmarksData[] = "bookmarksData";
// Metadata (Plugin -> Page) // Metadata (Plugin -> Page)
constexpr char kJSMetadataType[] = "metadata"; constexpr char kJSMetadataType[] = "metadata";
constexpr char kJSMetadataData[] = "metadataData";
constexpr char kJSTitle[] = "title"; constexpr char kJSTitle[] = "title";
constexpr char kJSAuthor[] = "author";
constexpr char kJSSubject[] = "subject";
constexpr char kJSCreator[] = "creator";
constexpr char kJSProducer[] = "producer";
constexpr char kJSCanSerializeDocument[] = "canSerializeDocument"; constexpr char kJSCanSerializeDocument[] = "canSerializeDocument";
// Get password (Plugin -> Page) // Get password (Plugin -> Page)
constexpr char kJSGetPasswordType[] = "getPassword"; constexpr char kJSGetPasswordType[] = "getPassword";
...@@ -2373,14 +2378,31 @@ void OutOfProcessInstance::SendMetadata() { ...@@ -2373,14 +2378,31 @@ void OutOfProcessInstance::SendMetadata() {
pp::VarDictionary metadata_message; pp::VarDictionary metadata_message;
metadata_message.Set(pp::Var(kType), pp::Var(kJSMetadataType)); metadata_message.Set(pp::Var(kType), pp::Var(kJSMetadataType));
const std::string& title = engine()->GetDocumentMetadata().title; const DocumentMetadata& document_metadata = engine()->GetDocumentMetadata();
if (!title.empty()) pp::VarDictionary metadata_data;
metadata_message.Set(pp::Var(kJSTitle), pp::Var(title));
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(kJSCanSerializeDocument),
pp::Var(IsSaveDataSizeValid(engine()->GetLoadedByteSize()))); pp::Var(IsSaveDataSizeValid(engine()->GetLoadedByteSize())));
metadata_message.Set(pp::Var(kJSMetadataData), metadata_data);
PostMessage(metadata_message); 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