Truly independent web browser
LibWeb: Implement the credentials in Rust
Shannon Booth5884b5e1d03e
diff --git a/Libraries/LibWeb/Bindings/Rust/src/credential_management/credential.rs b/Libraries/LibWeb/Bindings/Rust/src/credential_management/credential.rsindex d9be1331890..6e349627a16 100644--- a/Libraries/LibWeb/Bindings/Rust/src/credential_management/credential.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/credential_management/credential.rs@@ -7,10 +7,17 @@//! Credential, https://w3c.github.io/webappsec-credential-management/#credential+use ak::Utf16String;+use libjs_rust::api::{Trace, Value};++use super::federated_credential::FederatedCredential;+use super::password_credential::PasswordCredential;use crate::bindings::conversions::UsvString;+use crate::bindings::interface::{Ref, Wrappable};+use crate::bindings::promise::{WebIdlPromise, create_resolved_promise};+use crate::bindings::{CallContext, WebIdlResult};/// https://w3c.github.io/webappsec-credential-management/#dictdef-credentialdata-#[expect(dead_code, reason = "create() does not read the options yet")]pub(crate) struct CredentialData {pub(crate) id: UsvString,}@@ -23,3 +30,45 @@ pub(crate) enum CredentialMediationRequirement {Conditional,Required,}++#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct Credential {+ id: UsvString,+ r#type: Utf16String,+}++impl Wrappable for Credential {}++impl Credential {+ pub(crate) fn new(id: UsvString, r#type: &str) -> Self {+ Self {+ id,+ r#type: Utf16String::from_utf8(r#type),+ }+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-credential-id+ pub(crate) fn id(&self, _: &mut CallContext) -> WebIdlResult<UsvString> {+ Ok(self.id.clone())+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-credential-type+ pub(crate) fn r#type(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ Ok(self.r#type.clone())+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-credential-isconditionalmediationavailable+ pub(crate) fn is_conditional_mediation_available(cx: &mut CallContext) -> WebIdlResult<WebIdlPromise> {+ // 1. Return a promise resolved with with false.+ Ok(create_resolved_promise(cx.vm(), cx.realm(), Value::from_bool(false)))+ }+}++#[derive(Clone, Copy, Trace)]+#[gc(crate = libjs_rust)]+pub(crate) enum AnyCredential {+ Credential(Ref<Credential>),+ FederatedCredential(Ref<FederatedCredential>),+ PasswordCredential(Ref<PasswordCredential>),+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/credential_management/credential_user_data.rs b/Libraries/LibWeb/Bindings/Rust/src/credential_management/credential_user_data.rsnew file mode 100644index 00000000000..a033632dba5--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/credential_management/credential_user_data.rs@@ -0,0 +1,35 @@+/*+ * Copyright (c) 2025, Kenneth Myhra <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! CredentialUserData, https://w3c.github.io/webappsec-credential-management/#credentialuserdata++use libjs_rust::api::Trace;++use crate::bindings::conversions::UsvString;++#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct CredentialUserData {+ name: UsvString,+ icon_url: UsvString,+}++impl CredentialUserData {+ pub(crate) fn new(name: UsvString, icon_url: UsvString) -> Self {+ Self { name, icon_url }+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-credentialuserdata-name+ pub(crate) fn name(&self) -> UsvString {+ self.name.clone()+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-credentialuserdata-iconurl+ pub(crate) fn icon_url(&self) -> UsvString {+ self.icon_url.clone()+ }+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/credential_management/credentials_container.rs b/Libraries/LibWeb/Bindings/Rust/src/credential_management/credentials_container.rsindex cc2713e4154..1a73e9a0ea8 100644--- a/Libraries/LibWeb/Bindings/Rust/src/credential_management/credentials_container.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/credential_management/credentials_container.rs@@ -11,7 +11,7 @@ use core::ffi::c_void;use libjs_rust::api::{ErrorKind, ErrorType, Trace, Vm};-use super::credential::CredentialMediationRequirement;+use super::credential::{AnyCredential, CredentialMediationRequirement};use super::federated_credential::{FederatedCredentialInit, FederatedCredentialRequestOptions};use super::password_credential::PasswordCredentialInit;use crate::bindings::conversions::CppInterface;@@ -64,7 +64,7 @@ impl CredentialsContainer {}// https://w3c.github.io/webappsec-credential-management/#dom-credentialscontainer-store- pub(crate) fn store(&self, cx: &mut CallContext, promise: WebIdlPromise, _: CppInterface) -> WebIdlResult<()> {+ pub(crate) fn store(&self, cx: &mut CallContext, promise: WebIdlPromise, _: AnyCredential) -> WebIdlResult<()> {eprintln!("FIXME: Unimplemented CredentialsContainer::store()");reject_not_implemented_promise(cx.vm(), promise, "store");Ok(())diff --git a/Libraries/LibWeb/Bindings/Rust/src/credential_management/federated_credential.rs b/Libraries/LibWeb/Bindings/Rust/src/credential_management/federated_credential.rsindex 84e9563d5c9..9b598705802 100644--- a/Libraries/LibWeb/Bindings/Rust/src/credential_management/federated_credential.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/credential_management/federated_credential.rs@@ -8,9 +8,17 @@//! FederatedCredential, https://w3c.github.io/webappsec-credential-management/#federatedcredentialuse ak::Utf16String;+use libjs_rust::api::Trace;+use liburl_rust::origin::Origin;+use liburl_rust::{BasicParseOptions, basic_parse};-use super::credential::CredentialData;+use super::credential::{Credential, CredentialData};+use super::credential_user_data::CredentialUserData;+use super::federated_credential_operations::create_federated_credential;use crate::bindings::conversions::UsvString;+use crate::bindings::interface::{Inherits, Ref, Wrappable};+use crate::bindings::{CallContext, Exception, WebIdlResult};+use crate::domurl::url_input;/// https://w3c.github.io/webappsec-credential-management/#dictdef-federatedcredentialrequestoptions#[expect(dead_code, reason = "get() does not read the options yet")]@@ -20,7 +28,6 @@ pub(crate) struct FederatedCredentialRequestOptions {}/// https://w3c.github.io/webappsec-credential-management/#dictdef-federatedcredentialinit-#[expect(dead_code, reason = "create() does not read the options yet")]pub(crate) struct FederatedCredentialInit {pub(crate) parent: CredentialData,pub(crate) icon_url: Option<UsvString>,@@ -28,3 +35,86 @@ pub(crate) struct FederatedCredentialInit {pub(crate) protocol: Option<Utf16String>,pub(crate) provider: UsvString,}++#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct FederatedCredential {+ credential: Credential,+ user_data: CredentialUserData,+ provider: UsvString,+ protocol: Option<Utf16String>,+ // https://w3c.github.io/webappsec-credential-management/#dom-credential-origin-slot+ #[gc(untraced)]+ #[cfg_attr(web_idl_bindings, expect(dead_code, reason = "no algorithm reads [[origin]] yet"))]+ origin: Origin,+}++impl Wrappable for FederatedCredential {}++impl Inherits<Credential> for FederatedCredential {+ fn parent(&self) -> &Credential {+ &self.credential+ }+}++impl FederatedCredential {+ pub(crate) fn new(init: FederatedCredentialInit, origin: Origin) -> Self {+ Self {+ credential: Credential::new(init.parent.id, "federated"),+ user_data: CredentialUserData::new(+ init.name.unwrap_or_else(|| UsvString::from_ascii(b"")),+ init.icon_url.unwrap_or_else(|| UsvString::from_ascii(b"")),+ ),+ provider: init.provider,+ protocol: init.protocol,+ origin,+ }+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-federatedcredential-federatedcredential+ pub(crate) fn construct(cx: &mut CallContext, data: FederatedCredentialInit) -> WebIdlResult<Ref<Self>> {+ // 1. Let r be the result of executing Create a FederatedCredential from FederatedCredentialInit on data. If that+ // threw an exception, rethrow that exception.+ // 2. Return r.+ if data.parent.id.as_utf16_string().is_empty() {+ return Err(Exception::TypeError(Utf16String::from_ascii(+ b"'id' must not be empty.",+ )));+ }+ if data.provider.as_utf16_string().is_empty() {+ return Err(Exception::TypeError(Utf16String::from_ascii(+ b"'provider' must not be empty.",+ )));+ }++ // AD-HOC: Aligning with how Chromium retrieves the origin by parsing the URL from data.provider.+ let Some(url) = basic_parse(url_input(data.provider.units()), BasicParseOptions::new()) else {+ return Err(Exception::Dom(+ "SyntaxError",+ Utf16String::from_ascii(b"'provider' is not a valid url."),+ ));+ };++ Ok(create_federated_credential(cx.vm(), data, url.origin()))+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-federatedcredential-provider+ pub(crate) fn provider(&self, _: &mut CallContext) -> WebIdlResult<UsvString> {+ Ok(self.provider.clone())+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-federatedcredential-protocol+ pub(crate) fn protocol(&self, _: &mut CallContext) -> WebIdlResult<Option<Utf16String>> {+ Ok(self.protocol.clone())+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-credentialuserdata-name+ pub(crate) fn name(&self, _: &mut CallContext) -> WebIdlResult<UsvString> {+ Ok(self.user_data.name())+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-credentialuserdata-iconurl+ pub(crate) fn icon_url(&self, _: &mut CallContext) -> WebIdlResult<UsvString> {+ Ok(self.user_data.icon_url())+ }+}diff --git a/Libraries/LibWeb/CredentialManagement/FederatedCredentialOperations.cpp b/Libraries/LibWeb/Bindings/Rust/src/credential_management/federated_credential_operations.rssimilarity index 50%rename from Libraries/LibWeb/CredentialManagement/FederatedCredentialOperations.cpprename to Libraries/LibWeb/Bindings/Rust/src/credential_management/federated_credential_operations.rsindex 1b49ef066ea..6a7571240ed 100644--- a/Libraries/LibWeb/CredentialManagement/FederatedCredentialOperations.cpp+++ b/Libraries/LibWeb/Bindings/Rust/src/credential_management/federated_credential_operations.rs@@ -1,17 +1,22 @@/** Copyright (c) 2025, Kenneth Myhra <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.** SPDX-License-Identifier: BSD-2-Clause*/-#include <LibGC/Heap.h>-#include <LibWeb/CredentialManagement/FederatedCredentialOperations.h>+use libjs_rust::api::Vm;+use liburl_rust::origin::Origin;-namespace Web::CredentialManagement {+use super::federated_credential::{FederatedCredential, FederatedCredentialInit};+use crate::bindings::interface::{Ref, allocate};-// https://www.w3.org/TR/credential-management-1/#abstract-opdef-create-a-federatedcredential-from-federatedcredentialinit-GC::Ref<FederatedCredential> create_federated_credential(FederatedCredentialInit init, URL::Origin origin)-{+/// https://w3c.github.io/webappsec-credential-management/#abstract-opdef-create-a-federatedcredential-from-federatedcredentialinit+pub(crate) fn create_federated_credential(+ vm: &Vm,+ init: FederatedCredentialInit,+ origin: Origin,+) -> Ref<FederatedCredential> {// 1. Let c be a new FederatedCredential object.// 3. Set c’s properties as follows:// - id@@ -26,7 +31,5 @@ GC::Ref<FederatedCredential> create_federated_credential(FederatedCredentialInit// - init.origin's value.// NOTE: origin is retrieved by parsing the URL from init.provider.// 4. Return c.- return GC::Heap::the().allocate<FederatedCredential>(move(init), move(origin));-}-+ allocate(vm, |_| FederatedCredential::new(init, origin))}diff --git a/Libraries/LibWeb/Bindings/Rust/src/credential_management/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/credential_management/mod.rsindex 63864b143f2..a9d115fd272 100644--- a/Libraries/LibWeb/Bindings/Rust/src/credential_management/mod.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/credential_management/mod.rs@@ -7,6 +7,9 @@//! Credential Management, https://w3c.github.io/webappsec-credential-management/pub(crate) mod credential;+pub(crate) mod credential_user_data;pub(crate) mod credentials_container;pub(crate) mod federated_credential;+pub(crate) mod federated_credential_operations;pub(crate) mod password_credential;+pub(crate) mod password_credential_operations;diff --git a/Libraries/LibWeb/Bindings/Rust/src/credential_management/password_credential.rs b/Libraries/LibWeb/Bindings/Rust/src/credential_management/password_credential.rsindex de0d2d50b94..7b9f1d8e9cd 100644--- a/Libraries/LibWeb/Bindings/Rust/src/credential_management/password_credential.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/credential_management/password_credential.rs@@ -7,11 +7,21 @@//! PasswordCredential, https://w3c.github.io/webappsec-credential-management/#passwordcredential-use super::credential::CredentialData;+use libjs_rust::api::Trace;+use liburl_rust::origin::Origin;++use super::credential::{Credential, CredentialData};+use super::credential_user_data::CredentialUserData;+use super::password_credential_operations::{+ create_password_credential_from_data, create_password_credential_from_form,+};use crate::bindings::conversions::{CppInterface, UsvString};+use crate::bindings::environment_settings_object::relevant_settings_object;+use crate::bindings::interface::{Inherits, Ref, Wrappable};+use crate::bindings::{CallContext, WebIdlResult};+use crate::html::html_form_element::CppHTMLFormElement;/// https://w3c.github.io/webappsec-credential-management/#dictdef-passwordcredentialdata-#[expect(dead_code, reason = "create() does not read the options yet")]pub(crate) struct PasswordCredentialData {pub(crate) parent: CredentialData,pub(crate) icon_url: Option<UsvString>,@@ -25,3 +35,78 @@ pub(crate) enum PasswordCredentialInit {PasswordCredentialData(PasswordCredentialData),HTMLFormElement(CppInterface),}++#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct PasswordCredential {+ credential: Credential,+ user_data: CredentialUserData,+ // TODO: Use Core::SecretString when it comes back+ password: UsvString,+ // https://w3c.github.io/webappsec-credential-management/#dom-credential-origin-slot+ #[gc(untraced)]+ #[cfg_attr(web_idl_bindings, expect(dead_code, reason = "no algorithm reads [[origin]] yet"))]+ origin: Origin,+}++impl Wrappable for PasswordCredential {}++impl Inherits<Credential> for PasswordCredential {+ fn parent(&self) -> &Credential {+ &self.credential+ }+}++fn current_settings_object_origin(cx: &CallContext) -> Origin {+ relevant_settings_object(cx.realm().global_object()).origin()+}++impl PasswordCredential {+ pub(crate) fn new(data: PasswordCredentialData, origin: Origin) -> Self {+ Self {+ credential: Credential::new(data.parent.id, "password"),+ user_data: CredentialUserData::new(+ data.name.unwrap_or_else(|| UsvString::from_ascii(b"")),+ data.icon_url.unwrap_or_else(|| UsvString::from_ascii(b"")),+ ),+ password: data.password,+ origin,+ }+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-passwordcredential-passwordcredential+ pub(crate) fn construct_from_form(cx: &mut CallContext, form: CppInterface) -> WebIdlResult<Ref<Self>> {+ // 1. Let origin be the current settings object’s origin.+ let origin = current_settings_object_origin(cx);++ // 2. Let r be the result of executing Create a PasswordCredential from an HTMLFormElement given form and origin.+ // 3. If r is an exception, throw r. Otherwise, return r.+ // SAFETY: The bindings pass the wrapper of an HTMLFormElement.+ let form = unsafe { CppHTMLFormElement::from_interface(form) };+ create_password_credential_from_form(cx, form, origin)+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-passwordcredential-passwordcredential-data+ pub(crate) fn construct_from_data(cx: &mut CallContext, data: PasswordCredentialData) -> WebIdlResult<Ref<Self>> {+ let origin = current_settings_object_origin(cx);++ // 1. Let r be the result of executing Create a PasswordCredential from PasswordCredentialData on data.+ // 2. If r is an exception, throw r.+ create_password_credential_from_data(cx.vm(), data, origin)+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-passwordcredential-password+ pub(crate) fn password(&self, _: &mut CallContext) -> WebIdlResult<UsvString> {+ Ok(self.password.clone())+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-credentialuserdata-name+ pub(crate) fn name(&self, _: &mut CallContext) -> WebIdlResult<UsvString> {+ Ok(self.user_data.name())+ }++ // https://w3c.github.io/webappsec-credential-management/#dom-credentialuserdata-iconurl+ pub(crate) fn icon_url(&self, _: &mut CallContext) -> WebIdlResult<UsvString> {+ Ok(self.user_data.icon_url())+ }+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/credential_management/password_credential_operations.rs b/Libraries/LibWeb/Bindings/Rust/src/credential_management/password_credential_operations.rsnew file mode 100644index 00000000000..a0b54440708--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/credential_management/password_credential_operations.rs@@ -0,0 +1,173 @@+/*+ * Copyright (c) 2025, Kenneth Myhra <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use ak::Utf16String;+use libjs_rust::api::Vm;+use liburl_rust::origin::Origin;++use super::credential::CredentialData;+use super::password_credential::{PasswordCredential, PasswordCredentialData};+use crate::bindings::conversions::UsvString;+use crate::bindings::interface::{Ref, allocate};+use crate::bindings::{CallContext, Exception, WebIdlResult};+use crate::html::html_form_element::CppHTMLFormElement;+use crate::xhr::form_data::{FormData, FormDataEntryValue};++/// https://w3c.github.io/webappsec-credential-management/#abstract-opdef-create-a-passwordcredential-from-an-htmlformelement+pub(crate) fn create_password_credential_from_form(+ cx: &mut CallContext,+ form: CppHTMLFormElement,+ origin: Origin,+) -> WebIdlResult<Ref<PasswordCredential>> {+ // 1. Let data be a new PasswordCredentialData dictionary.+ let mut data = PasswordCredentialData {+ parent: CredentialData {+ id: UsvString::from_ascii(b""),+ },+ icon_url: None,+ name: None,+ password: UsvString::from_ascii(b""),+ };++ // 2. Set data’s origin member’s value to origin’s value.++ // 3. Let formData be the result of executing the FormData constructor on form.+ let form_data = FormData::construct(cx, Some(form.interface()), None)?;++ // 4. Let elements be a list of all the submittable elements whose form owner is form, in tree order.+ let elements = form.submittable_elements(cx.vm());++ // 5. Let newPasswordObserved be false.+ let mut new_password_observed = false;++ // 6. For each field in elements, run the following steps:+ for index in 0..elements.len() {+ let field = elements.get(index).expect("the index is in range");++ // 1. If field does not have an autocomplete attribute, then skip to the next field.+ let Some(autocomplete_attribute) = field.attribute("autocomplete").filter(|value| !value.is_empty()) else {+ continue;+ };++ // 2. Let name be the value of field’s name attribute.+ // 3. If formData’s has() method returns false when executed on name, then skip to the next field.+ let Some(name) = field.attribute("name") else {+ continue;+ };+ let name = UsvString::from_utf16_string(&name);+ if !form_data.has(cx, name.clone())? {+ continue;+ }++ let string_value_of = |cx: &mut CallContext| -> WebIdlResult<Option<UsvString>> {+ Ok(match form_data.get(cx, name.clone())? {+ Some(FormDataEntryValue::USVString(value)) => Some(value),+ _ => None,+ })+ };++ // 4. If field’s autocomplete attribute’s value contains one or more autofill detail tokens (tokens), then:+ // 1. For each token in tokens:+ let autocomplete_attribute = String::from_utf16_lossy(&autocomplete_attribute.to_utf16());+ for token in autocomplete_attribute.split(' ').filter(|token| !token.is_empty()) {+ // 1. If token is an ASCII case-insensitive match for one of the following strings, run the associated steps:+ // - "new-password"+ // Set data’s password member’s value to the result of executing formData’s get() method on name,+ // and newPasswordObserved to true.+ if token.eq_ignore_ascii_case("new-password")+ && let Some(password) = string_value_of(cx)?+ {+ data.password = password;+ new_password_observed = true;+ }+ // - "current-password"+ // If newPasswordObserved is false, set data’s password member’s value to the result of executing+ // formData’s get() method on name.+ // Note: By checking that newPasswordObserved is false, new-password fields take precedence over+ // current-password fields.+ if !new_password_observed+ && token.eq_ignore_ascii_case("current-password")+ && let Some(password) = string_value_of(cx)?+ {+ data.password = password;+ }+ // - "photo"+ // Set data’s iconURL member’s value to the result of executing formData’s get() method on name.+ if token.eq_ignore_ascii_case("photo")+ && let Some(photo) = string_value_of(cx)?+ {+ data.icon_url = Some(photo);+ }+ // - "name"+ // - "nickname"+ // Set data’s name member’s value to the result of executing formData’s get() method on name.+ if token.eq_ignore_ascii_case("name")+ && let Some(name) = string_value_of(cx)?+ {+ data.name = Some(name);+ }+ if token.eq_ignore_ascii_case("nickname")+ && let Some(nickname) = string_value_of(cx)?+ {+ data.name = Some(nickname);+ }+ // - "username"+ // Set data’s id member’s value to the result of executing formData’s get() method on name.+ if token.eq_ignore_ascii_case("username")+ && let Some(username) = string_value_of(cx)?+ {+ data.parent.id = username;+ }+ }+ }++ // 7. Let c be the result of executing Create a PasswordCredential from PasswordCredentialData on data.+ // If that threw an exception, rethrow that exception.+ // 8. Assert: c is a PasswordCredential.+ // 9. Return c.+ create_password_credential_from_data(cx.vm(), data, origin)+}++/// https://w3c.github.io/webappsec-credential-management/#abstract-opdef-create-a-passwordcredential-from-passwordcredentialdata+pub(crate) fn create_password_credential_from_data(+ vm: &Vm,+ data: PasswordCredentialData,+ origin: Origin,+) -> WebIdlResult<Ref<PasswordCredential>> {+ // 1. Let c be a new PasswordCredential object.+ // 2. If any of the following are the empty string, throw a TypeError exception:+ // - data’s id member’s value+ // - data’s origin member’s value+ // NOTE: origin cannot be an empty string at this time since it is retrieved from the current settings object+ // in the constructor.+ // - data’s password member’s value+ if data.parent.id.as_utf16_string().is_empty() {+ return Err(Exception::TypeError(Utf16String::from_ascii(+ b"'id' must not be empty.",+ )));+ }+ if data.password.as_utf16_string().is_empty() {+ return Err(Exception::TypeError(Utf16String::from_ascii(+ b"'password' must not be empty.",+ )));+ }++ // 3. Set c’s properties as follows:+ // - password+ // - data’s password member’s value+ // - id+ // - data’s id member’s value+ // - iconUrl+ // - data’s iconURL member’s value+ // - name+ // - data’s name member’s value+ // - [[origin]]+ // - data’s origin member’s value.+ // NOTE: origin is retrieved from the current settings object in the constructor.+ // 4. Return c.+ Ok(allocate(vm, |_| PasswordCredential::new(data, origin)))+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/dom/element.rs b/Libraries/LibWeb/Bindings/Rust/src/dom/element.rsnew file mode 100644index 00000000000..9e1d01f4c10--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/dom/element.rs@@ -0,0 +1,56 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use core::ffi::c_void;++use ak::Utf16String;+use libjs_rust::api::Trace;++use crate::bindings::cpp_cell::CppCell;++unsafe extern "C" {+ fn web_dom_element_attribute(+ element: *mut c_void,+ name: ak::Span<'_, u8>,+ value: *mut c_void,+ on_value: unsafe extern "C" fn(*mut c_void, usize),+ );+}++unsafe extern "C" fn on_value(value: *mut c_void, raw_value: usize) {+ // SAFETY: value is the result slot of the caller, and LibWeb hands over a reference to the string.+ unsafe { *value.cast::<Option<Utf16String>>() = Some(Utf16String::from_raw_owned(raw_value)) };+}++/// https://dom.spec.whatwg.org/#concept-element+#[derive(Clone, Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct CppElement(CppCell);++impl CppElement {+ /// # Safety+ ///+ /// `element` must be a live Element.+ pub(crate) unsafe fn from_raw(element: *mut c_void) -> Self {+ // SAFETY: The caller passes a live Element.+ Self(unsafe { CppCell::from_raw(element) })+ }++ /// https://dom.spec.whatwg.org/#concept-element-attributes-get-value+ pub(crate) fn attribute(&self, name: &str) -> Option<Utf16String> {+ let mut value = None;+ // SAFETY: The element is live, the name is lent for the call, and the value outlives it.+ unsafe {+ web_dom_element_attribute(+ self.0.as_ptr(),+ ak::Span::new(name.as_bytes()),+ (&raw mut value).cast(),+ on_value,+ );+ }+ value+ }+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/dom/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/dom/mod.rsindex 7d46beaf6de..37220eeb4bc 100644--- a/Libraries/LibWeb/Bindings/Rust/src/dom/mod.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/dom/mod.rs@@ -10,4 +10,6 @@pub(crate) mod abort_signal;#[cfg(not(test))]pub(crate) mod document;+#[cfg(not(test))]+pub(crate) mod element;pub(crate) mod event;diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/html_form_element.rs b/Libraries/LibWeb/Bindings/Rust/src/html/html_form_element.rsnew file mode 100644index 00000000000..08fde1f102e--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/html/html_form_element.rs@@ -0,0 +1,56 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++use core::ffi::c_void;++use libjs_rust::api::{MarkedVec, Vm};++use crate::bindings::conversions::CppInterface;+use crate::dom::element::CppElement;++unsafe extern "C" {+ fn web_html_form_element_submittable_elements(+ form: *mut c_void,+ elements: *mut c_void,+ on_element: unsafe extern "C" fn(*mut c_void, *mut c_void),+ );+}++unsafe extern "C" fn on_element(elements: *mut c_void, element: *mut c_void) {+ // SAFETY: elements is the list of the caller, and LibWeb passes a live Element.+ unsafe { (*elements.cast::<MarkedVec<'_, CppElement>>()).push(CppElement::from_raw(element)) };+}++/// https://html.spec.whatwg.org/multipage/forms.html#the-form-element+#[derive(Clone, Copy)]+pub(crate) struct CppHTMLFormElement(CppInterface);++impl CppHTMLFormElement {+ /// # Safety+ ///+ /// `form` must be the wrapper of an HTMLFormElement.+ pub(crate) unsafe fn from_interface(form: CppInterface) -> Self {+ Self(form)+ }++ pub(crate) fn interface(self) -> CppInterface {+ self.0+ }++ /// The submittable elements whose form owner is the form, in tree order.+ pub(crate) fn submittable_elements<'vm>(&self, vm: &'vm Vm) -> MarkedVec<'vm, CppElement> {+ let elements = MarkedVec::new(vm);+ // SAFETY: The form is live, and the list outlives the call.+ unsafe {+ web_html_form_element_submittable_elements(+ self.0.wrapper().as_ptr().cast(),+ (&raw const elements).cast_mut().cast(),+ on_element,+ );+ }+ elements+ }+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/html/mod.rsindex f4b6de4761b..927518cd8c4 100644--- a/Libraries/LibWeb/Bindings/Rust/src/html/mod.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/html/mod.rs@@ -57,6 +57,8 @@ pub(crate) mod canvas_transform;#[cfg(not(test))]pub(crate) mod exports;#[cfg(not(test))]+pub(crate) mod html_form_element;+#[cfg(not(test))]pub(crate) mod image_bitmap;#[cfg(not(test))]pub(crate) mod image_bitmap_rendering_context;diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txtindex 2b5e93b6fd0..484185c6df6 100644--- a/Libraries/LibWeb/CMakeLists.txt+++ b/Libraries/LibWeb/CMakeLists.txt@@ -56,12 +56,7 @@ set(SOURCESContentSecurityPolicy/Violation.cppCookieStore/CookieChangeEvent.cppCookieStore/CookieStore.cpp- CredentialManagement/Credential.cppCredentialManagement/CredentialsContainer.cpp- CredentialManagement/FederatedCredential.cpp- CredentialManagement/FederatedCredentialOperations.cpp- CredentialManagement/PasswordCredential.cpp- CredentialManagement/PasswordCredentialOperations.cppCrypto/Crypto.cppCrypto/CryptoKey.cppCSS/Angle.cppdiff --git a/Libraries/LibWeb/CredentialManagement/Credential.cpp b/Libraries/LibWeb/CredentialManagement/Credential.cppdeleted file mode 100644index b8500814550..00000000000--- a/Libraries/LibWeb/CredentialManagement/Credential.cpp+++ /dev/null@@ -1,35 +0,0 @@-/*- * Copyright (c) 2025, Altomani Gianluca <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibWeb/CredentialManagement/Credential.h>-#include <LibWeb/WebIDL/Promise.h>--namespace Web::CredentialManagement {--// https://www.w3.org/TR/credential-management-1/#dom-credential-isconditionalmediationavailable-bool Credential::is_conditional_mediation_available()-{- // 1. Return false.- return false;-}--GC::Ref<WebIDL::Promise> Credential::is_conditional_mediation_available_impl(JS::VM& vm)-{- return WebIDL::create_resolved_promise(*vm.current_realm(), JS::Value(is_conditional_mediation_available()));-}--Credential::~Credential() { }--Credential::Credential()-{-}--Credential::Credential(Utf16String id)- : m_id(move(id))-{-}--}diff --git a/Libraries/LibWeb/CredentialManagement/Credential.h b/Libraries/LibWeb/CredentialManagement/Credential.hdeleted file mode 100644index d049dc124a5..00000000000--- a/Libraries/LibWeb/CredentialManagement/Credential.h+++ /dev/null@@ -1,41 +0,0 @@-/*- * Copyright (c) 2025, Altomani Gianluca <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/Utf16String.h>-#include <LibWeb/Bindings/Wrappable.h>--namespace Web::CredentialManagement {--// https://www.w3.org/TR/credential-management-1/#credential-class Credential : public Bindings::GCAllocatedWrappable {- WEB_WRAPPABLE(Credential, Bindings::GCAllocatedWrappable);- GC_DECLARE_ALLOCATOR(Credential);--public:- static bool is_conditional_mediation_available();- static GC::Ref<WebIDL::Promise> is_conditional_mediation_available_impl(JS::VM&);-- virtual ~Credential() override;-- Utf16String const& id() const { return m_id; }-- virtual Utf16FlyString const& type() const = 0;--protected:- explicit Credential();- Credential(Utf16String id);-- Utf16String m_id;-};--// https://www.w3.org/TR/credential-management-1/#dictdef-credentialdata-struct CredentialData {- Utf16String id;-};--}diff --git a/Libraries/LibWeb/CredentialManagement/Credential.idl b/Libraries/LibWeb/CredentialManagement/Credential.idlindex a493b8b74b1..c0e874332a6 100644--- a/Libraries/LibWeb/CredentialManagement/Credential.idl+++ b/Libraries/LibWeb/CredentialManagement/Credential.idl@@ -1,8 +1,8 @@-[Exposed=Window, SecureContext]+[Exposed=Window, SecureContext, ImplementedIn=Rust]interface Credential {readonly attribute USVString id;readonly attribute DOMString type;- [ImplementedAs=is_conditional_mediation_available_impl] static Promise<boolean> isConditionalMediationAvailable();+ static Promise<boolean> isConditionalMediationAvailable();};[SecureContext]diff --git a/Libraries/LibWeb/CredentialManagement/CredentialUserData.h b/Libraries/LibWeb/CredentialManagement/CredentialUserData.hdeleted file mode 100644index edec5d7cd77..00000000000--- a/Libraries/LibWeb/CredentialManagement/CredentialUserData.h+++ /dev/null@@ -1,32 +0,0 @@-/*- * Copyright (c) 2025, Kenneth Myhra <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/Utf16String.h>--namespace Web::CredentialManagement {--// https://www.w3.org/TR/credential-management-1/#credentialuserdata-class CredentialUserData {-public:- virtual ~CredentialUserData() = default;-- Utf16String const& name() const { return m_name; }- Utf16String const& icon_url() const { return m_icon_url; }--protected:- CredentialUserData(Utf16String name, Utf16String icon_url)- : m_name(move(name))- , m_icon_url(move(icon_url))- {- }-- Utf16String m_name;- Utf16String m_icon_url;-};--}diff --git a/Libraries/LibWeb/CredentialManagement/FederatedCredential.cpp b/Libraries/LibWeb/CredentialManagement/FederatedCredential.cppdeleted file mode 100644index 7aec78d85fb..00000000000--- a/Libraries/LibWeb/CredentialManagement/FederatedCredential.cpp+++ /dev/null@@ -1,55 +0,0 @@-/*- * Copyright (c) 2025, Altomani Gianluca <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibURL/Parser.h>-#include <LibWeb/CredentialManagement/FederatedCredential.h>-#include <LibWeb/CredentialManagement/FederatedCredentialOperations.h>-#include <LibWeb/WebIDL/DOMException.h>-#include <LibWeb/WebIDL/ExceptionOr.h>--namespace Web::CredentialManagement {--GC_DEFINE_ALLOCATOR(FederatedCredential);--// https://www.w3.org/TR/credential-management-1/#dom-federatedcredential-federatedcredential-WebIDL::ExceptionOr<GC::Ref<FederatedCredential>> FederatedCredential::create(FederatedCredentialInit const& data)-{- // 1. Let r be the result of executing Create a FederatedCredential from FederatedCredentialInit on data. If that- // threw an exception, rethrow that exception.- // 2. Return r.- if (data.id.is_empty())- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "'id' must not be empty."_utf16 };- if (data.provider.is_empty())- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "'provider' must not be empty."_utf16 };-- // AD-HOC: Aligning with how Chromium retrieves the origin by parsing the URL from data.provider.- auto url = URL::Parser::basic_parse(data.provider);- if (!url.has_value())- return WebIDL::SyntaxError::create("'provider' is not a valid url."_utf16);-- return create_federated_credential(data, url->origin());-}--FederatedCredential::~FederatedCredential()-{-}--Utf16FlyString const& FederatedCredential::type() const-{- static Utf16FlyString const& type = *new Utf16FlyString("federated"_utf16_fly_string);- return type;-}--FederatedCredential::FederatedCredential(FederatedCredentialInit init, URL::Origin origin)- : Credential(move(init.id))- , CredentialUserData(init.name.value_or(Utf16String {}), init.icon_url.value_or(Utf16String {}))- , m_provider(move(init.provider))- , m_protocol(move(init.protocol))- , m_origin(move(origin))-{-}--}diff --git a/Libraries/LibWeb/CredentialManagement/FederatedCredential.h b/Libraries/LibWeb/CredentialManagement/FederatedCredential.hdeleted file mode 100644index 95abbd270ee..00000000000--- a/Libraries/LibWeb/CredentialManagement/FederatedCredential.h+++ /dev/null@@ -1,52 +0,0 @@-/*- * Copyright (c) 2025, Altomani Gianluca <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <LibWeb/Bindings/FederatedCredential.h>-#include <LibWeb/CredentialManagement/Credential.h>-#include <LibWeb/CredentialManagement/CredentialUserData.h>--namespace Web::CredentialManagement {--// https://www.w3.org/TR/credential-management-1/#dictdef-federatedcredentialrequestoptions-struct FederatedCredentialRequestOptions {- Vector<String> providers;- Vector<String> protocols;-};--// https://www.w3.org/TR/credential-management-1/#dictdef-federatedcredentialinit-using FederatedCredentialInit = Bindings::FederatedCredentialInit;--// https://w3c.github.io/webappsec-credential-management/#federatedcredential-class FederatedCredential final- : public Credential- , public CredentialUserData {- WEB_WRAPPABLE(FederatedCredential, Credential);- GC_DECLARE_ALLOCATOR(FederatedCredential);--public:- [[nodiscard]] static WebIDL::ExceptionOr<GC::Ref<FederatedCredential>> create(FederatedCredentialInit const&);-- virtual ~FederatedCredential() override;-- Utf16String const& provider() const { return m_provider; }- Optional<Utf16String> const& protocol() const { return m_protocol; }- URL::Origin const& origin() const { return m_origin; }-- Utf16FlyString const& type() const override;--private:- FederatedCredential(FederatedCredentialInit, URL::Origin);-- Utf16String m_provider;- Optional<Utf16String> m_protocol;-- // https://www.w3.org/TR/credential-management-1/#dom-credential-origin-slot- URL::Origin m_origin;-};--}diff --git a/Libraries/LibWeb/CredentialManagement/FederatedCredential.idl b/Libraries/LibWeb/CredentialManagement/FederatedCredential.idlindex 1c800863557..1566e71801e 100644--- a/Libraries/LibWeb/CredentialManagement/FederatedCredential.idl+++ b/Libraries/LibWeb/CredentialManagement/FederatedCredential.idl@@ -1,4 +1,4 @@-[Exposed=Window, SecureContext]+[Exposed=Window, SecureContext, ImplementedIn=Rust]interface FederatedCredential : Credential {constructor(FederatedCredentialInit data);readonly attribute USVString provider;diff --git a/Libraries/LibWeb/CredentialManagement/FederatedCredentialOperations.h b/Libraries/LibWeb/CredentialManagement/FederatedCredentialOperations.hdeleted file mode 100644index 7bcb98b4239..00000000000--- a/Libraries/LibWeb/CredentialManagement/FederatedCredentialOperations.h+++ /dev/null@@ -1,16 +0,0 @@-/*- * Copyright (c) 2025, Kenneth Myhra <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <LibURL/Origin.h>-#include <LibWeb/CredentialManagement/FederatedCredential.h>--namespace Web::CredentialManagement {--GC::Ref<FederatedCredential> create_federated_credential(FederatedCredentialInit, URL::Origin);--}diff --git a/Libraries/LibWeb/CredentialManagement/PasswordCredential.cpp b/Libraries/LibWeb/CredentialManagement/PasswordCredential.cppdeleted file mode 100644index 1d9c3441e6b..00000000000--- a/Libraries/LibWeb/CredentialManagement/PasswordCredential.cpp+++ /dev/null@@ -1,63 +0,0 @@-/*- * Copyright (c) 2025, Altomani Gianluca <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibWeb/CredentialManagement/PasswordCredential.h>-#include <LibWeb/CredentialManagement/PasswordCredentialOperations.h>-#include <LibWeb/HTML/Scripting/Environments.h>-#include <LibWeb/HTML/Window.h>-#include <LibWeb/WebIDL/ExceptionOr.h>--namespace Web::CredentialManagement {--GC_DEFINE_ALLOCATOR(PasswordCredential);--// https://www.w3.org/TR/credential-management-1/#dom-passwordcredential-passwordcredential-WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> PasswordCredential::create(URL::Origin origin, GC::Ref<HTML::HTMLFormElement> form)-{- // 2. Let r be the result of executing Create a PasswordCredential from an HTMLFormElement given form and origin.- // 3. If r is an exception, throw r. Otherwise, return r.- return create_password_credential(form, move(origin));-}--// https://www.w3.org/TR/credential-management-1/#dom-passwordcredential-passwordcredential-data-WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> PasswordCredential::create(URL::Origin origin, PasswordCredentialData const& data)-{- // 1. Let r be the result of executing Create a PasswordCredential from PasswordCredentialData on data.- // 2. If r is an exception, throw r.- return create_password_credential(data, move(origin));-}--WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> PasswordCredential::create_for_constructor(JS::Object& relevant_global_object, GC::Ref<HTML::HTMLFormElement> form)-{- auto& window = HTML::relevant_window(relevant_global_object);- return create(HTML::relevant_settings_object(window).origin(), form);-}--WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> PasswordCredential::create_for_constructor(JS::Object& relevant_global_object, PasswordCredentialData const& data)-{- auto& window = HTML::relevant_window(relevant_global_object);- return create(HTML::relevant_settings_object(window).origin(), data);-}--PasswordCredential::~PasswordCredential()-{-}--Utf16FlyString const& PasswordCredential::type() const-{- static Utf16FlyString const& type = *new Utf16FlyString("password"_utf16_fly_string);- return type;-}--PasswordCredential::PasswordCredential(PasswordCredentialData data, URL::Origin origin)- : Credential(move(data.id))- , CredentialUserData(data.name.value_or(Utf16String {}), data.icon_url.value_or(Utf16String {}))- , m_password(move(data.password))- , m_origin(move(origin))-{-}--}diff --git a/Libraries/LibWeb/CredentialManagement/PasswordCredential.h b/Libraries/LibWeb/CredentialManagement/PasswordCredential.hdeleted file mode 100644index 679b2a171cf..00000000000--- a/Libraries/LibWeb/CredentialManagement/PasswordCredential.h+++ /dev/null@@ -1,50 +0,0 @@-/*- * Copyright (c) 2025, Altomani Gianluca <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <LibURL/Origin.h>-#include <LibWeb/Bindings/PasswordCredential.h>-#include <LibWeb/CredentialManagement/Credential.h>-#include <LibWeb/CredentialManagement/CredentialUserData.h>-#include <LibWeb/HTML/HTMLFormElement.h>--namespace Web::CredentialManagement {--// https://www.w3.org/TR/credential-management-1/#dictdef-passwordcredentialdata-using PasswordCredentialData = Bindings::PasswordCredentialData;--// https://www.w3.org/TR/credential-management-1/#passwordcredential-class PasswordCredential final- : public Credential- , public CredentialUserData {- WEB_WRAPPABLE(PasswordCredential, Credential);- GC_DECLARE_ALLOCATOR(PasswordCredential);--public:- [[nodiscard]] static WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> create(URL::Origin, GC::Ref<HTML::HTMLFormElement>);- [[nodiscard]] static WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> create(URL::Origin, PasswordCredentialData const&);- [[nodiscard]] static WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> create_for_constructor(JS::Object&, GC::Ref<HTML::HTMLFormElement>);- [[nodiscard]] static WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> create_for_constructor(JS::Object&, PasswordCredentialData const&);-- virtual ~PasswordCredential() override;-- Utf16String const& password() const { return m_password; }- URL::Origin const& origin() const { return m_origin; }-- Utf16FlyString const& type() const override;--private:- PasswordCredential(PasswordCredentialData, URL::Origin);-- // TODO: Use Core::SecretString when it comes back- Utf16String m_password;-- // https://www.w3.org/TR/credential-management-1/#dom-credential-origin-slot- URL::Origin m_origin;-};--}diff --git a/Libraries/LibWeb/CredentialManagement/PasswordCredential.idl b/Libraries/LibWeb/CredentialManagement/PasswordCredential.idlindex 8d8dfefbb94..481712ea8c6 100644--- a/Libraries/LibWeb/CredentialManagement/PasswordCredential.idl+++ b/Libraries/LibWeb/CredentialManagement/PasswordCredential.idl@@ -1,7 +1,7 @@-[Exposed=Window, SecureContext]+[Exposed=Window, SecureContext, ImplementedIn=Rust]interface PasswordCredential : Credential {- constructor(HTMLFormElement form);- constructor(PasswordCredentialData data);+ [ImplementedAs=construct_from_form] constructor(HTMLFormElement form);+ [ImplementedAs=construct_from_data] constructor(PasswordCredentialData data);readonly attribute USVString password;};PasswordCredential includes CredentialUserData;diff --git a/Libraries/LibWeb/CredentialManagement/PasswordCredentialOperations.cpp b/Libraries/LibWeb/CredentialManagement/PasswordCredentialOperations.cppdeleted file mode 100644index e1f0c2737de..00000000000--- a/Libraries/LibWeb/CredentialManagement/PasswordCredentialOperations.cpp+++ /dev/null@@ -1,134 +0,0 @@-/*- * Copyright (c) 2025, Kenneth Myhra <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibGC/Heap.h>-#include <LibWeb/CredentialManagement/PasswordCredentialOperations.h>-#include <LibWeb/HTML/HTMLFormElement.h>-#include <LibWeb/XHR/FormData.h>--namespace Web::CredentialManagement {--// https://www.w3.org/TR/credential-management-1/#abstract-opdef-create-a-passwordcredential-from-an-htmlformelement-WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> create_password_credential(GC::Ref<HTML::HTMLFormElement> form, URL::Origin origin)-{- // 1. Let data be a new PasswordCredentialData dictionary.- PasswordCredentialData data;-- // 2. Set data’s origin member’s value to origin’s value.-- // 3. Let formData be the result of executing the FormData constructor on form.- auto form_data = TRY(XHR::FormData::create_from_form(form));-- // 4. Let elements be a list of all the submittable elements whose form owner is form, in tree order.- auto elements = form->get_submittable_elements();-- // 5. Let newPasswordObserved be false.- bool new_password_observed = false;-- // 6. For each field in elements, run the following steps:- for (auto const& field : elements) {- // 1. If field does not have an autocomplete attribute, then skip to the next field.- if (auto attr = field->attribute(HTML::AttributeNames::autocomplete); !attr.has_value() || attr->is_empty())- continue;-- // 2. Let name be the value of field’s name attribute.- // 3. If formData’s has() method returns false when executed on name, then skip to the next field.- auto name = field->attribute(HTML::AttributeNames::name);- if (!name.has_value())- continue;- if (!form_data->has(*name))- continue;-- // 4. If field’s autocomplete attribute’s value contains one or more autofill detail tokens (tokens), then:- // 1. For each token in tokens:- auto autocomplete_attribute = field->attribute(HTML::AttributeNames::autocomplete).value();- for (auto token : autocomplete_attribute.split_view(u' ', SplitBehavior::Nothing)) {- // 1. If token is an ASCII case-insensitive match for one of the following strings, run the associated steps:- // - "new-password"- // Set data’s password member’s value to the result of executing formData’s get() method on name,- // and newPasswordObserved to true.- if (token.equals_ignoring_ascii_case(u"new-password"sv)) {- if (auto password = form_data->get(*name); password.has<Utf16String>()) {- data.password = password.get<Utf16String>();- new_password_observed = true;- }- }- // - "current-password"- // If newPasswordObserved is false, set data’s password member’s value to the result of executing- // formData’s get() method on name.- // Note: By checking that newPasswordObserved is false, new-password fields take precedence over- // current-password fields.- if (!new_password_observed && token.equals_ignoring_ascii_case(u"current-password"sv)) {- if (auto password = form_data->get(*name); password.has<Utf16String>())- data.password = password.get<Utf16String>();- }- // - "photo"- // Set data’s iconURL member’s value to the result of executing formData’s get() method on name.- if (token.equals_ignoring_ascii_case(u"photo"sv)) {- if (auto photo = form_data->get(*name); photo.has<Utf16String>())- data.icon_url = photo.get<Utf16String>();- }- // - "name"- // - "nickname"- // Set data’s name member’s value to the result of executing formData’s get() method on name.- if (token.equals_ignoring_ascii_case(u"name"sv)) {- if (auto name_ = form_data->get(*name); name_.has<Utf16String>())- data.name = name_.get<Utf16String>();- }- if (token.equals_ignoring_ascii_case(u"nickname"sv)) {- if (auto nickname = form_data->get(*name); nickname.has<Utf16String>())- data.name = nickname.get<Utf16String>();- }- // - "username"- // Set data’s id member’s value to the result of executing formData’s get() method on name.- if (token.equals_ignoring_ascii_case(u"username"sv)) {- if (auto username = form_data->get(*name); username.has<Utf16String>()) {- auto id = username.get<Utf16String>();- data.id = id;- }- }- }- }-- // 7. Let c be the result of executing Create a PasswordCredential from PasswordCredentialData on data.- // If that threw an exception, rethrow that exception.- // 8. Assert: c is a PasswordCredential.- // 9. Return c.- return create_password_credential(data, move(origin));-}--// https://www.w3.org/TR/credential-management-1/#abstract-opdef-create-a-passwordcredential-from-passwordcredentialdata-WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> create_password_credential(PasswordCredentialData data, URL::Origin origin)-{- // 1. Let c be a new PasswordCredential object.- // 2. If any of the following are the empty string, throw a TypeError exception:- // - data’s id member’s value- // - data’s origin member’s value- // NOTE: origin cannot be an empty string at this time since it is retrieved from the current settings object- // in the constructor.- // - data’s password member’s value- if (data.id.is_empty())- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "'id' must not be empty."_utf16 };- if (data.password.is_empty())- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "'password' must not be empty."_utf16 };-- // 3. Set c’s properties as follows:- // - password- // - data’s password member’s value- // - id- // - data’s id member’s value- // - iconUrl- // - data’s iconURL member’s value- // - name- // - data’s name member’s value- // - [[origin]]- // - data’s origin member’s value.- // NOTE: origin is retrieved from the current settings object in the constructor.- // 4. Return c.- return GC::Heap::the().allocate<PasswordCredential>(move(data), move(origin));-}--}diff --git a/Libraries/LibWeb/CredentialManagement/PasswordCredentialOperations.h b/Libraries/LibWeb/CredentialManagement/PasswordCredentialOperations.hdeleted file mode 100644index 2be28695e92..00000000000--- a/Libraries/LibWeb/CredentialManagement/PasswordCredentialOperations.h+++ /dev/null@@ -1,16 +0,0 @@-/*- * Copyright (c) 2025, Kenneth Myhra <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <LibWeb/CredentialManagement/PasswordCredential.h>--namespace Web::CredentialManagement {--WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> create_password_credential(GC::Ref<HTML::HTMLFormElement>, URL::Origin);-WebIDL::ExceptionOr<GC::Ref<PasswordCredential>> create_password_credential(PasswordCredentialData, URL::Origin);--}diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cppindex 492cf0ad930..41415fb6739 100644--- a/Libraries/LibWeb/DOM/Element.cpp+++ b/Libraries/LibWeb/DOM/Element.cpp@@ -177,6 +177,12 @@namespace Web::DOM {+extern "C" {++// Called by Bindings/Rust/src/dom/element.rs.+void web_dom_element_attribute(Element*, ReadonlyBytes name, void* value, void (*on_value)(void*, FlatPtr));+}+#if ARCH(X86_64) && !defined(AK_OS_WINDOWS)static_assert(sizeof(Element) == 304);#endif@@ -7328,6 +7334,14 @@ bool Element::is_potentially_render_blocking()return false;}+void web_dom_element_attribute(Element* element, ReadonlyBytes name, void* value, void (*on_value)(void*, FlatPtr))+{+ auto attribute = element->attribute(Utf16FlyString::from_utf8(StringView { name }));+ if (!attribute.has_value())+ return;+ on_value(value, attribute.release_value().into_raw());+}+}namespace Web::Bindings {diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.hindex 3c67ebcd772..19f460c5d9f 100644--- a/Libraries/LibWeb/Forward.h+++ b/Libraries/LibWeb/Forward.h@@ -244,10 +244,7 @@ class CookieStore;namespace Web::CredentialManagement {-class Credential;class CredentialsContainer;-class FederatedCredential;-class PasswordCredential;}diff --git a/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Libraries/LibWeb/HTML/HTMLFormElement.cppindex 77bf039761c..0f7a59ad7b0 100644--- a/Libraries/LibWeb/HTML/HTMLFormElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLFormElement.cpp@@ -11,9 +11,11 @@#include <AK/QuickSort.h>#include <AK/StringBuilder.h>#include <AK/Utf16StringBuilder.h>+#include <LibJS/HostClassBuilder.h>#include <LibTextCodec/Decoder.h>#include <LibWeb/Bindings/CSS.h>#include <LibWeb/Bindings/HTMLFormElement.h>+#include <LibWeb/Bindings/Wrappable.h>#include <LibWeb/CSS/Invalidation/ElementStateInvalidator.h>#include <LibWeb/DOM/DOMTokenList.h>#include <LibWeb/DOM/Document.h>@@ -48,6 +50,12 @@namespace Web::HTML {+extern "C" {++// Called by Bindings/Rust/src/html/html_form_element.rs.+void web_html_form_element_submittable_elements(JSObject* form, void* elements, void (*on_element)(void*, DOM::Element*));+}+GC_DEFINE_ALLOCATOR(HTMLFormElement);HTMLFormElement::HTMLFormElement(DOM::Document& document, DOM::QualifiedName qualified_name)@@ -1386,4 +1394,11 @@ size_t HTMLFormElement::number_of_fields_blocking_implicit_submission() constreturn count;}+void web_html_form_element_submittable_elements(JSObject* form, void* elements, void (*on_element)(void*, DOM::Element*))+{+ auto& form_element = as<HTMLFormElement>(*Bindings::wrappable_impl_from(JS::HostABI::object_from_abi(form)));+ for (auto& element : form_element.get_submittable_elements())+ on_element(elements, element.ptr());+}+}diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex f5eb2402230..68c02665a0d 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -599,6 +599,7 @@ Text/input/wpt-import/scroll-animations/scroll-timelines/idlharness.window.htmlText/input/wpt-import/server-timing/idlharness.https.any.htmlText/input/wpt-import/server-timing/idlharness.https.any.worker.htmlText/input/wpt-import/speech-api/idlharness.https.window.html+Text/input/wpt-import/credential-management/idlharness.https.window.htmlText/input/wpt-import/streams/idlharness.any.htmlText/input/wpt-import/svg/idlharness.window.htmlText/input/wpt-import/trusted-types/idlharness.window.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/credential-management/historical.https.txt b/Tests/LibWeb/Text/expected/wpt-import/credential-management/historical.https.txtnew file mode 100644index 00000000000..83ab7c94d58--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/credential-management/historical.https.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Credential.willRequestConditionalCreation should not exist\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/credential-management/idlharness.https.window.txt b/Tests/LibWeb/Text/expected/wpt-import/credential-management/idlharness.https.window.txtnew file mode 100644index 00000000000..88ac66129ca--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/credential-management/idlharness.https.window.txt@@ -0,0 +1,101 @@+Harness status: OK++Found 96 tests++96 Pass+Pass idl_test setup+Pass idl_test validation+Pass Partial interface Navigator: original interface defined+Pass Partial interface Navigator: member names are unique+Pass Partial dictionary CredentialRequestOptions: original dictionary defined+Pass Partial dictionary CredentialRequestOptions: member names are unique+Pass Partial dictionary CredentialCreationOptions: original dictionary defined+Pass Partial dictionary CredentialCreationOptions: member names are unique+Pass Partial dictionary CredentialRequestOptions[2]: original dictionary defined+Pass Partial dictionary CredentialRequestOptions[2]: member names are unique+Pass Partial dictionary CredentialCreationOptions[2]: original dictionary defined+Pass Partial dictionary CredentialCreationOptions[2]: member names are unique+Pass Partial interface Navigator[2]: member names are unique+Pass Partial interface Element: member names are unique+Pass Partial interface mixin NavigatorID: member names are unique+Pass PasswordCredential includes CredentialUserData: member names are unique+Pass FederatedCredential includes CredentialUserData: member names are unique+Pass HTMLElement includes GlobalEventHandlers: member names are unique+Pass HTMLElement includes ElementContentEditable: member names are unique+Pass HTMLElement includes HTMLOrSVGElement: member names are unique+Pass Navigator includes NavigatorID: member names are unique+Pass Navigator includes NavigatorLanguage: member names are unique+Pass Navigator includes NavigatorOnLine: member names are unique+Pass Navigator includes NavigatorContentUtils: member names are unique+Pass Navigator includes NavigatorCookies: member names are unique+Pass Navigator includes NavigatorPlugins: member names are unique+Pass Navigator includes NavigatorConcurrentHardware: member names are unique+Pass Element includes ParentNode: member names are unique+Pass Element includes NonDocumentTypeChildNode: member names are unique+Pass Element includes ChildNode: member names are unique+Pass Element includes Slottable: member names are unique+Pass Credential interface: existence and properties of interface object+Pass Credential interface object length+Pass Credential interface object name+Pass Credential interface: existence and properties of interface prototype object+Pass Credential interface: existence and properties of interface prototype object's "constructor" property+Pass Credential interface: existence and properties of interface prototype object's @@unscopables property+Pass Credential interface: attribute id+Pass Credential interface: attribute type+Pass Credential interface: operation isConditionalMediationAvailable()+Pass CredentialsContainer interface: existence and properties of interface object+Pass CredentialsContainer interface object length+Pass CredentialsContainer interface object name+Pass CredentialsContainer interface: existence and properties of interface prototype object+Pass CredentialsContainer interface: existence and properties of interface prototype object's "constructor" property+Pass CredentialsContainer interface: existence and properties of interface prototype object's @@unscopables property+Pass CredentialsContainer interface: operation get(optional CredentialRequestOptions)+Pass CredentialsContainer interface: operation store(Credential)+Pass CredentialsContainer interface: operation create(optional CredentialCreationOptions)+Pass CredentialsContainer interface: operation preventSilentAccess()+Pass CredentialsContainer must be primary interface of navigator.credentials+Pass Stringification of navigator.credentials+Pass CredentialsContainer interface: navigator.credentials must inherit property "get(optional CredentialRequestOptions)" with the proper type+Pass CredentialsContainer interface: calling get(optional CredentialRequestOptions) on navigator.credentials with too few arguments must throw TypeError+Pass CredentialsContainer interface: navigator.credentials must inherit property "store(Credential)" with the proper type+Pass CredentialsContainer interface: calling store(Credential) on navigator.credentials with too few arguments must throw TypeError+Pass CredentialsContainer interface: navigator.credentials must inherit property "create(optional CredentialCreationOptions)" with the proper type+Pass CredentialsContainer interface: calling create(optional CredentialCreationOptions) on navigator.credentials with too few arguments must throw TypeError+Pass CredentialsContainer interface: navigator.credentials must inherit property "preventSilentAccess()" with the proper type+Pass PasswordCredential interface: existence and properties of interface object+Pass PasswordCredential interface object length+Pass PasswordCredential interface object name+Pass PasswordCredential interface: existence and properties of interface prototype object+Pass PasswordCredential interface: existence and properties of interface prototype object's "constructor" property+Pass PasswordCredential interface: existence and properties of interface prototype object's @@unscopables property+Pass PasswordCredential interface: attribute password+Pass PasswordCredential interface: attribute name+Pass PasswordCredential interface: attribute iconURL+Pass PasswordCredential must be primary interface of passwordCredential+Pass Stringification of passwordCredential+Pass PasswordCredential interface: passwordCredential must inherit property "password" with the proper type+Pass PasswordCredential interface: passwordCredential must inherit property "name" with the proper type+Pass PasswordCredential interface: passwordCredential must inherit property "iconURL" with the proper type+Pass Credential interface: passwordCredential must inherit property "id" with the proper type+Pass Credential interface: passwordCredential must inherit property "type" with the proper type+Pass Credential interface: passwordCredential must inherit property "isConditionalMediationAvailable()" with the proper type+Pass FederatedCredential interface: existence and properties of interface object+Pass FederatedCredential interface object length+Pass FederatedCredential interface object name+Pass FederatedCredential interface: existence and properties of interface prototype object+Pass FederatedCredential interface: existence and properties of interface prototype object's "constructor" property+Pass FederatedCredential interface: existence and properties of interface prototype object's @@unscopables property+Pass FederatedCredential interface: attribute provider+Pass FederatedCredential interface: attribute protocol+Pass FederatedCredential interface: attribute name+Pass FederatedCredential interface: attribute iconURL+Pass FederatedCredential must be primary interface of federatedCredential+Pass Stringification of federatedCredential+Pass FederatedCredential interface: federatedCredential must inherit property "provider" with the proper type+Pass FederatedCredential interface: federatedCredential must inherit property "protocol" with the proper type+Pass FederatedCredential interface: federatedCredential must inherit property "name" with the proper type+Pass FederatedCredential interface: federatedCredential must inherit property "iconURL" with the proper type+Pass Credential interface: federatedCredential must inherit property "id" with the proper type+Pass Credential interface: federatedCredential must inherit property "type" with the proper type+Pass Credential interface: federatedCredential must inherit property "isConditionalMediationAvailable()" with the proper type+Pass Navigator interface: attribute credentials\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/credential-management/historical.https.html b/Tests/LibWeb/Text/input/wpt-import/credential-management/historical.https.htmlnew file mode 100644index 00000000000..2722a5c7527--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/credential-management/historical.https.html@@ -0,0 +1,11 @@+<!doctype html>+<meta charset=utf-8>+<title>Credential Management historical tests</title>+<link rel="help" href="https://github.com/w3c/webappsec-credential-management/pull/282">+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script>+test(() => {+ assert_false("willRequestConditionalCreation" in Credential);+}, "Credential.willRequestConditionalCreation should not exist");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/credential-management/idlharness.https.window.html b/Tests/LibWeb/Text/input/wpt-import/credential-management/idlharness.https.window.htmlnew file mode 100644index 00000000000..24b4c406d64--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/credential-management/idlharness.https.window.html@@ -0,0 +1,9 @@+<!doctype html>+<meta charset=utf-8>+<meta name="timeout" content="long">+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script src="../resources/WebIDLParser.js"></script>+<script src="../resources/idlharness.js"></script>+<div id=log></div>+<script src="../credential-management/idlharness.https.window.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/credential-management/idlharness.https.window.js b/Tests/LibWeb/Text/input/wpt-import/credential-management/idlharness.https.window.jsnew file mode 100644index 00000000000..26d7c493b04--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/credential-management/idlharness.https.window.js@@ -0,0 +1,37 @@+// META: script=/resources/WebIDLParser.js+// META: script=/resources/idlharness.js+// META: timeout=long++// https://w3c.github.io/webappsec-credential-management/++'use strict';++idl_test(+ ['credential-management'],+ ['html', 'dom'],+ idl_array => {+ idl_array.add_objects({+ CredentialsContainer: ['navigator.credentials'],+ PasswordCredential: ['passwordCredential'],+ FederatedCredential: ['federatedCredential'],+ });++ try {+ self.passwordCredential = new PasswordCredential({+ id: "id",+ password: "pencil",+ iconURL: "https://example.com/",+ name: "name"+ });+ } catch (e) {}++ try {+ self.federatedCredential = new FederatedCredential({+ id: "id",+ provider: "https://example.com",+ iconURL: "https://example.com/",+ name: "name"+ });+ } catch (e) {}+ }+)diff --git a/Tests/LibWeb/Text/input/wpt-import/interfaces/credential-management.idl b/Tests/LibWeb/Text/input/wpt-import/interfaces/credential-management.idlnew file mode 100644index 00000000000..1684f1d0233--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/interfaces/credential-management.idl@@ -0,0 +1,111 @@+// GENERATED CONTENT - DO NOT EDIT+// Content was automatically extracted by Reffy into webref+// (https://github.com/w3c/webref)+// Source: Credential Management Level 1 (https://w3c.github.io/webappsec-credential-management/)++[Exposed=Window, SecureContext]+interface Credential {+ readonly attribute USVString id;+ readonly attribute DOMString type;+ static Promise<boolean> isConditionalMediationAvailable();+};++[SecureContext]+interface mixin CredentialUserData {+ readonly attribute USVString name;+ readonly attribute USVString iconURL;+};++partial interface Navigator {+ [SecureContext, SameObject] readonly attribute CredentialsContainer credentials;+};++[Exposed=Window, SecureContext]+interface CredentialsContainer {+ Promise<Credential?> get(optional CredentialRequestOptions options = {});+ Promise<undefined> store(Credential credential);+ Promise<Credential?> create(optional CredentialCreationOptions options = {});+ Promise<undefined> preventSilentAccess();+};++dictionary CredentialData {+ required USVString id;+};++dictionary CredentialRequestOptions {+ CredentialMediationRequirement mediation = "optional";+ DOMString uiMode;+ AbortSignal signal;+};++enum CredentialMediationRequirement {+ "silent",+ "optional",+ "conditional",+ "required"+};++enum CredentialUiMode {+ "immediate"+};++dictionary CredentialCreationOptions {+ CredentialMediationRequirement mediation = "optional";+ AbortSignal signal;+};++[Exposed=Window,+ SecureContext]+interface PasswordCredential : Credential {+ constructor(HTMLFormElement form);+ constructor(PasswordCredentialData data);+ readonly attribute USVString password;+};+PasswordCredential includes CredentialUserData;++partial dictionary CredentialRequestOptions {+ boolean password = false;+};++dictionary PasswordCredentialData : CredentialData {+ USVString name;+ USVString iconURL;+ required USVString origin;+ required USVString password;+};++typedef (PasswordCredentialData or HTMLFormElement) PasswordCredentialInit;++partial dictionary CredentialCreationOptions {+ PasswordCredentialInit password;+};++[Exposed=Window,+ SecureContext]+interface FederatedCredential : Credential {+ constructor(FederatedCredentialInit data);+ readonly attribute USVString provider;+ readonly attribute DOMString? protocol;+};+FederatedCredential includes CredentialUserData;++dictionary FederatedCredentialRequestOptions {+ sequence<USVString> providers;+ sequence<DOMString> protocols;+};++partial dictionary CredentialRequestOptions {+ FederatedCredentialRequestOptions federated;+};++dictionary FederatedCredentialInit : CredentialData {+ USVString name;+ USVString iconURL;+ required USVString origin;+ required USVString provider;+ DOMString protocol;+};++partial dictionary CredentialCreationOptions {+ FederatedCredentialInit federated;+};