浏览代码

LibWeb: Exit navigation process if navigation id has changed

Change of navigation id means that it has been aborted, and we should
return early.
Aliaksandr Kalenik 1 年之前
父节点
当前提交
7ad2dd2693
共有 1 个文件被更改,包括 10 次插入1 次删除
  1. 10 1
      Userland/Libraries/LibWeb/HTML/Navigable.cpp

+ 10 - 1
Userland/Libraries/LibWeb/HTML/Navigable.cpp

@@ -1052,6 +1052,10 @@ WebIDL::ExceptionOr<void> Navigable::navigate(
                     // NOTE: This check is not in the spec but we should not continue navigation if navigable has been destroyed.
                     return;
                 }
+                if (this->ongoing_navigation() != navigation_id) {
+                    // NOTE: This check is not in the spec but we should not continue navigation if ongoing navigation id has changed.
+                    return;
+                }
                 finalize_a_cross_document_navigation(*this, to_history_handling_behavior(history_handling), history_entry);
             });
         }).release_value_but_fixme_should_propagate_errors();
@@ -1113,7 +1117,12 @@ WebIDL::ExceptionOr<void> Navigable::navigate_to_a_fragment(AK::URL const& url,
     auto traversable = traversable_navigable();
 
     // 17. Append the following session history synchronous navigation steps involving navigable to traversable:
-    traversable->append_session_history_traversal_steps([this, traversable, history_entry, entry_to_replace] {
+    traversable->append_session_history_traversal_steps([this, traversable, history_entry, entry_to_replace, navigation_id] {
+        if (this->ongoing_navigation() != navigation_id) {
+            // NOTE: This check is not in the spec but we should not continue navigation if ongoing navigation id has changed.
+            return;
+        }
+
         // 1. Finalize a same-document navigation given traversable, navigable, historyEntry, and entryToReplace.
         finalize_a_same_document_navigation(*traversable, *this, history_entry, entry_to_replace);