From 4f98b59e4f6c74b84d2b1862d573214e0726f438 Mon Sep 17 00:00:00 2001 From: Leaskovski Date: Tue, 4 Jun 2019 17:26:04 +0100 Subject: [PATCH] Removed cefBrowser_InitializedChanged event handling because this actually had no use to the browser loading and being usable. Fixed the issue of the CEF Browser not loading the requested URL on connect. Changed the loading logic of the CEF Browser to wait for cefBrowser_LoadingStateChanged to trigger and to look at if it is still loading before logging that the browser is initialised. Altered cefBrowser_LoadingStateChanged to register itself as an event once the browser is loaded as we don't care for any more events once we know it is safe to issue the Browser.Load() method. Updated Connect to record when it has been requested so that if the browser initialises after this request, it can retrigger the code to load the required URL automatically. Removed the dispose code, though this might need to be reimplemented after testing. Updated App.config and .csproj with settings defined in CEF user documentation. Updated some of the CEF Settings to recommended values. --- .../Http/Connection.Protocol.HTTPBase.cs | 36 +++++++------------ mRemoteV1/UI/Forms/frmMain.cs | 7 ++++ mRemoteV1/app.config | 1 + mRemoteV1/mRemoteV1.csproj | 5 ++- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPBase.cs b/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPBase.cs index 7c52a11e..997eab96 100644 --- a/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPBase.cs +++ b/mRemoteV1/Connection/Protocol/Http/Connection.Protocol.HTTPBase.cs @@ -20,6 +20,7 @@ namespace mRemoteNG.Connection.Protocol.Http protected int defaultPort; private string tabTitle; private bool browserInitialised = false; + private bool connectCalled = false; #endregion @@ -102,7 +103,6 @@ namespace mRemoteNG.Connection.Protocol.Http var CEFBrowser = (ChromiumWebBrowser)wBrowser; if (CEFBrowser != null) { - CEFBrowser.IsBrowserInitializedChanged += cefBrowser_InitializedChanged; CEFBrowser.LoadingStateChanged += cefBrowser_LoadingStateChanged; CEFBrowser.TitleChanged += wBrowser_DocumentTitleChanged; } @@ -133,21 +133,6 @@ namespace mRemoteNG.Connection.Protocol.Http } } - ~HTTPBase() - { - try - { - if (InterfaceControl.Info.RenderingEngine == RenderingEngine.CEF) - { - ((ChromiumWebBrowser)wBrowser).Dispose(); - } - } - finally - { - Dispose(); - } - } - public override bool Connect() { try @@ -169,6 +154,7 @@ namespace mRemoteNG.Connection.Protocol.Http } base.Connect(); + connectCalled = true; return true; } catch (Exception ex) @@ -232,16 +218,20 @@ namespace mRemoteNG.Connection.Protocol.Http #region Events - private void cefBrowser_InitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e) - { - browserInitialised = e.IsBrowserInitialized; - } - private void cefBrowser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e) { - if (browserInitialised == true) + browserInitialised = !e.IsLoading; + if (browserInitialised) { - Connect(); + // Unhook the loading state changes now, as navigation is done by the user on links in the control + ((ChromiumWebBrowser)wBrowser).LoadingStateChanged -= cefBrowser_LoadingStateChanged; + + // If this Connection has already been asked to connect but the browser hadn't finished initalising + // then the connect wouldn't have been allowed to take place, so now we can call it! + if (connectCalled) + { + Connect(); + } } } diff --git a/mRemoteV1/UI/Forms/frmMain.cs b/mRemoteV1/UI/Forms/frmMain.cs index 345107e3..4dd89ad6 100644 --- a/mRemoteV1/UI/Forms/frmMain.cs +++ b/mRemoteV1/UI/Forms/frmMain.cs @@ -156,6 +156,13 @@ namespace mRemoteNG.UI.Forms SetMenuDependencies(); + //Monitor parent process exit and close subprocesses if parent process exits first + //This will at some point in the future becomes the default + CefSharpSettings.SubprocessExitIfParentProcessClosed = true; + + //For Windows 7 and above, best to include relevant app.manifest entries as well + Cef.EnableHighDPISupport(); + CefSettings settings = new CefSettings(); settings.LogSeverity = CefSharp.LogSeverity.Verbose; Cef.Initialize(settings); diff --git a/mRemoteV1/app.config b/mRemoteV1/app.config index 5f3c2962..54062ce2 100644 --- a/mRemoteV1/app.config +++ b/mRemoteV1/app.config @@ -778,6 +778,7 @@ + diff --git a/mRemoteV1/mRemoteV1.csproj b/mRemoteV1/mRemoteV1.csproj index 79f91f54..0b78ea5a 100644 --- a/mRemoteV1/mRemoteV1.csproj +++ b/mRemoteV1/mRemoteV1.csproj @@ -50,6 +50,7 @@ false true true + true @@ -1141,7 +1142,9 @@ - + + Designer + PreserveNewest