History.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include <LibWeb/WebIDL/Types.h>
  12. namespace Web::HTML {
  13. class History final : public Bindings::PlatformObject {
  14. WEB_PLATFORM_OBJECT(History, Bindings::PlatformObject);
  15. JS_DECLARE_ALLOCATOR(History);
  16. public:
  17. [[nodiscard]] static JS::NonnullGCPtr<History> create(JS::Realm&, DOM::Document&);
  18. virtual ~History() override;
  19. WebIDL::ExceptionOr<void> push_state(JS::Value data, String const& unused, Optional<String> const& url = {});
  20. WebIDL::ExceptionOr<void> replace_state(JS::Value data, String const& unused, Optional<String> const& url = {});
  21. WebIDL::ExceptionOr<void> go(WebIDL::Long delta);
  22. WebIDL::ExceptionOr<void> back();
  23. WebIDL::ExceptionOr<void> forward();
  24. WebIDL::ExceptionOr<u64> length() const;
  25. WebIDL::ExceptionOr<JS::Value> state() const;
  26. u64 m_index { 0 };
  27. u64 m_length { 0 };
  28. void set_state(JS::Value s) { m_state = s; }
  29. private:
  30. History(JS::Realm&, DOM::Document&);
  31. virtual void initialize(JS::Realm&) override;
  32. virtual void visit_edges(Cell::Visitor&) override;
  33. WebIDL::ExceptionOr<void> shared_history_push_replace_state(JS::Value data, Optional<String> const& url, HistoryHandlingBehavior);
  34. JS::NonnullGCPtr<DOM::Document> m_associated_document;
  35. JS::Value m_state { JS::js_null() };
  36. };
  37. bool can_have_its_url_rewritten(DOM::Document const& document, URL const& target_url);
  38. }