Quellcode durchsuchen

LibWeb: Process session history queue after initial iframe navigation

This is not in the spec, but we need to make sure that "apply the
history step" for initial navigation to about:blank in iframe is
applied before subsequent navigations. Otherwise, "set ongoing
navigation" call during "about:blank" traversal might abort subsequent
ongoing navigation which is not expected to happen.
Aliaksandr Kalenik vor 1 Jahr
Ursprung
Commit
9b16e5373d

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

@@ -934,6 +934,8 @@ WebIDL::ExceptionOr<void> Navigable::navigate(
         // 1. Navigate to a fragment given navigable, url, historyHandling, and navigationId.
         TRY(navigate_to_a_fragment(url, to_history_handling_behavior(history_handling), navigation_id));
 
+        traversable_navigable()->process_session_history_traversal_queue();
+
         // 2. Return.
         return {};
     }

+ 3 - 0
Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp

@@ -208,6 +208,9 @@ Optional<AK::URL> NavigableContainer::shared_attribute_processing_steps_for_ifra
     // 4. If url matches about:blank and initialInsertion is true, then perform the URL and history update steps given element's content navigable's active document and url.
     if (url_matches_about_blank(url) && initial_insertion) {
         perform_url_and_history_update_steps(*m_content_navigable->active_document(), url);
+        // NOTE: Not in the spec but we need to make sure that "apply the history step" for initial navigation to about:blank
+        //       is applied before subsequent navigation.
+        navigable()->traversable_navigable()->process_session_history_traversal_queue();
     }
 
     // 5. Return url.

+ 8 - 0
Userland/Libraries/LibWeb/HTML/SessionHistoryTraversalQueue.h

@@ -31,6 +31,14 @@ public:
         }
     }
 
+    void process()
+    {
+        while (m_queue.size() > 0) {
+            auto steps = m_queue.take_first();
+            steps();
+        }
+    }
+
 private:
     Vector<JS::SafeFunction<void()>> m_queue;
     RefPtr<Core::Timer> m_timer;

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

@@ -55,6 +55,11 @@ public:
         m_session_history_traversal_queue.append(move(steps));
     }
 
+    void process_session_history_traversal_queue()
+    {
+        m_session_history_traversal_queue.process();
+    }
+
     Page* page() { return m_page; }
     Page const* page() const { return m_page; }