Exemple #1
0
        private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.m_iWebBrowser = (SHDocVw.WebBrowser) this.ctlBrowser.GetType().InvokeMember(
                "ActiveXInstance",
                BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                null,
                this.ctlBrowser,
                new object[] { });

            this.m_iWebBrowser.Resizable            = false;
            this.m_iWebBrowser.Silent               = true;
            this.m_iWebBrowser.StatusBar            = false;
            this.m_iWebBrowser.TheaterMode          = false;
            this.m_iWebBrowser.Offline              = false;
            this.m_iWebBrowser.MenuBar              = false;
            this.m_iWebBrowser.RegisterAsBrowser    = false;
            this.m_iWebBrowser.RegisterAsDropTarget = false;
            this.m_iWebBrowser.AddressBar           = false;

            this.m_iWebBrowser.NewWindow2    += (ref object ppDisp, ref bool Cancel) => Cancel = true;
            this.m_iWebBrowser.NewWindow3    += (ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl) => Cancel = true;
            this.m_iWebBrowser.NewProcess    += (int lCauseFlag, object pWB2, ref bool Cancel) => Cancel = true;
            this.m_iWebBrowser.FileDownload  += (bool ActiveDocument, ref bool Cancel) => Cancel = true;
            this.m_iWebBrowser.WindowClosing += (bool IsChildWindow, ref bool Cancel) => Cancel = true;

            this.m_iWebBrowser.NavigateError     += this.vwWebBrowser_NavigateError;
            this.m_iWebBrowser.NavigateComplete2 += this.vwWebBrowser_NavigateComplete2;
        }
Exemple #2
0
        public static mshtml.IHTMLElement GetXPath(this SHDocVw.WebBrowser wb, string xpath)
        {
            CallScript(wb);


            //bool completed = false;
            ////wb.ScriptErrorsSuppressed = true;
            ////wb.DocumentCompleted += delegate { completed = true; };
            ////wb.Navigate("http://stackoverflow.com/");

            ////while (!completed)
            ////{
            ////    Application.DoEvents();
            ////    Thread.Sleep(100);
            ////}

            //if (wb.Document != null)
            //{
            //    mshtml.IHTMLElement head = wb.Document.GetElementsByTagName("head")[0];
            //    HtmlElement scriptEl = wb.Document.CreateElement("script");
            //    mshtml.IHTMLScriptElement element = (mshtml.IHTMLScriptElement)scriptEl.DomElement;
            //    element.text = System.IO.File.ReadAllText(@"wgxpath.install.js");
            //    head.AppendChild(scriptEl);

            //    // Call wgxpath.install() from JavaScript code, which will ensure document.evaluate
            //    wb.Document.InvokeScript("eval", new object[] { "wgxpath.install()" });

            //    string xPathQuery = @"count(//script)";
            //    string code = string.Format("document.evaluate('{0}', document, null, XPathResult.NUMBER_TYPE, null).numberValue;", xPathQuery);
            //    int iResult = (int)wb.Document.InvokeScript("eval", new object[] { code });
            //}
            return(null);
        }
Exemple #3
0
        public static treeelement[] GetRootElements()
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
            SHDocVw.WebBrowser   Browser      = null;
            mshtml.HTMLDocument  Document     = null;
            foreach (SHDocVw.InternetExplorer _ie in shellWindows)
            {
                var filename = System.IO.Path.GetFileNameWithoutExtension(_ie.FullName).ToLower();

                if (filename.Equals("iexplore"))
                {
                    //Debug.WriteLine("Web Site   : {0}", _ie.LocationURL);
                    try
                    {
                        Browser  = _ie as SHDocVw.WebBrowser;
                        Document = (Browser.Document as mshtml.HTMLDocument);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "");
                    }
                }
            }
            if (Document == null)
            {
                Log.Warning("Failed locating an Internet Explore instance");
                return(new treeelement[] { });
            }

            var e = new IETreeElement(null, true, new IEElement(Document.documentElement));

            return(new treeelement[] { e });
        }
