-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
CefSharp 43
CefSharp 43 provides much better access to the underlying CEF API
and as such there are many changes over version 41
. A number of changes will be required when updating. This document provides some information.
-
Expose
IFrame
andIBrowser
interfaces. -
Access to the underlying popup browser wrappers.
-
New CEF binary files need to be included with
libcef.dll
, etc.: -
natives_blob.bin
-
snapshot_blob.bin
-
Breaking changes for many handlers
-
Built-in PDF viewer removed. See #1144 for workaround.
-
List methods that will be deprecated
-
Include information on any areas that were rewritten, e.g. resource handling
PR's tagged as breaking change
can be found at https://github.com/cefsharp/CefSharp/issues?utf8=%E2%9C%93&q=label%3Abreaking-change+is%3Amerged
- WCF can now be disabled via
CefSharpSettings.WcfEnabled = false;
. Disables JavaScript object binding. Native ChromeIPC
used instead for allIPC
,ExecuteScriptAsync
andEvaluateScriptAsync
.
ISchemeHandlerFactory
//To upgrade: add new parameters. Code logic does not need to change.
public SchemeHandlerFactory: ISchemeHandlerFactory
{
//Old
ISchemeHandler Create()
{
return handler;
}
//New
public IResourceHandler Create(IBrowser browser, IFrame frame, string schemeName, IRequest request)
{
//To read a file of disk no need to implement your own handler
if (schemeName == SchemeName && request.Url.EndsWith("CefSharp.Core.xml", System.StringComparison.OrdinalIgnoreCase))
{
//Display the CefSharp.Core.xml file in the browser
return ResourceHandler.FromFileName("CefSharp.Core.xml", ".xml");
}
return new CefSharpSchemeHandler();
}
}
**ISchemeHandler **
//NOTE: ISchemeHandler renamed to IResourceHandler (shares code with ResourceHandler implementation)
public class CefSharpSchemeHandler : IResourceHandler
{
//Old:
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback)
{
//Processing goes here...
return true;
}
//New:
//To upgrade: store the response stream in a class field, then call callback.Continue() instead of the old `requestCompletedCallback`.
//See here for example of new usage: https://github.com/cefsharp/CefSharp/blob/cefsharp/43/CefSharp.Example/CefSharpSchemeHandler.cs
public bool ProcessRequestAsync(IRequest request, ICallback callback)
{
Task.Run(() =>
{
// Base to dispose of callback as it wraps a managed resource
using (callback)
{
//Perform processing here
// When processing complete call continue
callback.Continue();
}
});
return true;
}
public Stream GetResponse(IResponse response, out long responseLength, out string redirectUrl)
{
//How long is your stream?
responseLength = stream.Length;
//Set to null if not redirecting to a different url
redirectUrl = null;
//Set response related stuff here
response.StatusCode = (int)HttpStatusCode.OK;
response.StatusText = "OK";
response.MimeType = mimeType;
//Return your populated stream
return stream;
}
}
IKeyboardHandler
Old: public bool OnKeyEvent(IWebBrowser browserControl, KeyType type, int windowsKeyCode, CefEventFlags modifiers, bool isSystemKey)
New: bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut);
To upgrade: add new parameters IBrowser browser
, int nativeKeyCode
and ref bool isKeyboardShortcut
. Code logic does not need to change.