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

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

Issue 1894713002: Strong html (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: ready for review Created 4 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 // 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 * Class which helps construct standard node validation policies. 9 * Class which helps construct standard node validation policies.
10 * 10 *
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 * This will allow the elements as custom tags (such as <x-foo></x-foo>), 150 * This will allow the elements as custom tags (such as <x-foo></x-foo>),
151 * but will not allow tag extensions. Use [allowTagExtension] to allow 151 * but will not allow tag extensions. Use [allowTagExtension] to allow
152 * tag extensions. 152 * tag extensions.
153 */ 153 */
154 void allowCustomElement(String tagName, 154 void allowCustomElement(String tagName,
155 {UriPolicy uriPolicy, 155 {UriPolicy uriPolicy,
156 Iterable<String> attributes, 156 Iterable<String> attributes,
157 Iterable<String> uriAttributes}) { 157 Iterable<String> uriAttributes}) {
158 158
159 var tagNameUpper = tagName.toUpperCase(); 159 var tagNameUpper = tagName.toUpperCase();
160 var attrs; 160 var attrs = attributes != null ?
161 if (attributes != null) { 161 attributes.map/*<String>*/((name) => '$tagNameUpper::${name.toLowerCase( )}') : null;
162 attrs = 162 var uriAttrs = uriAttributes != null ?
163 attributes.map((name) => '$tagNameUpper::${name.toLowerCase()}'); 163 uriAttributes.map/*<String>*/((name) => '$tagNameUpper::${name.toLowerCa se()}') : null;
164 }
165 var uriAttrs;
166 if (uriAttributes != null) {
167 uriAttrs =
168 uriAttributes.map((name) => '$tagNameUpper::${name.toLowerCase()}');
169 }
170 if (uriPolicy == null) { 164 if (uriPolicy == null) {
171 uriPolicy = new UriPolicy(); 165 uriPolicy = new UriPolicy();
172 } 166 }
173 167
174 add(new _CustomElementNodeValidator( 168 add(new _CustomElementNodeValidator(
175 uriPolicy, 169 uriPolicy,
176 [tagNameUpper], 170 [tagNameUpper],
177 attrs, 171 attrs,
178 uriAttrs, 172 uriAttrs,
179 false, 173 false,
180 true)); 174 true));
181 } 175 }
182 176
183 /** 177 /**
184 * Allow custom tag extensions with the specified type name and specified 178 * Allow custom tag extensions with the specified type name and specified
185 * attributes. 179 * attributes.
186 * 180 *
187 * This will allow tag extensions (such as <div is="x-foo"></div>), 181 * This will allow tag extensions (such as <div is="x-foo"></div>),
188 * but will not allow custom tags. Use [allowCustomElement] to allow 182 * but will not allow custom tags. Use [allowCustomElement] to allow
189 * custom tags. 183 * custom tags.
190 */ 184 */
191 void allowTagExtension(String tagName, String baseName, 185 void allowTagExtension(String tagName, String baseName,
192 {UriPolicy uriPolicy, 186 {UriPolicy uriPolicy,
193 Iterable<String> attributes, 187 Iterable<String> attributes,
194 Iterable<String> uriAttributes}) { 188 Iterable<String> uriAttributes}) {
195 189
196 var baseNameUpper = baseName.toUpperCase(); 190 var baseNameUpper = baseName.toUpperCase();
197 var tagNameUpper = tagName.toUpperCase(); 191 var tagNameUpper = tagName.toUpperCase();
198 var attrs; 192 var attrs = attributes != null ? attributes.map/*<String>*/((name) => '$base NameUpper::${name.toLowerCase()}') : null;
199 if (attributes != null) { 193 var uriAttrs = uriAttributes != null ? uriAttributes.map/*<String>*/((name) => '$baseNameUpper::${name.toLowerCase()}') : null;
200 attrs =
201 attributes.map((name) => '$baseNameUpper::${name.toLowerCase()}');
202 }
203 var uriAttrs;
204 if (uriAttributes != null) {
205 uriAttrs =
206 uriAttributes.map((name) => '$baseNameUpper::${name.toLowerCase()}');
207 }
208 if (uriPolicy == null) { 194 if (uriPolicy == null) {
209 uriPolicy = new UriPolicy(); 195 uriPolicy = new UriPolicy();
210 } 196 }
211 197
212 add(new _CustomElementNodeValidator( 198 add(new _CustomElementNodeValidator(
213 uriPolicy, 199 uriPolicy,
214 [tagNameUpper, baseNameUpper], 200 [tagNameUpper, baseNameUpper],
215 attrs, 201 attrs,
216 uriAttrs, 202 uriAttrs,
217 true, 203 true,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 class _CustomElementNodeValidator extends _SimpleNodeValidator { 369 class _CustomElementNodeValidator extends _SimpleNodeValidator {
384 final bool allowTypeExtension; 370 final bool allowTypeExtension;
385 final bool allowCustomTag; 371 final bool allowCustomTag;
386 372
387 _CustomElementNodeValidator(UriPolicy uriPolicy, 373 _CustomElementNodeValidator(UriPolicy uriPolicy,
388 Iterable<String> allowedElements, 374 Iterable<String> allowedElements,
389 Iterable<String> allowedAttributes, 375 Iterable<String> allowedAttributes,
390 Iterable<String> allowedUriAttributes, 376 Iterable<String> allowedUriAttributes,
391 bool allowTypeExtension, 377 bool allowTypeExtension,
392 bool allowCustomTag): 378 bool allowCustomTag):
393 379 this.allowTypeExtension = allowTypeExtension == true,
380 this.allowCustomTag = allowCustomTag == true,
394 super(uriPolicy, 381 super(uriPolicy,
395 allowedElements: allowedElements, 382 allowedElements: allowedElements,
396 allowedAttributes: allowedAttributes, 383 allowedAttributes: allowedAttributes,
397 allowedUriAttributes: allowedUriAttributes), 384 allowedUriAttributes: allowedUriAttributes);
398 this.allowTypeExtension = allowTypeExtension == true,
399 this.allowCustomTag = allowCustomTag == true;
400 385
401 bool allowsElement(Element element) { 386 bool allowsElement(Element element) {
402 if (allowTypeExtension) { 387 if (allowTypeExtension) {
403 var isAttr = element.attributes['is']; 388 var isAttr = element.attributes['is'];
404 if (isAttr != null) { 389 if (isAttr != null) {
405 return allowedElements.contains(isAttr.toUpperCase()) && 390 return allowedElements.contains(isAttr.toUpperCase()) &&
406 allowedElements.contains(Element._safeTagName(element)); 391 allowedElements.contains(Element._safeTagName(element));
407 } 392 }
408 } 393 }
409 return allowCustomTag && allowedElements.contains(Element._safeTagName(eleme nt)); 394 return allowCustomTag && allowedElements.contains(Element._safeTagName(eleme nt));
(...skipping 11 matching lines...) Expand all
421 } 406 }
422 } 407 }
423 408
424 class _TemplatingNodeValidator extends _SimpleNodeValidator { 409 class _TemplatingNodeValidator extends _SimpleNodeValidator {
425 static const _TEMPLATE_ATTRS = 410 static const _TEMPLATE_ATTRS =
426 const <String>['bind', 'if', 'ref', 'repeat', 'syntax']; 411 const <String>['bind', 'if', 'ref', 'repeat', 'syntax'];
427 412
428 final Set<String> _templateAttrs; 413 final Set<String> _templateAttrs;
429 414
430 _TemplatingNodeValidator(): 415 _TemplatingNodeValidator():
416 _templateAttrs = new Set<String>.from(_TEMPLATE_ATTRS),
431 super(null, 417 super(null,
432 allowedElements: [ 418 allowedElements: [
433 'TEMPLATE' 419 'TEMPLATE'
434 ], 420 ],
435 allowedAttributes: _TEMPLATE_ATTRS.map((attr) => 'TEMPLATE::$attr')), 421 allowedAttributes: _TEMPLATE_ATTRS.map((attr) => 'TEMPLATE::$attr')) {
436 _templateAttrs = new Set<String>.from(_TEMPLATE_ATTRS) {
437 } 422 }
438 423
439 bool allowsAttribute(Element element, String attributeName, String value) { 424 bool allowsAttribute(Element element, String attributeName, String value) {
440 if (super.allowsAttribute(element, attributeName, value)) { 425 if (super.allowsAttribute(element, attributeName, value)) {
441 return true; 426 return true;
442 } 427 }
443 428
444 if (attributeName == 'template' && value == "") { 429 if (attributeName == 'template' && value == "") {
445 return true; 430 return true;
446 } 431 }
(...skipping 24 matching lines...) Expand all
471 return false; 456 return false;
472 } 457 }
473 458
474 bool allowsAttribute(Element element, String attributeName, String value) { 459 bool allowsAttribute(Element element, String attributeName, String value) {
475 if (attributeName == 'is' || attributeName.startsWith('on')) { 460 if (attributeName == 'is' || attributeName.startsWith('on')) {
476 return false; 461 return false;
477 } 462 }
478 return allowsElement(element); 463 return allowsElement(element);
479 } 464 }
480 } 465 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698