public InternalHandle printToPDF(V8Engine engine, bool isConstructCall, InternalHandle _this, InternalHandle[] args) { if (args.Length == 2 && browser != null) { var path = args[0].AsString; var settings = new CefPdfPrintSettings(); var _callback = new CefPdfClient(); browser.GetHost().PrintToPdf(path, settings, _callback); } return(Engine.CreateNullValue()); }
protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception) { returnValue = CefV8Value.CreateNull(); exception = null; try { var context = CefV8Context.GetCurrentContext(); var browser = context.GetBrowser(); var frame = browser.GetMainFrame(); if (name.ToLower().Equals("back")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); back(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { back(); } return(true); } else if (name.ToLower().Equals("copy")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); copy(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { copy(); } return(true); } else if (name.ToLower().Equals("cut")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); cut(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { cut(); } return(true); } else if (name.ToLower().Equals("delete")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); delete(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { delete(); } return(true); } else if (name.ToLower().Equals("find")) { if (arguments.Length >= 5) { var identifier = arguments[0].GetIntValue(); var searchText = arguments[1].GetStringValue(); var forward = arguments[2].GetBoolValue(); var matchCase = arguments[3].GetBoolValue(); var findNext = arguments[4].GetBoolValue(); var callback = (arguments.Length == 6 ? arguments[5] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); find(identifier, searchText, forward, matchCase, findNext); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { find(identifier, searchText, forward, matchCase, findNext); } } return(true); } else if (name.ToLower().Equals("forward")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); forward(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { forward(); } return(true); } else if (name.ToLower().Equals("getsource")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); getSource(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { getSource(); } return(true); } else if (name.ToLower().Equals("getzoomlevel")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); runner.PostTask(new CallbackTask(context, callback, getZoomLevel())); context.Exit(); }).Start(); } else { returnValue = CefV8Value.CreateDouble(getZoomLevel()); } return(true); } else if (name.ToLower().Equals("load")) { if (arguments.Length >= 1) { var url = arguments[0].GetStringValue(); var callback = (arguments.Length == 2 ? arguments[1] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); load(url); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { load(url); } } return(true); } else if (name.ToLower().Equals("loadstring")) { if (arguments.Length >= 2) { var html = arguments[0].GetStringValue(); var url = arguments[1].GetStringValue(); var callback = (arguments.Length == 3 ? arguments[2] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); loadString(html, url); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { loadString(html, url); } } return(true); } else if (name.ToLower().Equals("paste")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); paste(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { paste(); } return(true); } else if (name.ToLower().Equals("print")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); print(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { print(); } return(true); } else if (name.ToLower().Equals("redo")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); redo(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { redo(); } return(true); } else if (name.ToLower().Equals("refresh")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); refresh(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { refresh(); } return(true); } else if (name.ToLower().Equals("selectall")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); selectAll(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { selectAll(); } return(true); } else if (name.ToLower().Equals("showdevtools")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); showDevTools(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { showDevTools(); } return(true); } else if (name.ToLower().Equals("stop")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); stop(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { stop(); } return(true); } else if (name.ToLower().Equals("undo")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); undo(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { undo(); } return(true); } else if (name.ToLower().Equals("viewsource")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); viewSource(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { viewSource(); } return(true); } else if (name.ToLower().Equals("shutdown")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); shutdown(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { shutdown(); } return(true); } else if (name.ToLower().Equals("printtopdf")) { if (arguments.Length >= 1) { var path = arguments[0].GetStringValue(); var settings = new CefPdfPrintSettings(); var _callback = new CefPdfClient(); var callback = (arguments.Length == 2 ? arguments[1] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); printToPDF(path, settings, null); runner.PostTask(new CallbackTask(context, callback, _callback)); context.Exit(); }).Start(); } else { printToPDF(path, settings, _callback); } } return(true); } else if (name.ToLower().Equals("getwindowsize")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); getWindowSize(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { getWindowSize(); } return(true); } else if (name.ToLower().Equals("update")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); Update(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { Update(); } return(true); } else if (name.ToLower().Equals("checkforupdates")) { var callback = (arguments.Length == 1 ? arguments[0] : null); if (callback != null && callback.IsFunction) { var runner = CefTaskRunner.GetForCurrentThread(); new Task(() => { context.Enter(); CheckForUpdates(); runner.PostTask(new CallbackTask(context, callback, null)); context.Exit(); }).Start(); } else { CheckForUpdates(); } return(true); } } catch (Exception ex) { returnValue = CefV8Value.CreateNull(); exception = ex.Message; return(true); } return(false); }