Exemple #4
0
 ///<summary>Used when opening a new browser window via a link or to display html content.
 ///If html content and url specified, url will be used and given content ignored. postData and additionalHeaders will only be used if url is
 ///passed in.</summary>
 public FormWebBrowser(string url = "", string htmlContent = "", string postData = null, string additionalHeaders = "", bool canWrapNewWindow = true)
 {
     InitializeComponent();
     Lan.F(this);
     SHDocVw.WebBrowser axBrowser = (SHDocVw.WebBrowser)browser.ActiveXInstance;
     if (axBrowser != null)           //This was null once during testing.  Not sure when null can happen.  Not sure if we should allow the user to continue.
     {
         axBrowser.NewWindow2 += axBrowser_NewWindow2;
         axBrowser.NewWindow3 += axBrowser_NewWindow3;
     }
     _postData                     = postData;
     _additionalHeaders            = additionalHeaders;
     browser.DocumentTitleChanged += browser_DocumentTitleChanged;
     if (string.IsNullOrEmpty(url))
     {
         if (!string.IsNullOrEmpty(htmlContent))
         {
             browser.DocumentText = htmlContent;
         }
     }
     else
     {
         _urlBrowseTo = url;
     }
     _canWrapNewWindow = canWrapNewWindow;
 }
Exemple #5
0
 protected override void Dispose(bool disposing)
 {
     try
     {
         SHDocVw.WebBrowser wb2 = (SHDocVw.WebBrowser)ActiveXInstance;
         wb2.NavigateError   -= Wb2_NavigateError;
         wb2.BeforeNavigate2 -= Wb2_BeforeNavigate2;
         if (_domDocument != null)
         {
             _domDocument.onmousewheel -= docEvents_onmousewheel;
             Marshal.ReleaseComObject(_domDocument);
         }
         _timer?.Dispose();
         //release events
         NavigateRestricted = null;
         NavigateError      = null;
         Loading            = null;
         Timeout            = null;
         _domDocument       = null;
         base.Dispose(disposing);
     }
     catch (Exception e)
     {
         Log.Error(e);
     }
 }
 private void NavigateLogout()
 {
     logoutBrowser.Navigate("https://www.mercadolibre.com/jms/mla/lgz/logout?go=www.google.com");
     logoutBrowser.NewWindow += new CancelEventHandler(logoutBrowser_NewWindow);
     SHDocVw.WebBrowser axBrowser = (SHDocVw.WebBrowser) this.logoutBrowser.ActiveXInstance;
     axBrowser.NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axBrowser_NewWindow3);
 }
Exemple #7
0
 protected override void OnCreateControl()
 {
     base.OnCreateControl();
     SHDocVw.WebBrowser wb2 = (SHDocVw.WebBrowser)ActiveXInstance;
     wb2.NavigateError   += Wb2_NavigateError;
     wb2.BeforeNavigate2 += Wb2_BeforeNavigate2;
 }
Exemple #8
0
 private void SetupBrowser(object sender, WebBrowserDocumentCompletedEventArgs e)
 {
     DocumentCompleted -= SetupBrowser;
     SHDocVw.WebBrowser xBrowser = (SHDocVw.WebBrowser)ActiveXInstance;
     xBrowser.BeforeNavigate2 += BeforeNavigate;
     DocumentCompleted        += PageLoaded;
 }
        void BringToFore(SHDocVw.WebBrowser ietab)
        {
            try
            {
                IntPtr hwndParent = (IntPtr)ietab.HWND;
                if (IntPtr.Zero.Equals(hwndParent))
                {
                    return;
                }

                // Step 1: bring parent window to the front, or restore it.
                if (Win32.IsIconic(hwndParent))
                {
                    // the window is currently minimized
                    Win32.ShowWindow(hwndParent, Constants.SW_RESTORE);
                }

                // It is now, or was already, maximzed or restored.  Honestly
                // I don't know if I always need all of these next three
                // calls, but I also don't know how to test all the scenarios
                // to find out if I need them all.
                Win32.BringWindowToTop(hwndParent);
                Win32.SetForegroundWindow(hwndParent);
                Win32.SetActiveWindow(hwndParent);

                // Step 2: activate the particular tab within the window
                Win32.ActivateTab(ietab);
            }
            catch (System.Exception exc1)
            {
                var msg = String.Format("Exception bringing tab forward: {0}", exc1);
                appState.Messages.AddAlert(msg);
            }
        }
        void Browser_NavigateComplete2(object pDisp, ref object URL)
        {
            // If the site or url is null, do not continue
            if (pDisp == null || URL == null)
            {
                return;
            }

            // Access both the web browser object and the url passed
            // to this event handler
            SHDocVw.WebBrowser browser = (SHDocVw.WebBrowser)pDisp;
            string             url     = URL.ToString();

            // Grab the document object off of the Web Browser control
            IHTMLDocument2 document = (IHTMLDocument2)Browser.Document;

            if (document == null)
            {
                return;
            }

            // Report the total number of links on the current page
            MessageBox.Show("Total link in URL " + url + ": \n" +
                            document.links.length.ToString());
        }
