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

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

Issue 2737273002: [DOM] Fix null namespace handling in Node.isDefaultNamespace(). (Closed)
Patch Set: Created 3 years, 9 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 | « third_party/WebKit/LayoutTests/external/wpt/dom/nodes/Node-lookupNamespaceURI-expected.txt ('k') | no next file » | 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, 2010, 2011 Apple Inc. All 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
6 * rights reserved. 6 * rights reserved.
7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * 10 *
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 1158
1159 if (documentTypeThis->systemId() != documentTypeOther->systemId()) 1159 if (documentTypeThis->systemId() != documentTypeOther->systemId())
1160 return false; 1160 return false;
1161 } 1161 }
1162 1162
1163 return true; 1163 return true;
1164 } 1164 }
1165 1165
1166 bool Node::isDefaultNamespace( 1166 bool Node::isDefaultNamespace(
1167 const AtomicString& namespaceURIMaybeEmpty) const { 1167 const AtomicString& namespaceURIMaybeEmpty) const {
1168 // https://dom.spec.whatwg.org/#dom-node-isdefaultnamespace
1169
1170 // 1. If namespace is the empty string, then set it to null.
1168 const AtomicString& namespaceURI = 1171 const AtomicString& namespaceURI =
1169 namespaceURIMaybeEmpty.isEmpty() ? nullAtom : namespaceURIMaybeEmpty; 1172 namespaceURIMaybeEmpty.isEmpty() ? nullAtom : namespaceURIMaybeEmpty;
1170 1173
1171 switch (getNodeType()) { 1174 // 2. Let defaultNamespace be the result of running locate a namespace for
1172 case kElementNode: { 1175 // context object using null.
1173 const Element& element = toElement(*this); 1176 const AtomicString& defaultNamespace = lookupNamespaceURI(String());
1174 1177
1175 if (element.prefix().isNull()) 1178 // 3. Return true if defaultNamespace is the same as namespace, and false
1176 return element.namespaceURI() == namespaceURI; 1179 // otherwise.
1177 1180 return namespaceURI == defaultNamespace;
1178 AttributeCollection attributes = element.attributes();
1179 for (const Attribute& attr : attributes) {
1180 if (attr.localName() == xmlnsAtom)
1181 return attr.value() == namespaceURI;
1182 }
1183
1184 if (Element* parent = parentElement())
1185 return parent->isDefaultNamespace(namespaceURI);
1186
1187 return false;
1188 }
1189 case kDocumentNode:
1190 if (Element* de = toDocument(this)->documentElement())
1191 return de->isDefaultNamespace(namespaceURI);
1192 return false;
1193 case kDocumentTypeNode:
1194 case kDocumentFragmentNode:
1195 return false;
1196 case kAttributeNode: {
1197 const Attr* attr = toAttr(this);
1198 if (attr->ownerElement())
1199 return attr->ownerElement()->isDefaultNamespace(namespaceURI);
1200 return false;
1201 }
1202 default:
1203 if (Element* parent = parentElement())
1204 return parent->isDefaultNamespace(namespaceURI);
1205 return false;
1206 }
1207 } 1181 }
1208 1182
1209 const AtomicString& Node::lookupPrefix(const AtomicString& namespaceURI) const { 1183 const AtomicString& Node::lookupPrefix(const AtomicString& namespaceURI) const {
1210 // Implemented according to 1184 // Implemented according to
1211 // https://dom.spec.whatwg.org/#dom-node-lookupprefix 1185 // https://dom.spec.whatwg.org/#dom-node-lookupprefix
1212 1186
1213 if (namespaceURI.isEmpty() || namespaceURI.isNull()) 1187 if (namespaceURI.isEmpty() || namespaceURI.isNull())
1214 return nullAtom; 1188 return nullAtom;
1215 1189
1216 const Element* context; 1190 const Element* context;
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 if (node) { 2537 if (node) {
2564 std::stringstream stream; 2538 std::stringstream stream;
2565 node->printNodePathTo(stream); 2539 node->printNodePathTo(stream);
2566 LOG(INFO) << stream.str(); 2540 LOG(INFO) << stream.str();
2567 } else { 2541 } else {
2568 LOG(INFO) << "Cannot showNodePath for <null>"; 2542 LOG(INFO) << "Cannot showNodePath for <null>";
2569 } 2543 }
2570 } 2544 }
2571 2545
2572 #endif 2546 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/external/wpt/dom/nodes/Node-lookupNamespaceURI-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698