Skip to content

Commit

Permalink
LibWeb/HTML: Pass user_involvement through navigables code
Browse files Browse the repository at this point in the history
This corresponds to part of whatwg/html#10818
  • Loading branch information
AtkinsSJ committed Jan 7, 2025
1 parent 056b774 commit 57e5e21
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 94 deletions.
7 changes: 4 additions & 3 deletions Libraries/LibWeb/DOM/DocumentLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,16 @@ GC::Ptr<DOM::Document> load_document(HTML::NavigationParams const& navigation_pa
if (type.essence() == "application/pdf"_string
|| type.essence() == "text/pdf"_string) {
// FIXME: If the user agent's PDF viewer supported is true, return the result of creating a document for inline
// content that doesn't have a DOM given navigationParams's navigable.
// content that doesn't have a DOM given navigationParams's navigable, navigationParams's id,
// navigationParams's navigation timing type, and navigationParams's user involvement.
}

// Otherwise, proceed onward.

// 3. If, given type, the new resource is to be handled by displaying some sort of inline content, e.g., a
// FIXME: 3. If, given type, the new resource is to be handled by displaying some sort of inline content, e.g., a
// native rendering of the content or an error message because the specified type is not supported, then
// return the result of creating a document for inline content that doesn't have a DOM given navigationParams's
// navigable, navigationParams's id, and navigationParams's navigation timing type.
// navigable, navigationParams's id, navigationParams's navigation timing type, and navigationParams's user involvement.

// FIXME: 4. Otherwise, the document's type is such that the resource will not affect navigationParams's navigable,
// e.g., because the resource is to be handed to an external application or because it is an unknown type
Expand Down
4 changes: 3 additions & 1 deletion Libraries/LibWeb/DOM/DocumentLoading.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bool can_load_document_with_type(MimeSniff::MimeType const&);

// https://html.spec.whatwg.org/multipage/document-lifecycle.html#read-ua-inline
template<typename MutateDocument>
GC::Ref<DOM::Document> create_document_for_inline_content(GC::Ptr<HTML::Navigable> navigable, Optional<String> navigation_id, MutateDocument mutate_document)
GC::Ref<DOM::Document> create_document_for_inline_content(GC::Ptr<HTML::Navigable> navigable, Optional<String> navigation_id, HTML::UserNavigationInvolvement user_involvement, MutateDocument mutate_document)
{
auto& vm = navigable->vm();

Expand Down Expand Up @@ -53,6 +53,7 @@ GC::Ref<DOM::Document> create_document_for_inline_content(GC::Ptr<HTML::Navigabl
// opener policy: coop
// FIXME: navigation timing type: navTimingType
// about base URL: null
// user involvement: userInvolvement
auto response = Fetch::Infrastructure::Response::create(vm);
response->url_list().append(URL::URL("about:error")); // AD-HOC: https://github.com/whatwg/html/issues/9122
auto navigation_params = vm.heap().allocate<HTML::NavigationParams>();
Expand All @@ -69,6 +70,7 @@ GC::Ref<DOM::Document> create_document_for_inline_content(GC::Ptr<HTML::Navigabl
navigation_params->final_sandboxing_flag_set = HTML::SandboxingFlagSet {};
navigation_params->opener_policy = move(coop);
navigation_params->about_base_url = {};
navigation_params->user_involvement = user_involvement;

// 5. Let document be the result of creating and initializing a Document object given "html", "text/html", and navigationParams.
auto document = DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html"_string, navigation_params).release_value_but_fixme_should_propagate_errors();
Expand Down
94 changes: 52 additions & 42 deletions Libraries/LibWeb/HTML/Navigable.cpp

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions Libraries/LibWeb/HTML/Navigable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ enum class CSPNavigationType {
FormSubmission,
};

// https://html.spec.whatwg.org/multipage/browsing-the-web.html#user-navigation-involvement
enum class UserNavigationInvolvement {
BrowserUI,
Activation,
None,
};

// https://html.spec.whatwg.org/multipage/browsing-the-web.html#target-snapshot-params
struct TargetSnapshotParams {
SandboxingFlagSet sandboxing_flags {};
Expand Down Expand Up @@ -133,6 +126,7 @@ class Navigable : public JS::Cell {
GC::Ptr<SessionHistoryEntry> entry,
SourceSnapshotParams const& source_snapshot_params,
TargetSnapshotParams const& target_snapshot_params,
UserNavigationInvolvement user_involvement,
Optional<String> navigation_id = {},
NavigationParamsVariant navigation_params = Navigable::NullOrError {},
CSPNavigationType csp_navigation_type = CSPNavigationType::Other,
Expand All @@ -156,12 +150,12 @@ class Navigable : public JS::Cell {

WebIDL::ExceptionOr<void> navigate_to_a_fragment(URL::URL const&, HistoryHandlingBehavior, UserNavigationInvolvement, Optional<SerializationRecord> navigation_api_state, String navigation_id);

GC::Ptr<DOM::Document> evaluate_javascript_url(URL::URL const&, URL::Origin const& new_document_origin, String navigation_id);
void navigate_to_a_javascript_url(URL::URL const&, HistoryHandlingBehavior, URL::Origin const& initiator_origin, CSPNavigationType csp_navigation_type, String navigation_id);
GC::Ptr<DOM::Document> evaluate_javascript_url(URL::URL const&, URL::Origin const& new_document_origin, UserNavigationInvolvement, String navigation_id);
void navigate_to_a_javascript_url(URL::URL const&, HistoryHandlingBehavior, URL::Origin const& initiator_origin, UserNavigationInvolvement, CSPNavigationType csp_navigation_type, String navigation_id);

bool allowed_by_sandboxing_to_navigate(Navigable const& target, SourceSnapshotParams const&);

void reload();
void reload(UserNavigationInvolvement = UserNavigationInvolvement::None);

// https://github.com/whatwg/html/issues/9690
[[nodiscard]] bool has_been_destroyed() const { return m_has_been_destroyed; }
Expand Down Expand Up @@ -245,7 +239,7 @@ class Navigable : public JS::Cell {
HashTable<Navigable*>& all_navigables();

bool navigation_must_be_a_replace(URL::URL const& url, DOM::Document const& document);
void finalize_a_cross_document_navigation(GC::Ref<Navigable>, HistoryHandlingBehavior, GC::Ref<SessionHistoryEntry>);
void finalize_a_cross_document_navigation(GC::Ref<Navigable>, HistoryHandlingBehavior, UserNavigationInvolvement, GC::Ref<SessionHistoryEntry>);
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&);

Expand Down
13 changes: 13 additions & 0 deletions Libraries/LibWeb/HTML/NavigationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@

namespace Web::HTML {

// https://html.spec.whatwg.org/multipage/browsing-the-web.html#user-navigation-involvement
enum class UserNavigationInvolvement {
BrowserUI,
Activation,
None,
};

// https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigation-params
struct NavigationParams : JS::Cell {
GC_CELL(NavigationParams, JS::Cell);
Expand Down Expand Up @@ -66,6 +73,9 @@ struct NavigationParams : JS::Cell {
// a URL or null used to populate the new Document's about base URL
Optional<URL::URL> about_base_url;

// a user navigation involvement used when obtaining a browsing context for the new Document
UserNavigationInvolvement user_involvement;

void visit_edges(Visitor& visitor) override;
};

Expand Down Expand Up @@ -94,6 +104,9 @@ struct NonFetchSchemeNavigationParams : JS::Cell {

// FIXME: a NavigationTimingType used for creating the navigation timing entry for the new Document

// a user navigation involvement used when obtaining a browsing context for the new Document (if one is created)
UserNavigationInvolvement user_involvement;

void visit_edges(Visitor& visitor) override;
};

Expand Down
Loading

0 comments on commit 57e5e21

Please sign in to comment.