History.h 1.6 KB

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