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

Side by Side Diff: Source/core/xml/parser/XMLDocumentParser.cpp

Issue 436603003: Make Element::attributes() less error-prone and simplify call sites (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Keep synchronizeAllAttributes() in hasAttributes() Created 6 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2000 Peter Kelly (pmk@post.com) 2 * Copyright (C) 2000 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2005, 2006, 2008, 2014 Apple Inc. All rights reserved. 3 * Copyright (C) 2005, 2006, 2008, 2014 Apple Inc. All rights reserved.
4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
5 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) 5 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2008 Holger Hans Peter Freyther 7 * Copyright (C) 2008 Holger Hans Peter Freyther
8 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 8 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 if (!n || !n->isElementNode()) 805 if (!n || !n->isElementNode())
806 break; 806 break;
807 parentElement = toElement(n); 807 parentElement = toElement(n);
808 } 808 }
809 809
810 if (elemStack.isEmpty()) 810 if (elemStack.isEmpty())
811 return; 811 return;
812 812
813 for (; !elemStack.isEmpty(); elemStack.removeLast()) { 813 for (; !elemStack.isEmpty(); elemStack.removeLast()) {
814 Element* element = elemStack.last(); 814 Element* element = elemStack.last();
815 if (element->hasAttributes()) { 815 AttributeCollection attributes = element->attributes();
816 AttributeCollection attributes = element->attributes(); 816 AttributeCollection::const_iterator end = attributes.end();
817 AttributeCollection::const_iterator end = attributes.end(); 817 for (AttributeCollection::const_iterator it = attributes.begin(); it != end; ++it) {
818 for (AttributeCollection::const_iterator it = attributes.begin(); it != end; ++it) { 818 if (it->localName() == xmlnsAtom)
819 if (it->localName() == xmlnsAtom) 819 m_defaultNamespaceURI = it->value();
820 m_defaultNamespaceURI = it->value(); 820 else if (it->prefix() == xmlnsAtom)
821 else if (it->prefix() == xmlnsAtom) 821 m_prefixToNamespaceMap.set(it->localName(), it->value());
822 m_prefixToNamespaceMap.set(it->localName(), it->value());
823 }
824 } 822 }
825 } 823 }
826 824
827 // If the parent element is not in document tree, there may be no xmlns attr ibute; just default to the parent's namespace. 825 // If the parent element is not in document tree, there may be no xmlns attr ibute; just default to the parent's namespace.
828 if (m_defaultNamespaceURI.isNull() && !parentElement->inDocument()) 826 if (m_defaultNamespaceURI.isNull() && !parentElement->inDocument())
829 m_defaultNamespaceURI = parentElement->namespaceURI(); 827 m_defaultNamespaceURI = parentElement->namespaceURI();
830 } 828 }
831 829
832 XMLParserContext::~XMLParserContext() 830 XMLParserContext::~XMLParserContext()
833 { 831 {
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 sax.initialized = XML_SAX2_MAGIC; 1629 sax.initialized = XML_SAX2_MAGIC;
1632 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax, &state); 1630 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax, &state);
1633 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; 1631 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />";
1634 parseChunk(parser->context(), parseString); 1632 parseChunk(parser->context(), parseString);
1635 finishParsing(parser->context()); 1633 finishParsing(parser->context());
1636 attrsOK = state.gotAttributes; 1634 attrsOK = state.gotAttributes;
1637 return state.attributes; 1635 return state.attributes;
1638 } 1636 }
1639 1637
1640 } // namespace blink 1638 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698