Refactor: Enhance safety, correctness and modernization - #398
Merged
Conversation
Wide-ranging improvements: better diagnostics and error messages; stronger thread-safety and disposal (Volatile/Interlocked, sync-context deadlock guard); improved logging and HTTP pattern matching; WebView queue severity raised; JS modernizations (crypto-based request IDs, non-enumerable dispatch, safer eval); native platform robustness (Win32/Gtk checks and error handling); project file/editorconfig tweaks; DI lifetimes changed to scoped; API shape updates for window configuration; and many test modernizations and assertion/syntax fixes to align with updated code.
Add host-driven browser controls and strengthen safety/cleanup across the codebase. Highlights: - Add browser feature toggles in TS (context menu, zoom, shortcuts) and guard UI events. - Replace injected JS toggles with structured web messages from native backends (Win/Mac/Linux) and register script handler in WebKit. - Thread-safety and lifecycle fixes: WindowRegistrationStateMachine (locking), InfiniFrameWindow (owns service provider, async-dispose guard), InfiniNavigation cancellation handling. - Resource/disposal improvements: DisposableCompositeFileProvider, FileProviderFactory returns disposable, native-build copy filter, clean.ps1 -KillProcesses flag. - Security and robustness: stronger static asset path checks, ExceptionsUtility excludes StackOverflowException from non-fatal list, PageNavigation catch condition fix, other small bugfixes and formatting. These changes centralize browser policy via host messaging and harden concurrency, disposal and security behavior.
Close TcpClient on probe timeout to avoid socket leaks and throw when AllocCoTaskMem fails to detect allocation failure. Update tests to be type-safe and more robust: cast DPI to int for comparison, compare JS argument to (object)element, and refactor RemoteDebuggingPortTests to obtain a port via PortUtils.GetOpenPortValue() (removed method-data parameter). These changes prevent resource leaks, surface allocation errors, and reduce flaky test failures.
Use optional chaining when accessing window.infiniframe and its subproperties to avoid runtime errors (Index.ts, BrowserInfiniFrameWindowFeature.ts). Add a beforeEach test stub to ensure window.infiniframe.messaging and utils exist for unit tests (InfiniFrame.test.ts). Fix window-related test setup to create/return a single InfiniFrameWindow instance and assign it to window.infiniframe.window, stabilizing InfiniFrameWindow.* tests.
Adjust test assertions to use explicit casts to the expected types to avoid boxing/nullable mismatches. In InfiniFrameJsTests.cs cast jsArguments[1] to (long) before asserting. In RemoteDebuggingPortTests.cs cast window.Features.Debugging.RemoteDebuggingPort to (int?) when comparing to the expected value.
Critical fixes: - Fix GC-collection risk for delegates passed to native via GetFunctionPointerForDelegate - Fix ANSI/UTF-8 mismatch in CustomSchemeNameMemory (StringToHGlobalAnsi → StringToCoTaskMemUTF8) - Add upper-bound check on PtrToNativeStringArray count from native side - Move PublishTrimmed/PublishAot out of library Directory.Build.props High fixes: - Fix boolean marshaling inconsistency (U1 → I1 in SetDragDropEnabled) - Add logging on NativeWindowHandle destructor failure - Expand exception filter in NativeInvoke to exclude ThreadAbortException, OperationCanceledException - Expand IsNonFatalException to exclude BadImageFormatException, SEHException, ThreadAbortException - Fix race condition in InfiniFrameEvents.Messaging (capture Sender in local variable) - Mark _primaryMutex volatile in InstanceArbitration - Change IInfiniFrameWindowBuilderConfiguration.ChildWindows to IReadOnlyList Medium fixes: - Reduce InteropEnvelopeProtocol MaxDepth from 64 to 16 - Use Enum.TryParse in NotificationsWebMessageDispatcher - Add control character check for tab in custom scheme content type validation - Expand path traversal checks for double-encoding and uppercase hex - Fix NativeMonitor.Scale type from double to float (match native ABI) - Fix CustomSchemeNameMemoryEqualityComparer to dereference pointers - Remove status overwrite in NativeInvoke.EnsureSuccess - Fix InfiniFrameEventsStore from record to class - Change IStateInfiniFrameWindowFeature cached bounds to internal set - Fix validator side-effect (remove CreateDirectory in probe) - Use stream.GetBuffer() instead of ToArray() for envelope protocol - Add null guard for InfiniFrameWindow.Features - Remove PublishTrimmed/PublishAot from library builds Low fixes: - Dispose embedded providers in DisposableCompositeFileProvider - Fix DeepCopy() documentation to reflect shallow copy - Remove redundant RegexOptions.Compiled from GeneratedRegex attributes - Fix test file for float Scale type change
Replace direct Serilog usage with Microsoft.Extensions.Logging and introduce DI for the pack tool. CommandLine, ProcessRunner and PublishService were converted from static to instance types and wired in Program via ServiceCollection. Updated Directory.Packages.props and csproj to add logging/DI packages and Serilog.Extensions.Hosting. Tests adjusted to use NullLogger and construct instances. Also includes several small documentation, lifecycle, locking and robustness tweaks across window, native-parameter, webapp and handler code (comments, safety checks and improved exception logging).
…aintainability - Fix path traversal bypass via iterative URI decoding in StaticAssetSchemeHandler - Fix stream leak in InfiniFrameHttpHandler by using async and proper cancellation - Fix DisposeAsync race condition with try/finally guard in InfiniFrameWindow - Fix validator side effects: move directory creation out of FluentValidation rule - Fix fire-and-forget exception swallowing in RegisterWindowCreatedUtility - Fix integer overflow in MonitorsUtility area calculation - Add thread safety to InfiniFrameUriSecurityPolicyRegistry.ConfigureForBuilder - Use DisposableCompositeFileProvider to dispose PhysicalFileProvider on shutdown - Add InfiniFrameNativeInteropException for native interop errors (replaces ApplicationException) - Add XML escaping in TempTargetsFile to prevent MSBuild injection - Add missing MIME types (.wasm, .mp4, .webm, .webp, .avif) - Align ExceptionsUtility between Shared and Tools.Pack - Add LastAddComponentException to InfiniFrameJsComponentConfiguration for error visibility - Fix InfiniNotificationOperation catch block for new exception type
…reation The original CanAccessTemporaryFilesPath intentionally creates the directory as a side effect. Tests rely on this behavior. Added EnsureTemporaryFilesPath as a public utility for callers who want explicit directory creation.
C1: Fix double-disposal of PhysicalFileProvider in DisposableCompositeFileProvider C2: Remove GC.SuppressFinalize from InfiniFrameBlazorApp (no finalizer exists) H1: Fix WebMessageQueueFullMode default to DropWrite (TryWrite ignores Wait) H2: Add WaitForExit after Kill in ProcessRunner to prevent zombie processes H3: Use Interlocked.Exchange for thread-safe exception store in JsComponentConfiguration M1: Add root deletion guard to SafeDeleteDirectory M2: Document SynchronizationContext.Send deadlock restriction M3: Document OS shell trust dependency in OpenExternalTargetWebMessageHandler M4: Add missing ThreadAbortException to Tools.Pack ExceptionsUtility M5: Add security policy configuration to WebApplicationBuilder.Build L1: Add SynchronizationContext guard to InfiniFrameBlazorApp.Run() L2: Add SynchronizationContext guard to InfiniFrameWebApplication.Run() L3: Document InfiniFrameHttpHandler stream ownership L4: Add null callback guard in ExecutionContextThunk
…ks.py Use certifi when available for broader CA coverage, and fall back to an unverified SSL context on SSLError for CI environments with self-signed certificates (corporate proxies, custom runners).
Introduce gtkThread and mainLoop globals and add a Shutdown() function to stop the GTK main loop and join the UI thread instead of detaching it. EnsureInitialized now starts gtkThread and stores the GMainLoop; Shutdown quits the loop (if running) and joins the thread. Add a destructor function to call Shutdown() at process unload and expose Shutdown() in the header. This fixes shutdown races and ensures proper cleanup of GTK resources.
Small API and style cleanups across native and managed code: bump GitHub Action versions and global .NET SDK; add missing const qualifiers and tighten parameter types in many C/C++ files; fix null-check/bracing and callback signatures for GTK/Win32 integrations; refactor Linux taskbar DBus variable names and error handling; minor Windows/WebView and notification API tweaks; simplify a few C# members (expression-bodied property, remove unused using, Enum.TryParse usage) and adjust tests. These changes improve consistency, reduce compiler warnings and tighten APIs.
Introduce ShutdownAndJoin in the Linux GTK UI thread (declared in UiThread.Gtk.h and implemented in UiThread.Gtk.cpp) to call Shutdown() and then join the GTK thread for a clean shutdown. Update tests to fix type mismatches: cast element to object in InfiniFrameJsTests and compare RemoteDebuggingPort as (int?) in RemoteDebuggingPortTests so assertions match expected types.
Delete .github/workflows/ci-testing-python.yml and remove its entry from InfiniFrame.slnx. Also simplify the Task.Run lambda in RemoteDebuggingPortTests.cs to an expression-bodied call (no behavior change) while preserving the CA1416 suppression.
Detach the gtkThread after starting it and remove the ShutdownAndJoin API. This makes the GTK UI thread run independently and eliminates the explicit join logic (function removed from both header and source). Adjusts initialization/shutdown flow to avoid blocking on thread join.
Bump multiple devDependencies and corresponding package-lock updates across examples, src and tests (vite, @types/node/react/dom, @vitejs/plugin-react/vue, eslint, lightningcss, rolldown and bindings, postcss, nanoid, terser, @analogjs/vite-plugin-angular, vue-tsc, etc.). Also add a LibraryImport for InfiniFrameNative_Shutdown in InfiniFrameNative.Lifecycle.cs to properly shut down the native UI thread on Linux and prevent GLib assertion failures. Lockfiles updated to reflect resolved versions.
…est on System.Object' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…tunity' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.