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

Side by Side Diff: tools/dom/src/Validators.dart

Issue 23511007: Adding warning message when HTML contents get sanitized away. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('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 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.dom.html; 5 part of dart.dom.html;
6 6
7 7
8 /** 8 /**
9 * Interface used to validate that only accepted elements and attributes are 9 * Interface used to validate that only accepted elements and attributes are
10 * allowed while parsing HTML strings into DOM nodes. 10 * allowed while parsing HTML strings into DOM nodes.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 158 }
159 walk(node); 159 walk(node);
160 } 160 }
161 161
162 void sanitizeNode(Node node) { 162 void sanitizeNode(Node node) {
163 switch (node.nodeType) { 163 switch (node.nodeType) {
164 case Node.ELEMENT_NODE: 164 case Node.ELEMENT_NODE:
165 Element element = node; 165 Element element = node;
166 var attrs = element.attributes; 166 var attrs = element.attributes;
167 if (!validator.allowsElement(element)) { 167 if (!validator.allowsElement(element)) {
168 window.console.warn(
169 'Removing disallowed element <${element.tagName}>');
168 element.remove(); 170 element.remove();
169 break; 171 break;
170 } 172 }
171 173
172 var isAttr = attrs['is']; 174 var isAttr = attrs['is'];
173 if (isAttr != null) { 175 if (isAttr != null) {
174 if (!validator.allowsAttribute(element, 'is', isAttr)) { 176 if (!validator.allowsAttribute(element, 'is', isAttr)) {
177 window.console.warn('Removing disallowed type extension '
178 '<${element.tagName} is="$isAttr">');
175 element.remove(); 179 element.remove();
176 break; 180 break;
177 } 181 }
178 } 182 }
179 183
180 // TODO(blois): Need to be able to get all attributes, irrespective of 184 // TODO(blois): Need to be able to get all attributes, irrespective of
181 // XMLNS. 185 // XMLNS.
182 var keys = attrs.keys.toList(); 186 var keys = attrs.keys.toList();
183 for (var i = attrs.length - 1; i >= 0; --i) { 187 for (var i = attrs.length - 1; i >= 0; --i) {
184 var name = keys[i]; 188 var name = keys[i];
185 if (!validator.allowsAttribute(element, name.toLowerCase(), 189 if (!validator.allowsAttribute(element, name.toLowerCase(),
186 attrs[name])) { 190 attrs[name])) {
191 window.console.warn('Removing disallowed attribute '
192 '<${element.tagName} $name="${attrs[name]}">');
187 attrs.remove(name); 193 attrs.remove(name);
188 } 194 }
189 } 195 }
190 196
191 if (element is TemplateElement) { 197 if (element is TemplateElement) {
192 TemplateElement template = element; 198 TemplateElement template = element;
193 sanitizeTree(template.content); 199 sanitizeTree(template.content);
194 } 200 }
195 break; 201 break;
196 case Node.COMMENT_NODE: 202 case Node.COMMENT_NODE:
197 case Node.DOCUMENT_FRAGMENT_NODE: 203 case Node.DOCUMENT_FRAGMENT_NODE:
198 case Node.TEXT_NODE: 204 case Node.TEXT_NODE:
199 case Node.CDATA_SECTION_NODE: 205 case Node.CDATA_SECTION_NODE:
200 break; 206 break;
201 default: 207 default:
202 node.remove(); 208 node.remove();
203 } 209 }
204 } 210 }
205 } 211 }
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698