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

Side by Side Diff: Source/core/rendering/shapes/ShapeOutsideInfo.cpp

Issue 305173003: Heap-use-after-free in WebCore::GraphicsContext::drawImage (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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 unified diff | Download patch
« no previous file with comments | « Source/core/rendering/shapes/ShapeOutsideInfo.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (imageResource.isAccessAllowed(document.securityOrigin())) 90 if (imageResource.isAccessAllowed(document.securityOrigin()))
91 return true; 91 return true;
92 92
93 const KURL& url = imageResource.url(); 93 const KURL& url = imageResource.url();
94 String urlString = url.isNull() ? "''" : url.elidedString(); 94 String urlString = url.isNull() ? "''" : url.elidedString();
95 document.addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, "Unsafe attempt to load URL " + urlString + "."); 95 document.addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, "Unsafe attempt to load URL " + urlString + ".");
96 96
97 return false; 97 return false;
98 } 98 }
99 99
100 static void getShapeImageAndRect(const ShapeValue& shapeValue, const RenderBox& renderBox, const LayoutSize& referenceBoxSize, Image*& image, LayoutRect& rect)
101 {
102 ASSERT(shapeValue.isImageValid());
103 StyleImage* styleImage = shapeValue.image();
104
105 const IntSize& imageSize = renderBox.calculateImageIntrinsicDimensions(style Image, roundedIntSize(referenceBoxSize), RenderImage::ScaleByEffectiveZoom);
106 styleImage->setContainerSizeForRenderer(&renderBox, imageSize, renderBox.sty le()->effectiveZoom());
107
108 image = 0;
109 if (styleImage->isImageResource() || styleImage->isImageResourceSet())
110 image = styleImage->cachedImage()->imageForRenderer(&renderBox);
111 else if (styleImage->isGeneratedImage())
112 image = styleImage->image(const_cast<RenderBox*>(&renderBox), imageSize) .get();
113
114 if (renderBox.isRenderImage())
115 rect = toRenderImage(&renderBox)->replacedContentRect();
116 else
117 rect = LayoutRect(LayoutPoint(), imageSize);
118 }
119
120 static LayoutRect getShapeImageMarginRect(const RenderBox& renderBox, const Layo utSize& referenceBoxLogicalSize) 100 static LayoutRect getShapeImageMarginRect(const RenderBox& renderBox, const Layo utSize& referenceBoxLogicalSize)
121 { 101 {
122 LayoutPoint marginBoxOrigin(-renderBox.marginLogicalLeft() - renderBox.borde rAndPaddingLogicalLeft(), -renderBox.marginBefore() - renderBox.borderBefore() - renderBox.paddingBefore()); 102 LayoutPoint marginBoxOrigin(-renderBox.marginLogicalLeft() - renderBox.borde rAndPaddingLogicalLeft(), -renderBox.marginBefore() - renderBox.borderBefore() - renderBox.paddingBefore());
123 LayoutSize marginBoxSizeDelta(renderBox.marginLogicalWidth() + renderBox.bor derAndPaddingLogicalWidth(), renderBox.marginLogicalHeight() + renderBox.borderA ndPaddingLogicalHeight()); 103 LayoutSize marginBoxSizeDelta(renderBox.marginLogicalWidth() + renderBox.bor derAndPaddingLogicalWidth(), renderBox.marginLogicalHeight() + renderBox.borderA ndPaddingLogicalHeight());
124 return LayoutRect(marginBoxOrigin, referenceBoxLogicalSize + marginBoxSizeDe lta); 104 return LayoutRect(marginBoxOrigin, referenceBoxLogicalSize + marginBoxSizeDe lta);
125 } 105 }
126 106
107 PassOwnPtr<Shape> ShapeOutsideInfo::createShapeForImage(StyleImage* styleImage, float shapeImageThreshold, WritingMode writingMode, float margin) const
108 {
109 const IntSize& imageSize = m_renderer.calculateImageIntrinsicDimensions(styl eImage, roundedIntSize(m_referenceBoxLogicalSize), RenderImage::ScaleByEffective Zoom);
110 styleImage->setContainerSizeForRenderer(&m_renderer, imageSize, m_renderer.s tyle()->effectiveZoom());
111
112 const LayoutRect& marginRect = getShapeImageMarginRect(m_renderer, m_referen ceBoxLogicalSize);
113 const LayoutRect& imageRect = (m_renderer.isRenderImage())
114 ? toRenderImage(&m_renderer)->replacedContentRect()
115 : LayoutRect(LayoutPoint(), imageSize);
116
117 Image* image = 0;
eseidel 2014/05/30 21:06:45 Might as well just make this a RefPtr and then cal
118 RefPtr<Image> generatedImage;
rwlbuis 2014/05/30 21:14:05 Nit: could move this into the else if section sinc
119
120 if (styleImage->isImageResource() || styleImage->isImageResourceSet()) {
121 image = styleImage->cachedImage()->imageForRenderer(&m_renderer);
122 } else if (styleImage->isGeneratedImage()) {
123 generatedImage = styleImage->image(const_cast<RenderBox*>(&m_renderer), imageSize).get();
124 image = generatedImage.get();
eseidel 2014/05/30 21:22:08 I was more reacting to this line which is strange.
125 }
126
127 return Shape::createRasterShape(image, shapeImageThreshold, imageRect, margi nRect, writingMode, margin);
128 }
129
127 const Shape& ShapeOutsideInfo::computedShape() const 130 const Shape& ShapeOutsideInfo::computedShape() const
128 { 131 {
129 if (Shape* shape = m_shape.get()) 132 if (Shape* shape = m_shape.get())
130 return *shape; 133 return *shape;
131 134
132 const RenderStyle& style = *m_renderer.style(); 135 const RenderStyle& style = *m_renderer.style();
133 ASSERT(m_renderer.containingBlock()); 136 ASSERT(m_renderer.containingBlock());
134 const RenderStyle& containingBlockStyle = *m_renderer.containingBlock()->sty le(); 137 const RenderStyle& containingBlockStyle = *m_renderer.containingBlock()->sty le();
135 138
136 WritingMode writingMode = containingBlockStyle.writingMode(); 139 WritingMode writingMode = containingBlockStyle.writingMode();
137 LayoutUnit maximumValue = m_renderer.containingBlock() ? m_renderer.containi ngBlock()->contentWidth() : LayoutUnit(); 140 LayoutUnit maximumValue = m_renderer.containingBlock() ? m_renderer.containi ngBlock()->contentWidth() : LayoutUnit();
138 float margin = floatValueForLength(m_renderer.style()->shapeMargin(), maximu mValue.toFloat()); 141 float margin = floatValueForLength(m_renderer.style()->shapeMargin(), maximu mValue.toFloat());
139 142
140 float shapeImageThreshold = style.shapeImageThreshold(); 143 float shapeImageThreshold = style.shapeImageThreshold();
141 ASSERT(style.shapeOutside()); 144 ASSERT(style.shapeOutside());
142 const ShapeValue& shapeValue = *style.shapeOutside(); 145 const ShapeValue& shapeValue = *style.shapeOutside();
143 146
144 switch (shapeValue.type()) { 147 switch (shapeValue.type()) {
145 case ShapeValue::Shape: 148 case ShapeValue::Shape:
146 ASSERT(shapeValue.shape()); 149 ASSERT(shapeValue.shape());
147 m_shape = Shape::createShape(shapeValue.shape(), m_referenceBoxLogicalSi ze, writingMode, margin); 150 m_shape = Shape::createShape(shapeValue.shape(), m_referenceBoxLogicalSi ze, writingMode, margin);
148 break; 151 break;
149 case ShapeValue::Image: { 152 case ShapeValue::Image:
150 Image* image; 153 ASSERT(shapeValue.isImageValid());
151 LayoutRect imageRect; 154 m_shape = createShapeForImage(shapeValue.image(), shapeImageThreshold, w ritingMode, margin);
152 getShapeImageAndRect(shapeValue, m_renderer, m_referenceBoxLogicalSize, image, imageRect);
153 const LayoutRect& marginRect = getShapeImageMarginRect(m_renderer, m_ref erenceBoxLogicalSize);
154 m_shape = Shape::createRasterShape(image, shapeImageThreshold, imageRect , marginRect, writingMode, margin);
155 break; 155 break;
156 }
157 case ShapeValue::Box: { 156 case ShapeValue::Box: {
158 const RoundedRect& shapeRect = style.getRoundedBorderFor(LayoutRect(Layo utPoint(), m_referenceBoxLogicalSize), m_renderer.view()); 157 const RoundedRect& shapeRect = style.getRoundedBorderFor(LayoutRect(Layo utPoint(), m_referenceBoxLogicalSize), m_renderer.view());
159 m_shape = Shape::createLayoutBoxShape(shapeRect, writingMode, margin); 158 m_shape = Shape::createLayoutBoxShape(shapeRect, writingMode, margin);
160 break; 159 break;
161 } 160 }
162 } 161 }
163 162
164 ASSERT(m_shape); 163 ASSERT(m_shape);
165 return *m_shape; 164 return *m_shape;
166 } 165 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 345 }
347 346
348 FloatSize ShapeOutsideInfo::shapeToRendererSize(FloatSize size) const 347 FloatSize ShapeOutsideInfo::shapeToRendererSize(FloatSize size) const
349 { 348 {
350 if (!m_renderer.style()->isHorizontalWritingMode()) 349 if (!m_renderer.style()->isHorizontalWritingMode())
351 return size.transposedSize(); 350 return size.transposedSize();
352 return size; 351 return size;
353 } 352 }
354 353
355 } 354 }
OLDNEW
« no previous file with comments | « Source/core/rendering/shapes/ShapeOutsideInfo.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698