Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by tools/webidl-v8-bindings/generate.mjs. Do not edit.
// Exposure manifest SHA-256: e0b8a262956eb19c856043f2aca06a86e1f66a198adc4c52bd8ef4879f155c09
// Exposure manifest SHA-256: fdbb9a18487dbd2997d4224fcae8863bb911d901383a14640c4f53087072df97
// Inputs: @webref/idl 3.82.1, webidl2 24.5.0.

enum class generated_dom_interface : uint8_t {
Expand Down Expand Up @@ -3305,6 +3305,12 @@ void install_generated_dom_templates(v8::Local<v8::Context>)
isolate, attach_shadow, v8::Local<v8::Value>(),
generated_Element_signature, 1,
v8::ConstructorBehavior::kThrow));
generated_Element_template->PrototypeTemplate()->Set(
js_string(isolate, "requestFullscreen"),
v8::FunctionTemplate::New(
isolate, element_request_fullscreen, v8::Local<v8::Value>(),
generated_Element_signature, 0,
v8::ConstructorBehavior::kThrow));
element_template.Reset(isolate, generated_Element_template);

auto generated_SVGElement_template = v8::FunctionTemplate::New(isolate, illegal_dom_constructor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ struct webscene_engine final {
std::atomic<bool> low_memory_requested_{false};
std::atomic<bool> host_visible_{true};
std::atomic<bool> visibility_changed_{false};
std::atomic<bool> host_focused_{true};
std::atomic<bool> focus_changed_{false};
std::atomic<bool> host_fullscreen_{false};
std::atomic<bool> fullscreen_changed_{false};
std::atomic<uint32_t> preferred_color_scheme_{
WEBSCENE_PREFERRED_COLOR_SCHEME_LIGHT};
std::atomic<bool> preferred_color_scheme_changed_{false};
Expand Down Expand Up @@ -1291,6 +1295,58 @@ size_t webscene_engine_take_host_request(
: engine->take_host_request(destination, destination_capacity);
}

const webscene_host_request_v1*
webscene_engine_take_typed_host_request_v1(webscene_engine* engine)
{
if (engine == nullptr) return nullptr;
auto request = engine->take_typed_host_request();
if (!request) return nullptr;
request->bind();
return &request.release()->view;
}

void webscene_host_request_release_v1(
const webscene_host_request_v1* request)
{
delete reinterpret_cast<const webscene_native::native_host_request*>(request);
}

uint8_t webscene_engine_discard_host_request_v1(webscene_engine* engine)
{
return engine != nullptr && engine->discard_host_request() ? 1U : 0U;
}

uint8_t webscene_engine_complete_host_request_v1(
webscene_engine* engine,
uint64_t request_id,
uint32_t status,
const char* content_type,
const uint8_t* bytes,
size_t byte_count,
const char* error_message)
{
constexpr size_t maximum_clipboard_bytes = 16U * 1024U * 1024U;
if (engine == nullptr || request_id == 0U || status > 2U
|| byte_count > maximum_clipboard_bytes
|| (byte_count != 0U && bytes == nullptr)) {
return 0U;
}
webscene_native::native_host_completion completion;
completion.id = request_id;
completion.status = status;
completion.content_type = content_type == nullptr ? "" : content_type;
completion.error = error_message == nullptr ? "" : error_message;
if (completion.content_type.size() > 256U || completion.error.size() > 4096U)
return 0U;
if (status == 0U) {
if (byte_count != 0U && completion.content_type.empty()) return 0U;
if (byte_count != 0U) completion.bytes.assign(bytes, bytes + byte_count);
} else if (byte_count != 0U) {
return 0U;
}
return engine->complete_host_request(std::move(completion)) ? 1U : 0U;
}

void webscene_engine_configure_diagnostics(
webscene_engine* engine, uint32_t flags,
webscene_diagnostic_available_callback callback, void* user_data)
Expand Down Expand Up @@ -1416,6 +1472,18 @@ uint8_t webscene_engine_set_visible(webscene_engine* engine, uint8_t visible)
return engine != nullptr && engine->set_visible(visible != 0) ? 1U : 0U;
}

uint8_t webscene_engine_set_window_focused_v1(
webscene_engine* engine, uint8_t focused)
{
return engine != nullptr && engine->set_focused(focused != 0) ? 1U : 0U;
}

uint8_t webscene_engine_set_window_fullscreen_v1(
webscene_engine* engine, uint8_t fullscreen)
{
return engine != nullptr && engine->set_fullscreen(fullscreen != 0) ? 1U : 0U;
}

uint8_t webscene_engine_set_preferred_color_scheme(
webscene_engine* engine,
uint32_t preferred_color_scheme)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ _webscene_engine_request_scene_checkpoint
_webscene_engine_set_resource_root
_webscene_engine_set_preferred_color_scheme
_webscene_engine_set_visible
_webscene_engine_set_window_focused_v1
_webscene_engine_set_window_fullscreen_v1
_webscene_engine_take_console_message
_webscene_engine_take_diagnostic
_webscene_engine_take_host_request
_webscene_engine_take_typed_host_request_v1
_webscene_host_request_release_v1
_webscene_engine_complete_host_request_v1
_webscene_engine_discard_host_request_v1
_webscene_engine_take_input_dispatch_failure
_webscene_engine_take_invoke_result_v3
_webscene_engine_take_callback_v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,14 @@ WEBSCENE_API uint8_t webscene_engine_request_low_memory(webscene_engine* engine)
* worker; returning visible before the deadline cancels it.
*/
WEBSCENE_API uint8_t webscene_engine_set_visible(webscene_engine* engine, uint8_t visible);
/* Publishes native key-window focus to document.hasFocus() and standard
* top-level focus/blur events. Repeated values are coalesced. */
WEBSCENE_API uint8_t webscene_engine_set_window_focused_v1(
webscene_engine* engine, uint8_t focused);
/* Synchronizes fullscreen changes initiated by native window controls. Script
* initiated transitions use the typed request/completion path. */
WEBSCENE_API uint8_t webscene_engine_set_window_fullscreen_v1(
webscene_engine* engine, uint8_t fullscreen);
/*
* Updates the host's effective color preference. The worker re-evaluates CSS
* media rules and subsequent Window.matchMedia snapshots against this value.
Expand Down Expand Up @@ -1366,10 +1374,61 @@ WEBSCENE_API uint8_t webscene_engine_complete_file_request_v1(webscene_engine* e
uint64_t request_id, uint32_t status, const webscene_file_data_v1* files,
size_t file_count, const char* error_message);

/* Typed native desktop request ABI. Request memory is immutable and remains
* valid until release. Byte payloads are capped at 16 MiB, strings are UTF-8,
* and at most 16 completion-bearing operations may be pending per document. */
enum {
WEBSCENE_HOST_REQUEST_OPEN_EXTERNAL_URL_V1 = 1,
WEBSCENE_HOST_REQUEST_CLIPBOARD_READ_V1 = 2,
WEBSCENE_HOST_REQUEST_CLIPBOARD_WRITE_V1 = 3,
WEBSCENE_HOST_REQUEST_WINDOW_FOCUS_V1 = 4,
WEBSCENE_HOST_REQUEST_WINDOW_CLOSE_V1 = 5,
WEBSCENE_HOST_REQUEST_WINDOW_RELOAD_V1 = 6,
WEBSCENE_HOST_REQUEST_FULLSCREEN_ENTER_V1 = 7,
WEBSCENE_HOST_REQUEST_FULLSCREEN_EXIT_V1 = 8
};
enum {
WEBSCENE_HOST_REQUEST_CLIPBOARD_REPLACE_V1 = 1U << 0U
};
typedef struct webscene_host_request_v1 {
uint32_t struct_size, version;
uint64_t request_id;
uint32_t kind, flags;
uint64_t target_node_id;
const char* content_type;
const uint8_t* bytes;
size_t byte_count;
const char* url;
} webscene_host_request_v1;
WEBSCENE_API const webscene_host_request_v1*
webscene_engine_take_typed_host_request_v1(webscene_engine* engine);
WEBSCENE_API void webscene_host_request_release_v1(
const webscene_host_request_v1* request);

/* JSON compatibility queue retained for older host integrations and unrelated
* application-defined messages. New desktop capabilities use the typed ABI. */
WEBSCENE_API size_t webscene_engine_take_host_request(
webscene_engine* engine,
char* destination,
size_t destination_capacity);
/* Consumes the oldest JSON compatibility request without allocating its
* payload. Hosts use this after rejecting an oversized item so one malformed
* request cannot permanently block the FIFO. */
WEBSCENE_API uint8_t webscene_engine_discard_host_request_v1(
webscene_engine* engine);
/* Completes a request carrying a numeric requestId from take_host_request.
* status: 0 completed, 1 cancelled, 2 denied/failed. Inputs are copied before
* return. Clipboard data is limited to 16 MiB, content_type to 256 bytes and
* error_message to 4096 bytes. Completion is delivered on the engine worker;
* stale request IDs are safely ignored there. */
WEBSCENE_API uint8_t webscene_engine_complete_host_request_v1(
webscene_engine* engine,
uint64_t request_id,
uint32_t status,
const char* content_type,
const uint8_t* bytes,
size_t byte_count,
const char* error_message);
/*
* Removes one V8 console entry. The UTF-8 payload is `<level>\n<message>`;
* querying with a null/short destination reports the required byte count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ using script_work_request =
std::variant<
script_request,
webscene_native::native_file_completion,
webscene_native::native_host_completion,
url_request,
interop_evaluate_work_v3,
interop_invoke_work_v3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@
signal_worker();
return true;
}
bool complete_host_request(webscene_native::native_host_completion completion) {
std::lock_guard lock(script_mutex_);
if (script_work_.size() >= 1024) return false;
script_work_.emplace_back(std::move(completion));
signal_worker();
return true;
}
bool discard_host_request() {
#if defined(WEBSCENE_NATIVE_ENGINE_WITH_V8)
std::lock_guard lock(file_runtime_mutex_);
return file_runtime_ready_ && runtime_->discard_host_request();
#else
return false;
#endif
}
void retire_file_runtime() {
#if defined(WEBSCENE_NATIVE_ENGINE_WITH_V8)
std::unique_ptr<webscene_native::v8_dom_runtime> retired;
Expand Down Expand Up @@ -135,6 +150,14 @@
#if defined(WEBSCENE_NATIVE_ENGINE_WITH_V8)
std::lock_guard lock(file_runtime_mutex_);
if (file_runtime_ready_) return runtime_->take_file_request();
#endif
return {};
}
std::unique_ptr<webscene_native::native_host_request>
take_typed_host_request() {
#if defined(WEBSCENE_NATIVE_ENGINE_WITH_V8)
std::lock_guard lock(file_runtime_mutex_);
if (file_runtime_ready_) return runtime_->take_typed_host_request();
#endif
return {};
}
Expand Down Expand Up @@ -220,6 +243,21 @@
return true;
}

bool set_focused(bool focused)
{
host_focused_.store(focused, std::memory_order_release);
focus_changed_.store(true, std::memory_order_release);
signal_worker();
return true;
}
bool set_fullscreen(bool fullscreen)
{
host_fullscreen_.store(fullscreen, std::memory_order_release);
fullscreen_changed_.store(true, std::memory_order_release);
signal_worker();
return true;
}

bool set_preferred_color_scheme(uint32_t preferred_color_scheme)
{
if (preferred_color_scheme != WEBSCENE_PREFERRED_COLOR_SCHEME_LIGHT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,23 @@
+ std::chrono::milliseconds(500);
}
}
if (focus_changed_.exchange(false, std::memory_order_acq_rel)) {
const auto host_focused = host_focused_.load(std::memory_order_acquire);
if (runtime_ != nullptr
&& !runtime_->set_focused(host_focused)) {
script_errors_.fetch_add(1, std::memory_order_relaxed);
set_last_error(runtime_->last_error());
}
}
if (fullscreen_changed_.exchange(false, std::memory_order_acq_rel)) {
const auto host_fullscreen =
host_fullscreen_.load(std::memory_order_acquire);
if (runtime_ != nullptr
&& !runtime_->set_fullscreen(host_fullscreen)) {
script_errors_.fetch_add(1, std::memory_order_relaxed);
set_last_error(runtime_->last_error());
}
}
if (low_memory_requested_.exchange(false, std::memory_order_acq_rel)
&& runtime_ != nullptr) {
runtime_->notify_low_memory();
Expand Down Expand Up @@ -904,6 +921,11 @@
changed = true;
continue;
}
if (auto* host = std::get_if<webscene_native::native_host_completion>(&request)) {
if (runtime_) runtime_->complete_host_request(*host);
changed = true;
continue;
}
#endif
if (auto* url = std::get_if<url_request>(&request)) {
if (url->initial_viewport) apply(*url->initial_viewport);
Expand Down Expand Up @@ -1273,6 +1295,8 @@
|| resize_pending_.load(std::memory_order_acquire)
|| low_memory_requested_.load(std::memory_order_acquire)
|| visibility_changed_.load(std::memory_order_acquire)
|| focus_changed_.load(std::memory_order_acquire)
|| fullscreen_changed_.load(std::memory_order_acquire)
|| preferred_color_scheme_changed_.load(
std::memory_order_acquire);
});
Expand Down
Loading
Loading