CrossOriginAbstractOperations.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <AK/Traits.h>
  9. #include <LibJS/Forward.h>
  10. #include <LibJS/Runtime/PropertyKey.h>
  11. #include <LibWeb/Forward.h>
  12. namespace Web::Bindings {
  13. struct CrossOriginProperty {
  14. String property;
  15. Optional<bool> needs_get {};
  16. Optional<bool> needs_set {};
  17. };
  18. struct CrossOriginKey {
  19. FlatPtr current_settings_object;
  20. FlatPtr relevant_settings_object;
  21. JS::PropertyKey property_key;
  22. };
  23. using CrossOriginPropertyDescriptorMap = HashMap<CrossOriginKey, JS::PropertyDescriptor>;
  24. Vector<CrossOriginProperty> cross_origin_properties(Variant<LocationObject const*, HTML::Window const*> const&);
  25. bool is_cross_origin_accessible_window_property_name(JS::PropertyKey const&);
  26. JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS::VM&, JS::PropertyKey const&);
  27. bool is_platform_object_same_origin(JS::Object const&);
  28. Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<LocationObject*, HTML::Window*> const&, JS::PropertyKey const&);
  29. JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::VM&, JS::Object const&, JS::PropertyKey const&, JS::Value receiver);
  30. JS::ThrowCompletionOr<bool> cross_origin_set(JS::VM&, JS::Object&, JS::PropertyKey const&, JS::Value, JS::Value receiver);
  31. JS::MarkedVector<JS::Value> cross_origin_own_property_keys(Variant<LocationObject const*, HTML::Window const*> const&);
  32. }
  33. namespace AK {
  34. template<>
  35. struct Traits<Web::Bindings::CrossOriginKey> : public GenericTraits<Web::Bindings::CrossOriginKey> {
  36. static unsigned hash(Web::Bindings::CrossOriginKey const& key)
  37. {
  38. return pair_int_hash(
  39. Traits<JS::PropertyKey>::hash(key.property_key),
  40. pair_int_hash(ptr_hash(key.current_settings_object), ptr_hash(key.relevant_settings_object)));
  41. }
  42. static bool equals(Web::Bindings::CrossOriginKey const& a, Web::Bindings::CrossOriginKey const& b)
  43. {
  44. return a.current_settings_object == b.current_settings_object
  45. && a.relevant_settings_object == b.relevant_settings_object
  46. && Traits<JS::PropertyKey>::equals(a.property_key, b.property_key);
  47. }
  48. };
  49. }