public void Stop() { CefRuntime.PostTask(CefThreadId.UI, BrowserTask.Create(() => { if (!isMultiThreadedMessageLoop) { CefRuntime.QuitMessageLoop(); } })); dispatcher.PostTask(() => { CefRuntime.Shutdown(); }); dispatcher.Shutdown(); int browserMapCount = browserMap.Count; if (browserMapCount != 0) { throw new CefRuntimeException(String.Format( "After shutting down {0} browser instances were undisposed", browserMapCount)); } dispatcher = null; }
public void OpenUrl(string Url) { while (true) { if (created) { break; } Application.DoEvents(); } if (browser != null) { OnNavigating(); CefCookie cookie = new CefCookie(); cookie.Name = "cwberCookieName"; cookie.Value = "cwberCookie"; cookie.Domain = "cwberCookieDomain"; cookie.Path = cookiePath; cookie.Secure = false; cookie.HttpOnly = false; cookie.Expires = DateTime.Now; cookie.Creation = DateTime.Now; CefRuntime.PostTask(CefThreadId.IO, new CwbCookieTask(Url, cookie)); browser.GetMainFrame().LoadUrl(Url); OnNavigated(); } }
/// <summary> /// Calls back into V8 in response to either: /// - a remote function response message (triggered by the framework or by a native plugin calling a delegate it was provided) /// - a remote event fired message /// - an exception while making a remote function call /// Will switch to the Renderer thread if needed. /// </summary> /// <param name="pluginMessage"></param> /// <param name="result"></param> private void OnBrowserCallbackInvokeReceived(PluginMessage pluginMessage, ResultData result) { Logger.Debug("BrowserCallbackInvokeReceived MsgType {0} Plugin {1} Member {2}", pluginMessage.MessageType, pluginMessage.PluginId, pluginMessage.MemberName); try { var context = GetContextById(pluginMessage.ContextId); var info = _pendingCallbacks.Get(pluginMessage.MessageId); if (info != null) { if (!info.IsRetained) { _pendingCallbacks.Remove(info); } // Call completed received from remote process, so currently are on the IO method. Marshal to the renderer to callback into V8 CefRuntime.PostTask(CefThreadId.Renderer, new ActionCallbackTask(() => InvokeV8Callback(context, info, result))); } } catch (Exception exception) { Logger.Error("BrowserCallbackInvokeReceived Failed MsgType {0} Plugin {1} Member {2}: {3}", pluginMessage.MessageType, pluginMessage.PluginId, pluginMessage.MemberName, exception); } }
public static void Visit(Action <CefWebPluginInfo> action) { ManualResetEventSlim disposedEvent = new ManualResetEventSlim(); // Needs to be run on a different thread or else it will lock up and never release the object CefRuntime.PostTask(CefThreadId.UI, BrowserTask.Create(() => { CefRuntime.VisitWebPluginInfo(new BrowserPluginVisitor(disposedEvent, action)); })); }
protected override void QueueTask(Task task) { lock (Tasks) { var t = new TaskWrapper(this, task); if (CefRuntime.PostTask(ThreadId, t)) { Tasks.AddLast(t); } } }
protected override bool Open(CefRequest request, out bool handleRequest, CefCallback callback) { if (client != null) { throw new InvalidOperationException("DisableCspResourceHandler is not reusable!"); } client = new Client(callback); CefRuntime.PostTask(CefThreadId.IO, new CefActionTask(() => frame.CreateUrlRequest(request, client))); handleRequest = false; return(true); }
public override void OnRenderSideMessageReceived(string message, CefFrame frame, MessageArrayValue arguments) { if (message == EVALUATE_JS_CALLBACK) { CefRuntime.PostTask(CefThreadId.UI, new JavaScriptExecutionCallBackTask(frame, arguments)); } if (message == JS_OBJECT_MAPPING_MESSAGE) { CefRuntime.PostTask(CefThreadId.UI, new BrowserSideJavaScriptObjectMappingTask(this, frame)); } }
/* * I think it is possible to RegisterMessageRouter prior to an event being added but after the other handler objects are made * The MessageRouterHandler will do a lookup of registered events every time **/ private void RegisterMessageRouter() { Debug.WriteLine(DBGPREFIX + "Message Router, attempting registration"); if (!CefRuntime.CurrentlyOn(CefThreadId.UI)) { Debug.WriteLine(DBGPREFIX + "Message Router, creating task on UI Thread"); CefRuntime.PostTask(CefThreadId.UI, new ActionTask(RegisterMessageRouter)); return; } // window.cefQuery({ request: 'my_request', onSuccess: function(response) { console.log(response); }, onFailure: function(err,msg) { console.log(err, msg); } }); _messageRouter.AddHandler(MessageRouterHandler); Debug.WriteLine(DBGPREFIX + "Message Router, registered"); }
/// <summary> /// Executes the task on the selected CEF thread. /// </summary> /// <param name="threadId">The thread identifier.</param> /// <param name="action">The action.</param> /// <exception cref="System.ArgumentNullException">action</exception> public static void ExecuteTask(CefThreadId threadId, Action action) { if (action == null) { throw new ArgumentNullException("action"); } if (!CefRuntime.CurrentlyOn(threadId)) { CefRuntime.PostTask(threadId, new ActionTask(action)); } else { action(); } }
public void Error(string text = "Invalid operation") { if (_isCalled) { throw new InvalidOperationException(); } var arguments = new MessageArrayValue(); arguments.Add(MessageValue.CreateBool(false)); arguments.Add(MessageValue.CreateString(text)); arguments.Add(MessageValue.CreateString($"{_uuid}")); CefRuntime.PostTask(CefThreadId.Renderer, new JavaScriptCommunicationBridge.RenderSideJavaScriptExecutionCallbackTask(_jsBridge, _frame, arguments)); _isCalled = true; }
public void Success(params JavaScriptValue[] retvals) { if (_isCalled) { throw new InvalidOperationException(); } var retval = retvals?.ToJSValue() ?? JavaScriptValue.CreateArray(); var arguments = new MessageArrayValue(); arguments.Add(MessageValue.CreateBool(true)); arguments.Add(MessageValue.CreateString(retval.ToDefinition())); arguments.Add(MessageValue.CreateString($"{_uuid}")); CefRuntime.PostTask(CefThreadId.Renderer, new JavaScriptCommunicationBridge.RenderSideJavaScriptExecutionCallbackTask(_jsBridge, _frame, arguments)); _isCalled = true; }
/// <summary> /// Calls back into V8 in response to either: /// - a local function response message /// - a local event fired message /// - an exception while making a local function call /// Will switch to the Renderer thread if needed. /// </summary> /// <param name="call"></param> /// <param name="result"></param> /// <param name="errorCode"></param> /// <param name="error"></param> public void LocalCallbackInvoked(LocalRenderCallInfo call, object result, int errorCode, string error) { if (!CefRuntime.CurrentlyOn(CefThreadId.Renderer)) { // Call completed received from remote process, so currently are on the IO method. Marshal to the renderer to callback into V8 CefRuntime.PostTask(CefThreadId.Renderer, new ActionCallbackTask(() => LocalCallbackInvoked(call, result, errorCode, error))); return; } var msg = call.RequestMessage; Logger.Info("LocalCallbackInvoked MsgType {0} Plugin {1} Member {2}", msg.MessageType, msg.PluginId, msg.MemberName); // Already on the render thread (e.g. local plugin event triggered by call into function from JS, or function invoke failed try { var context = GetContextById(call.RequestMessage.ContextId); if (!call.IsRetained) { _pendingCallbacks.Remove(call); } if (context != null && call.Callback != null) { call.Callback.Invoke(this, context, result, errorCode, error); } if (!call.IsRetained) { call.Dispose(); } } catch (Exception exception) { Logger.Error("LocalCallbackInvoked Failed MsgType {0} Plugin {1} Member {2}: {3}", call.RequestMessage.MessageType, call.RequestMessage.PluginId, call.RequestMessage.MemberName, exception); } }
public void CloseBrowser(bool isForcingClose) { httpServer.Stop(); closeFinishedEvent = new ManualResetEventSlim(false); // make sure we arent mid browser creation // lock on browser lock (browserLock) { CefRuntime.PostTask(CefThreadId.UI, BrowserTask.Create(() => { if (browser != null) { browserClient.LifeSpanHandler.OnBeforeCloseEvent = new OnBeforeCloseEventHandler(OnBeforeClose); browser.GetHost().CloseBrowser(isForcingClose); } else { closeFinishedEvent.Set(); } })); closeFinishedEvent.Wait(); BrowserManager.Instance.UnregisterBrowser( browser.Identifier); // clean up the other client stuff UninitClient(); // make sure browser doesn't get disposed before close has finished browser = null; } closeFinishedEvent = null; }
public bool SetCookie(string name, string value, string domain, string path, bool httpOnly, bool secure, DateTime?expires, bool global) { // Reset the wait event. _setCookieEvent.Reset(); var success = false; // Set the cookie on the IO thread. CefRuntime.PostTask(CefThreadId.IO, new ActionCallbackTask(() => { try { // Create a cookie in the Chromium cookie manager. success = CefCookieManager.GetGlobal(null).SetCookie( "http://gs.com", new CefCookie { Name = name, Value = value, Domain = domain, Path = path, HttpOnly = httpOnly, Secure = secure, Expires = expires }, null); } finally { _setCookieEvent.Set(); } })); // Wait for the call to SetCookie to complete. _setCookieEvent.WaitOne(5000); return(success); }
/// <summary> /// The post task. /// </summary> /// <param name="threadId"> /// The thread id. /// </param> /// <param name="action"> /// The action. /// </param> private static void PostTask(CefThreadId threadId, Action action) { CefRuntime.PostTask(threadId, new ActionTask(action)); }
public void SetCookies(IList <Cookie> cookies) { var cookiesTask = new CookiesSetTask(cookies); CefRuntime.PostTask(CefThreadId.IO, cookiesTask); }
/// <summary> /// The post task. /// </summary> /// <param name="threadId"> /// The thread id. /// </param> /// <param name="action"> /// The action. /// </param> /// <param name="flag"> /// The flag. /// </param> private void PostTask(CefThreadId threadId, Action <bool> action, bool flag) { CefRuntime.PostTask(threadId, new ActionTask4(action, flag)); }
/// <summary> /// The post task. /// </summary> /// <param name="threadId"> /// The thread id. /// </param> /// <param name="action"> /// The action. /// </param> /// <param name="completionCallback"> /// The completion callback. /// </param> private void PostTask(CefThreadId threadId, Action <Action> action, Action completionCallback) { CefRuntime.PostTask(threadId, new ActionTask3(action, completionCallback)); }
/// <summary> /// The post task. /// </summary> /// <param name="threadId"> /// The thread id. /// </param> /// <param name="action"> /// The action. /// </param> /// <param name="port"> /// The port. /// </param> /// <param name="completionCallback"> /// The completion callback. /// </param> private void PostTask(CefThreadId threadId, Action <int, Action> action, int port, Action completionCallback) { CefRuntime.PostTask(threadId, new ActionTask2(action, port, completionCallback)); }
/// <summary> /// The post task. /// </summary> /// <param name="threadId"> /// The thread id. /// </param> /// <param name="action"> /// The action. /// </param> /// <param name="address"> /// The address. /// </param> /// <param name="port"> /// The port. /// </param> /// <param name="completionCallback"> /// The completion callback. /// </param> private void PostTask(CefThreadId threadId, Action <string, int, Action> action, string address, int port, Action completionCallback) { CefRuntime.PostTask(threadId, new ActionTask1(action, address, port, completionCallback)); }
public bool CreateBrowser(BrowserSource browserSource, BrowserConfig browserConfig) { if (browserClient == null) { InitClient(browserSource); } Debug.Assert(browserClient != null); Debug.Assert(browserConfig != null); BrowserConfig = browserConfig; CefWindowInfo windowInfo = CefWindowInfo.Create(); windowInfo.Width = (int)browserConfig.BrowserSourceSettings.Width; windowInfo.Height = (int)browserConfig.BrowserSourceSettings.Height; windowInfo.SetAsWindowless(IntPtr.Zero, true); BrowserInstanceSettings settings = AbstractSettings.DeepClone( BrowserSettings.Instance.InstanceSettings); settings.MergeWith(browserConfig.BrowserInstanceSettings); CefBrowserSettings browserSettings = new CefBrowserSettings { WindowlessFrameRate = browserConfig.BrowserSourceSettings.Fps, ApplicationCache = settings.ApplicationCache, CaretBrowsing = settings.CaretBrowsing, CursiveFontFamily = settings.CursiveFontFamily, Databases = settings.Databases, DefaultEncoding = settings.DefaultEncoding, DefaultFixedFontSize = settings.DefaultFixedFontSize, DefaultFontSize = settings.DefaultFontSize, FantasyFontFamily = settings.FantasyFontFamily, FileAccessFromFileUrls = settings.FileAccessFromFileUrls, FixedFontFamily = settings.FixedFontFamily, ImageLoading = settings.ImageLoading, ImageShrinkStandaloneToFit = settings.ImageShrinkStandaloneToFit, Java = settings.Java, JavaScript = settings.JavaScript, JavaScriptAccessClipboard = settings.JavaScriptAccessClipboard, JavaScriptCloseWindows = settings.JavaScriptCloseWindows, JavaScriptDomPaste = settings.JavaScriptDomPaste, JavaScriptOpenWindows = settings.JavaScriptOpenWindows, LocalStorage = settings.LocalStorage, MinimumFontSize = settings.MinimumFontSize, MinimumLogicalFontSize = settings.MinimumLogicalFontSize, Plugins = settings.Plugins, RemoteFonts = settings.RemoteFonts, SansSerifFontFamily = settings.SansSerifFontFamily, SerifFontFamily = settings.SerifFontFamily, StandardFontFamily = settings.StandardFontFamily, //TabToLinks = settings.TabToLinks, //TextAreaResize = settings.TextAreaResize, UniversalAccessFromFileUrls = settings.UniversalAccessFromFileUrls, WebGL = settings.WebGL, WebSecurity = settings.WebSecurity }; String url = browserConfig.BrowserSourceSettings.Url; if (browserConfig.BrowserSourceSettings.IsApplyingTemplate) { url = "http://absolute"; } lock (browserLock) { ManualResetEventSlim createdBrowserEvent = new ManualResetEventSlim(); CefRuntime.PostTask(CefThreadId.UI, BrowserTask.Create(() => { try { browser = CefBrowserHost.CreateBrowserSync(windowInfo, browserClient, browserSettings, new Uri(url)); BrowserManager.Instance.RegisterBrowser(browser.Identifier, this); // request the render process id for volume control browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("renderProcessIdRequest")); } catch (Exception) { browser = null; } finally { createdBrowserEvent.Set(); } })); createdBrowserEvent.Wait(); } return(browser != null); }
public static void StartNew(CefThreadId threadId, Action action) { CefRuntime.PostTask(threadId, new CefActionTask(action)); }
public void DeleteCookies() { var deleteAll = new CookiesDeleteTask(); CefRuntime.PostTask(CefThreadId.IO, deleteAll); }
public static void PostTaskUncertainty(CefThreadId threadId, Action action) { CefRuntime.PostTask(threadId, new ActionTask(action)); }