mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 12:20:00 +01:00
LibWeb: Implement TrustedScriptURL class
This commit is contained in:
parent
40691bf25d
commit
adaad653ca
|
|
@ -899,6 +899,7 @@ set(SOURCES
|
|||
SVG/ViewBox.cpp
|
||||
TrustedTypes/TrustedHTML.cpp
|
||||
TrustedTypes/TrustedScript.cpp
|
||||
TrustedTypes/TrustedScriptURL.cpp
|
||||
TrustedTypes/TrustedTypePolicy.cpp
|
||||
TrustedTypes/TrustedTypePolicyFactory.cpp
|
||||
UIEvents/CompositionEvent.cpp
|
||||
|
|
|
|||
|
|
@ -1222,6 +1222,7 @@ namespace Web::TrustedTypes {
|
|||
|
||||
class TrustedHTML;
|
||||
class TrustedScript;
|
||||
class TrustedScriptURL;
|
||||
class TrustedTypePolicy;
|
||||
class TrustedTypePolicyFactory;
|
||||
struct TrustedTypePolicyOptions;
|
||||
|
|
|
|||
43
Libraries/LibWeb/TrustedTypes/TrustedScriptURL.cpp
Normal file
43
Libraries/LibWeb/TrustedTypes/TrustedScriptURL.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Miguel Sacristán Izcue <miguel_tete17@hotmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/TrustedTypes/TrustedScriptURL.h>
|
||||
|
||||
#include <LibGC/Ptr.h>
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
|
||||
namespace Web::TrustedTypes {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(TrustedScriptURL);
|
||||
|
||||
TrustedScriptURL::TrustedScriptURL(JS::Realm& realm, Utf16String data)
|
||||
: PlatformObject(realm)
|
||||
, m_data(move(data))
|
||||
{
|
||||
}
|
||||
|
||||
void TrustedScriptURL::initialize(JS::Realm& realm)
|
||||
{
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(TrustedScriptURL);
|
||||
Base::initialize(realm);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/trusted-types/dist/spec/#trustedscripturl-stringification-behavior
|
||||
Utf16String const& TrustedScriptURL::to_string() const
|
||||
{
|
||||
// 1. return the associated data value.
|
||||
return m_data;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedscripturl-tojson
|
||||
Utf16String const& TrustedScriptURL::to_json() const
|
||||
{
|
||||
// 1. return the associated data value.
|
||||
return to_string();
|
||||
}
|
||||
|
||||
}
|
||||
32
Libraries/LibWeb/TrustedTypes/TrustedScriptURL.h
Normal file
32
Libraries/LibWeb/TrustedTypes/TrustedScriptURL.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Miguel Sacristán Izcue <miguel_tete17@hotmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/Bindings/TrustedScriptURLPrototype.h>
|
||||
|
||||
namespace Web::TrustedTypes {
|
||||
|
||||
class TrustedScriptURL final : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(TrustedScriptURL, Bindings::PlatformObject);
|
||||
GC_DECLARE_ALLOCATOR(TrustedScriptURL);
|
||||
|
||||
public:
|
||||
virtual ~TrustedScriptURL() override = default;
|
||||
|
||||
Utf16String const& to_string() const;
|
||||
Utf16String const& to_json() const;
|
||||
|
||||
private:
|
||||
explicit TrustedScriptURL(JS::Realm&, Utf16String);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
Utf16String const m_data;
|
||||
};
|
||||
|
||||
}
|
||||
6
Libraries/LibWeb/TrustedTypes/TrustedScriptURL.idl
Normal file
6
Libraries/LibWeb/TrustedTypes/TrustedScriptURL.idl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// https://w3c.github.io/trusted-types/dist/spec/#trused-script-url
|
||||
[Exposed=(Window,Worker)]
|
||||
interface TrustedScriptURL {
|
||||
stringifier;
|
||||
Utf16DOMString toJSON();
|
||||
};
|
||||
|
|
@ -330,6 +330,7 @@ libweb_js_bindings(Streams/WritableStreamDefaultController)
|
|||
libweb_js_bindings(Streams/WritableStreamDefaultWriter)
|
||||
libweb_js_bindings(TrustedTypes/TrustedHTML)
|
||||
libweb_js_bindings(TrustedTypes/TrustedScript)
|
||||
libweb_js_bindings(TrustedTypes/TrustedScriptURL)
|
||||
libweb_js_bindings(TrustedTypes/TrustedTypePolicy)
|
||||
libweb_js_bindings(TrustedTypes/TrustedTypePolicyFactory)
|
||||
libweb_js_bindings(SVG/SVGAElement)
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ static bool is_platform_object(Type const& type)
|
|||
"TimeRanges"sv,
|
||||
"TrustedHTML"sv,
|
||||
"TrustedScript"sv,
|
||||
"TrustedScriptURL"sv,
|
||||
"TrustedTypePolicy"sv,
|
||||
"TrustedTypePolicyFactory"sv,
|
||||
"URLSearchParams"sv,
|
||||
|
|
|
|||
|
|
@ -434,6 +434,7 @@ TransitionEvent
|
|||
TreeWalker
|
||||
TrustedHTML
|
||||
TrustedScript
|
||||
TrustedScriptURL
|
||||
TrustedTypePolicy
|
||||
TrustedTypePolicyFactory
|
||||
TypeError
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user