diff --git a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp new file mode 100644 index 00000000000..b608ea133de --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include +#include + +namespace Web::Bindings { + +// 7.2.3.1 CrossOriginProperties ( O ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginproperties-(-o-) +Vector cross_origin_properties(Variant const& object) +{ + // 1. Assert: O is a Location or Window object. + + return object.visit( + // 2. If O is a Location object, then return « { [[Property]]: "href", [[NeedsGet]]: false, [[NeedsSet]]: true }, { [[Property]]: "replace" } ». + [](LocationObject const*) -> Vector { + return { + { .property = "href"sv, .needs_get = false, .needs_set = true }, + { .property = "replace"sv }, + }; + }, + // 3. Return « { [[Property]]: "window", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "self", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "location", [[NeedsGet]]: true, [[NeedsSet]]: true }, { [[Property]]: "close" }, { [[Property]]: "closed", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "focus" }, { [[Property]]: "blur" }, { [[Property]]: "frames", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "length", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "top", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "opener", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "parent", [[NeedsGet]]: true, [[NeedsSet]]: false }, { [[Property]]: "postMessage" } ». + [](WindowObject const*) -> Vector { + return { + { .property = "window"sv, .needs_get = true, .needs_set = false }, + { .property = "self"sv, .needs_get = true, .needs_set = false }, + { .property = "location"sv, .needs_get = true, .needs_set = true }, + { .property = "close"sv }, + { .property = "closed"sv, .needs_get = true, .needs_set = false }, + { .property = "focus"sv }, + { .property = "blur"sv }, + { .property = "frames"sv, .needs_get = true, .needs_set = false }, + { .property = "length"sv, .needs_get = true, .needs_set = false }, + { .property = "top"sv, .needs_get = true, .needs_set = false }, + { .property = "opener"sv, .needs_get = true, .needs_set = false }, + { .property = "parent"sv, .needs_get = true, .needs_set = false }, + { .property = "postMessage"sv }, + }; + }); +} + +} diff --git a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h index 945296ae9bc..ba2c1c9cc67 100644 --- a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h +++ b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h @@ -9,9 +9,16 @@ #include #include #include +#include namespace Web::Bindings { +struct CrossOriginProperty { + String property; + Optional needs_get {}; + Optional needs_set {}; +}; + struct CrossOriginKey { FlatPtr current_settings_object; FlatPtr relevant_settings_object; @@ -20,6 +27,8 @@ struct CrossOriginKey { using CrossOriginPropertyDescriptorMap = HashMap; +Vector cross_origin_properties(Variant const&); + } namespace AK { diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index c14edb84cb9..c106bf150da 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -1,5 +1,6 @@ set(SOURCES Bindings/AudioConstructor.cpp + Bindings/CrossOriginAbstractOperations.cpp Bindings/CSSNamespace.cpp Bindings/CSSRuleWrapperFactory.cpp Bindings/CSSStyleDeclarationWrapperCustom.cpp