Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7281)

Unified Diff: chrome/browser/ui/webui/theme_source.cc

Issue 2279373002: Refix bug 497949 in a more efficient way that also doesn't rebreak bug 442384. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup
Patch Set: Add dependency Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/theme_source.cc
diff --git a/chrome/browser/ui/webui/theme_source.cc b/chrome/browser/ui/webui/theme_source.cc
index 68a5f8b834904e57f724501aabb7c2c3b2c97da1..3d70ed81312d87a21136c4bd0d1d6f8407e88b5c 100644
--- a/chrome/browser/ui/webui/theme_source.cc
+++ b/chrome/browser/ui/webui/theme_source.cc
@@ -92,7 +92,6 @@ void ThemeSource::StartDataRequest(
float scale = 1.0f;
std::string parsed_path;
webui::ParsePathAndScale(GetThemeURL(path), &parsed_path, &scale);
- scale = ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(scale));
if (IsNewTabCSSPath(parsed_path)) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
@@ -131,13 +130,20 @@ void ThemeSource::StartDataRequest(
resource_id = ResourcesUtil::GetThemeResourceId(parsed_path);
}
+ // Limit the maximum scale we'll respond to. Very large scale factors can
+ // take significant time to serve or, at worst, crash the browser due to OOM.
+ // We don't want to clamp to the max scale factor, though, for devices that
+ // use 2x scale without 2x data packs, as well as omnibox requests for larger
+ // (but still reasonable) scales (see below).
const float max_scale = ui::GetScaleForScaleFactor(
ResourceBundle::GetSharedInstance().GetMaxScaleFactor());
- if (resource_id == -1) {
- // We have no data to send back. This shouldn't happen normally, as
- // chrome://theme/ URLs are only used by WebUI pages and component
- // extensions. However, the user can also enter these into the omnibox, so
- // we need to fail gracefully.
+ const float unreasonable_scale = max_scale * 32;
+ if ((resource_id == -1) || (scale >= unreasonable_scale)) {
+ // Either we have no data to send back, or the requested scale is
+ // unreasonably large. This shouldn't happen normally, as chrome://theme/
+ // URLs are only used by WebUI pages and component extensions. However, the
+ // user can also enter these into the omnibox, so we need to fail
+ // gracefully.
callback.Run(nullptr);
} else if ((GetMimeType(path) == "image/png") && (scale > max_scale)) {
SendThemeImage(callback, resource_id, scale);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698