diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-04-18 16:38:54 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-19 07:57:52 +0200 |
commit | f8d6a67294a93f9e23d9311e05d285178028ec0c (patch) | |
tree | a1155f62fad1185fcce8ebb3ed7b9b140e889b54 /Userland/Libraries/LibWeb | |
parent | 7833b321a37677d34dc16f4dfe43f418e8c14199 (diff) | |
download | serenity-f8d6a67294a93f9e23d9311e05d285178028ec0c.zip |
LibWeb: Implement the HTMLMediaElement crossOrigin attribute
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLMediaElement.idl | 1 |
3 files changed, 24 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index c6674a6dbe..0b0c43acf2 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -91,6 +91,14 @@ void HTMLMediaElement::parse_attribute(DeprecatedFlyString const& name, Deprecat if (name == HTML::AttributeNames::src) load_element().release_value_but_fixme_should_propagate_errors(); + else if (name == HTML::AttributeNames::crossorigin) + m_crossorigin = cors_setting_attribute_from_keyword(String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors()); +} + +void HTMLMediaElement::did_remove_attribute(DeprecatedFlyString const& name) +{ + if (name == HTML::AttributeNames::crossorigin) + m_crossorigin = cors_setting_attribute_from_keyword({}); } // https://html.spec.whatwg.org/multipage/media.html#dom-media-buffered @@ -572,8 +580,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::fetch_resource(AK::URL const& url_re // 3. Let request be the result of creating a potential-CORS request given current media resource's URL record, destination, and the current state // of media element's crossorigin content attribute. - // FIXME: Parse the media element's crossorigin content attribute. - auto request = create_potential_CORS_request(vm, url_record, destination, CORSSettingAttribute::Anonymous); + auto request = create_potential_CORS_request(vm, url_record, destination, m_crossorigin); // 4. Set request's client to the media element's node document's relevant settings object. request->set_client(&document().relevant_settings_object()); @@ -640,6 +647,15 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::fetch_resource(AK::URL const& url_re // ability to cache data. // 5. Otherwise, incrementally read response's body given updateMedia, processEndOfMedia, an empty algorithm, and global. + + // FIXME: Spec issue: If the response is CORS-cross-origin, we need to read from its internal response instead. + // https://github.com/whatwg/html/issues/3483 + // https://github.com/whatwg/html/issues/9066 + if (response->type() == Fetch::Infrastructure::Response::Type::Opaque || response->type() == Fetch::Infrastructure::Response::Type::OpaqueRedirect) { + auto& filtered_response = static_cast<Fetch::Infrastructure::FilteredResponse&>(*response); + response = filtered_response.internal_response(); + } + VERIFY(response->body().has_value()); auto empty_algorithm = [](auto&) {}; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h index 86846017db..b3d7740927 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h @@ -12,6 +12,7 @@ #include <AK/Variant.h> #include <LibJS/Heap/MarkedVector.h> #include <LibJS/SafeFunction.h> +#include <LibWeb/HTML/CORSSettingAttribute.h> #include <LibWeb/HTML/EventLoop/Task.h> #include <LibWeb/HTML/HTMLElement.h> #include <LibWeb/WebIDL/DOMException.h> @@ -89,6 +90,7 @@ private: using ByteRange = Variant<EntireResource>; // FIXME: This will need to include "until end" and an actual byte range. virtual void parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) override; + virtual void did_remove_attribute(DeprecatedFlyString const&) override; Task::Source media_element_event_task_source() const { return m_media_element_event_task_source.source; } @@ -137,6 +139,9 @@ private: // https://html.spec.whatwg.org/multipage/media.html#media-element-event-task-source UniqueTaskSource m_media_element_event_task_source {}; + // https://html.spec.whatwg.org/multipage/media.html#dom-media-crossorigin + CORSSettingAttribute m_crossorigin { CORSSettingAttribute::NoCORS }; + // https://html.spec.whatwg.org/multipage/media.html#dom-media-networkstate NetworkState m_network_state { NetworkState::Empty }; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.idl index a6acd35800..3cb3440752 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.idl @@ -14,6 +14,7 @@ interface HTMLMediaElement : HTMLElement { // network state [Reflect, CEReactions] attribute DOMString src; + [Reflect=crossorigin, CEReactions] attribute DOMString? crossOrigin; const unsigned short NETWORK_EMPTY = 0; const unsigned short NETWORK_IDLE = 1; const unsigned short NETWORK_LOADING = 2; |