private void LoadHistory() { totalHistory = Helper.ReadFromJsonFile <List <BrowserHistory> >("history.txt"); //In case of no file if (totalHistory == null) { totalHistory = new List <BrowserHistory>(); } else { //Every tab is saved in totalHistory foreach (var item in totalHistory) { CustomTab tab = new CustomTab(); tab.Text = item.Urls[item.currentIndex]; tab.textbox.Text = GetHTML(tab.Text, tab); tab.history = item; //Multi threading //BrowserThread bthread = new BrowserThread(tab); //Thread thread = new Thread(new ThreadStart(bthread.Start)); //thread.Start(); //Adding Pages to control tabControl.TabPages.Add(tab); tabControl.SelectTab(tabControl.TabPages.Count - 1); } //Update current window history RefreshHistoryList(GetCurrentTab()); } }
private void button1_Click(object sender, EventArgs e) { //next button CustomTab tab = GetCurrentTab(); if (tab.history.currentIndex + 1 <= tab.history.Urls.Count) { tab.history.currentIndex++; LoadPage(tab.history.Urls[tab.history.currentIndex], tab); } }
private void btnBack_Click(object sender, EventArgs e) { //back button CustomTab tab = GetCurrentTab(); if (tab.history.currentIndex - 1 >= 0) { tab.history.currentIndex--; LoadPage(tab.history.Urls[tab.history.currentIndex], tab); } }
private void AddToHistoryView(string url, CustomTab tab) { //Add url to tab history if (tabControl.TabIndex != -1) { tab.history.Urls.Add(url); //Refresh the history menu RefreshHistoryList(tab); SaveHistory(); } }
private void RefreshHistoryList(CustomTab tab) { if (tab != null) { //clear menu history historyToolStripMenuItem.DropDownItems.Clear(); //add history from tab container foreach (var item in tab.history.Urls) { ToolStripItem subItem = new ToolStripMenuItem(item); subItem.Click += SubItem_Click; historyToolStripMenuItem.DropDownItems.Add(subItem); } } }
public void LoadPage(string url, CustomTab tab) { //In case if this is a new tab if (tab == null) { tab = new CustomTab(); tab.Text = url; tab.textbox.Text = GetHTML(url, tab); tabControl.TabPages.Add(tab); tabControl.SelectTab(tabControl.TabPages.Count - 1); } //Open in the current tab else { tab.Text = url; tab.textbox.Text = GetHTML(url, tab); } }
public BrowserThread(CustomTab tab) { this.tab = tab; }
public string GetHTML(string url, CustomTab tab) { //Add to menu history AddToHistoryView(url, tab); string result = ""; if (!url.Contains("http://")) { url = "http://" + url; } else if (!url.Contains("https://")) { url = "https://" + url; } try { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.CookieContainer = cookie; req.Method = "GET"; req.KeepAlive = true; req.ContentLength = 0; req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36"; req.ContentType = "application/x-www-form-urlencoded"; req.Accept = "*/*"; string s; HttpWebResponse webResp = (HttpWebResponse)req.GetResponse(); Stream datastream = webResp.GetResponseStream(); StreamReader reader = new StreamReader(datastream); s = reader.ReadToEnd(); result += s; } catch (WebException e) { using (WebResponse response = e.Response) { if (response != null) { HttpWebResponse httpResponse = (HttpWebResponse)response; result += "Error code: " + (int)httpResponse.StatusCode + " " + httpResponse.StatusCode.ToString() + Environment.NewLine; using (Stream data = response.GetResponseStream()) using (var reader = new StreamReader(data)) { string text = reader.ReadToEnd(); result += text + Environment.NewLine; } } else { result += "Error :" + e.Message + Environment.NewLine; } } } return(result); }