Browse Source

LibWeb: Bring HistoryHandlingBehavior up to date with the specification

Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
Aliaksandr Kalenik 1 năm trước cách đây
mục cha
commit
39f74d3437

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

@@ -17,7 +17,6 @@
 #include <LibJS/Heap/Cell.h>
 #include <LibWeb/DOM/Position.h>
 #include <LibWeb/HTML/ActivateTab.h>
-#include <LibWeb/HTML/HistoryHandlingBehavior.h>
 #include <LibWeb/HTML/NavigableContainer.h>
 #include <LibWeb/HTML/Origin.h>
 #include <LibWeb/HTML/SandboxingFlagSet.h>

+ 0 - 3
Userland/Libraries/LibWeb/HTML/HistoryHandlingBehavior.h

@@ -10,9 +10,6 @@ namespace Web::HTML {
 
 // https://html.spec.whatwg.org/multipage/browsing-the-web.html#history-handling-behavior
 enum class HistoryHandlingBehavior {
-    Default,     // FIXME: This is no longer part of the spec. Remove.
-    EntryUpdate, // FIXME: This is no longer part of the spec. Remove.
-    Reload,      // FIXME: This is no longer part of the spec. Remove.
     Push,
     Replace,
 };

+ 4 - 16
Userland/Libraries/LibWeb/HTML/Location.cpp

@@ -61,20 +61,8 @@ JS::GCPtr<DOM::Document> Location::relevant_document() const
     return browsing_context ? browsing_context->active_document() : nullptr;
 }
 
-static Bindings::NavigationHistoryBehavior to_navigation_history_behavior(HistoryHandlingBehavior b)
-{
-    switch (b) {
-    case HistoryHandlingBehavior::Push:
-        return Bindings::NavigationHistoryBehavior::Push;
-    case HistoryHandlingBehavior::Replace:
-        return Bindings::NavigationHistoryBehavior::Replace;
-    default:
-        return Bindings::NavigationHistoryBehavior::Auto;
-    }
-}
-
 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#location-object-navigate
-WebIDL::ExceptionOr<void> Location::navigate(URL::URL url, HistoryHandlingBehavior history_handling)
+WebIDL::ExceptionOr<void> Location::navigate(URL::URL url, Bindings::NavigationHistoryBehavior history_handling)
 {
     // 1. Let navigable be location's relevant global object's navigable.
     auto navigable = verify_cast<HTML::Window>(HTML::relevant_global_object(*this)).navigable();
@@ -84,14 +72,14 @@ WebIDL::ExceptionOr<void> Location::navigate(URL::URL url, HistoryHandlingBehavi
 
     // 3. If location's relevant Document is not yet completely loaded, and the incumbent global object does not have transient activation, then set historyHandling to "replace".
     if (!relevant_document()->is_completely_loaded() && !verify_cast<HTML::Window>(incumbent_global_object()).has_transient_activation()) {
-        history_handling = HistoryHandlingBehavior::Replace;
+        history_handling = Bindings::NavigationHistoryBehavior::Replace;
     }
 
     // 4. Navigate navigable to url using sourceDocument, with exceptionsEnabled set to true and historyHandling set to historyHandling.
     TRY(navigable->navigate({ .url = url,
         .source_document = source_document,
         .exceptions_enabled = true,
-        .history_handling = to_navigation_history_behavior(history_handling) }));
+        .history_handling = history_handling }));
 
     return {};
 }
@@ -389,7 +377,7 @@ WebIDL::ExceptionOr<void> Location::replace(String const& url)
         return WebIDL::SyntaxError::create(realm(), MUST(String::formatted("Invalid URL '{}'", url)));
 
     // 3. Location-object navigate this to the resulting URL record given "replace".
-    TRY(navigate(replace_url, HistoryHandlingBehavior::Replace));
+    TRY(navigate(replace_url, Bindings::NavigationHistoryBehavior::Replace));
 
     return {};
 }

+ 2 - 2
Userland/Libraries/LibWeb/HTML/Location.h

@@ -13,7 +13,7 @@
 #include <LibWeb/Bindings/PlatformObject.h>
 #include <LibWeb/Forward.h>
 #include <LibWeb/HTML/CrossOrigin/CrossOriginPropertyDescriptorMap.h>
