Skip to content

Commit 0efd172

Browse files
AtkinsSJgmta
authored andcommitted
LibWeb/HTML: Update navigation request's reserved client
Fill in a couple of FIXMEs to discard an old reserved client, and/or create a new one, in `create_navigation_params_by_fetching()`.
1 parent 5a4f15d commit 0efd172

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

Libraries/LibWeb/HTML/Navigable.cpp

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,49 @@ static WebIDL::ExceptionOr<Navigable::NavigationParamsVariant> create_navigation
934934

935935
// 19. While true:
936936
while (true) {
937-
// FIXME: 1. If request's reserved client is not null and currentURL's origin is not the same as request's reserved client's creation URL's origin, then:
938-
// FIXME: 2. If request's reserved client is null, then:
937+
// 1. If request's reserved client is not null and currentURL's origin is not the same as request's reserved client's creation URL's origin, then:
938+
if (request->reserved_client() && !current_url.origin().is_same_origin(request->reserved_client()->creation_url.origin())) {
939+
// 1. Run the environment discarding steps for request's reserved client.
940+
request->reserved_client()->discard_environment();
941+
942+
// 2. Set request's reserved client to null.
943+
request->set_reserved_client(nullptr);
944+
945+
// 3. Set commitEarlyHints to null.
946+
commit_early_hints = nullptr;
947+
}
948+
949+
// 2. If request's reserved client is null, then:
950+
if (!request->reserved_client()) {
951+
// 1. Let topLevelCreationURL be currentURL.
952+
auto top_level_creation_url = current_url;
953+
954+
// 2. Let topLevelOrigin be null.
955+
URL::Origin top_level_origin;
956+
957+
// 3. If navigable is not a top-level traversable, then:
958+
if (!navigable->is_top_level_traversable()) {
959+
// 1. Let parentEnvironment be navigable's parent's active document's relevant settings object.
960+
auto& parent_environment = navigable->parent()->active_document()->relevant_settings_object();
961+
962+
// 2. Set topLevelCreationURL to parentEnvironment's top-level creation URL.
963+
top_level_creation_url = parent_environment.top_level_creation_url;
964+
965+
// 3. Set topLevelOrigin to parentEnvironment's top-level origin.
966+
top_level_origin = parent_environment.top_level_origin;
967+
}
968+
969+
// 4. Set request's reserved client to a new environment whose id is a unique opaque string,
970+
// target browsing context is navigable's active browsing context,
971+
// creation URL is currentURL,
972+
// top-level creation URL is topLevelCreationURL,
973+
// and top-level origin is topLevelOrigin.
974+
// FIXME: Make this a proper unique opaque string.
975+
static int next_id = 1;
976+
auto id_string = MUST(String::formatted("create-by-fetching-{}", next_id++));
977+
request->set_reserved_client(realm.create<Environment>(id_string, current_url, top_level_creation_url, top_level_origin, navigable->active_browsing_context()));
978+
}
979+
939980
// FIXME: 3. If the result of should navigation request of type be blocked by Content Security Policy? given request and cspNavigationType is "Blocked", then set response to a network error and break. [CSP]
940981

941982
// 4. Set response to null.

Libraries/LibWeb/HTML/Scripting/Environments.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ struct Environment : public JS::Cell {
5050
virtual void discard_environment() { }
5151

5252
protected:
53+
Environment() = default;
54+
Environment(String id, URL::URL creation_url, URL::URL top_level_creation_url, URL::Origin top_level_origin, GC::Ptr<BrowsingContext> target_browsing_context)
55+
: id(move(id))
56+
, creation_url(move(creation_url))
57+
, top_level_creation_url(move(top_level_creation_url))
58+
, top_level_origin(move(top_level_origin))
59+
, target_browsing_context(move(target_browsing_context))
60+
{
61+
}
5362
virtual void visit_edges(Cell::Visitor&) override;
5463
};
5564

0 commit comments

Comments
 (0)