Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

1.9 KB
Raw Blame
use super::super::super::{
    document,
    node::{node_runtime_and_handle_from_args, node_runtime_and_handle_from_args_or_detached},
    throw_dom_exception,
};
use super::super::is_disabled_form_control;
use super::default_action::{
    activate_handle_via_synthetic_click, perform_file_chooser_default_action,
};

pub(in crate::native_bridge) fn node_click_callback<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    args: v8::FunctionCallbackArguments<'s>,
    mut rv: v8::ReturnValue<'_, v8::Value>,
) {
    let Ok((runtime_ptr, handle)) = node_runtime_and_handle_from_args(scope, &args) else {
        document::detached_click_method_callback(scope, args, rv);
        return;
    };
    let outcome = activate_handle_via_synthetic_click(scope, runtime_ptr, handle, 0.0, 0.0, 0, 0);
    if let Some(download) = outcome.pending_download {
        unsafe { &mut *runtime_ptr }.record_pending_download_activation(download);
    }
    if let Some(file_chooser) = outcome.pending_file_chooser {
        unsafe { &mut *runtime_ptr }.record_pending_file_chooser_activation(file_chooser);
    }
    rv.set_undefined();
}

pub(in crate::native_bridge) fn input_show_picker_callback(
    scope: &mut v8::PinScope<'_, '_>,
    args: v8::FunctionCallbackArguments<'_>,
    mut rv: v8::ReturnValue<'_, v8::Value>,
) {
    let Ok((runtime_ptr, handle)) = node_runtime_and_handle_from_args_or_detached(scope, &args)
    else {
        rv.set_undefined();
        return;
    };
    let runtime = unsafe { &*runtime_ptr };
    if is_disabled_form_control(runtime, handle) {
        throw_dom_exception(
            scope,
            "InvalidStateError",
            11,
            "showPicker() cannot be used on disabled controls.",
        );
        return;
    }
    if let Some(file_chooser) = perform_file_chooser_default_action(scope, runtime_ptr, handle) {
        unsafe { &mut *runtime_ptr }.record_pending_file_chooser_activation(file_chooser);
    }
    rv.set_undefined();
}