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

Unified Diff: sdk/lib/html/dartium/html_dartium.dart

Side-by-side diff isn't available for this file because of its large size.
Issue 1123173003: Another try at appendHtml and insertAdjacentHtml should be consistently sanitized (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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:
Download patch
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | sdk/lib/svg/dart2js/svg_dart2js.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/dartium/html_dartium.dart
diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart
index 62bf3eeb517b617d84905b6ba35dd0217b821e44..25d91f6ec164c1a4b3897437e8bd5367cc704467 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -9412,8 +9412,10 @@ class DocumentFragment extends Node implements ParentNode {
* Parses the specified text as HTML and adds the resulting node after the
* last child of this document fragment.
*/
- void appendHtml(String text) {
- this.append(new DocumentFragment.html(text));
+ void appendHtml(String text, {NodeValidator validator,
+ NodeTreeSanitizer, treeSanitizer}) {
+ this.append(new DocumentFragment.html(text, validator: validator,
+ treeSanitizer: treeSanitizer));
}
/**
@@ -12255,8 +12257,10 @@ abstract class Element extends Node implements GlobalEventHandlers, ParentNode,
* Parses the specified text as HTML and adds the resulting node after the
* last child of this element.
*/
- void appendHtml(String text) {
- this.insertAdjacentHtml('beforeend', text);
+ void appendHtml(String text, {NodeValidator validator,
+ NodeTreeSanitizer treeSanitizer}) {
+ this.insertAdjacentHtml('beforeend', text, validator: validator,
+ treeSanitizer: treeSanitizer);
}
/**
@@ -12395,6 +12399,56 @@ abstract class Element extends Node implements GlobalEventHandlers, ParentNode,
}
+ /**
+ * Parses text as an HTML fragment and inserts it into the DOM at the
+ * specified location.
+ *
+ * The [where] parameter indicates where to insert the HTML fragment:
+ *
+ * * 'beforeBegin': Immediately before this element.
+ * * 'afterBegin': As the first child of this element.
+ * * 'beforeEnd': As the last child of this element.
+ * * 'afterEnd': Immediately after this element.
+ *
+ * var html = '<div class="something">content</div>';
+ * // Inserts as the first child
+ * document.body.insertAdjacentHtml('afterBegin', html);
+ * var createdElement = document.body.children[0];
+ * print(createdElement.classes[0]); // Prints 'something'
+ *
+ * See also:
+ *
+ * * [insertAdjacentText]
+ * * [insertAdjacentElement]
+ */
+ void insertAdjacentHtml(String where, String html, {NodeValidator validator,
+ NodeTreeSanitizer treeSanitizer}) {
+ _insertAdjacentNode(where, new DocumentFragment.html(html,
+ validator: validator, treeSanitizer: treeSanitizer));
+ }
+
+
+ void _insertAdjacentNode(String where, Node node) {
+ switch (where.toLowerCase()) {
+ case 'beforebegin':
+ this.parentNode.insertBefore(node, this);
+ break;
+ case 'afterbegin':
+ var first = this.nodes.length > 0 ? this.nodes[0] : null;
+ this.insertBefore(node, first);
+ break;
+ case 'beforeend':
+ this.append(node);
+ break;
+ case 'afterend':
+ this.parentNode.insertBefore(node, this.nextNode);
+ break;
+ default:
+ throw new ArgumentError("Invalid position ${where}");
+ }
+ }
+
+
/** Checks if this element or any of its parents match the CSS selectors. */
@Experimental()
bool matchesWithAncestors(String selectors) {
@@ -13649,7 +13703,7 @@ abstract class Element extends Node implements GlobalEventHandlers, ParentNode,
@DomName('Element.insertAdjacentHTML')
@DocsEditable()
@Experimental() // untriaged
- void insertAdjacentHtml(String where, String html) => _blink.BlinkElement.instance.insertAdjacentHTML_Callback_2_(this, where, html);
+ void _insertAdjacentHtml(String where, String html) => _blink.BlinkElement.instance.insertAdjacentHTML_Callback_2_(this, where, html);
@DomName('Element.insertAdjacentText')
@DocsEditable()
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | sdk/lib/svg/dart2js/svg_dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698