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

Side by Side Diff: Source/core/html/HTMLFormElement.cpp

Issue 148013008: Use stricter typing for HTMLCollection named getter (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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
« no previous file with comments | « Source/core/html/HTMLFormElement.h ('k') | Source/core/html/HTMLFormElement.idl » ('j') | 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) 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 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 for (unsigned i = 0; i < elements.size(); ++i) { 704 for (unsigned i = 0; i < elements.size(); ++i) {
705 if (elements[i]->form() == this && elements[i]->isFormControlElement()) { 705 if (elements[i]->form() == this && elements[i]->isFormControlElement()) {
706 HTMLFormControlElement* control = toHTMLFormControlElement(elements[ i].get()); 706 HTMLFormControlElement* control = toHTMLFormControlElement(elements[ i].get());
707 if (!control->checkValidity(unhandledInvalidControls, dispatchEvents ) && control->formOwner() == this) 707 if (!control->checkValidity(unhandledInvalidControls, dispatchEvents ) && control->formOwner() == this)
708 hasInvalidControls = true; 708 hasInvalidControls = true;
709 } 709 }
710 } 710 }
711 return hasInvalidControls; 711 return hasInvalidControls;
712 } 712 }
713 713
714 Node* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName) 714 Element* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName)
715 { 715 {
716 if (pastName.isEmpty() || !m_pastNamesMap) 716 if (pastName.isEmpty() || !m_pastNamesMap)
717 return 0; 717 return 0;
718 Node* node = m_pastNamesMap->get(pastName); 718 Element* element = m_pastNamesMap->get(pastName);
719 #if !ASSERT_DISABLED 719 #if !ASSERT_DISABLED
720 if (!node) 720 if (!element)
721 return 0; 721 return 0;
722 ASSERT_WITH_SECURITY_IMPLICATION(toHTMLElement(node)->formOwner() == this); 722 ASSERT_WITH_SECURITY_IMPLICATION(toHTMLElement(element)->formOwner() == this );
723 if (node->hasTagName(imgTag)) { 723 if (element->hasTagName(imgTag)) {
724 ASSERT_WITH_SECURITY_IMPLICATION(imageElements().find(node) != kNotFound ); 724 ASSERT_WITH_SECURITY_IMPLICATION(imageElements().find(element) != kNotFo und);
725 } else if (node->hasTagName(objectTag)) { 725 } else if (element->hasTagName(objectTag)) {
726 ASSERT_WITH_SECURITY_IMPLICATION(associatedElements().find(toHTMLObjectE lement(node)) != kNotFound); 726 ASSERT_WITH_SECURITY_IMPLICATION(associatedElements().find(toHTMLObjectE lement(element)) != kNotFound);
727 } else { 727 } else {
728 ASSERT_WITH_SECURITY_IMPLICATION(associatedElements().find(toHTMLFormCon trolElement(node)) != kNotFound); 728 ASSERT_WITH_SECURITY_IMPLICATION(associatedElements().find(toHTMLFormCon trolElement(element)) != kNotFound);
729 } 729 }
730 #endif 730 #endif
731 return node; 731 return element;
732 } 732 }
733 733
734 void HTMLFormElement::addToPastNamesMap(Node* element, const AtomicString& pastN ame) 734 void HTMLFormElement::addToPastNamesMap(Element* element, const AtomicString& pa stName)
735 { 735 {
736 if (pastName.isEmpty()) 736 if (pastName.isEmpty())
737 return; 737 return;
738 if (!m_pastNamesMap) 738 if (!m_pastNamesMap)
739 m_pastNamesMap = adoptPtr(new PastNamesMap); 739 m_pastNamesMap = adoptPtr(new PastNamesMap);
740 m_pastNamesMap->set(pastName, element); 740 m_pastNamesMap->set(pastName, element);
741 } 741 }
742 742
743 void HTMLFormElement::removeFromPastNamesMap(HTMLElement& element) 743 void HTMLFormElement::removeFromPastNamesMap(HTMLElement& element)
744 { 744 {
745 if (!m_pastNamesMap) 745 if (!m_pastNamesMap)
746 return; 746 return;
747 PastNamesMap::iterator end = m_pastNamesMap->end(); 747 PastNamesMap::iterator end = m_pastNamesMap->end();
748 for (PastNamesMap::iterator it = m_pastNamesMap->begin(); it != end; ++it) { 748 for (PastNamesMap::iterator it = m_pastNamesMap->begin(); it != end; ++it) {
749 if (it->value == &element) { 749 if (it->value == &element) {
750 it->value = 0; 750 it->value = 0;
751 // Keep looping. Single element can have multiple names. 751 // Keep looping. Single element can have multiple names.
752 } 752 }
753 } 753 }
754 } 754 }
755 755
756 void HTMLFormElement::getNamedElements(const AtomicString& name, Vector<RefPtr<N ode> >& namedItems) 756 void HTMLFormElement::getNamedElements(const AtomicString& name, Vector<RefPtr<E lement> >& namedItems)
757 { 757 {
758 // http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#do m-form-nameditem 758 // http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#do m-form-nameditem
759 elements()->namedItems(name, namedItems); 759 elements()->namedItems(name, namedItems);
760 760
761 Node* elementFromPast = elementFromPastNamesMap(name); 761 Element* elementFromPast = elementFromPastNamesMap(name);
762 if (namedItems.size() && namedItems.first() != elementFromPast) { 762 if (namedItems.size() && namedItems.first() != elementFromPast) {
763 addToPastNamesMap(namedItems.first().get(), name); 763 addToPastNamesMap(namedItems.first().get(), name);
764 } else if (elementFromPast && namedItems.isEmpty()) { 764 } else if (elementFromPast && namedItems.isEmpty()) {
765 namedItems.append(elementFromPast); 765 namedItems.append(elementFromPast);
766 UseCounter::count(document(), UseCounter::FormNameAccessForPastNamesMap) ; 766 UseCounter::count(document(), UseCounter::FormNameAccessForPastNamesMap) ;
767 } 767 }
768 } 768 }
769 769
770 bool HTMLFormElement::shouldAutocomplete() const 770 bool HTMLFormElement::shouldAutocomplete() const
771 { 771 {
772 return !equalIgnoringCase(fastGetAttribute(autocompleteAttr), "off"); 772 return !equalIgnoringCase(fastGetAttribute(autocompleteAttr), "off");
773 } 773 }
774 774
775 void HTMLFormElement::finishParsingChildren() 775 void HTMLFormElement::finishParsingChildren()
776 { 776 {
777 HTMLElement::finishParsingChildren(); 777 HTMLElement::finishParsingChildren();
778 document().formController()->restoreControlStateIn(*this); 778 document().formController()->restoreControlStateIn(*this);
779 m_didFinishParsingChildren = true; 779 m_didFinishParsingChildren = true;
780 } 780 }
781 781
782 void HTMLFormElement::copyNonAttributePropertiesFromElement(const Element& sourc e) 782 void HTMLFormElement::copyNonAttributePropertiesFromElement(const Element& sourc e)
783 { 783 {
784 m_wasDemoted = static_cast<const HTMLFormElement&>(source).m_wasDemoted; 784 m_wasDemoted = static_cast<const HTMLFormElement&>(source).m_wasDemoted;
785 HTMLElement::copyNonAttributePropertiesFromElement(source); 785 HTMLElement::copyNonAttributePropertiesFromElement(source);
786 } 786 }
787 787
788 void HTMLFormElement::anonymousNamedGetter(const AtomicString& name, bool& retur nValue0Enabled, RefPtr<RadioNodeList>& returnValue0, bool& returnValue1Enabled, RefPtr<Node>& returnValue1) 788 void HTMLFormElement::anonymousNamedGetter(const AtomicString& name, bool& retur nValue0Enabled, RefPtr<RadioNodeList>& returnValue0, bool& returnValue1Enabled, RefPtr<Element>& returnValue1)
789 { 789 {
790 // Call getNamedElements twice, first time check if it has a value 790 // Call getNamedElements twice, first time check if it has a value
791 // and let HTMLFormElement update its cache. 791 // and let HTMLFormElement update its cache.
792 // See issue: 867404 792 // See issue: 867404
793 { 793 {
794 Vector<RefPtr<Node> > elements; 794 Vector<RefPtr<Element> > elements;
795 getNamedElements(name, elements); 795 getNamedElements(name, elements);
796 if (elements.isEmpty()) 796 if (elements.isEmpty())
797 return; 797 return;
798 } 798 }
799 799
800 // Second call may return different results from the first call, 800 // Second call may return different results from the first call,
801 // but if the first the size cannot be zero. 801 // but if the first the size cannot be zero.
802 Vector<RefPtr<Node> > elements; 802 Vector<RefPtr<Element> > elements;
803 getNamedElements(name, elements); 803 getNamedElements(name, elements);
804 ASSERT(!elements.isEmpty()); 804 ASSERT(!elements.isEmpty());
805 805
806 if (elements.size() == 1) { 806 if (elements.size() == 1) {
807 returnValue1Enabled = true; 807 returnValue1Enabled = true;
808 returnValue1 = elements.at(0); 808 returnValue1 = elements.at(0);
809 return; 809 return;
810 } 810 }
811 811
812 bool onlyMatchImg = elements.size() && elements.at(0)->hasTagName(imgTag); 812 bool onlyMatchImg = elements.size() && elements.at(0)->hasTagName(imgTag);
813 returnValue0Enabled = true; 813 returnValue0Enabled = true;
814 returnValue0 = radioNodeList(name, onlyMatchImg); 814 returnValue0 = radioNodeList(name, onlyMatchImg);
815 } 815 }
816 816
817 void HTMLFormElement::setDemoted(bool demoted) 817 void HTMLFormElement::setDemoted(bool demoted)
818 { 818 {
819 if (demoted) 819 if (demoted)
820 UseCounter::count(document(), UseCounter::DemotedFormElement); 820 UseCounter::count(document(), UseCounter::DemotedFormElement);
821 m_wasDemoted = demoted; 821 m_wasDemoted = demoted;
822 } 822 }
823 823
824 } // namespace 824 } // namespace
OLDNEW
« no previous file with comments | « Source/core/html/HTMLFormElement.h ('k') | Source/core/html/HTMLFormElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698