dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / fetch / infrastructure / network_partition_key.lucb
#==============================================================================================
#
# network_partition_key - Fetch's network partition key of an environment or a request
#
# DESCRIPTION:
# Port of Libraries/LibWeb/Fetch/Infrastructure/NetworkPartitionKey.cpp (lines 13-45).
#
# Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/Fetch/Infrastructure/NetworkPartitionKey.cpp:13 Web::Fetch::Infrastructure::determine_the_network_partition_key.
# https://fetch.spec.whatwg.org/#determine-the-network-partition-key
pub func fetch_determine_the_network_partition_key_html_environment(environment: HtmlEnvironment*) -> FetchNetworkPartitionKey:
# 1. Let topLevelOrigin be environment’s top-level origin.
var top_level_origin = environment.top_level_origin
# 2. If topLevelOrigin is null, then set topLevelOrigin to environment’s top-level creation URL’s origin
if top_level_origin == none:
let top_level_creation_url = environment.top_level_creation_url else trap("VERIFY: the environment has a top-level creation URL")
top_level_origin = web_url.url_origin(&top_level_creation_url)
# 3. Assert: topLevelOrigin is an origin.
# FIXME: 4. Let topLevelSite be the result of obtaining a site, given topLevelOrigin.
# 5. Let secondKey be null or an implementation-defined value.
let second_key: void*? = none
# 6. Return (topLevelSite, secondKey).
return FetchNetworkPartitionKey(top_level_origin = top_level_origin else trap("VERIFY: topLevelOrigin is an origin"), second_key = second_key)
## Ported from Libraries/LibWeb/Fetch/Infrastructure/NetworkPartitionKey.cpp:34 Web::Fetch::Infrastructure::determine_the_network_partition_key (of a request).
# https://fetch.spec.whatwg.org/#request-determine-the-network-partition-key
pub func fetch_determine_the_network_partition_key_fetch_request(request: FetchRequest*) -> FetchNetworkPartitionKey?:
# 1. If request’s reserved client is non-null, then return the result of determining the network partition key given request’s reserved client.
if let reserved_client = fetch_request_reserved_client(request):
return fetch_determine_the_network_partition_key_html_environment(reserved_client)
# 2. If request’s client is non-null, then return the result of determining the network partition key given request’s client.
if let client = fetch_request_client(request):
return fetch_determine_the_network_partition_key_html_environment(client.html_environment())
return none