Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007-2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2007-2011 Google Inc. 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "V8CSSStyleDeclaration.h" | 32 #include "V8CSSStyleDeclaration.h" |
| 33 | 33 |
| 34 #include "CSSParser.h" | 34 #include "CSSParser.h" |
| 35 #include "CSSPropertyNames.h" | 35 #include "CSSPropertyNames.h" |
| 36 #include "CSSStyleDeclaration.h" | 36 #include "CSSStyleDeclaration.h" |
| 37 #include "CSSValue.h" | 37 #include "CSSValue.h" |
| 38 #include "CSSPrimitiveValue.h" | 38 #include "CSSPrimitiveValue.h" |
| 39 #include "EventTarget.h" | 39 #include "EventTarget.h" |
| 40 #include "HashTools.h" | |
| 41 #include "RuntimeCSSEnabled.h" | |
| 40 | 42 |
| 41 #include "V8Binding.h" | 43 #include "V8Binding.h" |
| 42 | 44 |
| 43 #include <wtf/text/StringBuilder.h> | 45 #include <wtf/text/StringBuilder.h> |
| 44 #include <wtf/text/StringConcatenate.h> | 46 #include <wtf/text/StringConcatenate.h> |
| 45 #include <wtf/ASCIICType.h> | 47 #include <wtf/ASCIICType.h> |
| 46 #include <wtf/PassRefPtr.h> | 48 #include <wtf/PassRefPtr.h> |
| 47 #include <wtf/RefPtr.h> | 49 #include <wtf/RefPtr.h> |
| 48 #include <wtf/StdLibExtras.h> | 50 #include <wtf/StdLibExtras.h> |
| 49 #include <wtf/Vector.h> | 51 #include <wtf/Vector.h> |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 for (; i < length; ++i) { | 136 for (; i < length; ++i) { |
| 135 UChar c = propertyName[i]; | 137 UChar c = propertyName[i]; |
| 136 if (!isASCIIUpper(c)) | 138 if (!isASCIIUpper(c)) |
| 137 builder.append(c); | 139 builder.append(c); |
| 138 else | 140 else |
| 139 builder.append(makeString('-', toASCIILower(c))); | 141 builder.append(makeString('-', toASCIILower(c))); |
| 140 } | 142 } |
| 141 | 143 |
| 142 String propName = builder.toString(); | 144 String propName = builder.toString(); |
| 143 CSSPropertyID propertyID = cssPropertyID(propName); | 145 CSSPropertyID propertyID = cssPropertyID(propName); |
| 144 if (propertyID) { | 146 if (propertyID && RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID)) { |
| 145 propInfo = new CSSPropertyInfo(); | 147 propInfo = new CSSPropertyInfo(); |
| 146 propInfo->hadPixelOrPosPrefix = hadPixelOrPosPrefix; | 148 propInfo->hadPixelOrPosPrefix = hadPixelOrPosPrefix; |
| 147 propInfo->propID = propertyID; | 149 propInfo->propID = propertyID; |
| 148 map.add(propertyName, propInfo); | 150 map.add(propertyName, propInfo); |
| 149 } | 151 } |
| 150 } | 152 } |
| 151 return propInfo; | 153 return propInfo; |
| 152 } | 154 } |
| 153 | 155 |
| 156 static bool isCSSValueEnabled(String& value) | |
| 157 { | |
| 158 const struct Value* propertyValue = findValue( | |
| 159 reinterpret_cast<const char*>(value.characters8()), | |
| 160 value.length()); | |
| 161 | |
| 162 if (!propertyValue) | |
| 163 return true; | |
| 164 return RuntimeCSSEnabled::isCSSValueEnabled( | |
| 165 static_cast<CSSValueID>(propertyValue->id)); | |
| 166 } | |
| 167 | |
| 168 static bool isValueOfPropertyEnabled(CSSStyleDeclaration* imp, v8::Local<v8::Str ing> propertyName) | |
| 169 { | |
| 170 if (!imp) | |
| 171 return true; | |
| 172 | |
| 173 CSSPropertyInfo* propInfo = cssPropertyInfo(propertyName); | |
| 174 if (!propInfo || propInfo->propID == CSSPropertyInvalid) | |
|
eseidel
2013/04/23 01:36:36
When is CSSPropertyInvalid ever possible in propIn
| |
| 175 return true; | |
| 176 | |
| 177 String propertyValueName = imp->getPropertyValueInternal(propInfo->propID); | |
| 178 if (propertyValueName.isEmpty()) | |
| 179 return true; | |
| 180 return isCSSValueEnabled(propertyValueName); | |
| 181 } | |
| 182 | |
| 154 v8::Handle<v8::Array> V8CSSStyleDeclaration::namedPropertyEnumerator(const v8::A ccessorInfo& info) | 183 v8::Handle<v8::Array> V8CSSStyleDeclaration::namedPropertyEnumerator(const v8::A ccessorInfo& info) |
| 155 { | 184 { |
| 156 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector; | 185 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector; |
| 157 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ()); | 186 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ()); |
| 158 static unsigned propertyNamesLength = 0; | 187 static unsigned propertyNamesLength = 0; |
| 159 | 188 |
| 160 if (propertyNames.isEmpty()) { | 189 if (propertyNames.isEmpty()) { |
| 161 for (int id = firstCSSProperty; id < firstCSSProperty + numCSSProperties ; ++id) | 190 for (int id = firstCSSProperty; id < firstCSSProperty + numCSSProperties ; ++id) |
| 162 propertyNames.append(getJSPropertyName(static_cast<CSSPropertyID>(id ))); | 191 if (RuntimeCSSEnabled::isCSSPropertyEnabled(static_cast<CSSPropertyI D>(id))) |
| 192 propertyNames.append(getJSPropertyName(static_cast<CSSPropertyID >(id))); | |
| 163 sort(propertyNames.begin(), propertyNames.end(), codePointCompareLessTha n); | 193 sort(propertyNames.begin(), propertyNames.end(), codePointCompareLessTha n); |
| 164 propertyNamesLength = propertyNames.size(); | 194 propertyNamesLength = propertyNames.size(); |
| 165 } | 195 } |
| 166 | 196 |
| 167 v8::Handle<v8::Array> properties = v8::Array::New(propertyNamesLength); | 197 v8::Handle<v8::Array> properties = v8::Array::New(propertyNamesLength); |
| 168 for (unsigned i = 0; i < propertyNamesLength; ++i) { | 198 for (unsigned i = 0; i < propertyNamesLength; ++i) { |
| 169 String key = propertyNames.at(i); | 199 String key = propertyNames.at(i); |
| 170 ASSERT(!key.isNull()); | 200 ASSERT(!key.isNull()); |
| 171 properties->Set(v8Integer(i, info.GetIsolate()), v8String(key, info.GetI solate())); | 201 properties->Set(v8Integer(i, info.GetIsolate()), v8String(key, info.GetI solate())); |
| 172 } | 202 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 189 return v8Undefined(); | 219 return v8Undefined(); |
| 190 | 220 |
| 191 // Search the style declaration. | 221 // Search the style declaration. |
| 192 CSSPropertyInfo* propInfo = cssPropertyInfo(name); | 222 CSSPropertyInfo* propInfo = cssPropertyInfo(name); |
| 193 | 223 |
| 194 // Do not handle non-property names. | 224 // Do not handle non-property names. |
| 195 if (!propInfo) | 225 if (!propInfo) |
| 196 return v8Undefined(); | 226 return v8Undefined(); |
| 197 | 227 |
| 198 CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder()); | 228 CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder()); |
| 229 if (!isValueOfPropertyEnabled(imp, name)) | |
| 230 return v8Undefined(); | |
| 231 | |
| 199 RefPtr<CSSValue> cssValue = imp->getPropertyCSSValueInternal(static_cast<CSS PropertyID>(propInfo->propID)); | 232 RefPtr<CSSValue> cssValue = imp->getPropertyCSSValueInternal(static_cast<CSS PropertyID>(propInfo->propID)); |
| 200 if (cssValue) { | 233 if (cssValue) { |
| 201 if (propInfo->hadPixelOrPosPrefix && | 234 if (propInfo->hadPixelOrPosPrefix && |
| 202 cssValue->isPrimitiveValue()) { | 235 cssValue->isPrimitiveValue()) { |
| 203 return v8::Number::New(static_cast<CSSPrimitiveValue*>( | 236 return v8::Number::New(static_cast<CSSPrimitiveValue*>( |
| 204 cssValue.get())->getFloatValue(CSSPrimitiveValue::CSS_PX)); | 237 cssValue.get())->getFloatValue(CSSPrimitiveValue::CSS_PX)); |
| 205 } | 238 } |
| 206 return v8StringOrNull(cssValue->cssText(), info.GetIsolate()); | 239 return v8StringOrNull(cssValue->cssText(), info.GetIsolate()); |
| 207 } | 240 } |
| 208 | 241 |
| 209 String result = imp->getPropertyValueInternal(static_cast<CSSPropertyID>(pro pInfo->propID)); | 242 String result = imp->getPropertyValueInternal(static_cast<CSSPropertyID>(pro pInfo->propID)); |
| 210 if (result.isNull()) | 243 if (result.isNull()) |
| 211 result = ""; // convert null to empty string. | 244 result = ""; // convert null to empty string. |
| 212 | 245 |
| 213 return v8String(result, info.GetIsolate()); | 246 return v8String(result, info.GetIsolate()); |
| 214 } | 247 } |
| 215 | 248 |
| 216 v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertySetter(v8::Local<v8::S tring> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) | 249 v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertySetter(v8::Local<v8::S tring> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) |
| 217 { | 250 { |
| 251 String wsValue = toWebCoreString(value); | |
| 252 if (!isCSSValueEnabled(wsValue)) | |
|
eseidel
2013/04/23 01:32:00
I don't believe this part is correct or necessary.
| |
| 253 return v8Undefined(); | |
| 254 | |
| 218 CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder()); | 255 CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder()); |
| 219 CSSPropertyInfo* propInfo = cssPropertyInfo(name); | 256 CSSPropertyInfo* propInfo = cssPropertyInfo(name); |
| 220 if (!propInfo) | 257 if (!propInfo) |
| 221 return v8Undefined(); | 258 return v8Undefined(); |
| 222 | 259 |
| 223 String propertyValue = toWebCoreStringWithNullCheck(value); | 260 String propertyValue = toWebCoreStringWithNullCheck(value); |
| 224 if (propInfo->hadPixelOrPosPrefix) | 261 if (propInfo->hadPixelOrPosPrefix) |
| 225 propertyValue.append("px"); | 262 propertyValue.append("px"); |
| 226 | 263 |
| 227 ExceptionCode ec = 0; | 264 ExceptionCode ec = 0; |
| 228 imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prope rtyValue, false, ec); | 265 imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prope rtyValue, false, ec); |
| 229 | 266 |
| 230 if (ec) | 267 if (ec) |
| 231 setDOMException(ec, info.GetIsolate()); | 268 setDOMException(ec, info.GetIsolate()); |
| 232 | 269 |
| 233 return value; | 270 return value; |
| 234 } | 271 } |
| 235 | 272 |
| 236 } // namespace WebCore | 273 } // namespace WebCore |
| OLD | NEW |