@@ -439,19 +439,25 @@ void HTMLLinkElement::default_fetch_and_process_linked_resource()
439439
440440 // 1. Let success be true.
441441 bool success = true ;
442+ ByteBuffer successful_body_bytes;
442443
443444 // 2. If either of the following conditions are met:
444445 // - bodyBytes is null or failure; or
445446 // - response's status is not an ok status,
446- if (body_bytes.template has <Empty>() || body_bytes.template has <Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag>() || !Fetch::Infrastructure::is_ok_status (response->status ())) {
447- // then set success to false.
448- success = false ;
449- }
447+ // then set success to false.
448+ body_bytes.visit (
449+ [&](ByteBuffer& body_bytes) {
450+ if (Fetch::Infrastructure::is_ok_status (response->status ()))
451+ successful_body_bytes = move (body_bytes);
452+ else
453+ success = false ;
454+ },
455+ [&](auto ) { success = false ; });
450456
451457 // FIXME: 3. Otherwise, wait for the link resource's critical subresources to finish loading.
452458
453459 // 4. Process the linked resource given el, success, response, and bodyBytes.
454- process_linked_resource (success, response, body_bytes );
460+ process_linked_resource (success, response, move (successful_body_bytes) );
455461 };
456462
457463 if (m_fetch_controller)
@@ -499,10 +505,10 @@ bool HTMLLinkElement::stylesheet_linked_resource_fetch_setup_steps(Fetch::Infras
499505}
500506
501507// https://html.spec.whatwg.org/multipage/semantics.html#process-the-linked-resource
502- void HTMLLinkElement::process_linked_resource (bool success, Fetch::Infrastructure::Response const & response, Variant<Empty, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag, ByteBuffer> body_bytes)
508+ void HTMLLinkElement::process_linked_resource (bool success, Fetch::Infrastructure::Response const & response, ByteBuffer body_bytes)
503509{
504510 if (m_relationship & Relationship::Stylesheet)
505- process_stylesheet_resource (success, response, body_bytes);
511+ process_stylesheet_resource (success, response, move ( body_bytes) );
506512}
507513
508514void HTMLLinkElement::process_icon_resource ()
@@ -519,7 +525,7 @@ void HTMLLinkElement::process_icon_resource()
519525}
520526
521527// https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:process-the-linked-resource
522- void HTMLLinkElement::process_stylesheet_resource (bool success, Fetch::Infrastructure::Response const & response, Variant<Empty, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag, ByteBuffer> body_bytes)
528+ void HTMLLinkElement::process_stylesheet_resource (bool success, Fetch::Infrastructure::Response const & response, ByteBuffer body_bytes)
523529{
524530 // 1. If the resource's Content-Type metadata is not text/css, then set success to false.
525531 auto mime_type_string = m_mime_type;
@@ -532,9 +538,8 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru
532538 mime_type_charset = charset.value ();
533539 }
534540
535- if (mime_type_string.has_value () && mime_type_string != " text/css" sv) {
541+ if (mime_type_string.has_value () && mime_type_string != " text/css" sv)
536542 success = false ;
537- }
538543
539544 // FIXME: 2. If el no longer creates an external resource link that contributes to the styling processing model,
540545 // or if, since the resource in question was fetched, it has become appropriate to fetch it again, then return.
@@ -581,7 +586,7 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru
581586 if (!environment_encoding.has_value () && document ().encoding ().has_value ())
582587 environment_encoding = document ().encoding ().value ();
583588
584- auto maybe_decoded_string = css_decode_bytes (environment_encoding, mime_type_charset, body_bytes. get <ByteBuffer>() );
589+ auto maybe_decoded_string = css_decode_bytes (environment_encoding, mime_type_charset, body_bytes);
585590 if (maybe_decoded_string.is_error ()) {
586591 dbgln (" Failed to decode CSS file: {}" , response.url ().value_or (URL::URL ()));
587592 dispatch_event (*DOM::Event::create (realm (), HTML::EventNames::error));
0 commit comments