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

Unified Diff: Source/core/html/canvas/CanvasRenderingContext2D.cpp

Issue 186063003: Prevent crash when calling text-related methods on a 2D canvas in a frame-less document. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed test Created 6 years, 10 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 | « LayoutTests/fast/canvas/script-tests/canvas-frameless-document-text.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/canvas/CanvasRenderingContext2D.cpp
diff --git a/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
index 9707f9a2e3cc298eee4f138b0cd6b3b0a9e842ff..ede1ee636ac6cd82da99f165b07d3d834bc1c45a 100644
--- a/Source/core/html/canvas/CanvasRenderingContext2D.cpp
+++ b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
@@ -2081,6 +2081,10 @@ String CanvasRenderingContext2D::font() const
void CanvasRenderingContext2D::setFont(const String& newFont)
{
+ // The style resolution required for rendering text is not available in frame-less documents.
+ if (!canvas()->document().frame())
+ return;
+
MutableStylePropertyMap::iterator i = m_fetchedFonts.find(newFont);
RefPtr<MutableStylePropertySet> parsedStyle = i != m_fetchedFonts.end() ? i->value : nullptr;
@@ -2199,8 +2203,13 @@ void CanvasRenderingContext2D::strokeText(const String& text, float x, float y,
PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text)
{
- FontCachePurgePreventer fontCachePurgePreventer;
RefPtr<TextMetrics> metrics = TextMetrics::create();
+
+ // The style resolution required for rendering text is not available in frame-less documents.
+ if (!canvas()->document().frame())
+ return metrics.release();
+
+ FontCachePurgePreventer fontCachePurgePreventer;
canvas()->document().updateStyleIfNeeded();
metrics->setWidth(accessFont().width(TextRun(text)));
return metrics.release();
@@ -2218,6 +2227,10 @@ static void replaceCharacterInString(String& text, WTF::CharacterMatchFunctionPt
void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, float y, bool fill, float maxWidth, bool useMaxWidth)
{
+ // The style resolution required for rendering text is not available in frame-less documents.
+ if (!canvas()->document().frame())
+ return;
+
// accessFont needs the style to be up to date, but updating style can cause script to run,
// (e.g. due to autofocus) which can free the GraphicsContext, so update style before grabbing
// the GraphicsContext.
« no previous file with comments | « LayoutTests/fast/canvas/script-tests/canvas-frameless-document-text.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698