コード例 #1
0
        public Task Navigate(Uri iUri, object iViewModel, JavascriptBindingMode iMode = JavascriptBindingMode.TwoWay)
        {
            if (iUri == null)
            {
                throw ExceptionHelper.GetArgument(string.Format("ViewModel not registered: {0}", iViewModel.GetType()));
            }

            _Navigating = true;

            INavigable oldvm = (Binding != null) ? Binding.Root as INavigable : null;

            if (_UseINavigable && (oldvm != null))
            {
                oldvm.Navigation = null;
            }

            var wh = new WindowHelper(new HTMLLogicWindow());

            if (_CurrentWebControl != null)
            {
                _CurrentWebControl.Crashed -= Crashed;
            }

            Task closetask = (_CurrentWebControl != null) ? _Window.CloseAsync() : TaskHelper.Ended();

            _NextWebControl = _IWebViewLifeCycleManager.Create();
            _NextWebControl.ConsoleMessage += ConsoleMessage;

            TaskCompletionSource <IAwesomeBinding> tcs = new TaskCompletionSource <IAwesomeBinding>();

            UrlEventHandler sourceupdate = null;

            sourceupdate = (o, e) =>
            {
                _NextWebControl.AddressChanged -= sourceupdate;
                _IAwesomiumBindingFactory.Bind(_NextWebControl, iViewModel, wh, iMode).WaitWith(closetask,
                                                                                                t => Switch(t, wh.__window__, tcs));
            };

            _NextWebControl.AddressChanged += sourceupdate;

            if (_NextWebControl.Source == iUri)
            {
                _NextWebControl.Reload(false);
            }
            else
            {
                _NextWebControl.Source = iUri;
            }

            return(tcs.Task);
        }
コード例 #2
0
        //private void Crashed(object sender, CrashedEventArgs e)
        //{
        //    if ((WebCore.IsShuttingDown) || (!WebCore.IsInitialized) || (Application.Current==null))
        //        return;

        //    var dest = _CurrentWebControl.Source;
        //    var vm = Binding.Root;

        //    LogCritical("WebView crashed trying recover");

        //    _IWebViewLifeCycleManager.Dispose(_CurrentWebControl);
        //    _CurrentWebControl.ConsoleMessage -= ConsoleMessage;
        //    _CurrentWebControl.Crashed -= Crashed;
        //    _CurrentWebControl = null;

        //    Binding = null;

        //    WebCore.QueueWork(() => Navigate(dest, vm, JavascriptBindingMode.TwoWay));
        //}

        public Task Navigate(string iUri, object iViewModel, JavascriptBindingMode iMode = JavascriptBindingMode.TwoWay)
        {
            if (iUri == null)
            {
                throw ExceptionHelper.GetArgument(string.Format("ViewModel not registered: {0}", iViewModel.GetType()));
            }

            _Navigating = true;

            INavigable oldvm = (Binding != null) ? Binding.Root as INavigable : null;

            if (_UseINavigable && (oldvm != null))
            {
                oldvm.Navigation = null;
            }

            var wh = new WindowHelper(new HTMLLogicWindow());

            //if (_CurrentWebControl != null)
            //    _CurrentWebControl.Crashed -= Crashed;

            Task closetask = (_CurrentWebControl != null) ? _Window.CloseAsync() : TaskHelper.Ended();

            _NextWebControl = _IWebViewLifeCycleManager.Create();
            _NextWebControl.HTMLWindow.ConsoleMessage += ConsoleMessage;

            TaskCompletionSource <IHTMLBinding> tcs = new TaskCompletionSource <IHTMLBinding>();

            EventHandler <LoadEndEventArgs> sourceupdate = null;

            sourceupdate = (o, e) =>
            {
                _NextWebControl.HTMLWindow.LoadEnd -= sourceupdate;

                HTML_Binding.Bind(_NextWebControl, iViewModel, iMode, wh).
                WaitWith(closetask, t => Switch(t, wh.__window__, tcs));
            };

            _Url = iUri;
            _NextWebControl.HTMLWindow.LoadEnd += sourceupdate;
            _NextWebControl.HTMLWindow.NavigateTo(iUri);

            return(tcs.Task);
        }
