| OLD | NEW |
| 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 * Class which helps construct standard node validation policies. | 8 * Class which helps construct standard node validation policies. |
| 9 * | 9 * |
| 10 * By default this will not accept anything, but the 'allow*' functions can be | 10 * By default this will not accept anything, but the 'allow*' functions can be |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 * This will allow the elements as custom tags (such as <x-foo></x-foo>), | 147 * This will allow the elements as custom tags (such as <x-foo></x-foo>), |
| 148 * but will not allow tag extensions. Use [allowTagExtension] to allow | 148 * but will not allow tag extensions. Use [allowTagExtension] to allow |
| 149 * tag extensions. | 149 * tag extensions. |
| 150 */ | 150 */ |
| 151 void allowCustomElement(String tagName, | 151 void allowCustomElement(String tagName, |
| 152 {UriPolicy uriPolicy, | 152 {UriPolicy uriPolicy, |
| 153 Iterable<String> attributes, | 153 Iterable<String> attributes, |
| 154 Iterable<String> uriAttributes}) { | 154 Iterable<String> uriAttributes}) { |
| 155 var tagNameUpper = tagName.toUpperCase(); | 155 var tagNameUpper = tagName.toUpperCase(); |
| 156 var attrs = attributes | 156 var attrs = attributes |
| 157 ?.map /*<String>*/ ((name) => '$tagNameUpper::${name.toLowerCase()}'); | 157 ?.map/*<String>*/((name) => '$tagNameUpper::${name.toLowerCase()}'); |
| 158 var uriAttrs = uriAttributes | 158 var uriAttrs = uriAttributes |
| 159 ?.map /*<String>*/ ((name) => '$tagNameUpper::${name.toLowerCase()}'); | 159 ?.map/*<String>*/((name) => '$tagNameUpper::${name.toLowerCase()}'); |
| 160 if (uriPolicy == null) { | 160 if (uriPolicy == null) { |
| 161 uriPolicy = new UriPolicy(); | 161 uriPolicy = new UriPolicy(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 add(new _CustomElementNodeValidator( | 164 add(new _CustomElementNodeValidator( |
| 165 uriPolicy, [tagNameUpper], attrs, uriAttrs, false, true)); | 165 uriPolicy, [tagNameUpper], attrs, uriAttrs, false, true)); |
| 166 } | 166 } |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * Allow custom tag extensions with the specified type name and specified | 169 * Allow custom tag extensions with the specified type name and specified |
| 170 * attributes. | 170 * attributes. |
| 171 * | 171 * |
| 172 * This will allow tag extensions (such as <div is="x-foo"></div>), | 172 * This will allow tag extensions (such as <div is="x-foo"></div>), |
| 173 * but will not allow custom tags. Use [allowCustomElement] to allow | 173 * but will not allow custom tags. Use [allowCustomElement] to allow |
| 174 * custom tags. | 174 * custom tags. |
| 175 */ | 175 */ |
| 176 void allowTagExtension(String tagName, String baseName, | 176 void allowTagExtension(String tagName, String baseName, |
| 177 {UriPolicy uriPolicy, | 177 {UriPolicy uriPolicy, |
| 178 Iterable<String> attributes, | 178 Iterable<String> attributes, |
| 179 Iterable<String> uriAttributes}) { | 179 Iterable<String> uriAttributes}) { |
| 180 var baseNameUpper = baseName.toUpperCase(); | 180 var baseNameUpper = baseName.toUpperCase(); |
| 181 var tagNameUpper = tagName.toUpperCase(); | 181 var tagNameUpper = tagName.toUpperCase(); |
| 182 var attrs = attributes | 182 var attrs = attributes |
| 183 ?.map /*<String>*/ ((name) => '$baseNameUpper::${name.toLowerCase()}'); | 183 ?.map/*<String>*/((name) => '$baseNameUpper::${name.toLowerCase()}'); |
| 184 var uriAttrs = uriAttributes | 184 var uriAttrs = uriAttributes |
| 185 ?.map /*<String>*/ ((name) => '$baseNameUpper::${name.toLowerCase()}'); | 185 ?.map/*<String>*/((name) => '$baseNameUpper::${name.toLowerCase()}'); |
| 186 if (uriPolicy == null) { | 186 if (uriPolicy == null) { |
| 187 uriPolicy = new UriPolicy(); | 187 uriPolicy = new UriPolicy(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 add(new _CustomElementNodeValidator(uriPolicy, | 190 add(new _CustomElementNodeValidator(uriPolicy, |
| 191 [tagNameUpper, baseNameUpper], attrs, uriAttrs, true, false)); | 191 [tagNameUpper, baseNameUpper], attrs, uriAttrs, true, false)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void allowElement(String tagName, | 194 void allowElement(String tagName, |
| 195 {UriPolicy uriPolicy, | 195 {UriPolicy uriPolicy, |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 return false; | 445 return false; |
| 446 } | 446 } |
| 447 | 447 |
| 448 bool allowsAttribute(Element element, String attributeName, String value) { | 448 bool allowsAttribute(Element element, String attributeName, String value) { |
| 449 if (attributeName == 'is' || attributeName.startsWith('on')) { | 449 if (attributeName == 'is' || attributeName.startsWith('on')) { |
| 450 return false; | 450 return false; |
| 451 } | 451 } |
| 452 return allowsElement(element); | 452 return allowsElement(element); |
| 453 } | 453 } |
| 454 } | 454 } |
| OLD | NEW |