Browse Source

LibWeb: Implement reload for navigables

Aliaksandr Kalenik 2 years ago
parent
commit
ffd5b3da16

+ 15 - 0
Userland/Libraries/LibWeb/HTML/Navigable.cpp

@@ -951,4 +951,19 @@ WebIDL::ExceptionOr<void> Navigable::navigate_to_a_javascript_url(AK::URL const&
     TODO();
 }
 
+// https://html.spec.whatwg.org/multipage/browsing-the-web.html#reload
+void Navigable::reload()
+{
+    // 1. Set navigable's active session history entry's document state's reload pending to true.
+    active_session_history_entry()->document_state->set_reload_pending(true);
+
+    // 2. Let traversable be navigable's traversable navigable.
+    auto traversable = traversable_navigable();
+
+    // FIXME: 3. Append the following session history traversal steps to traversable:
+
+    // 1. Apply pending history changes to traversable with true.
+    traversable->apply_pending_history_changes();
+}
+
 }

+ 2 - 0
Userland/Libraries/LibWeb/HTML/Navigable.h

@@ -87,6 +87,8 @@ public:
 
     WebIDL::ExceptionOr<void> navigate_to_a_javascript_url(AK::URL const&, HistoryHandlingBehavior, Origin const& initiator_origin, CSPNavigationType csp_navigation_type);
 
+    void reload();
+
 protected:
     Navigable();
 

+ 10 - 0
Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp

@@ -498,4 +498,14 @@ void TraversableNavigable::traverse_the_history_by_delta(int delta)
     apply_the_history_step(all_steps[target_step_index]);
 }
 
+// https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-pending-history-changes
+void TraversableNavigable::apply_pending_history_changes()
+{
+    // 1. Let targetStep be traversable's current session history step.
+    auto target_step = current_session_history_step();
+
+    // 2. Apply the history step targetStep to traversable with checkForUserCancelation set to checkForUserCancelation.
+    apply_the_history_step(target_step);
+}
+
 }

+ 1 - 0
Userland/Libraries/LibWeb/HTML/TraversableNavigable.h

@@ -37,6 +37,7 @@ public:
     HistoryObjectLengthAndIndex get_the_history_object_length_and_index(int) const;
 
     void apply_the_history_step(int step, Optional<SourceSnapshotParams> = {});
+    void apply_pending_history_changes();
 
     int get_the_used_step(int step) const;
     Vector<JS::Handle<Navigable>> get_all_navigables_whose_current_session_history_entry_will_change_or_reload(int) const;