0

pdf: Disable annotation if password protected or large

Bug: 902646
Change-Id: If6f594535a1d1cdff19e441d0995d1ef57e22885
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1504670
Commit-Queue: dstockwell <dstockwell@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638070}
This commit is contained in:
dstockwell
2019-03-06 10:55:26 +00:00
committed by Commit Bot
parent 995aa16339
commit 048aed00b9
2 changed files with 24 additions and 2 deletions
chrome/browser/resources/pdf
pdf

@ -136,6 +136,12 @@ function PDFViewer(browserApi) {
/** @private {boolean} */
this.hasEnteredAnnotationMode_ = false;
/** @private {boolean} */
this.hadPassword_ = false;
/** @private {boolean} */
this.canSerializeDocument_ = false;
PDFMetrics.record(PDFMetrics.UserAction.DOCUMENT_OPENED);
// Parse open pdf parameters.
@ -1074,6 +1080,8 @@ PDFViewer.prototype = {
// If the password screen isn't up, put it up. Otherwise we're
// responding to an incorrect password so deny it.
if (!this.passwordScreen_.active) {
this.hadPassword_ = true;
this.updateAnnotationAvailable_();
this.passwordScreen_.show();
} else {
this.passwordScreen_.deny();
@ -1119,8 +1127,9 @@ PDFViewer.prototype = {
* Sets document metadata from the current controller.
* @param {string} title
* @param {Array} bookmarks
* @param {boolean} canSerializeDocument
*/
setDocumentMetadata: function(title, bookmarks) {
setDocumentMetadata: function(title, bookmarks, canSerializeDocument) {
if (title) {
document.title = title;
} else {
@ -1131,6 +1140,8 @@ PDFViewer.prototype = {
this.toolbar_.docTitle = document.title;
this.toolbar_.bookmarks = this.bookmarks;
}
this.canSerializeDocument_ = canSerializeDocument;
this.updateAnnotationAvailable_();
},
/**
@ -1227,6 +1238,12 @@ PDFViewer.prototype = {
if (this.viewport_.getClockwiseRotations() != 0) {
annotationAvailable = false;
}
if (this.hadPassword_) {
annotationAvailable = false;
}
if (!this.canSerializeDocument_) {
annotationAvailable = false;
}
this.toolbar_.annotationAvailable = annotationAvailable;
},
@ -1563,7 +1580,8 @@ class PluginController extends ContentController {
break;
case 'metadata':
this.viewer_.setDocumentMetadata(
message.data.title, message.data.bookmarks);
message.data.title, message.data.bookmarks,
message.data.canSerializeDocument);
break;
case 'setIsSelecting':
this.viewer_.setIsSelecting(message.data.isSelecting);

@ -91,6 +91,7 @@ constexpr char kJSPreviewLoadedType[] = "printPreviewLoaded";
constexpr char kJSMetadataType[] = "metadata";
constexpr char kJSBookmarks[] = "bookmarks";
constexpr char kJSTitle[] = "title";
constexpr char kJSCanSerializeDocument[] = "canSerializeDocument";
// Get password (Plugin -> Page)
constexpr char kJSGetPasswordType[] = "getPassword";
// Get password complete arguments (Page -> Plugin)
@ -1654,6 +1655,9 @@ void OutOfProcessInstance::DocumentLoadComplete(
metadata_message.Set(pp::Var(kJSTitle), pp::Var(title));
HistogramEnumeration("PDF.DocumentFeature", HAS_TITLE, FEATURES_COUNT);
}
metadata_message.Set(
pp::Var(kJSCanSerializeDocument),
pp::Var(engine_->GetLoadedByteSize() <= kMaximumSavedFileSize));
pp::VarArray bookmarks = engine_->GetBookmarks();
metadata_message.Set(pp::Var(kJSBookmarks), bookmarks);