コード例 #3
0
        private Task <IHTMLBinding> Navigate(Uri uri, object iViewModel, JavascriptBindingMode iMode = JavascriptBindingMode.TwoWay)
        {
            if (uri == null)
            {
                throw ExceptionHelper.GetArgument($"ViewModel not registered: {iViewModel.GetType()}");
            }

            _Navigating = true;

            var oldvm = Binding?.Root as INavigable;

            if (_UseINavigable && (oldvm != null))
            {
                oldvm.Navigation = null;
            }

            var wh = new WindowHelper(new HTMLLogicWindow());

            if (_CurrentWebControl != null)
            {
                _CurrentWebControl.HTMLWindow.Crashed -= Crashed;
            }

            var closetask = (_CurrentWebControl != null) ? _Window.CloseAsync() : TaskHelper.Ended();

            _NextWebControl = _WebViewLifeCycleManager.Create();
            _NextWebControl.HTMLWindow.ConsoleMessage += ConsoleMessage;

            var moderWindow = _NextWebControl.HTMLWindow as IModernWebBrowserWindow;

            if (moderWindow != null)
            {
                var debugContext = _WebViewLifeCycleManager.DebugContext;
                EventHandler <BeforeJavascriptExcecutionArgs> before = null;
                before = (o, e) =>
                {
                    moderWindow.BeforeJavascriptExecuted -= before;
                    e.JavascriptExecutor(_javascriptFrameworkManager.GetMainScript(debugContext));
                };
                moderWindow.BeforeJavascriptExecuted += before;
            }

            var tcs = new TaskCompletionSource <IHTMLBinding>();

            EventHandler <LoadEndEventArgs> sourceupdate = null;

            sourceupdate = (o, e) =>
            {
                var injectorFactory = GetInjectorFactory(uri);
                _NextWebControl.HTMLWindow.LoadEnd -= sourceupdate;
                var engine = new HTMLViewEngine(_NextWebControl, injectorFactory, _webSessionLogger);

                HTML_Binding.Bind(engine, iViewModel, iMode, wh).WaitWith(closetask, t => Switch(t, wh.__window__, tcs));
            };

            Url = uri;
            _NextWebControl.HTMLWindow.LoadEnd += sourceupdate;
            _NextWebControl.HTMLWindow.NavigateTo(uri);

            return(tcs.Task);
        }
コード例 #4
0
        private Task <IHtmlBinding> Navigate(Uri uri, object viewModel, JavascriptBindingMode mode = JavascriptBindingMode.TwoWay)
        {
            if (uri == null)
            {
                throw ExceptionHelper.GetArgument($"ViewModel not registered: {viewModel.GetType()}");
            }

            _Navigating = true;

            var oldvm = GetMainViewModel(Binding) as INavigable;

            if (_UseINavigable && (oldvm != null))
            {
                oldvm.Navigation = null;
            }

            if (_CurrentWebControl != null)
            {
                _CurrentWebControl.HtmlWindow.Crashed -= Crashed;
            }

            var closetask = (_CurrentWebControl != null) ? _Window.CloseAsync() : TaskHelper.Ended();

            _NextWebControl = _WebViewLifeCycleManager.Create();
            _NextWebControl.HtmlWindow.ConsoleMessage += ConsoleMessage;

            var moderWindow = _NextWebControl.HtmlWindow as IModernWebBrowserWindow;

            var injectorFactory = GetInjectorFactory(uri);
            var engine          = new HtmlViewEngine(_NextWebControl, injectorFactory, _webSessionLogger);

            var dataContext = new DataContextViewModel(viewModel);
            var initVm      = HtmlBinding.GetBindingBuilder(engine, dataContext, mode);

            if (moderWindow != null)
            {
                var debugContext = _WebViewLifeCycleManager.DebugContext;
                EventHandler <BeforeJavascriptExcecutionArgs> before = null;
                before = (o, e) =>
                {
                    moderWindow.BeforeJavascriptExecuted -= before;
                    e.JavascriptExecutor(_JavascriptFrameworkManager.GetMainScript(debugContext));
                };
                moderWindow.BeforeJavascriptExecuted += before;
            }
            var tcs = new TaskCompletionSource <IHtmlBinding>();

            EventHandler <LoadEndEventArgs> sourceupdate = null;

            sourceupdate = async(o, e) =>
            {
                _NextWebControl.HtmlWindow.LoadEnd -= sourceupdate;

                var builder = await initVm;
                await builder.CreateBinding(_WebViewLifeCycleManager.DebugContext).WaitWith(closetask, t => Switch(t, dataContext.Window, tcs)).ConfigureAwait(false);
            };

            Url = uri;
            _NextWebControl.HtmlWindow.LoadEnd += sourceupdate;
            _NextWebControl.HtmlWindow.NavigateTo(uri);

            return(tcs.Task);
        }