mirror of
https://github.com/RGBCube/serenity
synced 2025-05-29 07:05:06 +00:00
LibWeb: Add state field to History
This is the "classic history API state" referenced in the current HTML spec.
This commit is contained in:
parent
2c27b4e63c
commit
49e0466a3d
3 changed files with 17 additions and 1 deletions
|
@ -38,6 +38,7 @@ void History::visit_edges(Cell::Visitor& visitor)
|
||||||
{
|
{
|
||||||
Base::visit_edges(visitor);
|
Base::visit_edges(visitor);
|
||||||
visitor.visit(m_associated_document);
|
visitor.visit(m_associated_document);
|
||||||
|
visitor.visit(m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/history.html#dom-history-pushstate
|
// https://html.spec.whatwg.org/multipage/history.html#dom-history-pushstate
|
||||||
|
@ -65,6 +66,17 @@ WebIDL::ExceptionOr<u64> History::length() const
|
||||||
return m_length;
|
return m_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-history-state
|
||||||
|
WebIDL::ExceptionOr<JS::Value> History::state() const
|
||||||
|
{
|
||||||
|
// 1. If this's relevant global object's associated Document is not fully active, then throw a "SecurityError" DOMException.
|
||||||
|
if (!m_associated_document->is_fully_active())
|
||||||
|
return WebIDL::SecurityError::create(realm(), "Cannot perform state on a document that isn't fully active."_fly_string);
|
||||||
|
|
||||||
|
// 2. Return this's state.
|
||||||
|
return m_state;
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/history.html#dom-history-go
|
// https://html.spec.whatwg.org/multipage/history.html#dom-history-go
|
||||||
WebIDL::ExceptionOr<void> History::go(long delta = 0)
|
WebIDL::ExceptionOr<void> History::go(long delta = 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,10 +28,13 @@ public:
|
||||||
WebIDL::ExceptionOr<void> back();
|
WebIDL::ExceptionOr<void> back();
|
||||||
WebIDL::ExceptionOr<void> forward();
|
WebIDL::ExceptionOr<void> forward();
|
||||||
WebIDL::ExceptionOr<u64> length() const;
|
WebIDL::ExceptionOr<u64> length() const;
|
||||||
|
WebIDL::ExceptionOr<JS::Value> state() const;
|
||||||
|
|
||||||
u64 m_index { 0 };
|
u64 m_index { 0 };
|
||||||
u64 m_length { 0 };
|
u64 m_length { 0 };
|
||||||
|
|
||||||
|
void set_state(JS::Value s) { m_state = s; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
History(JS::Realm&, DOM::Document&);
|
History(JS::Realm&, DOM::Document&);
|
||||||
|
|
||||||
|
@ -41,6 +44,7 @@ private:
|
||||||
WebIDL::ExceptionOr<void> shared_history_push_replace_state(JS::Value data, Optional<String> const& url, HistoryHandlingBehavior);
|
WebIDL::ExceptionOr<void> shared_history_push_replace_state(JS::Value data, Optional<String> const& url, HistoryHandlingBehavior);
|
||||||
|
|
||||||
JS::NonnullGCPtr<DOM::Document> m_associated_document;
|
JS::NonnullGCPtr<DOM::Document> m_associated_document;
|
||||||
|
JS::Value m_state { JS::js_null() };
|
||||||
};
|
};
|
||||||
|
|
||||||
bool can_have_its_url_rewritten(DOM::Document const& document, AK::URL const& target_url);
|
bool can_have_its_url_rewritten(DOM::Document const& document, AK::URL const& target_url);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
interface History {
|
interface History {
|
||||||
readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
// FIXME: attribute ScrollRestoration scrollRestoration;
|
// FIXME: attribute ScrollRestoration scrollRestoration;
|
||||||
// FIXME: readonly attribute any state;
|
readonly attribute any state;
|
||||||
undefined go(optional long delta = 0);
|
undefined go(optional long delta = 0);
|
||||||
undefined back();
|
undefined back();
|
||||||
undefined forward();
|
undefined forward();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue