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

Side by Side Diff: Source/core/css/CSSPrimitiveValue.cpp

Issue 864143006: Remove unsafe DEFINE_STATIC_LOCALs in CSSPrimitiveValue (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.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 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 18 matching lines...) Expand all
29 #include "core/css/Counter.h" 29 #include "core/css/Counter.h"
30 #include "core/css/Pair.h" 30 #include "core/css/Pair.h"
31 #include "core/css/Rect.h" 31 #include "core/css/Rect.h"
32 #include "core/css/StyleSheetContents.h" 32 #include "core/css/StyleSheetContents.h"
33 #include "core/dom/Node.h" 33 #include "core/dom/Node.h"
34 #include "core/rendering/style/RenderStyle.h" 34 #include "core/rendering/style/RenderStyle.h"
35 #include "platform/Decimal.h" 35 #include "platform/Decimal.h"
36 #include "platform/LayoutUnit.h" 36 #include "platform/LayoutUnit.h"
37 #include "platform/fonts/FontMetrics.h" 37 #include "platform/fonts/FontMetrics.h"
38 #include "wtf/StdLibExtras.h" 38 #include "wtf/StdLibExtras.h"
39 #include "wtf/ThreadSpecific.h"
40 #include "wtf/Threading.h"
39 #include "wtf/text/StringBuffer.h" 41 #include "wtf/text/StringBuffer.h"
40 #include "wtf/text/StringBuilder.h" 42 #include "wtf/text/StringBuilder.h"
41 43
42 using namespace WTF; 44 using namespace WTF;
43 45
44 namespace blink { 46 namespace blink {
45 47
48 namespace {
49
46 // Max/min values for CSS, needs to slightly smaller/larger than the true max/mi n values to allow for rounding without overflowing. 50 // Max/min values for CSS, needs to slightly smaller/larger than the true max/mi n values to allow for rounding without overflowing.
47 // Subtract two (rather than one) to allow for values to be converted to float a nd back without exceeding the LayoutUnit::max. 51 // Subtract two (rather than one) to allow for values to be converted to float a nd back without exceeding the LayoutUnit::max.
48 const int maxValueForCssLength = INT_MAX / kFixedPointDenominator - 2; 52 const int maxValueForCssLength = INT_MAX / kFixedPointDenominator - 2;
49 const int minValueForCssLength = INT_MIN / kFixedPointDenominator + 2; 53 const int minValueForCssLength = INT_MIN / kFixedPointDenominator + 2;
50 54
51 static inline bool isValidCSSUnitTypeForDoubleConversion(CSSPrimitiveValue::Unit Type unitType) 55 static inline bool isValidCSSUnitTypeForDoubleConversion(CSSPrimitiveValue::Unit Type unitType)
52 { 56 {
53 switch (unitType) { 57 switch (unitType) {
54 case CSSPrimitiveValue::CSS_CALC: 58 case CSSPrimitiveValue::CSS_CALC:
55 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER: 59 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER:
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 table.set(String("vh"), CSSPrimitiveValue::CSS_VH); 136 table.set(String("vh"), CSSPrimitiveValue::CSS_VH);
133 table.set(String("vmin"), CSSPrimitiveValue::CSS_VMIN); 137 table.set(String("vmin"), CSSPrimitiveValue::CSS_VMIN);
134 table.set(String("vmax"), CSSPrimitiveValue::CSS_VMAX); 138 table.set(String("vmax"), CSSPrimitiveValue::CSS_VMAX);
135 table.set(String("rem"), CSSPrimitiveValue::CSS_REMS); 139 table.set(String("rem"), CSSPrimitiveValue::CSS_REMS);
136 table.set(String("fr"), CSSPrimitiveValue::CSS_FR); 140 table.set(String("fr"), CSSPrimitiveValue::CSS_FR);
137 table.set(String("turn"), CSSPrimitiveValue::CSS_TURN); 141 table.set(String("turn"), CSSPrimitiveValue::CSS_TURN);
138 table.set(String("ch"), CSSPrimitiveValue::CSS_CHS); 142 table.set(String("ch"), CSSPrimitiveValue::CSS_CHS);
139 return table; 143 return table;
140 } 144 }
141 145
146 StringToUnitTable& unitTable()
147 {
148 DEFINE_STATIC_LOCAL(StringToUnitTable, unitTable, (createStringToUnitTable() ));
149 return unitTable;
150 }
151
152 } // namespace
153
154 void CSSPrimitiveValue::initUnitTable()
155 {
156 // Make sure we initialize this during blink initialization
157 // to avoid racy static local initialization.
158 unitTable();
159 }
160
142 CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const String& unit) 161 CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const String& unit)
143 { 162 {
144 DEFINE_STATIC_LOCAL(StringToUnitTable, unitTable, (createStringToUnitTable() )); 163 return unitTable().get(unit.lower());
145 return unitTable.get(unit.lower());
146 } 164 }
147 165
148 CSSPrimitiveValue::UnitCategory CSSPrimitiveValue::unitCategory(UnitType type) 166 CSSPrimitiveValue::UnitCategory CSSPrimitiveValue::unitCategory(UnitType type)
149 { 167 {
150 // Here we violate the spec (http://www.w3.org/TR/DOM-Level-2-Style/css.html #CSS-CSSPrimitiveValue) and allow conversions 168 // Here we violate the spec (http://www.w3.org/TR/DOM-Level-2-Style/css.html #CSS-CSSPrimitiveValue) and allow conversions
151 // between CSS_PX and relative lengths (see cssPixelsPerInch comment in core /css/CSSHelper.h for the topic treatment). 169 // between CSS_PX and relative lengths (see cssPixelsPerInch comment in core /css/CSSHelper.h for the topic treatment).
152 switch (type) { 170 switch (type) {
153 case CSS_NUMBER: 171 case CSS_NUMBER:
154 return CSSPrimitiveValue::UNumber; 172 return CSSPrimitiveValue::UNumber;
155 case CSS_PERCENTAGE: 173 case CSS_PERCENTAGE:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 case CSSValueCurrentcolor: 209 case CSSValueCurrentcolor:
192 return true; 210 return true;
193 default: 211 default:
194 return false; 212 return false;
195 } 213 }
196 } 214 }
197 215
198 typedef HashMap<const CSSPrimitiveValue*, String> CSSTextCache; 216 typedef HashMap<const CSSPrimitiveValue*, String> CSSTextCache;
199 static CSSTextCache& cssTextCache() 217 static CSSTextCache& cssTextCache()
200 { 218 {
201 DEFINE_STATIC_LOCAL(CSSTextCache, cache, ()); 219 AtomicallyInitializedStaticReference(ThreadSpecific<CSSTextCache>, cache, ne w ThreadSpecific<CSSTextCache>());
sof 2015/12/02 13:32:41 fwiw, http/tests/misc/client-hints-picture-source-
202 return cache; 220 return *cache;
203 } 221 }
204 222
205 CSSPrimitiveValue::UnitType CSSPrimitiveValue::primitiveType() const 223 CSSPrimitiveValue::UnitType CSSPrimitiveValue::primitiveType() const
206 { 224 {
207 if (m_primitiveUnitType == CSS_PROPERTY_ID || m_primitiveUnitType == CSS_VAL UE_ID) 225 if (m_primitiveUnitType == CSS_PROPERTY_ID || m_primitiveUnitType == CSS_VAL UE_ID)
208 return CSS_IDENT; 226 return CSS_IDENT;
209 227
210 if (m_primitiveUnitType != CSS_CALC) 228 if (m_primitiveUnitType != CSS_CALC)
211 return static_cast<UnitType>(m_primitiveUnitType); 229 return static_cast<UnitType>(m_primitiveUnitType);
212 230
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 visitor->trace(m_value.shape); 1238 visitor->trace(m_value.shape);
1221 break; 1239 break;
1222 default: 1240 default:
1223 break; 1241 break;
1224 } 1242 }
1225 #endif 1243 #endif
1226 CSSValue::traceAfterDispatch(visitor); 1244 CSSValue::traceAfterDispatch(visitor);
1227 } 1245 }
1228 1246
1229 } // namespace blink 1247 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698