History.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/Document.h>
  7. #include <LibWeb/HTML/History.h>
  8. namespace Web::HTML {
  9. History::History(DOM::Document& document)
  10. : m_associated_document(document)
  11. {
  12. }
  13. History::~History()
  14. {
  15. }
  16. // https://html.spec.whatwg.org/multipage/history.html#dom-history-pushstate
  17. DOM::ExceptionOr<void> History::push_state(JS::Value data, String const&, String const& url)
  18. {
  19. // NOTE: The second parameter of this function is intentionally unused.
  20. return shared_history_push_replace_state(data, url, IsPush::Yes);
  21. }
  22. // https://html.spec.whatwg.org/multipage/history.html#dom-history-replacestate
  23. DOM::ExceptionOr<void> History::replace_state(JS::Value data, String const&, String const& url)
  24. {
  25. // NOTE: The second parameter of this function is intentionally unused.
  26. return shared_history_push_replace_state(data, url, IsPush::No);
  27. }
  28. // https://html.spec.whatwg.org/multipage/history.html#shared-history-push/replace-state-steps
  29. DOM::ExceptionOr<void> History::shared_history_push_replace_state(JS::Value, String const&, IsPush)
  30. {
  31. // 1. Let document be history's associated Document. (NOTE: Not necessary)
  32. // 2. If document is not fully active, then throw a "SecurityError" DOMException.
  33. if (!m_associated_document.is_fully_active())
  34. return DOM::SecurityError::create("Cannot perform pushState or replaceState on a document that isn't fully active.");
  35. // 3. Optionally, return. (For example, the user agent might disallow calls to these methods that are invoked on a timer,
  36. // or from event listeners that are not triggered in response to a clear user action, or that are invoked in rapid succession.)
  37. dbgln("FIXME: Implement shared_history_push_replace_state.");
  38. return {};
  39. // FIXME: Add the rest of the spec steps once they're added.
  40. }
  41. }