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); }
/// <summary> /// Create a new visual to render. /// </summary> /// <returns></returns> private WebControl CreateRenderable() { // Get the web control. var pControl = new WebControl(); // Create a web-session with our settings. if (pWebSession == null) { pWebSession = WebCore.CreateWebSession(new WebPreferences() { EnableGPUAcceleration = Properties.Settings.Default.EnableGPUAcceleration, Databases = Properties.Settings.Default.EnableWebDatabases, WebGL = Properties.Settings.Default.EnableWebGL, WebSecurity = Properties.Settings.Default.EnableWebSecurity, FileAccessFromFileURL = Properties.Settings.Default.EnableWebFileAccessFromFileURL, Plugins = true, }); } pControl.WebSession = pWebSession; // Set the render dimensions. pControl.Width = this.RenderResolution.X; pControl.Height = this.RenderResolution.Y; // Hide the surface while we load. if (ActiveSurface != null) ActiveSurface.ContentOpacity = 0.01; // When the process has been createad, bind the global JS objects. // http://awesomium.com/docs/1_7_rc3/sharp_api/html/M_Awesomium_Core_IWebView_CreateGlobalJavascriptObject.htm pControl.ProcessCreated += (object sender, EventArgs e) => { // CALLING window.Surface = {} in JS here has no effect. // Bind all the Authority.request and Authority.call methods. Log.Write("Display Process Created (1)", this.ToString(), Log.Type.AppError); BindAPIFunctions(pControl); }; UrlEventHandler p = null; p = new UrlEventHandler((object senderOuter, UrlEventArgs eOuter) => { // Unbind this handler. pControl.DocumentReady -= p; // Force a re-load so the $(document).ready will have access to our Authority.request etc. pControl.Reload(false); // CALLING window.Surface = {} in JS here has no effect. //SignalSurfacePropertiesChanged(); Log.Write("Display DocReady (1)", this.ToString(), Log.Type.AppError); // Bind the other events. #region Events // Handle navigating away from the URL in the load instruction. pControl.AddressChanged += (object sender, UrlEventArgs e) => { // Rebind the API methods? Log.Write("Display has changed web address. " + e.Url, this.ToString(), Log.Type.DisplayInfo); }; // Handle console messages. pControl.TitleChanged += (object sender, TitleChangedEventArgs e) => { this.Title = e.Title; }; // Document ready.. do we beat JQuery? pControl.DocumentReady += (object sender, UrlEventArgs e) => { // Show the surface now we are loaded. if (ActiveSurface != null) ActiveSurface.ContentOpacity = 1.0; // CALLING window.Surface = {} in JS here does not work quick enough. Log.Write("Display DocReady (2)", this.ToString(), Log.Type.AppError); SignalSurfacePropertiesChanged(); // EXPERIMENTAL - this sort of works.. depends on how the page detects touch events.. // SEE: Nice example: http://paulirish.com/demo/multi // SEE: Nicer example: Bing maps! // Try to inject multi-touch into the page. if (ActiveSurface.AttemptMultiTouchInject) { pControl.ExecuteJavascript(Properties.Resources.MultiTouchInject); } }; // Handle changes in responsiveness. pControl.ResponsiveChanged += (object sender, ResponsiveChangedEventArgs e) => { // If it is not responsive, log the problem. if (!e.IsResponsive) { Log.Write("Display is not responsive. Try reloading.", this.ToString(), Log.Type.DisplayError); //this.Reload(false, true); } else { Log.Write("Ready", this.ToString(), Log.Type.DisplayError); } }; // Handle crashes by reloading. pControl.Crashed += (object sender, CrashedEventArgs e) => { // Log the crash. Log.Write("Display crashed - forcing reload. Termination Status = " + e.Status.ToString(), this.LoadInstruction, Log.Type.DisplayError); // Force a hard-reload. This will remove then re-create the entire web control. this.Reload(true); }; /* // Handle javascript updates. pControl.JSConsoleMessageAdded += (object sender, Awesomium.Core.JSConsoleMessageEventArgs e) => { Log.Write("JS line " + e.LineNumber + ": " + e.Message, pActiveDisplay.ToString(), Log.Type.DisplayInfo); }; // Handle pop-up messages (like alert). pControl.ShowPopupMenu += (object sender, PopupMenuEventArgs e) => { }; */ #endregion }); pControl.DocumentReady += p; // Set the load instruction. // n.b. we have to then re-load it later to get access to our value pControl.Source = new Uri(this.LoadInstruction); // Return the created control. return pControl; }
/// <summary> /// Create a new visual to render. /// </summary> /// <returns></returns> private WebControl CreateRenderable() { // Get the web control. var pControl = new WebControl(); // Create a web-session with our settings. if (pWebSession == null) { pWebSession = WebCore.CreateWebSession(new WebPreferences() { EnableGPUAcceleration = Properties.Settings.Default.EnableGPUAcceleration, Databases = Properties.Settings.Default.EnableWebDatabases, WebGL = Properties.Settings.Default.EnableWebGL, WebSecurity = Properties.Settings.Default.EnableWebSecurity, FileAccessFromFileURL = Properties.Settings.Default.EnableWebFileAccessFromFileURL, Plugins = true, }); } pControl.WebSession = pWebSession; // Set the render dimensions. pControl.Width = this.RenderResolution.X; pControl.Height = this.RenderResolution.Y; // Hide the surface while we load. if (ActiveSurface != null) { ActiveSurface.ContentOpacity = 0.01; } // When the process has been createad, bind the global JS objects. // http://awesomium.com/docs/1_7_rc3/sharp_api/html/M_Awesomium_Core_IWebView_CreateGlobalJavascriptObject.htm pControl.ProcessCreated += (object sender, EventArgs e) => { // CALLING window.Surface = {} in JS here has no effect. // Bind all the Authority.request and Authority.call methods. Log.Write("Display Process Created (1)", this.ToString(), Log.Type.AppError); BindAPIFunctions(pControl); }; UrlEventHandler p = null; p = new UrlEventHandler((object senderOuter, UrlEventArgs eOuter) => { // Unbind this handler. pControl.DocumentReady -= p; // Force a re-load so the $(document).ready will have access to our Authority.request etc. pControl.Reload(false); // CALLING window.Surface = {} in JS here has no effect. //SignalSurfacePropertiesChanged(); Log.Write("Display DocReady (1)", this.ToString(), Log.Type.AppError); // Bind the other events. #region Events // Handle navigating away from the URL in the load instruction. pControl.AddressChanged += (object sender, UrlEventArgs e) => { // Rebind the API methods? Log.Write("Display has changed web address. " + e.Url, this.ToString(), Log.Type.DisplayInfo); }; // Handle console messages. pControl.TitleChanged += (object sender, TitleChangedEventArgs e) => { this.Title = e.Title; }; // Document ready.. do we beat JQuery? pControl.DocumentReady += (object sender, UrlEventArgs e) => { // Show the surface now we are loaded. if (ActiveSurface != null) { ActiveSurface.ContentOpacity = 1.0; } // CALLING window.Surface = {} in JS here does not work quick enough. Log.Write("Display DocReady (2)", this.ToString(), Log.Type.AppError); SignalSurfacePropertiesChanged(); // EXPERIMENTAL - this sort of works.. depends on how the page detects touch events.. // SEE: Nice example: http://paulirish.com/demo/multi // SEE: Nicer example: Bing maps! // Try to inject multi-touch into the page. if (ActiveSurface.AttemptMultiTouchInject) { pControl.ExecuteJavascript(Properties.Resources.MultiTouchInject); } }; // Handle changes in responsiveness. pControl.ResponsiveChanged += (object sender, ResponsiveChangedEventArgs e) => { // If it is not responsive, log the problem. if (!e.IsResponsive) { Log.Write("Display is not responsive. Try reloading.", this.ToString(), Log.Type.DisplayError); //this.Reload(false, true); } else { Log.Write("Ready", this.ToString(), Log.Type.DisplayError); } }; // Handle crashes by reloading. pControl.Crashed += (object sender, CrashedEventArgs e) => { // Log the crash. Log.Write("Display crashed - forcing reload. Termination Status = " + e.Status.ToString(), this.LoadInstruction, Log.Type.DisplayError); // Force a hard-reload. This will remove then re-create the entire web control. this.Reload(true); }; /* * // Handle javascript updates. * pControl.JSConsoleMessageAdded += (object sender, Awesomium.Core.JSConsoleMessageEventArgs e) => * { * Log.Write("JS line " + e.LineNumber + ": " + e.Message, pActiveDisplay.ToString(), Log.Type.DisplayInfo); * }; * * // Handle pop-up messages (like alert). * pControl.ShowPopupMenu += (object sender, PopupMenuEventArgs e) => * { * * }; */ #endregion }); pControl.DocumentReady += p; // Set the load instruction. // n.b. we have to then re-load it later to get access to our value pControl.Source = new Uri(this.LoadInstruction); // Return the created control. return(pControl); }