Location.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibJS/Forward.h>
  9. #include <LibJS/Runtime/Completion.h>
  10. #include <LibURL/URL.h>
  11. #include <LibWeb/Bindings/PlatformObject.h>
  12. #include <LibWeb/Forward.h>
  13. #include <LibWeb/HTML/CrossOrigin/CrossOriginPropertyDescriptorMap.h>
  14. #include <LibWeb/HTML/Navigable.h>
  15. namespace Web::HTML {
  16. class Location final : public Bindings::PlatformObject {
  17. JS_OBJECT(Location, Bindings::PlatformObject);
  18. JS_DECLARE_ALLOCATOR(Location);
  19. public:
  20. virtual ~Location() override;
  21. WebIDL::ExceptionOr<String> href() const;
  22. WebIDL::ExceptionOr<void> set_href(String const&);
  23. WebIDL::ExceptionOr<String> origin() const;
  24. WebIDL::ExceptionOr<String> protocol() const;
  25. WebIDL::ExceptionOr<void> set_protocol(String const&);
  26. WebIDL::ExceptionOr<String> host() const;
  27. WebIDL::ExceptionOr<void> set_host(String const&);
  28. WebIDL::ExceptionOr<String> hostname() const;
  29. WebIDL::ExceptionOr<void> set_hostname(String const&);
  30. WebIDL::ExceptionOr<String> port() const;
  31. WebIDL::ExceptionOr<void> set_port(String const&);
  32. WebIDL::ExceptionOr<String> pathname() const;
  33. WebIDL::ExceptionOr<void> set_pathname(String const&);
  34. WebIDL::ExceptionOr<String> search() const;
  35. WebIDL::ExceptionOr<void> set_search(String const&);
  36. WebIDL::ExceptionOr<String> hash() const;
  37. WebIDL::ExceptionOr<void> set_hash(String const&);
  38. WebIDL::ExceptionOr<void> replace(String const& url);
  39. void reload() const;
  40. WebIDL::ExceptionOr<void> assign(String const& url);
  41. virtual JS::ThrowCompletionOr<JS::Object*> internal_get_prototype_of() const override;
  42. virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(Object* prototype) override;
  43. virtual JS::ThrowCompletionOr<bool> internal_is_extensible() const override;
  44. virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;
  45. virtual JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> internal_get_own_property(JS::PropertyKey const&) const override;
  46. virtual JS::ThrowCompletionOr<bool> internal_define_own_property(JS::PropertyKey const&, JS::PropertyDescriptor const&) override;
  47. virtual JS::ThrowCompletionOr<JS::Value> internal_get(JS::PropertyKey const&, JS::Value receiver, JS::CacheablePropertyMetadata*) const override;
  48. virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver, JS::CacheablePropertyMetadata*) override;
  49. virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const&) override;
  50. virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override;
  51. HTML::CrossOriginPropertyDescriptorMap const& cross_origin_property_descriptor_map() const { return m_cross_origin_property_descriptor_map; }
  52. HTML::CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; }
  53. private:
  54. explicit Location(JS::Realm&);
  55. virtual void initialize(JS::Realm&) override;
  56. virtual void visit_edges(Cell::Visitor&) override;
  57. JS::GCPtr<DOM::Document> relevant_document() const;
  58. URL::URL url() const;
  59. WebIDL::ExceptionOr<void> navigate(URL::URL, Bindings::NavigationHistoryBehavior = Bindings::NavigationHistoryBehavior::Auto);
  60. // [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap
  61. HTML::CrossOriginPropertyDescriptorMap m_cross_origin_property_descriptor_map;
  62. // [[DefaultProperties]], https://html.spec.whatwg.org/multipage/history.html#defaultproperties
  63. Vector<JS::Value> m_default_properties;
  64. };
  65. }