Example #1
0
        static public IHTMLElement GetFrame(mshtml.IHTMLDocument2 doc)
        {
            IHTMLElement frame = null;

            mshtml.IHTMLWindow2 window2 = null;
            try
            {
                window2 = doc.parentWindow as mshtml.IHTMLWindow2;
                if (window2 != null)
                {
                    return(((mshtml.HTMLWindow2)window2).frameElement as IHTMLElement);
                }
            }
            catch (UnauthorizedAccessException) {
                //主页面和IFRAME页面处于不同域名的时候会报UnauthorizedAccessException,下面通过IHTMLWindow2->IWebBrowser2
                //比较IWebBrowser2和iframe元素url定位iframe
                SHDocVw.IWebBrowser2          browser          = CrossFrameIE.GetIWebBrowser2(window2);
                mshtml.IHTMLDocument3         parentDoc        = browser.Parent as mshtml.IHTMLDocument3;
                mshtml.IHTMLElementCollection framesCollection = parentDoc.getElementsByTagName("iframe") as mshtml.IHTMLElementCollection;
                foreach (mshtml.IHTMLElement f in framesCollection)
                {
                    SHDocVw.IWebBrowser2 wb2 = (SHDocVw.IWebBrowser2)((mshtml.HTMLFrameElement)f);
                    if (wb2.LocationURL == browser.LocationURL)
                    {
                        frame = f as IHTMLElement;
                        break;
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(frame);
        }
Example #2
0
        private static bool GetEleParentFrames(mshtml.IHTMLDOMNode root, mshtml.IHTMLDOMNode node, List <mshtml.IHTMLDOMNode> frames)
        {
            bool flag = false;

            if (root == node)
            {
                return(true);
            }
            bool flag2 = false;

            switch (root.nodeName.ToLower())
            {
            case "frame":
            case "iframe":
                flag2 = true;
                break;
            }
            IHTMLDOMChildrenCollection childNodes = null;

            if (flag2)
            {
                SHDocVw.IWebBrowser2 browser = root as SHDocVw.IWebBrowser2;
                if (browser != null)
                {
                    mshtml.IHTMLDocument2 document = browser.Document as mshtml.IHTMLDocument2;
                    if (document != null)
                    {
                        mshtml.IHTMLDOMNode parentElement = document.body.parentElement as mshtml.IHTMLDOMNode;
                        childNodes = parentElement.childNodes as IHTMLDOMChildrenCollection;
                    }
                }
            }
            if (childNodes == null)
            {
                childNodes = root.childNodes as IHTMLDOMChildrenCollection;
            }
            if (childNodes == null)
            {
                return(false);
            }
            for (int i = 0; i < childNodes.length; i++)
            {
                mshtml.IHTMLDOMNode node3 = childNodes.item(i) as mshtml.IHTMLDOMNode;
                if (GetEleParentFrames(node3, node, frames))
                {
                    if (flag2)
                    {
                        frames.Add(root);
                    }
                    flag = true;
                }
            }
            return(flag);
        }
Example #3
0
        public virtual void Release()
        {
            canvasHWND = IntPtr.Zero;
            mainHWND   = IntPtr.Zero;

            if (m_pDWebBrowserEvents2 != null)
            {
                Marshal.ReleaseComObject(m_pDWebBrowserEvents2);
                m_pDWebBrowserEvents2 = null;
            }

            if (m_pIWebBrowser2 != null)
            {
                Marshal.ReleaseComObject(m_pIWebBrowser2);
                m_pIWebBrowser2 = null;
            }
        }
Example #4
0
 protected override void DetachInterfaces()
 {
     Iwb2 = null;
     base.DetachInterfaces();
 }
Example #5
0
 protected override void AttachInterfaces(object nativeActiveXObject)
 {
     Iwb2 = (SHDocVw.IWebBrowser2)nativeActiveXObject;
     Iwb2.Silent = true;
     base.AttachInterfaces(nativeActiveXObject);
 }
Example #6
0
        public SetSiteResults SetSiteWithStatus(object pUnkSite)
        {
            if (m_pIWebBrowser2 != null)
            {
                Release();
            }

            if (pUnkSite == null)
            {
                return(SetSiteResults.NoSite);
            }

            try
            {
                MySpace.MSFast.SysImpl.Win32.ComIterop.IServiceProvider pSp = pUnkSite as MySpace.MSFast.SysImpl.Win32.ComIterop.IServiceProvider;

                if (pSp == null)
                {
                    Release();
                    return(SetSiteResults.SiteIsNotServiceProvider);
                }

                IntPtr ipWb2 = IntPtr.Zero;

                pSp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out ipWb2);

                if (ipWb2 == IntPtr.Zero)
                {
                    Marshal.Release(ipWb2);
                    Release();
                    return(SetSiteResults.SiteIsNotAWebBrowser);
                }

                m_pIWebBrowser2 = Marshal.GetObjectForIUnknown(ipWb2) as IWebBrowser2;
                Marshal.Release(ipWb2);

                if (m_pIWebBrowser2 == null)
                {
                    Release();
                    return(SetSiteResults.SiteIsNotAWebBrowser);
                }

                string sHostName = m_pIWebBrowser2.FullName;

                if (sHostName == null)
                {
                    Release();
                    return(SetSiteResults.SiteHasNoName);
                }

                if (!(sHostName.ToUpper().EndsWith("IEXPLORE.EXE")))
                {
                    Release();
                    return(SetSiteResults.SiteIsNotIExplorer);
                }

                m_pDWebBrowserEvents2 = m_pIWebBrowser2 as SHDocVw.DWebBrowserEvents2_Event;

                this.mainHWND = (IntPtr)m_pIWebBrowser2.HWND;

                if (m_pDWebBrowserEvents2 == null)
                {
                    Release();
                    return(SetSiteResults.CantRegisterEventHandlers);
                }

                m_pDWebBrowserEvents2.BeforeNavigate2   += new SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate);
                m_pDWebBrowserEvents2.DocumentComplete  += new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
                m_pDWebBrowserEvents2.OnQuit            += new SHDocVw.DWebBrowserEvents2_OnQuitEventHandler(this.OnQuit);
                m_pDWebBrowserEvents2.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(this.NavigateComplete2);
            }
            catch
            {
                Release();
                return(SetSiteResults.UnknownException);
            }

            CheckPageReady();

            return(SetSiteResults.Success);
        }
Example #7
0
 public SecondaryOnloadEventArgs(IWebBrowser2 _pWb)
 {
     this.m_pWb  = _pWb;
     this.Cancel = false;
 }