@vibesdotdev/host-cef 0.0.0-stage → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -0
- package/README.md +101 -2
- package/dist/cef-environment.impl.d.ts +58 -0
- package/dist/cef-environment.impl.d.ts.map +1 -0
- package/dist/cef-environment.impl.js +117 -0
- package/dist/cef-environment.impl.js.map +1 -0
- package/dist/contracts.d.ts +65 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +235 -0
- package/dist/contracts.js.map +1 -0
- package/dist/docs/plugin.d.ts +10 -0
- package/dist/docs/plugin.d.ts.map +1 -0
- package/dist/docs/plugin.js +17 -0
- package/dist/docs/plugin.js.map +1 -0
- package/dist/docs/runtime-environment-cef.docs.descriptor.d.ts +20 -0
- package/dist/docs/runtime-environment-cef.docs.descriptor.d.ts.map +1 -0
- package/dist/docs/runtime-environment-cef.docs.descriptor.js +174 -0
- package/dist/docs/runtime-environment-cef.docs.descriptor.js.map +1 -0
- package/dist/environment.d.ts +11 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +10 -0
- package/dist/environment.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/native-host.client.d.ts +15 -0
- package/dist/native-host.client.d.ts.map +1 -0
- package/dist/native-host.client.descriptor.d.ts +27 -0
- package/dist/native-host.client.descriptor.d.ts.map +1 -0
- package/dist/native-host.client.descriptor.js +8 -0
- package/dist/native-host.client.descriptor.js.map +1 -0
- package/dist/native-host.client.impl.browser.d.ts +24 -0
- package/dist/native-host.client.impl.browser.d.ts.map +1 -0
- package/dist/native-host.client.impl.browser.js +279 -0
- package/dist/native-host.client.impl.browser.js.map +1 -0
- package/dist/native-host.client.js +5 -0
- package/dist/native-host.client.js.map +1 -0
- package/dist/native-host.plugin.d.ts +5 -0
- package/dist/native-host.plugin.d.ts.map +1 -0
- package/dist/native-host.plugin.js +15 -0
- package/dist/native-host.plugin.js.map +1 -0
- package/dist/runtime-environment-cef.plugin.d.ts +14 -0
- package/dist/runtime-environment-cef.plugin.d.ts.map +1 -0
- package/dist/runtime-environment-cef.plugin.js +31 -0
- package/dist/runtime-environment-cef.plugin.js.map +1 -0
- package/dist/schemas/facts.d.ts +48 -0
- package/dist/schemas/facts.d.ts.map +1 -0
- package/dist/schemas/facts.js +35 -0
- package/dist/schemas/facts.js.map +1 -0
- package/dist/schemas/failure.d.ts +17 -0
- package/dist/schemas/failure.d.ts.map +1 -0
- package/dist/schemas/failure.js +7 -0
- package/dist/schemas/failure.js.map +1 -0
- package/dist/schemas/namespace.d.ts +56 -0
- package/dist/schemas/namespace.d.ts.map +1 -0
- package/dist/schemas/namespace.js +32 -0
- package/dist/schemas/namespace.js.map +1 -0
- package/dist/schemas/native-host.d.ts +43 -0
- package/dist/schemas/native-host.d.ts.map +1 -0
- package/dist/schemas/native-host.js +55 -0
- package/dist/schemas/native-host.js.map +1 -0
- package/dist/schemas/options.d.ts +88 -0
- package/dist/schemas/options.d.ts.map +1 -0
- package/dist/schemas/options.js +22 -0
- package/dist/schemas/options.js.map +1 -0
- package/dist/schemas/readiness.d.ts +10 -0
- package/dist/schemas/readiness.d.ts.map +1 -0
- package/dist/schemas/readiness.js +11 -0
- package/dist/schemas/readiness.js.map +1 -0
- package/package.json +91 -4
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Docs-only plugin for the CEF runtime environment.
|
|
3
|
+
*
|
|
4
|
+
* Registers the owner `docs/topic` for runtime docs discovery. It does not
|
|
5
|
+
* select or register the environment: that happens before bootstrap through
|
|
6
|
+
* `@vibesdotdev/host-cef/plugin`.
|
|
7
|
+
*/
|
|
8
|
+
import { createRuntimePlugin } from '@vibesdotdev/kernel';
|
|
9
|
+
import runtimeEnvironmentCefDocs from "./runtime-environment-cef.docs.descriptor.js";
|
|
10
|
+
export const runtimeEnvironmentCefDocsPlugin = createRuntimePlugin({
|
|
11
|
+
id: '@vibesdotdev/host-cef/docs',
|
|
12
|
+
name: 'CEF Runtime Environment Docs',
|
|
13
|
+
description: 'Documentation for the CEF renderer runtime environment.',
|
|
14
|
+
descriptors: [runtimeEnvironmentCefDocs]
|
|
15
|
+
});
|
|
16
|
+
export default runtimeEnvironmentCefDocsPlugin;
|
|
17
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/docs/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,yBAAyB,MAAM,8CAA8C,CAAC;AAErF,MAAM,CAAC,MAAM,+BAA+B,GAAG,mBAAmB,CAAC;IAClE,EAAE,EAAE,4BAA4B;IAChC,IAAI,EAAE,8BAA8B;IACpC,WAAW,EAAE,yDAAyD;IACtE,WAAW,EAAE,CAAC,yBAAyB,CAAC;CACxC,CAAC,CAAC;AAEH,eAAe,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Owner-authored `docs/topic` for the CEF renderer runtime environment. */
|
|
2
|
+
declare const descriptor: {
|
|
3
|
+
kind: "docs/topic";
|
|
4
|
+
id: string;
|
|
5
|
+
parent: string;
|
|
6
|
+
order: number;
|
|
7
|
+
title: string;
|
|
8
|
+
summary: string;
|
|
9
|
+
tags: string[];
|
|
10
|
+
surfaces: readonly ["cli", "web", "in-app"];
|
|
11
|
+
hardware: readonly ["consumer"];
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
body: {
|
|
14
|
+
type: "markdown";
|
|
15
|
+
sourceType: "raw";
|
|
16
|
+
source: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export default descriptor;
|
|
20
|
+
//# sourceMappingURL=runtime-environment-cef.docs.descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-environment-cef.docs.descriptor.d.ts","sourceRoot":"","sources":["../../src/docs/runtime-environment-cef.docs.descriptor.ts"],"names":[],"mappings":"AAAA,4EAA4E;AA6J5E,QAAA,MAAM,UAAU;;;;;;;;;;;;;;;;CAgBf,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/** Owner-authored `docs/topic` for the CEF renderer runtime environment. */
|
|
2
|
+
const source = `---
|
|
3
|
+
title: CEF Runtime Environment
|
|
4
|
+
summary: Credential-dark runtime environment for a native-attested CEF renderer
|
|
5
|
+
tags: [runtime, environment, cef, browser, desktop]
|
|
6
|
+
parent: runtime
|
|
7
|
+
order: 6
|
|
8
|
+
id: runtime.environment.cef
|
|
9
|
+
surfaces: [cli, web, in-app]
|
|
10
|
+
hardware: [consumer]
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# CEF Runtime Environment
|
|
14
|
+
|
|
15
|
+
\`@vibesdotdev/host-cef\` registers a CEF renderer as the local
|
|
16
|
+
\`runtime/environment\`. The native host attests renderer facts; this package
|
|
17
|
+
parses them strictly and turns them into runtime scope. It never exposes daemon
|
|
18
|
+
endpoints, socket paths, credentials, undeclared environment values or filesystem paths.
|
|
19
|
+
|
|
20
|
+
## Select it before bootstrap
|
|
21
|
+
|
|
22
|
+
The environment must register before core bootstrap so its scope facts take
|
|
23
|
+
part in discovery and candidate selection:
|
|
24
|
+
|
|
25
|
+
\`\`\`ts
|
|
26
|
+
import { ensureBrowserRuntime } from '@vibesdotdev/surface-sveltekit/surface-browser';
|
|
27
|
+
import { createRuntimeEnvironmentCefPlugin } from '@vibesdotdev/host-cef/plugin';
|
|
28
|
+
|
|
29
|
+
await ensureBrowserRuntime({
|
|
30
|
+
environment: async () => createRuntimeEnvironmentCefPlugin(),
|
|
31
|
+
plugins: [() => import('@vibesdotdev/kernel/client/plugin')]
|
|
32
|
+
});
|
|
33
|
+
\`\`\`
|
|
34
|
+
|
|
35
|
+
Registering it as an ordinary feature plugin after bootstrap is a bug: its facts
|
|
36
|
+
would not affect selection.
|
|
37
|
+
|
|
38
|
+
## Host contract
|
|
39
|
+
|
|
40
|
+
The plugin reads facts with one call, \`namespace.call('environment')\`, on the
|
|
41
|
+
generic native namespace the host injects at \`globalThis.vibes.runtime\`. The
|
|
42
|
+
host marks the page synchronously at document start
|
|
43
|
+
(\`globalThis.__vibesNativeHost = 'cef'\`) and fires
|
|
44
|
+
\`vibes:runtime-host-ready\` once the namespace is installed, so the plugin
|
|
45
|
+
uses a namespace that is already there at once and otherwise waits for that
|
|
46
|
+
event instead of polling. Pass \`namespace\` to supply it explicitly. Replies
|
|
47
|
+
cross the host's JSON IPC.
|
|
48
|
+
|
|
49
|
+
| Fact | Type |
|
|
50
|
+
|---|---|
|
|
51
|
+
| \`protocol\` | \`{ major: 1, minor }\` |
|
|
52
|
+
| \`renderer\` | \`{ windowId, frameId, generation, origin }\` |
|
|
53
|
+
| \`lifecycle\` | \`{ phase: 'loading' \\| 'ready' \\| 'closing', generation }\` |
|
|
54
|
+
| \`trustedOrigin\` | non-empty string |
|
|
55
|
+
| \`platform\` | \`'macos' \\| 'linux' \\| 'windows' \\| 'unknown'\` |
|
|
56
|
+
| \`environmentTier\` | \`'local' \\| 'staging' \\| 'production'\` |
|
|
57
|
+
| \`dev\` | boolean: the host runs a development build |
|
|
58
|
+
| \`channelReady\` | boolean |
|
|
59
|
+
| \`env\` | declared \`PUBLIC_*\` values the host captured once at launch; served by \`getEnv\`/\`getEnvSnapshot\` |
|
|
60
|
+
| \`capabilities\` | up to 256 semantic runtime kind ids, never native method names |
|
|
61
|
+
|
|
62
|
+
Every object, including the nested \`protocol\`, \`renderer\` and \`lifecycle\`,
|
|
63
|
+
is strict. An unknown key such as \`renderer.token\` or \`protocol.endpoint\`
|
|
64
|
+
fails the parse.
|
|
65
|
+
|
|
66
|
+
## Host clock
|
|
67
|
+
|
|
68
|
+
The environment supplies the host monotonic clock the kernel's lifecycle
|
|
69
|
+
requires: live milliseconds from the renderer's browser performance clock
|
|
70
|
+
(\`performance.now()\`, captured once at construction so readings cannot drift
|
|
71
|
+
to another clock — never \`Date.now()\`). \`runtime.lifecycle.now()\` and
|
|
72
|
+
disposal's finalization budget read it; the kernel validates the readings
|
|
73
|
+
(finite, nonnegative, nondecreasing) and owns every lifecycle refusal. The
|
|
74
|
+
page's own \`performance\` object is kept: \`performance.now\` is a browser
|
|
75
|
+
interface operation that requires its original receiver, so the captured
|
|
76
|
+
clock is never read off a copied object. A page whose \`performance\` global is missing,
|
|
77
|
+
unreadable or has no callable \`now\` refuses
|
|
78
|
+
\`UNAVAILABLE / host-unavailable\` at construction.
|
|
79
|
+
|
|
80
|
+
## Runtime bindings
|
|
81
|
+
|
|
82
|
+
The environment serves two values through the reader's owning schema:
|
|
83
|
+
\`cef/runtime-namespace\` is the original native namespace with its receivers;
|
|
84
|
+
\`cef/runtime-capabilities\` is the advertised semantic kind ids, available even
|
|
85
|
+
without a namespace. An absent namespace or unknown binding key returns
|
|
86
|
+
\`undefined\`. Reader-schema mismatches refuse
|
|
87
|
+
\`INVALID_INPUT / binding-invalid\`. \`@vibesdotdev/kernel-rpc/cef\`
|
|
88
|
+
consumes both bindings through the runtime, without reading page globals.
|
|
89
|
+
|
|
90
|
+
## Resulting scope
|
|
91
|
+
|
|
92
|
+
- \`surface: 'browser'\`, \`hardware: 'consumer'\`, \`purpose: 'direct'\`,
|
|
93
|
+
\`lifecycle: 'persistent'\`
|
|
94
|
+
- \`hosting: { mode: 'local', owner: 'consumer', venue: 'user-device' }\`
|
|
95
|
+
- no credential capability: the advertised ids stay host facts, and a renderer
|
|
96
|
+
has one actor (a single-principal invocation store), so
|
|
97
|
+
\`requestPrincipal()\` fails \`principal-source-undeclared\`
|
|
98
|
+
- \`qualifiers\`: \`dev\`, \`cef: true\`, \`os\` (the platform),
|
|
99
|
+
\`environmentTier\`, \`trustedOrigin\`, \`rendererGeneration\`
|
|
100
|
+
|
|
101
|
+
Config reads the \`environmentTier\` qualifier to pick the deployment
|
|
102
|
+
environment. \`getEnv()\`/\`getEnvSnapshot()\` serve only the declared \`PUBLIC_*\` values the host captured at launch (every other key is \`undefined\`), and there is no secret accessor: credentials resolve through \`runtime.resolveCredential\`, which answers \`no-store\` here.
|
|
103
|
+
|
|
104
|
+
## Native host client
|
|
105
|
+
|
|
106
|
+
\`@vibesdotdev/host-cef/native-host/plugin\` registers \`cefNativeHostPlugin\`,
|
|
107
|
+
the browser-scoped \`runtime/client\` \`host-cef\`; resolve it with
|
|
108
|
+
\`getVibesClient(runtime, 'host-cef')\` and type it as the abstract
|
|
109
|
+
\`CefNativeHostClient\`. It offers \`ready\`, \`call\`, \`emit\`, \`subscribe\` and
|
|
110
|
+
\`subscribeLegacy\` over the own-property-only \`bridge\` and \`vibes\` globals.
|
|
111
|
+
\`subscribeLegacy\` forwards \`bridge.onMessage\` and restores the original
|
|
112
|
+
descriptor when the last listener leaves. Subscriptions and pending calls are
|
|
113
|
+
released when the runtime is disposed.
|
|
114
|
+
|
|
115
|
+
\`awaitCefRuntimeNamespace({ signal, lifecycle })\` also accepts an abort signal
|
|
116
|
+
and a runtime lifecycle, and resolves on either \`vibes:runtime-host-ready\` or
|
|
117
|
+
the legacy \`bridgeReady\` event.
|
|
118
|
+
|
|
119
|
+
| Condition | Result |
|
|
120
|
+
|---|---|
|
|
121
|
+
| native member absent or inherited | \`UNAVAILABLE / cef-native-unavailable\` |
|
|
122
|
+
| malformed native address, payload or member | \`INVALID_INPUT / cef-native-invalid\` |
|
|
123
|
+
| wait or call aborted | \`CANCELLED / wait-aborted\`, \`details.cause\` \`caller-aborted\` (caller \`signal\`) or \`runtime-disposed\` (runtime or caller \`lifecycle\`) |
|
|
124
|
+
|
|
125
|
+
\`call()\` rejects with the native function's own rejection unchanged; only
|
|
126
|
+
boundary or member failures become \`cef-native-*\` refusals. Caught boundary
|
|
127
|
+
failures appear only as \`details.failure.name\`, narrowed to a fixed
|
|
128
|
+
class-name category.
|
|
129
|
+
|
|
130
|
+
## Failures
|
|
131
|
+
|
|
132
|
+
| Condition | Result | Remedy |
|
|
133
|
+
|---|---|---|
|
|
134
|
+
| the page carries no native host marker | \`CapabilityError\` \`UNAVAILABLE\` \`host-unavailable\`, at once | Load the renderer inside the Vibes CEF host, or pass \`namespace\` |
|
|
135
|
+
| the ready event fires without an installed namespace | \`UNAVAILABLE\` \`host-unavailable\` | Fix the native host's injection order |
|
|
136
|
+
| invalid or unreadable facts | \`INVALID_INPUT / cef-host-facts-invalid\` | Repair the strict host payload |
|
|
137
|
+
| failed native environment call | \`UNAVAILABLE / cef-host-facts-unavailable\` | Restore the native channel |
|
|
138
|
+
| unreadable globals or failed event registration | \`UNAVAILABLE / host-unavailable\` | Repair native injection |
|
|
139
|
+
| unreadable renderer performance clock | \`UNAVAILABLE\` \`host-unavailable\`, at construction | Repair the page so its \`performance\` global is readable |
|
|
140
|
+
| invalid constructor or plugin options | \`INVALID_INPUT / cef-environment-options-invalid\` | Supply a callable namespace and workspace root of 1–4096 characters |
|
|
141
|
+
|
|
142
|
+
Host and options failures are typed, value-free refusals: fixed messages, bounded
|
|
143
|
+
issue counts or fixed failure categories, without input values or raw causes.
|
|
144
|
+
Compose \`@vibesdotdev/docs/plugin\` with this package's \`./docs/plugin\`
|
|
145
|
+
to contribute this topic without selecting or registering a CEF environment.
|
|
146
|
+
|
|
147
|
+
There is no timer, poll or optional mode: a build that selects this
|
|
148
|
+
environment requires the CEF host.
|
|
149
|
+
|
|
150
|
+
## Path mechanics
|
|
151
|
+
|
|
152
|
+
This environment deliberately does not implement \`paths/runtime-path\`. A
|
|
153
|
+
renderer has no host filesystem authority, and that contract exposes
|
|
154
|
+
\`homedir()\` and \`tmpdir()\`.
|
|
155
|
+
`;
|
|
156
|
+
const descriptor = {
|
|
157
|
+
kind: 'docs/topic',
|
|
158
|
+
id: 'runtime.environment.cef',
|
|
159
|
+
parent: 'runtime',
|
|
160
|
+
order: 6,
|
|
161
|
+
title: 'CEF Runtime Environment',
|
|
162
|
+
summary: 'Credential-dark runtime environment for a native-attested CEF renderer',
|
|
163
|
+
tags: ['runtime', 'environment', 'cef', 'browser', 'desktop'],
|
|
164
|
+
surfaces: ['cli', 'web', 'in-app'],
|
|
165
|
+
hardware: ['consumer'],
|
|
166
|
+
enabled: true,
|
|
167
|
+
body: {
|
|
168
|
+
type: 'markdown',
|
|
169
|
+
sourceType: 'raw',
|
|
170
|
+
source
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
export default descriptor;
|
|
174
|
+
//# sourceMappingURL=runtime-environment-cef.docs.descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-environment-cef.docs.descriptor.js","sourceRoot":"","sources":["../../src/docs/runtime-environment-cef.docs.descriptor.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyJd,CAAC;AAEF,MAAM,UAAU,GAAG;IAClB,IAAI,EAAE,YAAqB;IAC3B,EAAE,EAAE,yBAAyB;IAC7B,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,yBAAyB;IAChC,OAAO,EAAE,wEAAwE;IACjF,IAAI,EAAE,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC;IAC7D,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAU;IAC3C,QAAQ,EAAE,CAAC,UAAU,CAAU;IAC/B,OAAO,EAAE,IAAI;IACb,IAAI,EAAE;QACL,IAAI,EAAE,UAAmB;QACzB,UAAU,EAAE,KAAc;QAC1B,MAAM;KACN;CACD,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Direct construction of the concrete CEF environment implementation.
|
|
3
|
+
*
|
|
4
|
+
* Normal composition goes through `./plugin` or `runtime/environment`
|
|
5
|
+
* resolution; this explicit entrypoint exists for hosts and tests that
|
|
6
|
+
* construct `CefEnvironment` themselves (with or without a namespace).
|
|
7
|
+
* The root barrel deliberately does not export the implementation class.
|
|
8
|
+
*/
|
|
9
|
+
export { CefEnvironment } from './cef-environment.impl.ts';
|
|
10
|
+
export type { CefEnvironmentDeclaration } from './schemas/options.ts';
|
|
11
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,YAAY,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Direct construction of the concrete CEF environment implementation.
|
|
3
|
+
*
|
|
4
|
+
* Normal composition goes through `./plugin` or `runtime/environment`
|
|
5
|
+
* resolution; this explicit entrypoint exists for hosts and tests that
|
|
6
|
+
* construct `CefEnvironment` themselves (with or without a namespace).
|
|
7
|
+
* The root barrel deliberately does not export the implementation class.
|
|
8
|
+
*/
|
|
9
|
+
export { CefEnvironment } from "./cef-environment.impl.js";
|
|
10
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CEF_ENVIRONMENT_OPTIONS_INVALID, CEF_RUNTIME_CAPABILITIES_BINDING, CEF_RUNTIME_NAMESPACE_BINDING, CefHostFactsSchema, CefHostLifecycleSchema, getGlobalCefRuntimeNamespace, readCefHostFacts, awaitCefRuntimeNamespace, NATIVE_HOST_MARKER, NATIVE_HOST_READY_EVENT, type CefHostFacts, type CefHostLifecycle, type CefRuntimeNamespace } from './contracts.ts';
|
|
2
|
+
export type { CefEnvironmentDeclaration } from './schemas/options.ts';
|
|
3
|
+
export { createRuntimeEnvironmentCefPlugin, runtimeEnvironmentCefPlugin, type RuntimeEnvironmentCefPluginOptions } from './runtime-environment-cef.plugin.ts';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,+BAA+B,EAC/B,gCAAgC,EAChC,6BAA6B,EAC7B,kBAAkB,EAClB,sBAAsB,EACtB,4BAA4B,EAC5B,gBAAgB,EAChB,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,EACvB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EACN,iCAAiC,EACjC,2BAA2B,EAC3B,KAAK,kCAAkC,EACvC,MAAM,qCAAqC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { CEF_ENVIRONMENT_OPTIONS_INVALID, CEF_RUNTIME_CAPABILITIES_BINDING, CEF_RUNTIME_NAMESPACE_BINDING, CefHostFactsSchema, CefHostLifecycleSchema, getGlobalCefRuntimeNamespace, readCefHostFacts, awaitCefRuntimeNamespace, NATIVE_HOST_MARKER, NATIVE_HOST_READY_EVENT } from "./contracts.js";
|
|
2
|
+
export { createRuntimeEnvironmentCefPlugin, runtimeEnvironmentCefPlugin } from "./runtime-environment-cef.plugin.js";
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,+BAA+B,EAC/B,gCAAgC,EAChC,6BAA6B,EAC7B,kBAAkB,EAClB,sBAAsB,EACtB,4BAA4B,EAC5B,gBAAgB,EAChB,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,EAIvB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,iCAAiC,EACjC,2BAA2B,EAE3B,MAAM,qCAAqC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseRuntimeClient } from '@vibesdotdev/kernel/client';
|
|
2
|
+
import type { VibesRuntime } from '@vibesdotdev/kernel';
|
|
3
|
+
import type { JsonValue } from '@vibesdotdev/kernel/schemas/json';
|
|
4
|
+
import type { CefNativeCall, CefNativeEvent, CefNativeListener, CefLegacyListener } from './schemas/native-host.ts';
|
|
5
|
+
import type { CefRuntimeNamespace } from './schemas/namespace.ts';
|
|
6
|
+
import type { CefReadinessOptions } from './schemas/readiness.ts';
|
|
7
|
+
/** Semantic native mechanism; resolve 'host-cef' through kernel/client. Domain replies belong to their owners. */
|
|
8
|
+
export declare abstract class CefNativeHostClient extends BaseRuntimeClient<VibesRuntime> {
|
|
9
|
+
abstract ready(options?: CefReadinessOptions): Promise<CefRuntimeNamespace>;
|
|
10
|
+
abstract call(input: CefNativeCall, options?: CefReadinessOptions): Promise<JsonValue>;
|
|
11
|
+
abstract emit(input: CefNativeCall): void;
|
|
12
|
+
abstract subscribe(input: CefNativeEvent, listener: CefNativeListener): () => void;
|
|
13
|
+
abstract subscribeLegacy(listener: CefLegacyListener): () => void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=native-host.client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-host.client.d.ts","sourceRoot":"","sources":["../src/native-host.client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACpH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE,kHAAkH;AAClH,8BAAsB,mBAAoB,SAAQ,iBAAiB,CAAC,YAAY,CAAC;IAChF,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAC3E,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,SAAS,CAAC;IACtF,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IACzC,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,iBAAiB,GAAG,MAAM,IAAI;IAClF,QAAQ,CAAC,eAAe,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,IAAI;CACjE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
id: string;
|
|
3
|
+
kind: "runtime/client";
|
|
4
|
+
name?: string | undefined;
|
|
5
|
+
tags?: string[] | undefined;
|
|
6
|
+
hardware?: string[] | undefined;
|
|
7
|
+
enabled?: boolean | undefined;
|
|
8
|
+
priority?: number | undefined;
|
|
9
|
+
capabilityId?: string | undefined;
|
|
10
|
+
requiredContext?: string[] | undefined;
|
|
11
|
+
optionalContext?: string[] | undefined;
|
|
12
|
+
config?: unknown;
|
|
13
|
+
retention?: string | {
|
|
14
|
+
reason: string;
|
|
15
|
+
maxAgeDays?: number | undefined;
|
|
16
|
+
maxEntries?: number | undefined;
|
|
17
|
+
maxBytes?: number | undefined;
|
|
18
|
+
cascadeFrom?: string | undefined;
|
|
19
|
+
ageField?: string | undefined;
|
|
20
|
+
enforcedBy?: string | undefined;
|
|
21
|
+
} | undefined;
|
|
22
|
+
configManifestId?: string | undefined;
|
|
23
|
+
baseUrl?: string | undefined;
|
|
24
|
+
description?: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
export default _default;
|
|
27
|
+
//# sourceMappingURL=native-host.client.descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-host.client.descriptor.d.ts","sourceRoot":"","sources":["../src/native-host.client.descriptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wBAKG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RuntimeClientDescriptorSchema } from '@vibesdotdev/kernel/client';
|
|
2
|
+
export default RuntimeClientDescriptorSchema.parse({
|
|
3
|
+
id: 'host-cef',
|
|
4
|
+
kind: 'runtime/client',
|
|
5
|
+
surfaces: ['browser'],
|
|
6
|
+
description: 'Lifecycle-owned CEF native calls, events and compatibility messages.'
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=native-host.client.descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-host.client.descriptor.js","sourceRoot":"","sources":["../src/native-host.client.descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAE3E,eAAe,6BAA6B,CAAC,KAAK,CAAC;IAClD,EAAE,EAAE,UAAU;IACd,IAAI,EAAE,gBAAgB;IACtB,QAAQ,EAAE,CAAC,SAAS,CAAC;IACrB,WAAW,EAAE,sEAAsE;CACnF,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type JsonValue } from '@vibesdotdev/kernel/schemas/json';
|
|
2
|
+
import { CefNativeHostClient } from './native-host.client.ts';
|
|
3
|
+
import { type CefReadinessOptions } from './schemas/readiness.ts';
|
|
4
|
+
import { type CefNativeCall, type CefNativeEvent, type CefNativeListener, type CefLegacyListener } from './schemas/native-host.ts';
|
|
5
|
+
export default class CefNativeHostBrowserClient extends CefNativeHostClient {
|
|
6
|
+
private closed;
|
|
7
|
+
private readonly cleanups;
|
|
8
|
+
private readonly legacy;
|
|
9
|
+
private detachLegacy?;
|
|
10
|
+
private assertLive;
|
|
11
|
+
/** A caller lifecycle is lifecycle, like the runtime's own: only the caller's plain signal is `caller-aborted`. */
|
|
12
|
+
private cancelled;
|
|
13
|
+
ready(options?: CefReadinessOptions): Promise<{
|
|
14
|
+
call: (method: string, args?: JsonValue) => Promise<JsonValue>;
|
|
15
|
+
subscribe?: ((event: string, listener: (value: JsonValue) => void) => () => void) | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
call(input: CefNativeCall, optionsInput?: CefReadinessOptions): Promise<JsonValue>;
|
|
18
|
+
emit(input: CefNativeCall): void;
|
|
19
|
+
private own;
|
|
20
|
+
subscribe(input: CefNativeEvent, listenerInput: CefNativeListener): () => void;
|
|
21
|
+
subscribeLegacy(listenerInput: CefLegacyListener): () => void;
|
|
22
|
+
protected onDispose(): void;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=native-host.client.impl.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-host.client.impl.browser.d.ts","sourceRoot":"","sources":["../src/native-host.client.impl.browser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EAA6B,KAAK,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7F,OAAO,EAKiB,KAAK,aAAa,EAAE,KAAK,cAAc,EAC9D,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAC9C,MAAM,0BAA0B,CAAC;AA8DlC,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,mBAAmB;IAC1E,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAClD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IACvD,OAAO,CAAC,YAAY,CAAC,CAAa;IAElC,OAAO,CAAC,UAAU;IAIlB,mHAAmH;IACnH,OAAO,CAAC,SAAS;IAQjB,KAAK,CAAC,OAAO,GAAE,mBAAwB;;;;IAUjC,IAAI,CAAC,KAAK,EAAE,aAAa,EAAE,YAAY,GAAE,mBAAwB,GAAG,OAAO,CAAC,SAAS,CAAC;IAoD5F,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAOhC,OAAO,CAAC,GAAG;IAiBX,SAAS,CAAC,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,iBAAiB,GAAG,MAAM,IAAI;IAkB9E,eAAe,CAAC,aAAa,EAAE,iBAAiB,GAAG,MAAM,IAAI;cA+C1C,SAAS,IAAI,IAAI;CASpC"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { CapabilityError, settle, settleNow } from '@vibesdotdev/kernel';
|
|
2
|
+
import { JsonValueSchema } from '@vibesdotdev/kernel/schemas/json';
|
|
3
|
+
import { CefNativeHostClient } from "./native-host.client.js";
|
|
4
|
+
import { awaitCefRuntimeNamespace, failureFacts, readCefInput } from "./contracts.js";
|
|
5
|
+
import { CefReadinessOptionsSchema } from "./schemas/readiness.js";
|
|
6
|
+
import { CefNativeAddressSchema, CefNativeCallSchema, CefNativeEventSchema, CefNativeNameSchema, CefNativeListenerSchema, CefLegacyListenerSchema, CefNativeObjectSchema, CefNativeFunctionSchema, CefNativeEmitSchema, CefNativeSubscribeSchema, CefNativeDisposeSchema, CefNativePayloadSchema } from "./schemas/native-host.js";
|
|
7
|
+
function refusal(reason, failure) {
|
|
8
|
+
return new CapabilityError('The CEF native capability could not be used.', reason === 'cef-native-invalid' ? 'INVALID_INPUT' : 'UNAVAILABLE', {
|
|
9
|
+
reason, retryable: false,
|
|
10
|
+
details: failure ? failureFacts(failure) : undefined
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Read an own member of a native holder. Getters run with their holder as
|
|
15
|
+
* receiver, matching ordinary property access; callers parse the result
|
|
16
|
+
* through the owning schema before using it.
|
|
17
|
+
*/
|
|
18
|
+
function member(object, name) {
|
|
19
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, name);
|
|
20
|
+
const getter = descriptor?.get;
|
|
21
|
+
if (getter !== undefined)
|
|
22
|
+
return getter.call(object);
|
|
23
|
+
return descriptor?.value;
|
|
24
|
+
}
|
|
25
|
+
/** Resolve only injected own properties; never grant inherited or fallback authority. */
|
|
26
|
+
function target(input) {
|
|
27
|
+
const address = readCefInput(CefNativeAddressSchema, input);
|
|
28
|
+
const result = settleNow(() => {
|
|
29
|
+
let current = CefNativeObjectSchema.parse(globalThis);
|
|
30
|
+
for (const part of [address.scope, ...(address.namespace?.split('.') ?? [])]) {
|
|
31
|
+
if (!Object.hasOwn(current, part))
|
|
32
|
+
throw refusal('cef-native-unavailable');
|
|
33
|
+
const next = member(current, part);
|
|
34
|
+
if (next === undefined)
|
|
35
|
+
throw refusal('cef-native-unavailable');
|
|
36
|
+
const parsed = CefNativeObjectSchema.safeParse(next);
|
|
37
|
+
if (!parsed.success)
|
|
38
|
+
throw refusal('cef-native-invalid');
|
|
39
|
+
current = parsed.data;
|
|
40
|
+
}
|
|
41
|
+
return current;
|
|
42
|
+
});
|
|
43
|
+
if (result.ok)
|
|
44
|
+
return result.value;
|
|
45
|
+
if (result.cause instanceof CapabilityError)
|
|
46
|
+
throw result.cause;
|
|
47
|
+
throw refusal('cef-native-invalid', result.cause);
|
|
48
|
+
}
|
|
49
|
+
function method(object, name, schema) {
|
|
50
|
+
const result = settleNow(() => {
|
|
51
|
+
if (!Object.hasOwn(object, name))
|
|
52
|
+
throw refusal('cef-native-unavailable');
|
|
53
|
+
const value = member(object, name);
|
|
54
|
+
if (value === undefined)
|
|
55
|
+
throw refusal('cef-native-unavailable');
|
|
56
|
+
const parsed = schema.safeParse(value);
|
|
57
|
+
if (!parsed.success)
|
|
58
|
+
throw refusal('cef-native-invalid');
|
|
59
|
+
return parsed.data;
|
|
60
|
+
});
|
|
61
|
+
if (result.ok)
|
|
62
|
+
return result.value;
|
|
63
|
+
if (result.cause instanceof CapabilityError)
|
|
64
|
+
throw result.cause;
|
|
65
|
+
throw refusal('cef-native-invalid', result.cause);
|
|
66
|
+
}
|
|
67
|
+
function payload(value, serialized = false) {
|
|
68
|
+
const result = settleNow(() => (serialized ? CefNativePayloadSchema : JsonValueSchema).safeParse(value));
|
|
69
|
+
if (!result.ok)
|
|
70
|
+
throw refusal('cef-native-invalid', result.cause);
|
|
71
|
+
if (!result.value.success)
|
|
72
|
+
throw refusal('cef-native-invalid', result.value.error);
|
|
73
|
+
return result.value.data;
|
|
74
|
+
}
|
|
75
|
+
export default class CefNativeHostBrowserClient extends CefNativeHostClient {
|
|
76
|
+
closed = false;
|
|
77
|
+
cleanups = new Set();
|
|
78
|
+
legacy = new Set();
|
|
79
|
+
detachLegacy;
|
|
80
|
+
assertLive() {
|
|
81
|
+
if (this.closed || this.runtime.lifecycle.signal.aborted)
|
|
82
|
+
throw this.cancelled();
|
|
83
|
+
}
|
|
84
|
+
/** A caller lifecycle is lifecycle, like the runtime's own: only the caller's plain signal is `caller-aborted`. */
|
|
85
|
+
cancelled(lifecycle) {
|
|
86
|
+
const disposed = this.closed || this.runtime.lifecycle.signal.aborted || lifecycle?.aborted === true;
|
|
87
|
+
return new CapabilityError('The CEF native operation was cancelled.', 'CANCELLED', {
|
|
88
|
+
reason: 'wait-aborted', retryable: false,
|
|
89
|
+
details: { cause: disposed ? 'runtime-disposed' : 'caller-aborted' }
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
ready(options = {}) {
|
|
93
|
+
this.assertLive();
|
|
94
|
+
const parsed = readCefInput(CefReadinessOptionsSchema, options);
|
|
95
|
+
const lifecycle = [this.runtime.lifecycle.signal, parsed.lifecycle?.signal].filter((signal) => signal !== undefined);
|
|
96
|
+
return awaitCefRuntimeNamespace({
|
|
97
|
+
signal: parsed.signal,
|
|
98
|
+
lifecycle: { signal: AbortSignal.any(lifecycle) }
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async call(input, optionsInput = {}) {
|
|
102
|
+
this.assertLive();
|
|
103
|
+
const request = readCefInput(CefNativeCallSchema, input);
|
|
104
|
+
const options = readCefInput(CefReadinessOptionsSchema, optionsInput);
|
|
105
|
+
const signals = [options.signal, options.lifecycle?.signal, this.runtime.lifecycle.signal]
|
|
106
|
+
.filter((signal) => signal !== undefined);
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
let settled = false;
|
|
109
|
+
const cleanup = () => {
|
|
110
|
+
this.cleanups.delete(abort);
|
|
111
|
+
const failures = [];
|
|
112
|
+
for (const signal of signals) {
|
|
113
|
+
const result = settleNow(() => signal.removeEventListener('abort', abort));
|
|
114
|
+
if (!result.ok)
|
|
115
|
+
failures.push(result.cause);
|
|
116
|
+
}
|
|
117
|
+
return failures;
|
|
118
|
+
};
|
|
119
|
+
const finish = (result) => {
|
|
120
|
+
if (settled)
|
|
121
|
+
return;
|
|
122
|
+
settled = true;
|
|
123
|
+
const failures = cleanup();
|
|
124
|
+
if ('failure' in result) {
|
|
125
|
+
// Preserve admission rejection identity, including non-Error throws.
|
|
126
|
+
reject(result.failure instanceof Error ? result.failure : result.failure.value);
|
|
127
|
+
}
|
|
128
|
+
else if (failures.length)
|
|
129
|
+
reject(refusal('cef-native-invalid', failures[0]));
|
|
130
|
+
else
|
|
131
|
+
resolve(result.value);
|
|
132
|
+
};
|
|
133
|
+
const abort = () => finish({ failure: this.cancelled(options.lifecycle?.signal) });
|
|
134
|
+
this.cleanups.add(abort);
|
|
135
|
+
const registration = settleNow(() => {
|
|
136
|
+
for (const signal of signals) {
|
|
137
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
138
|
+
if (settled)
|
|
139
|
+
signal.removeEventListener('abort', abort);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
if (!registration.ok) {
|
|
143
|
+
finish({ failure: refusal('cef-native-invalid', registration.cause) });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (signals.some((signal) => signal.aborted)) {
|
|
147
|
+
abort();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
void settle(async () => {
|
|
151
|
+
if (settled)
|
|
152
|
+
return null;
|
|
153
|
+
const receiver = target(request);
|
|
154
|
+
const call = method(receiver, 'call', CefNativeFunctionSchema);
|
|
155
|
+
return payload(await call.call(receiver, request.method, request.args));
|
|
156
|
+
}).then((result) => {
|
|
157
|
+
if (result.ok)
|
|
158
|
+
finish({ value: result.value });
|
|
159
|
+
else
|
|
160
|
+
finish({ failure: result.cause });
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
emit(input) {
|
|
165
|
+
this.assertLive();
|
|
166
|
+
const request = readCefInput(CefNativeCallSchema, input);
|
|
167
|
+
const receiver = target(request);
|
|
168
|
+
method(receiver, 'emit', CefNativeEmitSchema).call(receiver, request.method, request.args);
|
|
169
|
+
}
|
|
170
|
+
own(dispose) {
|
|
171
|
+
let active = true;
|
|
172
|
+
const cleanup = () => {
|
|
173
|
+
if (!active)
|
|
174
|
+
return;
|
|
175
|
+
active = false;
|
|
176
|
+
this.cleanups.delete(cleanup);
|
|
177
|
+
const detached = settleNow(() => this.runtime.lifecycle.signal.removeEventListener('abort', cleanup));
|
|
178
|
+
const disposed = settleNow(dispose);
|
|
179
|
+
if (!disposed.ok)
|
|
180
|
+
throw refusal('cef-native-invalid', disposed.cause);
|
|
181
|
+
if (!detached.ok)
|
|
182
|
+
throw refusal('cef-native-invalid', detached.cause);
|
|
183
|
+
};
|
|
184
|
+
this.cleanups.add(cleanup);
|
|
185
|
+
this.runtime.lifecycle.signal.addEventListener('abort', cleanup, { once: true });
|
|
186
|
+
if (this.runtime.lifecycle.signal.aborted)
|
|
187
|
+
cleanup();
|
|
188
|
+
return cleanup;
|
|
189
|
+
}
|
|
190
|
+
subscribe(input, listenerInput) {
|
|
191
|
+
this.assertLive();
|
|
192
|
+
const request = readCefInput(CefNativeEventSchema, input);
|
|
193
|
+
const listener = readCefInput(CefNativeListenerSchema, listenerInput);
|
|
194
|
+
const receiver = target(request);
|
|
195
|
+
let active = true;
|
|
196
|
+
const unsubscribe = method(receiver, 'subscribe', CefNativeSubscribeSchema).call(receiver, request.event, (value) => {
|
|
197
|
+
const decoded = payload(value, true);
|
|
198
|
+
if (active && !this.runtime.lifecycle.signal.aborted)
|
|
199
|
+
listener(decoded);
|
|
200
|
+
});
|
|
201
|
+
const parsed = CefNativeDisposeSchema.safeParse(unsubscribe);
|
|
202
|
+
if (!parsed.success) {
|
|
203
|
+
active = false;
|
|
204
|
+
throw refusal('cef-native-invalid', parsed.error);
|
|
205
|
+
}
|
|
206
|
+
return this.own(() => {
|
|
207
|
+
active = false;
|
|
208
|
+
parsed.data();
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
subscribeLegacy(listenerInput) {
|
|
212
|
+
this.assertLive();
|
|
213
|
+
const listener = readCefInput(CefLegacyListenerSchema, listenerInput);
|
|
214
|
+
const bridge = target({ scope: 'bridge', namespace: null });
|
|
215
|
+
if (!this.detachLegacy) {
|
|
216
|
+
const capture = settleNow(() => {
|
|
217
|
+
const original = Object.getOwnPropertyDescriptor(bridge, 'onMessage');
|
|
218
|
+
const previous = member(bridge, 'onMessage');
|
|
219
|
+
return { original, previous };
|
|
220
|
+
});
|
|
221
|
+
if (!capture.ok)
|
|
222
|
+
throw refusal('cef-native-invalid', capture.cause);
|
|
223
|
+
const { original, previous } = capture.value;
|
|
224
|
+
const callback = CefLegacyListenerSchema.optional().safeParse(previous);
|
|
225
|
+
if (!callback.success)
|
|
226
|
+
throw refusal('cef-native-invalid', callback.error);
|
|
227
|
+
const forward = (name, value) => {
|
|
228
|
+
const messageName = CefNativeNameSchema.parse(name);
|
|
229
|
+
const decoded = payload(value, true);
|
|
230
|
+
const failures = [];
|
|
231
|
+
if (callback.data) {
|
|
232
|
+
const result = settleNow(() => callback.data?.call(bridge, messageName, value));
|
|
233
|
+
if (!result.ok)
|
|
234
|
+
failures.push(result.cause);
|
|
235
|
+
}
|
|
236
|
+
for (const handler of this.legacy) {
|
|
237
|
+
const result = settleNow(() => handler(messageName, decoded));
|
|
238
|
+
if (!result.ok)
|
|
239
|
+
failures.push(result.cause);
|
|
240
|
+
}
|
|
241
|
+
if (failures.length)
|
|
242
|
+
throw refusal('cef-native-invalid', new AggregateError(failures));
|
|
243
|
+
};
|
|
244
|
+
const installed = settleNow(() => {
|
|
245
|
+
if (!Reflect.set(bridge, 'onMessage', forward))
|
|
246
|
+
throw refusal('cef-native-invalid');
|
|
247
|
+
});
|
|
248
|
+
if (!installed.ok)
|
|
249
|
+
throw refusal('cef-native-invalid', installed.cause);
|
|
250
|
+
this.detachLegacy = () => {
|
|
251
|
+
if (member(bridge, 'onMessage') === forward) {
|
|
252
|
+
if (original)
|
|
253
|
+
Object.defineProperty(bridge, 'onMessage', original);
|
|
254
|
+
else if (!Reflect.deleteProperty(bridge, 'onMessage'))
|
|
255
|
+
throw refusal('cef-native-invalid');
|
|
256
|
+
}
|
|
257
|
+
this.detachLegacy = undefined;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
this.legacy.add(listener);
|
|
261
|
+
return this.own(() => {
|
|
262
|
+
this.legacy.delete(listener);
|
|
263
|
+
if (!this.legacy.size)
|
|
264
|
+
this.detachLegacy?.();
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
onDispose() {
|
|
268
|
+
this.closed = true;
|
|
269
|
+
const failures = [];
|
|
270
|
+
for (const cleanup of this.cleanups) {
|
|
271
|
+
const result = settleNow(cleanup);
|
|
272
|
+
if (!result.ok)
|
|
273
|
+
failures.push(result.cause);
|
|
274
|
+
}
|
|
275
|
+
if (failures.length)
|
|
276
|
+
throw refusal('cef-native-invalid', new AggregateError(failures));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=native-host.client.impl.browser.js.map
|