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

Unified Diff: tools/dom/templates/html/impl/impl_SVGElement.darttemplate

Issue 16374007: First rev of Safe DOM (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixing up recent test additions. 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
Index: tools/dom/templates/html/impl/impl_SVGElement.darttemplate
diff --git a/tools/dom/templates/html/impl/impl_SVGElement.darttemplate b/tools/dom/templates/html/impl/impl_SVGElement.darttemplate
index 02963d7cdbf01cadfa3e1840be9d710dec7da1d8..0838bd2e5e35a328a0f2a5de0307fc3d6fc76eeb 100644
--- a/tools/dom/templates/html/impl/impl_SVGElement.darttemplate
+++ b/tools/dom/templates/html/impl/impl_SVGElement.darttemplate
@@ -31,10 +31,29 @@ class _AttributeClassSet extends CssClassSetImpl {
}
$(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
+ static final _START_TAG_REGEXP = new RegExp('<(\\w+)');
+
factory $CLASSNAME.tag(String tag) =>
- _$(CLASSNAME)FactoryProvider.create$(CLASSNAME)_tag(tag);
- factory $CLASSNAME.svg(String svg) =>
- _$(CLASSNAME)FactoryProvider.create$(CLASSNAME)_svg(svg);
+ document.$dom_createElementNS("http://www.w3.org/2000/svg", tag);
+ factory $CLASSNAME.svg(String svg,
+ {NodeValidator validator, NodeTreeSanitizer treeSanitizer}) {
+
+ if (validator == null && treeSanitizer == null) {
+ validator = new NodeValidatorBuilder.common()
+ ..allowSvg();
Jennifer Messerly 2013/08/17 06:07:07 remove newline?
blois 2013/08/19 22:02:09 Done.
+ }
+
+ final match = _START_TAG_REGEXP.firstMatch(svg);
+ var parentElement;
+ if (match != null && match.group(1).toLowerCase() == 'svg') {
+ parentElement = document.body;
+ } else {
+ parentElement = new SvgSvgElement();
+ }
+ var fragment = parentElement.createFragment(svg, validator: validator,
+ treeSanitizer: treeSanitizer);
+ return fragment.nodes.where((e) => e is SvgElement).single;
+ }
_AttributeClassSet _cssClassSet;
CssClassSet get classes {
@@ -66,12 +85,29 @@ $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
return container.innerHtml;
}
- void set innerHtml(String svg) {
- final container = new Element.tag("div");
- // Wrap the SVG string in <svg> so that SvgElements are created, rather than
- // HTMLElements.
- container.innerHtml = '<svg version="1.1">$svg</svg>';
- this.children = container.children[0].children;
+ DocumentFragment createFragment(String svg,
+ {NodeValidator validator, NodeTreeSanitizer treeSanitizer}) {
+
+ if (treeSanitizer == null) {
+ if (validator == null) {
+ validator = new NodeValidatorBuilder.common()
+ ..allowSvg();
+ }
+ treeSanitizer = new NodeTreeSanitizer(validator);
+ }
+
+ // We create a fragment which will parse in the HTML parser
+ var html = '<svg version="1.1">$svg</svg>';
+ var fragment = document.body.createFragment(html,
+ treeSanitizer: treeSanitizer);
+
+ var svgFragment = new DocumentFragment();
+ // The root is the <svg/> element, need to pull out the contents.
+ var root = fragment.nodes.single;
+ while (root.firstChild != null) {
+ svgFragment.append(root.firstChild);
+ }
+ return svgFragment;
}
// Unsupported methods inherited from Element.

Powered by Google App Engine
This is Rietveld 408576698