public static void DisposeAllChildWebBrowserControls(IWindowForm ownerForm) { //dispose all web browser (child) windows inside this window form List <MyCefBrowser> foundList; if (registerTopWindowForms.TryGetValue(ownerForm, out foundList)) { //remove webbrowser controls for (int i = foundList.Count - 1; i >= 0; --i) { MyCefBrowser mycefBw = foundList[i]; IWindowControl wb = mycefBw.ParentControl; mycefBw.NotifyCloseBw(); //--------------------------------------- var parent = wb.GetParent(); parent.RemoveChild(wb); //this Dispose() will terminate cef_life_time_handle *** //after native side dispose the wb control //it will raise event BrowserDisposed wb.Dispose(); //--------------------------------------- } registerTopWindowForms.Remove(ownerForm); } }
void InitWebBrowserControl() { //--------- //create timer for notify when browser is ready var bwReadyTimer = new Timer(); bwReadyTimer.Interval = 50;//ms bwReadyTimer.Tick += (s, e1) => { if (this.IsHandleCreated && this.Agent.IsBrowserCreated) { bwReadyTimer.Enabled = false;//stop timer if (cefBrowser != null) { cefBrowser.SetSize(this.Width, this.Height); } if (BrowserReady != null) { BrowserReady(this, EventArgs.Empty); } bwReadyTimer.Dispose(); bwReadyTimer = null; } }; bwReadyTimer.Enabled = true; //--------- //create cef browser when handle is created this.cefBrowser = new MyCefBrowser(thisWindowControl, 0, 0, 800, 500, "about:blank", false); }
void TmClosingCheck_Tick(object sender, EventArgs e) { if (MyCefBrowser.IsReadyToClose(this)) { tmClosingCheck.Enabled = false; form.Close(); //we not dispose here } }
static void cefBrowserControl_Disposed(object sender, EventArgs e) { //web browser control is dispose MyCefBrowser wb = (MyCefBrowser)sender; List <MyCefBrowser> wblist; IWindowForm winHandle = wb.ParentForm; if (registerTopWindowForms.TryGetValue(winHandle, out wblist)) { lock (sync_remove) { wblist.Remove(wb); } } }
static void RegisterCefWbControl(MyCefBrowser cefWb) { // get top level of this cef browser control var ownerForm = (IWindowForm)cefWb.ParentControl.GetTopLevelControl(); List <MyCefBrowser> foundList; if (!registerTopWindowForms.TryGetValue(ownerForm, out foundList)) { foundList = new List <MyCefBrowser>(); registerTopWindowForms.Add(ownerForm, foundList); } if (!foundList.Contains(cefWb)) { foundList.Add(cefWb); cefWb.BrowserDisposed += new EventHandler(cefBrowserControl_Disposed); } }
private void Form_FormClosing(object sender, FormClosingEventArgs e) { bool closing = false; lock (closingLock) { closing = startClosing; startClosing = true; } if (!closing) { //this is 1st time we start close startClosing = closing = true; e.Cancel = true; formHandle = form.Handle; MyCefBrowser.DisposeAllChildWebBrowserControls(this); tmClosingCheck.Enabled = true; } }
static void cefBrowserControl_Disposed(object sender, EventArgs e) { //web browser control is disposed //TODO: review here MyCefBrowser wb = sender as MyCefBrowser; if (wb != null) { IWindowForm winHandle = wb.ParentForm; List <MyCefBrowser> wblist; if (registerTopWindowForms.TryGetValue(winHandle, out wblist)) { lock (sync_remove) { wblist.Remove(wb); } } } else { throw new NotSupportedException(); } }
public MyCefBwHandler(MyCefBrowser owner) { this._ownerBrowser = owner; }