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
Expand Up @@ -1205,6 +1205,8 @@ struct webscene_engine final {
void* resource_load_v3_user_data_{nullptr};
webscene_resource_load_callback_v4 resource_load_callback_v4_{nullptr};
void* resource_load_v4_user_data_{nullptr};
webscene_resource_load_callback_v5 resource_load_callback_v5_{nullptr};
void* resource_load_v5_user_data_{nullptr};
webscene_stylesheet_consumed_callback stylesheet_consumed_callback_{nullptr};
void* stylesheet_consumed_user_data_{nullptr};
webscene_webgpu_policy_callback webgpu_policy_callback_{nullptr};
Expand Down Expand Up @@ -1785,6 +1787,11 @@ webscene_engine* webscene_engine_create_with_options(const webscene_engine_optio
+ sizeof(uint64_t);
const auto has_storage_options = options->struct_size
>= storage_options_size;
constexpr auto resource_callback_v5_options_size =
offsetof(webscene_engine_options, resource_load_v5_user_data)
+ sizeof(void*);
const auto has_resource_callback_v5 = options->struct_size
>= resource_callback_v5_options_size;
if (has_storage_options && options->storage_directory != nullptr
&& options->storage_directory_length > 0U) {
storage_directory.assign(
Expand All @@ -1811,6 +1818,8 @@ webscene_engine* webscene_engine_create_with_options(const webscene_engine_optio
has_resource_callback_v3 ? options->resource_load_v3_user_data : nullptr,
has_resource_callback_v4 ? options->resource_load_callback_v4 : nullptr,
has_resource_callback_v4 ? options->resource_load_v4_user_data : nullptr,
has_resource_callback_v5 ? options->resource_load_callback_v5 : nullptr,
has_resource_callback_v5 ? options->resource_load_v5_user_data : nullptr,
has_scene_published_callback ? options->scene_published_callback : nullptr,
has_scene_published_callback ? options->scene_published_user_data : nullptr,
has_text_measure_callback ? options->text_measure_callback : nullptr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,45 @@ typedef size_t (*webscene_resource_load_callback_v4)(
char* destination,
size_t destination_capacity);

/* v5 preserves the bounded author request-header list that accompanies fetch.
* Header buffers are borrowed only for the callback invocation. Cookie,
* Origin and Referer remain available through their dedicated fields so hosts
* can apply transport policy without reconstructing browser-owned metadata. */
typedef struct webscene_resource_request_context_v5 {
uint32_t struct_size;
uint32_t initiator;
const char* origin;
size_t origin_length;
const char* referrer;
size_t referrer_length;
uint32_t mode;
uint32_t destination;
const char* method;
size_t method_length;
const char* body;
size_t body_length;
const char* content_type;
size_t content_type_length;
uint32_t credentials;
const char* cookie;
size_t cookie_length;
const webscene_resource_header_v4* headers;
size_t header_count;
} webscene_resource_request_context_v5;

typedef size_t (*webscene_resource_load_callback_v5)(
void* user_data,
uint32_t kind,
const char* url,
size_t url_length,
const char* entity_tag,
size_t entity_tag_length,
int64_t last_modified_unix_seconds,
const webscene_resource_request_context_v5* request_context,
webscene_resource_response_v4* response,
char* destination,
size_t destination_capacity);

/*
* Asynchronous notification emitted after an immutable scene has been
* published. Consumers use this edge to schedule a compositor paint; they
Expand Down Expand Up @@ -1495,6 +1534,8 @@ typedef struct webscene_engine_options {
const char* storage_partition_key;
size_t storage_partition_key_length;
uint64_t storage_quota_bytes;
webscene_resource_load_callback_v5 resource_load_callback_v5;
void* resource_load_v5_user_data;
} webscene_engine_options;

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
void* resource_load_v3_user_data = nullptr,
webscene_resource_load_callback_v4 resource_load_callback_v4 = nullptr,
void* resource_load_v4_user_data = nullptr,
webscene_resource_load_callback_v5 resource_load_callback_v5 = nullptr,
void* resource_load_v5_user_data = nullptr,
webscene_scene_published_callback scene_published_callback = nullptr,
void* scene_published_user_data = nullptr,
webscene_text_measure_callback text_measure_callback = nullptr,
Expand Down Expand Up @@ -46,6 +48,8 @@
, resource_load_v3_user_data_(resource_load_v3_user_data)
, resource_load_callback_v4_(resource_load_callback_v4)
, resource_load_v4_user_data_(resource_load_v4_user_data)
, resource_load_callback_v5_(resource_load_callback_v5)
, resource_load_v5_user_data_(resource_load_v5_user_data)
, stylesheet_consumed_callback_(stylesheet_consumed_callback)
, stylesheet_consumed_user_data_(stylesheet_consumed_user_data)
, webgpu_policy_callback_(webgpu_policy_callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
const std::string& entity_tag,
int64_t last_modified_unix_seconds,
webscene_native::v8_dom_runtime::resource_response& response) {
if (resource_load_callback_v4_ == nullptr
if (resource_load_callback_v5_ == nullptr
&& resource_load_callback_v4_ == nullptr
&& resource_load_callback_v3_ == nullptr
&& resource_load_callback_v2_ == nullptr
&& resource_load_callback_ == nullptr) return false;
Expand Down Expand Up @@ -159,11 +160,44 @@
request_context.credentials,
request_context.cookie.data(),
request_context.cookie.size()};
std::vector<webscene_resource_header_v4> native_request_headers;
native_request_headers.reserve(request_context.headers.size());
for (const auto& [name, value] : request_context.headers) {
native_request_headers.push_back(webscene_resource_header_v4{
sizeof(webscene_resource_header_v4),
name.data(), name.size(), value.data(), value.size()});
}
const webscene_resource_request_context_v5 native_context_v5{
sizeof(webscene_resource_request_context_v5),
request_context.initiator,
request_context.origin.data(),
request_context.origin.size(),
request_context.referrer.data(),
request_context.referrer.size(),
request_context.mode,
request_context.destination,
request_context.method.data(),
request_context.method.size(),
request_context.body.data(),
request_context.body.size(),
request_context.content_type.data(),
request_context.content_type.size(),
request_context.credentials,
request_context.cookie.data(),
request_context.cookie.size(),
native_request_headers.data(),
native_request_headers.size()};
webscene_resource_response_v4 native_response{};
const auto invoke = [&](char* destination, size_t capacity) {
native_response = {};
native_response.struct_size = sizeof(native_response);
return resource_load_callback_v4_ != nullptr
return resource_load_callback_v5_ != nullptr
? resource_load_callback_v5_(
resource_load_v5_user_data_, kind, url.data(), url.size(),
entity_tag.data(), entity_tag.size(),
last_modified_unix_seconds, &native_context_v5,
&native_response, destination, capacity)
: resource_load_callback_v4_ != nullptr
? resource_load_callback_v4_(
resource_load_v4_user_data_, kind, url.data(), url.size(),
entity_tag.data(), entity_tag.size(),
Expand Down Expand Up @@ -233,7 +267,8 @@
response.content.assign(
buffer + envelope_header_size + response_tag_length,
required - envelope_header_size - response_tag_length);
if (resource_load_callback_v4_ != nullptr) {
if (resource_load_callback_v5_ != nullptr
|| resource_load_callback_v4_ != nullptr) {
response.has_http_metadata = true;
constexpr size_t maximum_response_headers = 64U;
constexpr size_t maximum_response_metadata_bytes = 64U * 1024U;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,98 @@ void test_response_header_cookie_contracts()
webscene_engine_destroy(engine);
}

struct request_header_v5_server final {
std::mutex mutex;
std::vector<std::pair<std::string, std::string>> headers;
};

size_t load_request_header_resource_v5(
void* user_data,
uint32_t,
const char* url,
size_t url_length,
const char*,
size_t,
int64_t,
const webscene_resource_request_context_v5* context,
webscene_resource_response_v4* response,
char* destination,
size_t destination_capacity)
{
auto& server = *static_cast<request_header_v5_server*>(user_data);
const std::string_view address(url, url_length);
static constexpr std::string_view document = R"HTML(
<!doctype html><script>
globalThis.__requestHeadersDone = false;
fetch('/api', {headers:{
'Accept':'application/json',
'X-CSRF-Token':'csrf-probe'
}}).then(() => globalThis.__requestHeadersDone = true);
</script>)HTML";
static constexpr std::string_view payload{"{}"};
const auto is_api = address.ends_with("/api");
if (is_api && context != nullptr) {
std::lock_guard lock(server.mutex);
server.headers.clear();
for (size_t index = 0U; index < context->header_count; ++index) {
const auto& header = context->headers[index];
server.headers.emplace_back(
std::string(header.name, header.name_length),
std::string(header.value, header.value_length));
}
}
if (response != nullptr) {
response->status = 200U;
response->status_text = "OK";
response->status_text_length = 2U;
response->final_url = url;
response->final_url_length = url_length;
}
const auto body = is_api ? payload : document;
constexpr size_t header_size = 2U + sizeof(uint32_t) + sizeof(int64_t) * 2U;
const auto required = header_size + body.size();
if (destination == nullptr || destination_capacity < required) return required;
std::memset(destination, 0, header_size);
destination[0] = 1;
std::copy(body.begin(), body.end(), destination + header_size);
return required;
}

void test_request_headers_reach_resource_callback_v5()
{
request_header_v5_server server;
webscene_engine_options options{};
options.struct_size = sizeof(options);
options.resource_load_callback_v5 = load_request_header_resource_v5;
options.resource_load_v5_user_data = &server;
auto* engine = webscene_engine_create_with_options(&options);
require(engine != nullptr, "request-header v5 engine creation failed");
constexpr std::string_view address{"https://auth.test/index.html"};
require(webscene_engine_load_url(engine, address.data(), address.size()) != 0U,
"request-header v5 navigation failed");
for (auto attempt = 0; attempt < 500; ++attempt) {
if (evaluate(engine, "globalThis.__requestHeadersDone === true",
"request-header-v5-state.js") == "true") break;
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
require(
evaluate(engine, "globalThis.__requestHeadersDone === true",
"request-header-v5-result.js") == "true",
"request-header v5 fetch did not complete");
{
std::lock_guard lock(server.mutex);
const auto has_header = [&](std::string_view name, std::string_view value) {
return std::ranges::any_of(server.headers, [&](const auto& header) {
return header.first == name && header.second == value;
});
};
require(has_header("accept", "application/json")
&& has_header("x-csrf-token", "csrf-probe"),
"author request headers did not reach resource callback v5");
}
webscene_engine_destroy(engine);
}

struct durable_profile_server final {
std::atomic<uint32_t> phase{1U};
std::mutex mutex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ int main()
if (selected == "response-header-cookie") {
test_response_header_cookie_contracts();
test_durable_profile_restart_contract();
test_request_headers_reach_resource_callback_v5();
test_parallel_resource_prefetch();
test_fetch_carries_document_origin_to_resource_host();
test_tradingview_save_acknowledgement_uses_multipart_post();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ self.addEventListener('fetch', event => {
const range = event.request.headers.get('range');
const validator = event.request.headers.get('if-none-match');
const token = event.request.headers.get('x-broker-token');
const csrf = event.request.headers.get('x-csrf-token');
observations.push({path:url.pathname, method:event.request.method,
range, validator, token});
range, validator, token, csrf});
if (url.pathname.endsWith('/range')) {
event.respondWith(new Response('2345', {status:206, headers:{
'content-type':'application/octet-stream',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

const head = await fetch('head', {method:'HEAD'});
const method = await fetch('method', {
method:'POST', headers:{'X-Broker-Token':'method-token'}, body:'payload'
method:'POST', headers:{
'X-Broker-Token':'method-token', 'X-CSRF-Token':'csrf-probe'
}, body:'payload'
});
record('HEAD and rejected methods preserve method and empty-body semantics',
head.status === 200 && await head.text() === ''
Expand Down Expand Up @@ -72,7 +74,8 @@
&& observed('conditional')?.validator === '"cache-v1"'
&& observed('head')?.method === 'HEAD'
&& observed('method')?.method === 'POST'
&& observed('method')?.token === 'method-token',
&& observed('method')?.token === 'method-token'
&& observed('method')?.csrf === 'csrf-probe',
JSON.stringify(report));
state.diagnostics.push(`bulk32MiB=${bulkDuration.toFixed(3)}ms`);
await registration.unregister();
Expand Down
4 changes: 2 additions & 2 deletions tests/WebPlatformSubset/webscene-component-profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -2653,9 +2653,9 @@
{
"path": "contracts/service-worker-range-cache-broker.html",
"type": "contract",
"capabilities": ["service-worker-request-headers", "service-worker-range-response", "service-worker-conditional-response", "service-worker-aggregate-body-budget"],
"capabilities": ["service-worker-request-headers", "csrf-request-header-preservation", "service-worker-range-response", "service-worker-conditional-response", "service-worker-aggregate-body-budget"],
"evidence": ["fetch-request-headers-derived", "service-workers-fetch-event-derived", "chromium-153-direct-neutral-contract", "vscode-oss-webview-range-cache-broker"],
"reason": "Candidate range/cache broker slice for WebScene #266. It preserves bounded page-authored Request headers through controlled FetchEvent dispatch so the unchanged Code OSS broker can observe Range and cache validators, while retaining status, MIME, ETag, Last-Modified, Content-Range, HEAD, and method-rejection semantics. The native companion gate adds a 64 MiB aggregate queued response-body budget over the existing 32-fetch cap, 100 warm 64 KiB requests at p95 <= 100 ms, 32 concurrent 1 MiB responses, malformed-header closure, <= 8 MiB retained V8 heap, and bounded peak RSS. Host message streaming, local-resource admission, localhost mapping, abort/timeout, and exact unchanged Markdown remain cumulative work.",
"reason": "Candidate range/cache broker slice for WebScene #266. It preserves bounded page-authored Request headers, including CSRF tokens, through controlled FetchEvent dispatch so application authentication and the unchanged Code OSS broker can observe custom headers, Range, and cache validators, while retaining status, MIME, ETag, Last-Modified, Content-Range, HEAD, and method-rejection semantics. The native companion gates expose the same bounded header list to v5 host resource callbacks and add a 64 MiB aggregate queued response-body budget over the existing 32-fetch cap, 100 warm 64 KiB requests at p95 <= 100 ms, 32 concurrent 1 MiB responses, malformed-header closure, <= 8 MiB retained V8 heap, and bounded peak RSS. Host message streaming, local-resource admission, localhost mapping, abort/timeout, and exact unchanged Markdown remain cumulative work.",
"nativeNavigation": true
},
{
Expand Down
Loading