internal void OnBrowserCreated(CefBrowser browser) { BrowserWindowHandle = browser.GetHost().GetWindowHandle(); Browser = browser; ProcessMessageBridge = new MessageBridgeBrowserSide(Owner); JSBridge = new JavaScriptCommunicationBridge(); ProcessMessageBridge.AddMessageHandler(JSBridge); var handlers = WinFormium.Runtime.Container.GetAllInstances <ProcessMessageBridgeHandler>(); foreach (var handler in handlers) { ProcessMessageBridge.AddMessageHandler(handler); } Owner.OnBrowserCreated(); Browser.GetHost()?.WasResized(); Browser.GetHost()?.SendFocusEvent(true); WebViewIsReady = true; }
/// <summary> /// The on context menu command. /// </summary> /// <param name="browser"> /// The browser. /// </param> /// <param name="frame"> /// The frame. /// </param> /// <param name="state"> /// The state. /// </param> /// <param name="commandId"> /// The command id. /// </param> /// <param name="eventFlags"> /// The event flags. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> protected override bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags) { if (commandId == ShowDevTools) { var host = browser.GetHost(); var wi = CefWindowInfo.Create(); if (CefRuntime.Platform == CefRuntimePlatform.Windows) { wi.SetAsPopup(IntPtr.Zero, "DevTools"); } else { var parentWindowHandle = NativeMethods.gdk_x11_drawable_get_xid(IntPtr.Zero); wi.SetAsChild(parentWindowHandle, new CefRectangle(0, 0, 0, 0)); } host.ShowDevTools(wi, new DevToolsWebClient(), new CefBrowserSettings(), new CefPoint(0, 0)); } if (commandId == CloseDevTools) { browser.GetHost().CloseDevTools(); } if (commandId == Refresh) { browser.Reload(); } return(false); }
public void ShowDevTool() { string devUrl = browser.GetHost().GetDevToolsUrl(true); browser.GetMainFrame().ExecuteJavaScript( "window.open('" + devUrl + "');", "about:blank", 0); }
private LVCefClient _lvCefClient; //keeping references to anything CEF makes it crashy, release reference after browser made public void openDevTools() { if (_browser != null) { var host = _browser.GetHost(); var wi = CefWindowInfo.Create(); wi.SetAsPopup(IntPtr.Zero, "DevTools"); host.ShowDevTools(wi, new DevToolsWebClient(), new CefBrowserSettings(), new CefPoint(0, 0)); } }
public void showDevTools(bool firstWindow = true) { if (this.Browser != null) { CefBrowser b = firstWindow ? this.Browser : this.LastBrowser; CefWindowInfo wi = CefWindowInfo.Create(); wi.SetAsPopup(b.GetHost().GetWindowHandle(), "DevTools"); b.GetHost().ShowDevTools(wi, this.Client, new CefBrowserSettings(), new CefPoint()); } }
public void showDevTools(bool firstwindow = true) { this.allBrowsersSemaphore.Wait(); if (this.allBrowsers.Count > 0) { CefBrowser b = firstwindow ? this.allBrowsers.First() : this.allBrowsers.Last(); CefWindowInfo wi = CefWindowInfo.Create(); wi.SetAsPopup(b.GetHost().GetWindowHandle(), "DevTools"); b.GetHost().ShowDevTools(wi, this.Client, new CefBrowserSettings(), new CefPoint()); } this.allBrowsersSemaphore.Release(); }
public void CloseBrowser() { try { _bs.GetHost().CloseBrowser(true); _autoResetEvent.Set(); Logger.Info("close browser success:" + _url); } catch (Exception ex) { Logger.Error("CloseBrowser", ex); } }
protected override bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags) { if (commandId == ShowDevTools) { var host = browser.GetHost(); var wi = CefWindowInfo.Create(); wi.SetAsPopup(IntPtr.Zero, "DevTools"); host.ShowDevTools(wi, new DevToolsWebClient(), new CefBrowserSettings(), new CefPoint(0, 0)); } if (commandId == CloseDevTools) { browser.GetHost().CloseDevTools(); } return(false); }
void bc_OnCreated(object sender, EventArgs e) { bs = (CefBrowser)sender; var handle = bs.GetHost().GetWindowHandle(); ResizeWindow(handle, Parent.Width, Parent.Height); }
internal protected virtual void OnBrowserAfterCreated(CefBrowser browser) { m_browser = browser; m_browserWindowHandle = m_browser.GetHost().GetWindowHandle(); BrowserCreated?.Invoke(this, EventArgs.Empty); }
public void HandleEvents() { var menuController = _inputProcessor[0]; foreach (var button in _buttons) { var currentState = menuController.GetButtonState(button); if (currentState == GameControllerButtonState.None) { continue; } var eventType = currentState == GameControllerButtonState.Down ? CefKeyEventType.KeyDown : CefKeyEventType.KeyUp; var cefKeyEvent = new CefKeyEvent { EventType = eventType, WindowsKeyCode = (short)InputProcessor.GetVirtualKey(button) }; _browser.GetHost().SendKeyEvent(cefKeyEvent); } }
/// <summary> /// Handles the browser created event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void Window_BrowserCreated(object sender, BrowserCreatedEventArgs e) { // hook mouse events var threadId = NativeMethods.GetWindowThreadProcessId(CefBrowser.GetHost().GetWindowHandle(), IntPtr.Zero); NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_MOUSE, Browser_MouseEventDelegate, IntPtr.Zero, threadId); }
internal void Attach(CefBrowser browser) { FBrowser = browser; FBrowserHost = browser.GetHost(); FBrowserHost.SetMouseCursorChangeDisabled(true); FBrowserAttachedEvent.Set(); }
// Runs on the Cef thread. internal void OnCreated(CefBrowser browser) { browser.GetHost().SendFocusEvent(true); this.allBrowsersSemaphore.Wait(); this.allBrowsers.Add(browser); this.allBrowsersSemaphore.Release(); }
public void HandleAfterCreated(CefBrowser browser) { int width = 0, height = 0; bool hasAlreadyBeenInitialized = false; _mainUiDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate { if (_browser != null) { hasAlreadyBeenInitialized = true; } else { _browser = browser; _browserHost = _browser.GetHost(); _App.Associate(_browser, this); // _browserHost.SetFocus(IsFocused); width = (int)_browserWidth; height = (int)_browserHeight; } })); // Make sure we don't initialize ourselves more than once. That seems to break things. if (hasAlreadyBeenInitialized) { return; } if (width > 0 && height > 0) { _browserHost.WasResized(); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { Application.Current.EnsureMainThread(); if (!_disposed) { if (disposing) { // CEF browser if (CefBrowser != null) { var host = CefBrowser.GetHost(); if (host != null) { host.CloseBrowser(true); host.Dispose(); } CefBrowser.Dispose(); } DestroyControllers(); } _disposed = true; } }
/// <summary> /// 打开或者关闭DevTools /// </summary> /// <param name="_core"></param> /// <param name="browser"></param> public static void DevTools(CefWebBrowser _core, CefBrowser browser) { MainForm.Instance.Invoke(new Action(() => { if (!_core.DevToolsOpen) { if (MainForm.Instance.faTabStrip1.SelectedItem.DevToolsName == null || MainForm.Instance.faTabStrip1.SelectedItem.DevToolsName == string.Empty) { CefWindowInfo CefWindowInfo1; int devWidth = MainForm.Instance.faTabStrip1.SelectedItem.Width; MainForm.Instance.faTabStrip1.SelectedItem.splic.Panel1.AutoScroll = true; MainForm.Instance.faTabStrip1.SelectedItem.splic.Panel2.AutoScroll = true; MainForm.Instance.faTabStrip1.SelectedItem.splic.Panel2Collapsed = false; MainForm.Instance.faTabStrip1.SelectedItem.Tag = _core; CefWindowInfo1 = CefWindowInfo.Create(); CefWindowInfo1.X = devWidth / 2; CefWindowInfo1.Y = 0; CefRectangle rectangle = new CefRectangle(0, 0, devWidth / 2, _core.Height); //此举是为了多个Devtools打开的情况,要让后面的FindwindowEX函数能找到这个窗口的句柄 MainForm.Instance.faTabStrip1.SelectedItem.DevToolsName = "CefDevTools" + DateTime.Now.ToString("yyyyMMddHHmmss"); CefWindowInfo1.SetAsWindow(MainForm.Instance.faTabStrip1.SelectedItem.splic.Panel2.Handle, rectangle, MainForm.Instance.faTabStrip1.SelectedItem.DevToolsName); browser.GetHost().ShowDevTools(CefWindowInfo1, new DevFormClient(), new CefBrowserSettings(), new CefPoint(0, 0)); browser.GetHost().SetFocus(true); _core.DevToolsOpen = MainForm.Instance.faTabStrip1.SelectedItem.DevToolsOpen = true; MainForm.Instance.faTabStrip1.SelectedItem.ItemBrowser = browser; MainForm.Instance.faTabStrip1.SelectedItem.splic.BackColor = SystemColors.ControlDark; } else { MainForm.Instance.faTabStrip1.SelectedItem.splic.Panel2Collapsed = false; _core.DevToolsOpen = MainForm.Instance.faTabStrip1.SelectedItem.DevToolsOpen = true; MainForm.Instance.faTabStrip1.SelectedItem.ItemBrowser = browser; } } else { MainForm.Instance.faTabStrip1.SelectedItem.splic.Panel2Collapsed = true; _core.DevToolsOpen = MainForm.Instance.faTabStrip1.SelectedItem.DevToolsOpen = false; //_core = null; MainForm.Instance.faTabStrip1.SelectedItem.ItemBrowser = null; // MainForm.Instance.faTabStrip1.SelectedItem.DevToolsName = null; ResizeWindow(browser.GetHost().GetWindowHandle(), MainForm.Instance.faTabStrip1.SelectedItem.Width, MainForm.Instance.faTabStrip1.SelectedItem.Height); GC.Collect(); } })); }
public void Dispose() { var browserhost = _CefBrowser.GetHost(); browserhost.CloseBrowser(true); _CefFrame.Dispose(); _CefBrowser.Dispose(); }
void Parent_SizeChanged(object sender, EventArgs e) { if (bs != null) { var handle = bs.GetHost().GetWindowHandle(); ResizeWindow(handle, Parent.Width, Parent.Height); } }
public InternalHandle find(V8Engine engine, bool isConstructCall, InternalHandle _this, InternalHandle[] args) { try { if (browser != null) { var identifier = args[0].AsInt32; var searchText = args[1].AsString; var forward = args[2].AsBoolean; var matchCase = args[3].AsBoolean; var findNext = args[4].AsBoolean; browser.GetHost().Find(identifier, searchText, forward, matchCase, findNext); } } catch (Exception ex) { Log.Trace(ex.Message, ex.StackTrace, true); } return(Engine.CreateNullValue()); }
public void HandleAfterCreated(CefBrowser browser) { if (_browser == null) { _browser = browser; _browserHost = _browser.GetHost(); } }
protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects , System.IntPtr buffer, int width, int height) { System.Console.WriteLine("Entering OnPaint"); // if (isPainting == true) return; isPainting = true; string savePath = ""; // if (System.Environment.OSVersion.Platform == System.PlatformID.Unix) savePath = "/opt/pdfglue/"; // Save the provided buffer (a bitmap image) as a PNG. using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, width * 4, System.Drawing.Imaging.PixelFormat.Format32bppRgb, buffer)) { System.Console.WriteLine("PixelFormat: " + bitmap.PixelFormat); System.Console.WriteLine("HorizontalResolution: " + bitmap.HorizontalResolution); System.Console.WriteLine("VerticalResolution: " + bitmap.VerticalResolution); bitmap.Save(savePath + "LastOnPaint.bmp"); bitmap.Save(savePath + "LastOnPaint.png", System.Drawing.Imaging.ImageFormat.Png); } // End Using bitmap // CefPdfPrintSettings ps = new CefPdfPrintSettings(); // ps.PageWidth = CmToMicrons(21); // ps.PageHeight = CmToMicrons(29.7); // A0 // ps.PageWidth = CmToMicrons(84.1); // ps.PageHeight = CmToMicrons(118.9); // 5= zuviel // 2,3,4 = OK // ps.PageWidth = CmToMicrons(15*84.1); // ps.PageHeight = CmToMicrons(15*118.9); //ps.Landscape = false; //ps.MarginLeft = 0; //ps.MarginTop = 0; //ps.MarginRight = 0; //ps.MarginBottom = 0; //ps.BackgroundsEnabled = true; //ps.SelectionOnly = false; CefPdfPrintSettings ps = new PageSize(PageSize_t.A4).PrintSettings; browser.GetHost().PrintToPdf(savePath + "AAA.pdf", ps, new PdfPrintCallback()); // browser.GetHost().CloseBrowser(); // browser.Dispose(); // We have the image - stop re-rendering System.Console.WriteLine("Exiting OnPaint"); } // End Sub OnPaint
internal void OnCreated(CefBrowser browser) { if (this.Browsers == null) { this.Browsers = new List <CefBrowser>(); } this.Browsers.Add(browser); browser.GetHost().SendFocusEvent(true); }
protected override void OnAfterCreated(CefBrowser browser) { MainBrowser = browser; MainBrowserHost = browser.GetHost(); //scroll // CefFrame frame = MainBrowser.GetMainFrame(); // frame.ExecuteJavaScript("window.ScrollTo(" + _mainWorker.ClientX + "," + _mainWorker.ClientY + ");", frame.Url, 0); }
internal protected virtual void OnBrowserAfterCreated(CefBrowser browser) { _browser = browser; _browserWindowHandle = _browser.GetHost().GetWindowHandle(); ResizeWindow(_browserWindowHandle, Width, Height); if (BrowserCreated != null) BrowserCreated(this, EventArgs.Empty); }
public void Dispose() { if (Closed) { return; } Browser.GetHost().CloseBrowser(true); Closed = true; }
protected override void OnDownloadUpdated(CefBrowser browser, CefDownloadItem downloadItem, CefDownloadItemCallback callback) { //downloadItem.CurrentSpeed 下载速度 //downloadItem.TotalBytes 总字节数 //downloadItem.ReceivedBytes 已完成字节数 //downloadItem.PercentComplete 完成百分比 //downloadItem.StartTime 下载开始时间 //downloadItem.EndTime 下载完成时间 if (downloadItem.IsComplete) { MessageBox.Show("文件下载成功!"); if (browser.IsPopup && !browser.HasDocument) { browser.GetHost().ParentWindowWillClose(); browser.GetHost().CloseBrowser(); } } }
protected override void OnAfterCreated(CefBrowser browser) { base.OnAfterCreated(browser); var wi = CefWindowInfo.Create(); var host = browser.GetHost(); wi.SetAsPopup(IntPtr.Zero, "DevTools"); host.ShowDevTools(wi, new DevToolsWebClient(), new CefBrowserSettings(), new CefPoint(0, 0)); }
/// <summary> /// Handles the GotFocus event of the Form control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void Form_GotFocus(object sender, EventArgs e) { if (CefBrowser != null) { CefUtility.ExecuteTask(CefThreadId.UI, () => { CefBrowser.GetHost().SetFocus(true); }); } }
protected override void OnAfterCreated(CefBrowser browser) { var hostHandle = browser.GetHost().GetWindowHandle(); var hIcon = _formium.Icon.Handle; User32.SendMessage(hostHandle, (uint)WindowsMessages.WM_SETICON, (IntPtr)ICO_BIG, hIcon); base.OnAfterCreated(browser); }
internal void BrowserAfterCreated(CefBrowser browser) { _browser = browser; _browserWindowHandle = _browser.GetHost().GetWindowHandle(); ResizeWindow(_browserWindowHandle, Width, Height); }
internal protected virtual void OnBrowserAfterCreated(CefBrowser browser) { _browser = browser; _browserWindowHandle = _browser.GetHost().GetWindowHandle(); ResizeWindow(_browserWindowHandle, Width, Height); if (BrowserCreated != null) BrowserCreated(this, EventArgs.Empty); }