/// <summary>
 /// Writes a url file representing the current navigation state of a browser
 /// </summary>
 /// <param name="browser">The IWebBrowser2 for which to write the url file</param>
 /// <param name="filePath">The path to the url file</param>
 public void WriteForBrowser( IWebBrowser2 browser, string filePath )
 {
     IObjectWithSite site = internetShortcut as IObjectWithSite ;
     site.SetSite( browser ) ;
     IPersistFile file = internetShortcut as IPersistFile ;
     file.Save( filePath, false ) ;
 }
Пример #2
1
 public void SetSite(object site) {
     explorer = site as IWebBrowser2;
     if(explorer == null || Process.GetCurrentProcess().ProcessName == "iexplore") {
         Marshal.ThrowExceptionForHR(E_FAIL);
     }
     else {
         ActivateIt();
     }
 }
Пример #3
0
        public object InvokeScript(IWebBrowser2 wb, string ScriptName, object[] Data)
        {
            object oRet = null;

            if (wb == null)
            {
                return(oRet);
            }

            IHTMLDocument doc = wb.Document as IHTMLDocument;

            if (doc == null)
            {
                return(oRet);
            }
            object oScript = doc.Script;

            if (oScript == null)
            {
                return(oRet);
            }
            //Invoke script
            if (Data == null)
            {
                Data = new object[] { }
            }
            ;
            oRet = oScript.GetType().InvokeMember(ScriptName,
                                                  System.Reflection.BindingFlags.InvokeMethod, null, oScript, Data);
            return(oRet);
        }
Пример #4
0
 protected override void AttachInterfaces()
 {
     try {
         control = (IWebBrowser2)base.GetOcx();
     }
     catch { }
 }
Пример #5
0
#pragma warning restore 618

        #region Implementation of IObjectWithSite
        int IObjectWithSite.SetSite(object site)
        {
#if DEBUG
            // launch debugger when in Debug build
            Debugger.Launch();
#endif

            if (site != null)
            {
                browser = (IWebBrowser2)site;

                // can't simply subscribe to OnBeforeNavigate2 from .NET - https://support.microsoft.com/en-us/kb/325079?wa=wsignin1.0
#pragma warning disable 618
                UCOMIConnectionPointContainer icpc = (UCOMIConnectionPointContainer)site;
#pragma warning restore 618
                Guid g = typeof(DWebBrowserEvents).GUID;
                icpc.FindConnectionPoint(ref g, out icp);
                icp.Advise(this, out cookie);

                ((DWebBrowserEvents2_Event)browser).DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
                ((DWebBrowserEvents2_Event)browser).DownloadBegin    += new DWebBrowserEvents2_DownloadBeginEventHandler(this.OnDownloadBegin);
                ((DWebBrowserEvents2_Event)browser).DownloadComplete += new DWebBrowserEvents2_DownloadCompleteEventHandler(this.OnDownloadComplete);
            }
            else
            {
                icp.Unadvise(cookie);

                ((DWebBrowserEvents2_Event)browser).DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
                ((DWebBrowserEvents2_Event)browser).DownloadComplete -= new DWebBrowserEvents2_DownloadCompleteEventHandler(this.OnDownloadComplete);

                browser = null;
            }
            return(0);
        }
Пример #6
0
        int IObjectWithSite.SetSite(object site)
        {
            this.site = site;

            if (site != null)
            {
                LoadOptions();

                var    serviceProv        = (IServiceProvider)this.site;
                var    guidIWebBrowserApp = Marshal.GenerateGuidForType(typeof(IWebBrowserApp)); // new Guid("0002DF05-0000-0000-C000-000000000046");
                var    guidIWebBrowser2   = Marshal.GenerateGuidForType(typeof(IWebBrowser2));   // new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E");
                IntPtr intPtr;
                serviceProv.QueryService(ref guidIWebBrowserApp, ref guidIWebBrowser2, out intPtr);

                browser = (IWebBrowser2)Marshal.GetObjectForIUnknown(intPtr);

                ((DWebBrowserEvents2_Event)browser).DocumentComplete +=
                    new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
            }
            else
            {
                ((DWebBrowserEvents2_Event)browser).DocumentComplete -=
                    new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
                browser = null;
            }
            return(0);
        }
        private void StartBrowser()
        {
            this._WebBrowserExtendedState = Microsoft.Uii.Csr.Browser.Web.WebBrowserExtendedState.BrowserAcquiring;
            this.web = null;
            this.web = (IWebBrowser2)Activator.CreateInstance(Type.GetTypeFromCLSID(NativeMethods.IID_InternetExplorer));
            object flags   = 0;
            object missing = Type.Missing;

            this.web.Navigate("about:blank", ref flags, ref missing, ref missing, ref missing);
            if (web.HWND == 0)
            {
                throw new Exception("Unable to attach to browser.   Protected Mode may be disable");
            }
            this._Process = Process.GetProcessById(NativeMethods.GetProcessIdFromWindow((IntPtr)this.web.HWND));
            if (_Process == null)
            {
                throw new Exception("Unable to attach to browser.   Protected Mode may be disable");
            }
            Win32API.ShowWindow((IntPtr)web.HWND, Win32API.ShowWindowValues.SW_MAXIMIZE);
            this._Process.Exited += _Process_Exited;
            this._Process.EnableRaisingEvents = true;
            this._WebBrowserExtendedState     = Microsoft.Uii.Csr.Browser.Web.WebBrowserExtendedState.BrowserAcquired;
            this.web.AddressBar = AddressBar;
            this.web.MenuBar    = MenuBar;
            this.web.StatusBar  = StatusBar;
            this.web.ToolBar    = ToolBar;
            if (userCanClose == false)
            {
                RemoveBrowserClose((IntPtr)web.HWND);
            }
        }
Пример #8
0
Файл: IE.cs Проект: minskowl/MY
        private void CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, bool createInNewProcess)
        {
            CheckThreadApartmentStateIsSTA();

            UtilityClass.MoveMousePoinerToTopLeft(Settings.AutoMoveMousePointerToTopLeft);

            if (createInNewProcess)
            {
                Logger.LogAction("Creating IE instance in a new process");

                ie = CreateIEPartiallyInitializedInNewProcess().ie;
                FinishInitialization(uri);
            }
            else
            {
                Logger.LogAction("Creating IE instance");

                ie = new InternetExplorerClass();
                FinishInitialization(uri);
            }

            if (logonDialogHandler != null)
            {
                // remove other logon dialog handlers since only one handler
                // can effectively handle the logon dialog.
                DialogWatcher.RemoveAll(new LogonDialogHandler("a", "b"));

                // Add the (new) logonHandler
                DialogWatcher.Add(logonDialogHandler);
            }

            WaitForComplete();
        }
Пример #9
0
        private static IWebBrowser2 FindIWebBrowser2(IntPtr ieServerWindowHandle)
        {
            IWebBrowser2 browser = null;

            if (!ieServerWindowHandle.Equals(IntPtr.Zero))
            {
                UIntPtr ptr;
                uint    msg = NativeMethods.RegisterWindowMessage("WM_HTML_GETOBJECT");
                if (!(NativeMethods.SendMessageTimeout(ieServerWindowHandle, msg, UIntPtr.Zero, IntPtr.Zero, NativeMethods.SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 0x3e8, out ptr) != IntPtr.Zero))
                {
                    return(browser);
                }
                Microsoft.Uii.Csr.Browser.Web.IServiceProvider provider = null;
                try
                {
                    provider = (Microsoft.Uii.Csr.Browser.Web.IServiceProvider)NativeMethods.ObjectFromLresult(ptr, NativeMethods.IID_IHTMLDocument, IntPtr.Zero);
                }
                catch (InvalidCastException)
                {
                }
                if (provider != null)
                {
                    object obj2;
                    provider.QueryService(ref NativeMethods.IID_IWebBrowserApp, ref NativeMethods.IID_IWebBrowser2, out obj2);
                    browser = obj2 as IWebBrowser2;
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(provider);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(obj2);
                }
            }
            return(browser);
        }
Пример #10
0
 /// <summary>
 /// Constructor for BrowserData
 /// </summary>
 /// <param name="iDataObject">The IDataObject from which to create the BrowserData</param>
 private BrowserData(IDataObject iDataObject, BrowserClipboardData browserClip)
 {
     m_dataObject   = iDataObject;
     m_webBrowser   = browserClip.Browser;
     m_isFormPost   = browserClip.IsFormPost;
     m_htmlDocument = browserClip.htmlDocument;
 }
Пример #11
0
        protected virtual void WaitForFramesToComplete(IHTMLDocument2 maindocument)
        {
            HTMLDocument mainHtmlDocument = (HTMLDocument)maindocument;

            int framesCount = WatiN.Core.Frame.GetFrameCountFromHTMLDocument(mainHtmlDocument);

            for (int i = 0; i != framesCount; ++i)
            {
                IWebBrowser2 frame = WatiN.Core.Frame.GetFrameFromHTMLDocument(i, mainHtmlDocument);

                if (frame != null)
                {
                    IHTMLDocument2 document;

                    try
                    {
                        WaitWhileIEBusy(frame);
                        waitWhileIEStateNotComplete(frame);
                        WaitWhileFrameDocumentNotAvailable(frame);

                        document = (IHTMLDocument2)frame.Document;
                    }
                    finally
                    {
                        // free frame
                        Marshal.ReleaseComObject(frame);
                    }

                    WaitWhileDocumentStateNotComplete(document);
                    WaitForFramesToComplete(document);
                }
            }
        }
Пример #12
0
        private void HookIntroPage()
        {
            try
            {
                IWebBrowser2   nativeBrowser = (SHDocVw.IWebBrowser2)webBrowser.ActiveXInstance;
                IHTMLDocument3 introDoc      = nativeBrowser.Document as IHTMLDocument3;

                if (introDoc != null)
                {
                    introDoc.attachEvent("onclick", new HtmlHandler(this.OnIntroClick, ((IHTMLDocument2)introDoc).parentWindow));

                    // Initialize checkbox with value in registry.
                    IHTMLInputElement checkBox          = (IHTMLInputElement)introDoc.getElementById(CatStudioConstants.INTRO_DONT_ASK_AGAIN_ATTR);
                    RegistryKey       twbstStudioRegKey = Registry.CurrentUser.OpenSubKey("Software\\Codecentrix\\OpenTwebst\\Studio", false);

                    if (twbstStudioRegKey != null)
                    {
                        int dontShowIntro = (int)twbstStudioRegKey.GetValue("dontshowintro", 0);

                        checkBox.@checked = (dontShowIntro != 0);
                        twbstStudioRegKey.Close();
                    }
                }
            }
            catch
            {
                // Do nothing. Maybe not this critical.
            }
        }
Пример #13
0
        int IObjectWithSite.SetSite(object site)
        {
            this.site = site;

            if (site != null)
            {
                var    serviceProv        = (IServiceProvider)this.site;
                var    guidIWebBrowserApp = Marshal.GenerateGuidForType(typeof(IWebBrowserApp));
                var    guidIWebBrowser2   = Marshal.GenerateGuidForType(typeof(IWebBrowser2));
                IntPtr intPtr;
                serviceProv.QueryService(ref guidIWebBrowserApp, ref guidIWebBrowser2, out intPtr);

                browser = (IWebBrowser2)Marshal.GetObjectForIUnknown(intPtr);

                ((DWebBrowserEvents2_Event)browser).DocumentComplete +=
                    new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
            }
            else
            {
                ((DWebBrowserEvents2_Event)browser).DocumentComplete -=
                    new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
                browser = null;
            }
            return(0);
        }
Пример #14
0
Файл: IE.cs Проект: minskowl/MY
        private void DisposeAndCloseIE(bool closeIE)
        {
            if (isDisposed)
            {
                return;
            }

            if (closeIE && IsInternetExplorerStillAvailable())
            {
                // Close all open HTMLDialogs
                HtmlDialogs.CloseAll();
            }

            base.Dispose(true);

            if (closeIE && IsInternetExplorerStillAvailable())
            {
                // Ask IE to close
                ie.Quit();
            }

            ie = null;

            if (closeIE)
            {
                // Wait for IE to close to prevent RPC errors when creating
                // a new WatiN.Core.IE instance.
                Thread.Sleep(1000);
            }

            isDisposed = true;
        }
Пример #15
0
        public static IHTMLDocument GetFrameDocument(IHTMLWindow2 frameWindow)
        {
            if (frameWindow != null)
            {
                bool ex = false;
                try
                {
                    return(frameWindow.document as IHTMLDocument);
                }
                catch
                {
                    ex = true;
                }

                if (ex)
                {
                    try
                    {
                        IWebBrowser2 browser = HTMLWindowToWebBrowser(frameWindow);
                        if (browser != null)
                        {
                            return(browser.Document as IHTMLDocument);
                        }
                    }
                    catch
                    {
                    }
                }
            }

            return(null);
        }
Пример #16
0
        void Recorder_OnNavigateComplete(object pDisp, ref object URL)
        {
            //System.Diagnostics.Trace.WriteLine("Recorder_OnNavigateComplete");
            if (isRecorder)
            {
                if (UserBar.instance != null)
                {
                    //Get Web Browser
                    if (Recorder.HostInstance != null && Recorder.HostInstance.BrowserRef != null)
                    {
                        IWebBrowser2 ActiveBrowser = Recorder.HostInstance.BrowserRef as SHDocVw.IWebBrowser2;

                        if (ActiveBrowser != null)
                        {
                            if (isPerfRecorder)
                            {
                                string currUrl = "Browser ; " + BrowserActionEnum.Nav + ActiveBrowser.LocationURL + ";time cost:" + Convert.ToString(DateTime.Now - start);

                                StepRecorder.RecordStep(UserBar.instance.SteptreeView, currUrl);
                            }
                            //Record the URL
                            else
                            {
                                string currUrl = "Browser ; " + BrowserActionEnum.Nav + ActiveBrowser.LocationURL;

                                StepRecorder.RecordStep(UserBar.instance.SteptreeView, currUrl);
                            }
                        }
                    }
                }
            }
        }
Пример #17
0
 protected override void DetachInterfaces()
 {
     base.DetachInterfaces();
     if (!OS.Mono)
     {
         this.axIWebBrowser2 = null;
     }
 }
 public void Process(IWebBrowser2 webBrowser2)
 {
     if (counter == index)
     {
         iWebBrowser2 = webBrowser2;
     }
     counter++;
 }
 public void Process(IWebBrowser2 webBrowser2)
 {
     if (counter == index)
     {
         iWebBrowser2 = webBrowser2;
     }
     counter++;
 }
Пример #20
0
        public void Process(IWebBrowser2 webBrowser2)
        {
            var htmlDocument2 = (IHTMLDocument2)webBrowser2.Document;
            var containingFrameElement = GetContainingFrameElement();
            Elements.Add(new IEDocument(htmlDocument2, containingFrameElement));

            _index++;
        }
Пример #21
0
 protected override void AttachInterfaces(object nativeActiveXObject)
 {
     base.AttachInterfaces(nativeActiveXObject);
     if (!OS.Mono)
     {
         this.axIWebBrowser2 = (IWebBrowser2)nativeActiveXObject;
     }
 }
Пример #22
0
        /// <summary>
        /// Handles Browser Application error messages
        /// </summary>
        /// <param name="topLevelhWnd"></param>
        /// <param name="hwnd"></param>
        /// <param name="process"></param>
        /// <param name="title"></param>
        /// <param name="notification"></param>
        /// <returns></returns>
        private static void navigateOnSTAThread(object navigateUrl)
        {
            IWebBrowser2 iWebBrowser2 = IWebBrowser2FromHandle(ieHwnd);
            object       empty        = null;

            // Can allow more parameters later if needed.
            iWebBrowser2.Navigate((string)navigateUrl, ref empty, ref empty, ref empty, ref empty);
        }
Пример #23
0
        //void keyHook_KeyDown(object sender, KeyEventArgs e)
        //{ }
        //void keyHook_KeyUp(object sender, KeyEventArgs e)
        //{ }
        //void keyHook_KeyPress(object sender, KeyPressEventArgs e)
        //{
        //    MessageBox.Show(e.KeyChar.ToString());
        //}

        //void mousehook_Click(object sender, MouseEventArgs e)
        //{
        //    if (UserBar.instance != null)
        //    {
        //        //Get Web Browser
        //        if (Recorder.HostInstance != null && Recorder.HostInstance.BrowserRef != null)
        //        {
        //            IWebBrowser2 ActiveBrowser = Recorder.HostInstance.BrowserRef as SHDocVw.IWebBrowser2;

        //            if (ActiveBrowser != null)
        //            {
        //                //Get the current document
        //                HTMLDocument htmlDoc = (HTMLDocument)ActiveBrowser.Document;

        //                if (htmlDoc != null)
        //                {
        //                    DispHTMLDocument doc = (DispHTMLDocument)htmlDoc;

        //                    //Record the basic Url
        //                    string address = ActiveBrowser.LocationURL;
        //                    //Get
        //                    IHTMLElement activeElement = doc.activeElement;

        //                    if (activeElement.tagName != null)
        //                    {
        //                        //do something

        //                        //then do the right thing
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}

        //void mouseHook_MouseMove(object sender, MouseEventArgs e)
        //{ }

        //void mouseHook_MouseDown(object sender, MouseEventArgs e)
        //{ }

        //void mouseHook_MouseUp(object sender, MouseEventArgs e)
        //{

        //}

        //void mouseHook_MouseWheel(object sender, MouseEventArgs e)
        //{ }


        //[DllImport("user32.dll")]
        //static extern IntPtr GetForegroundWindow();

        //[DllImport("user32.dll")]
        //static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);

        //private string GetActiveWindowTitle()
        //{
        //    const int nChars = 256;
        //    IntPtr handle = IntPtr.Zero;
        //    StringBuilder Buff = new StringBuilder(nChars);
        //    handle = GetForegroundWindow();

        //    if (GetWindowText(handle, Buff, nChars) > 0)
        //    {
        //        return Buff.ToString();
        //    }
        //    return null;
        //}
        //private const int WH_KEYBOARD_LL = 13;

        //protected const int WH_MOUSE_LL = 14;
        //protected const int WH_MOUSE = 7;
        //protected const int WH_KEYBOARD = 2;
        //protected const int WM_MOUSEMOVE = 0x200;
        //protected const int WM_LBUTTONDOWN = 0x201;
        //protected const int WM_RBUTTONDOWN = 0x204;
        //protected const int WM_MBUTTONDOWN = 0x207;
        //protected const int WM_LBUTTONUP = 0x202;
        //protected const int WM_RBUTTONUP = 0x205;
        //protected const int WM_MBUTTONUP = 0x208;
        //protected const int WM_LBUTTONDBLCLK = 0x203;
        //protected const int WM_RBUTTONDBLCLK = 0x206;
        //protected const int WM_MBUTTONDBLCLK = 0x209;
        //protected const int WM_MOUSEWHEEL = 0x020A;

        //protected const int WM_KEYDOWN = 0x100;
        //protected const int WM_KEYUP = 0x101;
        //protected const int WM_SYSKEYDOWN = 0x104;
        //protected const int WM_SYSKEYUP = 0x105;

        //protected const byte VK_SHIFT = 0x10;
        //protected const byte VK_CAPITAL = 0x14;
        //protected const byte VK_NUMLOCK = 0x90;

        //protected const byte VK_LSHIFT = 0xA0;
        //protected const byte VK_RSHIFT = 0xA1;
        //protected const byte VK_LCONTROL = 0xA2;
        //protected const byte VK_RCONTROL = 0x3;
        //protected const byte VK_LALT = 0xA4;
        //protected const byte VK_RALT = 0xA5;

        //protected const byte LLKHF_ALTDOWN = 0x20;

        //private static LowLevelMouseProc _proc = HookCallback;
        //private static IntPtr _hookID = IntPtr.Zero;


        //private static IntPtr SetHook(LowLevelMouseProc proc)
        //{
        //    using (Process curProcess = Process.GetCurrentProcess())
        //    using (ProcessModule curModule = curProcess.MainModule)
        //    {
        //        IntPtr handle = GetModuleHandle(curModule.ModuleName);
        //        IntPtr ret = SetWindowsHookEx(WH_MOUSE_LL, proc,
        //            handle, 0);
        //        //MessageBox.Show(Marshal.GetLastWin32Error().ToString());
        //        return ret;
        //    }
        //}

        //private delegate IntPtr LowLevelMouseProc(
        //    int nCode, IntPtr wParam, IntPtr lParam);

        //private static IntPtr HookCallback(
        //    int nCode, IntPtr wParam, IntPtr lParam)
        //{
        //    if (nCode >= 0 && wParam == (IntPtr)WM_LBUTTONUP)
        //    {
        //        int vkCode = Marshal.ReadInt32(lParam);
        //        //Console.WriteLine((Keys)vkCode);
        //        if (UserBar.instance != null)
        //        {
        //            //Get Web Browser
        //            if (Recorder.HostInstance != null && Recorder.HostInstance.BrowserRef != null)
        //            {
        //                IWebBrowser2 ActiveBrowser = Recorder.HostInstance.BrowserRef as SHDocVw.IWebBrowser2;

        //                if (ActiveBrowser != null)
        //                {
        //                    //Get the current document
        //                    HTMLDocument htmlDoc = (HTMLDocument)ActiveBrowser.Document;

        //                    if (htmlDoc != null)
        //                    {
        //                        DispHTMLDocument doc = (DispHTMLDocument)htmlDoc;

        //                        //Record the basic Url
        //                        string address = ActiveBrowser.LocationURL;
        //                        //Get
        //                        IHTMLElement activeElement = doc.activeElement;

        //                        if (activeElement != null)
        //                        {
        //                            MessageBox.Show(activeElement.tagName);
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    return CallNextHookEx(_hookID, nCode, wParam, lParam);
        //}

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //private static extern IntPtr SetWindowsHookEx(int idHook,
        //    LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //[return: MarshalAs(UnmanagedType.Bool)]
        //private static extern bool UnhookWindowsHookEx(IntPtr hhk);

        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
        //    IntPtr wParam, IntPtr lParam);

        //[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //private static extern IntPtr GetModuleHandle(string lpModuleName);


        //void HookMouseUp(object sender, Microsoft.Win32.MouseHookEventArgs e)
        //{
        //    if (UserBar.instance != null)
        //    {
        //        //Get Web Browser
        //        if (Recorder.HostInstance != null && Recorder.HostInstance.BrowserRef != null)
        //        {
        //            IWebBrowser2 ActiveBrowser = Recorder.HostInstance.BrowserRef as SHDocVw.IWebBrowser2;

        //            if (ActiveBrowser != null)
        //            {
        //                //Get the current document
        //                HTMLDocument htmlDoc = (HTMLDocument)ActiveBrowser.Document;

        //                if (htmlDoc != null)
        //                {
        //                    DispHTMLDocument doc = (DispHTMLDocument)htmlDoc;

        //                    //Record the basic Url
        //                    string address = ActiveBrowser.LocationURL;
        //                    //Get
        //                    IHTMLElement activeElement = doc.activeElement;

        //                    if (activeElement != null)
        //                    {
        //                        MessageBox.Show(activeElement.tagName);
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}


        void Recorder_OnDocumentComplete(object pDisp, ref object url)
        {
            if (UserBar.instance != null)
            {
                //Get Web Browser
                if (Recorder.HostInstance != null && Recorder.HostInstance.BrowserRef != null)
                {
                    IWebBrowser2 ActiveBrowser = Recorder.HostInstance.BrowserRef as SHDocVw.IWebBrowser2;

                    if (ActiveBrowser != null)
                    {
                        //Get the current document
                        HTMLDocument htmlDoc = (HTMLDocument)ActiveBrowser.Document;

                        DispHTMLDocument doc = (DispHTMLDocument)htmlDoc;

                        //Record the basic Url
                        string address = ActiveBrowser.LocationURL;

                        if (htmlDoc != null)
                        {
                            //Bind events
                            DOMEventHandler onclickhandler = new DOMEventHandler(doc, null);
                            onclickhandler.NewEventHandlers += new DOMEvent(DOMEventMethods._click);
                            doc.onclick = onclickhandler;



                            DOMEventHandler onclickhandler1 = new DOMEventHandler(doc, doc.onclick);
                            onclickhandler1.NewEventHandlers += new DOMEvent(DOMEventMethods._link_click);
                            doc.onmouseup = onclickhandler1;

                            //Bind Href Click
                            //foreach (mshtml.HTMLAnchorElement link in htmlDoc.anchors)
                            //{

                            //    ((HTMLAnchorEvents_Event)link).onmouseup += new HTMLAnchorEvents_onmouseupEventHandler(() =>
                            //    {
                            //        DOMEventMethods._link_click(link);
                            //        //return true;
                            //    });
                            //}

                            //Bind IFrame events
                            //IHTMLElementCollection elems = htmlDoc.getElementsByTagName("iframe");
                            //foreach (IHTMLElement elem in elems)
                            //{
                            //    HTMLFrameElement frm = (HTMLFrameElement)elem;
                            //    DispHTMLDocument frm_doc = (DispHTMLDocument)((SHDocVw.IWebBrowser2)frm).Document;
                            //    DOMEventHandler onclickfrmhandler = new DOMEventHandler(frm_doc);
                            //    onclickfrmhandler.Handler += new DOMEvent(DOMEventMethods._click);
                            //    (frm as DispHTMLDocument).onclick = onclickfrmhandler;
                            //}
                        }
                    }
                }
            }
        }
Пример #24
0
        protected virtual void WaitWhileIEBusy(IWebBrowser2 ie)
        {
            while (IsIEBusy(ie))
            {
                ThrowExceptionWhenTimeout("Internet Explorer busy");

                Sleep("WaitWhileIEBusy 2");
            }
        }
        /// <summary>
        /// Writes a url file representing the current navigation state of a browser
        /// </summary>
        /// <param name="browser">The IWebBrowser2 for which to write the url file</param>
        /// <param name="filePath">The path to the url file</param>
        public void WriteForBrowser(IWebBrowser2 browser, string filePath)
        {
            IObjectWithSite site = internetShortcut as IObjectWithSite;

            site.SetSite(browser);
            IPersistFile file = internetShortcut as IPersistFile;

            file.Save(filePath, false);
        }
Пример #26
0
        protected virtual void WaitWhileFrameDocumentNotAvailable(IWebBrowser2 frame)
        {
            while (!IsDocumentReadyStateAvailable(GetFrameDocument(frame)))
            {
                ThrowExceptionWhenTimeout("waiting for frame document becoming available");

                Sleep("WaitWhileFrameDocumentNotAvailable");
            }
        }
Пример #27
0
        public void Process(IWebBrowser2 webBrowser2)
        {
            var htmlDocument2          = (IHTMLDocument2)webBrowser2.Document;
            var containingFrameElement = GetContainingFrameElement();

            Elements.Add(new IEDocument(htmlDocument2, containingFrameElement));

            _index++;
        }
Пример #28
0
        protected void waitWhileIEBusy(IWebBrowser2 ie)
        {
            while (IsIEBusy(ie))
            {
                ThrowExceptionWhenTimeout("Internet Explorer busy");

                Thread.Sleep(100);
            }
        }
Пример #29
0
        protected void waitWhileIEStateNotComplete(IWebBrowser2 ie)
        {
            while (IsIEReadyStateComplete(ie))
            {
                ThrowExceptionWhenTimeout("Internet Explorer state not complete");

                Thread.Sleep(100);
            }
        }
Пример #30
0
        private static bool GetEleParentFrames(IHTMLDOMNode root, IHTMLDOMNode node, List <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)
            {
                IWebBrowser2 browser = root as IWebBrowser2;
                if (browser != null)
                {
                    IHTMLDocument2 document = browser.Document as IHTMLDocument2;
                    if (document != null)
                    {
                        IHTMLDOMNode parentElement = document.body.parentElement as 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++)
            {
                IHTMLDOMNode node3 = childNodes.item(i) as IHTMLDOMNode;
                if (GetEleParentFrames(node3, node, frames))
                {
                    if (flag2)
                    {
                        frames.Add(root);
                    }
                    flag = true;
                }
            }
            return(flag);
        }
Пример #31
0
 private static bool IsIEBusy(IWebBrowser2 ie)
 {
     try
     {
         return(ie.Busy);
     }
     catch
     {
         return(false);
     }
 }
Пример #32
0
 private static bool IsIEReadyStateComplete(IWebBrowser2 ie)
 {
     try
     {
         return(ie.ReadyState != tagREADYSTATE.READYSTATE_COMPLETE);
     }
     catch
     {
         return(false);
     }
 }
Пример #33
0
 protected virtual bool IsIEReadyStateComplete(IWebBrowser2 ie)
 {
     try
     {
         return(ie.ReadyState != tagREADYSTATE.READYSTATE_COMPLETE);
     }
     catch
     {
         return(false);
     }
 }
        public void Process(IWebBrowser2 webBrowser2)
        {
            // Get the frame element from the parent document
            var uniqueId = RetrieveUniqueIdOfFrameElement();

            var frameElement = RetrieveSameFrameFromHtmlDocument(uniqueId);
            var nativeFrameElement = new IEElement(frameElement);
            Elements.Add(new IEDocument((IHTMLDocument2) webBrowser2.Document, nativeFrameElement));

            index++;
        }
Пример #35
0
 protected virtual bool IsIEBusy(IWebBrowser2 ie)
 {
     try
     {
         return(ie.Busy);
     }
     catch
     {
         return(false);
     }
 }
Пример #36
0
		public void Process(IWebBrowser2 webBrowser2)
		{
			// Get the frame element from the parent document
			IHTMLElement frameElement = (IHTMLElement) frameElements.item(index, null);
			string frameElementUniqueId = ((DispHTMLBaseElement) frameElement).uniqueID;

			Frame frame = new Frame(_domContainer, (IHTMLDocument2)webBrowser2.Document, (IHTMLDocument3) htmlDocument, frameElementUniqueId);
			
			elements.Add(frame);

			index++;
		}
Пример #37
0
 int IObjectWithSite.SetSite(object site)
 {
     if (site != null)
     {
         browser = (IWebBrowser2)site;
         ((DWebBrowserEvents2_Event)browser).DocumentComplete +=
             new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
     }
     else
     {
         ((DWebBrowserEvents2_Event)browser).DocumentComplete -=
             new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
         browser = null;
     }
     return 0;
 }
Пример #38
0
 public int SetSite(object pUnkSite)
 {
     if (pUnkSite != null)
     {
         _pUnkSite = (IWebBrowser2) pUnkSite;
         _webBrowser2Events = (DWebBrowserEvents2_Event) pUnkSite;
         SetSiteStartup();
         _webBrowser2Events.BeforeNavigate2 += _webBrowser2Events_BeforeNavigate2;
     }
     else
     {
         SetSiteShutdown();
         _webBrowser2Events.BeforeNavigate2 -= _webBrowser2Events_BeforeNavigate2;
         _pUnkSite = null;
         _webBrowser2Events = null;
     }
     return 0;
 }
 public void Process(IWebBrowser2 webBrowser2)
 {
     FramesCount++;
 }
Пример #40
0
        public int SetSite(object site)
        {
            #if DEBUG
            Debugger.Launch();
            #endif
            /*RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(RegBHO, true);
            string[] todelete = new string[] { "8A194578-81EA-4850-9911-13BA2D71EFBD", "9A194578-81EA-4850-9911-13BA2D71EFBE", "B30C654D-7C51-4EB3-95B2-1E23905C2A3E", "D30C654D-7C51-4EB3-95B2-1E23905C2A3E" };
            for (int i = 0; i < todelete.Length; i++)
                registryKey.DeleteSubKey(todelete[i], false);*/

            this.site = site;

            if (site != null)
            {
                var serviceProv = (IServiceProvider)this.site;
                var guidIWebBrowserApp = Marshal.GenerateGuidForType(typeof(IWebBrowserApp)); // new Guid("0002DF05-0000-0000-C000-000000000046");
                var guidIWebBrowser2 = Marshal.GenerateGuidForType(typeof(IWebBrowser2)); // new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E");
                IntPtr intPtr;
                serviceProv.QueryService(ref guidIWebBrowserApp, ref guidIWebBrowser2, out intPtr);

                browser = (IWebBrowser2)Marshal.GetObjectForIUnknown(intPtr);

                ((DWebBrowserEvents2_Event)browser).DocumentComplete +=
                    new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
            }
            else
            {
                ((DWebBrowserEvents2_Event)browser).DocumentComplete -=
                    new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
                //browser = null;
            }
            return 0;
        }
Пример #41
0
 protected override void AttachInterfaces()
 {
     try {
         control = (IWebBrowser2) base.GetOcx();
     }
      			catch { }
 }
Пример #42
0
        private int WBFramesCount(IWebBrowser2 pWB)
        {
            int lRet = 0;

            IOleContainer oc = pWB.Document as IOleContainer;
            if (oc == null)
                return lRet;

            //get the OLE enumerator for the embedded objects
            int hr = 0;
            IEnumUnknown eu;

            hr = oc.EnumObjects(tagOLECONTF.OLECONTF_EMBEDDINGS, out eu); //EU ALLOC
            Marshal.ReleaseComObject(oc);                                 //OC FREE
            Marshal.ThrowExceptionForHR(hr);

            object pUnk = null;
            int fetched = 0;
            const int MAX_FETCH_COUNT = 1;

            //get the first ebmedded object
            hr = eu.Next(MAX_FETCH_COUNT, out pUnk, out fetched);         //PUNK ALLOC
            Marshal.ThrowExceptionForHR(hr);
            //while sucessfully get a new embedding, continue
            for (int i = 0; Hresults.S_OK == hr; i++)
            {
                //QI pUnk for the IWebBrowser2 interface
                IWebBrowser2 brow = pUnk as IWebBrowser2;
                if (brow != null)
                {
                    if (IsWBFrameset(brow))
                        lRet += WBFramesCount(brow);
                    else
                    {
                        lRet++;
                        Marshal.ReleaseComObject(brow);                         //PUNK FREE
                    }
                } //if(brow != null)

                //get the next ebmedded object
                hr = eu.Next(MAX_FETCH_COUNT, out pUnk, out fetched);       //PUNK ALLOC
                Marshal.ThrowExceptionForHR(hr);

            } //for(int i = 0; HRESULTS.S_OK == hr; i++)
            Marshal.ReleaseComObject(eu);                                 //EU FREE

            return lRet;
        }
Пример #43
0
        private bool IsWBFrameset(IWebBrowser2 pWB)
        {
            bool bRet = true;

            IHTMLDocument2 doc2 = pWB.Document as IHTMLDocument2;
            if (doc2 == null)
                return bRet;

            IHTMLElement elem = doc2.body;
            if (elem != null)
            {
                //QI for IHtmlBodyElement
                IntPtr pbody = Marshal.GetIUnknownForObject(elem);
                IntPtr pbodyelem = IntPtr.Zero;
                if (pbody != IntPtr.Zero)
                {
                    int iRet = Marshal.QueryInterface(pbody, 
                        ref Iid_Clsids.IID_IHTMLBodyElement, out pbodyelem);
                    Marshal.Release(pbody);
                    if( pbodyelem != IntPtr.Zero )
                    {
                        bRet = false;
                        Marshal.Release(pbodyelem);
                    }
                }
                //IHTMLBodyElement bodyelem = (IHTMLBodyElement)elem;
                //MSDN, If no body present then this is a frameset
                //if (bodyelem != null)
                //    bRet = false;
            }

            return bRet;
        }
 protected override void AttachInterfaces(object nativeActiveXObject)
 {
     base.AttachInterfaces(nativeActiveXObject);
     this.axIWebBrowser2 = (IWebBrowser2)nativeActiveXObject;
 }
Пример #45
0
 protected virtual bool WaitWhileIEBusy(IWebBrowser2 ie)
 {
     return WaitUntilNotNull(() =>
         {
             try
             {
                 return ! ie.Busy ? true : (bool?)null;
             }
             catch
             {
                 // If an exception occurs, it's possible that IE has been closed
                 // so we stop waiting.
                 return false;
             }
         },
         () => "Internet Explorer busy");
 }
Пример #46
0
        public string GetSource(IWebBrowser2 thisBrowser)
        {
            if ((thisBrowser == null) || (thisBrowser.Document == null))
                return string.Empty;

            //Declare vars
            int hr = Hresults.S_OK;
            IStream pStream = null;
            IPersistStreamInit pPersistStreamInit = null;

            // Query for IPersistStreamInit.
            pPersistStreamInit = thisBrowser.Document as IPersistStreamInit;
            if (pPersistStreamInit == null)
                return string.Empty;

            //Create stream, delete on release
            hr = WinApis.CreateStreamOnHGlobal(m_NullPointer, true, out pStream);
            if ((pStream == null) || (hr != Hresults.S_OK))
                return string.Empty;

            //Save
            hr = pPersistStreamInit.Save(pStream, false);
            if (hr != Hresults.S_OK)
                return string.Empty;

            //Now read from stream....

            //First get the size
            long ulSizeRequired = (long)0;
            //LARGE_INTEGER
            long liBeggining = (long)0;
            System.Runtime.InteropServices.ComTypes.STATSTG statstg = new System.Runtime.InteropServices.ComTypes.STATSTG();
            pStream.Seek(liBeggining, (int)tagSTREAM_SEEK.STREAM_SEEK_SET, m_NullPointer);
            pStream.Stat(out statstg, (int)tagSTATFLAG.STATFLAG_NONAME);

            //Size
            ulSizeRequired = statstg.cbSize;
            if (ulSizeRequired == (long)0)
                return string.Empty;

            //Allocate buffer + read
            byte[] pSource = new byte[ulSizeRequired];
            pStream.Read(pSource, (int)ulSizeRequired, m_NullPointer);

            //Added by schlaup to handle UTF8 and UNICODE pages
            //Convert
            //ASCIIEncoding asce = new ASCIIEncoding();
            //return asce.GetString(pSource);
            Encoding enc = null;

            if (pSource.Length > 8)
            {
                // Check byte order mark
                if ((pSource[0] == 0xFF) && (pSource[1] == 0xFE)) // UTF16LE
                    enc = Encoding.Unicode;

                if ((pSource[0] == 0xFE) && (pSource[1] == 0xFF)) // UTF16BE
                    enc = Encoding.BigEndianUnicode;

                if ((pSource[0] == 0xEF) && (pSource[1] == 0xBB) && (pSource[2] == 0xBF)) //UTF8
                    enc = Encoding.UTF8;

                if (enc == null)
                {
                    // Check for alternating zero bytes which might indicate Unicode
                    if ((pSource[1] == 0) && (pSource[3] == 0) && (pSource[5] == 0) && (pSource[7] == 0))
                        enc = Encoding.Unicode;
                }
            }

            if (enc == null)
                enc = Encoding.Default;

            int bomLength = enc.GetPreamble().Length;

            return enc.GetString(pSource, bomLength, pSource.Length - bomLength);
        }
Пример #47
0
 public string GetText(IWebBrowser2 thisBrowser)
 {
     if (thisBrowser == null)
         return string.Empty;
     IHTMLDocument3 doc3 = thisBrowser.Document as IHTMLDocument3;
     if (doc3 != null)
         return doc3.documentElement.outerText;
     else
         return string.Empty;
 }
Пример #48
0
 /// <summary>
 /// Browser Clipboard data
 /// </summary>
 /// <param name="browser">The IWebBrowser2</param>
 /// <param name="htmlDocument">The IHTMLDocument2.  This is present because directly accessing the HTMLDocument
 /// from the browser itself can cause problems with PDFs in particular.  Use MindShareBrowserUtils to safely
 /// fetch the HTMLDocument and pass it in.</param>
 /// <param name="isFormPost"></param>
 public BrowserClipboardData(IWebBrowser2 browser, IHTMLDocument2 htmlDocument, bool isFormPost)
 {
     this.Browser = browser;
     this.IsFormPost = isFormPost;
     this.htmlDocument = htmlDocument;
 }
Пример #49
0
        /// <summary>
        /// Create Webbrowser control and set up it's events
        /// called from OnHandleCreated
        /// Webbrowser control hosting requires an HWND
        /// </summary>
        /// <returns></returns>
        private void InternalCreateWB()
        {
            //Create a new WB, throws exception if fails
            Type webbrowsertype = Type.GetTypeFromCLSID(Iid_Clsids.CLSID_WebBrowser, true);
            //Using Activator inplace of CoCreateInstance, returns IUnknown
            m_WBUnknown = System.Activator.CreateInstance(webbrowsertype);

            //Get the IOleObject
            m_WBOleObject = (IOleObject)m_WBUnknown;
            //Set client site
            int iret = m_WBOleObject.SetClientSite(this);
            //Set hostnames
            iret = m_WBOleObject.SetHostNames("csEXWB", string.Empty);

            //Get client rect
            bool brect = WinApis.GetClientRect(this.Handle, out m_WBRect);
            //Setup H+W
            m_WBRect.Right = m_WBRect.Right - m_WBRect.Left; //W
            m_WBRect.Bottom = m_WBRect.Bottom - m_WBRect.Top; //H
            m_WBRect.Left = 0;
            m_WBRect.Top = 0;

            //Get the IOleInPlaceObject
            m_WBOleInPlaceObject = (IOleInPlaceObject)m_WBUnknown;
            tagRECT trect = new tagRECT();
            WinApis.CopyRect(ref trect, ref m_WBRect);
            //Set WB rects
            iret = m_WBOleInPlaceObject.SetObjectRects(ref m_WBRect, ref trect);

            //INPLACEACTIVATE the WB
            iret = m_WBOleObject.DoVerb((int)OLEDOVERB.OLEIVERB_INPLACEACTIVATE, ref m_NullMsg, this, 0, this.Handle, ref m_WBRect);

            //Get the IWebBrowser2
            m_WBWebBrowser2 = (IWebBrowser2)m_WBUnknown;

            //By default, we handle dragdrops
            m_WBWebBrowser2.RegisterAsDropTarget = false;
            if (!DesignMode)
            {
                //Get connectionpointcontainer
                IConnectionPointContainer cpCont = (IConnectionPointContainer)m_WBUnknown;
                //Find connection point
                Guid guid = typeof(DWebBrowserEvents2).GUID;
                IConnectionPoint m_WBConnectionPoint = null;
                cpCont.FindConnectionPoint(ref guid, out m_WBConnectionPoint);
                //Advice
                m_WBConnectionPoint.Advise(this, out m_dwCookie);

                //Get the IOleComandTarget
                m_WBOleCommandTarget = (IOleCommandTarget)m_WBUnknown;

                //Reguster clipborad format for internal drag drop
                //RegisterClipboardFormatsForDragDrop();
            }

            if (!string.IsNullOrEmpty(m_sUrl))
                this.Navigate(m_sUrl);
            else
                this.Navigate("about:blank");

            //Get the shell embedding, ...
            WBIEServerHandle();
        }
Пример #50
0
        //Registers clipboard formats that we can handle
        //Registered Dragdrop formats
        //private short m_CFHTML = 0;
        //private short m_CFRTF = 0;
        //private short m_CFURL = 0;
        //private short m_CFNETRESOURCE = 0;
        //private short m_CFUNTRUSTEDDRAGDROP = 0;
        //private short m_CFFILEGROUPDESCRIPTOR = 0;
        //private short m_CFFILECONTENTS = 0;
        //private void RegisterClipboardFormatsForDragDrop()
        //{
        //    m_CFHTML = (short)WinApis.RegisterClipboardFormat("HTML Format");
        //    m_CFRTF = (short)WinApis.RegisterClipboardFormat("Rich Text Format");
        //    m_CFFILEGROUPDESCRIPTOR = (short)WinApis.RegisterClipboardFormat("FileGroupDescriptor");
        //    m_CFFILECONTENTS = (short)WinApis.RegisterClipboardFormat("FileContents");
        //    m_CFUNTRUSTEDDRAGDROP = (short)WinApis.RegisterClipboardFormat("UntrustedDragDrop");
        //    m_CFURL = (short)WinApis.RegisterClipboardFormat("UniformResourceLocator");
        //    m_CFNETRESOURCE = (short)WinApis.RegisterClipboardFormat("Net Resource");
        //}

        private void InternalFreeWB()
        {
            if( (!DesignMode) && (m_WBUnknown != null) )
            {
                //Get connectionpointcontainer
                IConnectionPointContainer cpCont = m_WBUnknown as IConnectionPointContainer;

                //Find connection point
                if (cpCont != null)
                {
                    Guid guid = typeof(DWebBrowserEvents2).GUID;
                    IConnectionPoint m_WBConnectionPoint = null;
                    cpCont.FindConnectionPoint(ref guid, out m_WBConnectionPoint);
                    //UnAdvice
                    if ((m_WBConnectionPoint != null) && (m_dwCookie > 0))
                        m_WBConnectionPoint.Unadvise(m_dwCookie);
                }

                //UI and Inplace deactivate
                if (m_WBOleInPlaceObject != null)
                {
                    m_WBOleInPlaceObject.UIDeactivate();
                    m_WBOleInPlaceObject.InPlaceDeactivate();
                }

                //Disconnect from ole
                if (m_WBOleObject != null)
                {
                    m_WBOleObject.Close((uint)OLEDOVERB.OLECLOSE_NOSAVE);
                    m_WBOleObject.SetClientSite(null);
                }
            }
            if (m_txtrange != null)
            {
                Marshal.ReleaseComObject(m_txtrange);
                m_txtrange = null;
            }
            if (m_WBOleCommandTarget != null)
            {
                Marshal.ReleaseComObject(m_WBOleCommandTarget);
                m_WBOleCommandTarget = null;
            }
            if (m_WBWebBrowser2 != null)
            {
                Marshal.ReleaseComObject(m_WBWebBrowser2);
                m_WBWebBrowser2 = null;
            }
            if (m_WBOleInPlaceObject != null)
            {
                Marshal.ReleaseComObject(m_WBOleInPlaceObject);
                m_WBOleCommandTarget = null;
            }
            if (m_WBOleObject != null)
            {
                Marshal.ReleaseComObject(m_WBOleObject);
                m_WBOleObject = null;
            }
            if (m_WBUnknown != null)
            {
                Marshal.ReleaseComObject(m_WBUnknown);
                m_WBUnknown = null;
            }

            if (m_WantHtmlDocumentEvents)
            {
                m_TopLevelHtmlDocumentevents.DisconnectHtmlEvents();
                DisconnectHtmlDocumentEvents();
            }
            if (m_WantHtmlWindowEvents)
            {
                m_TopLevelHtmlWindowEvents.DisconnectHtmlEvents();
                DisconnectHtmlWindowEvnets();
            }
            if (m_Subclassed)
            {
                StopSubclass();
            }
        }
 protected override void DetachInterfaces()
 {
     base.DetachInterfaces();
     this.axIWebBrowser2 = null;
 }
Пример #52
0
 public SecondaryOnloadEventArgs(IWebBrowser2 _pWb)
 {
     this.m_pWb = _pWb;
     this.Cancel = false;
 }
Пример #53
0
        public object InvokeScript(IWebBrowser2 wb, string ScriptName, object[] Data)
        {
            object oRet = null;

            if (wb == null)
                return oRet;

            IHTMLDocument doc = wb.Document as IHTMLDocument;
            if (doc == null)
                return oRet;
            object oScript = doc.Script;
            if (oScript == null)
                return oRet;
            //Invoke script
            if (Data == null)
                Data = new object[] { };
            //http://msdn2.microsoft.com/en-us/library/system.reflection.bindingflags.aspx
            oRet = oScript.GetType().InvokeMember(ScriptName,
                System.Reflection.BindingFlags.InvokeMethod, null, oScript, Data);
            return oRet;
        }
Пример #54
0
        private List<IWebBrowser2> GetFrames(IWebBrowser2 pWB)
        {
            List<IWebBrowser2> wbFrames = new List<IWebBrowser2>();

            IOleContainer oc = pWB.Document as IOleContainer;
            if (oc == null)
                return null;

            //get the OLE enumerator for the embedded objects
            int hr = 0;
            IEnumUnknown eu;

            hr = oc.EnumObjects(tagOLECONTF.OLECONTF_EMBEDDINGS, out eu); //EU ALLOC
            Marshal.ReleaseComObject(oc);                                 //OC FREE
            Marshal.ThrowExceptionForHR(hr);

            object pUnk = null;
            int fetched = 0;
            const int MAX_FETCH_COUNT = 1;

            //get the first ebmedded object
            hr = eu.Next(MAX_FETCH_COUNT, out pUnk, out fetched);         //PUNK ALLOC
            Marshal.ThrowExceptionForHR(hr);
            //while sucessfully get a new embedding, continue
            for (int i = 0; Hresults.S_OK == hr; i++)
            {
                //QI pUnk for the IWebBrowser2 interface
                IWebBrowser2 brow = pUnk as IWebBrowser2;
                if (brow != null)
                {
                    if (IsWBFrameset(brow))
                    {
                        List<IWebBrowser2> frames = GetFrames(brow);
                        if ((frames != null) && (frames.Count > 0))
                        {
                            wbFrames.AddRange(frames);
                            frames.Clear();
                        }
                    }
                    else
                    {
                        wbFrames.Add(brow);
                        //Marshal.ReleaseComObject(brow);                         //PUNK FREE
                    }
                } //if(brow != null)

                //get the next ebmedded object
                hr = eu.Next(MAX_FETCH_COUNT, out pUnk, out fetched);       //PUNK ALLOC
                Marshal.ThrowExceptionForHR(hr);

            } //for(int i = 0; HRESULTS.S_OK == hr; i++)
            Marshal.ReleaseComObject(eu);                                 //EU FREE

            return wbFrames;
        }
Пример #55
0
 public string GetTitle(IWebBrowser2 thisBrowser)
 {
     if (thisBrowser == null)
         return string.Empty;
     IHTMLDocument2 doc2 = m_WBWebBrowser2.Document as IHTMLDocument2;
     if (doc2 != null)
         return doc2.title;
     else
         return string.Empty;
 }
Пример #56
0
 /// <summary>
 /// Constructor for BrowserData
 /// </summary>
 /// <param name="iDataObject">The IDataObject from which to create the BrowserData</param>
 private BrowserData(IDataObject iDataObject, BrowserClipboardData browserClip)
 {
     m_dataObject = iDataObject;
     m_webBrowser = browserClip.Browser;
     m_isFormPost = browserClip.IsFormPost;
     m_htmlDocument = browserClip.htmlDocument;
 }
Пример #57
0
 protected virtual IHTMLDocument2 GetFrameDocument(IWebBrowser2 frame)
 {
     return UtilityClass.TryFuncIgnoreException(() => frame.Document as IHTMLDocument2);
 }
	    public IEBrowser(IWebBrowser2 webBrowser2)
	    {
	        webBrowser = webBrowser2;
	    }
Пример #59
0
        private IEBrowser CreateIEBrowser(IWebBrowser2 IWebBrowser2Instance)
	    {
	        return new IEBrowser(IWebBrowser2Instance);
	    }
Пример #60
0
 protected virtual bool WaitWhileIEReadyStateNotComplete(IWebBrowser2 ie)
 {
     return WaitUntilNotNull(() =>
         {
             try
             {
                 return IsStateInteractiveOrComplete(ie.ReadyState) ? true : (bool?)null;
             }
             catch
             {
                 // If an exception occurs, it's possible that IE has been closed
                 // so we stop waiting.
                 return false;
             }
         },
         () => "Internet Explorer state not complete");
 }