summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/trustedtypes/trusted_html.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/trustedtypes/trusted_html.cc')
-rw-r--r--chromium/third_party/blink/renderer/core/trustedtypes/trusted_html.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/chromium/third_party/blink/renderer/core/trustedtypes/trusted_html.cc b/chromium/third_party/blink/renderer/core/trustedtypes/trusted_html.cc
index 2b1cf3fa061..54b6f1a6e45 100644
--- a/chromium/third_party/blink/renderer/core/trustedtypes/trusted_html.cc
+++ b/chromium/third_party/blink/renderer/core/trustedtypes/trusted_html.cc
@@ -4,7 +4,10 @@
#include "third_party/blink/renderer/core/trustedtypes/trusted_html.h"
+#include "third_party/blink/renderer/bindings/core/v8/string_or_trusted_html.h"
+#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
+#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink {
@@ -30,6 +33,25 @@ TrustedHTML* TrustedHTML::unsafelyCreate(ScriptState* script_state,
return TrustedHTML::Create(html);
}
+String TrustedHTML::GetString(StringOrTrustedHTML stringOrHTML,
+ const Document* doc,
+ ExceptionState& exception_state) {
+ DCHECK(stringOrHTML.IsString() ||
+ RuntimeEnabledFeatures::TrustedDOMTypesEnabled());
+ DCHECK(!stringOrHTML.IsNull());
+
+ if (!stringOrHTML.IsTrustedHTML() && doc && doc->RequireTrustedTypes()) {
+ exception_state.ThrowTypeError(
+ "This document requires `TrustedHTML` assignment.");
+ return g_empty_string;
+ }
+
+ String markup = stringOrHTML.IsString()
+ ? stringOrHTML.GetAsString()
+ : stringOrHTML.GetAsTrustedHTML()->toString();
+ return markup;
+}
+
String TrustedHTML::toString() const {
return html_;
}