#include "third_party/blink/renderer/modules/smart_card/smart_card_connection.h"
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
#include "third_party/blink/renderer/bindings/core/v8/script_function.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_smart_card_connection_status.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_smart_card_disposition.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_smart_card_protocol.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_smart_card_transaction_callback.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_smart_card_transaction_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_smart_card_transmit_options.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/modules/smart_card/smart_card_cancel_algorithm.h"
#include "third_party/blink/renderer/modules/smart_card/smart_card_context.h"
#include "third_party/blink/renderer/modules/smart_card/smart_card_error.h"
#include "third_party/blink/renderer/modules/smart_card/smart_card_util.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_associated_remote.h"
namespace blink {
namespace {
constexpr char kDisconnected[] = …;
constexpr char kTransactionAlreadyExists[] = …;
constexpr char kTransactionEndedWithPendingOperation[] = …;
SmartCardConnectionState;
SmartCardDisposition;
SmartCardProtocol;
SmartCardStatusPtr;
SmartCardDisposition ToMojomDisposition(
const V8SmartCardDisposition& disposition) { … }
device::mojom::blink::SmartCardProtocol ToMojoSmartCardProtocol(
const V8SmartCardProtocol& protocol) { … }
std::optional<V8SmartCardConnectionState::Enum> ToV8ConnectionState(
SmartCardConnectionState state,
SmartCardProtocol protocol) { … }
class TransactionFulfilledFunction : public ScriptFunction::Callable { … };
class TransactionRejectedFunction : public ScriptFunction::Callable { … };
}
class SmartCardConnection::TransactionState final
: public GarbageCollected<TransactionState> { … };
SmartCardConnection::TransactionState::~TransactionState() = default;
SmartCardConnection::TransactionState::TransactionState(
ScriptPromiseResolver<IDLUndefined>* start_transaction_request,
mojo::PendingAssociatedRemote<device::mojom::blink::SmartCardTransaction>
pending_remote,
ExecutionContext* execution_context)
: … { … }
void SmartCardConnection::TransactionState::Trace(Visitor* visitor) const { … }
void SmartCardConnection::TransactionState::SetCallbackException(
DOMExceptionCode code,
const String& message) { … }
void SmartCardConnection::TransactionState::SetCallbackException(
const ScriptValue& exception) { … }
void SmartCardConnection::TransactionState::SettleStartTransaction(
device::mojom::blink::SmartCardResultPtr end_transaction_result) { … }
void SmartCardConnection::TransactionState::RejectStartTransaction(
DOMExceptionCode exception_code,
const String& message) { … }
bool SmartCardConnection::TransactionState::HasPendingEnd() const { … }
void SmartCardConnection::TransactionState::SetPendingEnd(
SmartCardDisposition disposition) { … }
SmartCardDisposition SmartCardConnection::TransactionState::TakePendingEnd() { … }
void SmartCardConnection::TransactionState::EndTransaction(
SmartCardDisposition disposition,
base::OnceCallback<void(device::mojom::blink::SmartCardResultPtr)>
callback) { … }
SmartCardConnection::SmartCardConnection(
mojo::PendingRemote<device::mojom::blink::SmartCardConnection>
pending_connection,
device::mojom::blink::SmartCardProtocol active_protocol,
SmartCardContext* smart_card_context,
ExecutionContext* execution_context)
: … { … }
ScriptPromise<IDLUndefined> SmartCardConnection::disconnect(
ScriptState* script_state,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> SmartCardConnection::disconnect(
ScriptState* script_state,
const V8SmartCardDisposition& disposition,
ExceptionState& exception_state) { … }
ScriptPromise<DOMArrayBuffer> SmartCardConnection::transmit(
ScriptState* script_state,
const DOMArrayPiece& send_buffer,
SmartCardTransmitOptions* options,
ExceptionState& exception_state) { … }
ScriptPromise<SmartCardConnectionStatus> SmartCardConnection::status(
ScriptState* script_state,
ExceptionState& exception_state) { … }
ScriptPromise<DOMArrayBuffer> SmartCardConnection::control(
ScriptState* script_state,
uint32_t control_code,
const DOMArrayPiece& data,
ExceptionState& exception_state) { … }
ScriptPromise<DOMArrayBuffer> SmartCardConnection::getAttribute(
ScriptState* script_state,
uint32_t tag,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> SmartCardConnection::setAttribute(
ScriptState* script_state,
uint32_t tag,
const DOMArrayPiece& data,
ExceptionState& exception_state) { … }
ScriptPromise<IDLUndefined> SmartCardConnection::startTransaction(
ScriptState* script_state,
V8SmartCardTransactionCallback* transaction_callback,
SmartCardTransactionOptions* options,
ExceptionState& exception_state) { … }
void SmartCardConnection::OnOperationInProgressCleared() { … }
void SmartCardConnection::OnTransactionCallbackDone(
SmartCardDisposition disposition) { … }
void SmartCardConnection::OnTransactionCallbackFailed(
const ScriptValue& exception) { … }
void SmartCardConnection::Trace(Visitor* visitor) const { … }
void SmartCardConnection::SetOperationInProgress(
ScriptPromiseResolverBase* resolver) { … }
void SmartCardConnection::ClearOperationInProgress(
ScriptPromiseResolverBase* resolver) { … }
bool SmartCardConnection::EnsureConnection(
ExceptionState& exception_state) const { … }
void SmartCardConnection::OnDisconnectDone(
ScriptPromiseResolver<IDLUndefined>* resolver,
device::mojom::blink::SmartCardResultPtr result) { … }
void SmartCardConnection::OnPlainResult(
ScriptPromiseResolver<IDLUndefined>* resolver,
device::mojom::blink::SmartCardResultPtr result) { … }
void SmartCardConnection::OnDataResult(
ScriptPromiseResolver<DOMArrayBuffer>* resolver,
device::mojom::blink::SmartCardDataResultPtr result) { … }
void SmartCardConnection::OnStatusDone(
ScriptPromiseResolver<SmartCardConnectionStatus>* resolver,
device::mojom::blink::SmartCardStatusResultPtr result) { … }
void SmartCardConnection::OnBeginTransactionDone(
ScriptPromiseResolver<IDLUndefined>* resolver,
V8SmartCardTransactionCallback* transaction_callback,
AbortSignal* signal,
AbortSignal::AlgorithmHandle* abort_handle,
device::mojom::blink::SmartCardTransactionResultPtr result) { … }
void SmartCardConnection::OnEndTransactionDone(
device::mojom::blink::SmartCardResultPtr end_transaction_result) { … }
void SmartCardConnection::CloseMojoConnection() { … }
void SmartCardConnection::EndTransaction(SmartCardDisposition disposition) { … }
}