Location.h 3.7 KB

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