Commit dffec593 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Verify the "pdf-form-save" is enabled in the saveData_() JS handler.

Aside from adding the sanity check, this also hooks up loadTimeData in
pdf_viewer.js, and demonstrates how to plumb a feature flag from the
browser into pdf_viewer.js.

BUG=61248

Change-Id: I48850afaac17854af785d04a8ca93078ebd8532f
Reviewed-on: https://chromium-review.googlesource.com/c/1339244Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608890}
parent 14161095
...@@ -9,6 +9,7 @@ import("//chrome/common/features.gni") ...@@ -9,6 +9,7 @@ import("//chrome/common/features.gni")
import("//components/nacl/features.gni") import("//components/nacl/features.gni")
import("//extensions/buildflags/buildflags.gni") import("//extensions/buildflags/buildflags.gni")
import("//mojo/public/tools/bindings/mojom.gni") import("//mojo/public/tools/bindings/mojom.gni")
import("//pdf/features.gni")
import("//rlz/buildflags/buildflags.gni") import("//rlz/buildflags/buildflags.gni")
assert(enable_extensions) assert(enable_extensions)
...@@ -1102,6 +1103,13 @@ jumbo_static_library("extensions") { ...@@ -1102,6 +1103,13 @@ jumbo_static_library("extensions") {
] ]
} }
if (enable_pdf) {
deps += [
"//pdf:buildflags",
"//pdf:features",
]
}
if (enable_rlz_support) { if (enable_rlz_support) {
deps += [ "//rlz:rlz_lib" ] deps += [ "//rlz:rlz_lib" ]
} }
......
...@@ -12,9 +12,14 @@ ...@@ -12,9 +12,14 @@
#include "chrome/common/extensions/api/resources_private.h" #include "chrome/common/extensions/api/resources_private.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "pdf/buildflags.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/webui/web_ui_util.h" #include "ui/base/webui/web_ui_util.h"
#if BUILDFLAG(ENABLE_PDF)
#include "pdf/pdf_features.h"
#endif
// To add a new component to this API, simply: // To add a new component to this API, simply:
// 1. Add your component to the Component enum in // 1. Add your component to the Component enum in
// chrome/common/extensions/api/resources_private.idl // chrome/common/extensions/api/resources_private.idl
...@@ -54,6 +59,14 @@ void AddStringsForPdf(base::DictionaryValue* dict) { ...@@ -54,6 +59,14 @@ void AddStringsForPdf(base::DictionaryValue* dict) {
SetL10nString(dict, "tooltipZoomOut", IDS_PDF_TOOLTIP_ZOOM_OUT); SetL10nString(dict, "tooltipZoomOut", IDS_PDF_TOOLTIP_ZOOM_OUT);
} }
void AddAdditionalDataForPdf(base::DictionaryValue* dict) {
#if BUILDFLAG(ENABLE_PDF)
dict->SetKey("pdfFormSaveEnabled",
base::Value(base::FeatureList::IsEnabled(
chrome_pdf::features::kSaveEditedPDFForm)));
#endif
}
} // namespace } // namespace
namespace get_strings = api::resources_private::GetStrings; namespace get_strings = api::resources_private::GetStrings;
...@@ -65,7 +78,7 @@ ResourcesPrivateGetStringsFunction::~ResourcesPrivateGetStringsFunction() {} ...@@ -65,7 +78,7 @@ ResourcesPrivateGetStringsFunction::~ResourcesPrivateGetStringsFunction() {}
ExtensionFunction::ResponseAction ResourcesPrivateGetStringsFunction::Run() { ExtensionFunction::ResponseAction ResourcesPrivateGetStringsFunction::Run() {
std::unique_ptr<get_strings::Params> params( std::unique_ptr<get_strings::Params> params(
get_strings::Params::Create(*args_)); get_strings::Params::Create(*args_));
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); auto dict = std::make_unique<base::DictionaryValue>();
api::resources_private::Component component = params->component; api::resources_private::Component component = params->component;
...@@ -75,6 +88,7 @@ ExtensionFunction::ResponseAction ResourcesPrivateGetStringsFunction::Run() { ...@@ -75,6 +88,7 @@ ExtensionFunction::ResponseAction ResourcesPrivateGetStringsFunction::Run() {
break; break;
case api::resources_private::COMPONENT_PDF: case api::resources_private::COMPONENT_PDF:
AddStringsForPdf(dict.get()); AddStringsForPdf(dict.get());
AddAdditionalDataForPdf(dict.get());
break; break;
case api::resources_private::COMPONENT_NONE: case api::resources_private::COMPONENT_NONE:
NOTREACHED(); NOTREACHED();
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
<script src="zoom_manager.js"></script> <script src="zoom_manager.js"></script>
<script src="gesture_detector.js"></script> <script src="gesture_detector.js"></script>
<script src="pdf_scripting_api.js"></script> <script src="pdf_scripting_api.js"></script>
<script src="chrome://resources/js/load_time_data.js"></script>
<script src="chrome://resources/js/util.js"></script> <script src="chrome://resources/js/util.js"></script>
<script src="browser_api.js"></script> <script src="browser_api.js"></script>
<script src="coords_transformer.js"></script> <script src="coords_transformer.js"></script>
......
...@@ -652,6 +652,7 @@ PDFViewer.prototype = { ...@@ -652,6 +652,7 @@ PDFViewer.prototype = {
document.documentElement.dir = strings.textdirection; document.documentElement.dir = strings.textdirection;
document.documentElement.lang = strings.language; document.documentElement.lang = strings.language;
loadTimeData.data = strings;
$('toolbar').strings = strings; $('toolbar').strings = strings;
$('zoom-toolbar').strings = strings; $('zoom-toolbar').strings = strings;
$('password-screen').strings = strings; $('password-screen').strings = strings;
...@@ -798,6 +799,9 @@ PDFViewer.prototype = { ...@@ -798,6 +799,9 @@ PDFViewer.prototype = {
* @private * @private
*/ */
saveData_: function(messageData) { saveData_: function(messageData) {
if (!loadTimeData.getBoolean('pdfFormSaveEnabled'))
throw new Error('Internal error: save not enabled.');
// Verify a token that was created by this instance is included to avoid // Verify a token that was created by this instance is included to avoid
// being spammed. // being spammed.
if (!this.pendingTokens_.delete(messageData.token)) if (!this.pendingTokens_.delete(messageData.token))
......
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