-#include <LibWeb/HTML/HistoryHandlingBehavior.h>
+#include <LibWeb/HTML/Navigable.h>
 
 namespace Web::HTML {
 
@@ -76,7 +76,7 @@ private:
 
     JS::GCPtr<DOM::Document> relevant_document() const;
     URL::URL url() const;
-    WebIDL::ExceptionOr<void> navigate(URL::URL, HistoryHandlingBehavior = HistoryHandlingBehavior::Default);
+    WebIDL::ExceptionOr<void> navigate(URL::URL, Bindings::NavigationHistoryBehavior = Bindings::NavigationHistoryBehavior::Auto);
 
     // [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap
     HTML::CrossOriginPropertyDescriptorMap m_cross_origin_property_descriptor_map;

+ 1 - 1
Userland/Libraries/LibWeb/HTML/Navigable.h

@@ -231,7 +231,7 @@ HashTable<Navigable*>& all_navigables();
 
 bool navigation_must_be_a_replace(URL::URL const& url, DOM::Document const& document);
 void finalize_a_cross_document_navigation(JS::NonnullGCPtr<Navigable>, HistoryHandlingBehavior, JS::NonnullGCPtr<SessionHistoryEntry>);
-void perform_url_and_history_update_steps(DOM::Document& document, URL::URL new_url, Optional<SerializationRecord> = {}, HistoryHandlingBehavior history_handling = HistoryHandlingBehavior::Reload);
+void perform_url_and_history_update_steps(DOM::Document& document, URL::URL new_url, Optional<SerializationRecord> = {}, HistoryHandlingBehavior history_handling = HistoryHandlingBehavior::Replace);
 UserNavigationInvolvement user_navigation_involvement(DOM::Event const&);
 
 }

+ 16 - 0
Userland/Libraries/LibWeb/HTML/Navigation.cpp

@@ -186,6 +186,7 @@ bool Navigation::can_go_forward() const
     return (m_current_entry_index != static_cast<i64>(m_entry_list.size()));
 }
 
+// https://html.spec.whatwg.org/multipage/browsing-the-web.html#history-handling-behavior
 HistoryHandlingBehavior to_history_handling_behavior(Bindings::NavigationHistoryBehavior b)
 {
     // A history handling behavior is a NavigationHistoryBehavior that is either "push" or "replace",
@@ -203,6 +204,21 @@ HistoryHandlingBehavior to_history_handling_behavior(Bindings::NavigationHistory
     VERIFY_NOT_REACHED();
 }
 
+// https://html.spec.whatwg.org/multipage/browsing-the-web.html#history-handling-behavior
+Bindings::NavigationHistoryBehavior to_navigation_history_behavior(HistoryHandlingBehavior b)
+{
+    // A history handling behavior is a NavigationHistoryBehavior that is either "push" or "replace",
+    // i.e., that has been resolved away from any initial "auto" value.
+
+    switch (b) {
+    case HistoryHandlingBehavior::Push:
+        return Bindings::NavigationHistoryBehavior::Push;
+    case HistoryHandlingBehavior::Replace:
+        return Bindings::NavigationHistoryBehavior::Replace;
+    }
+    VERIFY_NOT_REACHED();
+}
+
 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigation-navigate
 WebIDL::ExceptionOr<NavigationResult> Navigation::navigate(String url, NavigationNavigateOptions const& options)
 {

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

@@ -190,5 +190,6 @@ private:
 };
 
 HistoryHandlingBehavior to_history_handling_behavior(Bindings::NavigationHistoryBehavior);
+Bindings::NavigationHistoryBehavior to_navigation_history_behavior(HistoryHandlingBehavior);
 
 }

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

@@ -10,7 +10,6 @@
 #include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
 #include <LibWeb/HTML/CrossOrigin/CrossOriginOpenerPolicy.h>
 #include <LibWeb/HTML/CrossOrigin/CrossOriginOpenerPolicyEnforcementResult.h>
-#include <LibWeb/HTML/HistoryHandlingBehavior.h>
 #include <LibWeb/HTML/Navigable.h>
 #include <LibWeb/HTML/Origin.h>
 #include <LibWeb/HTML/PolicyContainers.h>