Awesomium-displaying the current url

using Awesomium.Core;
using Awesomium.Windows.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication13
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            WebSession session = WebCore.CreateWebSession(new WebPreferences()
            {
               ProxyConfig = "socks4://52.52.109.113:1080"
             });
            var webControl = new WebControl();
            webControl.WebSession = session;
            panel1.Controls.Add(webControl);
            webControl.Size = new Size(700, 700);
            webControl.Location = new Point(10, 10);
            webControl.Source = new Uri("http://2ip.ru");
        }
    }
}

How do I show the site address after loading the link, taking into account JS redirects? Let's say that each redirect displays a link in textBox.

Author: 0xdb, 2016-10-30

1 answers

1) Can be used in the slender control AddressBox. Move it from the "Toolbar" to the form and set your WebControl in the AddressBox.WebControl property.

2) You can use Data Binding. To do this, you need to transfer 1 WebControl and one TextBox to the form. Next, click "F7" to go to CodeBehind and after InitializeComponent(); specify the following

Binding bind = new Binding("Text", webControl1, "Source", true);
bind.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;           
textBox1.DataBindings.Add(bind);

3)There is also an option to intercept any requests WebControl and decide for yourself what to do with them. To do this, you need to implement the interface IResourceInterceptor

public class ManagerRequest : IResourceInterceptor
{
    public bool OnFilterNavigation(NavigationRequest request)
    {
        return false;
    }
    public ResourceResponse OnRequest(ResourceRequest request)
    {
        //в url и будет храниться адрес текущего запроса,
        //в том числе и загрузка Css/Js
        var url=request.Url.AbsoluteUri;          
        return null;
    }
}

To make all this work, you need to set our implementation after loading the kernel. subscribe to the kernel loading events in the form upload. After InitializeComponent();, write WebCore.Initialized += WebCore_Initialized; and add the

private void WebCore_Initialized(object sender, CoreStartEventArgs e)
{
   Awesomium.Core.WebCore.ResourceInterceptor = new ManagerRequest();
}
 1
Author: 123_123, 2016-10-31 01:00:51