Esempio n. 1
0
        /// <summary>
        /// Handle the DocumentComplete event.
        /// </summary>
        /// <param name="pDisp">
        /// The pDisp is an an object implemented the interface InternetExplorer.
        /// By default, this object is the same as the ieInstance, but if the page 
        /// contains many frames, each frame has its own document.
        /// </param>
        void IeInstance_DocumentComplete(object pDisp, ref object URL)
        {
            if (ieInstance == null)
            {
                return;
            }

            // get the url
            string url = URL as string;
            if (string.IsNullOrEmpty(url) || url.Equals(@"about:Tabs", StringComparison.OrdinalIgnoreCase) || url.Equals("about:blank", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // http://borderstylo.com/posts/115-browser-wars-2-dot-0-the-plug-in
            SHDocVw.WebBrowser browser = (SHDocVw.WebBrowser)ieInstance;
            if (browser.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
            {
                return;
            }

            // Set the handler of the document in InternetExplorer.
            NativeMethods.ICustomDoc customDoc = (NativeMethods.ICustomDoc)ieInstance.Document;
            customDoc.SetUIHandler(openImageDocHostUIHandler);

            // sets the document
            this.document = (HTMLDocument) ieInstance.Document;

            try
            {
                if (this.document.url.Contains(@"thousandpass") || this.document.url.Contains(@"1000pass.com"))
                {
                    // Mark the add_on as installed!
                    IHTMLElement div1000pass_add_on = this.document.getElementById("1000pass_add_on");
                    div1000pass_add_on.className = @"installed";
                    IHTMLElement div1000pass_add_on_version = this.document.getElementById("1000pass_add_on_version");
                    div1000pass_add_on_version.innerText = VERSION;

                    // Try to save the token
                    string token = div1000pass_add_on.getAttribute("token").ToString();
                    if (!String.IsNullOrEmpty(token))
                    {
                        Utils.WriteToFile(Utils.TokenFileName, token);
                    }

                    foreach (IHTMLElement htmlElement in document.getElementsByTagName("IMG"))
                    {
                        if (htmlElement.className == "remote_site_logo")
                        {
                            IHTMLStyle htmlStyle = (IHTMLStyle)htmlElement.style;
                            htmlStyle.cursor = "pointer";

                            DHTMLEventHandler Handler = new DHTMLEventHandler((IHTMLDocument2)ieInstance.Document);
                            Handler.Handler += new DHTMLEvent(Logo_OnClick);
                            htmlElement.onclick = Handler;

                            htmlElement.setAttribute("alreadyopened", "false", 0);
                        }
                    }
                }
                else
                {
                    // Must run on a thread to guaranty the page has finished loading (js loading)
                    // http://stackoverflow.com/questions/3514945/running-a-javascript-function-in-an-instance-of-internetexplorer
                    System.Threading.ThreadPool.QueueUserWorkItem((o) =>
                    {
                        System.Threading.Thread.Sleep(500);
                        try
                        {
                            Thread aThread = new Thread(bind);
                            aThread.SetApartmentState(ApartmentState.STA);
                            aThread.Start();
                        }
                        catch (Exception ee)
                        {
                            Utils.l(ee);
                        }
                    }, browser);
                }
            }
            catch (Exception e)
            {
                Utils.l(e);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handle the DocumentComplete event.
        /// </summary>
        /// <param name="pDisp">
        /// The pDisp is an an object implemented the interface InternetExplorer.
        /// By default, this object is the same as the ieInstance, but if the page
        /// contains many frames, each frame has its own document.
        /// </param>
        void IeInstance_DocumentComplete(object pDisp, ref object URL)
        {
            if (ieInstance == null)
            {
                return;
            }

            // get the url
            string url = URL as string;

            if (string.IsNullOrEmpty(url) || url.Equals(@"about:Tabs", StringComparison.OrdinalIgnoreCase) || url.Equals("about:blank", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }


            // http://borderstylo.com/posts/115-browser-wars-2-dot-0-the-plug-in
            SHDocVw.WebBrowser browser = (SHDocVw.WebBrowser)ieInstance;
            if (browser.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
            {
                return;
            }


            // Set the handler of the document in InternetExplorer.
            NativeMethods.ICustomDoc customDoc = (NativeMethods.ICustomDoc)ieInstance.Document;
            customDoc.SetUIHandler(openImageDocHostUIHandler);


            // sets the document
            this.document = (HTMLDocument)ieInstance.Document;


            try
            {
                if (this.document.url.Contains(@"thousandpass") || this.document.url.Contains(@"1000pass.com"))
                {
                    // Mark the add_on as installed!
                    IHTMLElement div1000pass_add_on = this.document.getElementById("1000pass_add_on");
                    div1000pass_add_on.className = @"installed";
                    IHTMLElement div1000pass_add_on_version = this.document.getElementById("1000pass_add_on_version");
                    div1000pass_add_on_version.innerText = VERSION;


                    // Try to save the token
                    string token = div1000pass_add_on.getAttribute("token").ToString();
                    if (!String.IsNullOrEmpty(token))
                    {
                        Utils.WriteToFile(Utils.TokenFileName, token);
                    }


                    foreach (IHTMLElement htmlElement in document.getElementsByTagName("IMG"))
                    {
                        if (htmlElement.className == "remote_site_logo")
                        {
                            IHTMLStyle htmlStyle = (IHTMLStyle)htmlElement.style;
                            htmlStyle.cursor = "pointer";


                            DHTMLEventHandler Handler = new DHTMLEventHandler((IHTMLDocument2)ieInstance.Document);
                            Handler.Handler    += new DHTMLEvent(Logo_OnClick);
                            htmlElement.onclick = Handler;

                            htmlElement.setAttribute("alreadyopened", "false", 0);
                        }
                    }
                }
                else
                {
                    // Must run on a thread to guaranty the page has finished loading (js loading)
                    // http://stackoverflow.com/questions/3514945/running-a-javascript-function-in-an-instance-of-internetexplorer
                    System.Threading.ThreadPool.QueueUserWorkItem((o) =>
                    {
                        System.Threading.Thread.Sleep(500);
                        try
                        {
                            Thread aThread = new Thread(bind);
                            aThread.SetApartmentState(ApartmentState.STA);
                            aThread.Start();
                        }
                        catch (Exception ee)
                        {
                            Utils.l(ee);
                        }
                    }, browser);
                }
            }
            catch (Exception e)
            {
                Utils.l(e);
            }
        }