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 @@ ...@@ -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" /> <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>
<if expr="not is_android"> <if expr="not is_android">
<structure name="IDR_INCOGNITO_TAB_HTML" file="resources\ntp4\incognito_tab.html" flattenhtml="true" type="chrome_html" /> <!-- New Tab Page WebUI. -->
<structure name="IDR_GUEST_TAB_HTML" file="resources\ntp4\guest_tab.html" flattenhtml="true" type="chrome_html" /> <structure name="IDR_INCOGNITO_TAB_HTML" file="resources\ntp4\incognito_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" 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_TAB_4_HTML" file="resources\ntp4\new_tab.html" 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_THEME_CSS" file="resources\ntp4\new_tab_theme.css" 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. --> <!-- Bookmarks WebUI. -->
<if expr="optimize_webui"> <if expr="optimize_webui">
<then> <then>
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/no_destructor.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
...@@ -136,6 +137,15 @@ std::string GetNewTabBackgroundTilingCSS( ...@@ -136,6 +137,15 @@ std::string GetNewTabBackgroundTilingCSS(
return ThemeProperties::TilingToString(repeat_mode); 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 } // namespace
NTPResourceCache::NTPResourceCache(Profile* profile) NTPResourceCache::NTPResourceCache(Profile* profile)
...@@ -296,12 +306,13 @@ void NTPResourceCache::CreateNewTabIncognitoHTML() { ...@@ -296,12 +306,13 @@ void NTPResourceCache::CreateNewTabIncognitoHTML() {
const std::string& app_locale = g_browser_process->GetApplicationLocale(); const std::string& app_locale = g_browser_process->GetApplicationLocale();
webui::SetLoadTimeDataDefaults(app_locale, &replacements); webui::SetLoadTimeDataDefaults(app_locale, &replacements);
static const base::StringPiece incognito_tab_html( static const base::NoDestructor<scoped_refptr<base::RefCountedMemory>>
ui::ResourceBundle::GetSharedInstance().GetRawDataResource( incognito_tab_html(
IDR_INCOGNITO_TAB_HTML)); ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
IDR_INCOGNITO_TAB_HTML));
std::string full_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); new_tab_incognito_html_ = base::RefCountedString::TakeString(&full_html);
} }
...@@ -311,13 +322,13 @@ void NTPResourceCache::CreateNewTabGuestHTML() { ...@@ -311,13 +322,13 @@ void NTPResourceCache::CreateNewTabGuestHTML() {
localized_strings.SetString("title", localized_strings.SetString("title",
l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE)); l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE));
const char* guest_tab_link = kLearnMoreGuestSessionUrl; 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_description_ids = IDS_NEW_TAB_GUEST_SESSION_DESCRIPTION;
int guest_tab_heading_ids = IDS_NEW_TAB_GUEST_SESSION_HEADING; int guest_tab_heading_ids = IDS_NEW_TAB_GUEST_SESSION_HEADING;
int guest_tab_link_ids = IDS_LEARN_MORE; int guest_tab_link_ids = IDS_LEARN_MORE;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
guest_tab_ids = IDR_GUEST_SESSION_TAB_HTML; guest_tab_idr = IDR_GUEST_SESSION_TAB_HTML;
policy::BrowserPolicyConnectorChromeOS* connector = policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos(); g_browser_process->platform_part()->browser_policy_connector_chromeos();
...@@ -361,14 +372,14 @@ void NTPResourceCache::CreateNewTabGuestHTML() { ...@@ -361,14 +372,14 @@ void NTPResourceCache::CreateNewTabGuestHTML() {
const std::string& app_locale = g_browser_process->GetApplicationLocale(); const std::string& app_locale = g_browser_process->GetApplicationLocale();
webui::SetLoadTimeDataDefaults(app_locale, &localized_strings); webui::SetLoadTimeDataDefaults(app_locale, &localized_strings);
static const base::StringPiece guest_tab_html( static const base::NoDestructor<scoped_refptr<base::RefCountedMemory>>
ui::ResourceBundle::GetSharedInstance().GetRawDataResource( guest_tab_html(
guest_tab_ids)); ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
guest_tab_idr));
ui::TemplateReplacements replacements; ui::TemplateReplacements replacements;
ui::TemplateReplacementsFromDictionaryValue(localized_strings, &replacements); ui::TemplateReplacementsFromDictionaryValue(localized_strings, &replacements);
std::string full_html = std::string full_html =
ui::ReplaceTemplateExpressions(guest_tab_html, replacements); ReplaceTemplateExpressions(*guest_tab_html, replacements);
new_tab_guest_html_ = base::RefCountedString::TakeString(&full_html); new_tab_guest_html_ = base::RefCountedString::TakeString(&full_html);
} }
...@@ -476,12 +487,15 @@ void NTPResourceCache::CreateNewTabHTML() { ...@@ -476,12 +487,15 @@ void NTPResourceCache::CreateNewTabHTML() {
"isUserSignedIn", "isUserSignedIn",
IdentityManagerFactory::GetForProfile(profile_)->HasPrimaryAccount()); IdentityManagerFactory::GetForProfile(profile_)->HasPrimaryAccount());
// Load the new tab page appropriate for this build. // Load the new tab page template and localize it.
base::StringPiece new_tab_html( static const base::NoDestructor<scoped_refptr<base::RefCountedMemory>>
ui::ResourceBundle::GetSharedInstance().GetRawDataResource( new_tab_html(
IDR_NEW_TAB_4_HTML)); ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
std::string full_html = IDR_NEW_TAB_4_HTML));
webui::GetI18nTemplateHtml(new_tab_html, &load_time_data); 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); new_tab_html_ = base::RefCountedString::TakeString(&full_html);
} }
...@@ -504,13 +518,14 @@ void NTPResourceCache::CreateNewTabIncognitoCSS() { ...@@ -504,13 +518,14 @@ void NTPResourceCache::CreateNewTabIncognitoCSS() {
substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp); substitutions["backgroundTiling"] = GetNewTabBackgroundTilingCSS(tp);
// Get our template. // Get our template.
static const base::StringPiece new_tab_theme_css( static const base::NoDestructor<scoped_refptr<base::RefCountedMemory>>
ui::ResourceBundle::GetSharedInstance().GetRawDataResource( new_tab_theme_css(
IDR_NEW_INCOGNITO_TAB_THEME_CSS)); ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
IDR_NEW_INCOGNITO_TAB_THEME_CSS));
// Create the string from our template and the replacements. // Create the string from our template and the replacements.
std::string full_css = 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); new_tab_incognito_css_ = base::RefCountedString::TakeString(&full_css);
} }
...@@ -582,12 +597,13 @@ void NTPResourceCache::CreateNewTabCSS() { ...@@ -582,12 +597,13 @@ void NTPResourceCache::CreateNewTabCSS() {
tp.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ? "inline" : "none"; tp.HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ? "inline" : "none";
// Get our template. // Get our template.
static const base::StringPiece new_tab_theme_css( static const base::NoDestructor<scoped_refptr<base::RefCountedMemory>>
ui::ResourceBundle::GetSharedInstance().GetRawDataResource( new_tab_theme_css(
IDR_NEW_TAB_4_THEME_CSS)); ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
IDR_NEW_TAB_4_THEME_CSS));
// Create the string from our template and the replacements. // Create the string from our template and the replacements.
std::string css_string = 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); 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