fix: pdf viewer template strings (#24913)

This commit is contained in:
Shelley Vohr 2020-08-10 22:46:58 -07:00 committed by GitHub
parent 47d451ae52
commit 7ded768743
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View file

@ -55,6 +55,7 @@ template("electron_extra_paks") {
output = "${invoker.output_dir}/resources.pak" output = "${invoker.output_dir}/resources.pak"
sources = [ sources = [
"$root_gen_dir/chrome/dev_ui_browser_resources.pak", "$root_gen_dir/chrome/dev_ui_browser_resources.pak",
"$root_gen_dir/chrome/print_preview_pdf_resources.pak",
"$root_gen_dir/components/components_resources.pak", "$root_gen_dir/components/components_resources.pak",
"$root_gen_dir/content/browser/resources/media/media_internals_resources.pak", "$root_gen_dir/content/browser/resources/media/media_internals_resources.pak",
"$root_gen_dir/content/browser/tracing/tracing_resources.pak", "$root_gen_dir/content/browser/tracing/tracing_resources.pak",
@ -70,6 +71,7 @@ template("electron_extra_paks") {
] ]
deps = [ deps = [
"//chrome/browser:dev_ui_browser_resources", "//chrome/browser:dev_ui_browser_resources",
"//chrome/browser/resources:print_preview_pdf_resources",
"//components/resources", "//components/resources",
"//content:content_resources", "//content:content_resources",
"//content:dev_ui_content_resources", "//content:dev_ui_content_resources",

View file

@ -209,7 +209,7 @@ void CommonWebContentsDelegate::InitWithWebContents(
web_contents, std::make_unique<ElectronPDFWebContentsHelperClient>()); web_contents, std::make_unique<ElectronPDFWebContentsHelperClient>());
#endif #endif
// Determien whether the WebContents is offscreen. // Determine whether the WebContents is offscreen.
auto* web_preferences = WebContentsPreferences::From(web_contents); auto* web_preferences = WebContentsPreferences::From(web_contents);
offscreen_ = offscreen_ =
web_preferences && web_preferences->IsEnabled(options::kOffscreen); web_preferences && web_preferences->IsEnabled(options::kOffscreen);

View file

@ -5,6 +5,7 @@
#include "shell/browser/extensions/electron_component_extension_resource_manager.h" #include "shell/browser/extensions/electron_component_extension_resource_manager.h"
#include <string> #include <string>
#include <utility>
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
@ -13,6 +14,12 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/grit/component_extension_resources_map.h" #include "chrome/grit/component_extension_resources_map.h"
#include "electron/buildflags/buildflags.h"
#if BUILDFLAG(ENABLE_PDF_VIEWER)
#include "chrome/browser/pdf/pdf_extension_util.h"
#include "extensions/common/constants.h"
#endif
namespace extensions { namespace extensions {
@ -20,6 +27,19 @@ ElectronComponentExtensionResourceManager::
ElectronComponentExtensionResourceManager() { ElectronComponentExtensionResourceManager() {
AddComponentResourceEntries(kComponentExtensionResources, AddComponentResourceEntries(kComponentExtensionResources,
kComponentExtensionResourcesSize); kComponentExtensionResourcesSize);
#if BUILDFLAG(ENABLE_PDF_VIEWER)
// Register strings for the PDF viewer, so that $i18n{} replacements work.
base::Value pdf_strings(base::Value::Type::DICTIONARY);
pdf_extension_util::AddStrings(
pdf_extension_util::PdfViewerContext::kPdfViewer, &pdf_strings);
pdf_extension_util::AddAdditionalData(&pdf_strings);
ui::TemplateReplacements pdf_viewer_replacements;
ui::TemplateReplacementsFromDictionaryValue(
base::Value::AsDictionaryValue(pdf_strings), &pdf_viewer_replacements);
extension_template_replacements_[extension_misc::kPdfExtensionId] =
std::move(pdf_viewer_replacements);
#endif
} }
ElectronComponentExtensionResourceManager:: ElectronComponentExtensionResourceManager::