Files
ladybird/Libraries/LibWeb/CredentialManagement/FederatedCredentialOperations.cpp
Shannon Booth 5adfd1c43a LibWeb/Bindings: Generate struct definitions from IDL dictionaries
Previously we were inconsistent by generating code for enum definitions
but not generating code for dictionaries. With future changes to the
IDL generator to expose helpers to convert to and from IDL values
this produced circular depdendencies. To solve this problem, also
generate the dictionary definitions in bindings headers.
2026-05-09 10:49:49 +02:00

47 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Copyright (c) 2025, Kenneth Myhra <kennethmyhra@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibURL/Parser.h>
#include <LibWeb/CredentialManagement/FederatedCredentialOperations.h>
namespace Web::CredentialManagement {
// https://www.w3.org/TR/credential-management-1/#abstract-opdef-create-a-federatedcredential-from-federatedcredentialinit
WebIDL::ExceptionOr<GC::Ref<FederatedCredential>> create_federated_credential(JS::Realm& realm, Bindings::FederatedCredentialInit const& init)
{
// 1. Let c be a new FederatedCredential object.
// 2. If any of the following are the empty string, throw a TypeError exception:
// - init.id's value
// - init.provider's value
if (init.id.is_empty())
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "'id' must not be empty."sv };
if (init.provider.is_empty())
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "'provider' must not be empty."sv };
// AD-HOC: Aligning with how Chromium retrieves the origin by parsing the URL from init.provider.
auto url = URL::Parser::basic_parse(init.provider);
if (!url.has_value())
WebIDL::SyntaxError::create(realm, "'provider' is not a valid url."_utf16);
auto origin = url.value().origin();
// 3. Set cs properties as follows:
// - id
// - init.id's value
// - provider
// - init.provider's value
// - iconURL
// - init.iconURL's value
// - name
// - init.name's value
// - [[origin]]
// - init.origin's value.
// NOTE: origin is retrieved by parsing the URL from init.provider.
// 4. Return c.
return realm.create<FederatedCredential>(realm, init, move(origin));
}
}