Collegamento e motore: correzioni regole-1, regole-2, regole-6, websec-1, websec-5, websec-6, engine-1, engine-2, sched-1
Pagine aperte da Alberto non sono segnali (regole-1); cookie perso fuori sessione = disconnessione (regole-2); pagina a riposo quando Alberto lascia il browser (regole-6); la lease di «Accedi»/«Usa il browser» finisce da sola dopo 2 minuti senza vista remota né finestra (websec-1); ping con scadenza sulla vista remota (websec-5); aperture della vista remota serializzate (websec-6); orologio virtuale senza fine anticipata (engine-1); la sincronizzazione della coda non duplica il compito in corso (engine-2); raccolte in evidenza programmate (sched-1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
19 files changed
+1122
-92
No files matched your search
@@ -13,11 +13,14 @@ namespace Febe.Server;
|
||||
/// <summary>
|
||||
/// The remote view over the real Chromium (spec §4.1, §11, PROTOCOLLO.md): a <see cref="RemoteViewSession"/> per open
|
||||
/// view, which holds the «Alberto is driving» lease while it is open, so the engine is still. One view at a time: a
|
||||
/// view opened in another tab replaces the older one. Keys go to the browser and nowhere else.
|
||||
/// view opened in another tab replaces the older one, also when two open at the same moment (opening is serialized, so
|
||||
/// the older view is always ended — and its screencast stopped — before the newer one starts). Keys go to the browser
|
||||
/// and nowhere else.
|
||||
/// </summary>
|
||||
internal sealed class BrowserRemoteViewHost(ChromiumBrowser browser, BrowserUseTracker tracker, IClock clock, FebeLog log) : IRemoteViewHost
|
||||
{
|
||||
private readonly Lock _gate = new();
|
||||
private readonly SemaphoreSlim _opening = new(1, 1);
|
||||
private BrowserRemoteViewConnection? _current;
|
||||
private bool _shuttingDown;
|
||||
|
||||
@@ -30,41 +33,70 @@ internal sealed class BrowserRemoteViewHost(ChromiumBrowser browser, BrowserUseT
|
||||
: "Il browser di Febe si sta avviando: riprova fra qualche secondo.");
|
||||
}
|
||||
|
||||
BrowserRemoteViewConnection? previous;
|
||||
lock (_gate)
|
||||
// From the look at the current view to the new one in its place, one opening at a time: two views opened at once
|
||||
// would both start and the later assignment would orphan the other (still holding its lease, and stopping the
|
||||
// shared screencast when it closes).
|
||||
await _opening.WaitAsync(ct).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
if (_shuttingDown)
|
||||
BrowserRemoteViewConnection? previous;
|
||||
lock (_gate)
|
||||
{
|
||||
if (_shuttingDown)
|
||||
{
|
||||
throw new RemoteViewUnavailableException("Febe si sta fermando.");
|
||||
}
|
||||
|
||||
previous = _current;
|
||||
_current = null;
|
||||
}
|
||||
|
||||
if (previous is not null)
|
||||
{
|
||||
await previous.EndAsync(RemoteViewEnd.Replaced).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var connection = new BrowserRemoteViewConnection(this, browser, tracker, clock);
|
||||
try
|
||||
{
|
||||
await connection.StartAsync(browser.BrowserOptions.WindowWidth, browser.BrowserOptions.WindowHeight, ct).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Whatever went wrong (the page gone away, an unexpected frame tree), nothing of the view stays behind:
|
||||
// no lease, no screencast, no subscription.
|
||||
await connection.DisposeAsync().ConfigureAwait(false);
|
||||
if (ex is CdpDisconnectedException or BrowserUnavailableException or CdpCommandException or TimeoutException)
|
||||
{
|
||||
throw new RemoteViewUnavailableException("Il browser di Febe non risponde: riprova fra qualche secondo.", ex);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
bool stopping;
|
||||
lock (_gate)
|
||||
{
|
||||
stopping = _shuttingDown;
|
||||
if (!stopping)
|
||||
{
|
||||
_current = connection;
|
||||
}
|
||||
}
|
||||
|
||||
if (stopping)
|
||||
{
|
||||
await connection.EndAsync(RemoteViewEnd.ShuttingDown).ConfigureAwait(false);
|
||||
throw new RemoteViewUnavailableException("Febe si sta fermando.");
|
||||
}
|
||||
|
||||
previous = _current;
|
||||
_current = null;
|
||||
log.Info("vista", "Vista remota aperta: il motore resta fermo finché è aperta.");
|
||||
return connection;
|
||||
}
|
||||
|
||||
if (previous is not null)
|
||||
finally
|
||||
{
|
||||
await previous.EndAsync(RemoteViewEnd.Replaced).ConfigureAwait(false);
|
||||
_opening.Release();
|
||||
}
|
||||
|
||||
var connection = new BrowserRemoteViewConnection(this, browser, tracker, clock);
|
||||
try
|
||||
{
|
||||
await connection.StartAsync(browser.BrowserOptions.WindowWidth, browser.BrowserOptions.WindowHeight, ct).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is CdpDisconnectedException or BrowserUnavailableException or CdpCommandException or TimeoutException)
|
||||
{
|
||||
await connection.DisposeAsync().ConfigureAwait(false);
|
||||
throw new RemoteViewUnavailableException("Il browser di Febe non risponde: riprova fra qualche secondo.", ex);
|
||||
}
|
||||
|
||||
lock (_gate)
|
||||
{
|
||||
_current = connection;
|
||||
}
|
||||
|
||||
log.Info("vista", "Vista remota aperta: il motore resta fermo finché è aperta.");
|
||||
return connection;
|
||||
}
|
||||
|
||||
/// <summary>Febe is stopping: the open view is closed with a reason the page can show.</summary>
|
||||
|
||||
Reference in new issue
Block a user