mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-27 04:37:22 +00:00
LibWeb: Implement methods dependant on TrustedScriptURL
This commit is contained in:
parent
adaad653ca
commit
bc9e67a0dc
Notes:
github-actions[bot]
2025-08-11 11:22:53 +00:00
Author: https://github.com/tete17
Commit: bc9e67a0dc
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5668
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/Lubrsi ✅
Reviewed-by: https://github.com/tcl3
6 changed files with 34 additions and 3 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
#include <LibWeb/TrustedTypes/TrustedHTML.h>
|
#include <LibWeb/TrustedTypes/TrustedHTML.h>
|
||||||
#include <LibWeb/TrustedTypes/TrustedScript.h>
|
#include <LibWeb/TrustedTypes/TrustedScript.h>
|
||||||
|
#include <LibWeb/TrustedTypes/TrustedScriptURL.h>
|
||||||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||||
#include <LibWeb/WebIDL/CallbackType.h>
|
#include <LibWeb/WebIDL/CallbackType.h>
|
||||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||||
|
@ -64,6 +65,22 @@ WebIDL::ExceptionOr<GC::Root<TrustedScript>> TrustedTypePolicy::create_script(St
|
||||||
return trusted_type.get<GC::Root<TrustedScript>>();
|
return trusted_type.get<GC::Root<TrustedScript>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedtypepolicy-createscripturl
|
||||||
|
WebIDL::ExceptionOr<GC::Root<TrustedScriptURL>> TrustedTypePolicy::create_script_url(String const& input, GC::RootVector<JS::Value> const& arguments)
|
||||||
|
{
|
||||||
|
// 1. Returns the result of executing the Create a Trusted Type algorithm, with the following arguments:
|
||||||
|
// policy
|
||||||
|
// this value
|
||||||
|
// trustedTypeName
|
||||||
|
// "TrustedScriptURL"
|
||||||
|
// value
|
||||||
|
// input
|
||||||
|
// arguments
|
||||||
|
// arguments
|
||||||
|
auto const trusted_type = TRY(create_a_trusted_type(TrustedTypeName::TrustedScriptURL, input, arguments));
|
||||||
|
return trusted_type.get<GC::Root<TrustedScriptURL>>();
|
||||||
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/trusted-types/dist/spec/#create-a-trusted-type-algorithm
|
// https://w3c.github.io/trusted-types/dist/spec/#create-a-trusted-type-algorithm
|
||||||
TrustedTypesVariants TrustedTypePolicy::create_a_trusted_type(TrustedTypeName trusted_type_name, String const& value, GC::RootVector<JS::Value> const& arguments)
|
TrustedTypesVariants TrustedTypePolicy::create_a_trusted_type(TrustedTypeName trusted_type_name, String const& value, GC::RootVector<JS::Value> const& arguments)
|
||||||
{
|
{
|
||||||
|
@ -99,6 +116,8 @@ TrustedTypesVariants TrustedTypePolicy::create_a_trusted_type(TrustedTypeName tr
|
||||||
return realm.create<TrustedHTML>(realm, move(data_string));
|
return realm.create<TrustedHTML>(realm, move(data_string));
|
||||||
case TrustedTypeName::TrustedScript:
|
case TrustedTypeName::TrustedScript:
|
||||||
return realm.create<TrustedScript>(realm, move(data_string));
|
return realm.create<TrustedScript>(realm, move(data_string));
|
||||||
|
case TrustedTypeName::TrustedScriptURL:
|
||||||
|
return realm.create<TrustedScriptURL>(realm, move(data_string));
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@ namespace Web::TrustedTypes {
|
||||||
|
|
||||||
using TrustedTypesVariants = WebIDL::ExceptionOr<Variant<
|
using TrustedTypesVariants = WebIDL::ExceptionOr<Variant<
|
||||||
GC::Root<TrustedHTML>,
|
GC::Root<TrustedHTML>,
|
||||||
GC::Root<TrustedScript>>>;
|
GC::Root<TrustedScript>,
|
||||||
|
GC::Root<TrustedScriptURL>>>;
|
||||||
|
|
||||||
enum class TrustedTypeName {
|
enum class TrustedTypeName {
|
||||||
TrustedHTML,
|
TrustedHTML,
|
||||||
|
@ -44,6 +45,7 @@ public:
|
||||||
|
|
||||||
WebIDL::ExceptionOr<GC::Root<TrustedHTML>> create_html(String const&, GC::RootVector<JS::Value> const&);
|
WebIDL::ExceptionOr<GC::Root<TrustedHTML>> create_html(String const&, GC::RootVector<JS::Value> const&);
|
||||||
WebIDL::ExceptionOr<GC::Root<TrustedScript>> create_script(String const&, GC::RootVector<JS::Value> const&);
|
WebIDL::ExceptionOr<GC::Root<TrustedScript>> create_script(String const&, GC::RootVector<JS::Value> const&);
|
||||||
|
WebIDL::ExceptionOr<GC::Root<TrustedScriptURL>> create_script_url(String const&, GC::RootVector<JS::Value> const&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit TrustedTypePolicy(JS::Realm&, String const&, TrustedTypePolicyOptions const&);
|
explicit TrustedTypePolicy(JS::Realm&, String const&, TrustedTypePolicyOptions const&);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#import <TrustedTypes/TrustedHTML.idl>
|
#import <TrustedTypes/TrustedHTML.idl>
|
||||||
#import <TrustedTypes/TrustedScript.idl>
|
#import <TrustedTypes/TrustedScript.idl>
|
||||||
|
#import <TrustedTypes/TrustedScriptURL.idl>
|
||||||
|
|
||||||
// https://w3c.github.io/trusted-types/dist/spec/#trusted-type-policy
|
// https://w3c.github.io/trusted-types/dist/spec/#trusted-type-policy
|
||||||
[Exposed=(Window,Worker)]
|
[Exposed=(Window,Worker)]
|
||||||
|
@ -7,7 +8,7 @@ interface TrustedTypePolicy {
|
||||||
readonly attribute DOMString name;
|
readonly attribute DOMString name;
|
||||||
TrustedHTML createHTML(DOMString input, any... arguments);
|
TrustedHTML createHTML(DOMString input, any... arguments);
|
||||||
TrustedScript createScript(DOMString input, any... arguments);
|
TrustedScript createScript(DOMString input, any... arguments);
|
||||||
[FIXME] TrustedScriptURL createScriptURL(DOMString input, any... arguments);
|
TrustedScriptURL createScriptURL(DOMString input, any... arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://w3c.github.io/trusted-types/dist/spec/#trusted-type-policy-options
|
// https://w3c.github.io/trusted-types/dist/spec/#trusted-type-policy-options
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <LibWeb/SVG/TagNames.h>
|
#include <LibWeb/SVG/TagNames.h>
|
||||||
#include <LibWeb/TrustedTypes/TrustedHTML.h>
|
#include <LibWeb/TrustedTypes/TrustedHTML.h>
|
||||||
#include <LibWeb/TrustedTypes/TrustedScript.h>
|
#include <LibWeb/TrustedTypes/TrustedScript.h>
|
||||||
|
#include <LibWeb/TrustedTypes/TrustedScriptURL.h>
|
||||||
#include <LibWeb/TrustedTypes/TrustedTypePolicy.h>
|
#include <LibWeb/TrustedTypes/TrustedTypePolicy.h>
|
||||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||||
|
|
||||||
|
@ -172,6 +173,13 @@ bool TrustedTypePolicyFactory::is_script(JS::Value value)
|
||||||
return value.is_object() && is<TrustedScript>(value.as_object());
|
return value.is_object() && is<TrustedScript>(value.as_object());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedtypepolicyfactory-isscripturl
|
||||||
|
bool TrustedTypePolicyFactory::is_script_url(JS::Value value)
|
||||||
|
{
|
||||||
|
// 1. Returns true if value is an instance of TrustedScriptURL and has an associated data value set, false otherwise.
|
||||||
|
return value.is_object() && is<TrustedScriptURL>(value.as_object());
|
||||||
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/trusted-types/dist/spec/#create-trusted-type-policy-algorithm
|
// https://w3c.github.io/trusted-types/dist/spec/#create-trusted-type-policy-algorithm
|
||||||
WebIDL::ExceptionOr<GC::Ref<TrustedTypePolicy>> TrustedTypePolicyFactory::create_a_trusted_type_policy(String const& policy_name, TrustedTypePolicyOptions const& options, JS::Object& global)
|
WebIDL::ExceptionOr<GC::Ref<TrustedTypePolicy>> TrustedTypePolicyFactory::create_a_trusted_type_policy(String const& policy_name, TrustedTypePolicyOptions const& options, JS::Object& global)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
|
|
||||||
bool is_html(JS::Value);
|
bool is_html(JS::Value);
|
||||||
bool is_script(JS::Value);
|
bool is_script(JS::Value);
|
||||||
|
bool is_script_url(JS::Value);
|
||||||
|
|
||||||
Optional<String> get_attribute_type(String const& tag_name, String& attribute, Optional<String> element_ns, Optional<String> attr_ns);
|
Optional<String> get_attribute_type(String const& tag_name, String& attribute, Optional<String> element_ns, Optional<String> attr_ns);
|
||||||
Optional<String> get_property_type(String const& tag_name, String const& property, Optional<String> element_ns);
|
Optional<String> get_property_type(String const& tag_name, String const& property, Optional<String> element_ns);
|
||||||
|
|
|
@ -7,7 +7,7 @@ interface TrustedTypePolicyFactory {
|
||||||
DOMString policyName, optional TrustedTypePolicyOptions policyOptions = {});
|
DOMString policyName, optional TrustedTypePolicyOptions policyOptions = {});
|
||||||
boolean isHTML(any value);
|
boolean isHTML(any value);
|
||||||
boolean isScript(any value);
|
boolean isScript(any value);
|
||||||
[FIXME] boolean isScriptURL(any value);
|
boolean isScriptURL(any value);
|
||||||
[FIXME] readonly attribute TrustedHTML emptyHTML;
|
[FIXME] readonly attribute TrustedHTML emptyHTML;
|
||||||
[FIXME] readonly attribute TrustedScript emptyScript;
|
[FIXME] readonly attribute TrustedScript emptyScript;
|
||||||
DOMString? getAttributeType(
|
DOMString? getAttributeType(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue