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 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
| 35 #include "bindings/core/v8/V8Binding.h" | 35 #include "bindings/core/v8/V8Binding.h" |
| 36 #include "core/CSSPropertyNames.h" | 36 #include "core/CSSPropertyNames.h" |
| 37 #include "core/css/CSSPrimitiveValue.h" | 37 #include "core/css/CSSPrimitiveValue.h" |
| 38 #include "core/css/CSSPropertyMetadata.h" | 38 #include "core/css/CSSPropertyMetadata.h" |
| 39 #include "core/css/CSSStyleDeclaration.h" | 39 #include "core/css/CSSStyleDeclaration.h" |
| 40 #include "core/css/CSSValue.h" | 40 #include "core/css/CSSValue.h" |
| 41 #include "core/css/parser/CSSParser.h" | 41 #include "core/css/parser/CSSParser.h" |
| 42 #include "core/events/EventTarget.h" | 42 #include "core/events/EventTarget.h" |
| 43 #include "core/frame/UseCounter.h" | |
| 43 #include "wtf/ASCIICType.h" | 44 #include "wtf/ASCIICType.h" |
| 44 #include "wtf/PassRefPtr.h" | 45 #include "wtf/PassRefPtr.h" |
| 45 #include "wtf/RefPtr.h" | 46 #include "wtf/RefPtr.h" |
| 46 #include "wtf/StdLibExtras.h" | 47 #include "wtf/StdLibExtras.h" |
| 47 #include "wtf/Vector.h" | 48 #include "wtf/Vector.h" |
| 48 #include "wtf/text/StringBuilder.h" | 49 #include "wtf/text/StringBuilder.h" |
| 49 #include "wtf/text/StringConcatenate.h" | 50 #include "wtf/text/StringConcatenate.h" |
| 50 | 51 |
| 51 using namespace WTF; | 52 using namespace WTF; |
| 52 | 53 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 76 if (propertyName[i] != prefix[i]) | 77 if (propertyName[i] != prefix[i]) |
| 77 return false; | 78 return false; |
| 78 } | 79 } |
| 79 return false; | 80 return false; |
| 80 } | 81 } |
| 81 | 82 |
| 82 struct CSSPropertyInfo { | 83 struct CSSPropertyInfo { |
| 83 CSSPropertyID propID; | 84 CSSPropertyID propID; |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 static CSSPropertyID cssResolvedPropertyID(const String& propertyName) | 87 static CSSPropertyID cssResolvedPropertyID(const String& propertyName, v8::Isola te* isolate) |
| 87 { | 88 { |
| 88 unsigned length = propertyName.length(); | 89 unsigned length = propertyName.length(); |
| 89 if (!length) | 90 if (!length) |
| 90 return CSSPropertyInvalid; | 91 return CSSPropertyInvalid; |
| 91 | 92 |
| 92 StringBuilder builder; | 93 StringBuilder builder; |
| 93 builder.reserveCapacity(length); | 94 builder.reserveCapacity(length); |
| 94 | 95 |
| 95 unsigned i = 0; | 96 unsigned i = 0; |
| 96 bool hasSeenDash = false; | 97 bool hasSeenDash = false; |
| 97 | 98 |
| 98 if (hasCSSPropertyNamePrefix(propertyName, "css")) | 99 if (hasCSSPropertyNamePrefix(propertyName, "css")) { |
| 99 i += 3; | 100 // getComputedStyle("id").cssX is a non-standard behaviour |
| 100 else if (hasCSSPropertyNamePrefix(propertyName, "webkit")) | 101 // Measure this behaviour as CSSXGetComputedStyleQueries. |
| 102 UseCounter::count(callingExecutionContext(isolate), UseCounter::CSSXGetC omputedStyleQueries); | |
| 103 return CSSPropertyInvalid; | |
|
haraken
2014/10/03 14:07:27
Are you planning to actually change the behavior b
Sunil Ratnu
2014/10/03 14:22:32
Yeah correct, that is the usual flow. I might have
| |
| 104 } | |
| 105 if (hasCSSPropertyNamePrefix(propertyName, "webkit")) | |
| 101 builder.append('-'); | 106 builder.append('-'); |
| 102 else if (isASCIIUpper(propertyName[0])) | 107 else if (isASCIIUpper(propertyName[0])) |
| 103 return CSSPropertyInvalid; | 108 return CSSPropertyInvalid; |
| 104 | 109 |
| 105 bool hasSeenUpper = isASCIIUpper(propertyName[i]); | 110 bool hasSeenUpper = isASCIIUpper(propertyName[i]); |
| 106 | 111 |
| 107 builder.append(toASCIILower(propertyName[i++])); | 112 builder.append(toASCIILower(propertyName[i++])); |
| 108 | 113 |
| 109 for (; i < length; ++i) { | 114 for (; i < length; ++i) { |
| 110 UChar c = propertyName[i]; | 115 UChar c = propertyName[i]; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 129 | 134 |
| 130 // When getting properties on CSSStyleDeclarations, the name used from | 135 // When getting properties on CSSStyleDeclarations, the name used from |
| 131 // Javascript and the actual name of the property are not the same, so | 136 // Javascript and the actual name of the property are not the same, so |
| 132 // we have to do the following translation. The translation turns upper | 137 // we have to do the following translation. The translation turns upper |
| 133 // case characters into lower case characters and inserts dashes to | 138 // case characters into lower case characters and inserts dashes to |
| 134 // separate words. | 139 // separate words. |
| 135 // | 140 // |
| 136 // Example: 'backgroundPositionY' -> 'background-position-y' | 141 // Example: 'backgroundPositionY' -> 'background-position-y' |
| 137 // | 142 // |
| 138 // Also, certain prefixes such as 'css-' are stripped. | 143 // Also, certain prefixes such as 'css-' are stripped. |
| 139 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName) | 144 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName, v 8::Isolate* isolate) |
| 140 { | 145 { |
| 141 String propertyName = toCoreString(v8PropertyName); | 146 String propertyName = toCoreString(v8PropertyName); |
| 142 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; | 147 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; |
| 143 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); | 148 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); |
| 144 CSSPropertyInfo* propInfo = map.get(propertyName); | 149 CSSPropertyInfo* propInfo = map.get(propertyName); |
| 145 if (!propInfo) { | 150 if (!propInfo) { |
| 146 propInfo = new CSSPropertyInfo(); | 151 propInfo = new CSSPropertyInfo(); |
| 147 propInfo->propID = cssResolvedPropertyID(propertyName); | 152 propInfo->propID = cssResolvedPropertyID(propertyName, isolate); |
| 148 map.add(propertyName, propInfo); | 153 map.add(propertyName, propInfo); |
| 149 } | 154 } |
| 150 if (!propInfo->propID) | 155 if (!propInfo->propID) |
| 151 return 0; | 156 return 0; |
| 152 ASSERT(CSSPropertyMetadata::isEnabledProperty(propInfo->propID)); | 157 ASSERT(CSSPropertyMetadata::isEnabledProperty(propInfo->propID)); |
| 153 return propInfo; | 158 return propInfo; |
| 154 } | 159 } |
| 155 | 160 |
| 156 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall backInfo<v8::Array>& info) | 161 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall backInfo<v8::Array>& info) |
| 157 { | 162 { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 176 properties->Set(v8::Integer::New(info.GetIsolate(), i), v8String(info.Ge tIsolate(), key)); | 181 properties->Set(v8::Integer::New(info.GetIsolate(), i), v8String(info.Ge tIsolate(), key)); |
| 177 } | 182 } |
| 178 | 183 |
| 179 v8SetReturnValue(info, properties); | 184 v8SetReturnValue(info, properties); |
| 180 } | 185 } |
| 181 | 186 |
| 182 void V8CSSStyleDeclaration::namedPropertyQueryCustom(v8::Local<v8::String> v8Nam e, const v8::PropertyCallbackInfo<v8::Integer>& info) | 187 void V8CSSStyleDeclaration::namedPropertyQueryCustom(v8::Local<v8::String> v8Nam e, const v8::PropertyCallbackInfo<v8::Integer>& info) |
| 183 { | 188 { |
| 184 // NOTE: cssPropertyInfo lookups incur several mallocs. | 189 // NOTE: cssPropertyInfo lookups incur several mallocs. |
| 185 // Successful lookups have the same cost the first time, but are cached. | 190 // Successful lookups have the same cost the first time, but are cached. |
| 186 if (cssPropertyInfo(v8Name)) { | 191 if (cssPropertyInfo(v8Name, info.GetIsolate())) { |
| 187 v8SetReturnValueInt(info, 0); | 192 v8SetReturnValueInt(info, 0); |
| 188 return; | 193 return; |
| 189 } | 194 } |
| 190 } | 195 } |
| 191 | 196 |
| 192 void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::String> name , const v8::PropertyCallbackInfo<v8::Value>& info) | 197 void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::String> name , const v8::PropertyCallbackInfo<v8::Value>& info) |
| 193 { | 198 { |
| 194 // First look for API defined attributes on the style declaration object. | 199 // First look for API defined attributes on the style declaration object. |
| 195 if (info.Holder()->HasRealNamedCallbackProperty(name)) | 200 if (info.Holder()->HasRealNamedCallbackProperty(name)) |
| 196 return; | 201 return; |
| 197 | 202 |
| 198 // Search the style declaration. | 203 // Search the style declaration. |
| 199 CSSPropertyInfo* propInfo = cssPropertyInfo(name); | 204 CSSPropertyInfo* propInfo = cssPropertyInfo(name, info.GetIsolate()); |
| 200 | 205 |
| 201 // Do not handle non-property names. | 206 // Do not handle non-property names. |
| 202 if (!propInfo) | 207 if (!propInfo) |
| 203 return; | 208 return; |
| 204 | 209 |
| 205 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); | 210 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); |
| 206 RefPtrWillBeRawPtr<CSSValue> cssValue = impl->getPropertyCSSValueInternal(st atic_cast<CSSPropertyID>(propInfo->propID)); | 211 RefPtrWillBeRawPtr<CSSValue> cssValue = impl->getPropertyCSSValueInternal(st atic_cast<CSSPropertyID>(propInfo->propID)); |
| 207 if (cssValue) { | 212 if (cssValue) { |
| 208 v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate( )); | 213 v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate( )); |
| 209 return; | 214 return; |
| 210 } | 215 } |
| 211 | 216 |
| 212 String result = impl->getPropertyValueInternal(static_cast<CSSPropertyID>(pr opInfo->propID)); | 217 String result = impl->getPropertyValueInternal(static_cast<CSSPropertyID>(pr opInfo->propID)); |
| 213 v8SetReturnValueString(info, result, info.GetIsolate()); | 218 v8SetReturnValueString(info, result, info.GetIsolate()); |
| 214 } | 219 } |
| 215 | 220 |
| 216 void V8CSSStyleDeclaration::namedPropertySetterCustom(v8::Local<v8::String> name , v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 221 void V8CSSStyleDeclaration::namedPropertySetterCustom(v8::Local<v8::String> name , v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 217 { | 222 { |
| 218 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); | 223 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); |
| 219 CSSPropertyInfo* propInfo = cssPropertyInfo(name); | 224 CSSPropertyInfo* propInfo = cssPropertyInfo(name, info.GetIsolate()); |
| 220 if (!propInfo) | 225 if (!propInfo) |
| 221 return; | 226 return; |
| 222 | 227 |
| 223 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, propertyValue, value) ; | 228 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, propertyValue, value) ; |
| 224 ExceptionState exceptionState(ExceptionState::SetterContext, getPropertyName (static_cast<CSSPropertyID>(propInfo->propID)), "CSSStyleDeclaration", info.Hold er(), info.GetIsolate()); | 229 ExceptionState exceptionState(ExceptionState::SetterContext, getPropertyName (static_cast<CSSPropertyID>(propInfo->propID)), "CSSStyleDeclaration", info.Hold er(), info.GetIsolate()); |
| 225 impl->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prop ertyValue, false, exceptionState); | 230 impl->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prop ertyValue, false, exceptionState); |
| 226 | 231 |
| 227 if (exceptionState.throwIfNeeded()) | 232 if (exceptionState.throwIfNeeded()) |
| 228 return; | 233 return; |
| 229 | 234 |
| 230 v8SetReturnValue(info, value); | 235 v8SetReturnValue(info, value); |
| 231 } | 236 } |
| 232 | 237 |
| 233 } // namespace blink | 238 } // namespace blink |
| OLD | NEW |