agentmux_cef\commands/
mod.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Command handler modules for the CEF IPC bridge.
5// Each module corresponds to a category of commands ported from src-tauri/src/commands/.
6
7pub mod platform;
8pub mod window;
9pub mod backend;
10pub mod providers;
11pub mod drag;
12pub mod tear_off_hook;
13pub mod window_pool;
14pub mod clipboard;
15pub mod stubs;
16pub mod palette;
17pub mod orphan_reconcile;
18pub mod floating_pane;
19
20use std::sync::Arc;
21use crate::state::AppState;
22
23/// Create an isolated CEF RequestContext for a new browser window.
24///
25/// Each browser window needs its own renderer process to get an isolated
26/// JavaScript context (own `document`, own module state, own SolidJS render tree).
27/// CEF assigns a separate renderer process when the RequestContext has a unique
28/// `cache_path`. We use `<data_dir>/browser-contexts/<label>/` for this.
29pub fn create_isolated_request_context(state: &Arc<AppState>, label: &str) -> Option<cef::RequestContext> {
30    // Phase 1 diagnostic tracing (added 2026-05-02 freeze investigation, see
31    // docs/specs/SPEC_HOST_WINDOW_CREATION_RUNNER_2026-05-02.md). The freeze
32    // wedges the UI thread inside CEF's Chrome profile-init under concurrent
33    // load; we need to find the EXACT line that silences before committing
34    // to the runner-based serialization fix.
35    let t0 = std::time::Instant::now();
36    tracing::info!(label = %label, "[cef-profile-init] entering create_isolated_request_context");
37
38    let data_dir = state.version_data_dir.lock().clone()
39        .unwrap_or_else(|| {
40            std::env::temp_dir()
41                .join("agentmux-cef-contexts")
42                .to_string_lossy()
43                .to_string()
44        });
45
46    let ctx_path = std::path::PathBuf::from(&data_dir)
47        .join("browser-contexts")
48        .join(label);
49    // Do NOT pre-create the directory — CEF's Chrome profile initializer
50    // (chrome_browser_context.cc) fails when the directory already exists but
51    // has no valid profile structure. Let CEF create and initialize it.
52
53    let settings = cef::RequestContextSettings {
54        cache_path: cef::CefString::from(ctx_path.to_str().unwrap_or("")),
55        persist_session_cookies: 0,
56        ..Default::default()
57    };
58
59    tracing::info!(
60        label = %label,
61        elapsed_us = t0.elapsed().as_micros() as u64,
62        "[cef-profile-init] calling request_context_create_context"
63    );
64    let ctx = cef::request_context_create_context(Some(&settings), None);
65    tracing::info!(
66        label = %label,
67        elapsed_us = t0.elapsed().as_micros() as u64,
68        ok = ctx.is_some(),
69        "[cef-profile-init] request_context_create_context returned"
70    );
71
72    if ctx.is_some() {
73        tracing::info!(label = %label, path = %ctx_path.display(), "[cef] created isolated RequestContext");
74    } else {
75        tracing::warn!(label = %label, "[cef] failed to create isolated RequestContext — falling back to shared");
76    }
77    ctx
78}