Commit e0f6e047 authored by Sam Maier's avatar Sam Maier Committed by Commit Bot

Renaming DecompressData resource bundle functions

This changes the paradigm on retrieving resources. Before, for these functions,
you needed to know whether your resources were compressed to know to call the
right function.

Now, we can call it without knowing if there is decompression under the covers.
This also allows others to use std::string return types for convenience, even
if they don't use compression.

TBR: trivial renaming outside of reviewed area
Bug: 1003433
Change-Id: I0200d083d4a2d8f8fef98591e9c2e4188488a471
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1874514
Commit-Queue: Sam Maier <smaier@chromium.org>
Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711469}
parent d4ee1636
...@@ -250,7 +250,7 @@ void AwContentRendererClient::PrepareErrorPage( ...@@ -250,7 +250,7 @@ void AwContentRendererClient::PrepareErrorPage(
else else
replacements.push_back(""); replacements.push_back("");
*error_html = base::ReplaceStringPlaceholders( *error_html = base::ReplaceStringPlaceholders(
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_AW_LOAD_ERROR_HTML), IDR_AW_LOAD_ERROR_HTML),
replacements, nullptr); replacements, nullptr);
} }
......
...@@ -252,7 +252,7 @@ DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) { ...@@ -252,7 +252,7 @@ DevToolsManagerDelegateAndroid::CreateNewTarget(const GURL& url) {
} }
std::string DevToolsManagerDelegateAndroid::GetDiscoveryPageHTML() { std::string DevToolsManagerDelegateAndroid::GetDiscoveryPageHTML() {
return ui::ResourceBundle::GetSharedInstance().DecompressDataResource( return ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DEVTOOLS_DISCOVERY_PAGE_HTML); IDR_DEVTOOLS_DISCOVERY_PAGE_HTML);
} }
......
...@@ -25,7 +25,7 @@ std::string BuildErrorPageHtml() { ...@@ -25,7 +25,7 @@ std::string BuildErrorPageHtml() {
l10n_util::GetStringUTF8(IDS_DEV_UI_LOADER_ERROR_SUGGEST_CHECK_INTERNET); l10n_util::GetStringUTF8(IDS_DEV_UI_LOADER_ERROR_SUGGEST_CHECK_INTERNET);
std::string source = std::string source =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DEV_UI_LOADER_ERROR_HTML); IDR_DEV_UI_LOADER_ERROR_HTML);
return ui::ReplaceTemplateExpressions(source, replacements); return ui::ReplaceTemplateExpressions(source, replacements);
} }
......
...@@ -227,7 +227,7 @@ ChromeDevToolsManagerDelegate::CreateNewTarget(const GURL& url) { ...@@ -227,7 +227,7 @@ ChromeDevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
} }
std::string ChromeDevToolsManagerDelegate::GetDiscoveryPageHTML() { std::string ChromeDevToolsManagerDelegate::GetDiscoveryPageHTML() {
return ui::ResourceBundle::GetSharedInstance().DecompressDataResource( return ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DEVTOOLS_DISCOVERY_PAGE_HTML); IDR_DEVTOOLS_DISCOVERY_PAGE_HTML);
} }
......
...@@ -62,7 +62,7 @@ std::string TestSafeBrowsingBlockingPageQuiet::GetHTML() { ...@@ -62,7 +62,7 @@ std::string TestSafeBrowsingBlockingPageQuiet::GetHTML() {
webui::SetLoadTimeDataDefaults(controller()->GetApplicationLocale(), webui::SetLoadTimeDataDefaults(controller()->GetApplicationLocale(),
&load_time_data); &load_time_data);
std::string html = std::string html =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_SECURITY_INTERSTITIAL_QUIET_HTML); IDR_SECURITY_INTERSTITIAL_QUIET_HTML);
webui::AppendWebUiCssTextDefaults(&html); webui::AppendWebUiCssTextDefaults(&html);
html = webui::GetI18nTemplateHtml(html, &load_time_data); html = webui::GetI18nTemplateHtml(html, &load_time_data);
......
...@@ -318,7 +318,7 @@ SSLErrorAssistant::GetErrorAssistantProtoFromResourceBundle() { ...@@ -318,7 +318,7 @@ SSLErrorAssistant::GetErrorAssistantProtoFromResourceBundle() {
auto proto = std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>(); auto proto = std::make_unique<chrome_browser_ssl::SSLErrorAssistantConfig>();
DCHECK(proto); DCHECK(proto);
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
std::string data = bundle.DecompressDataResource(IDR_SSL_ERROR_ASSISTANT_PB); std::string data = bundle.LoadDataResourceString(IDR_SSL_ERROR_ASSISTANT_PB);
return proto->ParseFromString(data) ? std::move(proto) : nullptr; return proto->ParseFromString(data) ? std::move(proto) : nullptr;
} }
......
...@@ -172,7 +172,7 @@ std::string BuildHtml(bool allow_access_requests, ...@@ -172,7 +172,7 @@ std::string BuildHtml(bool allow_access_requests,
strings.SetString("requestFailedMessage", request_failed_message); strings.SetString("requestFailedMessage", request_failed_message);
webui::SetLoadTimeDataDefaults(app_locale, &strings); webui::SetLoadTimeDataDefaults(app_locale, &strings);
std::string html = std::string html =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML); IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML);
webui::AppendWebUiCssTextDefaults(&html); webui::AppendWebUiCssTextDefaults(&html);
std::string error_html = webui::GetI18nTemplateHtml(html, &strings); std::string error_html = webui::GetI18nTemplateHtml(html, &strings);
......
...@@ -412,7 +412,7 @@ class ChromeOSCreditsHandler ...@@ -412,7 +412,7 @@ class ChromeOSCreditsHandler
// If we fail to load Chrome OS credits from disk, load it from resources. // If we fail to load Chrome OS credits from disk, load it from resources.
if (contents_.empty() && path_ != kKeyboardUtilsPath) { if (contents_.empty() && path_ != kKeyboardUtilsPath) {
contents_ = contents_ =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_OS_CREDITS_HTML); IDR_OS_CREDITS_HTML);
} }
callback_.Run(base::RefCountedString::TakeString(&contents_)); callback_.Run(base::RefCountedString::TakeString(&contents_));
...@@ -482,7 +482,7 @@ class LinuxCreditsHandler ...@@ -482,7 +482,7 @@ class LinuxCreditsHandler
// TODO(rjwright): Add a linux-specific placeholder in resources. // TODO(rjwright): Add a linux-specific placeholder in resources.
if (contents_.empty() && path_ != kKeyboardUtilsPath) { if (contents_.empty() && path_ != kKeyboardUtilsPath) {
contents_ = contents_ =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_OS_CREDITS_HTML); IDR_OS_CREDITS_HTML);
} }
callback_.Run(base::RefCountedString::TakeString(&contents_)); callback_.Run(base::RefCountedString::TakeString(&contents_));
...@@ -616,7 +616,7 @@ void AboutUIHTMLSource::StartDataRequest( ...@@ -616,7 +616,7 @@ void AboutUIHTMLSource::StartDataRequest(
response = about_ui::GetCredits(true /*include_scripts*/); response = about_ui::GetCredits(true /*include_scripts*/);
} else { } else {
response = response =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource(idr); ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(idr);
} }
#if defined(OS_LINUX) || defined(OS_OPENBSD) #if defined(OS_LINUX) || defined(OS_OPENBSD)
} else if (source_name_ == chrome::kChromeUILinuxProxyConfigHost) { } else if (source_name_ == chrome::kChromeUILinuxProxyConfigHost) {
......
...@@ -524,7 +524,7 @@ void InterstitialHTMLSource::StartDataRequest( ...@@ -524,7 +524,7 @@ void InterstitialHTMLSource::StartDataRequest(
} else if (interstitial_delegate.get()) { } else if (interstitial_delegate.get()) {
html = interstitial_delegate.get()->GetHTMLContents(); html = interstitial_delegate.get()->GetHTMLContents();
} else { } else {
html = ui::ResourceBundle::GetSharedInstance().DecompressDataResource( html = ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_SECURITY_INTERSTITIAL_UI_HTML); IDR_SECURITY_INTERSTITIAL_UI_HTML);
} }
scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString;
......
...@@ -42,7 +42,7 @@ struct LazyDirectoryListerCacher { ...@@ -42,7 +42,7 @@ struct LazyDirectoryListerCacher {
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
value.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); value.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr");
std::string str = webui::GetI18nTemplateHtml( std::string str = webui::GetI18nTemplateHtml(
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DIR_HEADER_HTML), IDR_DIR_HEADER_HTML),
&value); &value);
......
...@@ -385,7 +385,7 @@ LocalizedError::PageState NetErrorHelper::GenerateLocalizedErrorPage( ...@@ -385,7 +385,7 @@ LocalizedError::PageState NetErrorHelper::GenerateLocalizedErrorPage(
int resource_id = IDR_NET_ERROR_HTML; int resource_id = IDR_NET_ERROR_HTML;
std::string extracted_string = std::string extracted_string =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
resource_id); resource_id);
base::StringPiece template_html(extracted_string.data(), base::StringPiece template_html(extracted_string.data(),
extracted_string.size()); extracted_string.size());
......
...@@ -80,7 +80,7 @@ class TranslateScriptBrowserTest : public ChromeRenderViewTest { ...@@ -80,7 +80,7 @@ class TranslateScriptBrowserTest : public ChromeRenderViewTest {
protected: protected:
void InjectElementLibrary() { void InjectElementLibrary() {
std::string script = std::string script =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_TRANSLATE_JS); IDR_TRANSLATE_JS);
script += kElementJs; script += kElementJs;
ExecuteScript(script); ExecuteScript(script);
......
...@@ -14,7 +14,7 @@ namespace about_ui { ...@@ -14,7 +14,7 @@ namespace about_ui {
std::string GetCredits(bool include_scripts) { std::string GetCredits(bool include_scripts) {
std::string response = std::string response =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_ABOUT_UI_CREDITS_HTML); IDR_ABOUT_UI_CREDITS_HTML);
if (include_scripts) { if (include_scripts) {
response += response +=
......
...@@ -43,7 +43,7 @@ void IsDistillablePageForDetector(content::WebContents* web_contents, ...@@ -43,7 +43,7 @@ void IsDistillablePageForDetector(content::WebContents* web_contents,
return; return;
} }
std::string extract_features_js = std::string extract_features_js =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_EXTRACT_PAGE_FEATURES_JS); IDR_EXTRACT_PAGE_FEATURES_JS);
RunIsolatedJavaScript( RunIsolatedJavaScript(
main_frame, extract_features_js, main_frame, extract_features_js,
......
...@@ -17,7 +17,7 @@ const DistillablePageDetector* DistillablePageDetector::GetNewModel() { ...@@ -17,7 +17,7 @@ const DistillablePageDetector* DistillablePageDetector::GetNewModel() {
static DistillablePageDetector* detector = nullptr; static DistillablePageDetector* detector = nullptr;
if (!detector) { if (!detector) {
std::string serialized_proto = std::string serialized_proto =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL_NEW); IDR_DISTILLABLE_PAGE_SERIALIZED_MODEL_NEW);
std::unique_ptr<AdaBoostProto> proto(new AdaBoostProto); std::unique_ptr<AdaBoostProto> proto(new AdaBoostProto);
CHECK(proto->ParseFromString(serialized_proto)); CHECK(proto->ParseFromString(serialized_proto));
...@@ -30,7 +30,7 @@ const DistillablePageDetector* DistillablePageDetector::GetLongPageModel() { ...@@ -30,7 +30,7 @@ const DistillablePageDetector* DistillablePageDetector::GetLongPageModel() {
static DistillablePageDetector* detector = nullptr; static DistillablePageDetector* detector = nullptr;
if (!detector) { if (!detector) {
std::string serialized_proto = std::string serialized_proto =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_LONG_PAGE_SERIALIZED_MODEL); IDR_LONG_PAGE_SERIALIZED_MODEL);
std::unique_ptr<AdaBoostProto> proto(new AdaBoostProto); std::unique_ptr<AdaBoostProto> proto(new AdaBoostProto);
CHECK(proto->ParseFromString(serialized_proto)); CHECK(proto->ParseFromString(serialized_proto));
......
...@@ -35,7 +35,7 @@ std::string GetDistillerScriptWithOptions( ...@@ -35,7 +35,7 @@ std::string GetDistillerScriptWithOptions(
const dom_distiller::proto::DomDistillerOptions& options, const dom_distiller::proto::DomDistillerOptions& options,
bool stringify_output) { bool stringify_output) {
std::string script = std::string script =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DISTILLER_JS); IDR_DISTILLER_JS);
if (script.empty()) { if (script.empty()) {
return ""; return "";
......
...@@ -58,15 +58,15 @@ const char kMonospaceCssClass[] = "monospace"; ...@@ -58,15 +58,15 @@ const char kMonospaceCssClass[] = "monospace";
std::string GetPlatformSpecificCss() { std::string GetPlatformSpecificCss() {
#if defined(OS_IOS) #if defined(OS_IOS)
return base::StrCat( return base::StrCat(
{ui::ResourceBundle::GetSharedInstance().DecompressDataResource( {ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DISTILLER_MOBILE_CSS), IDR_DISTILLER_MOBILE_CSS),
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DISTILLER_IOS_CSS)}); IDR_DISTILLER_IOS_CSS)});
#elif defined(OS_ANDROID) #elif defined(OS_ANDROID)
return ui::ResourceBundle::GetSharedInstance().DecompressDataResource( return ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DISTILLER_MOBILE_CSS); IDR_DISTILLER_MOBILE_CSS);
#else // Desktop #else // Desktop
return ui::ResourceBundle::GetSharedInstance().DecompressDataResource( return ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DISTILLER_DESKTOP_CSS); IDR_DISTILLER_DESKTOP_CSS);
#endif #endif
} }
...@@ -120,7 +120,7 @@ std::string ReplaceHtmlTemplateValues( ...@@ -120,7 +120,7 @@ std::string ReplaceHtmlTemplateValues(
const DistilledPagePrefs::Theme theme, const DistilledPagePrefs::Theme theme,
const DistilledPagePrefs::FontFamily font_family) { const DistilledPagePrefs::FontFamily font_family) {
std::string html_template = std::string html_template =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DOM_DISTILLER_VIEWER_HTML); IDR_DOM_DISTILLER_VIEWER_HTML);
std::vector<std::string> substitutions; std::vector<std::string> substitutions;
...@@ -233,18 +233,18 @@ const std::string GetUnsafeArticleContentJs( ...@@ -233,18 +233,18 @@ const std::string GetUnsafeArticleContentJs(
const std::string GetCss() { const std::string GetCss() {
return base::StrCat( return base::StrCat(
{ui::ResourceBundle::GetSharedInstance().DecompressDataResource( {ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DISTILLER_CSS), IDR_DISTILLER_CSS),
GetPlatformSpecificCss()}); GetPlatformSpecificCss()});
} }
const std::string GetLoadingImage() { const std::string GetLoadingImage() {
return ui::ResourceBundle::GetSharedInstance().DecompressDataResource( return ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DISTILLER_LOADING_IMAGE); IDR_DISTILLER_LOADING_IMAGE);
} }
const std::string GetJavaScript() { const std::string GetJavaScript() {
return ui::ResourceBundle::GetSharedInstance().DecompressDataResource( return ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DOM_DISTILLER_VIEWER_JS); IDR_DOM_DISTILLER_VIEWER_JS);
} }
......
...@@ -221,7 +221,7 @@ base::Value DefaultPopularSites() { ...@@ -221,7 +221,7 @@ base::Value DefaultPopularSites() {
} }
std::unique_ptr<base::ListValue> sites = std::unique_ptr<base::ListValue> sites =
base::ListValue::From(base::JSONReader::ReadDeprecated( base::ListValue::From(base::JSONReader::ReadDeprecated(
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_DEFAULT_POPULAR_SITES_JSON))); IDR_DEFAULT_POPULAR_SITES_JSON)));
DCHECK(sites); DCHECK(sites);
for (base::Value& site : *sites) { for (base::Value& site : *sites) {
......
...@@ -85,7 +85,7 @@ bool PageRenovationLoader::LoadSource() { ...@@ -85,7 +85,7 @@ bool PageRenovationLoader::LoadSource() {
// Our script file is stored in the resource bundle. Get this script. // Our script file is stored in the resource bundle. Get this script.
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
combined_source_ = base::UTF8ToUTF16( combined_source_ = base::UTF8ToUTF16(
rb.DecompressDataResource(IDR_OFFLINE_PAGES_RENOVATIONS_JS)); rb.LoadDataResourceString(IDR_OFFLINE_PAGES_RENOVATIONS_JS));
// If built correctly, IDR_OFFLINE_PAGES_RENOVATIONS_JS should // If built correctly, IDR_OFFLINE_PAGES_RENOVATIONS_JS should
// always exist in the resource pack and loading should never fail. // always exist in the resource pack and loading should never fail.
......
...@@ -96,7 +96,7 @@ OmniboxPedal::Tokens OmniboxPedalProvider::Tokenize( ...@@ -96,7 +96,7 @@ OmniboxPedal::Tokens OmniboxPedalProvider::Tokenize(
void OmniboxPedalProvider::LoadPedalConcepts() { void OmniboxPedalProvider::LoadPedalConcepts() {
// Load concept data then parse to base::Value in order to construct Pedals. // Load concept data then parse to base::Value in order to construct Pedals.
std::string uncompressed_data = std::string uncompressed_data =
ui::ResourceBundle::GetSharedInstance().DecompressLocalizedDataResource( ui::ResourceBundle::GetSharedInstance().LoadLocalizedResourceString(
IDR_OMNIBOX_PEDAL_CONCEPTS); IDR_OMNIBOX_PEDAL_CONCEPTS);
const auto concept_data = base::JSONReader::Read(uncompressed_data); const auto concept_data = base::JSONReader::Read(uncompressed_data);
......
...@@ -735,7 +735,7 @@ void PrintRenderFrameHelper::PrintHeaderAndFooter( ...@@ -735,7 +735,7 @@ void PrintRenderFrameHelper::PrintHeaderAndFooter(
blink::WebFrameWidget::CreateForMainFrame(&web_widget_client, frame); blink::WebFrameWidget::CreateForMainFrame(&web_widget_client, frame);
base::Value html( base::Value html(
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_PRINT_HEADER_FOOTER_TEMPLATE_PAGE)); IDR_PRINT_HEADER_FOOTER_TEMPLATE_PAGE));
// Load page with script to avoid async operations. // Load page with script to avoid async operations.
ExecuteScript(frame, kPageLoadScriptFormat, html); ExecuteScript(frame, kPageLoadScriptFormat, html);
......
...@@ -76,7 +76,7 @@ std::string SecurityInterstitialPage::GetHTMLContents() { ...@@ -76,7 +76,7 @@ std::string SecurityInterstitialPage::GetHTMLContents() {
webui::SetLoadTimeDataDefaults(controller()->GetApplicationLocale(), webui::SetLoadTimeDataDefaults(controller()->GetApplicationLocale(),
&load_time_data); &load_time_data);
std::string html = std::string html =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
GetHTMLTemplateId()); GetHTMLTemplateId());
webui::AppendWebUiCssTextDefaults(&html); webui::AppendWebUiCssTextDefaults(&html);
......
...@@ -154,7 +154,7 @@ void TranslateScript::OnScriptFetchComplete(bool success, ...@@ -154,7 +154,7 @@ void TranslateScript::OnScriptFetchComplete(bool success,
&data_, "var securityOrigin = '%s';", security_origin.spec().c_str()); &data_, "var securityOrigin = '%s';", security_origin.spec().c_str());
// Load embedded translate.js. // Load embedded translate.js.
data_.append(ui::ResourceBundle::GetSharedInstance().DecompressDataResource( data_.append(ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_TRANSLATE_JS)); IDR_TRANSLATE_JS));
#if defined(OS_IOS) #if defined(OS_IOS)
......
...@@ -22,7 +22,7 @@ class JsTranslateManagerTest : public PlatformTest { ...@@ -22,7 +22,7 @@ class JsTranslateManagerTest : public PlatformTest {
receiver_ = [[CRWTestJSInjectionReceiver alloc] init]; receiver_ = [[CRWTestJSInjectionReceiver alloc] init];
manager_ = [[JsTranslateManager alloc] initWithReceiver:receiver_]; manager_ = [[JsTranslateManager alloc] initWithReceiver:receiver_];
std::string script = std::string script =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_TRANSLATE_JS); IDR_TRANSLATE_JS);
[manager_ setScript:base::SysUTF8ToNSString(script + "('DummyKey');")]; [manager_ setScript:base::SysUTF8ToNSString(script + "('DummyKey');")];
} }
......
...@@ -70,7 +70,7 @@ std::string IOSSecurityInterstitialPage::GetHtmlContents() const { ...@@ -70,7 +70,7 @@ std::string IOSSecurityInterstitialPage::GetHtmlContents() const {
GetApplicationContext()->GetApplicationLocale(), &load_time_data); GetApplicationContext()->GetApplicationLocale(), &load_time_data);
AdjustFontSize(load_time_data); AdjustFontSize(load_time_data);
std::string html = std::string html =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_SECURITY_INTERSTITIAL_HTML); IDR_SECURITY_INTERSTITIAL_HTML);
webui::AppendWebUiCssTextDefaults(&html); webui::AppendWebUiCssTextDefaults(&html);
return webui::GetI18nTemplateHtml(html, &load_time_data); return webui::GetI18nTemplateHtml(html, &load_time_data);
......
...@@ -123,7 +123,7 @@ void AboutUIHTMLSource::StartDataRequest( ...@@ -123,7 +123,7 @@ void AboutUIHTMLSource::StartDataRequest(
idr = IDR_ABOUT_UI_CREDITS_JS; idr = IDR_ABOUT_UI_CREDITS_JS;
ui::ResourceBundle& resource_instance = ui::ResourceBundle& resource_instance =
ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle::GetSharedInstance();
response = resource_instance.DecompressDataResource(idr); response = resource_instance.LoadDataResourceString(idr);
} else if (source_name_ == kChromeUIHistogramHost) { } else if (source_name_ == kChromeUIHistogramHost) {
// Note: On other platforms, this is implemented in //content. If there is // Note: On other platforms, this is implemented in //content. If there is
// ever a need for embedders other than //ios/chrome to use // ever a need for embedders other than //ios/chrome to use
......
...@@ -59,7 +59,7 @@ NSString* GetErrorPage(const GURL& url, ...@@ -59,7 +59,7 @@ NSString* GetErrorPage(const GURL& url,
ui::ResourceBundle::GetSharedInstance().GetMaxScaleFactor(); ui::ResourceBundle::GetSharedInstance().GetMaxScaleFactor();
std::string extracted_string = std::string extracted_string =
ui::ResourceBundle::GetSharedInstance().DecompressDataResourceScaled( ui::ResourceBundle::GetSharedInstance().LoadDataResourceStringForScale(
IDR_NET_ERROR_HTML, scale_factor); IDR_NET_ERROR_HTML, scale_factor);
base::StringPiece template_html(extracted_string.data(), base::StringPiece template_html(extracted_string.data(),
extracted_string.size()); extracted_string.size());
......
...@@ -149,15 +149,15 @@ bool BrotliDecompress(base::StringPiece input, std::string* output) { ...@@ -149,15 +149,15 @@ bool BrotliDecompress(base::StringPiece input, std::string* output) {
} }
// Helper function for decompressing resource. // Helper function for decompressing resource.
void Decompress(base::StringPiece data, std::string* output) { void DecompressIfNeeded(base::StringPiece data, std::string* output) {
if (HasGzipHeader(data)) { if (!data.empty() && HasGzipHeader(data)) {
bool success = compression::GzipUncompress(data, output); bool success = compression::GzipUncompress(data, output);
DCHECK(success); DCHECK(success);
} else if (HasBrotliHeader(data)) { } else if (!data.empty() && HasBrotliHeader(data)) {
bool success = BrotliDecompress(data, output); bool success = BrotliDecompress(data, output);
DCHECK(success); DCHECK(success);
} else { } else {
NOTREACHED() << "Resource is not compressed"; data.CopyToString(output);
} }
} }
...@@ -588,7 +588,7 @@ base::RefCountedMemory* ResourceBundle::LoadDataResourceBytesForScale( ...@@ -588,7 +588,7 @@ base::RefCountedMemory* ResourceBundle::LoadDataResourceBytesForScale(
if (!data.empty()) { if (!data.empty()) {
if (HasGzipHeader(data) || HasBrotliHeader(data)) { if (HasGzipHeader(data) || HasBrotliHeader(data)) {
base::RefCountedString* bytes_string = new base::RefCountedString(); base::RefCountedString* bytes_string = new base::RefCountedString();
Decompress(data, &(bytes_string->data())); DecompressIfNeeded(data, &(bytes_string->data()));
bytes = bytes_string; bytes = bytes_string;
} else { } else {
bytes = new base::RefCountedStaticMemory(data.data(), data.length()); bytes = new base::RefCountedStaticMemory(data.data(), data.length());
...@@ -632,20 +632,20 @@ base::StringPiece ResourceBundle::GetRawDataResourceForScale( ...@@ -632,20 +632,20 @@ base::StringPiece ResourceBundle::GetRawDataResourceForScale(
return base::StringPiece(); return base::StringPiece();
} }
std::string ResourceBundle::DecompressDataResource(int resource_id) const { std::string ResourceBundle::LoadDataResourceString(int resource_id) const {
return DecompressDataResourceScaled(resource_id, ui::SCALE_FACTOR_NONE); return LoadDataResourceStringForScale(resource_id, ui::SCALE_FACTOR_NONE);
} }
std::string ResourceBundle::DecompressDataResourceScaled( std::string ResourceBundle::LoadDataResourceStringForScale(
int resource_id, int resource_id,
ScaleFactor scaling_factor) const { ScaleFactor scaling_factor) const {
std::string output; std::string output;
Decompress(GetRawDataResourceForScale(resource_id, scaling_factor), &output); DecompressIfNeeded(GetRawDataResourceForScale(resource_id, scaling_factor),
&output);
return output; return output;
} }
std::string ResourceBundle::DecompressLocalizedDataResource( std::string ResourceBundle::LoadLocalizedResourceString(int resource_id) const {
int resource_id) const {
base::AutoLock lock_scope(*locale_resources_data_lock_); base::AutoLock lock_scope(*locale_resources_data_lock_);
base::StringPiece data; base::StringPiece data;
if (!(locale_resources_data_.get() && if (!(locale_resources_data_.get() &&
...@@ -661,7 +661,7 @@ std::string ResourceBundle::DecompressLocalizedDataResource( ...@@ -661,7 +661,7 @@ std::string ResourceBundle::DecompressLocalizedDataResource(
} }
} }
std::string output; std::string output;
Decompress(data, &output); DecompressIfNeeded(data, &output);
return output; return output;
} }
......
...@@ -254,16 +254,16 @@ class UI_BASE_EXPORT ResourceBundle { ...@@ -254,16 +254,16 @@ class UI_BASE_EXPORT ResourceBundle {
// into a newly allocated string given the resource id. Todo: Look into // into a newly allocated string given the resource id. Todo: Look into
// introducing an Async version of this function in the future. // introducing an Async version of this function in the future.
// Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=973417 // Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=973417
std::string DecompressDataResource(int resource_id) const; std::string LoadDataResourceString(int resource_id) const;
// Return the contents of a scale dependent resource, decompressed into // Return the contents of a scale dependent resource, decompressed into
// a newly allocated string given the resource id. // a newly allocated string given the resource id.
std::string DecompressDataResourceScaled(int resource_id, std::string LoadDataResourceStringForScale(int resource_id,
ScaleFactor scaling_factor) const; ScaleFactor scaling_factor) const;
// Return the contents of a localized resource, decompressed into a // Return the contents of a localized resource, decompressed into a
// newly allocated string given the resource id. // newly allocated string given the resource id.
std::string DecompressLocalizedDataResource(int resource_id) const; std::string LoadLocalizedResourceString(int resource_id) const;
// Get a localized string given a message id. Returns an empty string if the // Get a localized string given a message id. Returns an empty string if the
// resource_id is not found. // resource_id is not found.
......
...@@ -457,7 +457,7 @@ TEST_F(ResourceBundleImageTest, LoadDataResourceBytesNotFound) { ...@@ -457,7 +457,7 @@ TEST_F(ResourceBundleImageTest, LoadDataResourceBytesNotFound) {
resource_bundle->LoadDataResourceBytes(kUnfoundResourceId)); resource_bundle->LoadDataResourceBytes(kUnfoundResourceId));
} }
TEST_F(ResourceBundleImageTest, DecompressDataResourceScaled) { TEST_F(ResourceBundleImageTest, LoadDataResourceStringForScale) {
base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak"));
base::FilePath data_2x_path = base::FilePath data_2x_path =
dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak"));
...@@ -477,13 +477,13 @@ TEST_F(ResourceBundleImageTest, DecompressDataResourceScaled) { ...@@ -477,13 +477,13 @@ TEST_F(ResourceBundleImageTest, DecompressDataResourceScaled) {
// Resource ID 6 is brotlied and exists in both 1x and 2x paks, so we expect a // Resource ID 6 is brotlied and exists in both 1x and 2x paks, so we expect a
// different result when requesting the 2x scale. // different result when requesting the 2x scale.
EXPECT_EQ("this is id 6", resource_bundle->DecompressDataResourceScaled( EXPECT_EQ("this is id 6", resource_bundle->LoadDataResourceStringForScale(
6, SCALE_FACTOR_100P)); 6, SCALE_FACTOR_100P));
EXPECT_EQ("this is id 6 x2", resource_bundle->DecompressDataResourceScaled( EXPECT_EQ("this is id 6 x2", resource_bundle->LoadDataResourceStringForScale(
6, SCALE_FACTOR_200P)); 6, SCALE_FACTOR_200P));
} }
TEST_F(ResourceBundleImageTest, DecompressLocalizedDataResource) { TEST_F(ResourceBundleImageTest, LoadLocalizedResourceString) {
base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak"));
// Dump content into pak file. // Dump content into pak file.
ASSERT_EQ(base::WriteFile(data_path, kSampleCompressPakContentsV5, ASSERT_EQ(base::WriteFile(data_path, kSampleCompressPakContentsV5,
...@@ -494,13 +494,11 @@ TEST_F(ResourceBundleImageTest, DecompressLocalizedDataResource) { ...@@ -494,13 +494,11 @@ TEST_F(ResourceBundleImageTest, DecompressLocalizedDataResource) {
resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_NONE); resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_NONE);
resource_bundle->OverrideLocalePakForTest(data_path); resource_bundle->OverrideLocalePakForTest(data_path);
EXPECT_EQ("this is id 6", EXPECT_EQ("this is id 6", resource_bundle->LoadLocalizedResourceString(6));
resource_bundle->DecompressLocalizedDataResource(6)); EXPECT_EQ("this is id 8", resource_bundle->LoadLocalizedResourceString(8));
EXPECT_EQ("this is id 8",
resource_bundle->DecompressLocalizedDataResource(8));
} }
TEST_F(ResourceBundleImageTest, DecompressDataResource) { TEST_F(ResourceBundleImageTest, LoadDataResourceString) {
base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak"));
// Dump content into pak file. // Dump content into pak file.
ASSERT_EQ(base::WriteFile(data_path, kSampleCompressPakContentsV5, ASSERT_EQ(base::WriteFile(data_path, kSampleCompressPakContentsV5,
...@@ -511,10 +509,10 @@ TEST_F(ResourceBundleImageTest, DecompressDataResource) { ...@@ -511,10 +509,10 @@ TEST_F(ResourceBundleImageTest, DecompressDataResource) {
resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_NONE); resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_NONE);
// Resource ID 6 is Brotli compressed, expect it to be uncompressed. // Resource ID 6 is Brotli compressed, expect it to be uncompressed.
EXPECT_EQ("this is id 6", resource_bundle->DecompressDataResource(6)); EXPECT_EQ("this is id 6", resource_bundle->LoadDataResourceString(6));
// Resource ID 8 is Gzip compressed, expect it to be uncompressed. // Resource ID 8 is Gzip compressed, expect it to be uncompressed.
EXPECT_EQ("this is id 8", resource_bundle->DecompressDataResource(8)); EXPECT_EQ("this is id 8", resource_bundle->LoadDataResourceString(8));
} }
TEST_F(ResourceBundleImageTest, GetRawDataResource) { TEST_F(ResourceBundleImageTest, GetRawDataResource) {
......
...@@ -39,7 +39,7 @@ void AppendJsonHtml(const base::DictionaryValue* json, std::string* output) { ...@@ -39,7 +39,7 @@ void AppendJsonHtml(const base::DictionaryValue* json, std::string* output) {
void AppendLoadTimeData(std::string* output) { void AppendLoadTimeData(std::string* output) {
// fetch and cache the pointer of the jstemplate resource source text. // fetch and cache the pointer of the jstemplate resource source text.
std::string load_time_data_src = std::string load_time_data_src =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_WEBUI_JS_LOAD_TIME_DATA); IDR_WEBUI_JS_LOAD_TIME_DATA);
if (load_time_data_src.empty()) { if (load_time_data_src.empty()) {
...@@ -56,7 +56,7 @@ void AppendLoadTimeData(std::string* output) { ...@@ -56,7 +56,7 @@ void AppendLoadTimeData(std::string* output) {
void AppendJsTemplateSourceHtml(std::string* output) { void AppendJsTemplateSourceHtml(std::string* output) {
// fetch and cache the pointer of the jstemplate resource source text. // fetch and cache the pointer of the jstemplate resource source text.
std::string jstemplate_src = std::string jstemplate_src =
ui::ResourceBundle::GetSharedInstance().DecompressDataResource( ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
IDR_WEBUI_JSTEMPLATE_JS); IDR_WEBUI_JSTEMPLATE_JS);
if (jstemplate_src.empty()) { if (jstemplate_src.empty()) {
......
...@@ -206,14 +206,14 @@ std::string GetWebUiCssTextDefaults() { ...@@ -206,14 +206,14 @@ std::string GetWebUiCssTextDefaults() {
const ui::ResourceBundle& resource_bundle = const ui::ResourceBundle& resource_bundle =
ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle::GetSharedInstance();
return GetWebUiCssTextDefaults( return GetWebUiCssTextDefaults(
resource_bundle.DecompressDataResource(IDR_WEBUI_CSS_TEXT_DEFAULTS)); resource_bundle.LoadDataResourceString(IDR_WEBUI_CSS_TEXT_DEFAULTS));
} }
std::string GetWebUiCssTextDefaultsMd() { std::string GetWebUiCssTextDefaultsMd() {
const ui::ResourceBundle& resource_bundle = const ui::ResourceBundle& resource_bundle =
ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle::GetSharedInstance();
return GetWebUiCssTextDefaults( return GetWebUiCssTextDefaults(
resource_bundle.DecompressDataResource(IDR_WEBUI_CSS_TEXT_DEFAULTS_MD)); resource_bundle.LoadDataResourceString(IDR_WEBUI_CSS_TEXT_DEFAULTS_MD));
} }
void AppendWebUiCssTextDefaults(std::string* html) { void AppendWebUiCssTextDefaults(std::string* html) {
......
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