1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 10:01:13 +09:00

LibWeb: Support SRI for import maps

See:
- b2fdca1
This commit is contained in:
Jamie Mansfield 2024-06-01 11:25:58 +01:00 committed by Tim Ledbetter
parent 124779a376
commit bab086694a
Notes: github-actions[bot] 2024-08-14 20:07:19 +00:00
6 changed files with 127 additions and 17 deletions

View file

@ -280,6 +280,43 @@ static void set_up_module_script_request(Fetch::Infrastructure::Request& request
request.set_priority(options.fetch_priority);
}
// https://html.spec.whatwg.org/multipage/webappapis.html#get-the-descendant-script-fetch-options
WebIDL::ExceptionOr<ScriptFetchOptions> get_descendant_script_fetch_options(ScriptFetchOptions const& original_options, URL::URL const& url, EnvironmentSettingsObject& settings_object)
{
// 1. Let newOptions be a copy of originalOptions.
auto new_options = original_options;
// 2. Let integrity be the empty string.
String integrity;
// 3. If settingsObject's global object is a Window object, then set integrity to the result of resolving a module integrity metadata with url and settingsObject.
if (is<Window>(settings_object.global_object()))
integrity = TRY(resolve_a_module_integrity_metadata(url, settings_object));
// 4. Set newOptions's integrity metadata to integrity.
new_options.integrity_metadata = integrity;
// 5. Set newOptions's fetch priority to "auto".
new_options.fetch_priority = Fetch::Infrastructure::Request::Priority::Auto;
// 6. Return newOptions.
return new_options;
}
// https://html.spec.whatwg.org/multipage/webappapis.html#resolving-a-module-integrity-metadata
WebIDL::ExceptionOr<String> resolve_a_module_integrity_metadata(const URL::URL& url, EnvironmentSettingsObject& settings_object)
{
// 1. Assert: settingsObject's global object is a Window object.
VERIFY(is<Window>(settings_object.global_object()));
// 2. Let map be settingsObject's global object's import map.
auto map = static_cast<Window const&>(settings_object.global_object()).import_map();
// 3. If map's integrity[url] does not exist, then return the empty string.
// 4. Return map's integrity[url].
return MUST(String::from_byte_string(map.integrity().get(url).value_or("")));
}
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-classic-script
WebIDL::ExceptionOr<void> fetch_classic_script(JS::NonnullGCPtr<HTMLScriptElement> element, URL::URL const& url, EnvironmentSettingsObject& settings_object, ScriptFetchOptions options, CORSSettingAttribute cors_setting, String character_encoding, OnFetchScriptComplete on_complete)
{
@ -858,7 +895,7 @@ void fetch_single_imported_module_script(JS::Realm& realm,
Fetch::Infrastructure::Request::Destination destination,
ScriptFetchOptions const& options,
EnvironmentSettingsObject& settings_object,
Fetch::Infrastructure::Request::Referrer referrer,
Fetch::Infrastructure::Request::ReferrerType referrer,
JS::ModuleRequest const& module_request,
PerformTheFetchHook perform_fetch,
OnFetchScriptComplete on_complete)