From 88b88251e7a59c75d730ede3b651d5ebde5678bc Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 2 Jul 2020 14:45:16 -0400 Subject: [PATCH] Fix decoding of resources (fixes issue #2966) Use LoadDataResourceString instead of GetDataResource. It will perform decoding if necessary. --- .../browser/extensions/pdf_extension_util.cc | 6 +++--- libcef/browser/net/chrome_scheme_handler.cc | 20 +++++++++---------- libcef/browser/net/internal_scheme_handler.cc | 7 ++++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libcef/browser/extensions/pdf_extension_util.cc b/libcef/browser/extensions/pdf_extension_util.cc index 4fb7066a3..9e3de9e9b 100644 --- a/libcef/browser/extensions/pdf_extension_util.cc +++ b/libcef/browser/extensions/pdf_extension_util.cc @@ -32,9 +32,9 @@ const char kPdfResourceIdentifier[] = "chromium-pdf"; const char kPdfPluginName[] = "Chrome PDF Viewer"; std::string GetManifest() { - std::string manifest_contents = ui::ResourceBundle::GetSharedInstance() - .GetRawDataResource(IDR_PDF_MANIFEST) - .as_string(); + std::string manifest_contents = + ui::ResourceBundle::GetSharedInstance().LoadDataResourceString( + IDR_PDF_MANIFEST); DCHECK(manifest_contents.find(kNameTag) != std::string::npos); base::ReplaceFirstSubstringAfterOffset(&manifest_contents, 0, kNameTag, kPdfPluginName); diff --git a/libcef/browser/net/chrome_scheme_handler.cc b/libcef/browser/net/chrome_scheme_handler.cc index 78ec6a84c..dbafb4687 100644 --- a/libcef/browser/net/chrome_scheme_handler.cc +++ b/libcef/browser/net/chrome_scheme_handler.cc @@ -44,6 +44,7 @@ #include "content/public/common/url_utils.h" #include "content/public/common/user_agent.h" #include "ipc/ipc_channel.h" +#include "ui/base/resource/resource_bundle.h" #include "v8/include/v8.h" using extensions::api::cef::kSupportedAPIs; @@ -342,17 +343,17 @@ bool OnExtensionsSupportUI(std::string* mime_type, std::string* output) { } bool OnLicenseUI(std::string* mime_type, std::string* output) { - base::StringPiece piece = - CefAppManager::Get()->GetContentClient()->GetDataResource( - IDR_CEF_LICENSE_TXT, ui::SCALE_FACTOR_NONE); + std::string piece = + ui::ResourceBundle::GetSharedInstance().LoadDataResourceString( + IDR_CEF_LICENSE_TXT); if (piece.empty()) { NOTREACHED() << "Failed to load license txt resource."; return false; } *mime_type = "text/html"; - *output = "License
" +
-            piece.as_string() + "
"; + *output = "License
" + piece +
+            "
"; return true; } @@ -360,10 +361,10 @@ bool OnLicenseUI(std::string* mime_type, std::string* output) { bool OnVersionUI(Profile* profile, std::string* mime_type, std::string* output) { - base::StringPiece piece = - CefAppManager::Get()->GetContentClient()->GetDataResource( - IDR_CEF_VERSION_HTML, ui::SCALE_FACTOR_NONE); - if (piece.empty()) { + std::string tmpl = + ui::ResourceBundle::GetSharedInstance().LoadDataResourceString( + IDR_CEF_VERSION_HTML); + if (tmpl.empty()) { NOTREACHED() << "Failed to load version html resource."; return false; } @@ -386,7 +387,6 @@ bool OnVersionUI(Profile* profile, parser.Add("MODULEPATH", GetModulePath()); parser.Add("CACHEPATH", CefString(profile->GetPath().value())); - std::string tmpl = piece.as_string(); parser.Parse(&tmpl); *mime_type = "text/html"; diff --git a/libcef/browser/net/internal_scheme_handler.cc b/libcef/browser/net/internal_scheme_handler.cc index 6498d62de..5c79f81f8 100644 --- a/libcef/browser/net/internal_scheme_handler.cc +++ b/libcef/browser/net/internal_scheme_handler.cc @@ -158,14 +158,15 @@ class InternalHandlerFactory : public CefSchemeHandlerFactory { action.mime_type = GetMimeType(url.path()); if (!action.bytes && action.resource_id >= 0) { - action.bytes = - CefAppManager::Get()->GetContentClient()->GetDataResourceBytes( + std::string str = + ui::ResourceBundle::GetSharedInstance().LoadDataResourceString( action.resource_id); - if (!action.bytes) { + if (str.empty()) { NOTREACHED() << "Failed to load internal resource for id: " << action.resource_id << " URL: " << url.spec().c_str(); return nullptr; } + action.bytes = base::RefCountedString::TakeString(&str); } if (action.bytes) {