149 lines
4.6 KiB
C#
149 lines
4.6 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
using AllBase;
|
|
using CefSharp;
|
|
using CefSharp.WinForms;
|
|
using DevComponents.DotNetBar;
|
|
using TemuKJD.BaseForms;
|
|
using NaiBa.CefHelper;
|
|
|
|
namespace TemuKJD.KJDForms.ToolForms
|
|
{
|
|
public partial class IeForm : LRBaseForm
|
|
{
|
|
public string Url { get; set; }
|
|
public ChromiumWebBrowser cefWebBrowser;
|
|
public static IeForm ieFormInstance = null;
|
|
|
|
public IeForm()
|
|
{
|
|
InitializeComponent();
|
|
|
|
if (ieFormInstance != null && ieFormInstance.Created)
|
|
{
|
|
ieFormInstance.Close();
|
|
ieFormInstance.Dispose();
|
|
}
|
|
ieFormInstance = this;
|
|
}
|
|
|
|
public IeForm(string _url)
|
|
{
|
|
Url = _url;
|
|
InitializeComponent();
|
|
|
|
if (ieFormInstance != null && ieFormInstance.Created)
|
|
{
|
|
ieFormInstance.Close();
|
|
ieFormInstance.Dispose();
|
|
}
|
|
ieFormInstance = this;
|
|
}
|
|
|
|
private void IeForm_Load(object sender, EventArgs e)
|
|
{
|
|
if (BaseClass.Ico != null)
|
|
Iconx = Icon = BaseClass.Ico;
|
|
if (string.IsNullOrEmpty(Url))
|
|
{
|
|
Url = "https://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&redirectURL=https://i.taobao.com/my_taobao.htm";
|
|
this.Width = 401;
|
|
this.Height = 428;
|
|
}
|
|
else
|
|
{
|
|
Location = new Point(330, 220);
|
|
TitleText = Text = "账号登录";
|
|
this.Width = 1250;
|
|
this.Height = 686;
|
|
}
|
|
|
|
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(Url);
|
|
cefWebBrowser.AutoSize = true;
|
|
cefWebBrowser.Dock = DockStyle.Fill;
|
|
//cefWebBrowser.RequestContext = new RequestContext(requestContextSettings);
|
|
cefWebBrowser.KeyboardHandler = new CefKeyboardHandler();
|
|
cefWebBrowser.FrameLoadEnd += CefWebBrowser_FrameLoadEnd;
|
|
panel2.Controls.Add(cefWebBrowser);
|
|
|
|
TitleText = BaseClass.ToolName;
|
|
|
|
cefWebBrowser.AddressChanged += CefWebBrowser_AddressChanged;
|
|
}
|
|
|
|
private void CefWebBrowser_AddressChanged(object sender, AddressChangedEventArgs e)
|
|
{
|
|
var url = e.Address;
|
|
Invoke(new Action(() =>
|
|
{
|
|
txtUrl.Text = url;
|
|
}));
|
|
}
|
|
|
|
private void CefWebBrowser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
|
|
{
|
|
if (!cefWebBrowser.IsBrowserInitialized) return;
|
|
|
|
ChromeCookiesTaoBao = GetCookies();
|
|
ChromeCookies1688 = GetCookies("1688.com");
|
|
}
|
|
|
|
public string GetCookies(string domain = "taobao.com")
|
|
{
|
|
if (cefWebBrowser != null)
|
|
{
|
|
var cookie = CEFBrowser.GetCookie(domain);
|
|
return cookie;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
private void btnGoTo_Click(object sender, EventArgs e)
|
|
{
|
|
var cookies = this.GetCookies();
|
|
}
|
|
|
|
public static string ChromeCookiesTaoBao { get; set; }
|
|
public static string ChromeCookies1688 { get; set; }
|
|
}
|
|
|
|
internal class CefKeyboardHandler : IKeyboardHandler
|
|
{
|
|
public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
|
|
{
|
|
if (type == KeyType.KeyUp && Enum.IsDefined(typeof(Keys), windowsKeyCode))
|
|
{
|
|
var key = (Keys)windowsKeyCode;
|
|
switch (key)
|
|
{
|
|
case Keys.F12:
|
|
browser.ShowDevTools();
|
|
break;
|
|
|
|
case Keys.F5:
|
|
|
|
if (modifiers == CefEventFlags.ControlDown)
|
|
{
|
|
//MessageBox.Show("ctrl+f5");
|
|
browser.Reload(true); //强制忽略缓存
|
|
}
|
|
else
|
|
{
|
|
//MessageBox.Show("f5");
|
|
browser.Reload();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|