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

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 1154423009: Make it easier and more efficient to use trusted HTML text (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Formatting Created 5 years, 6 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') | tests/html/custom/created_callback_test.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 5ab6241ee4e47d93cb7c2ca1fae7ac7e4579d59b..1de3e1cc28e3865a0fea7f8051e264284cb7a318 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -12423,8 +12423,12 @@ abstract class Element extends Node implements GlobalEventHandlers, ParentNode,
*/
void insertAdjacentHtml(String where, String html, {NodeValidator validator,
NodeTreeSanitizer treeSanitizer}) {
- _insertAdjacentNode(where, new DocumentFragment.html(html,
- validator: validator, treeSanitizer: treeSanitizer));
+ if (treeSanitizer is _TrustedHtmlTreeSanitizer) {
+ _insertAdjacentHtml(where, html);
+ } else {
+ _insertAdjacentNode(where, new DocumentFragment.html(html,
+ validator: validator, treeSanitizer: treeSanitizer));
+ }
}
@@ -12695,8 +12699,12 @@ abstract class Element extends Node implements GlobalEventHandlers, ParentNode,
void setInnerHtml(String html,
{NodeValidator validator, NodeTreeSanitizer treeSanitizer}) {
text = null;
- append(createFragment(
- html, validator: validator, treeSanitizer: treeSanitizer));
+ if (treeSanitizer is _TrustedHtmlTreeSanitizer) {
+ _innerHtml = html;
+ } else {
+ append(createFragment(
+ html, validator: validator, treeSanitizer: treeSanitizer));
+ }
}
String get innerHtml => _innerHtml;
@@ -40622,9 +40630,27 @@ abstract class NodeTreeSanitizer {
* will mark the entire tree as unsafe.
*/
void sanitizeTree(Node node);
+
+ /**
+ * A sanitizer for trees that we trust. It does no validation and allows
+ * any elements. It is also more efficient, since it can pass the text
+ * directly through to the underlying APIs without creating a document
+ * fragment to be sanitized.
+ */
+ static const trusted = const _TrustedHtmlTreeSanitizer();
}
/**
+ * A sanitizer for trees that we trust. It does no validation and allows
+ * any elements.
+ */
+class _TrustedHtmlTreeSanitizer implements NodeTreeSanitizer {
+ const _TrustedHtmlTreeSanitizer();
+
+ sanitizeTree(Node node) {}
+}
+
+/**
* Defines the policy for what types of uris are allowed for particular
* attribute values.
*
« no previous file with comments | « sdk/lib/html/dart2js/html_dart2js.dart ('k') | tests/html/custom/created_callback_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698