Fix decoding of resources (fixes issue #2966)

Use LoadDataResourceString instead of GetDataResource. It will perform
decoding if necessary.
This commit is contained in:
Marshall Greenblatt
2020-07-02 14:45:16 -04:00
parent 08c49aa624
commit f7c90a6bb2
3 changed files with 18 additions and 14 deletions

View File

@@ -32,9 +32,9 @@ const char kPdfResourceIdentifier[] = "chromium-pdf";
const char kPdfPluginName[] = "Chrome PDF Viewer"; const char kPdfPluginName[] = "Chrome PDF Viewer";
std::string GetManifest() { std::string GetManifest() {
std::string manifest_contents = ui::ResourceBundle::GetSharedInstance() std::string manifest_contents =
.GetRawDataResource(IDR_PDF_MANIFEST) ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
.as_string(); IDR_PDF_MANIFEST);
DCHECK(manifest_contents.find(kNameTag) != std::string::npos); DCHECK(manifest_contents.find(kNameTag) != std::string::npos);
base::ReplaceFirstSubstringAfterOffset(&manifest_contents, 0, kNameTag, base::ReplaceFirstSubstringAfterOffset(&manifest_contents, 0, kNameTag,
kPdfPluginName); kPdfPluginName);

View File

@@ -43,6 +43,7 @@
#include "content/public/common/url_utils.h" #include "content/public/common/url_utils.h"
#include "content/public/common/user_agent.h" #include "content/public/common/user_agent.h"
#include "ipc/ipc_channel.h" #include "ipc/ipc_channel.h"
#include "ui/base/resource/resource_bundle.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
using extensions::api::cef::kSupportedAPIs; using extensions::api::cef::kSupportedAPIs;
@@ -341,16 +342,17 @@ bool OnExtensionsSupportUI(std::string* mime_type, std::string* output) {
} }
bool OnLicenseUI(std::string* mime_type, std::string* output) { bool OnLicenseUI(std::string* mime_type, std::string* output) {
base::StringPiece piece = CefContentClient::Get()->GetDataResource( std::string piece =
IDR_CEF_LICENSE_TXT, ui::SCALE_FACTOR_NONE); ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_CEF_LICENSE_TXT);
if (piece.empty()) { if (piece.empty()) {
NOTREACHED() << "Failed to load license txt resource."; NOTREACHED() << "Failed to load license txt resource.";
return false; return false;
} }
*mime_type = "text/html"; *mime_type = "text/html";
*output = "<html><head><title>License</title></head><body><pre>" + *output = "<html><head><title>License</title></head><body><pre>" + piece +
piece.as_string() + "</pre></body></html>"; "</pre></body></html>";
return true; return true;
} }
@@ -358,9 +360,10 @@ bool OnLicenseUI(std::string* mime_type, std::string* output) {
bool OnVersionUI(Profile* profile, bool OnVersionUI(Profile* profile,
std::string* mime_type, std::string* mime_type,
std::string* output) { std::string* output) {
base::StringPiece piece = CefContentClient::Get()->GetDataResource( std::string tmpl =
IDR_CEF_VERSION_HTML, ui::SCALE_FACTOR_NONE); ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
if (piece.empty()) { IDR_CEF_VERSION_HTML);
if (tmpl.empty()) {
NOTREACHED() << "Failed to load version html resource."; NOTREACHED() << "Failed to load version html resource.";
return false; return false;
} }
@@ -381,7 +384,6 @@ bool OnVersionUI(Profile* profile,
parser.Add("MODULEPATH", GetModulePath()); parser.Add("MODULEPATH", GetModulePath());
parser.Add("CACHEPATH", CefString(profile->GetPath().value())); parser.Add("CACHEPATH", CefString(profile->GetPath().value()));
std::string tmpl = piece.as_string();
parser.Parse(&tmpl); parser.Parse(&tmpl);
*mime_type = "text/html"; *mime_type = "text/html";

View File

@@ -158,13 +158,15 @@ class InternalHandlerFactory : public CefSchemeHandlerFactory {
action.mime_type = GetMimeType(url.path()); action.mime_type = GetMimeType(url.path());
if (!action.bytes && action.resource_id >= 0) { if (!action.bytes && action.resource_id >= 0) {
action.bytes = std::string str =
CefContentClient::Get()->GetDataResourceBytes(action.resource_id); ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
if (!action.bytes) { action.resource_id);
if (str.empty()) {
NOTREACHED() << "Failed to load internal resource for id: " NOTREACHED() << "Failed to load internal resource for id: "
<< action.resource_id << " URL: " << url.spec().c_str(); << action.resource_id << " URL: " << url.spec().c_str();
return nullptr; return nullptr;
} }
action.bytes = base::RefCountedString::TakeString(&str);
} }
if (action.bytes) { if (action.bytes) {