Skip to content

Commit f8349db

Browse files
committed
Cef.h - Remove ThrowIfCefNotInitialized
As IsInitialized is set when CefInitialize returns and it appears to be possible the OnContextInitialized is called before it returns then this exception wasn't going to work. Testing with Cef.GetGlobalRequestContext and Cef.GetGlobalCookieManager and they both return null if called before Cef.Initialize So it shouldn't be possible to actually access the cookie manager/RequestContext. Improved the xml doc Resolves #2600
1 parent 49e543f commit f8349db

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

CefSharp.Core/Cef.h

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ namespace CefSharp
3232
{
3333
public ref class Cef sealed
3434
{
35-
#define ThrowIfCefNotInitialized() if (!_initialized) throw gcnew Exception(__FUNCTION__ + " requires that CefRequestContext be initialized first. The earlier possible place to execute " + __FUNCTION__ + " is in IBrowserProcessHandler.OnContextInitialized. Alternative use the ChromiumWebBrowser BrowserInitialized (OffScreen) or IsBrowserInitializedChanged (WinForms/WPF) events.");
36-
3735
private:
3836
static Object^ _sync;
3937

@@ -324,8 +322,6 @@ namespace CefSharp
324322
String^ targetDomain,
325323
bool allowTargetSubdomains)
326324
{
327-
//ThrowIfCefNotInitialized();
328-
329325
return CefAddCrossOriginWhitelistEntry(
330326
StringUtils::ToNative(sourceOrigin),
331327
StringUtils::ToNative(targetProtocol),
@@ -350,8 +346,6 @@ namespace CefSharp
350346
bool allowTargetSubdomains)
351347

352348
{
353-
//ThrowIfCefNotInitialized();
354-
355349
return CefRemoveCrossOriginWhitelistEntry(
356350
StringUtils::ToNative(sourceOrigin),
357351
StringUtils::ToNative(targetProtocol),
@@ -366,24 +360,24 @@ namespace CefSharp
366360
/// </remarks>
367361
static bool ClearCrossOriginWhitelist()
368362
{
369-
//ThrowIfCefNotInitialized();
370-
371363
return CefClearCrossOriginWhitelist();
372364
}
373365

374366
/// <summary>
375-
/// Returns the global cookie manager.
367+
/// Returns the global cookie manager. By default data will be stored at CefSettings.CachePath if specified or in memory otherwise.
368+
/// Using this method is equivalent to calling Cef.GetGlobalRequestContext().GetDefaultCookieManager()
369+
/// The earlier possible place to access the ICookieManager is in IBrowserProcessHandler.OnContextInitialized.
370+
/// Alternative use the ChromiumWebBrowser BrowserInitialized (OffScreen) or IsBrowserInitializedChanged (WinForms/WPF) events.
376371
/// </summary>
377-
/// <returns>A the global cookie manager</returns>
372+
/// <returns>A the global cookie manager or null if the RequestContext has not yet been initialized.</returns>
378373
static ICookieManager^ GetGlobalCookieManager()
379374
{
380-
//ThrowIfCefNotInitialized();
381-
382375
auto cookieManager = CefCookieManager::GetGlobalManager(NULL);
383376
if (cookieManager.get())
384377
{
385378
return gcnew CookieManager(cookieManager);
386379
}
380+
387381
return nullptr;
388382
}
389383

@@ -398,13 +392,12 @@ namespace CefSharp
398392
/// <returns>A blocking cookie manager</returns>
399393
static ICookieManager^ GetBlockingCookieManager()
400394
{
401-
//ThrowIfCefNotInitialized();
402-
403395
auto cookieManager = CefCookieManager::GetBlockingManager();
404396
if (cookieManager.get())
405397
{
406398
return gcnew CookieManager(cookieManager);
407399
}
400+
408401
return nullptr;
409402
}
410403

@@ -488,13 +481,13 @@ namespace CefSharp
488481
}
489482

490483
/// <summary>
491-
/// Clear all registered scheme handler factories.
484+
/// Clear all scheme handler factories registered with the global request context.
485+
/// Returns false on error. This function may be called on any thread in the browser process.
486+
/// Using this function is equivalent to calling Cef.GetGlobalRequestContext().ClearSchemeHandlerFactories().
492487
/// </summary>
493488
/// <returns>Returns false on error.</returns>
494489
static bool ClearSchemeHandlerFactories()
495490
{
496-
//ThrowIfCefNotInitialized();
497-
498491
return CefClearSchemeHandlerFactories();
499492
}
500493

@@ -503,8 +496,6 @@ namespace CefSharp
503496
/// </summary>
504497
static void VisitWebPluginInfo(IWebPluginInfoVisitor^ visitor)
505498
{
506-
//ThrowIfCefNotInitialized();
507-
508499
CefVisitWebPluginInfo(new PluginVisitor(visitor));
509500
}
510501

@@ -515,8 +506,6 @@ namespace CefSharp
515506
/// <returns>Returns List of <see cref="Plugin"/> structs.</returns>
516507
static Task<List<WebPluginInfo^>^>^ GetPlugins()
517508
{
518-
//ThrowIfCefNotInitialized();
519-
520509
auto taskVisitor = gcnew TaskWebPluginInfoVisitor();
521510
CefRefPtr<PluginVisitor> visitor = new PluginVisitor(taskVisitor);
522511

@@ -530,8 +519,6 @@ namespace CefSharp
530519
/// </summary>
531520
static void RefreshWebPlugins()
532521
{
533-
//ThrowIfCefNotInitialized();
534-
535522
CefRefreshWebPlugins();
536523
}
537524

@@ -541,8 +528,6 @@ namespace CefSharp
541528
/// <param name="path">Path (directory + file).</param>
542529
static void UnregisterInternalWebPlugin(String^ path)
543530
{
544-
//ThrowIfCefNotInitialized();
545-
546531
CefUnregisterInternalWebPlugin(StringUtils::ToNative(path));
547532
}
548533

@@ -567,12 +552,12 @@ namespace CefSharp
567552

568553
/// <summary>
569554
/// Gets the Global Request Context. Make sure to Dispose of this object when finished.
555+
/// The earlier possible place to access the IRequestContext is in IBrowserProcessHandler.OnContextInitialized.
556+
/// Alternative use the ChromiumWebBrowser BrowserInitialized (OffScreen) or IsBrowserInitializedChanged (WinForms/WPF) events.
570557
/// </summary>
571-
/// <returns>Returns the global request context or null.</returns>
558+
/// <returns>Returns the global request context or null if the RequestContext has not been initialized yet.</returns>
572559
static IRequestContext^ GetGlobalRequestContext()
573560
{
574-
//ThrowIfCefNotInitialized();
575-
576561
auto context = CefRequestContext::GetGlobalContext();
577562

578563
if (context.get())

0 commit comments

Comments
 (0)