Commit a3a883ee authored by Kyle Milka's avatar Kyle Milka Committed by Commit Bot

[NTP] Preload custom background image

Specify the custom background image via a <link rel="preload"...>
tag that's inserted at the time the page is served.

Bug: 853042
Change-Id: Id24b1815c66b32f04b1811e55c54b5066cfc9873
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1592122Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Reviewed-by: default avatarKristi Park <kristipark@chromium.org>
Commit-Queue: Kyle Milka <kmilka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657446}
parent 7df39b2d
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<link rel="stylesheet" href="chrome-search://local-ntp/local-ntp.css"></link> <link rel="stylesheet" href="chrome-search://local-ntp/local-ntp.css"></link>
<link rel="stylesheet" href="chrome-search://local-ntp/theme.css"></link> <link rel="stylesheet" href="chrome-search://local-ntp/theme.css"></link>
<link rel="stylesheet" href="chrome-search://local-ntp/voice.css"></link> <link rel="stylesheet" href="chrome-search://local-ntp/voice.css"></link>
$i18nRaw{bgPreloader}
<meta http-equiv="Content-Security-Policy" <meta http-equiv="Content-Security-Policy"
content="$i18nRaw{contentSecurityPolicy}"> content="$i18nRaw{contentSecurityPolicy}">
<script src="chrome-search://local-ntp/animations.js" <script src="chrome-search://local-ntp/animations.js"
......
...@@ -534,6 +534,29 @@ std::string GetErrorDict(const ErrorInfo& error) { ...@@ -534,6 +534,29 @@ std::string GetErrorDict(const ErrorInfo& error) {
return js_text; return js_text;
} }
// Return the URL that the custom background should be loaded from.
// Either chrome-search://local-ntp/background.jpg or a valid, secure URL.
GURL GetCustomBackgroundURL(PrefService* pref_service) {
if (pref_service->GetBoolean(prefs::kNtpCustomBackgroundLocalToDevice))
return GURL(chrome::kChromeSearchLocalNtpBackgroundUrl);
const base::DictionaryValue* background_info =
pref_service->GetDictionary(prefs::kNtpCustomBackgroundDict);
if (!background_info)
return GURL();
const base::Value* background_url =
background_info->FindKey("background_url");
if (!background_url)
return GURL();
GURL url(background_url->GetString());
if (!url.is_valid() || !url.SchemeIs(url::kHttpsScheme))
return GURL();
return url;
}
} // namespace } // namespace
// Keeps the search engine configuration data to be included on the Local NTP, // Keeps the search engine configuration data to be included on the Local NTP,
...@@ -973,6 +996,14 @@ void LocalNtpSource::StartDataRequest( ...@@ -973,6 +996,14 @@ void LocalNtpSource::StartDataRequest(
replacements["colorsOption"] = base::UTF16ToUTF8( replacements["colorsOption"] = base::UTF16ToUTF8(
l10n_util::GetStringUTF16(IDS_NTP_CUSTOMIZE_MENU_COLORS_LABEL)); l10n_util::GetStringUTF16(IDS_NTP_CUSTOMIZE_MENU_COLORS_LABEL));
replacements["bgPreloader"] = "";
GURL custom_background_url = GetCustomBackgroundURL(profile_->GetPrefs());
if (custom_background_url.is_valid()) {
replacements["bgPreloader"] = "<link rel=\"preload\" href=\"" +
custom_background_url.spec() +
"\" as=\"image\">";
}
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
base::StringPiece html = bundle.GetRawDataResource(IDR_LOCAL_NTP_HTML); base::StringPiece html = bundle.GetRawDataResource(IDR_LOCAL_NTP_HTML);
std::string replaced = ui::ReplaceTemplateExpressions(html, replacements); std::string replaced = ui::ReplaceTemplateExpressions(html, replacements);
......
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