Example #1
0
        private void RegisterJsHandlers()
        {
            // Register javascript handlers
            IEnumerable <object> jsHandlerObjs = IoC.GetAllInstances(typeof(ChromelyJsHandler));

            if (jsHandlerObjs != null)
            {
                var jsHandlers = jsHandlerObjs.ToList();

                foreach (var item in jsHandlers)
                {
                    if (item is ChromelyJsHandler)
                    {
                        ChromelyJsHandler             handler = (ChromelyJsHandler)item;
                        CefSharpGlobal.BindingOptions options = null;
                        if ((handler.BindingOptions != null) && (handler.BindingOptions is CefSharpGlobal.BindingOptions))
                        {
                            options = (CefSharpGlobal.BindingOptions)handler.BindingOptions;
                        }

                        if (handler.RegisterAsAsync)
                        {
                            m_browser.RegisterAsyncJsObject(handler.JsMethod, handler.BoundObject, options);
                        }
                        else
                        {
                            m_browser.RegisterJsObject(handler.JsMethod, handler.BoundObject, options);
                        }
                    }
                }
            }
        }
Example #2
0
        public void RegisterJsHandlers()
        {
            // Register javascript handlers
            object[] jsHandlerObjs = IoC.GetAllInstances(typeof(ChromelyJsHandler));
            if (jsHandlerObjs != null)
            {
                var jsHandlers = jsHandlerObjs.ToList();

                foreach (var item in jsHandlers)
                {
                    if (item is ChromelyJsHandler)
                    {
                        ChromelyJsHandler handler = (ChromelyJsHandler)item;
                        BindingOptions    options = null;

                        if ((handler.BindingOptions != null) && (handler.BindingOptions is BindingOptions))
                        {
                            options = (BindingOptions)handler.BindingOptions;
                        }

                        object boundObject = handler.UseDefault ? new CefSharpBoundObject() : handler.BoundObject;

                        if (handler.RegisterAsAsync)
                        {
                            m_browser.RegisterAsyncJsObject(handler.ObjectNameToBind, boundObject, options);
                        }
                        else
                        {
                            m_browser.RegisterJsObject(handler.ObjectNameToBind, boundObject, options);
                        }
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Registers Javascript object handler.
        /// </summary>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <param name="chromelyJsHandler">
        /// The chromely js handler.
        /// </param>
        /// <returns>
        /// The <see cref="ChromelyConfiguration"/> object.
        /// </returns>
        public static ChromelyConfiguration RegisterJsHandler(this ChromelyConfiguration configuration, ChromelyJsHandler chromelyJsHandler)
        {
            if (chromelyJsHandler != null)
            {
                IoC.RegisterInstance(typeof(ChromelyJsHandler), chromelyJsHandler.Key, chromelyJsHandler);
            }

            return(configuration);
        }