public void InitWebControl(WebControl wc, string filepath) { // Setup web control _web = wc; _web.Source = new Uri(new FileInfo(filepath).FullName); // porting web console to native console _web.ConsoleMessage += (sender1, args) => Console.Out.WriteLine("[JS]{1}:{2} {0}", args.Message, args.Source, args.LineNumber); _web.ShowContextMenu += (sender1, args) => args.Handled = true; //WebControl.DocumentReady += (sender1, arg) => WebControl.ExecuteJavascript(string.Format("alert('Gigi says hi');")); //Register global function to be called by Web using (JSObject webApp = _web.CreateGlobalJavascriptObject("native")) //create native object in WebApp global scope, i.e. window.native { webApp.BindAsync("callNative", (sender1, args) => { Console.Out.WriteLine((string)args.Arguments[0]); //_web.ExecuteJavascript(string.Format("alert({0});", "Gigi is calling")); //Execute.OnUIThreadAsync(() => _web.ExecuteJavascript(string.Format("mymethod({0});", 60))); }); } }
private void SetScriptingObject(WebControl webcontrol) { using (JSObject interop = webcontrol.CreateGlobalJavascriptObject("external")) { interop.Bind("OnLinkClicked", false, OnLinkClicked); } }
/// <summary> /// Helper function to bind the API functions to a web control. /// </summary> /// <param name="pControl">The web control to bind the functions too.</param> private void BindAPIFunctions(WebControl pControl) { // Create and acquire a global Javascript object - this will persist for the lifetime of the web-view. using (JSObject pAuthority = pControl.CreateGlobalJavascriptObject(Authority.APIObject_Authority)) { // Handle requests for Authority.request. pAuthority.Bind(Authority.APIObject_AuthorityRequest, false, (s, e) => { // Process the arguments. var sHandler = (e.Arguments.Length > 0 && e.Arguments[0].IsString) ? ((String)e.Arguments[0]) : null; var dObject = (e.Arguments.Length > 1 && e.Arguments[1].IsObject) ? e.Arguments[1] : new JSValue(); // Return the result. var bResult = Authority.ProcessRequest(this, this.ActiveSurface, sHandler, dObject); //e.Result = new JSValue(bResult); }); // Handle requests for Authority.request. pAuthority.Bind(Authority.APIObject_AuthorityCall, false, (s, e) => { // Process the arguments. var sTargetSurface = (e.Arguments.Length > 0 && e.Arguments[0].IsString) ? ((String)e.Arguments[0]) : null; var sTargetFunction = (e.Arguments.Length > 1 && e.Arguments[1].IsString) ? ((String)e.Arguments[1]) : null; //var dObject = (e.Arguments.Length > 2 && e.Arguments[2].IsObject) ? e.Arguments[2] : new JSValue(); List<JSValue> lArgs = new List<JSValue>(); for (int iArg = 2; iArg < e.Arguments.Length; ++iArg) { lArgs.Add(e.Arguments[iArg]); } // Return the result. var bResult = Authority.ProcessRMICall(this, this.ActiveSurface, sTargetSurface, sTargetFunction, lArgs.ToArray()); //e.Result = new JSValue(bResult); }); // Handle requests for Authority.request. pAuthority.Bind(Authority.APIObject_AuthorityLog, false, (s, e) => { // Process the arguments. StringBuilder sOut = new StringBuilder(); for (int iArg = 0; iArg < e.Arguments.Length; ++iArg) { sOut.Append(ToJSON(e.Arguments[iArg])); if (iArg < (e.Arguments.Length-1)) sOut.Append(" --- "); } // Return the result. Log.Write("JS Message: " + sOut.ToString(), this.ToString(), Log.Type.DisplayInfo); }); } // Create a surface object. using (JSObject pSurface = pControl.CreateGlobalJavascriptObject(Authority.APIObject_Surface)) { pSurface["Name"] = new JSValue(ActiveSurface.Identifier); pSurface["Width"] = new JSValue(ActiveSurface.Width); pSurface["Height"] = new JSValue(ActiveSurface.Height); pSurface["AspectRatio"] = new JSValue(ActiveSurface.AspectRatio); pSurface["Angle"] = new JSValue(ActiveSurface.Angle); } // Signal that the properties have changed too. //SignalSurfacePropertiesChanged(); }
void BindMethods() { JSObject jsobject = wc.CreateGlobalJavascriptObject("jsobject"); jsobject.Bind("callNETReturnXpath", false, JSHandler); }
/// <summary> /// Helper function to bind the API functions to a web control. /// </summary> /// <param name="pControl">The web control to bind the functions too.</param> private void BindAPIFunctions(WebControl pControl) { // Create and acquire a global Javascript object - this will persist for the lifetime of the web-view. using (JSObject pAuthority = pControl.CreateGlobalJavascriptObject(Authority.APIObject_Authority)) { // Handle requests for Authority.request. pAuthority.Bind(Authority.APIObject_AuthorityRequest, false, (s, e) => { // Process the arguments. var sHandler = (e.Arguments.Length > 0 && e.Arguments[0].IsString) ? ((String)e.Arguments[0]) : null; var dObject = (e.Arguments.Length > 1 && e.Arguments[1].IsObject) ? e.Arguments[1] : new JSValue(); // Return the result. var bResult = Authority.ProcessRequest(this, this.ActiveSurface, sHandler, dObject); //e.Result = new JSValue(bResult); }); // Handle requests for Authority.request. pAuthority.Bind(Authority.APIObject_AuthorityCall, false, (s, e) => { // Process the arguments. var sTargetSurface = (e.Arguments.Length > 0 && e.Arguments[0].IsString) ? ((String)e.Arguments[0]) : null; var sTargetFunction = (e.Arguments.Length > 1 && e.Arguments[1].IsString) ? ((String)e.Arguments[1]) : null; //var dObject = (e.Arguments.Length > 2 && e.Arguments[2].IsObject) ? e.Arguments[2] : new JSValue(); List <JSValue> lArgs = new List <JSValue>(); for (int iArg = 2; iArg < e.Arguments.Length; ++iArg) { lArgs.Add(e.Arguments[iArg]); } // Return the result. var bResult = Authority.ProcessRMICall(this, this.ActiveSurface, sTargetSurface, sTargetFunction, lArgs.ToArray()); //e.Result = new JSValue(bResult); }); // Handle requests for Authority.request. pAuthority.Bind(Authority.APIObject_AuthorityLog, false, (s, e) => { // Process the arguments. StringBuilder sOut = new StringBuilder(); for (int iArg = 0; iArg < e.Arguments.Length; ++iArg) { sOut.Append(ToJSON(e.Arguments[iArg])); if (iArg < (e.Arguments.Length - 1)) { sOut.Append(" --- "); } } // Return the result. Log.Write("JS Message: " + sOut.ToString(), this.ToString(), Log.Type.DisplayInfo); }); } // Create a surface object. using (JSObject pSurface = pControl.CreateGlobalJavascriptObject(Authority.APIObject_Surface)) { pSurface["Name"] = new JSValue(ActiveSurface.Identifier); pSurface["Width"] = new JSValue(ActiveSurface.Width); pSurface["Height"] = new JSValue(ActiveSurface.Height); pSurface["AspectRatio"] = new JSValue(ActiveSurface.AspectRatio); pSurface["Angle"] = new JSValue(ActiveSurface.Angle); } // Signal that the properties have changed too. //SignalSurfacePropertiesChanged(); }