using System; using System.Collections.Generic; using System.Linq; using System.Text; using CefSharp; using System.Threading.Tasks; using CefSharp.Structs; using CefSharp.Enums; using WebBrowser; using System.Net; using System.Drawing; using System.IO; namespace DiamondCreeperBrowser { 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) { return; } public bool OnAutoResize(IWebBrowser chromiumWebBrowser, IBrowser browser, CefSharp.Structs.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){ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmBrowser)); frmref.Icon = ((System.Drawing.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) { return; } public void OnLoadingProgressChange(IWebBrowser chromiumWebBrowser, IBrowser browser, double progress) { return; } public void OnStatusMessage(IWebBrowser chromiumWebBrowser, StatusMessageEventArgs statusMessageArgs) { return; } public void OnTitleChanged(IWebBrowser chromiumWebBrowser, TitleChangedEventArgs titleChangedArgs) { return; } public bool OnTooltipChanged(IWebBrowser chromiumWebBrowser, ref string text) { return true; } } }