Display warning when PDF signals an attempt to save
This CL adds a warning dialogue that is shown when a signal via SaveCalled is received. Currently this signal is only wired up for app.execMenuItem("SaveAs") in XFA JS, but will be added in other locations where saving is attempted. Once saving of PDFs is fully implemented this warning can be removed. BUG=pdfium:953,chromium:61248 Cq-Include-Trybots: luci.chromium.try:closure_compilation Change-Id: Ib89c394a07459692ee1302ea97f7b0b291b42b92 Reviewed-on: https://chromium-review.googlesource.com/1115205 Reviewed-by: Jochen Eisinger <jochen@chromium.org> Reviewed-by: Rebekah Potter <rbpotter@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org> Cr-Commit-Position: refs/heads/master@{#576920}
This commit is contained in:

committed by
Commit Bot

parent
230f4f9918
commit
277b7985fa
chrome/browser
extensions
api
resources_private
resources
components
pdf
@ -45,6 +45,9 @@ void AddStringsForPdf(base::DictionaryValue* dict) {
|
||||
SetL10nString(dict, "pageReload", IDS_PDF_PAGE_RELOAD_BUTTON);
|
||||
SetL10nString(dict, "bookmarks", IDS_PDF_BOOKMARKS);
|
||||
SetL10nString(dict, "labelPageNumber", IDS_PDF_LABEL_PAGE_NUMBER);
|
||||
SetL10nString(dict, "saveCalledTitle", IDS_PDF_SAVE_CALLED_TITLE);
|
||||
SetL10nString(dict, "saveCalledText", IDS_PDF_SAVE_CALLED_TEXT);
|
||||
SetL10nString(dict, "saveCalledButton", IDS_OK);
|
||||
SetL10nString(dict, "tooltipRotateCW", IDS_PDF_TOOLTIP_ROTATE_CW);
|
||||
SetL10nString(dict, "tooltipDownload", IDS_PDF_TOOLTIP_DOWNLOAD);
|
||||
SetL10nString(dict, "tooltipPrint", IDS_PDF_TOOLTIP_PRINT);
|
||||
|
@ -126,6 +126,8 @@
|
||||
<include name="IDR_PDF_VIEWER_PASSWORD_SCREEN_JS" file="pdf/elements/viewer-password-screen/viewer-password-screen.js" type="BINDATA" />
|
||||
<include name="IDR_PDF_VIEWER_PDF_TOOLBAR_HTML" file="pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.html" type="BINDATA" />
|
||||
<include name="IDR_PDF_VIEWER_PDF_TOOLBAR_JS" file="pdf/elements/viewer-pdf-toolbar/viewer-pdf-toolbar.js" type="BINDATA" />
|
||||
<include name="IDR_PDF_VIEWER_SAVE_CALLED_HTML" file="pdf/elements/viewer-save-called-screen/viewer-save-called-screen.html" type="BINDATA" />
|
||||
<include name="IDR_PDF_VIEWER_SAVE_CALLED_JS" file="pdf/elements/viewer-save-called-screen/viewer-save-called-screen.js" type="BINDATA" />
|
||||
<include name="IDR_PDF_VIEWER_TOOLBAR_DROPDOWN_HTML" file="pdf/elements/viewer-toolbar-dropdown/viewer-toolbar-dropdown.html" type="BINDATA" />
|
||||
<include name="IDR_PDF_VIEWER_TOOLBAR_DROPDOWN_JS" file="pdf/elements/viewer-toolbar-dropdown/viewer-toolbar-dropdown.js" type="BINDATA" />
|
||||
<include name="IDR_PDF_VIEWER_ZOOM_BUTTON_HTML" file="pdf/elements/viewer-zoom-toolbar/viewer-zoom-button.html" type="BINDATA" />
|
||||
|
@ -13,6 +13,7 @@ group("closure_compile") {
|
||||
"elements/viewer-page-indicator:closure_compile",
|
||||
"elements/viewer-page-selector:closure_compile",
|
||||
"elements/viewer-password-screen:closure_compile",
|
||||
"elements/viewer-save-called-screen:closure_compile",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
# Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//third_party/closure_compiler/compile_js.gni")
|
||||
|
||||
js_type_check("closure_compile") {
|
||||
deps = [
|
||||
":viewer-save-called-screen",
|
||||
]
|
||||
}
|
||||
|
||||
js_library("viewer-save-called-screen") {
|
||||
deps = [
|
||||
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
|
||||
]
|
||||
}
|
21
chrome/browser/resources/pdf/elements/viewer-save-called-screen/viewer-save-called-screen.html
Normal file
21
chrome/browser/resources/pdf/elements/viewer-save-called-screen/viewer-save-called-screen.html
Normal file
@ -0,0 +1,21 @@
|
||||
<link rel="import" href="chrome://resources/html/polymer.html">
|
||||
|
||||
<link rel="import" href="chrome://resources/cr_elements/cr_dialog/cr_dialog.html">
|
||||
<link rel="import" href="chrome://resources/cr_elements/paper_button_style_css.html">
|
||||
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
|
||||
|
||||
<dom-module id="viewer-save-called-screen">
|
||||
<template>
|
||||
<style include="paper-button-style"></style>
|
||||
<cr-dialog id="dialog" no-cancel>
|
||||
<div slot="title">[[strings.saveCalledTitle]]</div>
|
||||
<div slot="body">[[strings.saveCalledText]]</div>
|
||||
<div slot="button-container">
|
||||
<paper-button class="action-button" on-click="dismiss_">
|
||||
[[strings.saveCalledButton]]
|
||||
</paper-button>
|
||||
</div>
|
||||
</cr-dialog>
|
||||
</template>
|
||||
<script src="viewer-save-called-screen.js"></script>
|
||||
</dom-module>
|
20
chrome/browser/resources/pdf/elements/viewer-save-called-screen/viewer-save-called-screen.js
Normal file
20
chrome/browser/resources/pdf/elements/viewer-save-called-screen/viewer-save-called-screen.js
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
Polymer({
|
||||
is: 'viewer-save-called-screen',
|
||||
|
||||
properties: {
|
||||
strings: Object,
|
||||
},
|
||||
|
||||
show: function() {
|
||||
this.$.dialog.showModal();
|
||||
},
|
||||
|
||||
/** @private */
|
||||
dismiss_: function() {
|
||||
this.$.dialog.close();
|
||||
},
|
||||
});
|
@ -7,6 +7,7 @@
|
||||
<link rel="import" href="elements/viewer-page-selector/viewer-page-selector.html">
|
||||
<link rel="import" href="elements/viewer-password-screen/viewer-password-screen.html">
|
||||
<link rel="import" href="elements/viewer-pdf-toolbar/viewer-pdf-toolbar.html">
|
||||
<link rel="import" href="elements/viewer-save-called-screen/viewer-save-called-screen.html">
|
||||
<link rel="import" href="elements/viewer-zoom-toolbar/viewer-zoom-toolbar.html">
|
||||
<link rel="import" href="elements/shared-vars.html">
|
||||
|
||||
@ -26,6 +27,8 @@
|
||||
|
||||
<viewer-error-screen id="error-screen"></viewer-error-screen>
|
||||
|
||||
<viewer-save-called-screen id="save-called-screen"></viewer-save-called-screen>
|
||||
|
||||
</body>
|
||||
<script src="pdf_fitting_type.js"></script>
|
||||
<script src="toolbar_manager.js"></script>
|
||||
|
@ -629,6 +629,7 @@ PDFViewer.prototype = {
|
||||
$('zoom-toolbar').strings = strings;
|
||||
$('password-screen').strings = strings;
|
||||
$('error-screen').strings = strings;
|
||||
$('save-called-screen').strings = strings;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -761,6 +762,9 @@ PDFViewer.prototype = {
|
||||
case 'transformPagePointReply':
|
||||
this.coordsTransformer_.onReplyReceived(message);
|
||||
break;
|
||||
case 'saveCalled':
|
||||
$('save-called-screen').show();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -60,5 +60,12 @@
|
||||
=1 {Page 1}
|
||||
other {Page #}}
|
||||
</message>
|
||||
<message name="IDS_PDF_SAVE_CALLED_TITLE" desc="Title of the dialog which shows a message warning the user that saving documents directly is not implemented.">
|
||||
Warning
|
||||
</message>
|
||||
<message name="IDS_PDF_SAVE_CALLED_TEXT"
|
||||
desc="Contents of the dialog shown when a save operation is attempted in the PDF viewer. Indicates to the user that the operation is not currently implemented and that they will need to print the PDF and use 'Save as PDF' to create a new PDF with their data.">
|
||||
Saving content entered into PDF forms is currently not supported. Please print the PDF and use the 'Save as PDF' destination to create a new PDF with the entered data.
|
||||
</message>
|
||||
</if>
|
||||
</grit-part>
|
||||
|
@ -162,6 +162,9 @@ const char kJSIsEditMode[] = "isEditMode";
|
||||
const char kJSFieldFocusType[] = "formFocusChange";
|
||||
const char kJSFieldFocus[] = "focused";
|
||||
|
||||
// Notify when a save attempt has occured (Plugin -> Page)
|
||||
const char kJSSaveCalledType[] = "saveCalled";
|
||||
|
||||
const int kFindResultCooldownMs = 100;
|
||||
|
||||
// Same value as printing::COMPLETE_PREVIEW_DOCUMENT_INDEX.
|
||||
@ -1908,6 +1911,12 @@ float OutOfProcessInstance::GetToolbarHeightInScreenCoords() {
|
||||
return top_toolbar_height_in_viewport_coords_ * device_scale_;
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::SaveCalled() {
|
||||
pp::VarDictionary message;
|
||||
message.Set(pp::Var(kType), pp::Var(kJSSaveCalledType));
|
||||
PostMessage(message);
|
||||
}
|
||||
|
||||
void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url,
|
||||
int dest_page_index) {
|
||||
DCHECK(IsPrintPreview());
|
||||
|
@ -152,6 +152,7 @@ class OutOfProcessInstance : public pp::Instance,
|
||||
void SelectionChanged(const pp::Rect& left, const pp::Rect& right) override;
|
||||
void IsEditModeChanged(bool is_edit_mode) override;
|
||||
float GetToolbarHeightInScreenCoords() override;
|
||||
void SaveCalled() override;
|
||||
|
||||
// PreviewModeClient::Client implementation.
|
||||
void PreviewDocumentLoadComplete() override;
|
||||
|
@ -275,6 +275,9 @@ class PDFEngine {
|
||||
// Gets the height of the top toolbar in screen coordinates. This is
|
||||
// independent of whether it is hidden or not at the moment.
|
||||
virtual float GetToolbarHeightInScreenCoords() = 0;
|
||||
|
||||
// Notifies the client that there was an attempt to save the document
|
||||
virtual void SaveCalled() {}
|
||||
};
|
||||
|
||||
// Factory method to create an instance of the PDF Engine.
|
||||
|
@ -2703,6 +2703,7 @@ void PDFiumEngine::LoadForm() {
|
||||
if (document_->form_status() != PDF_FORM_NOTAVAIL ||
|
||||
doc_loader_->IsDocumentComplete()) {
|
||||
document_->InitializeForm(&form_filler_);
|
||||
form_filler_.RegisterSaveCalledHandler();
|
||||
#if defined(PDF_ENABLE_XFA)
|
||||
FPDF_LoadXFA(doc());
|
||||
#endif
|
||||
|
@ -82,6 +82,10 @@ PDFiumFormFiller::PDFiumFormFiller(PDFiumEngine* engine, bool enable_javascript)
|
||||
|
||||
PDFiumFormFiller::~PDFiumFormFiller() = default;
|
||||
|
||||
void PDFiumFormFiller::RegisterSaveCalledHandler() {
|
||||
FORM_SetSaveCallback(engine_->form(), PDFiumFormFiller::Form_SaveCalled);
|
||||
}
|
||||
|
||||
// static
|
||||
void PDFiumFormFiller::Form_Invalidate(FPDF_FORMFILLINFO* param,
|
||||
FPDF_PAGE page,
|
||||
@ -267,6 +271,11 @@ void PDFiumFormFiller::Form_DoGoToAction(FPDF_FORMFILLINFO* param,
|
||||
engine->ScrollToPage(page_index);
|
||||
}
|
||||
|
||||
// static
|
||||
void PDFiumFormFiller::Form_SaveCalled(FPDF_FORMFILLINFO* param) {
|
||||
GetEngine(param)->client_->SaveCalled();
|
||||
}
|
||||
|
||||
#if defined(PDF_ENABLE_XFA)
|
||||
|
||||
// static
|
||||
|
@ -22,6 +22,8 @@ class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
|
||||
PDFiumFormFiller(PDFiumEngine* engine, bool enable_javascript);
|
||||
~PDFiumFormFiller();
|
||||
|
||||
void RegisterSaveCalledHandler();
|
||||
|
||||
private:
|
||||
// FPDF_FORMFILLINFO callbacks.
|
||||
static void Form_Invalidate(FPDF_FORMFILLINFO* param,
|
||||
@ -61,6 +63,7 @@ class PDFiumFormFiller : public FPDF_FORMFILLINFO, public IPDF_JSPLATFORM {
|
||||
int zoom_mode,
|
||||
float* position_array,
|
||||
int size_of_array);
|
||||
static void Form_SaveCalled(FPDF_FORMFILLINFO* param);
|
||||
|
||||
#if defined(PDF_ENABLE_XFA)
|
||||
static void Form_EmailTo(FPDF_FORMFILLINFO* param,
|
||||
|
Reference in New Issue
Block a user