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

Side by Side Diff: third_party/WebKit/Source/core/dom/Element.cpp

Issue 2814673002: Use ASCII-caseless matching for attribute names. (Closed)
Patch Set: . Created 3 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
8 * All rights reserved. 8 * All rights reserved.
9 * (C) 2007 Eric Seidel (eric@webkit.org) 9 * (C) 2007 Eric Seidel (eric@webkit.org)
10 * 10 *
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 ToSVGElement(this)->SynchronizeAnimatedSVGAttribute(name); 386 ToSVGElement(this)->SynchronizeAnimatedSVGAttribute(name);
387 } 387 }
388 } 388 }
389 389
390 void Element::SynchronizeAttribute(const AtomicString& local_name) const { 390 void Element::SynchronizeAttribute(const AtomicString& local_name) const {
391 // This version of synchronizeAttribute() is streamlined for the case where 391 // This version of synchronizeAttribute() is streamlined for the case where
392 // you don't have a full QualifiedName, e.g when called from DOM API. 392 // you don't have a full QualifiedName, e.g when called from DOM API.
393 if (!GetElementData()) 393 if (!GetElementData())
394 return; 394 return;
395 if (GetElementData()->style_attribute_is_dirty_ && 395 if (GetElementData()->style_attribute_is_dirty_ &&
396 EqualPossiblyIgnoringCase(local_name, styleAttr.LocalName(), 396 EqualPossiblyIgnoringASCIICase(local_name, styleAttr.LocalName(),
397 ShouldIgnoreAttributeCase())) { 397 ShouldIgnoreAttributeCase())) {
398 DCHECK(IsStyledElement()); 398 DCHECK(IsStyledElement());
399 SynchronizeStyleAttributeInternal(); 399 SynchronizeStyleAttributeInternal();
400 return; 400 return;
401 } 401 }
402 if (GetElementData()->animated_svg_attributes_are_dirty_) { 402 if (GetElementData()->animated_svg_attributes_are_dirty_) {
403 // We're not passing a namespace argument on purpose. SVGNames::*Attr are 403 // We're not passing a namespace argument on purpose. SVGNames::*Attr are
404 // defined w/o namespaces as well. 404 // defined w/o namespaces as well.
405 405
406 // FIXME: this code is called regardless of whether name is an 406 // FIXME: this code is called regardless of whether name is an
407 // animated SVG Attribute. It would seem we should only call this method 407 // animated SVG Attribute. It would seem we should only call this method
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 ExceptionState& exception_state) { 1236 ExceptionState& exception_state) {
1237 if (!Document::IsValidName(local_name)) { 1237 if (!Document::IsValidName(local_name)) {
1238 exception_state.ThrowDOMException( 1238 exception_state.ThrowDOMException(
1239 kInvalidCharacterError, 1239 kInvalidCharacterError,
1240 "'" + local_name + "' is not a valid attribute name."); 1240 "'" + local_name + "' is not a valid attribute name.");
1241 return; 1241 return;
1242 } 1242 }
1243 1243
1244 SynchronizeAttribute(local_name); 1244 SynchronizeAttribute(local_name);
1245 const AtomicString& case_adjusted_local_name = 1245 const AtomicString& case_adjusted_local_name =
1246 ShouldIgnoreAttributeCase() ? local_name.DeprecatedLower() : local_name; 1246 ShouldIgnoreAttributeCase() ? local_name.LowerASCII() : local_name;
1247 1247
1248 if (!GetElementData()) { 1248 if (!GetElementData()) {
1249 SetAttributeInternal( 1249 SetAttributeInternal(
1250 kNotFound, 1250 kNotFound,
1251 QualifiedName(g_null_atom, case_adjusted_local_name, g_null_atom), 1251 QualifiedName(g_null_atom, case_adjusted_local_name, g_null_atom),
1252 value, kNotInSynchronizationOfLazyAttribute); 1252 value, kNotInSynchronizationOfLazyAttribute);
1253 return; 1253 return;
1254 } 1254 }
1255 1255
1256 AttributeCollection attributes = GetElementData()->Attributes(); 1256 AttributeCollection attributes = GetElementData()->Attributes();
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2456 // to re-use them in other elements. 2456 // to re-use them in other elements.
2457 if (attr_node->ownerElement()) { 2457 if (attr_node->ownerElement()) {
2458 exception_state.ThrowDOMException( 2458 exception_state.ThrowDOMException(
2459 kInUseAttributeError, 2459 kInUseAttributeError,
2460 "The node provided is an attribute node that is already an attribute " 2460 "The node provided is an attribute node that is already an attribute "
2461 "of another Element; attribute nodes must be explicitly cloned."); 2461 "of another Element; attribute nodes must be explicitly cloned.");
2462 return nullptr; 2462 return nullptr;
2463 } 2463 }
2464 2464
2465 if (!IsHTMLElement() && attr_node->GetDocument().IsHTMLDocument() && 2465 if (!IsHTMLElement() && attr_node->GetDocument().IsHTMLDocument() &&
2466 attr_node->name() != attr_node->name().DeprecatedLower()) 2466 attr_node->name() != attr_node->name().LowerASCII())
2467 UseCounter::Count( 2467 UseCounter::Count(
2468 GetDocument(), 2468 GetDocument(),
2469 UseCounter:: 2469 UseCounter::
2470 kNonHTMLElementSetAttributeNodeFromHTMLDocumentNameNotLowercase); 2470 kNonHTMLElementSetAttributeNodeFromHTMLDocumentNameNotLowercase);
2471 2471
2472 SynchronizeAllAttributes(); 2472 SynchronizeAllAttributes();
2473 const UniqueElementData& element_data = EnsureUniqueElementData(); 2473 const UniqueElementData& element_data = EnsureUniqueElementData();
2474 2474
2475 AttributeCollection attributes = element_data.Attributes(); 2475 AttributeCollection attributes = element_data.Attributes();
2476 size_t index = attributes.FindIndex(attr_node->GetQualifiedName(), 2476 size_t index = attributes.FindIndex(attr_node->GetQualifiedName(),
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
2623 EnsureUniqueElementData().Attributes().Append(name, value); 2623 EnsureUniqueElementData().Attributes().Append(name, value);
2624 if (!in_synchronization_of_lazy_attribute) 2624 if (!in_synchronization_of_lazy_attribute)
2625 DidAddAttribute(name, value); 2625 DidAddAttribute(name, value);
2626 } 2626 }
2627 2627
2628 void Element::removeAttribute(const AtomicString& name) { 2628 void Element::removeAttribute(const AtomicString& name) {
2629 if (!GetElementData()) 2629 if (!GetElementData())
2630 return; 2630 return;
2631 2631
2632 AtomicString local_name = 2632 AtomicString local_name =
2633 ShouldIgnoreAttributeCase() ? name.DeprecatedLower() : name; 2633 ShouldIgnoreAttributeCase() ? name.LowerASCII() : name;
2634 size_t index = GetElementData()->Attributes().FindIndex(local_name, false); 2634 size_t index = GetElementData()->Attributes().FindIndex(local_name, false);
2635 if (index == kNotFound) { 2635 if (index == kNotFound) {
2636 if (UNLIKELY(local_name == styleAttr) && 2636 if (UNLIKELY(local_name == styleAttr) &&
2637 GetElementData()->style_attribute_is_dirty_ && IsStyledElement()) 2637 GetElementData()->style_attribute_is_dirty_ && IsStyledElement())
2638 RemoveAllInlineStyleProperties(); 2638 RemoveAllInlineStyleProperties();
2639 return; 2639 return;
2640 } 2640 }
2641 2641
2642 RemoveAttributeInternal(index, kNotInSynchronizationOfLazyAttribute); 2642 RemoveAttributeInternal(index, kNotInSynchronizationOfLazyAttribute);
2643 } 2643 }
(...skipping 24 matching lines...) Expand all
2668 if (!attribute) 2668 if (!attribute)
2669 return nullptr; 2669 return nullptr;
2670 return EnsureAttr(attribute->GetName()); 2670 return EnsureAttr(attribute->GetName());
2671 } 2671 }
2672 2672
2673 bool Element::hasAttribute(const AtomicString& local_name) const { 2673 bool Element::hasAttribute(const AtomicString& local_name) const {
2674 if (!GetElementData()) 2674 if (!GetElementData())
2675 return false; 2675 return false;
2676 SynchronizeAttribute(local_name); 2676 SynchronizeAttribute(local_name);
2677 return GetElementData()->Attributes().FindIndex( 2677 return GetElementData()->Attributes().FindIndex(
2678 ShouldIgnoreAttributeCase() ? local_name.DeprecatedLower() 2678 ShouldIgnoreAttributeCase() ? local_name.LowerASCII() : local_name,
2679 : local_name,
2680 false) != kNotFound; 2679 false) != kNotFound;
2681 } 2680 }
2682 2681
2683 bool Element::hasAttributeNS(const AtomicString& namespace_uri, 2682 bool Element::hasAttributeNS(const AtomicString& namespace_uri,
2684 const AtomicString& local_name) const { 2683 const AtomicString& local_name) const {
2685 if (!GetElementData()) 2684 if (!GetElementData())
2686 return false; 2685 return false;
2687 QualifiedName q_name(g_null_atom, local_name, namespace_uri); 2686 QualifiedName q_name(g_null_atom, local_name, namespace_uri);
2688 SynchronizeAttribute(q_name); 2687 SynchronizeAttribute(q_name);
2689 return GetElementData()->Attributes().Find(q_name); 2688 return GetElementData()->Attributes().Find(q_name);
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after
3881 void Element::SetSavedLayerScrollOffset(const ScrollOffset& size) { 3880 void Element::SetSavedLayerScrollOffset(const ScrollOffset& size) {
3882 if (size.IsZero() && !HasRareData()) 3881 if (size.IsZero() && !HasRareData())
3883 return; 3882 return;
3884 EnsureElementRareData().SetSavedLayerScrollOffset(size); 3883 EnsureElementRareData().SetSavedLayerScrollOffset(size);
3885 } 3884 }
3886 3885
3887 Attr* Element::AttrIfExists(const QualifiedName& name) { 3886 Attr* Element::AttrIfExists(const QualifiedName& name) {
3888 if (AttrNodeList* attr_node_list = this->GetAttrNodeList()) { 3887 if (AttrNodeList* attr_node_list = this->GetAttrNodeList()) {
3889 bool should_ignore_case = ShouldIgnoreAttributeCase(); 3888 bool should_ignore_case = ShouldIgnoreAttributeCase();
3890 for (const auto& attr : *attr_node_list) { 3889 for (const auto& attr : *attr_node_list) {
3891 if (attr->GetQualifiedName().MatchesPossiblyIgnoringCase( 3890 if (attr->GetQualifiedName().MatchesPossiblyIgnoringASCIICase(
3892 name, should_ignore_case)) 3891 name, should_ignore_case))
3893 return attr.Get(); 3892 return attr.Get();
3894 } 3893 }
3895 } 3894 }
3896 return nullptr; 3895 return nullptr;
3897 } 3896 }
3898 3897
3899 Attr* Element::EnsureAttr(const QualifiedName& name) { 3898 Attr* Element::EnsureAttr(const QualifiedName& name) {
3900 Attr* attr_node = AttrIfExists(name); 3899 Attr* attr_node = AttrIfExists(name);
3901 if (!attr_node) { 3900 if (!attr_node) {
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
4343 } 4342 }
4344 4343
4345 DEFINE_TRACE_WRAPPERS(Element) { 4344 DEFINE_TRACE_WRAPPERS(Element) {
4346 if (HasRareData()) { 4345 if (HasRareData()) {
4347 visitor->TraceWrappers(GetElementRareData()); 4346 visitor->TraceWrappers(GetElementRareData());
4348 } 4347 }
4349 ContainerNode::TraceWrappers(visitor); 4348 ContainerNode::TraceWrappers(visitor);
4350 } 4349 }
4351 4350
4352 } // namespace blink 4351 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/AttributeCollection.h ('k') | third_party/WebKit/Source/core/dom/QualifiedName.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698