Ver código fonte

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 ano atrás
pai
commit
7ad2dd2693
1 arquivos alterados com 10 adições e 1 exclusões
  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.
                     // NOTE: This check is not in the spec but we should not continue navigation if navigable has been destroyed.
                     return;
                     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);
                 finalize_a_cross_document_navigation(*this, to_history_handling_behavior(history_handling), history_entry);
             });
             });
         }).release_value_but_fixme_should_propagate_errors();
         }).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();
     auto traversable = traversable_navigable();
 
 
     // 17. Append the following session history synchronous navigation steps involving navigable to traversable:
     // 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.
         // 1. Finalize a same-document navigation given traversable, navigable, historyEntry, and entryToReplace.
         finalize_a_same_document_navigation(*traversable, *this, history_entry, entry_to_replace);
         finalize_a_same_document_navigation(*traversable, *this, history_entry, entry_to_replace);