Exemple #11
0
        protected override void OnContentRendered(EventArgs e)
        {
            base.OnContentRendered(e);
            if (this.m_shown)
            {
                return;
            }

            this.m_shown = true;

            NativeMethods.SetCookieSupressBehavior();

            try
            {
                this.m_webBrowserSh = (SHDocVw.WebBrowser) this.ctlWebBrowser.GetType().InvokeMember("ActiveXInstance", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, this.ctlWebBrowser, new object[] { });

                this.m_webBrowserSh.Resizable            = false;
                this.m_webBrowserSh.Silent               = true;
                this.m_webBrowserSh.StatusBar            = false;
                this.m_webBrowserSh.TheaterMode          = false;
                this.m_webBrowserSh.Offline              = false;
                this.m_webBrowserSh.MenuBar              = false;
                this.m_webBrowserSh.RegisterAsBrowser    = false;
                this.m_webBrowserSh.RegisterAsDropTarget = false;
                this.m_webBrowserSh.AddressBar           = false;
            }
            catch
            {
            }

            this.ctlWebBrowser.Navigate("https://mobile.twitter.com/login?redirect_after_login=https%3A%2F%2Ftwitter.com%2F");

            this.ctlWebBrowser.LoadCompleted += this.CtlWebBrowser_LoadCompleted;
        }
Exemple #12
0
        private void GoUrl()
        {
            string url = this.txtUrl.Text;

            SHDocVw.WebBrowser wb = CreateNewWebBrowser();


            // Return if nowhere to go
            if (url == "")
            {
                return;
            }

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                Object o = null;
                wb.Navigate(url, ref o, ref o, ref o, ref o);
            }
            finally
            {
                int i = this.txtUrl.Items.IndexOf(url);
                if (i == -1)
                {
                    this.txtUrl.Items.Add(url);
                }

                Cursor.Current = Cursors.Default;
            }
        }
        public static void SetSilent(WebBrowser browser, bool silent, bool suppressNewWindow = false)
        {
            Native.IOleServiceProvider sp = browser.Document as Native.IOleServiceProvider;
            if (sp != null)
            {
                Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
                Guid IID_IWebBrowser2   = new Guid("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E");

                object webBrowser;
                sp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out webBrowser);
                if (webBrowser != null)
                {
                    webBrowser.GetType().InvokeMember("Silent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.PutDispProperty, null, webBrowser, new object[] { silent });
                }

                if (suppressNewWindow)
                {
                    Guid   iid = typeof(SHDocVw.WebBrowser).GUID;
                    object ppvObject;
                    sp.QueryService(ref IID_IWebBrowserApp, ref iid, out ppvObject);
                    SHDocVw.WebBrowser webBrowserPtr = ppvObject as SHDocVw.WebBrowser;
                    if (webBrowserPtr != null)
                    {
                        webBrowserPtr.NewWindow2 += WebBrowserPtr_NewWindow2;
                    }
                }
            }
        }
Exemple #14
0
 public void Connect(WebBrowser webBrowser)
 {
     this.webBrowser = webBrowser;
     this.webBrowser.BeforeNavigate2  += this.OnBeforeNavigate2;
     this.webBrowser.DocumentComplete += this.OnDocumentComplete;
     this.webBrowser.DownloadBegin    += this.OnDownloadBegin;
     this.webBrowser.DownloadComplete += this.OnDownloadEnd;
 }
Exemple #15
0
        public BbsSnifferForm()
        {
            InitializeComponent();

            wb = webBrowser.ActiveXInstance as SHDocVw.WebBrowser;
            wb.BeforeNavigate2  += new SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(wb_BeforeNavigate2);
            wb.DocumentComplete += new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(wb_DocumentComplete);
        }
 public void Disconnect(WebBrowser webBrowser)
 {
     this.webBrowser.BeforeNavigate2 -= this.OnBeforeNavigate2;
     this.webBrowser.DocumentComplete -= this.OnDocumentComplete;
     this.webBrowser.DownloadBegin -= this.OnDownloadBegin;
     this.webBrowser.DownloadComplete -= this.OnDownloadEnd;
     this.webBrowser = null;
 }
 public void Connect(WebBrowser webBrowser)
 {
     this.webBrowser = webBrowser;
     this.webBrowser.BeforeNavigate2 += this.OnBeforeNavigate2;
     this.webBrowser.DocumentComplete += this.OnDocumentComplete;
     this.webBrowser.DownloadBegin += this.OnDownloadBegin;
     this.webBrowser.DownloadComplete += this.OnDownloadEnd;
 }
Exemple #18
0
        public Main()
        {
            InitializeComponent();
            SHDocVw.WebBrowser popupHandle = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
            popupHandle.NewWindow3 += PopupHandle_NewWindow3;

            backgroundWorker1.RunWorkerAsync();
        }
Exemple #19
0
 public void Disconnect(WebBrowser webBrowser)
 {
     this.webBrowser.BeforeNavigate2  -= this.OnBeforeNavigate2;
     this.webBrowser.DocumentComplete -= this.OnDocumentComplete;
     this.webBrowser.DownloadBegin    -= this.OnDownloadBegin;
     this.webBrowser.DownloadComplete -= this.OnDownloadEnd;
     this.webBrowser = null;
 }
Exemple #20
0
 public FormErx()
 {
     InitializeComponent();
     Lan.F(this);
     SHDocVw.WebBrowser axBrowser = (SHDocVw.WebBrowser)browser.ActiveXInstance;
     //axBrowser.NewWindow2+=new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axBrowser_NewWindow2);
     axBrowser.NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axBrowser_NewWindow3);
 }
Exemple #21
0
 private void Inital()
 {
     wb.Url = uri;
     SHDocVw.WebBrowser wb1 = (SHDocVw.WebBrowser)wb.ActiveXInstance;
     wb1.BeforeNavigate2   += Wb1_BeforeNavigate2;
     wb1.NavigateComplete2 += Wb1_NavigateComplete2;
     wb.DocumentCompleted  += Wb_DocumentCompleted;
     wb.NewWindow          += Wb_NewWindow;
 }
Exemple #22
0
 public TYC_V2()
 {
     InitializeComponent();
     webBrowser1.ObjectForScripting     = this;
     webBrowser1.ScriptErrorsSuppressed = true;
     wb = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
     wb.BeforeScriptExecute        += Wb_BeforeScriptExecute;
     webBrowser1.DocumentCompleted += WebBrowser1_DocumentCompleted;
 }
Exemple #23
0
        public MainForm()
        {
            InitializeComponent();

            ax = (SHDocVw.WebBrowser)webBrowser.ActiveXInstance;

            ax.DocumentComplete += axDocumentComplete;
            ax.WindowClosing    += axWindowClosing;
        }
Exemple #24
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            web.ScriptErrorsSuppressed = true;
            web.Parent                = this;
            web.GotFocus             += Web_GotFocus;
            web.DocumentTitleChanged += Web_DocumentTitleChanged;

            SHDocVw.WebBrowser wbCOMmain = (SHDocVw.WebBrowser)web.ActiveXInstance;
            wbCOMmain.NewWindow3 += wbCOMmain_NewWindow3;
        }
Exemple #25
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (string.IsNullOrWhiteSpace(_url))
            {
                return;
            }

            nativeBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
            nativeBrowser.NewWindow2 += nativeBrowser_NewWindow2;
        }
Exemple #26
0
 ///<summary>Used when opening a new browser window via a link.</summary>
 public FormWebBrowser(string url = "")
 {
     InitializeComponent();
     Lan.F(this);
     _urlBrowseTo = url;
     SHDocVw.WebBrowser axBrowser = (SHDocVw.WebBrowser)browser.ActiveXInstance;
     if (axBrowser != null)           //This was null once during testing.  Not sure when null can happen.  Not sure if we should allow the user to continue.
     {
         axBrowser.NewWindow2 += axBrowser_NewWindow2;
         axBrowser.NewWindow3 += axBrowser_NewWindow3;
     }
     browser.DocumentTitleChanged += browser_DocumentTitleChanged;
 }
Exemple #27
0
        // https://stackoverflow.com/questions/15273311/how-to-invoke-scripts-work-in-mshtml
        public static void CallScript(SHDocVw.WebBrowser axWebBrowser)
        {
            //
            // Using C# dynamics, which maps to COM's IDispatch::GetIDsOfNames,
            // IDispatch::Invoke
            //


            //HtmlElement scriptJS = axWebBrowser.Document.CreateElement("script");
            //MSHTML.IHTMLScriptElement elementJS = (MSHTML.IHTMLScriptElement)scriptJS.DomElement;
            //elementJS.type = "text/javascript";
            //StreamReader streamReader = new StreamReader("TheFile.js");
            //elementJS.text = streamReader.ReadToEnd();
            //streamReader.Close();
            //webBrowser1.Document.Body.AppendChild(scriptJS);


            //mshtml.HTMLDocumentClass htmlDocument = axWebBrowser.Document;

            //var htmlWindow = (mshtml.IHTMLWindow2) htmlDocument.parentWindow;
            //mshtml.HTMLDocument hd = htmlDocument;

            ////htmlDocument.execsc

            ////// make sure the web page has at least one <script> tag for eval to work
            ////htmlDocument.body.appendChild(htmlDocument.createElement("script"));

            ////// can call any DOM window method
            ////htmlWindow.alert("hello from web page!");

            ////// call a global JavaScript function, e.g.:
            ////// <script>function TestFunc(arg) { alert(arg); }</script>
            ////htmlWindow.TestFunc("Hello again!");

            ////// call any JavaScript via "eval"
            //var result = (bool)htmlWindow.eval("(function() { return confirm('Continue?'); })()");
            //MessageBox.Show(result.ToString());

            //
            // Using .NET reflection:
            //

            object htmlWindowObject = GetProperty(axWebBrowser.Document, "parentWindow");

            // call a global JavaScript function
            InvokeScript(htmlWindowObject, "TestFunc", "Hello again!");

            //// call any JavaScript via "eval"
            //result = (bool)InvokeScript(htmlWindowObject, "eval", "(function() { return confirm('Continue?'); })()");
            //MessageBox.Show(result.ToString());
        }
Exemple #28
0
        public Form1(string url)
        {
            InitializeComponent();
            try
            {
                SetProxy.WinInetInterop.SetConnectionProxy(Properties.Settings.Default.Proxy.Trim());
                webBrowser1.IsWebBrowserContextMenuEnabled = Properties.Settings.Default.AllowContextMenu;
                webBrowser1.Navigate(url);
                webBrowser1.ScriptErrorsSuppressed = Properties.Settings.Default.NoScriptErrors;
                webBrowser1.AllowWebBrowserDrop    = Properties.Settings.Default.AllowDragDropPage;
                webBrowser1.ScrollBarsEnabled      = Properties.Settings.Default.EnableScrollBars;

                this.Text = Properties.Settings.Default.Title;


                activeBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
                (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(Form1_NewWindow3);
                activeBrowser.StatusTextChange += activeBrowser_StatusTextChange;

                if (Properties.Settings.Default.StartMaximized)
                {
                    this.WindowState = FormWindowState.Maximized;
                }
                this.Height = Properties.Settings.Default.StartHeight;
                this.Width  = Properties.Settings.Default.StartWidth;

                if (!Properties.Settings.Default.ShowToolBar)
                {
                    toolStrip1.Visible = false;
                }
                if (Properties.Settings.Default.ReadOnlyAddressBar)
                {
                    toolStripTextBox1.ReadOnly = true;
                }

                toolStripButton1.Visible = Properties.Settings.Default.ShowBack;
                toolStripButton2.Visible = Properties.Settings.Default.ShowForward;
                toolStripButton3.Visible = Properties.Settings.Default.ShowHome;
                toolStripButton4.Visible = Properties.Settings.Default.ShowRefresh;
                toolStripButton5.Visible = Properties.Settings.Default.ShowSave;
                toolStripButton6.Visible = Properties.Settings.Default.ShowPrint;
                toolStripButton7.Visible = Properties.Settings.Default.ShowFind;
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Error: {0}", ex.Message),
                                "Browser",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Exemple #29
0
        private HTMLDocument GetDocument()
        {
            try
            {
                SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)((System.Windows.Forms.WebBrowser) this.WebBrowserTab.TabPages[0].Controls[0]).ActiveXInstance;

                HTMLDocument htm = (HTMLDocument)wb.Document;
                return(htm);
            }
            catch (System.Exception ex)
            {
                throw (ex);
            }
        }
Exemple #30
0
        private void wb_DocumentComplete(object pDisp, ref object URL)
        {
            SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)((System.Windows.Forms.WebBrowser) this.WebBrowserTab.TabPages[0].Controls[0]).ActiveXInstance;

            if (wb.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
            {
                this.txtUrl.Text = wb.LocationURL;


                this.toolStripProgressBar1.Value   = 0;
                this.toolStripProgressBar1.Visible = false;
            }

            this.textBox1.Text = ((System.Windows.Forms.WebBrowser) this.WebBrowserTab.TabPages[0].Controls[0]).Document.Cookie.ToString();
        }
Exemple #31
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.HandleCreated"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
        /// <exception cref="T:System.Threading.ThreadStateException">
        /// The <see cref="P:System.Threading.Thread.ApartmentState"/> property of the application is not set to <see cref="F:System.Threading.ApartmentState.STA"/>.
        /// </exception>
        /// <remarks>Documented by Dev02, 2009-08-10</remarks>
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);

            if (this.ActiveXInstance == null)
            {
                Trace.WriteLine(String.Format("Could not attach NewWindow event to webbrowser {0} because ActiveX instance is null.", this.Name));
                return;
            }

            //native com component access is necessary because the managed webbrowser wrapper does not provide the url for the newwindow event
            //code from: http://windowsteamblog.com/blogs/developers/archive/2009/07/12/windows-7-e-best-practices-for-isvs.aspx
            SHDocVw.WebBrowser webBrowser = (SHDocVw.WebBrowser) this.ActiveXInstance;
            webBrowser.NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(webBrowser_NewWindow3);
        }
 public WebBrowserCore()
 {
     ScriptErrorsSuppressed = true;
     if (Properties.Settings.Default.UseProxy == true)
     {
         WinInetInterop.RefreshIESettings(Properties.Settings.Default.Proxy);
     }
     else
     {
         WinInetInterop.RefreshIESettings(":");
     }
     UrlMonInterop.ChangeUserAgent("Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko");
     IsWebBrowserContextMenuEnabled = false;
     xBrowser = (SHDocVw.WebBrowser)ActiveXInstance;
 }
            public int SetSite(object site)
            {
                // If the site is valid, cast as a WebBrowser object and
                // store it in the Browser variable
                if (site != null)
                {
                    Browser = (SHDocVw.WebBrowser)site;
                }
                else
                {
                    Browser = null;
                }

                //  Return S_OK
                return(S_OK);
            }
Exemple #34
0
        private void btn_ListenHTML_Click(object sender, EventArgs e)
        {
            p = new IEProxy(txt_Proxy.Text+":"+txt_ProxyPort.Text);

            wb = (SHDocVw.WebBrowser)webBrower1.ActiveXInstance;
            wb.BeforeNavigate2 += new SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(WebBrowser_BeforeNavigate2);

            HtmlDocument htmlDoc = webBrower1.Document;
            htmlDoc.MouseOver += new HtmlElementEventHandler(HtmlDocument1_MouseOver);
            webBrower1.ScriptErrorsSuppressed = true;

            btn_localBrowser.Enabled = true;
            btn_ProxyBrowser.Enabled = true;
            btn_IE.Enabled = true;
            btn_Chrome.Enabled = true;
            btn_Foxfire.Enabled = true;
            btn_ListenHTML.Enabled = false;
        }
        public FormMain(String[] args)
        {
            InitializeComponent();

            mainTitle = "";
            mainUrl = "http://www.imdb.com/";
            userAgent = "";
            minMouseSpeed = 10;
            maxMouseSpeed = 10;
            userDataFolder = "";
            zoom = 100;
            magnifierWidth = 1280;
            magnifierHeigth = 720;
            magnifierZoom = 3;
            showPopups = false;
            showScrollBar = true;
            useCustomCursor = true;
            customCursorSize = 64;
            mouseEnabled = true;
            scrollSpeed = 20;

            if (args.Length > 0)
            {
                userDataFolder = args[0].Replace("\"", "");
                mainTitle = args[1].Replace("\"", "");
                mainUrl = Uri.UnescapeDataString(args[2]);
                zoom = Convert.ToInt32(args[3]);
                showPopups = (args[4] == "yes");
                minMouseSpeed = Convert.ToInt32(args[5]);
                maxMouseSpeed = Convert.ToInt32(args[6]);
                String[] spl = args[7].Split('x');
                magnifierWidth = Convert.ToInt32(spl[0]);
                magnifierHeigth = Convert.ToInt32(spl[1]);
                useCustomCursor = (args[8] == "true");
                customCursorSize = Convert.ToInt32(args[9]);
                showScrollBar = (args[10] == "yes");
                scrollSpeed = Convert.ToInt32(args[11]);
                userAgent = args[12].Replace("\"", "");
            }

            //When using Windows
            String file = userDataFolder + "\\keymap";
            String file2 = "C:\\xbmc_webbrowser\\keymap";
            if (File.Exists(file))
            {
                importKeymap(file);
            }
            //When using Wine
            else if (File.Exists(file2))
            {
                importKeymap(file2);
            }
            //Default key mapping
            else
            {
                keyMapUp = "NumPad8";
                keyMapDown = "NumPad2";
                keyMapLeft = "NumPad4";
                keyMapRight = "NumPad6";
                keyMapUpLeft = "NumPad7";
                keyMapUpRight = "NumPad9";
                keyMapDownLeft = "NumPad1";
                keyMapDownRight = "NumPad3";
                keyMapToggleMouse = "Multiply";
                keyMapClick = "NumPad5";
                keyMapZoomIn = "Add";
                keyMapZoomOut = "Subtract";
                keyMapContextMenu = "Divide";
                keyMapClose = "NumPad0";
                keyMapMagnifier = "";
                keyMapFavourites = "";
                keyMapShortCuts = "";
                keyMapNavigate = "";
                keyMapDoubleClick = "";
                keyMapKeyboard = "";
                keyMapTAB = "";
                keyMapESC = "";
                keyMapF5 = "";
            }
            allKeys = new ArrayList();
            allKeys.Add(keyMapUp);
            allKeys.Add(keyMapDown);
            allKeys.Add(keyMapLeft);
            allKeys.Add(keyMapRight);
            allKeys.Add(keyMapUpLeft);
            allKeys.Add(keyMapUpRight);
            allKeys.Add(keyMapDownLeft);
            allKeys.Add(keyMapDownRight);
            allKeys.Add(keyMapClose);
            allKeys.Add(keyMapMagnifier);
            allKeys.Add(keyMapNavigate);
            allKeys.Add(keyMapZoomIn);
            allKeys.Add(keyMapZoomOut);
            allKeys.Add(keyMapClick);
            allKeys.Add(keyMapDoubleClick);
            allKeys.Add(keyMapKeyboard);
            allKeys.Add(keyMapFavourites);
            allKeys.Add(keyMapShortCuts);
            allKeys.Add(keyMapTAB);
            allKeys.Add(keyMapESC);
            allKeys.Add(keyMapToggleMouse);
            allKeys.Add(keyMapContextMenu);
            allKeys.Add(keyMapF5);

            formZoom = null;
            formPopup = null;
            formKeyboardNavi = null;
            formKeyboardSearch = null;
            formFavourites = null;
            formShortcuts = null;
            formContextMenu = null;

            lastMousePositionChange = 0;
            acceleration = minMouseSpeed;
            this.Size = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            webBrowser1.ScrollBarsEnabled = showScrollBar;
            if (useCustomCursor)
            {
                Cursor.Hide();
                formCursor = new FormCursor();
                String cursorPath = userDataFolder + "\\cursor.png";
                Bitmap oImage = null;
                if (File.Exists(cursorPath))
                {
                    oImage = new Bitmap(cursorPath);
                }
                else
                {
                    oImage = new Bitmap(XBMC_WebBrowser.Properties.Resources.cursorBlue);
                }
                formCursor.BackgroundImage = oImage;
                formCursor.MinimumSize = new System.Drawing.Size(32, 32);
                formCursor.Size = new System.Drawing.Size(customCursorSize, customCursorSize);
                formCursor.Location = new Point(Cursor.Position.X + 1, Cursor.Position.Y + 1);
                formCursor.Show();
            }
            if (userAgent=="")
                webBrowser1.Navigate(mainUrl);
            else
                webBrowser1.Navigate(mainUrl, null, null, "User-Agent: " + userAgent);
            nativeBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
            nativeBrowser.NewWindow2 += nativeBrowser_NewWindow2;
            webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
            mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
        }
