using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.IO; using System.Linq; using System.Net; using CefSharp; using CefSharp.Enums; using CefSharp.Structs; using Size = CefSharp.Structs.Size; namespace XeroBrowser { public class DisplayHandler : IDisplayHandler { public FrmBrowser Frmref; public DisplayHandler(FrmBrowser frm) { Frmref = frm; } public static Icon BytesToIcon(byte[] bytes) { using (MemoryStream ms = new MemoryStream(bytes)) { return new Icon(ms); } } public void OnAddressChanged(IWebBrowser chromiumWebBrowser, AddressChangedEventArgs addressChangedArgs) { } public bool OnAutoResize(IWebBrowser chromiumWebBrowser, IBrowser browser, Size newSize) { return true; } public bool OnConsoleMessage(IWebBrowser chromiumWebBrowser, ConsoleMessageEventArgs consoleMessageArgs) { return true; } public bool OnCursorChange(IWebBrowser chromiumWebBrowser, IBrowser browser, IntPtr cursor, CursorType type, CursorInfo customCursorInfo) { return true; } public void OnFaviconUrlChange(IWebBrowser chromiumWebBrowser, IBrowser browser, IList urls) { try { if (urls.Count > 0) { WebClient wc = new WebClient(); byte[] buffer = wc.DownloadData(urls[0]); Frmref.Icon = BytesToIcon(buffer); Frmref.Update(); Frmref.ParentTabs.UpdateThumbnailPreviewIcon(Frmref.ParentTabs.Tabs.Single(t => t.Content == Frmref)); Frmref.ParentTabs.RedrawTabs(); } } catch (Exception){ try { WebClient wc = new WebClient(); Uri furi = new Uri(chromiumWebBrowser.Address); byte[] buffer = wc.DownloadData(furi.GetLeftPart(UriPartial.Authority) +"/favicon.ico"); Frmref.Icon = BytesToIcon(buffer); Frmref.Update(); Frmref.ParentTabs.UpdateThumbnailPreviewIcon(Frmref.ParentTabs.Tabs.Single(t => t.Content == Frmref)); Frmref.ParentTabs.RedrawTabs(); } catch (Exception){ ComponentResourceManager resources = new ComponentResourceManager(typeof(FrmBrowser)); Frmref.Icon = ((Icon)(resources.GetObject("$this.Icon"))); Frmref.Update(); Frmref.ParentTabs.UpdateThumbnailPreviewIcon(Frmref.ParentTabs.Tabs.Single(t => t.Content == Frmref)); Frmref.ParentTabs.RedrawTabs(); } } } public void OnFullscreenModeChange(IWebBrowser chromiumWebBrowser, IBrowser browser, bool fullscreen) { } public void OnLoadingProgressChange(IWebBrowser chromiumWebBrowser, IBrowser browser, double progress) { } public void OnStatusMessage(IWebBrowser chromiumWebBrowser, StatusMessageEventArgs statusMessageArgs) { } public void OnTitleChanged(IWebBrowser chromiumWebBrowser, TitleChangedEventArgs titleChangedArgs) { } public bool OnTooltipChanged(IWebBrowser chromiumWebBrowser, ref string text) { return true; } } }