Commit 0e826fed authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

WebUI: Compress NTP resources

Bug: 965089
Change-Id: I1f5d74ef361270e8845fd863ed7b19af4da17b01
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876692Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709560}
parent c4bd5cac
......@@ -13,11 +13,13 @@
<structure name="IDR_SIGNIN_SHARED_OLD_CSS_HTML" file="resources\signin\signin_shared_old_css.html" preprocess="true" allowexternalscript="true" type="chrome_html" />
</if>
<if expr="not is_android">
<structure name="IDR_INCOGNITO_TAB_HTML" file="resources\ntp4\incognito_tab.html" flattenhtml="true" type="chrome_html" />
<structure name="IDR_GUEST_TAB_HTML" file="resources\ntp4\guest_tab.html" flattenhtml="true" type="chrome_html" />
<structure name="IDR_NEW_INCOGNITO_TAB_THEME_CSS" file="resources\ntp4\new_incognito_tab_theme.css" flattenhtml="true" type="chrome_html" />
<structure name="IDR_NEW_TAB_4_HTML" file="resources\ntp4\new_tab.html" flattenhtml="true" type="chrome_html" />
<structure name="IDR_NEW_TAB_4_THEME_CSS" file="resources\ntp4\new_tab_theme.css" flattenhtml="true" type="chrome_html" />
<!-- New Tab Page WebUI. -->
<structure name="IDR_INCOGNITO_TAB_HTML" file="resources\ntp4\incognito_tab.html" compress="gzip" flattenhtml="true" type="chrome_html" />
<structure name="IDR_GUEST_TAB_HTML" file="resources\ntp4\guest_tab.html" compress="gzip" flattenhtml="true" type="chrome_html" />
<structure name="IDR_NEW_INCOGNITO_TAB_THEME_CSS" file="resources\ntp4\new_incognito_tab_theme.css" compress="gzip" flattenhtml="true" type="chrome_html" />
<structure name="IDR_NEW_TAB_4_HTML" file="resources\ntp4\new_tab.html" compress="gzip" flattenhtml="true" type="chrome_html" />
<structure name="IDR_NEW_TAB_4_THEME_CSS" file="resources\ntp4\new_tab_theme.css" compress="gzip" flattenhtml="true" type="chrome_html" />
<!-- Bookmarks WebUI. -->
<if expr="optimize_webui">
<then>
......
......@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/memory/ref_counted_memory.h"
#include "base/no_destructor.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
......@@ -136,6 +137,15 @@ std::string GetNewTabBackgroundTilingCSS(
return ThemeProperties::TilingToString(repeat_mode);
}
std::string ReplaceTemplateExpressions(
const scoped_refptr<base::RefCountedMemory>& bytes,
const ui::TemplateReplacements& replacements) {
return ui::ReplaceTemplateExpressions(
base::StringPiece(reinterpret_cast<const char*>(bytes->front()),
bytes->size()),
replacements);
}
} // namespace
NTPResourceCache::NTPResourceCache(Profile* profile)
......@@ -296,12 +306,13 @@ void NTPResourceCache::CreateNewTabIncognitoHTML() {
const std::string& app_locale = g_browser_process->GetApplicationLocale();
webui::SetLoadTimeDataDefaults(app_locale, &replacements);
static const base::StringPiece incognito_tab_html(
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_INCOGNITO_TAB_HTML));
static const base::NoDestructor<scoped_refptr<base::RefCountedMemory>>
incognito_tab_html(
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
IDR_INCOGNITO_TAB_HTML));
std::string full_html =
ui::ReplaceTemplateExpressions(incognito_tab_html, replacements);
ReplaceTemplateExpressions(*incognito_tab_html, replacements);
new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html);
}
......@@ -311,13 +322,13 @@ void NTPResourceCache::CreateNewTabGuestHTML() {
localized_strings.SetString("title",
l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
const char* guest_tab_link = kLearnMoreGuestSessionUrl;
int guest_tab_ids = IDR_GUEST_TAB_HTML;
int guest_tab_idr = IDR_GUEST_TAB_HTML;
int guest_tab_description_ids = IDS_NEW_TAB_GUEST_SESSION_DESCRIPTION;
int guest_tab_heading_ids = IDS_NEW_TAB_GUEST_SESSION_HEADING;
int guest_tab_link_ids = IDS_LEARN_MORE;
#if defined(OS_CHROMEOS)
guest_tab_ids = IDR_GUEST_SESSION_TAB_HTML;
guest_tab_idr = IDR_GUEST_SESSION_TAB_HTML;
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
......@@ -361,14 +372,14 @@ void NTPResourceCache::CreateNewTabGuestHTML() {
const std::string& app_locale = g_browser_process->GetApplicationLocale();
webui::SetLoadTimeDataDefaults(app_locale, &localized_strings);
static const base::StringPiece guest_tab_html(
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
guest_tab_ids));
static const base::NoDestructor<scoped_refptr<base::RefCountedMemory>>
guest_tab_html(
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
guest_tab_idr));
ui::TemplateReplacements replacements;
ui::TemplateReplacementsFromDictionaryValue(localized_strings, &replacements);
std::string full_html =
ui::ReplaceTemplateExpressions(guest_tab_html, replacements);
ReplaceTemplateExpressions(*guest_tab_html, replacements);
new_tab_guest_html_ = base::RefCountedString::TakeString(&full_html);
}
......@@ -476,12 +487,15 @@ void NTPResourceCache::CreateNewTabHTML() {
"isUserSignedIn",
IdentityManagerFactory::GetForProfile(profile_)->HasPrimaryAccount());
// Load the new tab page appropriate for this build.
base::StringPiece new_tab_html(
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_NEW_TAB_4_HTML));
std::string full_html =
webui::GetI18nTemplateHtml(new_tab_html, &load_time_data);
// Load the new tab page template and localize it.
static const base::NoDestructor<scoped_refptr<base::RefCountedMemory>>
new_tab_html(
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
IDR_NEW_TAB_4_HTML));
std::string full_html = webui::GetI18nTemplateHtml(
base::StringPiece(reinterpret_cast<const char*>((*new_tab_html)->front()),
(*new_tab_html)->size()),
&load_time_data);
new_tab_html_ = base::RefCountedString::TakeString(&full_html);
}
......@@ -504,13 +518,14 @@ void NTPResourceCache::CreateNewTabIncognitoCSS() {
substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp);
// Get our template.
static const base::StringPiece new_tab_theme_css(
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_NEW_INCOGNITO_TAB_THEME_CSS));
static const base::NoDestructor<scoped_refptr<base::RefCountedMemory>>
new_tab_theme_css(
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
IDR_NEW_INCOGNITO_TAB_THEME_CSS));
// Create the string from our template and the replacements.
std::string full_css =
ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions);
ReplaceTemplateExpressions(*new_tab_theme_css, substitutions);
new_tab_incognito_css_ = base::RefCountedString::TakeString(&full_css);
}
......@@ -582,12 +597,13 @@ void NTPResourceCache::CreateNewTabCSS() {
tp.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ? "inline" : "none";
// Get our template.
static const base::StringPiece new_tab_theme_css(
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_NEW_TAB_4_THEME_CSS));
static const base::NoDestructor<scoped_refptr<base::RefCountedMemory>>
new_tab_theme_css(
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
IDR_NEW_TAB_4_THEME_CSS));
// Create the string from our template and the replacements.
std::string css_string =
ui::ReplaceTemplateExpressions(new_tab_theme_css, substitutions);
ReplaceTemplateExpressions(*new_tab_theme_css, substitutions);
new_tab_css_ = base::RefCountedString::TakeString(&css_string);
}
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