mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 12:09:40 +00:00
Core - Change Cef.IsInitialized from bool to bool? (#4869)
Resolves #4867
This commit is contained in:
@@ -46,7 +46,7 @@ namespace CefSharp
|
||||
private:
|
||||
static Object^ _sync;
|
||||
|
||||
static bool _initialized = false;
|
||||
static Nullable<bool> _initialized;
|
||||
static bool _hasShutdown = false;
|
||||
static HashSet<IDisposable^>^ _disposables;
|
||||
static int _initializedThreadId;
|
||||
@@ -86,9 +86,9 @@ namespace CefSharp
|
||||
|
||||
/// <summary>Gets a value that indicates whether CefSharp is initialized.</summary>
|
||||
/// <value>true if CefSharp is initialized; otherwise, false.</value>
|
||||
static property bool IsInitialized
|
||||
static property Nullable<bool> IsInitialized
|
||||
{
|
||||
bool get()
|
||||
Nullable<bool> get()
|
||||
{
|
||||
return _initialized;
|
||||
}
|
||||
@@ -255,7 +255,7 @@ namespace CefSharp
|
||||
/// <returns>true if successful; otherwise, false.</returns>
|
||||
static bool Initialize(CefSettingsBase^ cefSettings, bool performDependencyCheck, IApp^ cefApp)
|
||||
{
|
||||
if (_initialized)
|
||||
if (_initialized.HasValue)
|
||||
{
|
||||
// NOTE: Can only initialize Cef once, to make this explicitly clear throw exception on subsiquent attempts
|
||||
throw gcnew Exception("Cef.Initialize can only be called once per process. This is a limitation of the underlying " +
|
||||
@@ -555,11 +555,11 @@ namespace CefSharp
|
||||
/// </summary>
|
||||
static void Shutdown()
|
||||
{
|
||||
if (_initialized)
|
||||
if (_initialized.GetValueOrDefault())
|
||||
{
|
||||
msclr::lock l(_sync);
|
||||
|
||||
if (_initialized)
|
||||
if (_initialized.GetValueOrDefault())
|
||||
{
|
||||
if (_initializedThreadId != Thread::CurrentThread->ManagedThreadId)
|
||||
{
|
||||
@@ -615,11 +615,11 @@ namespace CefSharp
|
||||
/// </summary>
|
||||
static void ShutdownWithoutChecks()
|
||||
{
|
||||
if (_initialized)
|
||||
if (_initialized.GetValueOrDefault())
|
||||
{
|
||||
msclr::lock l(_sync);
|
||||
|
||||
if (_initialized)
|
||||
if (_initialized.GetValueOrDefault())
|
||||
{
|
||||
CefShutdown();
|
||||
_initialized = false;
|
||||
@@ -821,7 +821,7 @@ namespace CefSharp
|
||||
return;
|
||||
}
|
||||
|
||||
if (_initialized)
|
||||
if (_initialized.HasValue)
|
||||
{
|
||||
throw gcnew Exception("Must be enabled before Cef.Initialize is called. ");
|
||||
}
|
||||
|
||||
@@ -50,8 +50,11 @@ namespace CefSharp
|
||||
}
|
||||
|
||||
/// <summary>Gets a value that indicates whether CefSharp is initialized.</summary>
|
||||
/// <value>true if CefSharp is initialized; otherwise, false.</value>
|
||||
public static bool IsInitialized
|
||||
/// <value>
|
||||
/// true if CefSharp is initialized; returns false if initialize failed.
|
||||
/// null if initialize not yet called.
|
||||
/// </value>
|
||||
public static bool? IsInitialized
|
||||
{
|
||||
get { return Core.Cef.IsInitialized; }
|
||||
}
|
||||
|
||||
@@ -224,15 +224,7 @@ namespace CefSharp.OffScreen
|
||||
IRequestContext requestContext = null, bool automaticallyCreateBrowser = true,
|
||||
Action<IBrowser> onAfterBrowserCreated = null, bool useLegacyRenderHandler = true)
|
||||
{
|
||||
if (!Cef.IsInitialized)
|
||||
{
|
||||
var settings = new CefSettings();
|
||||
|
||||
if (!Cef.Initialize(settings))
|
||||
{
|
||||
throw new InvalidOperationException(CefInitializeFailedErrorMessage);
|
||||
}
|
||||
}
|
||||
InitializeCefInternal();
|
||||
|
||||
RequestContext = requestContext;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace CefSharp.Test
|
||||
|
||||
private void CefInitialize()
|
||||
{
|
||||
if (!Cef.IsInitialized)
|
||||
if (Cef.IsInitialized == null)
|
||||
{
|
||||
var isDefault = AppDomain.CurrentDomain.IsDefaultAppDomain();
|
||||
if (!isDefault)
|
||||
@@ -63,11 +63,16 @@ namespace CefSharp.Test
|
||||
|
||||
diagnosticMessageSink.OnMessage(new DiagnosticMessage("Cef Initialized:" + success));
|
||||
}
|
||||
|
||||
if (Cef.IsInitialized == false)
|
||||
{
|
||||
throw new InvalidOperationException("Cef.Initialize failed.");
|
||||
}
|
||||
}
|
||||
|
||||
private void CefShutdown()
|
||||
{
|
||||
if (Cef.IsInitialized)
|
||||
if (Cef.IsInitialized == true)
|
||||
{
|
||||
diagnosticMessageSink.OnMessage(new DiagnosticMessage("Before Cef Shutdown"));
|
||||
|
||||
|
||||
@@ -333,10 +333,7 @@ namespace CefSharp.WinForms
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
if (!Cef.IsInitialized && !Cef.Initialize(new CefSettings()))
|
||||
{
|
||||
throw new InvalidOperationException(CefInitializeFailedErrorMessage);
|
||||
}
|
||||
InitializeCefInternal();
|
||||
|
||||
Cef.AddDisposable(this);
|
||||
|
||||
|
||||
@@ -552,16 +552,7 @@ namespace CefSharp.Wpf
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private void NoInliningConstructor()
|
||||
{
|
||||
//Initialize CEF if it hasn't already been initialized
|
||||
if (!Cef.IsInitialized)
|
||||
{
|
||||
var settings = new CefSettings();
|
||||
|
||||
if (!Cef.Initialize(settings))
|
||||
{
|
||||
throw new InvalidOperationException(CefInitializeFailedErrorMessage);
|
||||
}
|
||||
}
|
||||
InitializeCefInternal();
|
||||
|
||||
//Add this ChromiumWebBrowser instance to a list of IDisposable objects
|
||||
// that if still alive at the time Cef.Shutdown is called will be disposed of
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace CefSharp.WinForms
|
||||
"the IsBrowserInitialized property to determine when the browser has been initialized.";
|
||||
|
||||
private const string CefInitializeFailedErrorMessage = "Cef.Initialize() failed.Check the log file see https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting#log-file for details.";
|
||||
private const string CefIsInitializedFalseErrorMessage = "Cef.IsInitialized was false!.Check the log file for errors!. See https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting#log-file for details.";
|
||||
|
||||
/// <summary>
|
||||
/// Used as workaround for issue https://github.com/cefsharp/CefSharp/issues/3021
|
||||
@@ -506,6 +507,22 @@ namespace CefSharp.WinForms
|
||||
this.FreeDevToolsContext();
|
||||
}
|
||||
|
||||
private static void InitializeCefInternal()
|
||||
{
|
||||
if (Cef.IsInitialized == null)
|
||||
{
|
||||
if (!Cef.Initialize(new CefSettings()))
|
||||
{
|
||||
throw new InvalidOperationException(CefInitializeFailedErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
if (Cef.IsInitialized == false)
|
||||
{
|
||||
throw new InvalidOperationException(CefIsInitializedFalseErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check is browser is initialized
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user