Commit c296859a authored by dpapad's avatar dpapad Committed by Commit Bot

Replace a few GetRawDataResource/GetStringUTF8 calls in c/b/ui/webui/

Specifically this CL affects the C++ backends of chrome://settings and
chrome://terms replacing some call sites of GetRawDataResource() as well
as GetStringUTF8(). The latter was somewhat misused, since it's not
intended to be used to load entire file contents.

GetRawDataResource assumes that underlying files are not compressed,
whereas LoadDataResourceString automatically decompresses if necessary.

This is one of many CLs, in preparation of compressing all HTML, JS,
CSS, SVG files by default (meaning without requiring compress="gzip"
to be specified).

Bug: 1068407
Change-Id: Ie06dda1c3bd37e66b79aa06ca3ce40a1cf85dc3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2151677
Commit-Queue: Esmael Elmoslimany <aee@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759516}
parent c2873dde
...@@ -319,8 +319,11 @@ class ChromeOSTermsHandler ...@@ -319,8 +319,11 @@ class ChromeOSTermsHandler
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// If we fail to load Chrome OS EULA from disk, load it from resources. // If we fail to load Chrome OS EULA from disk, load it from resources.
// Do nothing if OEM EULA or Play Store ToS load failed. // Do nothing if OEM EULA or Play Store ToS load failed.
if (contents_.empty() && path_.empty()) if (contents_.empty() && path_.empty()) {
contents_ = l10n_util::GetStringUTF8(IDS_TERMS_HTML); contents_ =
ui::ResourceBundle::GetSharedInstance().LoadLocalizedResourceString(
IDS_TERMS_HTML);
}
std::move(callback_).Run(base::RefCountedString::TakeString(&contents_)); std::move(callback_).Run(base::RefCountedString::TakeString(&contents_));
} }
...@@ -361,9 +364,9 @@ class ChromeOSCreditsHandler ...@@ -361,9 +364,9 @@ class ChromeOSCreditsHandler
void StartOnUIThread() { void StartOnUIThread() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (path_ == kKeyboardUtilsPath) { if (path_ == kKeyboardUtilsPath) {
contents_ = ui::ResourceBundle::GetSharedInstance() contents_ =
.GetRawDataResource(IDR_KEYBOARD_UTILS_JS) ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
.as_string(); IDR_KEYBOARD_UTILS_JS);
ResponseOnUIThread(); ResponseOnUIThread();
return; return;
} }
...@@ -428,9 +431,9 @@ class CrostiniCreditsHandler ...@@ -428,9 +431,9 @@ class CrostiniCreditsHandler
void StartOnUIThread() { void StartOnUIThread() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (path_ == kKeyboardUtilsPath) { if (path_ == kKeyboardUtilsPath) {
contents_ = ui::ResourceBundle::GetSharedInstance() contents_ =
.GetRawDataResource(IDR_KEYBOARD_UTILS_JS) ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
.as_string(); IDR_KEYBOARD_UTILS_JS);
ResponseOnUIThread(); ResponseOnUIThread();
return; return;
} }
...@@ -636,7 +639,9 @@ void AboutUIHTMLSource::StartDataRequest( ...@@ -636,7 +639,9 @@ void AboutUIHTMLSource::StartDataRequest(
return; return;
} }
#endif #endif
response = l10n_util::GetStringUTF8(IDS_TERMS_HTML); response =
ui::ResourceBundle::GetSharedInstance().LoadLocalizedResourceString(
IDS_TERMS_HTML);
#endif #endif
} }
......
...@@ -473,11 +473,11 @@ void AddChromeCleanupStrings(content::WebUIDataSource* html_source) { ...@@ -473,11 +473,11 @@ void AddChromeCleanupStrings(content::WebUIDataSource* html_source) {
// partner. The logo is added directly to the DOM, rather than as an <img> // partner. The logo is added directly to the DOM, rather than as an <img>
// src, to make sure that screen readers can find accessibility tags inside // src, to make sure that screen readers can find accessibility tags inside
// the SVG. // the SVG.
const std::string powered_by_element = const std::string powered_by_element = base::StrCat(
base::StrCat({"<span id='powered-by-logo'>", {"<span id='powered-by-logo'>",
ui::ResourceBundle::GetSharedInstance().GetRawDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_CHROME_CLEANUP_PARTNER), IDR_CHROME_CLEANUP_PARTNER),
"</span>"}); "</span>"});
const base::string16 powered_by_html = const base::string16 powered_by_html =
l10n_util::GetStringFUTF16(IDS_SETTINGS_RESET_CLEANUP_FOOTER_POWERED_BY, l10n_util::GetStringFUTF16(IDS_SETTINGS_RESET_CLEANUP_FOOTER_POWERED_BY,
base::UTF8ToUTF16(powered_by_element)); base::UTF8ToUTF16(powered_by_element));
......
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