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

Unified Diff: ui/native_theme/native_theme_win.cc

Issue 2355423002: Harden NativeThemeWin::PaintIndirect() (Closed)
Patch Set: first pass at Peter's requested comments Created 4 years, 3 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: ui/native_theme/native_theme_win.cc
diff --git a/ui/native_theme/native_theme_win.cc b/ui/native_theme/native_theme_win.cc
index 043a3d47278a278e01d1c455157a9ae06ceec4b9..6dc57e9dbc0aa3a53ed107c84153bcb225112d2a 100644
--- a/ui/native_theme/native_theme_win.cc
+++ b/ui/native_theme/native_theme_win.cc
@@ -665,11 +665,21 @@ void NativeThemeWin::PaintIndirect(SkCanvas* destination_canvas,
// keeping a cache of the resulting bitmaps.
// Create an offscreen canvas that is backed by an HDC.
+ // This can fail if we don't have access to GDI or if lower-level Windows
+ // calls fail, possibly due to GDI handle exhaustion.
base::win::ScopedCreateDC offscreen_hdc(
skia::CreateOffscreenSurface(rect.width(), rect.height()));
+ if (!offscreen_hdc.IsValid())
+ return;
+
+ // Will be NULL if lower-level Windows calls fail, or if the backing
+ // allocated is 0 pixels in size (which should never happen according to
+ // Windows documentation).
sk_sp<SkSurface> offscreen_surface =
skia::MapPlatformSurface(offscreen_hdc.Get());
- DCHECK(offscreen_surface);
+ if (!offscreen_surface)
+ return;
+
SkCanvas* offscreen_canvas = offscreen_surface->getCanvas();
DCHECK(offscreen_canvas);
« 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