Files
cefsharp/CefSharp/RequestContextExtensions.cs
T
Alex Maitland 02e3084af3 Add Chromium Extension Support (#2613)
* Add Chromium Extension Support

Add IRequestContext.LoadExtension
Add IExtensionHandler
Add IExtension
Add example (import from cefclient) - was added to CefSharp.WinForms.Example projct
Add RequestContextExtensions - to make loading an extension slightly easier
2018-12-31 13:12:10 +10:00

47 lines
2.3 KiB
C#

// Copyright © 2015 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.
using System.IO;
namespace CefSharp
{
public static class RequestContextExtensions
{
/// <summary>
/// Load an extension from the given directory.
/// For further details see <seealso cref="IRequestContext.LoadExtension(string, string, IExtensionHandler)"/>
/// </summary>
/// <param name="requestContext">request context</param>
/// <param name="rootDirectory">absolute path to the directory that contains the extension to be loaded.</param>
/// <param name="handler">handle events related to browser extensions</param>
public static void LoadExtensionFromDirectory(this IRequestContext requestContext, string rootDirectory, IExtensionHandler handler)
{
requestContext.LoadExtension(Path.GetFullPath(rootDirectory), null, handler);
}
/// <summary>
/// Load extension(s) from the given directory. This methods obtains all the sub directories of <paramref name="rootDirectory"/>
/// and calls <see cref="IRequestContext.LoadExtension(string, string, IExtensionHandler)"/> if manifest.json
/// is found in the sub folder.
/// For further details see <seealso cref="IRequestContext.LoadExtension(string, string, IExtensionHandler)"/>
/// </summary>
/// <param name="requestContext">request context</param>
/// <param name="rootDirectory">absolute path to the directory that contains the extension(s) to be loaded.</param>
/// <param name="handler">handle events related to browser extensions</param>
public static void LoadExtensionsFromDirectory(this IRequestContext requestContext, string rootDirectory, IExtensionHandler handler)
{
var fullPath = Path.GetFullPath(rootDirectory);
foreach (var dir in Directory.GetDirectories(fullPath))
{
//Check the directory has a manifest.json, if so call load
if (File.Exists(Path.Combine(dir, "manifest.json")))
{
requestContext.LoadExtension(dir, null, handler);
}
}
}
}
}