mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 03:32:37 +00:00
Refactor OnContextInitialized out as part of IBrowserProcessHandler interface
Add OnScheduleMessagePumpWork for use with integrating into existing message loop - probably better for WinForms integration, will look at providing an example later
This commit is contained in:
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CefSharp.Example.Handlers;
|
||||
using CefSharp.Example.Properties;
|
||||
using CefSharp.Example.Proxy;
|
||||
using CefSharp.Internals;
|
||||
@@ -165,24 +166,7 @@ namespace CefSharp.Example
|
||||
|
||||
settings.FocusedNodeChangedEnabled = true;
|
||||
|
||||
//The Request Context has been initialized, you can now set preferences, like proxy server settings
|
||||
Cef.OnContextInitialized = delegate
|
||||
{
|
||||
var cookieManager = Cef.GetGlobalCookieManager();
|
||||
cookieManager.SetStoragePath("cookies", true);
|
||||
cookieManager.SetSupportedSchemes("custom");
|
||||
|
||||
//Dispose of context when finished - preferable not to keep a reference if possible.
|
||||
using (var context = Cef.GetGlobalRequestContext())
|
||||
{
|
||||
string errorMessage;
|
||||
//You can set most preferences using a `.` notation rather than having to create a complex set of dictionaries.
|
||||
//The default is true, you can change to false to disable
|
||||
context.SetPreference("webkit.webprefs.plugins_enabled", true, out errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
if (!Cef.Initialize(settings, shutdownOnProcessExit: true, performDependencyCheck: !DebuggingSubProcess))
|
||||
if (!Cef.Initialize(settings, performDependencyCheck: !DebuggingSubProcess, browserProcessHandler: new BrowserProcessHandler()))
|
||||
{
|
||||
throw new Exception("Unable to Initialize Cef");
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@
|
||||
<Compile Include="FlashResourceHandler.cs" />
|
||||
<Compile Include="FlashResourceHandlerFactory.cs" />
|
||||
<Compile Include="Filters\PassThruResponseFilter.cs" />
|
||||
<Compile Include="Handlers\BrowserProcessHandler.cs" />
|
||||
<Compile Include="InMemorySchemeAndResourceHandlerFactory.cs" />
|
||||
<Compile Include="ScriptedMethodsBoundObject.cs" />
|
||||
<Compile Include="ExceptionTestBoundObject.cs" />
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright © 2010-2016 The CefSharp Authors. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
namespace CefSharp.Example.Handlers
|
||||
{
|
||||
public class BrowserProcessHandler : IBrowserProcessHandler
|
||||
{
|
||||
void IBrowserProcessHandler.OnContextInitialized()
|
||||
{
|
||||
//The Request Context has been initialized, you can now set preferences, like proxy server settings
|
||||
var cookieManager = Cef.GetGlobalCookieManager();
|
||||
cookieManager.SetStoragePath("cookies", true);
|
||||
cookieManager.SetSupportedSchemes("custom");
|
||||
|
||||
//Dispose of context when finished - preferable not to keep a reference if possible.
|
||||
using (var context = Cef.GetGlobalRequestContext())
|
||||
{
|
||||
string errorMessage;
|
||||
//You can set most preferences using a `.` notation rather than having to create a complex set of dictionaries.
|
||||
//The default is true, you can change to false to disable
|
||||
context.SetPreference("webkit.webprefs.plugins_enabled", true, out errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void IBrowserProcessHandler.OnScheduleMessagePumpWork(long delay)
|
||||
{
|
||||
//TODO: Schedule work on the UI thread - call Cef.DoMessageLoopWork
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user