예제 #1
0
        public static IntPtr WebBrowserGetInterface <T>(T geckoWebBrowser, nsIWebBrowser instance, ref Guid uuid)
            where T : IGeckoWebBrowser
        {
            object obj = geckoWebBrowser;

            // note: when a new window is created, gecko calls GetInterface on the webbrowser to get a DOMWindow in order
            // to set the starting url
            if (instance != null)
            {
                if (uuid == typeof(nsIDOMWindow).GUID)
                {
                    obj = instance.GetContentDOMWindowAttribute();
                }
                else if (uuid == typeof(nsIDOMDocument).GUID)
                {
                    obj =
                        new WebIDL.Window(instance.GetContentDOMWindowAttribute(),
                                          (nsISupports)instance.GetContentDOMWindowAttribute()).Document;
                }
            }

            IntPtr ppv, pUnk = Marshal.GetIUnknownForObject(obj);

            Marshal.QueryInterface(pUnk, ref uuid, out ppv);

            Marshal.Release(pUnk);

            return(ppv);
        }
예제 #2
0
        protected override void OnHandleDestroyed(EventArgs e)
        {
            if (BaseWindow != null)
            {
                this.Stop();

                WindowMediator.UnregisterWindow(this);

                if (_weakRef != null)
                {
                    _weakRef.Dispose();
                    _weakRef = null;
                }

                nsIDocShell docShell = Xpcom.QueryInterface <nsIDocShell>(BaseWindow);
                if (docShell != null && !docShell.IsBeingDestroyed())
                {
                    try
                    {
                        var window = Xpcom.QueryInterface <nsIDOMWindow>(docShell);
                        if (window != null)
                        {
                            try
                            {
                                var w = new WebIDL.Window(window, (nsISupports)window);
                                if (!w.Closed)
                                {
                                    w.Close();
                                }
                            }
                            finally
                            {
                                Xpcom.FreeComObject(ref window);
                            }
                        }
                    }
                    finally
                    {
                        Xpcom.FreeComObject(ref docShell);
                    }
                }

                if (EventTarget != null)
                {
                    RemoveFrameEvents();
                    DetachEvents();
                    EventTarget.Dispose();
                    EventTarget = null;
                }

                BaseWindow.Destroy();

                Xpcom.FreeComObject(ref CommandParams);

                var webBrowserFocus = this.WebBrowserFocus;
                this.WebBrowserFocus = null;
                Xpcom.FreeComObject(ref webBrowserFocus);
                Xpcom.FreeComObject(ref WebNav);
                Xpcom.FreeComObject(ref BaseWindow);
                Xpcom.FreeComObject(ref WebBrowser);

                if (this.menu != null)
                {
                    this.menu.MenuItems.Clear();
                    this.menu.Dispose();
                    this.menu = null;
                }
#if GTK
                if (m_wrapper != null)
                {
                    m_wrapper.Dispose();
                    m_wrapper = null;
                }
#endif
            }

            base.OnHandleDestroyed(e);
        }