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

Unified Diff: tools/dom/src/Html5NodeValidator.dart

Issue 16374007: First rev of Safe DOM (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/dom/scripts/systemhtml.py ('k') | tools/dom/src/NodeValidatorBuilder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/Html5NodeValidator.dart
diff --git a/tools/dom/src/Html5NodeValidator.dart b/tools/dom/src/Html5NodeValidator.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a5e0e57c42f28da3e2052ac31d5864536e63c567
--- /dev/null
+++ b/tools/dom/src/Html5NodeValidator.dart
@@ -0,0 +1,450 @@
+// DO NOT EDIT- this file is generated from running tool/generator.sh.
+
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of dart.dom.html;
+
+/**
+ * A Dart DOM validator generated from Caja whitelists.
+ *
+ * This contains a whitelist of known HTML tagNames and attributes and will only
+ * accept known good values.
+ *
+ * See also:
+ *
+ * * <https://code.google.com/p/google-caja/wiki/CajaWhitelists>
+ */
+class _Html5NodeValidator implements NodeValidator {
+
+ static final Set<String> _allowedElements = new Set.from([
+ 'A',
+ 'ABBR',
+ 'ACRONYM',
+ 'ADDRESS',
+ 'AREA',
+ 'ARTICLE',
+ 'ASIDE',
+ 'AUDIO',
+ 'B',
+ 'BDI',
+ 'BDO',
+ 'BIG',
+ 'BLOCKQUOTE',
+ 'BR',
+ 'BUTTON',
+ 'CANVAS',
+ 'CAPTION',
+ 'CENTER',
+ 'CITE',
+ 'CODE',
+ 'COL',
+ 'COLGROUP',
+ 'COMMAND',
+ 'DATA',
+ 'DATALIST',
+ 'DD',
+ 'DEL',
+ 'DETAILS',
+ 'DFN',
+ 'DIR',
+ 'DIV',
+ 'DL',
+ 'DT',
+ 'EM',
+ 'FIELDSET',
+ 'FIGCAPTION',
+ 'FIGURE',
+ 'FONT',
+ 'FOOTER',
+ 'FORM',
+ 'H1',
+ 'H2',
+ 'H3',
+ 'H4',
+ 'H5',
+ 'H6',
+ 'HEADER',
+ 'HGROUP',
+ 'HR',
+ 'I',
+ 'IFRAME',
+ 'IMG',
+ 'INPUT',
+ 'INS',
+ 'KBD',
+ 'LABEL',
+ 'LEGEND',
+ 'LI',
+ 'MAP',
+ 'MARK',
+ 'MENU',
+ 'METER',
+ 'NAV',
+ 'NOBR',
+ 'OL',
+ 'OPTGROUP',
+ 'OPTION',
+ 'OUTPUT',
+ 'P',
+ 'PRE',
+ 'PROGRESS',
+ 'Q',
+ 'S',
+ 'SAMP',
+ 'SECTION',
+ 'SELECT',
+ 'SMALL',
+ 'SOURCE',
+ 'SPAN',
+ 'STRIKE',
+ 'STRONG',
+ 'SUB',
+ 'SUMMARY',
+ 'SUP',
+ 'TABLE',
+ 'TBODY',
+ 'TD',
+ 'TEXTAREA',
+ 'TFOOT',
+ 'TH',
+ 'THEAD',
+ 'TIME',
+ 'TR',
+ 'TRACK',
+ 'TT',
+ 'U',
+ 'UL',
+ 'VAR',
+ 'VIDEO',
+ 'WBR',
+ ]);
+
+ static const _standardAttributes = const <String>[
+ '*::class',
+ '*::dir',
+ '*::draggable',
+ '*::hidden',
+ '*::id',
+ '*::inert',
+ '*::itemprop',
+ '*::itemref',
+ '*::itemscope',
+ '*::lang',
+ '*::spellcheck',
+ '*::title',
+ '*::translate',
+ 'A::accesskey',
+ 'A::coords',
+ 'A::hreflang',
+ 'A::name',
+ 'A::shape',
+ 'A::tabindex',
+ 'A::target',
+ 'A::type',
+ 'AREA::accesskey',
+ 'AREA::alt',
+ 'AREA::coords',
+ 'AREA::nohref',
+ 'AREA::shape',
+ 'AREA::tabindex',
+ 'AREA::target',
+ 'AUDIO::controls',
+ 'AUDIO::loop',
+ 'AUDIO::mediagroup',
+ 'AUDIO::muted',
+ 'AUDIO::preload',
+ 'BDO::dir',
+ 'BODY::alink',
+ 'BODY::bgcolor',
+ 'BODY::link',
+ 'BODY::text',
+ 'BODY::vlink',
+ 'BR::clear',
+ 'BUTTON::accesskey',
+ 'BUTTON::disabled',
+ 'BUTTON::name',
+ 'BUTTON::tabindex',
+ 'BUTTON::type',
+ 'BUTTON::value',
+ 'CANVAS::height',
+ 'CANVAS::width',
+ 'CAPTION::align',
+ 'COL::align',
+ 'COL::char',
+ 'COL::charoff',
+ 'COL::span',
+ 'COL::valign',
+ 'COL::width',
+ 'COLGROUP::align',
+ 'COLGROUP::char',
+ 'COLGROUP::charoff',
+ 'COLGROUP::span',
+ 'COLGROUP::valign',
+ 'COLGROUP::width',
+ 'COMMAND::checked',
+ 'COMMAND::command',
+ 'COMMAND::disabled',
+ 'COMMAND::label',
+ 'COMMAND::radiogroup',
+ 'COMMAND::type',
+ 'DATA::value',
+ 'DEL::datetime',
+ 'DETAILS::open',
+ 'DIR::compact',
+ 'DIV::align',
+ 'DL::compact',
+ 'FIELDSET::disabled',
+ 'FONT::color',
+ 'FONT::face',
+ 'FONT::size',
+ 'FORM::accept',
+ 'FORM::autocomplete',
+ 'FORM::enctype',
+ 'FORM::method',
+ 'FORM::name',
+ 'FORM::novalidate',
+ 'FORM::target',
+ 'FRAME::name',
+ 'H1::align',
+ 'H2::align',
+ 'H3::align',
+ 'H4::align',
+ 'H5::align',
+ 'H6::align',
+ 'HR::align',
+ 'HR::noshade',
+ 'HR::size',
+ 'HR::width',
+ 'HTML::version',
+ 'IFRAME::align',
+ 'IFRAME::frameborder',
+ 'IFRAME::height',
+ 'IFRAME::marginheight',
+ 'IFRAME::marginwidth',
+ 'IFRAME::width',
+ 'IMG::align',
+ 'IMG::alt',
+ 'IMG::border',
+ 'IMG::height',
+ 'IMG::hspace',
+ 'IMG::ismap',
+ 'IMG::name',
+ 'IMG::usemap',
+ 'IMG::vspace',
+ 'IMG::width',
+ 'INPUT::accept',
+ 'INPUT::accesskey',
+ 'INPUT::align',
+ 'INPUT::alt',
+ 'INPUT::autocomplete',
+ 'INPUT::checked',
+ 'INPUT::disabled',
+ 'INPUT::inputmode',
+ 'INPUT::ismap',
+ 'INPUT::list',
+ 'INPUT::max',
+ 'INPUT::maxlength',
+ 'INPUT::min',
+ 'INPUT::multiple',
+ 'INPUT::name',
+ 'INPUT::placeholder',
+ 'INPUT::readonly',
+ 'INPUT::required',
+ 'INPUT::size',
+ 'INPUT::step',
+ 'INPUT::tabindex',
+ 'INPUT::type',
+ 'INPUT::usemap',
+ 'INPUT::value',
+ 'INS::datetime',
+ 'KEYGEN::disabled',
+ 'KEYGEN::keytype',
+ 'KEYGEN::name',
+ 'LABEL::accesskey',
+ 'LABEL::for',
+ 'LEGEND::accesskey',
+ 'LEGEND::align',
+ 'LI::type',
+ 'LI::value',
+ 'LINK::sizes',
+ 'MAP::name',
+ 'MENU::compact',
+ 'MENU::label',
+ 'MENU::type',
+ 'METER::high',
+ 'METER::low',
+ 'METER::max',
+ 'METER::min',
+ 'METER::value',
+ 'OBJECT::typemustmatch',
+ 'OL::compact',
+ 'OL::reversed',
+ 'OL::start',
+ 'OL::type',
+ 'OPTGROUP::disabled',
+ 'OPTGROUP::label',
+ 'OPTION::disabled',
+ 'OPTION::label',
+ 'OPTION::selected',
+ 'OPTION::value',
+ 'OUTPUT::for',
+ 'OUTPUT::name',
+ 'P::align',
+ 'PRE::width',
+ 'PROGRESS::max',
+ 'PROGRESS::min',
+ 'PROGRESS::value',
+ 'SELECT::autocomplete',
+ 'SELECT::disabled',
+ 'SELECT::multiple',
+ 'SELECT::name',
+ 'SELECT::required',
+ 'SELECT::size',
+ 'SELECT::tabindex',
+ 'SOURCE::type',
+ 'TABLE::align',
+ 'TABLE::bgcolor',
+ 'TABLE::border',
+ 'TABLE::cellpadding',
+ 'TABLE::cellspacing',
+ 'TABLE::frame',
+ 'TABLE::rules',
+ 'TABLE::summary',
+ 'TABLE::width',
+ 'TBODY::align',
+ 'TBODY::char',
+ 'TBODY::charoff',
+ 'TBODY::valign',
+ 'TD::abbr',
+ 'TD::align',
+ 'TD::axis',
+ 'TD::bgcolor',
+ 'TD::char',
+ 'TD::charoff',
+ 'TD::colspan',
+ 'TD::headers',
+ 'TD::height',
+ 'TD::nowrap',
+ 'TD::rowspan',
+ 'TD::scope',
+ 'TD::valign',
+ 'TD::width',
+ 'TEXTAREA::accesskey',
+ 'TEXTAREA::autocomplete',
+ 'TEXTAREA::cols',
+ 'TEXTAREA::disabled',
+ 'TEXTAREA::inputmode',
+ 'TEXTAREA::name',
+ 'TEXTAREA::placeholder',
+ 'TEXTAREA::readonly',
+ 'TEXTAREA::required',
+ 'TEXTAREA::rows',
+ 'TEXTAREA::tabindex',
+ 'TEXTAREA::wrap',
+ 'TFOOT::align',
+ 'TFOOT::char',
+ 'TFOOT::charoff',
+ 'TFOOT::valign',
+ 'TH::abbr',
+ 'TH::align',
+ 'TH::axis',
+ 'TH::bgcolor',
+ 'TH::char',
+ 'TH::charoff',
+ 'TH::colspan',
+ 'TH::headers',
+ 'TH::height',
+ 'TH::nowrap',
+ 'TH::rowspan',
+ 'TH::scope',
+ 'TH::valign',
+ 'TH::width',
+ 'THEAD::align',
+ 'THEAD::char',
+ 'THEAD::charoff',
+ 'THEAD::valign',
+ 'TR::align',
+ 'TR::bgcolor',
+ 'TR::char',
+ 'TR::charoff',
+ 'TR::valign',
+ 'TRACK::default',
+ 'TRACK::kind',
+ 'TRACK::label',
+ 'TRACK::srclang',
+ 'UL::compact',
+ 'UL::type',
+ 'VIDEO::controls',
+ 'VIDEO::height',
+ 'VIDEO::loop',
+ 'VIDEO::mediagroup',
+ 'VIDEO::muted',
+ 'VIDEO::preload',
+ 'VIDEO::width',
+ ];
+
+ static const _uriAttributes = const <String>[
+ 'A::href',
+ 'AREA::href',
+ 'BLOCKQUOTE::cite',
+ 'BODY::background',
+ 'COMMAND::icon',
+ 'DEL::cite',
+ 'FORM::action',
+ 'IMG::src',
+ 'INPUT::src',
+ 'INS::cite',
+ 'Q::cite',
+ 'VIDEO::poster',
+ ];
+
+ final UriPolicy uriPolicy;
+
+ static final Map<String, Function> _attributeValidators = {};
+
+ /**
+ * All known URI attributes will be validated against the UriPolicy, if
+ * [uriPolicy] is null then a default UriPolicy will be used.
+ */
+ _Html5NodeValidator({UriPolicy uriPolicy})
+ :uriPolicy = uriPolicy != null ? uriPolicy : new UriPolicy() {
+
+ if (_attributeValidators.isEmpty) {
+ for (var attr in _standardAttributes) {
+ _attributeValidators[attr] = _standardAttributeValidator;
+ }
+
+ for (var attr in _uriAttributes) {
+ _attributeValidators[attr] = _uriAttributeValidator;
+ }
+ }
+ }
+
+ bool allowsElement(Element element) {
+ return _allowedElements.contains(element.tagName);
+ }
+
+ bool allowsAttribute(Element element, String attributeName, String value) {
+ var tagName = element.tagName;
+ var validator = _attributeValidators['$tagName::$attributeName'];
+ if (validator == null) {
+ validator = _attributeValidators['*::$attributeName'];
+ }
+ if (validator == null) {
+ return false;
+ }
+ return validator(element, attributeName, value, this);
+ }
+
+ static bool _standardAttributeValidator(Element element, String attributeName,
+ String value, _Html5NodeValidator context) {
+ return true;
+ }
+
+ static bool _uriAttributeValidator(Element element, String attributeName,
+ String value, _Html5NodeValidator context) {
+ return context.uriPolicy.allowsUri(value);
+ }
+}
« no previous file with comments | « tools/dom/scripts/systemhtml.py ('k') | tools/dom/src/NodeValidatorBuilder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698