Commit 02df50e5 authored by Yifan Luo's avatar Yifan Luo Committed by Commit Bot

[TrustedTypes] replace union types with WebIDL annotation

This CL add an extended attribute in the WebIDL compiler named
`TrustedType` and change the current ScriptString, ScriptURLString and
HTMLString types in the idl files into DOMString type with a
TrustedType=TrustedScript|TrustedScriptURL|TrustedHTML attribute.

Bug: 1043136
Change-Id: If23c81b59018ede2ef68bc785cde3f70ed9ee981
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2012284Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarDaniel Vogelheim <vogelheim@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Yifan Luo <lyf@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746333}
parent c4a0daca
...@@ -521,6 +521,20 @@ void func([TreatNullAs=Emptytring] DOMString str); ...@@ -521,6 +521,20 @@ void func([TreatNullAs=Emptytring] DOMString str);
Implementation: Given `[TreatNullAs=EmptyString]`, a JavaScript null is converted to a Blink empty string, for which `String::IsEmpty()` returns true, but `String::IsNull()` return false. Implementation: Given `[TreatNullAs=EmptyString]`, a JavaScript null is converted to a Blink empty string, for which `String::IsEmpty()` returns true, but `String::IsNull()` return false.
### [StringContext=TrustedHTML|TrustedScript|TrustedScriptURL] _(t)_
Standard: [TrustedType](https://w3c.github.io/webappsec-trusted-types/dist/spec/#!trustedtypes-extended-attribute)
Summary: Indicate that a DOMString for HTMLs and scripts or USVString for script URLs is to be supplemented with additional Trusted Types enforcement logic.
Usage: Must be specified on a DOMString or a USVString type.
```webidl
typedef [StringContext=TrustedHTML] DOMString TrustedString;
attribute TrustedString str;
void func(TrustedString str);
```
### [Unforgeable] _(m,a)_ ### [Unforgeable] _(m,a)_
Standard: [Unforgeable](http://heycam.github.io/webidl/#Unforgeable) Standard: [Unforgeable](http://heycam.github.io/webidl/#Unforgeable)
......
...@@ -98,6 +98,7 @@ SaveSameObject ...@@ -98,6 +98,7 @@ SaveSameObject
SecureContext=|* SecureContext=|*
Serializable Serializable
SetterCallWith=ExecutionContext|Isolate|ScriptState SetterCallWith=ExecutionContext|Isolate|ScriptState
StringContext=TrustedHTML|TrustedScript|TrustedScriptURL
Transferable Transferable
TreatNonObjectAsNull TreatNonObjectAsNull
TreatNullAs=EmptyString TreatNullAs=EmptyString
......
...@@ -7,10 +7,15 @@ ...@@ -7,10 +7,15 @@
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h" #include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_element.h" #include "third_party/blink/renderer/bindings/core/v8/v8_element.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/node.h"
#include "third_party/blink/renderer/core/dom/range.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/html/custom/ce_reactions_scope.h" #include "third_party/blink/renderer/core/html/custom/ce_reactions_scope.h"
#include "third_party/blink/renderer/core/html/custom/v0_custom_element_processing_stack.h" #include "third_party/blink/renderer/core/html/custom/v0_custom_element_processing_stack.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/core/xml/dom_parser.h"
#include "third_party/blink/renderer/platform/bindings/v8_per_context_data.h" #include "third_party/blink/renderer/platform/bindings/v8_per_context_data.h"
namespace blink { namespace blink {
...@@ -210,6 +215,29 @@ Document* ToDocumentFromExecutionContext(ExecutionContext* execution_context) { ...@@ -210,6 +215,29 @@ Document* ToDocumentFromExecutionContext(ExecutionContext* execution_context) {
return execution_context->ExecutingWindow()->document(); return execution_context->ExecutingWindow()->document();
} }
ExecutionContext* ExecutionContextFromV8Wrappable(
const LocalDOMWindow* window) {
return window->GetExecutionContext();
}
ExecutionContext* ExecutionContextFromV8Wrappable(
const WorkerGlobalScope* scope) {
return scope->GetExecutionContext();
}
ExecutionContext* ExecutionContextFromV8Wrappable(const Node* node) {
return node->GetDocument().ToExecutionContext();
}
ExecutionContext* ExecutionContextFromV8Wrappable(const Range* range) {
return range->startContainer()->GetDocument().ToExecutionContext();
}
ExecutionContext* ExecutionContextFromV8Wrappable(const DOMParser* parser) {
return parser->GetDocument() ? parser->GetDocument()->ToExecutionContext()
: nullptr;
}
} // namespace bindings } // namespace bindings
} // namespace blink } // namespace blink
...@@ -19,9 +19,14 @@ ...@@ -19,9 +19,14 @@
namespace blink { namespace blink {
class Document; class Document;
class DOMParser;
class ExecutionContext; class ExecutionContext;
class LocalDOMWindow;
class Node;
class Range;
class QualifiedName; class QualifiedName;
class ScriptState; class ScriptState;
class WorkerGlobalScope;
CORE_EXPORT void V8ConstructorAttributeGetter( CORE_EXPORT void V8ConstructorAttributeGetter(
v8::Local<v8::Name> property_name, v8::Local<v8::Name> property_name,
...@@ -132,6 +137,20 @@ CORE_EXPORT bool IsEsIterableObject(v8::Isolate* isolate, ...@@ -132,6 +137,20 @@ CORE_EXPORT bool IsEsIterableObject(v8::Isolate* isolate,
CORE_EXPORT Document* ToDocumentFromExecutionContext( CORE_EXPORT Document* ToDocumentFromExecutionContext(
ExecutionContext* execution_context); ExecutionContext* execution_context);
CORE_EXPORT ExecutionContext* ExecutionContextFromV8Wrappable(
const LocalDOMWindow* window);
CORE_EXPORT ExecutionContext* ExecutionContextFromV8Wrappable(
const WorkerGlobalScope* scope);
CORE_EXPORT ExecutionContext* ExecutionContextFromV8Wrappable(const Node* node);
CORE_EXPORT ExecutionContext* ExecutionContextFromV8Wrappable(
const Range* range);
CORE_EXPORT ExecutionContext* ExecutionContextFromV8Wrappable(
const DOMParser* parser);
} // namespace bindings } // namespace bindings
} // namespace blink } // namespace blink
......
...@@ -113,6 +113,16 @@ struct IDLStringBase final : public IDLBaseHelper<String> {}; ...@@ -113,6 +113,16 @@ struct IDLStringBase final : public IDLBaseHelper<String> {};
template <V8StringResourceMode Mode> template <V8StringResourceMode Mode>
struct IDLUSVStringBase final : public IDLBaseHelper<String> {}; struct IDLUSVStringBase final : public IDLBaseHelper<String> {};
template <V8StringResourceMode Mode>
struct IDLStringStringContextTrustedHTMLBase final
: public IDLBaseHelper<String> {};
template <V8StringResourceMode Mode>
struct IDLStringStringContextTrustedScriptBase final
: public IDLBaseHelper<String> {};
template <V8StringResourceMode Mode>
struct IDLUSVStringStringContextTrustedScriptURLBase final
: public IDLBaseHelper<String> {};
// Define non-template versions of the above for simplicity. // Define non-template versions of the above for simplicity.
using IDLByteString = IDLByteStringBase<V8StringResourceMode::kDefaultMode>; using IDLByteString = IDLByteStringBase<V8StringResourceMode::kDefaultMode>;
using IDLString = IDLStringBase<V8StringResourceMode::kDefaultMode>; using IDLString = IDLStringBase<V8StringResourceMode::kDefaultMode>;
...@@ -130,6 +140,33 @@ using IDLUSVStringOrNull = ...@@ -130,6 +140,33 @@ using IDLUSVStringOrNull =
using IDLStringTreatNullAsEmptyString = using IDLStringTreatNullAsEmptyString =
IDLStringBase<V8StringResourceMode::kTreatNullAsEmptyString>; IDLStringBase<V8StringResourceMode::kTreatNullAsEmptyString>;
// [StringContext] Strings
using IDLStringStringContextTrustedHTML =
IDLStringStringContextTrustedHTMLBase<V8StringResourceMode::kDefaultMode>;
using IDLStringStringContextTrustedScript =
IDLStringStringContextTrustedScriptBase<V8StringResourceMode::kDefaultMode>;
using IDLUSVStringStringContextTrustedScriptURL =
IDLUSVStringStringContextTrustedScriptURLBase<
V8StringResourceMode::kDefaultMode>;
using IDLStringStringContextTrustedHTMLOrNull =
IDLStringStringContextTrustedHTMLBase<
V8StringResourceMode::kTreatNullAndUndefinedAsNullString>;
using IDLStringStringContextTrustedScriptOrNull =
IDLStringStringContextTrustedScriptBase<
V8StringResourceMode::kTreatNullAndUndefinedAsNullString>;
using IDLUSVStringStringContextTrustedScriptURLOrNull =
IDLUSVStringStringContextTrustedScriptURLBase<
V8StringResourceMode::kTreatNullAndUndefinedAsNullString>;
using IDLStringStringContextTrustedHTMLTreatNullAsEmptyString =
IDLStringStringContextTrustedHTMLBase<
V8StringResourceMode::kTreatNullAsEmptyString>;
using IDLStringStringContextTrustedScriptTreatNullAsEmptyString =
IDLStringStringContextTrustedScriptBase<
V8StringResourceMode::kTreatNullAsEmptyString>;
using IDLUSVStringStringContextTrustedScriptURLTreatNullAsEmptyString =
IDLUSVStringStringContextTrustedScriptURLBase<
V8StringResourceMode::kTreatNullAsEmptyString>;
// Strings for the new bindings generator // Strings for the new bindings generator
namespace bindings { namespace bindings {
......
...@@ -11,7 +11,11 @@ ...@@ -11,7 +11,11 @@
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_trusted_html.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_trusted_script.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_trusted_script_url.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/trustedtypes/trusted_types_util.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_data_view.h" #include "third_party/blink/renderer/core/typed_arrays/dom_data_view.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h" #include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.h" #include "third_party/blink/renderer/platform/bindings/exception_messages.h"
...@@ -193,6 +197,72 @@ struct NativeValueTraits<IDLStringBase<mode>> ...@@ -193,6 +197,72 @@ struct NativeValueTraits<IDLStringBase<mode>>
} }
}; };
template <V8StringResourceMode mode>
struct NativeValueTraits<IDLStringStringContextTrustedHTMLBase<mode>>
: public NativeValueTraitsBase<
IDLStringStringContextTrustedHTMLBase<mode>> {
static String NativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value,
ExceptionState& exception_state,
ExecutionContext* execution_context) {
if (V8TrustedHTML::HasInstance(value, isolate)) {
TrustedHTML* trusted_value =
V8TrustedHTML::ToImpl(v8::Local<v8::Object>::Cast(value));
return trusted_value->toString();
} else {
V8StringResource<mode> string(value);
if (!string.Prepare(isolate, exception_state))
return String();
return GetStringFromTrustedHTML(string, execution_context,
exception_state);
}
}
};
template <V8StringResourceMode mode>
struct NativeValueTraits<IDLStringStringContextTrustedScriptBase<mode>>
: public NativeValueTraitsBase<
IDLStringStringContextTrustedScriptBase<mode>> {
static String NativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value,
ExceptionState& exception_state,
ExecutionContext* execution_context) {
if (V8TrustedScript::HasInstance(value, isolate)) {
TrustedScript* trusted_value =
V8TrustedScript::ToImpl(v8::Local<v8::Object>::Cast(value));
return trusted_value->toString();
} else {
V8StringResource<mode> string(value);
if (!string.Prepare(isolate, exception_state))
return String();
return GetStringFromTrustedScript(string, execution_context,
exception_state);
}
}
};
template <V8StringResourceMode mode>
struct NativeValueTraits<IDLUSVStringStringContextTrustedScriptURLBase<mode>>
: public NativeValueTraitsBase<
IDLUSVStringStringContextTrustedScriptURLBase<mode>> {
static String NativeValue(v8::Isolate* isolate,
v8::Local<v8::Value> value,
ExceptionState& exception_state,
ExecutionContext* execution_context) {
if (V8TrustedScriptURL::HasInstance(value, isolate)) {
TrustedScriptURL* trusted_value =
V8TrustedScriptURL::ToImpl(v8::Local<v8::Object>::Cast(value));
return trusted_value->toString();
} else {
V8StringResource<mode> string(value);
if (!string.Prepare(isolate, exception_state))
return String();
return GetStringFromTrustedScriptURL(string, execution_context,
exception_state);
}
}
};
template <V8StringResourceMode mode> template <V8StringResourceMode mode>
struct NativeValueTraits<IDLUSVStringBase<mode>> struct NativeValueTraits<IDLUSVStringBase<mode>>
: public NativeValueTraitsBase<IDLUSVStringBase<mode>> { : public NativeValueTraitsBase<IDLUSVStringBase<mode>> {
......
...@@ -356,6 +356,33 @@ VectorOf<typename NativeValueTraits<IDLType>::ImplType> ToImplArguments( ...@@ -356,6 +356,33 @@ VectorOf<typename NativeValueTraits<IDLType>::ImplType> ToImplArguments(
return result; return result;
} }
template <typename IDLType>
VectorOf<typename NativeValueTraits<IDLType>::ImplType> ToImplArguments(
const v8::FunctionCallbackInfo<v8::Value>& info,
int start_index,
ExceptionState& exception_state,
ExecutionContext* execution_context) {
using TraitsType = NativeValueTraits<IDLType>;
using VectorType = VectorOf<typename TraitsType::ImplType>;
int length = info.Length();
VectorType result;
if (start_index < length) {
if (static_cast<size_t>(length - start_index) > VectorType::MaxCapacity()) {
exception_state.ThrowRangeError("Array length exceeds supported limit.");
return VectorType();
}
result.ReserveInitialCapacity(length - start_index);
for (int i = start_index; i < length; ++i) {
result.UncheckedAppend(TraitsType::NativeValue(
info.GetIsolate(), info[i], exception_state, execution_context));
if (exception_state.HadException())
return VectorType();
}
}
return result;
}
// The functions below implement low-level abstract ES operations for dealing // The functions below implement low-level abstract ES operations for dealing
// with iterators. Most code should use ScriptIterator instead. // with iterators. Most code should use ScriptIterator instead.
// //
......
...@@ -87,6 +87,7 @@ EXTENDED_ATTRIBUTES_APPLICABLE_TO_TYPES = frozenset([ ...@@ -87,6 +87,7 @@ EXTENDED_ATTRIBUTES_APPLICABLE_TO_TYPES = frozenset([
'AllowShared', 'AllowShared',
'Clamp', 'Clamp',
'EnforceRange', 'EnforceRange',
'StringContext',
'TreatNullAs', 'TreatNullAs',
]) ])
...@@ -608,7 +609,8 @@ class IdlNullableType(IdlTypeBase): ...@@ -608,7 +609,8 @@ class IdlNullableType(IdlTypeBase):
class IdlAnnotatedType(IdlTypeBase): class IdlAnnotatedType(IdlTypeBase):
"""IdlAnnoatedType represents an IDL type with extended attributes. """IdlAnnoatedType represents an IDL type with extended attributes.
[Clamp], [EnforceRange], and [TreatNullAs] are applicable to types. [Clamp], [EnforceRange], [StringContext], and [TreatNullAs] are applicable
to types.
https://heycam.github.io/webidl/#idl-annotated-types https://heycam.github.io/webidl/#idl-annotated-types
""" """
...@@ -621,6 +623,9 @@ class IdlAnnotatedType(IdlTypeBase): ...@@ -621,6 +623,9 @@ class IdlAnnotatedType(IdlTypeBase):
for key in extended_attributes): for key in extended_attributes):
raise ValueError('Extended attributes not applicable to types: %s' % self) raise ValueError('Extended attributes not applicable to types: %s' % self)
if 'StringContext' in extended_attributes and inner_type.base_type not in ['DOMString', 'USVString']:
raise ValueError('StringContext is only applicable to string types.')
def __str__(self): def __str__(self):
annotation = ', '.join((key + ('' if val is None else '=' + val)) annotation = ', '.join((key + ('' if val is None else '=' + val))
for key, val in self.extended_attributes.iteritems()) for key, val in self.extended_attributes.iteritems())
...@@ -643,6 +648,10 @@ class IdlAnnotatedType(IdlTypeBase): ...@@ -643,6 +648,10 @@ class IdlAnnotatedType(IdlTypeBase):
def is_annotated_type(self): def is_annotated_type(self):
return True return True
@property
def has_string_context(self):
return 'StringContext' in self.extended_attributes
@property @property
def name(self): def name(self):
annotation = ''.join((key + ('' if val is None else val)) annotation = ''.join((key + ('' if val is None else val))
......
...@@ -124,6 +124,10 @@ def attribute_context(interface, attribute, interfaces, component_info): ...@@ -124,6 +124,10 @@ def attribute_context(interface, attribute, interfaces, component_info):
'SameObject' in attribute.extended_attributes and 'SameObject' in attribute.extended_attributes and
'SaveSameObject' in attribute.extended_attributes) 'SaveSameObject' in attribute.extended_attributes)
# [StringContext]
if idl_type.has_string_context:
includes.add('bindings/core/v8/generated_code_helper.h')
# [CachedAccessor] # [CachedAccessor]
is_cached_accessor = 'CachedAccessor' in extended_attributes is_cached_accessor = 'CachedAccessor' in extended_attributes
......
...@@ -297,6 +297,8 @@ def method_context(interface, method, component_info, is_visible=True): ...@@ -297,6 +297,8 @@ def method_context(interface, method, component_info, is_visible=True):
def argument_context(interface, method, argument, index, is_visible=True): def argument_context(interface, method, argument, index, is_visible=True):
extended_attributes = argument.extended_attributes extended_attributes = argument.extended_attributes
idl_type = argument.idl_type idl_type = argument.idl_type
if idl_type.has_string_context:
includes.add('third_party/blink/renderer/bindings/core/v8/generated_code_helper.h')
if is_visible: if is_visible:
idl_type.add_includes_for_type(extended_attributes) idl_type.add_includes_for_type(extended_attributes)
this_cpp_value = cpp_value(interface, method, index) this_cpp_value = cpp_value(interface, method, index)
...@@ -427,9 +429,12 @@ def v8_value_to_local_cpp_variadic_value(argument, index): ...@@ -427,9 +429,12 @@ def v8_value_to_local_cpp_variadic_value(argument, index):
assert argument.is_variadic assert argument.is_variadic
idl_type = v8_types.native_value_traits_type_name(argument.idl_type, idl_type = v8_types.native_value_traits_type_name(argument.idl_type,
argument.extended_attributes, True) argument.extended_attributes, True)
execution_context_if_needed = ''
if argument.idl_type.has_string_context:
execution_context_if_needed = ', bindings::ExecutionContextFromV8Wrappable(impl)'
assign_expression = 'ToImplArguments<%s>(info, %s, exception_state%s)' % (idl_type, index, execution_context_if_needed)
return { return {
'assign_expression': 'ToImplArguments<%s>(info, %s, exception_state)' % (idl_type, index), 'assign_expression': assign_expression,
'check_expression': 'exception_state.HadException()', 'check_expression': 'exception_state.HadException()',
'cpp_name': NameStyleConverter(argument.name).to_snake_case(), 'cpp_name': NameStyleConverter(argument.name).to_snake_case(),
'declare_variable': False, 'declare_variable': False,
......
...@@ -41,6 +41,7 @@ Design doc: http://www.chromium.org/developers/design-documents/idl-compiler ...@@ -41,6 +41,7 @@ Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
import posixpath import posixpath
from idl_types import IdlAnnotatedType
from idl_types import IdlArrayOrSequenceType from idl_types import IdlArrayOrSequenceType
from idl_types import IdlNullableType from idl_types import IdlNullableType
from idl_types import IdlRecordType from idl_types import IdlRecordType
...@@ -155,7 +156,8 @@ def string_resource_mode(idl_type): ...@@ -155,7 +156,8 @@ def string_resource_mode(idl_type):
treat_null_as = idl_type.extended_attributes.get('TreatNullAs') treat_null_as = idl_type.extended_attributes.get('TreatNullAs')
if treat_null_as == 'EmptyString': if treat_null_as == 'EmptyString':
return 'kTreatNullAsEmptyString' return 'kTreatNullAsEmptyString'
raise ValueError('Unknown value for [TreatNullAs]: %s' % treat_null_as) elif treat_null_as:
raise ValueError('Unknown value for [TreatNullAs]: %s' % treat_null_as)
return '' return ''
...@@ -238,6 +240,8 @@ def cpp_type(idl_type, extended_attributes=None, raw_type=False, used_as_rvalue_ ...@@ -238,6 +240,8 @@ def cpp_type(idl_type, extended_attributes=None, raw_type=False, used_as_rvalue_
if base_idl_type == 'SerializedScriptValue': if base_idl_type == 'SerializedScriptValue':
return 'scoped_refptr<%s>' % base_idl_type return 'scoped_refptr<%s>' % base_idl_type
if idl_type.is_string_type: if idl_type.is_string_type:
if idl_type.has_string_context:
return 'String'
if not raw_type: if not raw_type:
return 'const String&' if used_as_rvalue_type else 'String' return 'const String&' if used_as_rvalue_type else 'String'
return 'V8StringResource<%s>' % string_resource_mode(idl_type) return 'V8StringResource<%s>' % string_resource_mode(idl_type)
...@@ -588,10 +592,12 @@ V8_VALUE_TO_CPP_VALUE = { ...@@ -588,10 +592,12 @@ V8_VALUE_TO_CPP_VALUE = {
def v8_conversion_needs_exception_state(idl_type): def v8_conversion_needs_exception_state(idl_type):
return (idl_type.is_numeric_type or idl_type.is_enum or idl_type.is_dictionary or idl_type.is_array_buffer_view_or_typed_array return (idl_type.is_numeric_type or idl_type.is_enum or idl_type.is_dictionary or idl_type.is_array_buffer_view_or_typed_array
or idl_type.has_string_context
or idl_type.name in ('Boolean', 'ByteString', 'Dictionary', 'Object', 'USVString', 'SerializedScriptValue')) or idl_type.name in ('Boolean', 'ByteString', 'Dictionary', 'Object', 'USVString', 'SerializedScriptValue'))
IdlType.v8_conversion_needs_exception_state = property(v8_conversion_needs_exception_state) IdlType.v8_conversion_needs_exception_state = property(v8_conversion_needs_exception_state)
IdlAnnotatedType.v8_conversion_needs_exception_state = property(v8_conversion_needs_exception_state)
IdlArrayOrSequenceType.v8_conversion_needs_exception_state = True IdlArrayOrSequenceType.v8_conversion_needs_exception_state = True
IdlRecordType.v8_conversion_needs_exception_state = True IdlRecordType.v8_conversion_needs_exception_state = True
IdlUnionType.v8_conversion_needs_exception_state = True IdlUnionType.v8_conversion_needs_exception_state = True
...@@ -680,7 +686,10 @@ def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name ...@@ -680,7 +686,10 @@ def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name
else: else:
arguments = v8_value arguments = v8_value
if base_idl_type in V8_VALUE_TO_CPP_VALUE: if idl_type.has_string_context:
cpp_expression_format = 'NativeValueTraits<IDL%s>::NativeValue(%s, %s, exception_state, bindings::ExecutionContextFromV8Wrappable(impl))' % (
idl_type.name, isolate, v8_value)
elif base_idl_type in V8_VALUE_TO_CPP_VALUE:
cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type]
elif idl_type.name == 'ArrayBuffer': elif idl_type.name == 'ArrayBuffer':
cpp_expression_format = ( cpp_expression_format = (
...@@ -692,7 +701,6 @@ def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name ...@@ -692,7 +701,6 @@ def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, variable_name
cpp_expression_format = ('ToMaybeShared<%s>({isolate}, {v8_value}, exception_state)' % this_cpp_type) cpp_expression_format = ('ToMaybeShared<%s>({isolate}, {v8_value}, exception_state)' % this_cpp_type)
else: else:
cpp_expression_format = ('ToNotShared<%s>({isolate}, {v8_value}, exception_state)' % this_cpp_type) cpp_expression_format = ('ToNotShared<%s>({isolate}, {v8_value}, exception_state)' % this_cpp_type)
elif idl_type.is_union_type: elif idl_type.is_union_type:
nullable = 'UnionTypeConversionMode::kNullable' if idl_type.includes_nullable_type \ nullable = 'UnionTypeConversionMode::kNullable' if idl_type.includes_nullable_type \
else 'UnionTypeConversionMode::kNotNullable' else 'UnionTypeConversionMode::kNotNullable'
......
...@@ -31,6 +31,10 @@ ...@@ -31,6 +31,10 @@
// Test for interface extended attributes and special operations. // Test for interface extended attributes and special operations.
// Also used as a target by TestObject // Also used as a target by TestObject
typedef [StringContext=TrustedHTML] DOMString TrustedHTMLString;
typedef [StringContext=TrustedScript] DOMString TrustedScriptString;
typedef [StringContext=TrustedScriptURL] USVString TrustedScriptURLString;
[ [
ActiveScriptWrappable, ActiveScriptWrappable,
Custom=LegacyCallAsFunction, Custom=LegacyCallAsFunction,
...@@ -148,6 +152,16 @@ ...@@ -148,6 +152,16 @@
// Arguments that are sequences or records of nullable types. // Arguments that are sequences or records of nullable types.
void methodWithNullableSequences(sequence<double?> numbers, sequence<DOMString?> strings, sequence<Element?> elements, sequence<(double or DOMString)?> unions); void methodWithNullableSequences(sequence<double?> numbers, sequence<DOMString?> strings, sequence<Element?> elements, sequence<(double or DOMString)?> unions);
void methodWithNullableRecords(record<DOMString, double?> numbers, record<DOMString, DOMString?> strings, record<DOMString, Element?> elements, record<DOMString, (double or DOMString)?> unions); void methodWithNullableRecords(record<DOMString, double?> numbers, record<DOMString, DOMString?> strings, record<DOMString, Element?> elements, record<DOMString, (double or DOMString)?> unions);
// Trusted Types
[RaisesException=Setter] attribute TrustedScriptString scriptString;
[CallWith=ScriptState, RaisesException] long setTimeoutForScript(TrustedScriptString handler);
[RaisesException=Setter] attribute TrustedHTMLString htmlString;
[CallWith=ScriptState, RaisesException] long setTimeoutForHTML(TrustedHTMLString handler);
[RaisesException=Setter] attribute TrustedScriptURLString scriptURLString;
[CallWith=ScriptState, RaisesException] long setTimeoutForScriptURL(TrustedScriptURLString handler);
[RaisesException=Setter] attribute TrustedScriptString? optionalScriptString;
[RaisesException=Setter] attribute [StringContext=TrustedHTML, TreatNullAs=EmptyString] DOMString treatNullAsEmptyStringHTMLString;
}; };
TestInterface includes TestInterfaceMixin; TestInterface includes TestInterfaceMixin;
......
...@@ -139,6 +139,16 @@ class V8TestInterface { ...@@ -139,6 +139,16 @@ class V8TestInterface {
CORE_EXPORT static void SecureContextWindowExposedRuntimeEnabledAttributeAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void SecureContextWindowExposedRuntimeEnabledAttributeAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void SecureContextWorkerExposedRuntimeEnabledAttributeAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void SecureContextWorkerExposedRuntimeEnabledAttributeAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void SecureContextWorkerExposedRuntimeEnabledAttributeAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void SecureContextWorkerExposedRuntimeEnabledAttributeAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void ScriptStringAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void ScriptStringAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void HTMLStringAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void HTMLStringAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void ScriptURLStringAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void ScriptURLStringAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void OptionalScriptStringAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void OptionalScriptStringAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void TreatNullAsEmptyStringHTMLStringAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void TreatNullAsEmptyStringHTMLStringAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void MixinReadonlyStringAttributeAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void MixinReadonlyStringAttributeAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void MixinStringAttributeAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void MixinStringAttributeAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void MixinStringAttributeAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void MixinStringAttributeAttributeSetterCallback(const v8::FunctionCallbackInfo<v8::Value>&);
...@@ -219,6 +229,9 @@ class V8TestInterface { ...@@ -219,6 +229,9 @@ class V8TestInterface {
CORE_EXPORT static void SecureContextWorkerExposedRuntimeEnabledMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void SecureContextWorkerExposedRuntimeEnabledMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void MethodWithNullableSequencesMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void MethodWithNullableSequencesMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void MethodWithNullableRecordsMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void MethodWithNullableRecordsMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void SetTimeoutForScriptMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void SetTimeoutForHTMLMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void SetTimeoutForScriptURLMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void MixinVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void MixinVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void MixinComplexMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void MixinComplexMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&);
CORE_EXPORT static void MixinCustomVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&); CORE_EXPORT static void MixinCustomVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>&);
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "third_party/blink/renderer/bindings/core/v8/string_or_trusted_script_url.h" #include "third_party/blink/renderer/bindings/core/v8/string_or_trusted_script_url.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/window_proxy_manager.h" #include "third_party/blink/renderer/bindings/core/v8/window_proxy_manager.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h" #include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/trustedtypes/trusted_html.h" #include "third_party/blink/renderer/core/trustedtypes/trusted_html.h"
......
...@@ -64,4 +64,8 @@ void DOMParser::Trace(Visitor* visitor) { ...@@ -64,4 +64,8 @@ void DOMParser::Trace(Visitor* visitor) {
ScriptWrappable::Trace(visitor); ScriptWrappable::Trace(visitor);
} }
Document* DOMParser::GetDocument() const {
return context_document_.Get();
}
} // namespace blink } // namespace blink
...@@ -47,6 +47,8 @@ class DOMParser final : public ScriptWrappable { ...@@ -47,6 +47,8 @@ class DOMParser final : public ScriptWrappable {
void Trace(Visitor*) override; void Trace(Visitor*) override;
Document* GetDocument() const;
private: private:
Document* parseFromStringInternal(const String&, const String& type); Document* parseFromStringInternal(const String&, const String& type);
......
...@@ -62,7 +62,7 @@ ERROR_REMAP = { ...@@ -62,7 +62,7 @@ ERROR_REMAP = {
} }
_EXTENDED_ATTRIBUTES_APPLICABLE_TO_TYPES = [ _EXTENDED_ATTRIBUTES_APPLICABLE_TO_TYPES = [
'Clamp', 'EnforceRange', 'TreatNullAs'] 'Clamp', 'EnforceRange', 'StringContext', 'TreatNullAs']
def Boolean(val): def Boolean(val):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment