History.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  3. * Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibWeb/Bindings/HistoryPrototype.h>
  9. #include <LibWeb/Bindings/PlatformObject.h>
  10. #include <LibWeb/HTML/HistoryHandlingBehavior.h>
  11. #include <LibWeb/WebIDL/ExceptionOr.h>
  12. #include <LibWeb/WebIDL/Types.h>
  13. namespace Web::HTML {
  14. class History final : public Bindings::PlatformObject {
  15. WEB_PLATFORM_OBJECT(History, Bindings::PlatformObject);
  16. GC_DECLARE_ALLOCATOR(History);
  17. public:
  18. [[nodiscard]] static GC::Ref<History> create(JS::Realm&, DOM::Document&);
  19. virtual ~History() override;
  20. WebIDL::ExceptionOr<void> push_state(JS::Value data, String const& unused, Optional<String> const& url = {});
  21. WebIDL::ExceptionOr<void> replace_state(JS::Value data, String const& unused, Optional<String> const& url = {});
  22. WebIDL::ExceptionOr<void> go(WebIDL::Long delta);
  23. WebIDL::ExceptionOr<void> back();
  24. WebIDL::ExceptionOr<void> forward();
  25. WebIDL::ExceptionOr<u64> length() const;
  26. WebIDL::ExceptionOr<Bindings::ScrollRestoration> scroll_restoration() const;
  27. WebIDL::ExceptionOr<void> set_scroll_restoration(Bindings::ScrollRestoration);
  28. WebIDL::ExceptionOr<JS::Value> state() const;
  29. u64 m_index { 0 };
  30. u64 m_length { 0 };
  31. JS::Value unsafe_state() const;
  32. void set_state(JS::Value s) { m_state = s; }
  33. private:
  34. History(JS::Realm&, DOM::Document&);
  35. virtual void initialize(JS::Realm&) override;
  36. virtual void visit_edges(Cell::Visitor&) override;
  37. WebIDL::ExceptionOr<void> shared_history_push_replace_state(JS::Value data, Optional<String> const& url, HistoryHandlingBehavior);
  38. GC::Ref<DOM::Document> m_associated_document;
  39. JS::Value m_state { JS::js_null() };
  40. };
  41. bool can_have_its_url_rewritten(DOM::Document const& document, URL::URL const& target_url);
  42. }