Exemple #36
0
        public int SetSite(object site)
        {
            try
            {
                this.webBrowser = site as WebBrowser;

                if (this.webBrowser != null)
                {
                    eventSink = new WebBrowserEventSink(this.TryFillCredentials, this.TryFillCredentials);
                    eventSink.Connect(this.webBrowser);
                }
                else
                {
                    eventSink.Disconnect(this.webBrowser);
                }
            }
            catch (COMException ex)
            {
                Logger.Instance.LogError("Exception caught: {0}", ex.Message);
            }

            return 0;
        }
Exemple #37
0
        public Form1(string url)
        {   InitializeComponent();
        try
        {
            SetProxy.WinInetInterop.SetConnectionProxy(Properties.Settings.Default.Proxy.Trim());
            webBrowser1.IsWebBrowserContextMenuEnabled = Properties.Settings.Default.AllowContextMenu;
            webBrowser1.Navigate(url);
            webBrowser1.ScriptErrorsSuppressed = Properties.Settings.Default.NoScriptErrors;
            webBrowser1.AllowWebBrowserDrop = Properties.Settings.Default.AllowDragDropPage;
            webBrowser1.ScrollBarsEnabled = Properties.Settings.Default.EnableScrollBars;

            this.Text = Properties.Settings.Default.Title;


            activeBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
            (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(Form1_NewWindow3);
            activeBrowser.StatusTextChange += activeBrowser_StatusTextChange;

            if (Properties.Settings.Default.StartMaximized) this.WindowState = FormWindowState.Maximized;
            this.Height = Properties.Settings.Default.StartHeight;
            this.Width = Properties.Settings.Default.StartWidth;

            if (!Properties.Settings.Default.ShowToolBar) toolStrip1.Visible = false;
            if (Properties.Settings.Default.ReadOnlyAddressBar) toolStripTextBox1.ReadOnly = true;

            toolStripButton1.Visible = Properties.Settings.Default.ShowBack;
            toolStripButton2.Visible = Properties.Settings.Default.ShowForward;
            toolStripButton3.Visible = Properties.Settings.Default.ShowHome;
            toolStripButton4.Visible = Properties.Settings.Default.ShowRefresh;
            toolStripButton5.Visible = Properties.Settings.Default.ShowSave;
            toolStripButton6.Visible = Properties.Settings.Default.ShowPrint;
            toolStripButton7.Visible = Properties.Settings.Default.ShowFind;
         
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Error: {0}", ex.Message),
                    "Browser",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            
        }
 private void service_Click(object sender, RoutedEventArgs e)
 {
     Objects.UIService service = sender as Objects.UIService;
     if (service.Service.Registered)
     {
         ShowSettings(service);
     }
     else
     {
         _service = service;
         if (service.Service.RequireOAuth)
         {
             _pinPanel = new Popups.UIPinPanel(_service.Service.Image, _service.Service.OAuthVersion);
             _pinPanel.Ok.Click += PinPanelOk;
             _pinPanel.Cancel.Click += PinPanelCancel;
             UIController.ShowPanel(_pinPanel);
             _browser = service.Subscribe();
             if (_service.Service.OAuthVersion == 2)
                 _browser.DocumentComplete += browser_DocumentComplete;
         }
         else if (service.Service.RequireTFSAuthentication)
         {
             _tfsLoginPanel = new Popups.UITFSLogin(_service.Service.Image, _service.Service.RequireTFSDomain);
             _tfsLoginPanel.Ok.Click += TFSLoginOk;
             _tfsLoginPanel.Cancel.Click += TFSLoginCancel;
             UIController.ShowPanel(_tfsLoginPanel);
         }
     }
 }
Exemple #39
0
 private void InitWebBrowser()
 {
     //Init the WebBrowser
     webBrowser1.ScrollBarsEnabled = showScrollBar;
     webBrowser1.ScriptErrorsSuppressed = supressScriptWarnings;
     webBrowser1.IsWebBrowserContextMenuEnabled = false;
     //Navigate to 1st URL
     navigate(mainUrl);
     //Getting natvie webbrowser (ActiveX control) and safe for usage
     nativeBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
     nativeBrowser.NewWindow2 += nativeBrowser_NewWindow2;
     //webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
 }