Projektdateien hinzufügen.
This commit is contained in:
@@ -0,0 +1,235 @@
|
||||
namespace VideoBrowser.Controls.CefSharpBrowser.Helpers
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
/// <summary>
|
||||
/// Internals are mostly from here: http://www.codeproject.com/Articles/2532/Obtaining-and-managing-file-and-folder-icons-using
|
||||
/// Caches all results.
|
||||
/// </summary>
|
||||
public static class ApplicationIconHelper
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private static readonly Dictionary<string, ImageSource> _largeIconCache = new Dictionary<string, ImageSource>();
|
||||
|
||||
private static readonly Dictionary<string, ImageSource> _smallIconCache = new Dictionary<string, ImageSource>();
|
||||
|
||||
#endregion Fields
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Get an icon for a given filename.
|
||||
/// </summary>
|
||||
/// <param name="fileName">any filename.</param>
|
||||
/// <param name="large">16x16 or 32x32 icon.</param>
|
||||
/// <returns>null if path is null, otherwise - an icon.</returns>
|
||||
public static ImageSource FindIconForFilename(this string fileName, bool large)
|
||||
{
|
||||
var extension = Path.GetExtension(fileName);
|
||||
if (extension == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var cache = large ? _largeIconCache : _smallIconCache;
|
||||
ImageSource icon;
|
||||
if (cache.TryGetValue(extension, out icon))
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
|
||||
icon = IconReader.GetFileIcon(fileName, large ? IconReader.IconSize.Large : IconReader.IconSize.Small, false).ToImageSource();
|
||||
cache.Add(extension, icon);
|
||||
return icon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// http://stackoverflow.com/a/6580799/1943849.
|
||||
/// </summary>
|
||||
/// <param name="icon">The icon<see cref="Icon"/>.</param>
|
||||
/// <returns>The <see cref="ImageSource"/>.</returns>
|
||||
private static ImageSource ToImageSource(this Icon icon)
|
||||
{
|
||||
var imageSource = Imaging.CreateBitmapSourceFromHIcon(
|
||||
icon.Handle,
|
||||
Int32Rect.Empty,
|
||||
BitmapSizeOptions.FromEmptyOptions());
|
||||
return imageSource;
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
|
||||
/// <summary>
|
||||
/// Provides static methods to read system icons for both folders and files.
|
||||
/// </summary>
|
||||
private static class IconReader
|
||||
{
|
||||
#region Enums
|
||||
|
||||
/// <summary>
|
||||
/// Options to specify the size of icons to return.
|
||||
/// </summary>
|
||||
public enum IconSize
|
||||
{
|
||||
/// <summary>
|
||||
/// Specify large icon - 32 pixels by 32 pixels.
|
||||
/// </summary>
|
||||
Large = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Specify small icon - 16 pixels by 16 pixels.
|
||||
/// </summary>
|
||||
Small = 1
|
||||
}
|
||||
|
||||
#endregion Enums
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Returns an icon for a given file - indicated by the name parameter.
|
||||
/// </summary>
|
||||
/// <param name="name">Pathname for file.</param>
|
||||
/// <param name="size">Large or small.</param>
|
||||
/// <param name="linkOverlay">Whether to include the link icon.</param>
|
||||
/// <returns>System.Drawing.Icon.</returns>
|
||||
public static Icon GetFileIcon(string name, IconSize size, bool linkOverlay)
|
||||
{
|
||||
var shfi = new Shell32.Shfileinfo();
|
||||
var flags = Shell32.ShgfiIcon | Shell32.ShgfiUsefileattributes;
|
||||
if (linkOverlay)
|
||||
{
|
||||
flags += Shell32.ShgfiLinkoverlay;
|
||||
}
|
||||
|
||||
/* Check the size specified for return. */
|
||||
if (IconSize.Small == size)
|
||||
{
|
||||
flags += Shell32.ShgfiSmallicon;
|
||||
}
|
||||
else
|
||||
{
|
||||
flags += Shell32.ShgfiLargeicon;
|
||||
}
|
||||
|
||||
Shell32.SHGetFileInfo(name,
|
||||
Shell32.FileAttributeNormal,
|
||||
ref shfi,
|
||||
(uint)Marshal.SizeOf(shfi),
|
||||
flags);
|
||||
// Copy (clone) the returned icon to a new object, thus allowing us to clean-up properly
|
||||
var icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();
|
||||
User32.DestroyIcon(shfi.hIcon); // Cleanup
|
||||
return icon;
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps necessary Shell32.dll structures and functions required to retrieve Icon Handles using SHGetFileInfo. Code
|
||||
/// courtesy of MSDN Cold Rooster Consulting case study.
|
||||
/// </summary>
|
||||
private static class Shell32
|
||||
{
|
||||
#region Constants
|
||||
|
||||
public const uint FileAttributeNormal = 0x00000080;
|
||||
|
||||
public const uint ShgfiIcon = 0x000000100;// get icon
|
||||
|
||||
public const uint ShgfiLargeicon = 0x000000000;// get large icon
|
||||
|
||||
public const uint ShgfiLinkoverlay = 0x000008000;// put a link overlay on icon
|
||||
|
||||
public const uint ShgfiSmallicon = 0x000000001;// get small icon
|
||||
|
||||
public const uint ShgfiUsefileattributes = 0x000000010;// use passed dwFileAttribute
|
||||
|
||||
private const int MaxPath = 256;
|
||||
|
||||
#endregion Constants
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// The SHGetFileInfo.
|
||||
/// </summary>
|
||||
/// <param name="pszPath">The pszPath<see cref="string"/>.</param>
|
||||
/// <param name="dwFileAttributes">The dwFileAttributes<see cref="uint"/>.</param>
|
||||
/// <param name="psfi">The psfi<see cref="Shfileinfo"/>.</param>
|
||||
/// <param name="cbFileInfo">The cbFileInfo<see cref="uint"/>.</param>
|
||||
/// <param name="uFlags">The uFlags<see cref="uint"/>.</param>
|
||||
/// <returns>The <see cref="IntPtr"/>.</returns>
|
||||
[DllImport("Shell32.dll")]
|
||||
public static extern IntPtr SHGetFileInfo(
|
||||
string pszPath,
|
||||
uint dwFileAttributes,
|
||||
ref Shfileinfo psfi,
|
||||
uint cbFileInfo,
|
||||
uint uFlags
|
||||
);
|
||||
|
||||
#endregion Methods
|
||||
|
||||
/// <summary>
|
||||
/// Defines the <see cref="Shfileinfo" />.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Shfileinfo
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const int Namesize = 80;
|
||||
|
||||
#endregion Constants
|
||||
|
||||
#region Fields
|
||||
|
||||
public readonly IntPtr hIcon;
|
||||
|
||||
private readonly uint dwAttributes;
|
||||
|
||||
private readonly int iIcon;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MaxPath)]
|
||||
private readonly string szDisplayName;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Namesize)]
|
||||
private readonly string szTypeName;
|
||||
|
||||
#endregion Fields
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps necessary functions imported from User32.dll. Code courtesy of MSDN Cold Rooster Consulting example.
|
||||
/// </summary>
|
||||
private static class User32
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to function required to delete handle. This method is used internally
|
||||
/// and is not required to be called separately.
|
||||
/// </summary>
|
||||
/// <param name="hIcon">Pointer to icon handle.</param>
|
||||
/// <returns>N/A.</returns>
|
||||
[DllImport("User32.dll")]
|
||||
public static extern int DestroyIcon(IntPtr hIcon);
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
// Copyright © 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 VideoBrowser.Controls.CefSharpBrowser.Helpers
|
||||
{
|
||||
using CefSharp;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the <see cref="BrowserProcessHandler" />.
|
||||
/// </summary>
|
||||
public class BrowserProcessHandler : IBrowserProcessHandler
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// The interval between calls to Cef.DoMessageLoopWork
|
||||
/// </summary>
|
||||
protected const int SixtyTimesPerSecond = 1000 / 60;// 60fps
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of milliseconds we're willing to wait between calls to OnScheduleMessagePumpWork().
|
||||
/// </summary>
|
||||
protected const int ThirtyTimesPerSecond = 1000 / 30;//30fps
|
||||
|
||||
#endregion Constants
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// The Dispose.
|
||||
/// </summary>
|
||||
public virtual void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The OnScheduleMessagePumpWork.
|
||||
/// </summary>
|
||||
/// <param name="delay">The delay<see cref="int"/>.</param>
|
||||
protected virtual void OnScheduleMessagePumpWork(int delay)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The OnContextInitialized.
|
||||
/// </summary>
|
||||
void IBrowserProcessHandler.OnContextInitialized()
|
||||
{
|
||||
//The Global CookieManager has been initialized, you can now set cookies
|
||||
var cookieManager = Cef.GetGlobalCookieManager();
|
||||
////cookieManager.SetSupportedSchemes(new string[] { "custom" }, true);
|
||||
if (cookieManager.SetCookie("custom://cefsharp/home.html", new Cookie
|
||||
{
|
||||
Name = "CefSharpTestCookie",
|
||||
Value = "ILikeCookies",
|
||||
Expires = DateTime.Now.AddDays(1)
|
||||
}))
|
||||
{
|
||||
cookieManager.VisitUrlCookiesAsync("custom://cefsharp/home.html", false).ContinueWith(previous =>
|
||||
{
|
||||
if (previous.Status == TaskStatus.RanToCompletion)
|
||||
{
|
||||
var cookies = previous.Result;
|
||||
|
||||
foreach (var cookie in cookies)
|
||||
{
|
||||
Debug.WriteLine("CookieName: " + cookie.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("No Cookies found");
|
||||
}
|
||||
});
|
||||
|
||||
cookieManager.VisitAllCookiesAsync().ContinueWith(t =>
|
||||
{
|
||||
if (t.Status == TaskStatus.RanToCompletion)
|
||||
{
|
||||
var cookies = t.Result;
|
||||
|
||||
foreach (var cookie in cookies)
|
||||
{
|
||||
Debug.WriteLine("CookieName: " + cookie.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("No Cookies found");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//The Request Context has been initialized, you can now set preferences, like proxy server settings
|
||||
//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);
|
||||
|
||||
//string error;
|
||||
//var dicts = new List<string> { "en-GB", "en-US" };
|
||||
//var success = context.SetPreference("spellcheck.dictionaries", dicts, out error);
|
||||
|
||||
//The no-proxy-server flag is set in CefExample.cs class, you'll have to remove that before you can test
|
||||
//this code out
|
||||
//var v = new Dictionary<string, string>
|
||||
//{
|
||||
// ["mode"] = "fixed_servers",
|
||||
// ["server"] = "scheme://host:port"
|
||||
//};
|
||||
//success = context.SetPreference("proxy", v, out errorMessage);
|
||||
|
||||
//It's possible to register a scheme handler for the default http and https schemes
|
||||
//In this example we register the FolderSchemeHandlerFactory for https://cefsharp.example
|
||||
//Best to include the domain name, so only requests for that domain are forwarded to your scheme handler
|
||||
//It is possible to intercept all requests for a scheme, including the built in http/https ones, be very careful doing this!
|
||||
////var folderSchemeHandlerExample = new FolderSchemeHandlerFactory(rootFolder: @"..\..\..\..\CefSharp.Example\Resources",
|
||||
//// hostName: "cefsharp.example", //Optional param no hostname checking if null
|
||||
//// defaultPage: "home.html"); //Optional param will default to index.html
|
||||
|
||||
////context.RegisterSchemeHandlerFactory("https", "cefsharp.example", folderSchemeHandlerExample);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The OnScheduleMessagePumpWork.
|
||||
/// </summary>
|
||||
/// <param name="delay">The delay<see cref="long"/>.</param>
|
||||
void IBrowserProcessHandler.OnScheduleMessagePumpWork(long delay)
|
||||
{
|
||||
//If the delay is greater than the Maximum then use ThirtyTimesPerSecond
|
||||
//instead - we do this to achieve a minimum number of FPS
|
||||
if (delay > ThirtyTimesPerSecond)
|
||||
{
|
||||
delay = ThirtyTimesPerSecond;
|
||||
}
|
||||
OnScheduleMessagePumpWork((int)delay);
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
namespace VideoBrowser.Controls.CefSharpBrowser.Helpers
|
||||
{
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using VideoBrowser.Common;
|
||||
using VideoBrowser.Controls.CefSharpBrowser.Models;
|
||||
using VideoBrowser.Controls.CefSharpBrowser.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the <see cref="BrowserSettingsHelper" />.
|
||||
/// </summary>
|
||||
internal static class BrowserSettingsHelper
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes static members of the <see cref="BrowserSettingsHelper"/> class.
|
||||
/// </summary>
|
||||
static BrowserSettingsHelper()
|
||||
{
|
||||
var appName = Assembly.GetExecutingAssembly().GetName().Name;
|
||||
var userAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
UserJsonSettingsPath = Path.Combine(userAppDataPath, $@"{appName}\BrowserSettings.json");
|
||||
}
|
||||
|
||||
#endregion Constructors
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UserJsonSettingsPath.
|
||||
/// </summary>
|
||||
public static string UserJsonSettingsPath { get; }
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// The Load.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="BrowserSettings"/>.</returns>
|
||||
internal static BrowserSettings Load()
|
||||
{
|
||||
Logger.Info($"Loading Browser setting {UserJsonSettingsPath}");
|
||||
if (!File.Exists(UserJsonSettingsPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (StreamReader file = File.OpenText(UserJsonSettingsPath))
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
var browserSettings = (BrowserSettings)serializer.Deserialize(file, typeof(BrowserSettings));
|
||||
return browserSettings;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error($"Error Loading Browser Setting: {e.Message}");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Save.
|
||||
/// </summary>
|
||||
/// <param name="settings">The settings<see cref="BrowserSettings"/>.</param>
|
||||
/// <param name="browserModel">The browserModel<see cref="WebBrowserTabControlViewModel"/>.</param>
|
||||
internal static void Save(BrowserSettings settings, WebBrowserTabControlViewModel browserModel)
|
||||
{
|
||||
settings.BookmarkModels.Clear();
|
||||
settings.DownloadItems.Clear();
|
||||
settings.TabSettingModels.Clear();
|
||||
foreach (var tabItem in browserModel.TabItems)
|
||||
{
|
||||
if (tabItem.Content is FrameworkElement element && element.DataContext is VideoBrowserViewModel videoModel)
|
||||
{
|
||||
var tabModel = new TabSettingsModel
|
||||
{
|
||||
Title = videoModel.Header,
|
||||
Url = videoModel.Url
|
||||
};
|
||||
|
||||
settings.TabSettingModels.Add(tabModel);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var downloadItem in browserModel.GlobalBrowserData.DownloadItemModels)
|
||||
{
|
||||
if (downloadItem.Status == "Completed")
|
||||
{
|
||||
settings.DownloadItems.Add(new DownloadItemModel(downloadItem));
|
||||
}
|
||||
}
|
||||
|
||||
settings.SelectedTabSettingIndex = browserModel.SelectedTabIndex;
|
||||
var settingsFolder = Path.GetDirectoryName(UserJsonSettingsPath);
|
||||
if (!Directory.Exists(settingsFolder))
|
||||
{
|
||||
Directory.CreateDirectory(settingsFolder);
|
||||
}
|
||||
|
||||
var serializer = new JsonSerializer();
|
||||
serializer.Converters.Add(new JavaScriptDateTimeConverter());
|
||||
serializer.NullValueHandling = NullValueHandling.Ignore;
|
||||
|
||||
using (var sw = new StreamWriter(UserJsonSettingsPath))
|
||||
using (var writer = new JsonTextWriter(sw))
|
||||
{
|
||||
serializer.Serialize(writer, settings);
|
||||
}
|
||||
|
||||
Logger.Info($"Browser setting is saved in {UserJsonSettingsPath}");
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
300
VideoBrowser/Controls/CefSharpBrowser/Helpers/CefConfig.cs
Normal file
300
VideoBrowser/Controls/CefSharpBrowser/Helpers/CefConfig.cs
Normal file
@@ -0,0 +1,300 @@
|
||||
// Copyright © 2014 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 VideoBrowser.Controls.CefSharpBrowser.Helpers
|
||||
{
|
||||
using CefSharp;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
public static class CefConfig
|
||||
{
|
||||
//TODO: Revert after https://bitbucket.org/chromiumembedded/cef/issues/2685/networkservice-custom-scheme-unable-to
|
||||
//has been fixed.
|
||||
public const string ExampleDomain = "cefsharp.example";
|
||||
|
||||
public const string BaseUrl = "https://" + ExampleDomain;
|
||||
public const string DefaultUrl = BaseUrl + "/home.html";
|
||||
public const string BindingTestUrl = BaseUrl + "/BindingTest.html";
|
||||
public const string BindingTestSingleUrl = BaseUrl + "/BindingTestSingle.html";
|
||||
public const string BindingTestsAsyncTaskUrl = BaseUrl + "/BindingTestsAsyncTask.html";
|
||||
public const string LegacyBindingTestUrl = BaseUrl + "/LegacyBindingTest.html";
|
||||
public const string PostMessageTestUrl = BaseUrl + "/PostMessageTest.html";
|
||||
public const string PluginsTestUrl = BaseUrl + "/plugins.html";
|
||||
public const string PopupTestUrl = BaseUrl + "/PopupTest.html";
|
||||
public const string TooltipTestUrl = BaseUrl + "/TooltipTest.html";
|
||||
public const string BasicSchemeTestUrl = BaseUrl + "/SchemeTest.html";
|
||||
public const string ResponseFilterTestUrl = BaseUrl + "/ResponseFilterTest.html";
|
||||
public const string DraggableRegionTestUrl = BaseUrl + "/DraggableRegionTest.html";
|
||||
public const string DragDropCursorsTestUrl = BaseUrl + "/DragDropCursorsTest.html";
|
||||
public const string CssAnimationTestUrl = BaseUrl + "/CssAnimationTest.html";
|
||||
public const string CdmSupportTestUrl = BaseUrl + "/CdmSupportTest.html";
|
||||
public const string BindingApiCustomObjectNameTestUrl = BaseUrl + "/BindingApiCustomObjectNameTest.html";
|
||||
public const string TestResourceUrl = "http://test/resource/load";
|
||||
public const string RenderProcessCrashedUrl = "http://processcrashed";
|
||||
public const string TestUnicodeResourceUrl = "http://test/resource/loadUnicode";
|
||||
public const string PopupParentUrl = "http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_close";
|
||||
|
||||
// Use when debugging the actual SubProcess, to make breakpoints etc. inside that project work.
|
||||
private static readonly bool DebuggingSubProcess = Debugger.IsAttached;
|
||||
|
||||
private static string PluginInformation = "";
|
||||
|
||||
public static void Init(CefSettingsBase settings, IBrowserProcessHandler browserProcessHandler)
|
||||
{
|
||||
// Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys
|
||||
// Environment.SetEnvironmentVariable("GOOGLE_API_KEY", "");
|
||||
// Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", "");
|
||||
// Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET", "");
|
||||
|
||||
// Widevine CDM registration - pass in directory where Widevine CDM binaries and manifest.json are located.
|
||||
// For more information on support for DRM content with Widevine see: https://github.com/cefsharp/CefSharp/issues/1934
|
||||
//Cef.RegisterWidevineCdm(@".\WidevineCdm");
|
||||
|
||||
//Chromium Command Line args
|
||||
//http://peter.sh/experiments/chromium-command-line-switches/
|
||||
//NOTE: Not all relevant in relation to `CefSharp`, use for reference purposes only.
|
||||
//CEF specific command line args
|
||||
//https://bitbucket.org/chromiumembedded/cef/src/master/libcef/common/cef_switches.cc?fileviewer=file-view-default
|
||||
//IMPORTANT: For enabled/disabled command line arguments like disable-gpu specifying a value of "0" like
|
||||
//settings.CefCommandLineArgs.Add("disable-gpu", "0"); will have no effect as the second argument is ignored.
|
||||
|
||||
settings.RemoteDebuggingPort = 8088;
|
||||
//The location where cache data will be stored on disk. If empty an in-memory cache will be used for some features and a temporary disk cache for others.
|
||||
//HTML5 databases such as localStorage will only persist across sessions if a cache path is specified.
|
||||
settings.RootCachePath = Path.GetFullPath("cache");
|
||||
//If non-null then CachePath must be equal to or a child of RootCachePath
|
||||
//We're using a sub folder.
|
||||
//
|
||||
settings.CachePath = Path.GetFullPath("cache\\global");
|
||||
//settings.UserAgent = "CefSharp Browser" + Cef.CefSharpVersion; // Example User Agent
|
||||
//settings.CefCommandLineArgs.Add("renderer-process-limit", "1");
|
||||
//settings.CefCommandLineArgs.Add("renderer-startup-dialog");
|
||||
//settings.CefCommandLineArgs.Add("enable-media-stream"); //Enable WebRTC
|
||||
//settings.CefCommandLineArgs.Add("no-proxy-server"); //Don't use a proxy server, always make direct connections. Overrides any other proxy server flags that are passed.
|
||||
//settings.CefCommandLineArgs.Add("debug-plugin-loading"); //Dumps extra logging about plugin loading to the log file.
|
||||
//settings.CefCommandLineArgs.Add("disable-plugins-discovery"); //Disable discovering third-party plugins. Effectively loading only ones shipped with the browser plus third-party ones as specified by --extra-plugin-dir and --load-plugin switches
|
||||
//settings.CefCommandLineArgs.Add("enable-system-flash"); //Automatically discovered and load a system-wide installation of Pepper Flash.
|
||||
//settings.CefCommandLineArgs.Add("allow-running-insecure-content"); //By default, an https page cannot run JavaScript, CSS or plugins from http URLs. This provides an override to get the old insecure behavior. Only available in 47 and above.
|
||||
//https://peter.sh/experiments/chromium-command-line-switches/#disable-site-isolation-trials
|
||||
//settings.CefCommandLineArgs.Add("disable-site-isolation-trials");
|
||||
|
||||
//settings.CefCommandLineArgs.Add("enable-logging"); //Enable Logging for the Renderer process (will open with a cmd prompt and output debug messages - use in conjunction with setting LogSeverity = LogSeverity.Verbose;)
|
||||
//settings.LogSeverity = LogSeverity.Verbose; // Needed for enable-logging to output messages
|
||||
|
||||
//settings.CefCommandLineArgs.Add("disable-extensions"); //Extension support can be disabled
|
||||
//settings.CefCommandLineArgs.Add("disable-pdf-extension"); //The PDF extension specifically can be disabled
|
||||
|
||||
//Load the pepper flash player that comes with Google Chrome - may be possible to load these values from the registry and query the dll for it's version info (Step 2 not strictly required it seems)
|
||||
//settings.CefCommandLineArgs.Add("ppapi-flash-path", @"C:\Program Files (x86)\Google\Chrome\Application\47.0.2526.106\PepperFlash\pepflashplayer.dll"); //Load a specific pepper flash version (Step 1 of 2)
|
||||
//settings.CefCommandLineArgs.Add("ppapi-flash-version", "20.0.0.228"); //Load a specific pepper flash version (Step 2 of 2)
|
||||
|
||||
//Audo play example
|
||||
//settings.CefCommandLineArgs["autoplay-policy"] = "no-user-gesture-required";
|
||||
|
||||
//NOTE: For OSR best performance you should run with GPU disabled:
|
||||
// `--disable-gpu --disable-gpu-compositing --enable-begin-frame-scheduling`
|
||||
// (you'll loose WebGL support but gain increased FPS and reduced CPU usage).
|
||||
// http://magpcss.org/ceforum/viewtopic.php?f=6&t=13271#p27075
|
||||
//https://bitbucket.org/chromiumembedded/cef/commits/e3c1d8632eb43c1c2793d71639f3f5695696a5e8
|
||||
|
||||
//NOTE: The following function will set all three params
|
||||
//settings.SetOffScreenRenderingBestPerformanceArgs();
|
||||
//settings.CefCommandLineArgs.Add("disable-gpu");
|
||||
//settings.CefCommandLineArgs.Add("disable-gpu-compositing");
|
||||
//settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling");
|
||||
|
||||
//settings.CefCommandLineArgs.Add("disable-gpu-vsync"); //Disable Vsync
|
||||
|
||||
// The following options control accessibility state for all frames.
|
||||
// These options only take effect if accessibility state is not set by IBrowserHost.SetAccessibilityState call.
|
||||
// --force-renderer-accessibility enables browser accessibility.
|
||||
// --disable-renderer-accessibility completely disables browser accessibility.
|
||||
//settings.CefCommandLineArgs.Add("force-renderer-accessibility");
|
||||
//settings.CefCommandLineArgs.Add("disable-renderer-accessibility");
|
||||
|
||||
//Enables Uncaught exception handler
|
||||
settings.UncaughtExceptionStackSize = 10;
|
||||
|
||||
//Disable WebAssembly
|
||||
//settings.JavascriptFlags = "--noexpose_wasm";
|
||||
|
||||
// Off Screen rendering (WPF/Offscreen)
|
||||
if (settings.WindowlessRenderingEnabled)
|
||||
{
|
||||
//Disable Direct Composition to test https://github.com/cefsharp/CefSharp/issues/1634
|
||||
//settings.CefCommandLineArgs.Add("disable-direct-composition");
|
||||
|
||||
// DevTools doesn't seem to be working when this is enabled
|
||||
// http://magpcss.org/ceforum/viewtopic.php?f=6&t=14095
|
||||
//settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling");
|
||||
}
|
||||
|
||||
var proxy = ProxyConfig.GetProxyInformation();
|
||||
switch (proxy.AccessType)
|
||||
{
|
||||
case InternetOpenType.Direct:
|
||||
{
|
||||
//Don't use a proxy server, always make direct connections.
|
||||
settings.CefCommandLineArgs.Add("no-proxy-server");
|
||||
break;
|
||||
}
|
||||
case InternetOpenType.Proxy:
|
||||
{
|
||||
settings.CefCommandLineArgs.Add("proxy-server", proxy.ProxyAddress);
|
||||
break;
|
||||
}
|
||||
case InternetOpenType.PreConfig:
|
||||
{
|
||||
settings.CefCommandLineArgs.Add("proxy-auto-detect");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//settings.LogSeverity = LogSeverity.Verbose;
|
||||
|
||||
if (DebuggingSubProcess)
|
||||
{
|
||||
var architecture = Environment.Is64BitProcess ? "x64" : "x86";
|
||||
var path = Path.GetFullPath("CefSharp.BrowserSubprocess.exe");
|
||||
settings.BrowserSubprocessPath = path;
|
||||
}
|
||||
|
||||
settings.RegisterScheme(new CefCustomScheme
|
||||
{
|
||||
SchemeName = CefSharpSchemeHandlerFactory.SchemeName,
|
||||
SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(),
|
||||
IsSecure = true, //treated with the same security rules as those applied to "https" URLs
|
||||
});
|
||||
|
||||
settings.RegisterScheme(new CefCustomScheme
|
||||
{
|
||||
SchemeName = "https",
|
||||
SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(),
|
||||
DomainName = ExampleDomain
|
||||
});
|
||||
|
||||
settings.RegisterScheme(new CefCustomScheme
|
||||
{
|
||||
SchemeName = CefSharpSchemeHandlerFactory.SchemeNameTest,
|
||||
SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(),
|
||||
IsSecure = true //treated with the same security rules as those applied to "https" URLs
|
||||
});
|
||||
|
||||
//You can use the http/https schemes - best to register for a specific domain
|
||||
settings.RegisterScheme(new CefCustomScheme
|
||||
{
|
||||
SchemeName = "https",
|
||||
SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(),
|
||||
DomainName = "cefsharp.com",
|
||||
IsSecure = true //treated with the same security rules as those applied to "https" URLs
|
||||
});
|
||||
|
||||
////settings.RegisterScheme(new CefCustomScheme
|
||||
////{
|
||||
//// SchemeName = "localfolder",
|
||||
//// SchemeHandlerFactory = new FolderSchemeHandlerFactory(rootFolder: @"..\..\..\Resources",
|
||||
//// schemeName: "localfolder", //Optional param no schemename checking if null
|
||||
//// hostName: "cefsharp", //Optional param no hostname checking if null
|
||||
//// defaultPage: "home.html") //Optional param will default to index.html
|
||||
////});
|
||||
|
||||
////settings.RegisterExtension(new V8Extension("cefsharp/example", Resources.extension));
|
||||
|
||||
//This must be set before Cef.Initialized is called
|
||||
CefSharpSettings.FocusedNodeChangedEnabled = true;
|
||||
|
||||
//Async Javascript Binding - methods are queued on TaskScheduler.Default.
|
||||
//Set this to true to when you have methods that return Task<T>
|
||||
//CefSharpSettings.ConcurrentTaskExecution = true;
|
||||
|
||||
//Legacy Binding Behaviour - Same as Javascript Binding in version 57 and below
|
||||
//See issue https://github.com/cefsharp/CefSharp/issues/1203 for details
|
||||
//CefSharpSettings.LegacyJavascriptBindingEnabled = true;
|
||||
|
||||
//Exit the subprocess if the parent process happens to close
|
||||
//This is optional at the moment
|
||||
//https://github.com/cefsharp/CefSharp/pull/2375/
|
||||
CefSharpSettings.SubprocessExitIfParentProcessClosed = true;
|
||||
|
||||
//NOTE: Set this before any calls to Cef.Initialize to specify a proxy with username and password
|
||||
//One set this cannot be changed at runtime. If you need to change the proxy at runtime (dynamically) then
|
||||
//see https://github.com/cefsharp/CefSharp/wiki/General-Usage#proxy-resolution
|
||||
//CefSharpSettings.Proxy = new ProxyOptions(ip: "127.0.0.1", port: "8080", username: "cefsharp", password: "123");
|
||||
|
||||
if (!Cef.Initialize(settings, performDependencyCheck: !DebuggingSubProcess, browserProcessHandler: browserProcessHandler))
|
||||
{
|
||||
throw new Exception("Unable to Initialize Cef");
|
||||
}
|
||||
|
||||
Cef.AddCrossOriginWhitelistEntry(BaseUrl, "https", "cefsharp.com", false);
|
||||
}
|
||||
|
||||
public static async void RegisterTestResources(IWebBrowser browser)
|
||||
{
|
||||
if (browser.ResourceRequestHandlerFactory == null)
|
||||
{
|
||||
browser.ResourceRequestHandlerFactory = new ResourceRequestHandlerFactory();
|
||||
}
|
||||
|
||||
var handler = browser.ResourceRequestHandlerFactory as ResourceRequestHandlerFactory;
|
||||
|
||||
if (handler != null)
|
||||
{
|
||||
const string renderProcessCrashedBody = "<html><body><h1>Render Process Crashed</h1><p>Your seeing this message as the render process has crashed</p></body></html>";
|
||||
handler.RegisterHandler(RenderProcessCrashedUrl, ResourceHandler.GetByteArray(renderProcessCrashedBody, Encoding.UTF8));
|
||||
|
||||
const string responseBody = "<html><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p></body></html>";
|
||||
handler.RegisterHandler(TestResourceUrl, ResourceHandler.GetByteArray(responseBody, Encoding.UTF8));
|
||||
|
||||
const string unicodeResponseBody = "<html><body>整体满意度</body></html>";
|
||||
handler.RegisterHandler(TestUnicodeResourceUrl, ResourceHandler.GetByteArray(unicodeResponseBody, Encoding.UTF8));
|
||||
|
||||
if (string.IsNullOrEmpty(PluginInformation))
|
||||
{
|
||||
var pluginBody = new StringBuilder();
|
||||
pluginBody.Append("<html><body><h1>Plugins</h1><table>");
|
||||
pluginBody.Append("<tr>");
|
||||
pluginBody.Append("<th>Name</th>");
|
||||
pluginBody.Append("<th>Description</th>");
|
||||
pluginBody.Append("<th>Version</th>");
|
||||
pluginBody.Append("<th>Path</th>");
|
||||
pluginBody.Append("</tr>");
|
||||
|
||||
var plugins = await Cef.GetPlugins();
|
||||
|
||||
if (plugins.Count == 0)
|
||||
{
|
||||
pluginBody.Append("<tr>");
|
||||
pluginBody.Append("<td colspan='4'>Cef.GetPlugins returned an empty list - likely no plugins were loaded on your system</td>");
|
||||
pluginBody.Append("</tr>");
|
||||
pluginBody.Append("<tr>");
|
||||
pluginBody.Append("<td colspan='4'>You may find that NPAPI/PPAPI need to be enabled</td>");
|
||||
pluginBody.Append("</tr>");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var plugin in plugins)
|
||||
{
|
||||
pluginBody.Append("<tr>");
|
||||
pluginBody.Append("<td>" + plugin.Name + "</td>");
|
||||
pluginBody.Append("<td>" + plugin.Description + "</td>");
|
||||
pluginBody.Append("<td>" + plugin.Version + "</td>");
|
||||
pluginBody.Append("<td>" + plugin.Path + "</td>");
|
||||
pluginBody.Append("</tr>");
|
||||
}
|
||||
}
|
||||
|
||||
pluginBody.Append("</table></body></html>");
|
||||
|
||||
PluginInformation = pluginBody.ToString();
|
||||
}
|
||||
|
||||
handler.RegisterHandler(PluginsTestUrl, ResourceHandler.GetByteArray(PluginInformation, Encoding.UTF8));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright © 2012 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 VideoBrowser.Controls.CefSharpBrowser.Helpers
|
||||
{
|
||||
using CefSharp;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
internal class CefSharpSchemeHandler : ResourceHandler
|
||||
{
|
||||
public override CefReturnValue ProcessRequestAsync(IRequest request, ICallback callback)
|
||||
{
|
||||
var uri = new Uri(request.Url);
|
||||
var fileName = uri.AbsolutePath;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
using (callback)
|
||||
{
|
||||
Stream stream = null;
|
||||
|
||||
if (string.Equals(fileName, "/PostDataTest.html", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var postDataElement = request.PostData.Elements.FirstOrDefault();
|
||||
stream = ResourceHandler.GetMemoryStream("Post Data: " + (postDataElement == null ? "null" : postDataElement.GetBody()), Encoding.UTF8);
|
||||
}
|
||||
|
||||
if (string.Equals(fileName, "/PostDataAjaxTest.html", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var postData = request.PostData;
|
||||
if (postData == null)
|
||||
{
|
||||
stream = ResourceHandler.GetMemoryStream("Post Data: null", Encoding.UTF8);
|
||||
}
|
||||
else
|
||||
{
|
||||
var postDataElement = postData.Elements.FirstOrDefault();
|
||||
stream = ResourceHandler.GetMemoryStream("Post Data: " + (postDataElement == null ? "null" : postDataElement.GetBody()), Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
|
||||
if (stream == null)
|
||||
{
|
||||
callback.Cancel();
|
||||
}
|
||||
else
|
||||
{
|
||||
//Reset the stream position to 0 so the stream can be copied into the underlying unmanaged buffer
|
||||
stream.Position = 0;
|
||||
//Populate the response values - No longer need to implement GetResponseHeaders (unless you need to perform a redirect)
|
||||
ResponseLength = stream.Length;
|
||||
MimeType = "text/html";
|
||||
StatusCode = (int)HttpStatusCode.OK;
|
||||
Stream = stream;
|
||||
|
||||
callback.Continue();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return CefReturnValue.ContinueAsync;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
// Copyright © 2013 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 VideoBrowser.Controls.CefSharpBrowser.Helpers
|
||||
{
|
||||
using CefSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
public class CefSharpSchemeHandlerFactory : ISchemeHandlerFactory
|
||||
{
|
||||
public const string SchemeName = "custom";
|
||||
public const string SchemeNameTest = "test";
|
||||
|
||||
private static readonly IDictionary<string, string> ResourceDictionary;
|
||||
|
||||
static CefSharpSchemeHandlerFactory()
|
||||
{
|
||||
ResourceDictionary = new Dictionary<string, string>
|
||||
{
|
||||
////{ "/home.html", Resources.home_html },
|
||||
|
||||
////{ "/assets/css/shCore.css", Resources.assets_css_shCore_css },
|
||||
////{ "/assets/css/shCoreDefault.css", Resources.assets_css_shCoreDefault_css },
|
||||
////{ "/assets/css/docs.css", Resources.assets_css_docs_css },
|
||||
////{ "/assets/js/application.js", Resources.assets_js_application_js },
|
||||
////{ "/assets/js/jquery.js", Resources.assets_js_jquery_js },
|
||||
////{ "/assets/js/shBrushCSharp.js", Resources.assets_js_shBrushCSharp_js },
|
||||
////{ "/assets/js/shBrushJScript.js", Resources.assets_js_shBrushJScript_js },
|
||||
////{ "/assets/js/shCore.js", Resources.assets_js_shCore_js },
|
||||
|
||||
////{ "/bootstrap/bootstrap-theme.min.css", Resources.bootstrap_theme_min_css },
|
||||
////{ "/bootstrap/bootstrap.min.css", Resources.bootstrap_min_css },
|
||||
////{ "/bootstrap/bootstrap.min.js", Resources.bootstrap_min_js },
|
||||
|
||||
////{ "/BindingTest.html", Resources.BindingTest },
|
||||
////{ "/BindingTestSingle.html", Resources.BindingTestSingle },
|
||||
////{ "/LegacyBindingTest.html", Resources.LegacyBindingTest },
|
||||
////{ "/PostMessageTest.html", Resources.PostMessageTest },
|
||||
////{ "/ExceptionTest.html", Resources.ExceptionTest },
|
||||
////{ "/PopupTest.html", Resources.PopupTest },
|
||||
////{ "/SchemeTest.html", Resources.SchemeTest },
|
||||
////{ "/TooltipTest.html", Resources.TooltipTest },
|
||||
////{ "/FramedWebGLTest.html", Resources.FramedWebGLTest },
|
||||
////{ "/MultiBindingTest.html", Resources.MultiBindingTest },
|
||||
////{ "/ScriptedMethodsTest.html", Resources.ScriptedMethodsTest },
|
||||
////{ "/ResponseFilterTest.html", Resources.ResponseFilterTest },
|
||||
////{ "/DraggableRegionTest.html", Resources.DraggableRegionTest },
|
||||
////{ "/DragDropCursorsTest.html", Resources.DragDropCursorsTest },
|
||||
////{ "/CssAnimationTest.html", Resources.CssAnimation },
|
||||
////{ "/CdmSupportTest.html", Resources.CdmSupportTest },
|
||||
////{ "/Recaptcha.html", Resources.Recaptcha },
|
||||
////{ "/UnicodeExampleGreaterThan32kb.html", Resources.UnicodeExampleGreaterThan32kb },
|
||||
////{ "/UnocodeExampleEqualTo32kb.html", Resources.UnocodeExampleEqualTo32kb },
|
||||
////{ "/JavascriptCallbackTest.html", Resources.JavascriptCallbackTest },
|
||||
////{ "/BindingTestsAsyncTask.html", Resources.BindingTestsAsyncTask },
|
||||
////{ "/BindingApiCustomObjectNameTest.html", Resources.BindingApiCustomObjectNameTest }
|
||||
};
|
||||
}
|
||||
|
||||
public IResourceHandler Create(IBrowser browser, IFrame frame, string schemeName, IRequest request)
|
||||
{
|
||||
//Notes:
|
||||
// - The 'host' portion is entirely ignored by this scheme handler.
|
||||
// - If you register a ISchemeHandlerFactory for http/https schemes you should also specify a domain name
|
||||
// - Avoid doing lots of processing in this method as it will affect performance.
|
||||
// - Use the Default ResourceHandler implementation
|
||||
|
||||
var uri = new Uri(request.Url);
|
||||
var fileName = uri.AbsolutePath;
|
||||
|
||||
//Load a file directly from Disk
|
||||
if (fileName.EndsWith("CefSharp.Core.xml", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
//Convenient helper method to lookup the mimeType
|
||||
var mimeType = Cef.GetMimeType("xml");
|
||||
//Load a resource handler for CefSharp.Core.xml
|
||||
//mimeType is optional and will default to text/html
|
||||
return ResourceHandler.FromFilePath("CefSharp.Core.xml", mimeType, autoDisposeStream: true);
|
||||
}
|
||||
|
||||
if (fileName.EndsWith("Logo.png", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
//Convenient helper method to lookup the mimeType
|
||||
var mimeType = Cef.GetMimeType("png");
|
||||
//Load a resource handler for Logo.png
|
||||
//mimeType is optional and will default to text/html
|
||||
return ResourceHandler.FromFilePath("..\\..\\..\\..\\CefSharp.WinForms.Example\\Resources\\chromium-256.png", mimeType, autoDisposeStream: true);
|
||||
}
|
||||
|
||||
if (uri.Host == "cefsharp.com" && schemeName == "https" && (string.Equals(fileName, "/PostDataTest.html", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(fileName, "/PostDataAjaxTest.html", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return new CefSharpSchemeHandler();
|
||||
}
|
||||
|
||||
if (string.Equals(fileName, "/EmptyResponseFilterTest.html", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return ResourceHandler.FromString("", mimeType: ResourceHandler.DefaultMimeType);
|
||||
}
|
||||
|
||||
string resource;
|
||||
if (ResourceDictionary.TryGetValue(fileName, out resource) && !string.IsNullOrEmpty(resource))
|
||||
{
|
||||
var fileExtension = Path.GetExtension(fileName);
|
||||
return ResourceHandler.FromString(resource, includePreamble: true, mimeType: Cef.GetMimeType(fileExtension));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright © 2014 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 VideoBrowser.Controls.CefSharpBrowser.Helpers
|
||||
{
|
||||
#region Enums
|
||||
|
||||
/// <summary>
|
||||
/// Defines the InternetOpenType.
|
||||
/// </summary>
|
||||
public enum InternetOpenType
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the PreConfig.
|
||||
/// </summary>
|
||||
PreConfig = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Defines the Direct.
|
||||
/// </summary>
|
||||
Direct = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Defines the Proxy.
|
||||
/// </summary>
|
||||
Proxy = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Defines the PreConfigWithNoAutoProxy.
|
||||
/// </summary>
|
||||
PreConfigWithNoAutoProxy = 4
|
||||
}
|
||||
|
||||
#endregion Enums
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright © 2014 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 VideoBrowser.Controls.CefSharpBrowser.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the <see cref="InternetProxyInfo" />.
|
||||
/// </summary>
|
||||
public struct InternetProxyInfo
|
||||
{
|
||||
#region Fields
|
||||
|
||||
public InternetOpenType AccessType;
|
||||
|
||||
public string ProxyAddress;
|
||||
|
||||
public string ProxyBypass;
|
||||
|
||||
#endregion Fields
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
namespace VideoBrowser.Controls.CefSharpBrowser.Helpers
|
||||
{
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the <see cref="ProcessHelper" />.
|
||||
/// </summary>
|
||||
public static class ProcessHelper
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// The OpenFolder.
|
||||
/// </summary>
|
||||
/// <param name="filePath">The filePath<see cref="string"/>.</param>
|
||||
public static void OpenContainedFolder(string filePath)
|
||||
{
|
||||
var path = Path.GetDirectoryName(filePath);
|
||||
Start(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The OpenUrl.
|
||||
/// </summary>
|
||||
/// <param name="url">The url<see cref="string"/>.</param>
|
||||
public static void OpenUrl(string url)
|
||||
{
|
||||
Start(url);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Start.
|
||||
/// </summary>
|
||||
/// <param name="filePath">The filePath<see cref="string"/>.</param>
|
||||
public static void Start(string filePath)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
CreateNoWindow = true,
|
||||
ErrorDialog = true,
|
||||
FileName = filePath,
|
||||
Verb = "Open"
|
||||
}
|
||||
};
|
||||
process.Start();
|
||||
});
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
68
VideoBrowser/Controls/CefSharpBrowser/Helpers/ProxyConfig.cs
Normal file
68
VideoBrowser/Controls/CefSharpBrowser/Helpers/ProxyConfig.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
// 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.
|
||||
|
||||
namespace VideoBrowser.Controls.CefSharpBrowser.Helpers
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the <see cref="ProxyConfig" />.
|
||||
/// </summary>
|
||||
public class ProxyConfig
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const uint InternetOptionProxy = 38;
|
||||
|
||||
#endregion Constants
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// The GetProxyInformation.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="InternetProxyInfo"/>.</returns>
|
||||
public static InternetProxyInfo GetProxyInformation()
|
||||
{
|
||||
var bufferLength = 0;
|
||||
InternetQueryOption(IntPtr.Zero, InternetOptionProxy, IntPtr.Zero, ref bufferLength);
|
||||
var buffer = IntPtr.Zero;
|
||||
|
||||
try
|
||||
{
|
||||
buffer = Marshal.AllocHGlobal(bufferLength);
|
||||
|
||||
if (InternetQueryOption(IntPtr.Zero, InternetOptionProxy, buffer, ref bufferLength))
|
||||
{
|
||||
var ipi = (InternetProxyInfo)Marshal.PtrToStructure(buffer, typeof(InternetProxyInfo));
|
||||
return ipi;
|
||||
}
|
||||
|
||||
throw new Win32Exception();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (buffer != IntPtr.Zero)
|
||||
{
|
||||
Marshal.FreeHGlobal(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The InternetQueryOption.
|
||||
/// </summary>
|
||||
/// <param name="hInternet">The hInternet<see cref="IntPtr"/>.</param>
|
||||
/// <param name="dwOption">The dwOption<see cref="uint"/>.</param>
|
||||
/// <param name="lpBuffer">The lpBuffer<see cref="IntPtr"/>.</param>
|
||||
/// <param name="lpdwBufferLength">The lpdwBufferLength<see cref="int"/>.</param>
|
||||
/// <returns>The <see cref="bool"/>.</returns>
|
||||
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern bool InternetQueryOption(IntPtr hInternet, uint dwOption, IntPtr lpBuffer, ref int lpdwBufferLength);
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
42
VideoBrowser/Controls/CefSharpBrowser/Helpers/UrlHelper.cs
Normal file
42
VideoBrowser/Controls/CefSharpBrowser/Helpers/UrlHelper.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
namespace VideoBrowser.Controls.CefSharpBrowser.Helpers
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the <see cref="UrlHelper" />.
|
||||
/// </summary>
|
||||
public static class UrlHelper
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// The IsImageUrl.
|
||||
/// </summary>
|
||||
/// <param name="URL">The URL<see cref="string"/>.</param>
|
||||
/// <returns>The <see cref="bool"/>.</returns>
|
||||
public static bool IsImageUrl(this string URL)
|
||||
{
|
||||
if (!(HttpWebRequest.Create(URL) is HttpWebRequest req))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
req.Method = "HEAD";
|
||||
try
|
||||
{
|
||||
using (var resp = req.GetResponse())
|
||||
{
|
||||
return resp.ContentType.ToLower(CultureInfo.InvariantCulture).StartsWith("image/");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user