public BrowserTabView() { InitializeComponent(); browser.RequestHandler = new RequestHandler(); browser.RegisterJsObject("bound", new BoundObject(), BindingOptions.DefaultBinder); browser.RegisterAsyncJsObject("boundAsync", new AsyncBoundObject()); // Enable touch scrolling - once properly tested this will likely become the default //browser.IsManipulationEnabled = true; browser.LifeSpanHandler = new LifespanHandler(); browser.MenuHandler = new MenuHandler(); browser.GeolocationHandler = new GeolocationHandler(); var downloadHandler = new DownloadHandler(); downloadHandler.OnBeforeDownloadFired += OnBeforeDownloadFired; downloadHandler.OnDownloadUpdatedFired += OnDownloadUpdatedFired; browser.DownloadHandler = downloadHandler; var dragHandler = new DragHandler(); dragHandler.RegionsChanged += OnDragHandlerRegionsChanged; browser.DragHandler = dragHandler; //browser.ResourceHandlerFactory = new InMemorySchemeAndResourceHandlerFactory(); //You can specify a custom RequestContext to share settings amount groups of ChromiumWebBrowsers //Also this is now the only way to access OnBeforePluginLoad - need to implement IRequestContextHandler //browser.RequestContext = new RequestContext(new RequestContextHandler()); //NOTE - This is very important for this example as the default page will not load otherwise //browser.RequestContext.RegisterSchemeHandlerFactory(CefSharpSchemeHandlerFactory.SchemeName, null, new CefSharpSchemeHandlerFactory()); //You can start setting preferences on a RequestContext that you created straight away, still needs to be called on the CEF UI thread. //Cef.UIThreadTaskFactory.StartNew(delegate //{ // string errorMessage; // //Use this to check that settings preferences are working in your code // var success = browser.RequestContext.SetPreference("webkit.webprefs.minimum_font_size", 24, out errorMessage); //}); browser.RenderProcessMessageHandler = new RenderProcessMessageHandler(); browser.LoadError += (sender, args) => { // Don't display an error for downloaded files. if (args.ErrorCode == CefErrorCode.Aborted) { return; } // Don't display an error for external protocols that we allow the OS to // handle. See OnProtocolExecution(). //if (args.ErrorCode == CefErrorCode.UnknownUrlScheme) //{ // var url = args.Frame.Url; // if (url.StartsWith("spotify:")) // { // return; // } //} // Display a load error message. var errorBody = string.Format("<html><body bgcolor=\"white\"><h2>Failed to load URL {0} with error {1} ({2}).</h2></body></html>", args.FailedUrl, args.ErrorText, args.ErrorCode); args.Frame.LoadStringForUrl(errorBody, args.FailedUrl); }; CefExample.RegisterTestResources(browser); }
bool IRequestHandler.GetDownloadHandler(IWebBrowser browser, string mimeType, string fileName, long contentLength, ref IDownloadHandler handler) { handler = new DownloadHandler(fileName); return(true); }
bool IRequestHandler.GetDownloadHandler(IWebBrowser browser, out IDownloadHandler handler) { handler = new DownloadHandler(); return(true); }
bool IRequestHandler.GetDownloadHandler(IWebBrowser browser, out IDownloadHandler handler) { handler = new DownloadHandler(); return true; }
bool IRequestHandler.GetDownloadHandler(IWebBrowser browser, string mimeType, string fileName, long contentLength, ref IDownloadHandler handler) { handler = new DownloadHandler(fileName); return true; }