@native-sdk/cli 0.0.0 → 0.4.0
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 +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +44 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const geometry = @import("geometry");
|
|
3
|
+
const validation = @import("validation.zig");
|
|
4
|
+
const shell_layout = @import("shell_layout.zig");
|
|
5
|
+
const runtime_state = @import("state.zig");
|
|
6
|
+
const runtime_window_storage = @import("window_storage.zig");
|
|
7
|
+
const runtime_window_view_runtime = @import("window_view_runtime.zig");
|
|
8
|
+
const app_manifest = @import("app_manifest");
|
|
9
|
+
const platform = @import("../platform/root.zig");
|
|
10
|
+
|
|
11
|
+
const isMainWebViewLabel = validation.isMainWebViewLabel;
|
|
12
|
+
const RuntimeMainWebViewState = runtime_state.RuntimeMainWebViewState;
|
|
13
|
+
const ShellApplyMode = runtime_state.ShellApplyMode;
|
|
14
|
+
const ShellLayout = shell_layout.ShellLayout;
|
|
15
|
+
const shellRestorePolicy = shell_layout.shellRestorePolicy;
|
|
16
|
+
const shellViewOptions = shell_layout.shellViewOptions;
|
|
17
|
+
|
|
18
|
+
fn copyInto(buffer: []u8, value: []const u8) ![]const u8 {
|
|
19
|
+
if (value.len > buffer.len) return error.NoSpaceLeft;
|
|
20
|
+
@memcpy(buffer[0..value.len], value);
|
|
21
|
+
return buffer[0..value.len];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pub fn RuntimeWindowViews(comptime Runtime: type) type {
|
|
25
|
+
const WindowStorageMethods = runtime_window_storage.RuntimeWindowStorage(Runtime);
|
|
26
|
+
const WindowViewRuntimeMethods = runtime_window_view_runtime.RuntimeWindowViewRuntime(Runtime);
|
|
27
|
+
|
|
28
|
+
return struct {
|
|
29
|
+
const Self = @This();
|
|
30
|
+
|
|
31
|
+
pub const createWindow = WindowStorageMethods.createWindow;
|
|
32
|
+
pub const listWindows = WindowStorageMethods.listWindows;
|
|
33
|
+
pub const focusWindow = WindowStorageMethods.focusWindow;
|
|
34
|
+
pub const createWindowWithSourceMode = WindowStorageMethods.createWindowWithSourceMode;
|
|
35
|
+
pub const reserveWindow = WindowStorageMethods.reserveWindow;
|
|
36
|
+
pub const removeWindowAt = WindowStorageMethods.removeWindowAt;
|
|
37
|
+
pub const copySource = WindowStorageMethods.copySource;
|
|
38
|
+
pub const copyLoadedSource = WindowStorageMethods.copyLoadedSource;
|
|
39
|
+
pub const applyNativeInfo = WindowStorageMethods.applyNativeInfo;
|
|
40
|
+
pub const runtimeWindowStateForPersistence = WindowStorageMethods.runtimeWindowStateForPersistence;
|
|
41
|
+
pub const shellBoundsForWindow = WindowStorageMethods.shellBoundsForWindow;
|
|
42
|
+
pub const startupWindowFrame = WindowStorageMethods.startupWindowFrame;
|
|
43
|
+
pub const rectsEqual = WindowStorageMethods.rectsEqual;
|
|
44
|
+
pub const canvasDirtyRegionForView = WindowStorageMethods.canvasDirtyRegionForView;
|
|
45
|
+
pub const bindShellViews = WindowStorageMethods.bindShellViews;
|
|
46
|
+
pub const shellLayoutForWindow = WindowStorageMethods.shellLayoutForWindow;
|
|
47
|
+
pub const findShellLayoutIndex = WindowStorageMethods.findShellLayoutIndex;
|
|
48
|
+
pub const removeShellLayoutForWindow = WindowStorageMethods.removeShellLayoutForWindow;
|
|
49
|
+
pub const setFocusedIndex = WindowStorageMethods.setFocusedIndex;
|
|
50
|
+
pub const findWindowIndexById = WindowStorageMethods.findWindowIndexById;
|
|
51
|
+
pub const findWindowIndexByLabel = WindowStorageMethods.findWindowIndexByLabel;
|
|
52
|
+
pub const allocateWindowId = WindowStorageMethods.allocateWindowId;
|
|
53
|
+
pub const allocateViewId = WindowStorageMethods.allocateViewId;
|
|
54
|
+
|
|
55
|
+
pub const createView = WindowViewRuntimeMethods.createView;
|
|
56
|
+
pub const updateView = WindowViewRuntimeMethods.updateView;
|
|
57
|
+
pub const closeView = WindowViewRuntimeMethods.closeView;
|
|
58
|
+
pub const listViews = WindowViewRuntimeMethods.listViews;
|
|
59
|
+
pub const focusView = WindowViewRuntimeMethods.focusView;
|
|
60
|
+
pub const adoptViewSurface = WindowViewRuntimeMethods.adoptViewSurface;
|
|
61
|
+
pub const releaseViewSurface = WindowViewRuntimeMethods.releaseViewSurface;
|
|
62
|
+
pub const focusNextView = WindowViewRuntimeMethods.focusNextView;
|
|
63
|
+
pub const focusPreviousView = WindowViewRuntimeMethods.focusPreviousView;
|
|
64
|
+
pub const validateWebViewParent = WindowViewRuntimeMethods.validateWebViewParent;
|
|
65
|
+
pub const validateWebViewUrl = WindowViewRuntimeMethods.validateWebViewUrl;
|
|
66
|
+
pub const writeWebViewListJson = WindowViewRuntimeMethods.writeWebViewListJson;
|
|
67
|
+
pub const reserveWebView = WindowViewRuntimeMethods.reserveWebView;
|
|
68
|
+
pub const findWebViewIndex = WindowViewRuntimeMethods.findWebViewIndex;
|
|
69
|
+
pub const webViewLocalFrame = WindowViewRuntimeMethods.webViewLocalFrame;
|
|
70
|
+
pub const removeWebViewAt = WindowViewRuntimeMethods.removeWebViewAt;
|
|
71
|
+
pub const removeWebViewsForWindow = WindowViewRuntimeMethods.removeWebViewsForWindow;
|
|
72
|
+
pub const mainWebViewInfo = WindowViewRuntimeMethods.mainWebViewInfo;
|
|
73
|
+
pub const createWebViewView = WindowViewRuntimeMethods.createWebViewView;
|
|
74
|
+
pub const setMainWebViewParent = WindowViewRuntimeMethods.setMainWebViewParent;
|
|
75
|
+
pub const updateWebViewView = WindowViewRuntimeMethods.updateWebViewView;
|
|
76
|
+
pub const validateViewParent = WindowViewRuntimeMethods.validateViewParent;
|
|
77
|
+
pub const validateViewParentLink = WindowViewRuntimeMethods.validateViewParentLink;
|
|
78
|
+
pub const platformFrameForView = WindowViewRuntimeMethods.platformFrameForView;
|
|
79
|
+
pub const localFrameForView = WindowViewRuntimeMethods.localFrameForView;
|
|
80
|
+
pub const absoluteViewFrame = WindowViewRuntimeMethods.absoluteViewFrame;
|
|
81
|
+
pub const relayoutDescendantWebViewBackends = WindowViewRuntimeMethods.relayoutDescendantWebViewBackends;
|
|
82
|
+
pub const relayoutDescendantWebViewBackendsDepth = WindowViewRuntimeMethods.relayoutDescendantWebViewBackendsDepth;
|
|
83
|
+
pub const reserveView = WindowViewRuntimeMethods.reserveView;
|
|
84
|
+
pub const findViewIndex = WindowViewRuntimeMethods.findViewIndex;
|
|
85
|
+
pub const commandSourceForNativeView = WindowViewRuntimeMethods.commandSourceForNativeView;
|
|
86
|
+
pub const setFocusedView = WindowViewRuntimeMethods.setFocusedView;
|
|
87
|
+
pub const clearFocusedView = WindowViewRuntimeMethods.clearFocusedView;
|
|
88
|
+
pub const ensureFocusableViewFocused = WindowViewRuntimeMethods.ensureFocusableViewFocused;
|
|
89
|
+
pub const focusAdjacentView = WindowViewRuntimeMethods.focusAdjacentView;
|
|
90
|
+
pub const viewLabelExists = WindowViewRuntimeMethods.viewLabelExists;
|
|
91
|
+
pub const removeViewAt = WindowViewRuntimeMethods.removeViewAt;
|
|
92
|
+
pub const removeViewsForWindow = WindowViewRuntimeMethods.removeViewsForWindow;
|
|
93
|
+
pub const removeDescendantViewsForParent = WindowViewRuntimeMethods.removeDescendantViewsForParent;
|
|
94
|
+
pub const removeDescendantWebViewsForParent = WindowViewRuntimeMethods.removeDescendantWebViewsForParent;
|
|
95
|
+
pub const closeDescendantWebViewBackends = WindowViewRuntimeMethods.closeDescendantWebViewBackends;
|
|
96
|
+
pub const closeDescendantWebViewBackendsDepth = WindowViewRuntimeMethods.closeDescendantWebViewBackendsDepth;
|
|
97
|
+
pub const viewTreeHasFocused = WindowViewRuntimeMethods.viewTreeHasFocused;
|
|
98
|
+
pub const viewTreeHasFocusedDepth = WindowViewRuntimeMethods.viewTreeHasFocusedDepth;
|
|
99
|
+
|
|
100
|
+
pub fn closeWindow(self: *Runtime, window_id: platform.WindowId) anyerror!void {
|
|
101
|
+
const index = Self.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
|
|
102
|
+
// Flip the runtime flag BEFORE the platform call: hosts that
|
|
103
|
+
// run the close delegate synchronously (macOS `performClose`
|
|
104
|
+
// fires `windowWillClose` inline) echo a frame-changed
|
|
105
|
+
// open=false event, and the open->closed TRANSITION — which
|
|
106
|
+
// dispatches the `window_closed` app event — must stay
|
|
107
|
+
// reserved for closes the app did not initiate.
|
|
108
|
+
const was_open = self.windows[index].info.open;
|
|
109
|
+
const was_focused = self.windows[index].info.focused;
|
|
110
|
+
self.windows[index].info.open = false;
|
|
111
|
+
self.windows[index].info.focused = false;
|
|
112
|
+
self.options.platform.services.closeWindow(window_id) catch |err| {
|
|
113
|
+
self.windows[index].info.open = was_open;
|
|
114
|
+
self.windows[index].info.focused = was_focused;
|
|
115
|
+
return err;
|
|
116
|
+
};
|
|
117
|
+
Self.removeWindowRuntimeViews(self, window_id);
|
|
118
|
+
self.invalidated = true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/// The real OS minimize verb for a tracked window (app-drawn
|
|
122
|
+
/// window controls on chromeless windows). No runtime
|
|
123
|
+
/// bookkeeping moves: a minimized window stays open and keeps
|
|
124
|
+
/// its views — it comes back from the Dock/taskbar.
|
|
125
|
+
pub fn minimizeWindow(self: *Runtime, window_id: platform.WindowId) anyerror!void {
|
|
126
|
+
if (Self.findWindowIndexById(self, window_id) == null) return error.WindowNotFound;
|
|
127
|
+
try self.options.platform.services.minimizeWindow(window_id);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
pub fn updateWindowState(self: *Runtime, state: platform.WindowState) !void {
|
|
131
|
+
try WindowStorageMethods.updateWindowState(self, state);
|
|
132
|
+
if (!state.open) Self.removeWindowRuntimeViews(self, state.id);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
pub fn createShellWindow(self: *Runtime, shell_window: app_manifest.ShellWindow, source: ?platform.WebViewSource) anyerror!platform.WindowInfo {
|
|
136
|
+
return Self.createShellWindowWithSourceMode(self, shell_window, source, source == null);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/// A shell window that NEVER hosts the app webview source, even
|
|
140
|
+
/// when one is loaded: the shape for model-declared canvas
|
|
141
|
+
/// windows (UiApp secondary windows), whose whole content is
|
|
142
|
+
/// their gpu_surface view — a hybrid app's loaded source must
|
|
143
|
+
/// not silently materialize a webview under the canvas.
|
|
144
|
+
pub fn createSourcelessShellWindow(self: *Runtime, shell_window: app_manifest.ShellWindow) anyerror!platform.WindowInfo {
|
|
145
|
+
return Self.createShellWindowWithSourcePolicy(self, shell_window, null, false, .never_source);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
pub fn createShellWindowWithSourceMode(self: *Runtime, shell_window: app_manifest.ShellWindow, source: ?platform.WebViewSource, source_reloads_from_app: bool) anyerror!platform.WindowInfo {
|
|
149
|
+
return Self.createShellWindowWithSourcePolicy(self, shell_window, source, source_reloads_from_app, .allow_source_less);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
pub fn createShellWindowWithSourcePolicy(self: *Runtime, shell_window: app_manifest.ShellWindow, source: ?platform.WebViewSource, source_reloads_from_app: bool, source_policy: runtime_state.WindowSourcePolicy) anyerror!platform.WindowInfo {
|
|
153
|
+
const window_frame = geometry.RectF.init(
|
|
154
|
+
shell_window.x orelse 0,
|
|
155
|
+
shell_window.y orelse 0,
|
|
156
|
+
shell_window.width,
|
|
157
|
+
shell_window.height,
|
|
158
|
+
);
|
|
159
|
+
const info = try Self.createWindowWithSourceMode(self, .{
|
|
160
|
+
.label = shell_window.label,
|
|
161
|
+
.title = shell_window.title orelse "",
|
|
162
|
+
.default_frame = window_frame,
|
|
163
|
+
.resizable = shell_window.resizable,
|
|
164
|
+
.restore_state = shell_window.restore_state,
|
|
165
|
+
.restore_policy = shellRestorePolicy(shell_window.restore_policy),
|
|
166
|
+
.titlebar = shell_layout.shellTitlebarStyle(shell_window.titlebar),
|
|
167
|
+
.show = shell_layout.shellWindowShowMode(shell_window),
|
|
168
|
+
.min_width = shell_window.min_width,
|
|
169
|
+
.min_height = shell_window.min_height,
|
|
170
|
+
.source = source,
|
|
171
|
+
}, source_reloads_from_app, source_policy);
|
|
172
|
+
errdefer Self.closeWindow(self, info.id) catch {};
|
|
173
|
+
|
|
174
|
+
try Self.createShellViews(self, info.id, shell_window.views, Self.shellBoundsForWindow(self, info.id));
|
|
175
|
+
return info;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
pub fn createShellViews(self: *Runtime, window_id: platform.WindowId, views: []const app_manifest.ShellView, bounds: geometry.RectF) anyerror!void {
|
|
179
|
+
if (views.len > app_manifest.max_shell_views_per_window) return error.ViewLimitReached;
|
|
180
|
+
try Self.validateShellViewCreatePlan(self, window_id, views);
|
|
181
|
+
|
|
182
|
+
var main_state: RuntimeMainWebViewState = undefined;
|
|
183
|
+
try Self.captureMainWebViewState(self, window_id, &main_state);
|
|
184
|
+
errdefer Self.restoreMainWebViewState(self, window_id, &main_state) catch {};
|
|
185
|
+
|
|
186
|
+
var created_labels: [app_manifest.max_shell_views_per_window][]const u8 = undefined;
|
|
187
|
+
var created_count: usize = 0;
|
|
188
|
+
errdefer Self.rollbackCreatedShellViews(self, window_id, created_labels[0..created_count]);
|
|
189
|
+
|
|
190
|
+
try Self.applyShellViews(self, window_id, views, bounds, .create, &created_labels, &created_count);
|
|
191
|
+
try Self.bindShellViews(self, window_id, views);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
pub fn relayoutShellViews(self: *Runtime, window_id: platform.WindowId) anyerror!void {
|
|
195
|
+
const binding = Self.shellLayoutForWindow(self, window_id) orelse return;
|
|
196
|
+
try Self.applyShellViews(self, window_id, binding.viewSlice(), Self.shellBoundsForWindow(self, window_id), .update, null, null);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
pub fn validateShellViewCreatePlan(self: *Runtime, window_id: platform.WindowId, views: []const app_manifest.ShellView) anyerror!void {
|
|
200
|
+
try Self.validateViewParent(self, window_id);
|
|
201
|
+
|
|
202
|
+
var native_view_count: usize = 0;
|
|
203
|
+
var child_webview_count: usize = 0;
|
|
204
|
+
for (views, 0..) |view, index| {
|
|
205
|
+
for (views[0..index]) |previous| {
|
|
206
|
+
if (std.mem.eql(u8, previous.label, view.label)) return error.DuplicateViewLabel;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (view.kind == .webview and isMainWebViewLabel(view.label)) continue;
|
|
210
|
+
if (Self.viewLabelExists(self, window_id, view.label)) return error.DuplicateViewLabel;
|
|
211
|
+
|
|
212
|
+
if (view.kind == .webview) {
|
|
213
|
+
child_webview_count += 1;
|
|
214
|
+
} else {
|
|
215
|
+
native_view_count += 1;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (native_view_count > platform.max_views - self.view_count) return error.ViewLimitReached;
|
|
220
|
+
if (child_webview_count > platform.max_webviews - self.webview_count) return error.WebViewLimitReached;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
pub fn applyShellViews(self: *Runtime, window_id: platform.WindowId, views: []const app_manifest.ShellView, bounds: geometry.RectF, mode: ShellApplyMode, tracked_labels: ?*[app_manifest.max_shell_views_per_window][]const u8, tracked_count: ?*usize) anyerror!void {
|
|
224
|
+
var layout = ShellLayout.init(bounds, views);
|
|
225
|
+
var created: [app_manifest.max_shell_views_per_window]bool = [_]bool{false} ** app_manifest.max_shell_views_per_window;
|
|
226
|
+
var created_count: usize = 0;
|
|
227
|
+
while (created_count < views.len) {
|
|
228
|
+
var progressed = false;
|
|
229
|
+
for (views, 0..) |view, index| {
|
|
230
|
+
if (created[index]) continue;
|
|
231
|
+
if (view.parent) |parent| {
|
|
232
|
+
if (!layout.containsView(parent)) continue;
|
|
233
|
+
}
|
|
234
|
+
const did_create = try Self.applyShellView(self, try shellViewOptions(window_id, view, &layout), mode);
|
|
235
|
+
if (did_create) {
|
|
236
|
+
if (tracked_labels) |labels| {
|
|
237
|
+
const count = tracked_count.?;
|
|
238
|
+
labels[count.*] = view.label;
|
|
239
|
+
count.* += 1;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
created[index] = true;
|
|
243
|
+
created_count += 1;
|
|
244
|
+
progressed = true;
|
|
245
|
+
}
|
|
246
|
+
if (!progressed) return error.InvalidViewOptions;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
pub fn applyShellView(self: *Runtime, options: platform.ViewOptions, mode: ShellApplyMode) anyerror!bool {
|
|
251
|
+
switch (mode) {
|
|
252
|
+
.create => {
|
|
253
|
+
if (options.kind == .webview and isMainWebViewLabel(options.label)) {
|
|
254
|
+
try Self.setMainWebViewParent(self, options.window_id, options.parent);
|
|
255
|
+
_ = try Self.updateView(self, options.window_id, options.label, .{
|
|
256
|
+
.frame = options.frame,
|
|
257
|
+
.layer = options.layer,
|
|
258
|
+
});
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
_ = try Self.createView(self, options);
|
|
262
|
+
return true;
|
|
263
|
+
},
|
|
264
|
+
.update => {
|
|
265
|
+
if (options.kind == .webview and isMainWebViewLabel(options.label)) {
|
|
266
|
+
try Self.setMainWebViewParent(self, options.window_id, options.parent);
|
|
267
|
+
}
|
|
268
|
+
_ = Self.updateView(self, options.window_id, options.label, .{
|
|
269
|
+
.frame = options.frame,
|
|
270
|
+
.layer = options.layer,
|
|
271
|
+
}) catch |err| switch (err) {
|
|
272
|
+
error.ViewNotFound,
|
|
273
|
+
error.WebViewNotFound,
|
|
274
|
+
=> return false,
|
|
275
|
+
else => return err,
|
|
276
|
+
};
|
|
277
|
+
return false;
|
|
278
|
+
},
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
pub fn rollbackCreatedShellViews(self: *Runtime, window_id: platform.WindowId, labels: []const []const u8) void {
|
|
283
|
+
var index = labels.len;
|
|
284
|
+
while (index > 0) {
|
|
285
|
+
index -= 1;
|
|
286
|
+
Self.closeView(self, window_id, labels[index]) catch {};
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
pub fn captureMainWebViewState(self: *Runtime, window_id: platform.WindowId, state: *RuntimeMainWebViewState) !void {
|
|
291
|
+
const index = Self.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
|
|
292
|
+
const window = self.windows[index];
|
|
293
|
+
state.* = .{
|
|
294
|
+
.frame = window.main_frame,
|
|
295
|
+
.frame_set = window.main_frame_set,
|
|
296
|
+
.layer = window.main_layer,
|
|
297
|
+
};
|
|
298
|
+
state.parent = if (window.main_parent) |parent| try copyInto(&state.parent_storage, parent) else null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
pub fn restoreMainWebViewState(self: *Runtime, window_id: platform.WindowId, state: *const RuntimeMainWebViewState) !void {
|
|
302
|
+
const index = Self.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
|
|
303
|
+
const window = self.windows[index];
|
|
304
|
+
var restore_error: ?anyerror = null;
|
|
305
|
+
|
|
306
|
+
if (window.source != null) {
|
|
307
|
+
if (window.main_frame_set != state.frame_set or !Self.rectsEqual(window.main_frame, state.frame)) {
|
|
308
|
+
self.options.platform.services.setWebViewFrame(window_id, "main", state.frame) catch |err| {
|
|
309
|
+
restore_error = err;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
if (window.main_layer != state.layer) {
|
|
313
|
+
self.options.platform.services.setWebViewLayer(window_id, "main", state.layer) catch |err| {
|
|
314
|
+
if (restore_error == null) restore_error = err;
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
self.windows[index].main_frame = state.frame;
|
|
320
|
+
self.windows[index].main_frame_set = state.frame_set;
|
|
321
|
+
self.windows[index].main_layer = state.layer;
|
|
322
|
+
self.windows[index].main_parent = if (state.parent) |parent| try copyInto(&self.windows[index].main_parent_storage, parent) else null;
|
|
323
|
+
|
|
324
|
+
if (restore_error) |err| return err;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
pub fn removeWindowRuntimeViews(self: *Runtime, window_id: platform.WindowId) void {
|
|
328
|
+
if (Self.findWindowIndexById(self, window_id)) |index| self.windows[index].main_parent = null;
|
|
329
|
+
Self.removeShellLayoutForWindow(self, window_id);
|
|
330
|
+
Self.removeViewsForWindow(self, window_id);
|
|
331
|
+
Self.removeWebViewsForWindow(self, window_id);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
|
|
3
|
+
pub const permission_window = "window";
|
|
4
|
+
pub const permission_command = "command";
|
|
5
|
+
pub const permission_view = "view";
|
|
6
|
+
pub const permission_dialog = "dialog";
|
|
7
|
+
pub const permission_filesystem = "filesystem";
|
|
8
|
+
pub const permission_clipboard = "clipboard";
|
|
9
|
+
pub const permission_network = "network";
|
|
10
|
+
pub const permission_notifications = "notifications";
|
|
11
|
+
pub const permission_credentials = "credentials";
|
|
12
|
+
|
|
13
|
+
pub const ExternalLinkAction = enum(c_int) {
|
|
14
|
+
deny = 0,
|
|
15
|
+
open_system_browser = 1,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
pub const ExternalLinkPolicy = struct {
|
|
19
|
+
action: ExternalLinkAction = .deny,
|
|
20
|
+
allowed_urls: []const []const u8 = &.{},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
pub const NavigationPolicy = struct {
|
|
24
|
+
allowed_origins: []const []const u8 = &.{ "zero://app", "zero://inline" },
|
|
25
|
+
external_links: ExternalLinkPolicy = .{},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
pub const Policy = struct {
|
|
29
|
+
permissions: []const []const u8 = &.{},
|
|
30
|
+
navigation: NavigationPolicy = .{},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
pub fn hasPermission(grants: []const []const u8, permission: []const u8) bool {
|
|
34
|
+
for (grants) |grant| {
|
|
35
|
+
if (std.mem.eql(u8, grant, permission)) return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pub fn hasPermissions(grants: []const []const u8, required: []const []const u8) bool {
|
|
41
|
+
for (required) |permission| {
|
|
42
|
+
if (!hasPermission(grants, permission)) return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
pub fn allowsOrigin(allowed_origins: []const []const u8, origin: []const u8) bool {
|
|
48
|
+
for (allowed_origins) |allowed| {
|
|
49
|
+
if (std.mem.eql(u8, allowed, "*")) return true;
|
|
50
|
+
if (std.mem.eql(u8, allowed, origin)) return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
pub fn allowsExternalUrl(policy: ExternalLinkPolicy, url: []const u8) bool {
|
|
56
|
+
if (policy.action != .open_system_browser) return false;
|
|
57
|
+
for (policy.allowed_urls) |allowed| {
|
|
58
|
+
if (std.mem.eql(u8, allowed, "*")) return true;
|
|
59
|
+
if (std.mem.eql(u8, allowed, url)) return true;
|
|
60
|
+
if (externalWildcardPrefixValid(allowed)) {
|
|
61
|
+
const prefix = allowed[0 .. allowed.len - 1];
|
|
62
|
+
if (std.mem.startsWith(u8, url, prefix)) return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fn externalWildcardPrefixValid(pattern: []const u8) bool {
|
|
69
|
+
if (!std.mem.endsWith(u8, pattern, "*")) return false;
|
|
70
|
+
const prefix = pattern[0 .. pattern.len - 1];
|
|
71
|
+
const scheme = if (std.mem.startsWith(u8, prefix, "https://"))
|
|
72
|
+
"https://"
|
|
73
|
+
else if (std.mem.startsWith(u8, prefix, "http://"))
|
|
74
|
+
"http://"
|
|
75
|
+
else
|
|
76
|
+
return false;
|
|
77
|
+
const rest = prefix[scheme.len..];
|
|
78
|
+
const slash_index = std.mem.indexOfScalar(u8, rest, '/') orelse return false;
|
|
79
|
+
return slash_index > 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
test "permission checks require every requested grant" {
|
|
83
|
+
try std.testing.expect(hasPermissions(&.{ permission_window, permission_filesystem }, &.{permission_window}));
|
|
84
|
+
try std.testing.expect(!hasPermissions(&.{permission_window}, &.{ permission_window, permission_filesystem }));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
test "origin checks support exact origins and wildcard" {
|
|
88
|
+
try std.testing.expect(allowsOrigin(&.{ "zero://app", "zero://inline" }, "zero://inline"));
|
|
89
|
+
try std.testing.expect(allowsOrigin(&.{"*"}, "https://example.invalid"));
|
|
90
|
+
try std.testing.expect(!allowsOrigin(&.{"zero://app"}, "https://example.invalid"));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
test "external URL checks require open-browser action and allowed URL pattern" {
|
|
94
|
+
try std.testing.expect(!allowsExternalUrl(.{
|
|
95
|
+
.action = .deny,
|
|
96
|
+
.allowed_urls = &.{"https://example.com/*"},
|
|
97
|
+
}, "https://example.com/docs"));
|
|
98
|
+
try std.testing.expect(allowsExternalUrl(.{
|
|
99
|
+
.action = .open_system_browser,
|
|
100
|
+
.allowed_urls = &.{"https://example.com/*"},
|
|
101
|
+
}, "https://example.com/docs"));
|
|
102
|
+
try std.testing.expect(allowsExternalUrl(.{
|
|
103
|
+
.action = .open_system_browser,
|
|
104
|
+
.allowed_urls = &.{"https://example.com/docs"},
|
|
105
|
+
}, "https://example.com/docs"));
|
|
106
|
+
try std.testing.expect(!allowsExternalUrl(.{
|
|
107
|
+
.action = .open_system_browser,
|
|
108
|
+
.allowed_urls = &.{"https://example.com/*"},
|
|
109
|
+
}, "https://other.example/docs"));
|
|
110
|
+
try std.testing.expect(!allowsExternalUrl(.{
|
|
111
|
+
.action = .open_system_browser,
|
|
112
|
+
.allowed_urls = &.{"https://example.com/*"},
|
|
113
|
+
}, "https://example.com.evil/docs"));
|
|
114
|
+
try std.testing.expect(!allowsExternalUrl(.{
|
|
115
|
+
.action = .open_system_browser,
|
|
116
|
+
.allowed_urls = &.{"https://example.com*"},
|
|
117
|
+
}, "https://example.com.evil/docs"));
|
|
118
|
+
}
|