protected override void OnWebKitInitialized() { CefRuntime.RegisterExtension(bindingExtensionName, EmbeddedResourceReader.Read(typeof(MessageRenderProcessHandler), "/Renderer/Javascript/extension.js"), handler); base.OnWebKitInitialized(); }
protected override void OnWebKitInitialized() { // 注册CefTester脚本 CefRuntime.RegisterExtension("CefTester.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\CefTester\Resources\js", "register.js")), new CefTesterCefV8Handler()); // 注册集中管控脚本 CefRuntime.RegisterExtension("HomePage.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\HomePage\Resources\js", "register.js")), new HomePageCefV8Handler()); // 注册物流园集中管控脚本 CefRuntime.RegisterExtension("HomeYNWLY.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\HomeYNWLY\Resources\js", "register.js")), new HomeYNWLYCefV8Handler()); // 注册汽车衡脚本 CefRuntime.RegisterExtension("TruckWeighter.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\TruckWeighter\Resources\js", "register.js")), new TruckWeighterCefV8Handler()); // 注册汽车采样机脚本 CefRuntime.RegisterExtension("CarSampler.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\CarSampler\Resources\js", "register.js")), new CarSamplerCefV8Handler()); // 注册皮带采样机脚本 CefRuntime.RegisterExtension("TrainBeltSampler.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\TrainBeltSampler\Resources\js", "register.js")), new TrainBeltSamplerCefV8Handler()); // 注册汽车监控脚本 CefRuntime.RegisterExtension("CarMonitor.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\CarMonitor\Resources\js", "register.js")), new CarMonitorCefV8Handler()); // 注册全自动制样机脚本 CefRuntime.RegisterExtension("AutoMaker.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\AutoMaker\Resources\js", "register.js")), new AutoMakerCefV8Handler()); // 注册智能存样柜及气动传输脚本 CefRuntime.RegisterExtension("AutoCupboardPneumaticTransfer.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\AutoCupboardPneumaticTransfer\Resources\js", "register.js")), new AutoCupboardCefV8Handler()); // 注册智能存样柜及气动传输 CefRuntime.RegisterExtension("AutoCupboard.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\AutoCupboardPneumaticTransfer\Resources\js", "register.js")), new AutoCupboardCefV8Handler()); // 注册翻车机 CefRuntime.RegisterExtension("TrainUpender.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\TrainUpender\Resources\js", "register.js")), new TrainUpenderCefV8Handler()); base.OnWebKitInitialized(); }
protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context) { /*缓存数据库*/ string extensionCode = "var cachedb;" + "if(!cachedb)" + " cachedb={};"+ "(function() {" + " cachedb.Connect = function(dbName) {" + " native function Connect(dbName);"+ " return Connect(dbName);"+ " };" + " cachedb.Execute = function(commandText) {" + " native function Execute(commandText);"+ " return Execute(commandText);"+ " };" + " cachedb.Query = function(commandText) {" + " native function Query(commandText);"+ " return Query(commandText);"+ " };" + " cachedb.Close = function() {" + " native function Close();"+ " return Close();"+ " };" + "})();"; CefV8Handler ExtendsionHandler = new CwbJsExtendHandler(browser); CefRuntime.RegisterExtension("v8/cachedb", extensionCode, ExtendsionHandler); /*屏幕分辨率设置*/ int w = webBrowser.screenWidth; int h = webBrowser.screenHeight; if (w > 0 && h > 0) { string jscode = "Object.defineProperty(window.screen, 'height', {" + " get: function() {" + " return " + h + ";" + " }" + "});" + "Object.defineProperty(window.screen, 'width', {" + " get: function() {" + " return " + w + ";" + " }" + "});"; frame.ExecuteJavaScript(jscode, frame.Url, 0); } /*注册执行C#方法*/ CefV8Value globalValue = context.GetGlobal(); CefV8Handler callHandler = new CwbJsExtendHandler(browser); CefV8Value callMethod = CefV8Value.CreateFunction("CallCSharpMethod", callHandler); globalValue.SetValue("CallCSharpMethod", callMethod, CefV8PropertyAttribute.None); base.OnContextCreated(browser, frame, context); }
protected override void OnWebKitInitialized() { var extensions = WinFormium.Runtime.Container.GetAllInstances <JavaScriptExtensionBase>(); foreach (var ext in extensions) { CefRuntime.RegisterExtension(ext.Name, ext.JavaScriptCode, ext.GetHandler(JSBridge)); } }
/// <summary> /// 通过反射机制 注册c#函数到JS /// </summary> public void RegisterJs() { JsEvent js = new JsEvent(mainView); Cef = new CefJsV8Handler(js); string javascriptCode = CefJavaScriptEx.CreateJsCodeByObject(js, "Cef"); CefRuntime.RegisterExtension("Cef", javascriptCode, Cef); }
/// <summary> /// Called after WebKit has been initialized. /// </summary> protected override void OnWebKitInitialized() { Logger.Info("WebKit initialized."); CefRuntime.RegisterExtension("htmlUi.native", GetHtmlUiScript("native", false), NativeMessageHandler); if (!Application.IncludeHtmUiScriptMapping) { CefRuntime.RegisterExtension("htmlUi.main", GetHtmlUiScript("main", false), NativeMessageHandler); } }
protected override void OnWebKitInitialized() { // 注册CefTester脚本 CefRuntime.RegisterExtension("CefTester.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\CefTester\Resources\js", "register.js")), new CefTesterCefV8Handler()); // 注册集中管控脚本 CefRuntime.RegisterExtension("HomePage.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\HomePage\Resources\js", "register.js")), new HomePageCefV8Handler()); // 注册汽车衡脚本 CefRuntime.RegisterExtension("TruckWeighter.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\TruckWeighter\Resources\js", "register.js")), new TruckWeighterCefV8Handler()); base.OnWebKitInitialized(); }
protected override void OnWebKitInitialized() { #region 原生方式注册 ExampleA exampleA = new BsAv8Handler(); const string exampleAJavascriptCode = @"function exampleA() {} if (!exampleA) exampleA = {}; (function() { exampleA.__defineGetter__('myParam', function() { native function GetMyParam(); return GetMyParam(); }); exampleA.__defineSetter__('myParam', function(arg0) { native function SetMyParam(arg0); SetMyParam(arg0); }); exampleA.myFunction = function() { native function MyFunction(); return MyFunction(); }; exampleA.getMyParam = function() { native function GetMyParam(); return GetMyParam(); }; exampleA.setMyParam = function(arg0) { native function SetMyParam(arg0); SetMyParam(arg0); }; exampleA.setAccount = function(arg0,arg1) { native function SetAccount(arg0,arg1); SetAccount(arg0,arg1); }; exampleA.setCookies = function(arg0) { native function SetCookies(arg0); SetCookies(arg0); }; })();"; CefRuntime.RegisterExtension("exampleAExtensionName", exampleAJavascriptCode, exampleA); #endregion 原生方式注册 ExampleA base.OnWebKitInitialized(); }
protected override void OnWebKitInitialized() { myHandle = new MyV8Handler(); const string jsCode = @"function myHandle() {} if (!myHandle) myHandle = {}; (function() { myHandle.__defineGetter__('name', function() { native function GetName(); return GetName(); }); myHandle.__defineSetter__('name', function(arg0) { native function SetName(arg0); SetName(arg0); }); myHandle.myFunction = function() { native function MyFunction(); return MyFunction(); }; myHandle.getEmail = function() { native function GetEmail(); return GetEmail(); }; myHandle.setEmail = function(arg0) { native function SetEmail(arg0); SetEmail(arg0); }; })();"; CefRuntime.RegisterExtension("myHandleName", jsCode, myHandle); base.OnWebKitInitialized(); }
protected override void OnWebKitInitialized() { Logger.Info("Webkit initialized"); if (_jsExtensions != null) { foreach (var n in _jsExtensions.Keys) { var val = _jsExtensions[n]; if (!string.IsNullOrEmpty(val)) { CefRuntime.RegisterExtension(n, val, null); Logger.Info("Registered JavaScript extension: " + n); } } _jsExtensions.Clear(); _jsExtensions = null; } base.OnWebKitInitialized(); }
protected override void OnWebKitInitialized() { // 注册CefTester脚本 CefRuntime.RegisterExtension("CefTester.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\CefTester\Resources\js", "register.js")), new CefTesterCefV8Handler()); // 注册集中管控脚本 CefRuntime.RegisterExtension("HomePage.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\HomePage\Resources\js", "register.js")), new HomePageCefV8Handler()); // 注册汽车衡脚本 CefRuntime.RegisterExtension("TruckWeighter.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\TruckWeighter\Resources\js", "register.js")), new TruckWeighterCefV8Handler()); // 注册汽车采样机脚本 CefRuntime.RegisterExtension("CarSampler.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\CarSampler\Resources\js", "register.js")), new CarSamplerCefV8Handler()); // 注册火车采样机脚本 CefRuntime.RegisterExtension("TrainSampler.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\TrainSampler\Resources\js", "register.js")), new TrainSamplerCefV8Handler()); // 注册火车皮带采样机脚本 CefRuntime.RegisterExtension("TrainBeltSampler.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\TrainBeltSampler\Resources\js", "register.js")), new TrainBeltSamplerCefV8Handler()); // 注册制样机脚本 CefRuntime.RegisterExtension("AutoMaker.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\AutoMaker\Resources\js", "register.js")), new AutoMakerCefV8Handler()); // 注册合样归批脚本 CefRuntime.RegisterExtension("BatchMachine.Register", System.IO.File.ReadAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Web\BatchMachine\Resources\js", "register.js")), new BatchMachineCefV8Handler()); base.OnWebKitInitialized(); }
protected override void OnWebKitInitialized() { CefRuntime.RegisterExtension("MessageEvent", "var gmApi = function(jsonArg) {\r\n native function MyNativeFunction(jsonArg);\r\n return MyNativeFunction(jsonArg);\r\n };", (CefV8Handler)this.myCefV8Handler); base.OnWebKitInitialized(); }
protected override void OnWebKitInitialized() { base.OnWebKitInitialized(); CefRuntime.RegisterExtension("test", EmbeddedResourceReader.Read(typeof(Handler), "/Javascript/test_extension.js"), new TestHandler()); }
/// <summary> /// Registers the HTML UI as extension if needed. /// </summary> private void RegisterHtmlUiAsExtensionIfNeeded() { #if !DEBUG CefRuntime.RegisterExtension("htmlUi.main", GetHtmlUiScript("main"), V8NativeHandler); #endif }
/// <summary> /// Called after WebKit has been initialized. /// </summary> protected override void OnWebKitInitialized() { CefRuntime.RegisterExtension("htmlUi.native", GetHtmlUiScript("native", false), V8NativeHandler); RegisterHtmlUiAsExtensionIfNeeded(); }
private static void RuntimeRegisterExtension(string s, string s1, ICefV8Handler arg3) { CefRuntime.RegisterExtension(s, s1, new CefV8HandlerImpl(arg3)); }