protected override void OnHandleCreated(EventArgs e) { if (!this.DesignMode) { Xpcom.Initialize(); #if !NO_CUSTOM_PROMPT_SERVICE PromptServiceFactory.Register(); #endif WindowCreator.Register(); //CertificateDialogsFactory.Register(); //ToolTipTextProviderFactory.Register(); WebBrowser = Xpcom.CreateInstance<nsIWebBrowser>("@mozilla.org/embedding/browser/nsWebBrowser;1"); WebBrowserFocus = (nsIWebBrowserFocus)WebBrowser; BaseWindow = (nsIBaseWindow)WebBrowser; WebNav = (nsIWebNavigation)WebBrowser; WebBrowser.SetContainerWindow(this); //int type = ((this.ChromeFlags & (int)GeckoWindowFlags.OpenAsChrome) != 0) ? nsIDocShellTreeItemConstants.typeChromeWrapper : nsIDocShellTreeItemConstants.typeContentWrapper; //nsIDocShellTreeItem shellTreeItem = Xpcom.QueryInterface<nsIDocShellTreeItem>(WebBrowser); //if (shellTreeItem != null) // shellTreeItem.SetItemType(type); //else //{ // nsIDocShellTreeItem19 treeItem19 = Xpcom.QueryInterface<nsIDocShellTreeItem19>(WebBrowser); // if (treeItem19 != null) // treeItem19.SetItemType(type); //} BaseWindow.InitWindow(this.Handle, IntPtr.Zero, 0, 0, this.Width, this.Height); BaseWindow.Create(); Guid nsIWebProgressListenerGUID = typeof(nsIWebProgressListener).GUID; WebBrowser.AddWebBrowserListener(this, ref nsIWebProgressListenerGUID); nsIDOMEventTarget target = Xpcom.QueryInterface<nsIDOMWindow2>(WebBrowser.GetContentDOMWindow()).GetWindowRoot(); target.AddEventListener(new nsAString("submit"), this, true); target.AddEventListener(new nsAString("keydown"), this, true); target.AddEventListener(new nsAString("keyup"), this, true); target.AddEventListener(new nsAString("mousemove"), this, true); target.AddEventListener(new nsAString("mouseover"), this, true); target.AddEventListener(new nsAString("mouseout"), this, true); target.AddEventListener(new nsAString("mousedown"), this, true); target.AddEventListener(new nsAString("mouseup"), this, true); target.AddEventListener(new nsAString("click"), this, true); // history WebNav.GetSessionHistory().AddSHistoryListener(this); BaseWindow.SetVisibility(true); if ((this.ChromeFlags & (int)GeckoWindowFlags.OpenAsChrome) == 0) { // navigating to about:blank allows drag & drop to work properly before a page has been loaded into the browser Navigate("about:blank"); } // this fix prevents the browser from crashing if the first page loaded is invalid (missing file, invalid URL, etc) Document.Cookie = ""; } base.OnHandleCreated(e); }
protected override void Dispose(bool disposing) { if (!Environment.HasShutdownStarted && !AppDomain.CurrentDomain.IsFinalizingForUnload()) { // make sure the object is still alove before we call a method on it if (Xpcom.QueryInterface<nsIWebNavigation>(WebNav) != null) { WebNav.Stop(nsIWebNavigationConstants.STOP_ALL); } WebNav = null; if (Xpcom.QueryInterface<nsIBaseWindow>(BaseWindow) != null) { BaseWindow.Destroy(); } BaseWindow = null; } base.Dispose(disposing); }
protected override void OnHandleCreated(EventArgs e) { #if GTK if (Xpcom.IsMono) { base.OnHandleCreated(e); m_wrapper.Init(); } #endif if (!this.DesignMode) { Xpcom.Initialize(); #if !NO_CUSTOM_PROMPT_SERVICE PromptServiceFactory.Register(); #endif WindowCreator.Register(); LauncherDialogFactory.Register(); //CertificateDialogsFactory.Register(); //ToolTipTextProviderFactory.Register(); WebBrowser = Xpcom.CreateInstance<nsIWebBrowser>("@mozilla.org/embedding/browser/nsWebBrowser;1"); WebBrowserFocus = (nsIWebBrowserFocus)WebBrowser; BaseWindow = (nsIBaseWindow)WebBrowser; WebNav = (nsIWebNavigation)WebBrowser; WebBrowser.SetContainerWindowAttribute(this); //int type = ((this.ChromeFlags & (int)GeckoWindowFlags.OpenAsChrome) != 0) ? nsIDocShellTreeItemConstants.typeChromeWrapper : nsIDocShellTreeItemConstants.typeContentWrapper; //nsIDocShellTreeItem shellTreeItem = Xpcom.QueryInterface<nsIDocShellTreeItem>(WebBrowser); //if (shellTreeItem != null) // shellTreeItem.SetItemType(type); //else //{ // nsIDocShellTreeItem19 treeItem19 = Xpcom.QueryInterface<nsIDocShellTreeItem19>(WebBrowser); // if (treeItem19 != null) // treeItem19.SetItemType(type); //} #if GTK if (Xpcom.IsMono) BaseWindow.InitWindow(m_wrapper.BrowserWindow.Handle, IntPtr.Zero, 0, 0, this.Width, this.Height); else #endif BaseWindow.InitWindow(this.Handle, IntPtr.Zero, 0, 0, this.Width, this.Height); BaseWindow.Create(); Guid nsIWebProgressListenerGUID = typeof(nsIWebProgressListener).GUID; WebBrowser.AddWebBrowserListener(this, ref nsIWebProgressListenerGUID); nsIDOMEventTarget target = Xpcom.QueryInterface<nsIDOMWindow>(WebBrowser.GetContentDOMWindowAttribute()).GetWindowRootAttribute(); target.AddEventListener(new nsAString("submit"), this, true, true, 2); target.AddEventListener(new nsAString("keydown"), this, true, true, 2); target.AddEventListener(new nsAString("keyup"), this, true, true, 2); target.AddEventListener(new nsAString("keypress"), this, true, true, 2); target.AddEventListener(new nsAString("mousemove"), this, true, true, 2); target.AddEventListener(new nsAString("mouseover"), this, true, true, 2); target.AddEventListener(new nsAString("mouseout"), this, true, true, 2); target.AddEventListener(new nsAString("mousedown"), this, true, true, 2); target.AddEventListener(new nsAString("mouseup"), this, true, true, 2); target.AddEventListener(new nsAString("click"), this, true, true, 2); target.AddEventListener(new nsAString("dblclick"), this, true, true, 2); target.AddEventListener(new nsAString("compositionstart"), this, true, true, 2); target.AddEventListener(new nsAString("compositionend"), this, true, true, 2); target.AddEventListener(new nsAString("contextmenu"), this, true, true, 2); target.AddEventListener(new nsAString("DOMMouseScroll"), this, true, true, 2); target.AddEventListener(new nsAString("focus"), this, true, true, 2); // Load event added here rather than DOMDocument as DOMDocument recreated when navigating // ths losing attached listener. target.AddEventListener(new nsAString("load"), this, true, true, 2); target.AddEventListener(new nsAString("change"), this, true, true, 2); // history if (WebNav.GetSessionHistoryAttribute() != null) WebNav.GetSessionHistoryAttribute().AddSHistoryListener(this); BaseWindow.SetVisibilityAttribute(true); // this fix prevents the browser from crashing if the first page loaded is invalid (missing file, invalid URL, etc) Document.Cookie = ""; } base.OnHandleCreated(e); }
// protected override void Dispose(bool disposing) // { // //if (_target != null) // //{ // // //Remove Event Listener // // _target.RemoveEventListener(new nsAString("submit"), this, true); // // _target.RemoveEventListener(new nsAString("keydown"), this, true); // // _target.RemoveEventListener(new nsAString("keyup"), this, true); // // _target.RemoveEventListener(new nsAString("keypress"), this, true); // // _target.RemoveEventListener(new nsAString("mousemove"), this, true); // // _target.RemoveEventListener(new nsAString("mouseover"), this, true); // // _target.RemoveEventListener(new nsAString("mouseout"), this, true); // // _target.RemoveEventListener(new nsAString("mousedown"), this, true); // // _target.RemoveEventListener(new nsAString("mouseup"), this, true); // // _target.RemoveEventListener(new nsAString("click"), this, true); // // _target.RemoveEventListener(new nsAString("dblclick"), this, true); // // _target.RemoveEventListener(new nsAString("compositionstart"), this, true); // // _target.RemoveEventListener(new nsAString("compositionend"), this, true); // // _target.RemoveEventListener(new nsAString("contextmenu"), this, true); // // _target.RemoveEventListener(new nsAString("DOMMouseScroll"), this, true); // // _target.RemoveEventListener(new nsAString("focus"), this, true); // // _target.RemoveEventListener(new nsAString("blur"), this, true); // // _target.RemoveEventListener(new nsAString("load"), this, true); // // _target.RemoveEventListener(new nsAString("change"), this, true); // // _target.RemoveEventListener(new nsAString("hashchange"), this, false); // //} // //// If GC thread is calling Dispose // if (!disposing) // { // Debug.WriteLine("Warning: GeckoWebBrowser control not disposed."); // if (!IsHandleCreated) // return; // Invoke(new Action(Cleanup), new object[] { }); // base.Dispose(disposing); // return; // } // RemoveJsContextCallBack(); // //var count = Gecko.Interop.ComDebug.GetRefCount(WebBrowser); // if (NavigateFinishedNotifier != null) // NavigateFinishedNotifier.Dispose(); // if (!Environment.HasShutdownStarted && !AppDomain.CurrentDomain.IsFinalizingForUnload()) // { // // make sure the object is still alive before we call a method on it // if (WebNav != null) // { // var webNav = Xpcom.QueryInterface<nsIWebNavigation>(WebNav); // if (webNav != null) // { // webNav.Stop(nsIWebNavigationConstants.STOP_ALL); // Marshal.ReleaseComObject(webNav); // } // WebNav = null; // } // Cleanup(); // } //#if GTK // if (m_wrapper != null) // m_wrapper.Dispose(); //#endif // //count = Gecko.Interop.ComDebug.GetRefCount(WebBrowser); // base.Dispose(disposing); // } // This method should only run on the Main Thread. private void Cleanup() { // If control is not shown simply return if (BaseWindow == null) return; var baseWindow = Xpcom.QueryInterface<nsIBaseWindow>(BaseWindow); if (baseWindow != null) { baseWindow.Destroy(); Marshal.ReleaseComObject(baseWindow); } BaseWindow = null; }
protected override void Dispose(bool disposing) { // make sure the object is still alove before we call a method on it if (Xpcom.QueryInterface<nsIWebNavigation>(WebNav) != null) { WebNav.Stop(nsIWebNavigationConstants.STOP_ALL); } WebNav = null; if (Xpcom.QueryInterface<nsIBaseWindow>(BaseWindow) != null) { BaseWindow.Destroy(); } BaseWindow = null; base.Dispose(disposing); }