init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Data.SQLite;
|
||||
using System.IO;
|
||||
|
||||
namespace Sashulin
|
||||
{
|
||||
class CacheDB
|
||||
{
|
||||
SQLiteConnection conn = null;
|
||||
public CacheDB()
|
||||
{
|
||||
conn = new SQLiteConnection();
|
||||
}
|
||||
|
||||
public void Connect(string dbName)
|
||||
{
|
||||
Close();
|
||||
string datasource = System.IO.Directory.GetCurrentDirectory() + "\\" +dbName + ".db";
|
||||
if (!File.Exists(datasource))
|
||||
SQLiteConnection.CreateFile(datasource);
|
||||
SQLiteConnectionStringBuilder connStrBuilder = new SQLiteConnectionStringBuilder();
|
||||
connStrBuilder.DataSource = datasource;
|
||||
conn.ConnectionString = connStrBuilder.ToString();
|
||||
conn.Open();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (conn.State == System.Data.ConnectionState.Open)
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
public int Execute(string commandText)
|
||||
{
|
||||
int res = 0;
|
||||
using (SQLiteCommand cmd = new SQLiteCommand(commandText, conn))
|
||||
{
|
||||
try
|
||||
{
|
||||
res = cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show(e.Message);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public string Query(string commandText)
|
||||
{
|
||||
string res = string.Empty;
|
||||
using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(commandText, conn))
|
||||
{
|
||||
DataTable table = new DataTable();
|
||||
adapter.Fill(table);
|
||||
string tableName = "rows";
|
||||
int columnCount = table.Columns.Count;
|
||||
int rowcount = table.Rows.Count;
|
||||
string record = "[";
|
||||
foreach(DataRow row in table.Rows)
|
||||
{
|
||||
record += "{";
|
||||
foreach (DataColumn col in table.Columns)
|
||||
{
|
||||
record += "\""+col.ColumnName+"\":\""+row[col].ToString()+"\"";
|
||||
if (col != table.Columns[columnCount - 1])
|
||||
{
|
||||
record += ",";
|
||||
}
|
||||
}
|
||||
record += "}";
|
||||
if (row != table.Rows[rowcount - 1])
|
||||
{
|
||||
record += ",";
|
||||
}
|
||||
}
|
||||
record += "]";
|
||||
res = "{\"" + tableName + "\":" + record + "}";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+46
@@ -0,0 +1,46 @@
|
||||
namespace Sashulin
|
||||
{
|
||||
partial class ChromeWebBrowser
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
// System.Environment.Exit(0);
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// ChromeWebBrowser
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.SystemColors.ActiveBorder;
|
||||
this.Name = "ChromeWebBrowser";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,865 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Diagnostics;
|
||||
using Cef3;
|
||||
using Cef3.Wrapper;
|
||||
using Sashulin.common;
|
||||
using Sashulin.Core;
|
||||
|
||||
namespace Sashulin
|
||||
{
|
||||
public partial class ChromeWebBrowser: UserControl
|
||||
{
|
||||
private const string DumpRequestDomain = "dump-request.app.cefglue.sashulin.local";//"dump-request.clientapp.cefglue.sashulin.local";
|
||||
private CefClient client;
|
||||
private bool created = false;
|
||||
private static bool initialized = false;
|
||||
private string _homeUrl = "about:blank";
|
||||
private IntPtr browserHandle;
|
||||
private string cookiePath = "/";
|
||||
private CacheDB _cachedb = new CacheDB();
|
||||
private string _title = string.Empty;
|
||||
private string _url = string.Empty;
|
||||
private CSharpBrowserSettings browserSettings = new CSharpBrowserSettings();
|
||||
private CwbDocument _document = null;
|
||||
internal CefBrowser browser;
|
||||
internal CefRequest selfRequest;
|
||||
internal int screenWidth = 0;
|
||||
internal int screenHeight = 0;
|
||||
internal bool menuVisible = false;
|
||||
|
||||
public ChromeWebBrowser()
|
||||
{
|
||||
InitializeComponent();
|
||||
Global.instance = this;
|
||||
}
|
||||
|
||||
public ChromeWebBrowser(CSharpBrowserSettings settings) : this()
|
||||
{
|
||||
browserSettings = settings;
|
||||
Initialize();
|
||||
}
|
||||
|
||||
private void CreateBrowser()
|
||||
{
|
||||
CefWindowInfo windowInfo = CefWindowInfo.Create();
|
||||
windowInfo.SetAsChild(Handle, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height });
|
||||
if (client == null)
|
||||
{
|
||||
client = new ClientBrowser(this);
|
||||
}
|
||||
var settings = new CefBrowserSettings() { };
|
||||
settings.ApplicationCache = CefState.Enabled;
|
||||
settings.CaretBrowsing = CefState.Enabled;
|
||||
settings.Databases = CefState.Enabled;
|
||||
settings.FileAccessFromFileUrls = CefState.Enabled;
|
||||
settings.ImageLoading = CefState.Enabled;
|
||||
settings.ImageShrinkStandaloneToFit = CefState.Enabled;
|
||||
settings.Java = CefState.Enabled;
|
||||
settings.JavaScript = CefState.Enabled;
|
||||
settings.JavaScriptAccessClipboard = CefState.Enabled;
|
||||
settings.JavaScriptCloseWindows = CefState.Enabled;
|
||||
settings.JavaScriptDomPaste = CefState.Enabled; ;
|
||||
settings.JavaScriptOpenWindows = CefState.Enabled;
|
||||
settings.LocalStorage = CefState.Enabled; ;
|
||||
settings.Plugins = CefState.Enabled ;
|
||||
settings.RemoteFonts = CefState.Enabled;
|
||||
settings.TabToLinks = CefState.Enabled; ;
|
||||
settings.TextAreaResize = CefState.Enabled;
|
||||
settings.UniversalAccessFromFileUrls = CefState.Enabled;
|
||||
settings.WebGL = CefState.Enabled;
|
||||
settings.WebSecurity = CefState.Enabled;
|
||||
CefBrowserHost.CreateBrowser(windowInfo, client, settings, browserSettings.DefaultUrl);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int Initialize(CSharpBrowserSettings settings)
|
||||
{
|
||||
browserSettings = settings;
|
||||
int ret = Initialize();
|
||||
//load Plugins
|
||||
AddPluginDir(@"\Plugins");
|
||||
this.AddPluginPath(@"\PepperFlash\pepflashplayer.dll");
|
||||
this.AddPluginPath(@"\Plugins\NPSWF32_17_0_0_169.dll");
|
||||
return ret;
|
||||
}
|
||||
public static CefMessageRouterBrowserSide BrowserMessageRouter { get; private set; }
|
||||
public int Initialize()
|
||||
{
|
||||
if (initialized)
|
||||
{
|
||||
if (!created)
|
||||
{
|
||||
CreateBrowser();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
CefRuntime.Load();
|
||||
var settings = new CefSettings();
|
||||
settings.MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows;
|
||||
settings.SingleProcess = true;
|
||||
settings.PersistSessionCookies = true;
|
||||
settings.CommandLineArgsDisabled = false;
|
||||
settings.ContextSafetyImplementation = CefContextSafetyImplementation.SafeDefault;
|
||||
settings.IgnoreCertificateErrors = true;
|
||||
settings.ResourcesDirPath = "/res";
|
||||
settings.PackLoadingDisabled = false;
|
||||
settings.LogSeverity = CefLogSeverity.Disable;
|
||||
settings.LogFile = "cef.log";
|
||||
settings.ResourcesDirPath = System.IO.Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath);
|
||||
settings.RemoteDebuggingPort = 9000;
|
||||
settings.UserAgent = browserSettings.UserAgent;
|
||||
settings.Locale = browserSettings.Locale;
|
||||
settings.LocalesDirPath = browserSettings.LocaleDirPath;
|
||||
settings.CachePath = browserSettings.CachePath;
|
||||
settings.ContextSafetyImplementation = CefContextSafetyImplementation.SafeDefault;
|
||||
settings.Locale = "zh-CN";
|
||||
settings.WindowlessRenderingEnabled = true;
|
||||
settings.NoSandbox = true;
|
||||
|
||||
var args = new string[] { };
|
||||
var argv = args;
|
||||
if (CefRuntime.Platform != CefRuntimePlatform.Windows)
|
||||
{
|
||||
argv = new string[args.Length + 1];
|
||||
Array.Copy(args, 0, argv, 1, args.Length);
|
||||
argv[0] = "-";
|
||||
}
|
||||
|
||||
var mainArgs = new CefMainArgs(argv);
|
||||
Global.app = new ClientApp();
|
||||
Global.app.SetBrowserControl(Global.instance);
|
||||
|
||||
var exitCode = CefRuntime.ExecuteProcess(mainArgs, Global.app, IntPtr.Zero);
|
||||
Console.WriteLine("CefRuntime.ExecuteProcess() returns {0}", exitCode);
|
||||
if (exitCode != -1)
|
||||
return exitCode;
|
||||
|
||||
foreach (var arg in args) { if (arg.StartsWith("--type=")) { return -2; } }
|
||||
CefRuntime.Initialize(mainArgs, settings, Global.app, IntPtr.Zero);
|
||||
CefRuntime.RegisterSchemeHandlerFactory("http", DumpRequestDomain, new AppSchemeHandlerFactory());
|
||||
//bool b = CefRuntime.AddCrossOriginWhitelistEntry("http://localhost", "http", "", true);
|
||||
|
||||
RegisterMessageRouter();
|
||||
CreateBrowser();
|
||||
initialized = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void RegisterMessageRouter()
|
||||
{
|
||||
if (!CefRuntime.CurrentlyOn(CefThreadId.UI))
|
||||
{
|
||||
PostTask(CefThreadId.UI, this.RegisterMessageRouter);
|
||||
return;
|
||||
}
|
||||
|
||||
// window.cefQuery({ request: 'my_request', onSuccess: function(response) { console.log(response); }, onFailure: function(err,msg) { console.log(err, msg); } });
|
||||
BrowserMessageRouter = new CefMessageRouterBrowserSide(new CefMessageRouterConfig());
|
||||
BrowserMessageRouter.AddHandler(new CefMessageRouterBrowserSide.Handler());
|
||||
}
|
||||
|
||||
public static void PostTask(CefThreadId threadId, Action action)
|
||||
{
|
||||
CefRuntime.PostTask(threadId, new ActionTask(action));
|
||||
}
|
||||
|
||||
internal sealed class ActionTask : CefTask
|
||||
{
|
||||
public Action _action;
|
||||
|
||||
public ActionTask(Action action)
|
||||
{
|
||||
_action = action;
|
||||
}
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
_action();
|
||||
_action = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Free()
|
||||
{
|
||||
CefRuntime.Shutdown();
|
||||
}
|
||||
|
||||
private void ResizeWindow(IntPtr handle, int width, int height)
|
||||
{
|
||||
if (handle != IntPtr.Zero)
|
||||
{
|
||||
WinApi.SetWindowPos(handle, IntPtr.Zero,
|
||||
0, 0, width, height,
|
||||
SetWindowPosFlags.NoZOrder
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#region chromewebbrowser methods
|
||||
public void OpenUrl(string Url)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (created) break;
|
||||
Application.DoEvents();
|
||||
}
|
||||
if (browser != null)
|
||||
{
|
||||
OnNavigating();
|
||||
|
||||
CefCookie cookie = new CefCookie();
|
||||
cookie.Name = "cwberCookieName";
|
||||
cookie.Value = "cwberCookie";
|
||||
cookie.Domain = "cwberCookieDomain";
|
||||
cookie.Path = cookiePath;
|
||||
cookie.Secure = false;
|
||||
cookie.HttpOnly = false;
|
||||
cookie.Expires = DateTime.Now;
|
||||
cookie.Creation = DateTime.Now;
|
||||
CefRuntime.PostTask(CefThreadId.IO, new CwbCookieTask(Url, cookie));
|
||||
browser.GetMainFrame().LoadUrl(Url);
|
||||
OnNavigated();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenUrl(object request)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (created) break;
|
||||
Application.DoEvents();
|
||||
}
|
||||
if (browser != null)
|
||||
{
|
||||
OnNavigating();
|
||||
|
||||
|
||||
//browser.GetMainFrame().LoadUrl(((CefRequest)request).Url);
|
||||
browser.GetMainFrame().LoadRequest((CefRequest)request);
|
||||
//browser.Reload();
|
||||
//browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("LoadRequest"));
|
||||
OnNavigated();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCookiePath(string path)
|
||||
{
|
||||
cookiePath = path;
|
||||
CefCookieManager.GetGlobal(null).SetStoragePath(path, true,null);
|
||||
}
|
||||
|
||||
public void DeleteAllCookies()
|
||||
{
|
||||
CwbCookieVisitor visitor = new CwbCookieVisitor(CwbCookieStyle.csDeleteAllCookie, _document);
|
||||
CefCookieManager.GetGlobal(null).VisitAllCookies(visitor);
|
||||
}
|
||||
|
||||
public void DeleteCookie(string url, string cookieName)
|
||||
{
|
||||
CefCookieManager.GetGlobal(null).DeleteCookies(url, cookieName,null);
|
||||
}
|
||||
|
||||
public void DeleteCookie(string cookieName)
|
||||
{
|
||||
CefCookieManager.GetGlobal(null).DeleteCookies(browser.GetMainFrame().Url, cookieName,null);
|
||||
}
|
||||
|
||||
public string GetElementValueById(string id)
|
||||
{
|
||||
Global.flag = false;
|
||||
browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("GetElementValue|" + id));
|
||||
while (!Global.flag)
|
||||
{
|
||||
|
||||
}
|
||||
return Global.Result;
|
||||
}
|
||||
|
||||
public void SetElementValueByid(string id, string value)
|
||||
{
|
||||
browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("SetElementValue|" + id + "|" + value));
|
||||
}
|
||||
|
||||
public void SelectAll()
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.GetMainFrame().SelectAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void Copy()
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.GetMainFrame().Copy();
|
||||
}
|
||||
}
|
||||
|
||||
public void Paste()
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.GetMainFrame().Paste();
|
||||
}
|
||||
}
|
||||
|
||||
public void Reload(bool ignoreCache)
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
if (ignoreCache)
|
||||
browser.ReloadIgnoreCache();
|
||||
else
|
||||
browser.Reload();
|
||||
}
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.Reload();
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.StopLoad();
|
||||
}
|
||||
}
|
||||
|
||||
public void Back()
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.GoBack();
|
||||
}
|
||||
}
|
||||
|
||||
public void Forward()
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.GoForward();
|
||||
}
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.GetMainFrame().Undo();
|
||||
}
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.GetMainFrame().Redo();
|
||||
}
|
||||
}
|
||||
|
||||
public void Cut()
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.GetMainFrame().Cut();
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.GetMainFrame().Delete();
|
||||
}
|
||||
}
|
||||
|
||||
public void ViewSource()
|
||||
{
|
||||
browser.GetMainFrame().ViewSource();
|
||||
}
|
||||
|
||||
public string GetSource()
|
||||
{
|
||||
var pageVisitor = new CwbStringVisitor();
|
||||
browser.GetMainFrame().GetSource(pageVisitor);
|
||||
while (true)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(pageVisitor.source)) break;
|
||||
}
|
||||
return pageVisitor.source;
|
||||
}
|
||||
private class DevToolsWebClient : CefClient
|
||||
{
|
||||
}
|
||||
public void ShowDevTool()
|
||||
{
|
||||
var host = browser.GetHost();
|
||||
var wi = CefWindowInfo.Create();
|
||||
wi.SetAsPopup(IntPtr.Zero, "DevTools");
|
||||
host.ShowDevTools(wi, new DevToolsWebClient(), new CefBrowserSettings(), new CefPoint(0, 0));
|
||||
}
|
||||
|
||||
public void CloseDevTool()
|
||||
{
|
||||
if (browser.GetMainFrame().Url.Contains("devtools.html"))
|
||||
browser.GetHost().CloseBrowser();
|
||||
}
|
||||
|
||||
public void SetScreenSize(int w, int h)
|
||||
{
|
||||
screenWidth = w;
|
||||
screenHeight = h;
|
||||
if (browserHandle != IntPtr.Zero)
|
||||
{
|
||||
WinApi.SetWindowPos(browserHandle, IntPtr.Zero,
|
||||
(Width-w)/2, (Height-h)/2, w, h,
|
||||
SetWindowPosFlags.NoZOrder
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetScreen()
|
||||
{
|
||||
screenWidth = Screen.PrimaryScreen.Bounds.Width;
|
||||
screenWidth = Screen.PrimaryScreen.Bounds.Height;
|
||||
ResizeWindow(browserHandle, Width, Height);
|
||||
}
|
||||
|
||||
public void LoadHtml(string htmlText)
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
browser.GetMainFrame().LoadString(htmlText, "about:blank");
|
||||
}
|
||||
}
|
||||
public delegate void TCallBackElementEventListener();
|
||||
internal List<CwbListenerItem> elementListenerList = new List<CwbListenerItem>();
|
||||
public void AppendElementEventListener(string id,string eventName,TCallBackElementEventListener callFunc)
|
||||
{
|
||||
string elementID = id.Replace("|0", "");
|
||||
foreach (CwbListenerItem t in elementListenerList)
|
||||
{
|
||||
if (t.id == elementID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
CwbListenerItem item = new CwbListenerItem();
|
||||
item.id = elementID;
|
||||
item.eventName = eventName;
|
||||
item.elementListener = callFunc;
|
||||
elementListenerList.Add(item);
|
||||
browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("AppendListener|" + id));
|
||||
}
|
||||
|
||||
internal CwbListenerItem getEventListener(string id)
|
||||
{
|
||||
foreach (CwbListenerItem item in elementListenerList)
|
||||
{
|
||||
if (item.id == id)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
internal void AppendAllElementEventListener()
|
||||
{
|
||||
foreach (CwbListenerItem item in elementListenerList)
|
||||
{
|
||||
browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("AppendListener|" + item.id));
|
||||
}
|
||||
}
|
||||
|
||||
public void ExecuteScript(string script)
|
||||
{
|
||||
browser.GetMainFrame().ExecuteJavaScript(script, browser.GetMainFrame().Url, 0);
|
||||
}
|
||||
|
||||
public object EvaluateScript(string script)
|
||||
{
|
||||
Global.flag = false;
|
||||
browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("EvaluateScript|" + script));
|
||||
while (!Global.flag)
|
||||
{
|
||||
Application.DoEvents();
|
||||
}
|
||||
return Global.JsEvaResult;
|
||||
}
|
||||
|
||||
public void AddPluginPath(string PluginPath)
|
||||
{
|
||||
CefRuntime.AddWebPluginPath(PluginPath);
|
||||
CefRuntime.RefreshWebPlugins();
|
||||
}
|
||||
|
||||
public void AddPluginDir(string PluginDir)
|
||||
{
|
||||
CefRuntime.AddWebPluginDirectory(PluginDir);
|
||||
CefRuntime.RefreshWebPlugins();
|
||||
}
|
||||
|
||||
public void RemovePlugin(string path)
|
||||
{
|
||||
CefRuntime.RemoveWebPluginPath(path);
|
||||
CefRuntime.RefreshWebPlugins();
|
||||
}
|
||||
|
||||
public void GoForward()
|
||||
{
|
||||
this.Forward();
|
||||
}
|
||||
|
||||
public void GoBack()
|
||||
{
|
||||
this.Back();
|
||||
}
|
||||
|
||||
public bool canGoForward()
|
||||
{
|
||||
return browser.CanGoForward;
|
||||
}
|
||||
|
||||
public bool canGoBack()
|
||||
{
|
||||
return browser.CanGoBack;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SetPopupMenuVisible(bool visibled)
|
||||
{
|
||||
menuVisible = visibled;
|
||||
}
|
||||
|
||||
public void SetPopupMenu(ContextMenu popupMenu)
|
||||
{
|
||||
menuVisible = false;
|
||||
this.ContextMenu = popupMenu;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region chromewebbrowser properties
|
||||
|
||||
public CwbDocument Document
|
||||
{
|
||||
get { return _document; }
|
||||
}
|
||||
|
||||
public string HomeUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
return _homeUrl;
|
||||
}
|
||||
}
|
||||
|
||||
internal CacheDB cacheDb
|
||||
{
|
||||
get { return _cachedb; }
|
||||
}
|
||||
|
||||
public string Url
|
||||
{
|
||||
get { return browser.GetMainFrame().Url; }
|
||||
set { _url = value; }
|
||||
}
|
||||
|
||||
public string Title
|
||||
{
|
||||
get { return _title; }
|
||||
}
|
||||
|
||||
public string Version
|
||||
{
|
||||
get { return "1.1.3.2454"; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region chromewebbrowser events
|
||||
public event EventHandler BrowserCreated;
|
||||
internal void OnCreated(CefBrowser mainBrowser)
|
||||
{
|
||||
created = true;
|
||||
if (this.browser == null)
|
||||
this.browser = mainBrowser;
|
||||
browserHandle = browser.GetHost().GetWindowHandle();
|
||||
ResizeWindow(browserHandle, Width, Height);
|
||||
|
||||
|
||||
|
||||
var handler = BrowserCreated;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
public event EventHandler BrowserNavigated;
|
||||
internal void OnNavigated()
|
||||
{
|
||||
var handler = BrowserNavigated;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
public event EventHandler BrowserNavigating;
|
||||
internal void OnNavigating()
|
||||
{
|
||||
var handler = BrowserNavigating;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
public event EventHandler BrowserDocumentCompleted;
|
||||
internal void OnDocumentCompleted()
|
||||
{
|
||||
AppendAllElementEventListener();
|
||||
var handler = BrowserDocumentCompleted;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
_document = new CwbDocument(this.browser);
|
||||
JsMethodCall.AllFrameCompleted(this);
|
||||
}
|
||||
public event EventHandler BrowserFrameLoadStart;
|
||||
public event EventHandler PageLoadStartEventHandler;
|
||||
internal void OnLoadStart()
|
||||
{
|
||||
var handler = BrowserFrameLoadStart;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, EventArgs.Empty);
|
||||
return;
|
||||
}
|
||||
handler = PageLoadStartEventHandler;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
public event EventHandler BrowserFrameLoadEnd;
|
||||
internal void OnLoadEnd()
|
||||
{
|
||||
var handler = BrowserFrameLoadEnd;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, EventArgs.Empty);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler PageLoadFinishEventhandler;
|
||||
internal void OnPageFinished()
|
||||
{
|
||||
var handler = PageLoadFinishEventhandler;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, EventArgs.Empty);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public event FrameLoadErrorHandler BrowserFrameLoadError;
|
||||
internal void OnLoadError(CefErrorCode errorCode, string errorText, string url)
|
||||
{
|
||||
var handler = BrowserFrameLoadError;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, new LoadErrorEventArgs(errorCode, errorText, url));
|
||||
}
|
||||
string htmlErrText =
|
||||
"<html><body><h2>Failed to load URL " + url +
|
||||
" with error " + errorText + " (" + errorCode +
|
||||
").</h2></body></html>";
|
||||
browser.GetMainFrame().LoadString(htmlErrText, url);
|
||||
}
|
||||
public event TitleChangeEventHandler BrowserTitleChange;
|
||||
internal void OnTitleChange(string title)
|
||||
{
|
||||
_title = title;
|
||||
var handler = BrowserTitleChange;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, new TitleEventArgs(title));
|
||||
}
|
||||
}
|
||||
public event UrlChangeEventHandler BrowserUrlChange;
|
||||
internal void OnUrlChange(string url)
|
||||
{
|
||||
var handler = BrowserUrlChange;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, new UrlChangeEventArgs(url));
|
||||
}
|
||||
}
|
||||
public event PreviewKeyDownEventHandler BrowserPreviewKeyDown;
|
||||
internal void OnPreviewKeyDown(bool bAlt, bool bCtrl, bool bShift, bool OnEditor,
|
||||
int keyCode, char key)
|
||||
{
|
||||
var handler = BrowserPreviewKeyDown;
|
||||
switch (keyCode)
|
||||
{ //F5刷新
|
||||
case 116:
|
||||
browser.Reload();
|
||||
break;
|
||||
}
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, new BrowserKeyDownEventArgs(bAlt, bCtrl, bShift, OnEditor,
|
||||
keyCode, key));
|
||||
}
|
||||
}
|
||||
public event EventHandler BrowserBeforeDownload;
|
||||
internal void OnBeforeDownload()
|
||||
{
|
||||
var handler = BrowserBeforeDownload;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public event DownloadingEventHandler BrowserDownloading;
|
||||
private Form downloadForm = null;
|
||||
internal void OnDownloading(long totalSize,
|
||||
long loadSize,
|
||||
long speedSize,
|
||||
int percent,
|
||||
string fileUrl,
|
||||
string fileName,
|
||||
string mimeType,
|
||||
bool isComplete,
|
||||
bool isInProgress)
|
||||
{
|
||||
var handler = BrowserDownloading;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, new FileDownloadEventArgs(totalSize,
|
||||
loadSize,speedSize,
|
||||
percent,
|
||||
fileUrl,
|
||||
fileName,
|
||||
mimeType,
|
||||
isComplete,
|
||||
isInProgress));
|
||||
}
|
||||
else
|
||||
{
|
||||
string strTotalSize = CompareFileSize(totalSize);
|
||||
string strLoadedSize = CompareFileSize(loadSize);
|
||||
|
||||
if (downloadForm == null)
|
||||
{
|
||||
downloadForm = new Form();
|
||||
downloadForm.Text = "下载中";
|
||||
downloadForm.Width = 280;
|
||||
downloadForm.Height = 150;
|
||||
downloadForm.MaximizeBox = false;
|
||||
downloadForm.MinimizeBox = false;
|
||||
downloadForm.ControlBox = false;
|
||||
downloadForm.StartPosition = FormStartPosition.CenterScreen;
|
||||
|
||||
|
||||
Label label = new Label();
|
||||
label.Left = 20;
|
||||
label.Top = 50;
|
||||
label.Width = 250;
|
||||
label.Text = "已下载:" + strLoadedSize + "/" + strTotalSize;
|
||||
downloadForm.Controls.Add(label);
|
||||
}
|
||||
downloadForm.Show();
|
||||
downloadForm.BringToFront();
|
||||
foreach (Control c in downloadForm.Controls)
|
||||
{
|
||||
if (c is Label)
|
||||
{
|
||||
Label label = (Label)c;
|
||||
label.Text = "已下载:" + strLoadedSize + "/" + strTotalSize;
|
||||
label.Update();
|
||||
}
|
||||
}
|
||||
downloadForm.Update();
|
||||
if (isComplete)
|
||||
{
|
||||
downloadForm.Dispose();
|
||||
downloadForm = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string CompareFileSize(Int64 size)
|
||||
{
|
||||
//计算K,M单位
|
||||
string strTotalSize = string.Empty;
|
||||
if (size < 1024)
|
||||
{
|
||||
strTotalSize = size.ToString() + " B";
|
||||
}
|
||||
else if (size >= 1024 && size < 1024 * 1024)
|
||||
{
|
||||
strTotalSize = (size / 1024).ToString() + " KB";
|
||||
}
|
||||
else
|
||||
{
|
||||
strTotalSize = (size / 1024 / 1024).ToString() + " MB";
|
||||
}
|
||||
return strTotalSize;
|
||||
}
|
||||
|
||||
|
||||
public event NewWindowEventHandler BrowserNewWindow;
|
||||
internal bool OnNewWindow(string targetUrl)
|
||||
{
|
||||
bool res = false;
|
||||
var handler = BrowserNewWindow;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, new NewWindowEventArgs(targetUrl, selfRequest));
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
Global.BrowserList.Add(this);
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
var form = TopLevelControl as Form;
|
||||
if (form != null && form.WindowState != FormWindowState.Minimized)
|
||||
{
|
||||
ResizeWindow(browserHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Sashulin.Core
|
||||
{
|
||||
public class CwbCookie
|
||||
{
|
||||
private DateTime _creation;
|
||||
public DateTime Creation
|
||||
{
|
||||
get
|
||||
{
|
||||
return _creation;
|
||||
}
|
||||
set
|
||||
{
|
||||
_creation = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string _domain;
|
||||
public string Domain
|
||||
{
|
||||
get { return _domain; }
|
||||
set { _domain = value; }
|
||||
}
|
||||
|
||||
private DateTime? _expires;
|
||||
public DateTime? Expires
|
||||
{
|
||||
get { return _expires; }
|
||||
set { _expires = value; }
|
||||
}
|
||||
|
||||
private bool _httpOnly;
|
||||
public bool HttpOnly
|
||||
{
|
||||
get { return _httpOnly; }
|
||||
set { _httpOnly = value; }
|
||||
}
|
||||
|
||||
private DateTime _lastAccess;
|
||||
public DateTime LastAccess
|
||||
{
|
||||
get { return _lastAccess; }
|
||||
set { _lastAccess = value; }
|
||||
}
|
||||
|
||||
private string _name;
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
private string _value;
|
||||
public string Value
|
||||
{
|
||||
get { return _value; }
|
||||
set { _value = value; }
|
||||
}
|
||||
|
||||
private string _path;
|
||||
public string Path
|
||||
{
|
||||
get { return _path; }
|
||||
set { _path = value; }
|
||||
}
|
||||
|
||||
private bool _secure;
|
||||
public bool Secure
|
||||
{
|
||||
get { return _secure; }
|
||||
set { _secure = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
using Sashulin.common;
|
||||
using Sashulin.Core;
|
||||
|
||||
namespace Sashulin.Core
|
||||
{
|
||||
public class CwbDocument
|
||||
{
|
||||
internal List<CwbCookie> _cookies = new List<CwbCookie>();
|
||||
private CwbElement _root;
|
||||
private CefBrowser browser;
|
||||
internal string _cookie;
|
||||
|
||||
|
||||
public CwbDocument(CefBrowser browser)
|
||||
{
|
||||
this.browser = browser;
|
||||
}
|
||||
|
||||
public List<CwbCookie> Cookies
|
||||
{
|
||||
get { return _cookies; }
|
||||
set { _cookies = value; }
|
||||
}
|
||||
|
||||
public string Cookie
|
||||
{
|
||||
get
|
||||
{
|
||||
return _cookie;
|
||||
}
|
||||
set
|
||||
{
|
||||
_cookie = value;
|
||||
}
|
||||
}
|
||||
|
||||
public CwbElement Root
|
||||
{
|
||||
get { return _root; }
|
||||
set { _root = value; }
|
||||
}
|
||||
|
||||
public void Load()
|
||||
{
|
||||
Global.flag = false;
|
||||
if (Root != null)
|
||||
{
|
||||
Root.ChildElements.Clear();
|
||||
}
|
||||
browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("GetDocument"));
|
||||
while (!Global.flag)
|
||||
{
|
||||
|
||||
}
|
||||
_root = Global.RootList[ browser.Identifier ];
|
||||
CefCookieManager.GetGlobal(null).VisitUrlCookies(browser.GetMainFrame().Url, true, new CwbCookieVisitor(CwbCookieStyle.csVisitUrlCookie, this));
|
||||
}
|
||||
|
||||
|
||||
public List<CwbElement> GetElementsByTagName(string tagName)
|
||||
{
|
||||
List<CwbElement> list = GetElementsByTagName(tagName,Root);
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<CwbElement> GetElementsByTagName(string tagName, CwbElement parent)
|
||||
{
|
||||
List<CwbElement> list = new List<CwbElement>();
|
||||
foreach (CwbElement e in parent.ChildElements)
|
||||
{
|
||||
if (string.IsNullOrEmpty(e.TagName)) continue;
|
||||
List<CwbElement> items = GetElementsByTagName(tagName, e);
|
||||
if (e.TagName.ToUpper() == tagName.ToUpper())
|
||||
{
|
||||
list.Add(e);
|
||||
}
|
||||
list.AddRange(items);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public CwbElement GetElementById(string id)
|
||||
{
|
||||
return GetElementById(id,Root);
|
||||
}
|
||||
|
||||
private CwbElement GetElementById(string id, CwbElement parent)
|
||||
{
|
||||
foreach (CwbElement e in parent.ChildElements)
|
||||
{
|
||||
if (e.Id.ToUpper() == id.ToUpper())
|
||||
{
|
||||
return e;
|
||||
}
|
||||
CwbElement element = GetElementById(id, e);
|
||||
if (element != null)
|
||||
{
|
||||
if (element.Id.ToUpper() == id.ToUpper())
|
||||
{
|
||||
return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
|
||||
namespace Sashulin.Core
|
||||
{
|
||||
public class CwbElement
|
||||
{
|
||||
private string _id;
|
||||
private string _tagName;
|
||||
private string _indexPath;
|
||||
private string _value;
|
||||
private string _text;
|
||||
private Boolean _isElement;
|
||||
private Boolean _isEditable;
|
||||
private Boolean _hasChildren;
|
||||
private Boolean _hasAttributes;
|
||||
private List<CwbElement> _elements = new List<CwbElement>();
|
||||
private int browserIdentifier;
|
||||
private IDictionary<string, string> _attributes = new Dictionary<string, string>();
|
||||
|
||||
public CwbElement() { }
|
||||
public CwbElement(CefBrowser browser, string id, string tagName,
|
||||
string value,
|
||||
Boolean isElement,Boolean isEditable,
|
||||
Boolean hasChildren,
|
||||
string text, Boolean hasAttributes)
|
||||
{
|
||||
this.browserIdentifier = browser.Identifier;
|
||||
_id = id;
|
||||
_tagName = tagName;
|
||||
_value = value;
|
||||
_isElement = isElement;
|
||||
_isEditable = isEditable;
|
||||
_hasChildren = hasChildren;
|
||||
_text = text;
|
||||
_hasAttributes = hasAttributes;
|
||||
}
|
||||
|
||||
public string Id
|
||||
{
|
||||
get { return _id; }
|
||||
}
|
||||
|
||||
public string TagName
|
||||
{
|
||||
get { return _tagName; }
|
||||
}
|
||||
|
||||
public string IndexPath
|
||||
{
|
||||
get { return _indexPath; }
|
||||
set { _indexPath = value; }
|
||||
}
|
||||
|
||||
public List<CwbElement> ChildElements
|
||||
{
|
||||
get { return _elements; }
|
||||
set { _elements = value; }
|
||||
}
|
||||
|
||||
public Boolean IsElement
|
||||
{
|
||||
get { return _isElement; }
|
||||
}
|
||||
|
||||
public Boolean IsEditable
|
||||
{
|
||||
get { return _isEditable; }
|
||||
}
|
||||
|
||||
public Boolean HasChildren
|
||||
{
|
||||
get { return _hasChildren; }
|
||||
}
|
||||
|
||||
public Boolean HasAttributes
|
||||
{
|
||||
get { return _hasAttributes; }
|
||||
}
|
||||
|
||||
public IDictionary<string, string> Attributes
|
||||
{
|
||||
get { return _attributes; }
|
||||
}
|
||||
|
||||
public string InnerText
|
||||
{
|
||||
get { return _text; }
|
||||
}
|
||||
|
||||
public string InnerHtml
|
||||
{
|
||||
get
|
||||
{
|
||||
string retValue = string.Empty;
|
||||
string script = string.Empty;
|
||||
Boolean has = GetNodeScript(ref script);
|
||||
if (has)
|
||||
{
|
||||
script += ".innerHTML;";
|
||||
object o = GetCurrentBrowser().EvaluateScript(script);
|
||||
if (o != null)
|
||||
retValue = o.ToString();
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
string script = string.Empty;
|
||||
Boolean has = GetNodeScript(ref script);
|
||||
if (has)
|
||||
{
|
||||
script += ".innerHTML = '" + value + "'";
|
||||
GetCurrentBrowser().ExecuteScript(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Value
|
||||
{
|
||||
get {
|
||||
_value = string.Empty;
|
||||
string script = string.Empty;
|
||||
Boolean has = GetNodeScript(ref script);
|
||||
if (has)
|
||||
{
|
||||
script += ".value;";
|
||||
object o = GetCurrentBrowser().EvaluateScript(script);
|
||||
_value = o.ToString();
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
set {
|
||||
_value = value;
|
||||
string script = string.Empty;
|
||||
Boolean has = GetNodeScript(ref script);
|
||||
if (has)
|
||||
{
|
||||
script += ".value = '" + value + "'";
|
||||
GetCurrentBrowser().ExecuteScript(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAttribute(string attrName)
|
||||
{
|
||||
return _attributes.ContainsKey(attrName);
|
||||
}
|
||||
|
||||
public string GetAttribute(string attrName)
|
||||
{
|
||||
string retValue = string.Empty;
|
||||
if (HasAttribute(attrName))
|
||||
retValue = _attributes[attrName];
|
||||
return retValue;
|
||||
}
|
||||
|
||||
public void SetAttribute(string attrName,string value)
|
||||
{
|
||||
string script = string.Empty;
|
||||
Boolean has = GetNodeScript(ref script);
|
||||
if (has)
|
||||
{
|
||||
script += ".setAttribute('" + attrName + "','" + value + "');";
|
||||
GetCurrentBrowser().ExecuteScript(script);
|
||||
}
|
||||
}
|
||||
|
||||
public void Click()
|
||||
{
|
||||
string script = string.Empty;
|
||||
Boolean has = GetNodeScript(ref script);
|
||||
if (has)
|
||||
{
|
||||
script += ".click();";
|
||||
GetCurrentBrowser().ExecuteScript(script);
|
||||
}
|
||||
}
|
||||
|
||||
public void AttachEventListener(string eventName, ChromeWebBrowser.TCallBackElementEventListener eventListener)
|
||||
{
|
||||
GetCurrentBrowser().AppendElementEventListener(IndexPath + "|0", eventName, eventListener);
|
||||
}
|
||||
|
||||
private bool GetNodeScript(ref string script)
|
||||
{
|
||||
Boolean retValue = false;
|
||||
script = "document";
|
||||
string[] indexArray = IndexPath.Split(new char[] { '.' });
|
||||
for (int i = 1; i < indexArray.Length; i++)
|
||||
{
|
||||
retValue = true;
|
||||
script += ".childNodes[" + indexArray[i] + "]";
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
|
||||
private ChromeWebBrowser GetCurrentBrowser()
|
||||
{
|
||||
ChromeWebBrowser b = null;
|
||||
foreach (ChromeWebBrowser c in Global.BrowserList)
|
||||
{
|
||||
if (c == null) continue;
|
||||
if (c.browser.Identifier == browserIdentifier)
|
||||
{
|
||||
b = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using Cef3;
|
||||
using Sashulin.common;
|
||||
using Sashulin.Core;
|
||||
namespace Sashulin
|
||||
{
|
||||
internal class Global
|
||||
{
|
||||
internal static List<ChromeWebBrowser> BrowserList = new List<ChromeWebBrowser>();
|
||||
internal static Dictionary<int, CwbElement> RootList = new Dictionary<int,CwbElement>();
|
||||
internal static ClientApp app;
|
||||
internal static ChromeWebBrowser instance;
|
||||
internal static string Result;
|
||||
internal static bool flag;
|
||||
internal static object JsEvaResult;
|
||||
internal static CacheDB cacheDB = new CacheDB();
|
||||
|
||||
const string ERROR_CALL_NOTFOUND = "error: this method can not be found.";
|
||||
const string ERROR_CALL_PARAMETER = "error: parameter is incorrect";
|
||||
|
||||
internal static string CallMethod(CefBrowser browser,string methodName, string paramValues)
|
||||
{
|
||||
Type t = null;
|
||||
object form = null;
|
||||
foreach(ChromeWebBrowser c in BrowserList)
|
||||
{
|
||||
if (c == null) continue;
|
||||
if (c.browser.Identifier == browser.Identifier)
|
||||
{
|
||||
t = c.FindForm().GetType();
|
||||
form = c.FindForm();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (t == null)
|
||||
{
|
||||
return ERROR_CALL_NOTFOUND;
|
||||
}
|
||||
|
||||
MethodInfo m = t.GetMethod(methodName);
|
||||
if (m == null)
|
||||
{
|
||||
return ERROR_CALL_NOTFOUND;
|
||||
}
|
||||
object[] objArray = null;
|
||||
string[] values = new string[0];
|
||||
if (paramValues != null)
|
||||
values = paramValues.Split(new char[] { ',' });
|
||||
objArray = new object[values.Length];
|
||||
ParameterInfo[] pa = m.GetParameters();
|
||||
|
||||
if (objArray.Length != pa.Length)
|
||||
{
|
||||
return ERROR_CALL_PARAMETER;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
foreach (ParameterInfo p in pa)
|
||||
{
|
||||
switch (p.ParameterType.Name)
|
||||
{
|
||||
case "String":
|
||||
objArray[i] = values[i];
|
||||
break;
|
||||
case "Int32":
|
||||
objArray[i] = Int32.Parse(values[i]);
|
||||
break;
|
||||
case "Boolean":
|
||||
objArray[i] = Boolean.Parse(values[i]);
|
||||
break;
|
||||
case "Double":
|
||||
objArray[i] = Double.Parse(values[i]);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
object o = m.Invoke(form, objArray);
|
||||
string retVal = string.Empty;
|
||||
if (o != null)
|
||||
retVal = o.ToString();
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
enum CwbBusinStyle
|
||||
{
|
||||
bsGetElementValue = 0,
|
||||
bsSetElementValue = 1,
|
||||
bsAddElementEvent = 2,
|
||||
bsVisitDocument = 3,
|
||||
bsFocusElement = 4,
|
||||
bsAttachElementEvent = 5,
|
||||
bsNone = -1
|
||||
}
|
||||
|
||||
enum CwbCookieStyle
|
||||
{
|
||||
csDeleteAllCookie = 0,
|
||||
csVisitUrlCookie = 1
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Sashulin
|
||||
{
|
||||
public class JsMethodCall
|
||||
{
|
||||
/// <summary>
|
||||
/// 调整页面滚动条
|
||||
/// </summary>
|
||||
/// <param name="chrome"></param>
|
||||
/// <param name="ratioX">x坐标</param>
|
||||
/// <param name="ratioY">y坐标</param>
|
||||
public static void ScrollTo(ChromeWebBrowser chrome,float ratioX,float ratioY)
|
||||
{
|
||||
string jsCode = "var w=document.body.scrollWidth;" +
|
||||
"var h=document.body.scrollHeight;" +
|
||||
"window.scrollTo(w*{0},h*{1});";
|
||||
jsCode = string.Format(jsCode, ratioX, ratioY);
|
||||
chrome.ExecuteScript(jsCode);
|
||||
}
|
||||
public static void DoElementClick(ChromeWebBrowser chrome,string id)
|
||||
{
|
||||
string jsCode = "document.getElementById('{0}').click();";
|
||||
jsCode = string.Format(jsCode,id);
|
||||
chrome.ExecuteScript(jsCode);
|
||||
}
|
||||
/// <summary>
|
||||
/// 过滤元素,并触发点击
|
||||
/// </summary>
|
||||
/// <param name="chrome"></param>
|
||||
/// <param name="elementName">html元素名称,如input,a,div</param>
|
||||
/// <param name="attribute">元素属性名,如name,href,src</param>
|
||||
/// <param name="value">元素值</param>
|
||||
/// <param name="isFilter">true:模糊匹配,false:全量匹配</param>
|
||||
public static void DoElementClick(ChromeWebBrowser chrome,string elementName, string attribute, string value, bool isFilter)
|
||||
{
|
||||
string condStr = " if(attr == '" + value + "') {";
|
||||
if (!isFilter)
|
||||
{
|
||||
condStr = " if(attr.indexOf('"+value+"')>=0) {";
|
||||
}
|
||||
string jsCode = " var controls = document.getElementsByTagName('" + elementName + "'); " +
|
||||
"for(var i=0;i<controls.length;i++){" +
|
||||
" var attr = controls[i].getAttribute('" + attribute + "')+'';" +
|
||||
condStr +
|
||||
" controls[i].click(); " +
|
||||
" }}";
|
||||
chrome.ExecuteScript(jsCode);
|
||||
}
|
||||
|
||||
public static void AllFrameCompleted(ChromeWebBrowser chrome)
|
||||
{
|
||||
string jsCode = "var ifrs=document.getElementsByTagName('iframe');L=ifrs.length,n=0;" +
|
||||
"for(var i=0;i<L;i++)" +
|
||||
"{" +
|
||||
" ifrs.onload=function(){" +
|
||||
" n++;" +
|
||||
" if(n==L) window.PageFinished();" +
|
||||
" }" +
|
||||
"}" +
|
||||
"if (n==0) window.PageFinished();";
|
||||
chrome.ExecuteScript(jsCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息通过以下
|
||||
// 特性集控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("cwber")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Sashulin")]
|
||||
[assembly: AssemblyProduct("cwber")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
|
||||
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("73ee2192-f847-4f3a-a98d-12e266d211a3")]
|
||||
|
||||
// 程序集的版本信息由下面四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
// 方法是按如下所示使用“*”:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Sashulin
|
||||
{
|
||||
class WinApi
|
||||
{
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
|
||||
}
|
||||
[Flags]
|
||||
internal enum SetWindowPosFlags : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// If the calling thread and the thread that owns the window are attached to different input queues,
|
||||
/// the system posts the request to the thread that owns the window. This prevents the calling thread from
|
||||
/// blocking its execution while other threads process the request.
|
||||
/// </summary>
|
||||
/// <remarks>SWP_ASYNCWINDOWPOS</remarks>
|
||||
AsyncWindowPosition = 0x4000,
|
||||
|
||||
/// <summary>
|
||||
/// Prevents generation of the WM_SYNCPAINT message.
|
||||
/// </summary>
|
||||
/// <remarks>SWP_DEFERERASE</remarks>
|
||||
DeferErase = 0x2000,
|
||||
|
||||
/// <summary>
|
||||
/// Draws a frame (defined in the window's class description) around the window.
|
||||
/// </summary>
|
||||
/// <remarks>SWP_DRAWFRAME</remarks>
|
||||
DrawFrame = 0x0020,
|
||||
|
||||
/// <summary>
|
||||
/// Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to
|
||||
/// the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE
|
||||
/// is sent only when the window's size is being changed.
|
||||
/// </summary>
|
||||
/// <remarks>SWP_FRAMECHANGED</remarks>
|
||||
FrameChanged = 0x0020,
|
||||
|
||||
/// <summary>
|
||||
/// Hides the window.
|
||||
/// </summary>
|
||||
/// <remarks>SWP_HIDEWINDOW</remarks>
|
||||
HideWindow = 0x0080,
|
||||
|
||||
/// <summary>
|
||||
/// Does not activate the window. If this flag is not set, the window is activated and moved to the
|
||||
/// top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
|
||||
/// </summary>
|
||||
/// <remarks>SWP_NOACTIVATE</remarks>
|
||||
NoActivate = 0x0010,
|
||||
|
||||
/// <summary>
|
||||
/// Discards the entire contents of the client area. If this flag is not specified, the valid contents
|
||||
/// of the client area are saved and copied back into the client area after the window is sized or repositioned.
|
||||
/// </summary>
|
||||
/// <remarks>SWP_NOCOPYBITS</remarks>
|
||||
NoCopyBits = 0x0100,
|
||||
|
||||
/// <summary>
|
||||
/// Retains the current position (ignores X and Y parameters).
|
||||
/// </summary>
|
||||
/// <remarks>SWP_NOMOVE</remarks>
|
||||
NoMove = 0x0002,
|
||||
|
||||
/// <summary>
|
||||
/// Does not change the owner window's position in the Z order.
|
||||
/// </summary>
|
||||
/// <remarks>SWP_NOOWNERZORDER</remarks>
|
||||
NoOwnerZOrder = 0x0200,
|
||||
|
||||
/// <summary>
|
||||
/// Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to
|
||||
/// the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent
|
||||
/// window uncovered as a result of the window being moved. When this flag is set, the application must
|
||||
/// explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
|
||||
/// </summary>
|
||||
/// <remarks>SWP_NOREDRAW</remarks>
|
||||
NoRedraw = 0x0008,
|
||||
|
||||
/// <summary>
|
||||
/// Same as the SWP_NOOWNERZORDER flag.
|
||||
/// </summary>
|
||||
/// <remarks>SWP_NOREPOSITION</remarks>
|
||||
NoReposition = 0x0200,
|
||||
|
||||
/// <summary>
|
||||
/// Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
|
||||
/// </summary>
|
||||
/// <remarks>SWP_NOSENDCHANGING</remarks>
|
||||
NoSendChanging = 0x0400,
|
||||
|
||||
/// <summary>
|
||||
/// Retains the current size (ignores the cx and cy parameters).
|
||||
/// </summary>
|
||||
/// <remarks>SWP_NOSIZE</remarks>
|
||||
NoSize = 0x0001,
|
||||
|
||||
/// <summary>
|
||||
/// Retains the current Z order (ignores the hWndInsertAfter parameter).
|
||||
/// </summary>
|
||||
/// <remarks>SWP_NOZORDER</remarks>
|
||||
NoZOrder = 0x0004,
|
||||
|
||||
/// <summary>
|
||||
/// Displays the window.
|
||||
/// </summary>
|
||||
/// <remarks>SWP_SHOWWINDOW</remarks>
|
||||
ShowWindow = 0x0040,
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
namespace Sashulin.common
|
||||
{
|
||||
internal sealed class AppSchemeHandlerFactory : CefSchemeHandlerFactory
|
||||
{
|
||||
protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request)
|
||||
{
|
||||
return new RequestResourceHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using Cef3;
|
||||
namespace Sashulin.common
|
||||
{
|
||||
internal sealed class BrowserProcessHandler : CefBrowserProcessHandler
|
||||
{
|
||||
protected override void OnBeforeChildProcessLaunch(CefCommandLine commandLine)
|
||||
{
|
||||
Console.WriteLine("AppendExtraCommandLineSwitches: {0}", commandLine);
|
||||
Console.WriteLine(" Program == {0}", commandLine.GetProgram());
|
||||
|
||||
// .NET in Windows treat assemblies as native images, so no any magic required.
|
||||
// Mono on any platform usually located far away from entry assembly, so we want prepare command line to call it correctly.
|
||||
if (Type.GetType("Mono.Runtime") != null)
|
||||
{
|
||||
if (!commandLine.HasSwitch("cefglue"))
|
||||
{
|
||||
var path = new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath;
|
||||
commandLine.SetProgram(path);
|
||||
|
||||
var mono = CefRuntime.Platform == CefRuntimePlatform.Linux ? "/usr/bin/mono" : @"C:\Program Files\Mono-2.10.8\bin\monow.exe";
|
||||
commandLine.PrependArgument(mono);
|
||||
|
||||
commandLine.AppendSwitch("cefglue", "w");
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine(" -> {0}", commandLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Cef3;
|
||||
namespace Sashulin.common
|
||||
{
|
||||
public sealed class ClientApp : CefApp
|
||||
{
|
||||
private CefBrowserProcessHandler _browserProcessHandler = new BrowserProcessHandler();
|
||||
private RenderProcessHandler _renderProcessHandler = new RenderProcessHandler();
|
||||
|
||||
protected override void OnBeforeCommandLineProcessing(string processType, CefCommandLine commandLine)
|
||||
{
|
||||
Console.WriteLine("OnBeforeCommandLineProcessing: {0} {1}", processType, commandLine);
|
||||
|
||||
commandLine.AppendSwitch("ppapi-flash-path", "plugins/pepflashplayer.dll");
|
||||
commandLine.AppendSwitch("ppapi-flash-version","17.0.0.134");
|
||||
|
||||
// TODO: currently on linux platform location of locales and pack files are determined
|
||||
// incorrectly (relative to main module instead of libcef.so module).
|
||||
// Once issue http://code.google.com/p/chromiumembedded/issues/detail?id=668 will be resolved
|
||||
// this code can be removed.
|
||||
if (CefRuntime.Platform == CefRuntimePlatform.Linux)
|
||||
{
|
||||
var path = new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath;
|
||||
path = Path.GetDirectoryName(path);
|
||||
|
||||
commandLine.AppendSwitch("resources-dir-path", path);
|
||||
commandLine.AppendSwitch("locales-dir-path", Path.Combine(path, "locales"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override CefBrowserProcessHandler GetBrowserProcessHandler()
|
||||
{
|
||||
return _browserProcessHandler;
|
||||
}
|
||||
|
||||
protected override CefRenderProcessHandler GetRenderProcessHandler()
|
||||
{
|
||||
return _renderProcessHandler;
|
||||
}
|
||||
|
||||
public void SetBrowserControl(ChromeWebBrowser browser)
|
||||
{
|
||||
_renderProcessHandler.SetBrowserControl(browser);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
|
||||
namespace Sashulin.common
|
||||
{
|
||||
public sealed class ClientBrowser : CefClient
|
||||
{
|
||||
private readonly CwbLifeSpanHandler _lifeSpanHandler;
|
||||
private readonly CwbDisplayHandler _displayHandler;
|
||||
private readonly CwbLoadHandler _loadHandler;
|
||||
private readonly CwbKeyboardHandler _keyboardHandler;
|
||||
private readonly FileDownloadHandler _fileDownloadHandler;
|
||||
private readonly CwbRequestHandler _requestHandler;
|
||||
private readonly CwbRenderHandler _renderHandler;
|
||||
private readonly CwbMenuHandler _menuHandler;
|
||||
|
||||
private ChromeWebBrowser webBrowser;
|
||||
public ClientBrowser(ChromeWebBrowser browser)
|
||||
{
|
||||
webBrowser = browser;
|
||||
_lifeSpanHandler = new CwbLifeSpanHandler(browser);
|
||||
_displayHandler = new CwbDisplayHandler(browser);
|
||||
_loadHandler = new CwbLoadHandler(browser);
|
||||
_keyboardHandler = new CwbKeyboardHandler(browser);
|
||||
_fileDownloadHandler = new FileDownloadHandler(browser);
|
||||
_requestHandler = new CwbRequestHandler(browser);
|
||||
_renderHandler = new CwbRenderHandler(browser);
|
||||
_menuHandler = new CwbMenuHandler(browser);
|
||||
}
|
||||
|
||||
protected override CefLifeSpanHandler GetLifeSpanHandler()
|
||||
{
|
||||
return _lifeSpanHandler;
|
||||
}
|
||||
|
||||
protected override CefDisplayHandler GetDisplayHandler()
|
||||
{
|
||||
return _displayHandler;
|
||||
}
|
||||
|
||||
protected override CefLoadHandler GetLoadHandler()
|
||||
{
|
||||
return _loadHandler;
|
||||
}
|
||||
|
||||
protected override CefKeyboardHandler GetKeyboardHandler()
|
||||
{
|
||||
return _keyboardHandler;
|
||||
}
|
||||
|
||||
protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
|
||||
{
|
||||
Console.WriteLine("Client::OnProcessMessageReceived: SourceProcess={0}", sourceProcess);
|
||||
Console.WriteLine("Message Name={0} IsValid={1} IsReadOnly={2}", message.Name, message.IsValid, message.IsReadOnly);
|
||||
var arguments = message.Arguments;
|
||||
for (var i = 0; i < arguments.Count; i++)
|
||||
{
|
||||
var type = arguments.GetValueType(i);
|
||||
object value;
|
||||
switch (type)
|
||||
{
|
||||
case CefValueType.Null: value = null; break;
|
||||
case CefValueType.String: value = arguments.GetString(i); break;
|
||||
case CefValueType.Int: value = arguments.GetInt(i); break;
|
||||
case CefValueType.Double: value = arguments.GetDouble(i); break;
|
||||
case CefValueType.Bool: value = arguments.GetBool(i); break;
|
||||
default: value = null; break;
|
||||
}
|
||||
|
||||
Console.WriteLine(" [{0}] ({1}) = {2}", i, type, value);
|
||||
}
|
||||
|
||||
if (message.Name == "myMessage2" || message.Name == "myMessage3") return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override CefDownloadHandler GetDownloadHandler()
|
||||
{
|
||||
return _fileDownloadHandler;
|
||||
}
|
||||
protected override CefRenderHandler GetRenderHandler()
|
||||
{
|
||||
return _renderHandler;
|
||||
}
|
||||
|
||||
protected override CefRequestHandler GetRequestHandler()
|
||||
{
|
||||
return _requestHandler;
|
||||
}
|
||||
|
||||
protected override CefJSDialogHandler GetJSDialogHandler()
|
||||
{
|
||||
return base.GetJSDialogHandler();
|
||||
}
|
||||
protected override CefContextMenuHandler GetContextMenuHandler()
|
||||
{
|
||||
return _menuHandler;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
|
||||
namespace Sashulin.common
|
||||
{
|
||||
class CwbCookieTask : CefTask
|
||||
{
|
||||
private string Url;
|
||||
private CefCookie Cookie;
|
||||
public CwbCookieTask(string url, CefCookie cookie)
|
||||
{
|
||||
Url = url;
|
||||
Cookie = cookie;
|
||||
}
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
CefCookieManager.GetGlobal(null).SetCookie(Url, Cookie,null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
using Sashulin.Core;
|
||||
|
||||
namespace Sashulin.common
|
||||
{
|
||||
class CwbCookieVisitor : CefCookieVisitor
|
||||
{
|
||||
private CwbCookieStyle _style;
|
||||
private CwbDocument _document;
|
||||
public CwbCookieVisitor(CwbCookieStyle style,CwbDocument document)
|
||||
{
|
||||
_style = style;
|
||||
_document = document;
|
||||
}
|
||||
|
||||
protected override bool Visit(CefCookie cookie, int count, int total, out bool delete)
|
||||
{
|
||||
delete = false;
|
||||
switch (_style)
|
||||
{
|
||||
case CwbCookieStyle.csDeleteAllCookie:
|
||||
delete = true;
|
||||
break;
|
||||
case CwbCookieStyle.csVisitUrlCookie:
|
||||
string cookieValue = cookie.Name + "=" + cookie.Value + ";";
|
||||
_document._cookie += cookieValue;
|
||||
CwbCookie cookieItem = new CwbCookie();
|
||||
cookieItem.Creation = cookie.Creation;
|
||||
cookieItem.Domain = cookie.Domain;
|
||||
cookieItem.Expires = cookie.Expires;
|
||||
cookieItem.HttpOnly = cookie.HttpOnly;
|
||||
cookieItem.LastAccess = cookie.LastAccess;
|
||||
cookieItem.Name = cookie.Name;
|
||||
cookieItem.Path = cookie.Path;
|
||||
cookieItem.Secure = cookie.Secure;
|
||||
cookieItem.Value = cookie.Value;
|
||||
_document._cookies.Add(cookieItem);
|
||||
break;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
using Sashulin.Core;
|
||||
|
||||
namespace Sashulin.common
|
||||
{
|
||||
class CwbDOMVisitor : CefDomVisitor
|
||||
{
|
||||
private CwbBusinStyle _businID;
|
||||
private string _elementID;
|
||||
private string _elementValue;
|
||||
private CwbListenerItem _item;
|
||||
private CefBrowser browser;
|
||||
public CwbDOMVisitor(CefBrowser browser, CwbBusinStyle businID, string elementID)
|
||||
{
|
||||
_businID = businID;
|
||||
_elementID = elementID;
|
||||
this.browser = browser;
|
||||
}
|
||||
public CwbDOMVisitor(CefBrowser browser, CwbBusinStyle businID, string elementID, string elementValue)
|
||||
{
|
||||
_businID = businID;
|
||||
_elementID = elementID;
|
||||
_elementValue = elementValue;
|
||||
this.browser = browser;
|
||||
}
|
||||
public CwbDOMVisitor(CefBrowser browser, CwbBusinStyle businID, CwbListenerItem item)
|
||||
{
|
||||
this.browser = browser;
|
||||
_businID = businID;
|
||||
_item = item;
|
||||
}
|
||||
protected override void Visit(CefDomDocument document)
|
||||
{
|
||||
CefDomNode element;
|
||||
switch (_businID)
|
||||
{
|
||||
case CwbBusinStyle.bsGetElementValue:
|
||||
|
||||
Global.Result = "";
|
||||
element = document.GetElementById(_elementID);
|
||||
if (element == null)
|
||||
{
|
||||
Global.flag = true;
|
||||
return;
|
||||
}
|
||||
Global.Result = element.Value;
|
||||
if (element.ElementTagName.ToLower() != "input")
|
||||
Global.Result = element.InnerText;
|
||||
Global.flag = true;
|
||||
break;
|
||||
case CwbBusinStyle.bsSetElementValue:
|
||||
element = document.GetElementById(_elementID);
|
||||
if (element == null) return;
|
||||
if (element.IsEditable)
|
||||
element.SetAttribute("value", _elementValue);
|
||||
else
|
||||
{
|
||||
string code = "document.getElementById('{0}').innerHTML = '{1}';";
|
||||
code = string.Format(code,_elementID,_elementValue);
|
||||
Global.instance.ExecuteScript(code);
|
||||
}
|
||||
break;
|
||||
case CwbBusinStyle.bsAddElementEvent:
|
||||
element = document.GetElementById(_item.id);
|
||||
if (element == null) return;
|
||||
//element.AddEventListener(_item.eventName,new RSEventListener(_item.elementListener),true);
|
||||
break;
|
||||
case CwbBusinStyle.bsVisitDocument:
|
||||
Global.flag = false;
|
||||
CefDomNode root = document.Root;
|
||||
CwbElement Root = CreateElement(root);
|
||||
if (Global.RootList.ContainsKey(browser.Identifier))
|
||||
{
|
||||
Global.RootList[ browser.Identifier ] = Root;
|
||||
}
|
||||
else
|
||||
{
|
||||
Global.RootList.Add(browser.Identifier, Root);
|
||||
}
|
||||
string indexPath = "0";
|
||||
Root.IndexPath = indexPath;
|
||||
AppendAllChildElement(root, Root, indexPath);
|
||||
Global.flag = true;
|
||||
break;
|
||||
case CwbBusinStyle.bsAttachElementEvent:
|
||||
CefDomNode root1 = document.Root;
|
||||
string indexPath1 = "0";
|
||||
AttachEventHandler(root1, indexPath1, new RSEventListener(_item.elementListener));
|
||||
Global.flag = true;
|
||||
break;
|
||||
}
|
||||
_businID = CwbBusinStyle.bsNone;
|
||||
}
|
||||
|
||||
public void AttachEventHandler(CefDomNode parentNode, string indexPath, RSEventListener listener)
|
||||
{
|
||||
if (parentNode.HasChildren)
|
||||
{
|
||||
CefDomNode node = parentNode.FirstChild;
|
||||
if (node == null) return;
|
||||
|
||||
int index = 0;
|
||||
string indexPath1 = indexPath + "." + index.ToString();
|
||||
if (indexPath1 == _item.id)
|
||||
{
|
||||
//node.AddEventListener(_item.eventName, listener, true);
|
||||
return;
|
||||
}
|
||||
AttachEventHandler(node, indexPath1, listener);
|
||||
|
||||
node = node.NextSibling;
|
||||
while (node != null)
|
||||
{
|
||||
index++;
|
||||
indexPath1 = indexPath + "." + index.ToString();
|
||||
if (indexPath1 == _item.id)
|
||||
{
|
||||
//node.AddEventListener(_item.eventName, listener, true);
|
||||
return;
|
||||
}
|
||||
AttachEventHandler(node, indexPath1, listener);
|
||||
node = node.NextSibling;
|
||||
System.Windows.Forms.Application.DoEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AppendAllChildElement(CefDomNode parentNode,CwbElement parentElement, string indePath)
|
||||
{
|
||||
if (parentNode.HasChildren)
|
||||
{
|
||||
CefDomNode node = parentNode.FirstChild;
|
||||
if (node == null) return;
|
||||
|
||||
int index = 0;
|
||||
CwbElement childElement = CreateElement(node);
|
||||
childElement.IndexPath = indePath + "."+index.ToString();
|
||||
parentElement.ChildElements.Add(childElement);
|
||||
AppendAllChildElement(node, childElement, childElement.IndexPath);
|
||||
|
||||
node = node.NextSibling;
|
||||
while (node != null)
|
||||
{
|
||||
childElement = CreateElement(node);
|
||||
index++;
|
||||
childElement.IndexPath = indePath + "." + index.ToString();
|
||||
parentElement.ChildElements.Add(childElement);
|
||||
AppendAllChildElement(node, childElement, childElement.IndexPath);
|
||||
node = node.NextSibling;
|
||||
System.Windows.Forms.Application.DoEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private CwbElement CreateElement(CefDomNode node)
|
||||
{
|
||||
string id = string.Empty;
|
||||
if (node.HasAttribute("id"))
|
||||
{
|
||||
id = node.GetAttribute("id");
|
||||
}
|
||||
CwbElement retValue = new CwbElement(browser,id, node.ElementTagName,node.GetAttribute("value"),
|
||||
node.IsElement,node.IsEditable,
|
||||
node.HasChildren,node.InnerText,
|
||||
node.HasAttributes
|
||||
);
|
||||
foreach (KeyValuePair<string, string> item in node.GetAttributes())
|
||||
{
|
||||
retValue.Attributes.Add(item);
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
}
|
||||
|
||||
class RSEventListener //: CefDomEventListener
|
||||
{
|
||||
private ChromeWebBrowser.TCallBackElementEventListener _listener;
|
||||
public RSEventListener(ChromeWebBrowser.TCallBackElementEventListener listener)
|
||||
{
|
||||
_listener = listener;
|
||||
}
|
||||
/*protected override void HandleEvent(CefDomEvent @event)
|
||||
{
|
||||
_listener();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
|
||||
namespace Sashulin.common
|
||||
{
|
||||
internal sealed class CwbDisplayHandler : CefDisplayHandler
|
||||
{
|
||||
private ChromeWebBrowser webBrowser;
|
||||
|
||||
public CwbDisplayHandler(ChromeWebBrowser browser)
|
||||
{
|
||||
webBrowser = browser;
|
||||
}
|
||||
|
||||
protected override void OnTitleChange(CefBrowser browser, string title)
|
||||
{
|
||||
webBrowser.OnTitleChange(title);
|
||||
}
|
||||
|
||||
protected override void OnAddressChange(CefBrowser browser, CefFrame frame, string url)
|
||||
{
|
||||
if (frame.IsMain)
|
||||
{
|
||||
webBrowser.OnUrlChange(url);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnStatusMessage(CefBrowser browser, string value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override bool OnTooltip(CefBrowser browser, string text)
|
||||
{
|
||||
Console.WriteLine("OnTooltip: {0}", text);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
|
||||
namespace Sashulin.common
|
||||
{
|
||||
class CwbJsExtendHandler : CefV8Handler
|
||||
{
|
||||
CefBrowser activeBrowser;
|
||||
public CwbJsExtendHandler(CefBrowser browser)
|
||||
{
|
||||
activeBrowser = browser;
|
||||
}
|
||||
protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
|
||||
{
|
||||
exception = null;
|
||||
switch (name)
|
||||
{
|
||||
case "CallCSharpMethod":
|
||||
string methodName = arguments[0].GetStringValue();
|
||||
string values = arguments[1].GetStringValue();
|
||||
string res = Global.CallMethod(activeBrowser, methodName, values);
|
||||
returnValue = CefV8Value.CreateString(res);
|
||||
return true;
|
||||
case "Connect":
|
||||
string dbName = arguments[0].GetStringValue();
|
||||
Global.cacheDB.Connect(dbName);
|
||||
returnValue = CefV8Value.CreateString("0");
|
||||
return true;
|
||||
case "Execute":
|
||||
string commandSql = arguments[0].GetStringValue();
|
||||
int recordCount = Global.cacheDB.Execute(commandSql);
|
||||
returnValue = CefV8Value.CreateInt(recordCount);
|
||||
return true;
|
||||
case "Query":
|
||||
string querySql = arguments[0].GetStringValue();
|
||||
string records = Global.cacheDB.Query(querySql);
|
||||
returnValue = CefV8Value.CreateString(records);
|
||||
return true;
|
||||
case "Close":
|
||||
Global.cacheDB.Close();
|
||||
returnValue = CefV8Value.CreateString("0");
|
||||
return true;
|
||||
case "PageFinished":
|
||||
Global.instance.OnPageFinished();
|
||||
returnValue = CefV8Value.CreateString("0");
|
||||
return true;
|
||||
}
|
||||
|
||||
returnValue = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
|
||||
namespace Sashulin.common
|
||||
{
|
||||
internal sealed class CwbKeyboardHandler : CefKeyboardHandler
|
||||
{
|
||||
private ChromeWebBrowser webBrowser;
|
||||
|
||||
public CwbKeyboardHandler(ChromeWebBrowser browser)
|
||||
{
|
||||
webBrowser = browser;
|
||||
}
|
||||
|
||||
protected override bool OnPreKeyEvent(CefBrowser browser, CefKeyEvent keyEvent, IntPtr os_event, out bool isKeyboardShortcut)
|
||||
{
|
||||
if (keyEvent.EventType == CefKeyEventType.RawKeyDown)
|
||||
webBrowser.OnPreviewKeyDown(keyEvent.Modifiers == CefEventFlags.AltDown,
|
||||
keyEvent.Modifiers == CefEventFlags.ControlDown,
|
||||
keyEvent.Modifiers == CefEventFlags.ShiftDown,
|
||||
keyEvent.FocusOnEditableField,
|
||||
keyEvent.WindowsKeyCode,
|
||||
keyEvent.Character);
|
||||
|
||||
return base.OnPreKeyEvent(browser, keyEvent, os_event, out isKeyboardShortcut);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
namespace Sashulin.common
|
||||
{
|
||||
internal sealed class CwbLifeSpanHandler : CefLifeSpanHandler
|
||||
{
|
||||
private ChromeWebBrowser webBrowser;
|
||||
public CwbLifeSpanHandler(ChromeWebBrowser browser)
|
||||
{
|
||||
webBrowser = browser;
|
||||
}
|
||||
|
||||
protected override void OnAfterCreated(CefBrowser browser)
|
||||
{
|
||||
base.OnAfterCreated(browser);
|
||||
webBrowser.OnCreated(browser);
|
||||
}
|
||||
|
||||
protected override bool DoClose(CefBrowser browser)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
|
||||
{
|
||||
bool res = false;
|
||||
if (!string.IsNullOrEmpty(targetUrl))
|
||||
{
|
||||
if (webBrowser.selfRequest != null)
|
||||
{
|
||||
CefRequest req = CefRequest.Create();
|
||||
req.FirstPartyForCookies = webBrowser.selfRequest.FirstPartyForCookies;
|
||||
req.Options = webBrowser.selfRequest.Options;
|
||||
/*CefPostData postData = CefPostData.Create();
|
||||
CefPostDataElement element = CefPostDataElement.Create();
|
||||
int index = targetUrl.IndexOf("?");
|
||||
string url = targetUrl.Substring(0, index);
|
||||
string data = targetUrl.Substring(index + 1);
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(data);
|
||||
element.SetToBytes(bytes);
|
||||
postData.Add(element);
|
||||
*/
|
||||
System.Collections.Specialized.NameValueCollection h = new System.Collections.Specialized.NameValueCollection();
|
||||
h.Add("Content-Type", "application/x-www-form-urlencoded");
|
||||
req.Set(targetUrl, webBrowser.selfRequest.Method, null, webBrowser.selfRequest.GetHeaderMap());
|
||||
webBrowser.selfRequest = req;
|
||||
}
|
||||
//webBrowser.selfRequest.Set(targetUrl, webBrowser.selfRequest.Method, webBrowser.selfRequest.PostData, webBrowser.selfRequest.GetHeaderMap());
|
||||
res = webBrowser.OnNewWindow(targetUrl);
|
||||
if (res)
|
||||
return res;
|
||||
}
|
||||
res = base.OnBeforePopup(browser, frame, targetUrl, targetFrameName, targetDisposition, userGesture, popupFeatures, windowInfo, ref client, settings, ref noJavascriptAccess);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Sashulin.common
|
||||
{
|
||||
class CwbListenerItem
|
||||
{
|
||||
private string _id;
|
||||
private string _eventName;
|
||||
private ChromeWebBrowser.TCallBackElementEventListener _listener;
|
||||
|
||||
public string id
|
||||
{
|
||||
get { return _id; }
|
||||
set { _id = value; }
|
||||
}
|
||||
|
||||
public string eventName
|
||||
{
|
||||
get { return _eventName; }
|
||||
set { _eventName = value; }
|
||||
}
|
||||
|
||||
public ChromeWebBrowser.TCallBackElementEventListener elementListener
|
||||
{
|
||||
get { return _listener; }
|
||||
set { _listener = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
namespace Sashulin.common
|
||||
{
|
||||
internal sealed class CwbLoadHandler : CefLoadHandler
|
||||
{
|
||||
private ChromeWebBrowser webBrowser;
|
||||
|
||||
public CwbLoadHandler(ChromeWebBrowser browser)
|
||||
{
|
||||
webBrowser = browser;
|
||||
}
|
||||
|
||||
protected override void OnLoadingStateChange(CefBrowser browser, bool isLoading, bool canGoBack, bool canGoForward)
|
||||
{
|
||||
//_core.OnLoadingStateChanged(isLoading, canGoBack, canGoForward);
|
||||
}
|
||||
|
||||
protected override void OnLoadStart(CefBrowser browser, CefFrame frame)
|
||||
{
|
||||
base.OnLoadStart(browser, frame);
|
||||
webBrowser.OnLoadStart();
|
||||
}
|
||||
|
||||
protected override void OnLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode)
|
||||
{
|
||||
base.OnLoadEnd(browser, frame, httpStatusCode);
|
||||
|
||||
if (frame.IsMain)
|
||||
{
|
||||
//browser.SendProcessMessage(CefProcessId.Renderer, CefProcessMessage.Create("VisitorDocument"));
|
||||
webBrowser.OnDocumentCompleted();
|
||||
}
|
||||
webBrowser.OnLoadEnd();
|
||||
}
|
||||
|
||||
protected override void OnLoadError(CefBrowser browser, CefFrame frame, CefErrorCode errorCode, string errorText, string failedUrl)
|
||||
{
|
||||
base.OnLoadError(browser, frame, errorCode, errorText, failedUrl);
|
||||
if (errorCode == CefErrorCode.Aborted) return;
|
||||
webBrowser.OnLoadError(errorCode, errorText, failedUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Cef3;
|
||||
namespace Sashulin.common
|
||||
{
|
||||
class CwbMenuHandler : CefContextMenuHandler
|
||||
{
|
||||
private ChromeWebBrowser webBrowser;
|
||||
private List<CommandItem> commandItems = new List<CommandItem>();
|
||||
|
||||
public CwbMenuHandler(ChromeWebBrowser browser)
|
||||
{
|
||||
webBrowser = browser;
|
||||
}
|
||||
protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
|
||||
{
|
||||
if (!webBrowser.menuVisible)
|
||||
model.Clear();
|
||||
int commandId = 1001;
|
||||
if (webBrowser.ContextMenu != null)
|
||||
{
|
||||
foreach (MenuItem item in webBrowser.ContextMenu.MenuItems)
|
||||
{
|
||||
if (item.Text == "-")
|
||||
model.AddSeparator();
|
||||
else
|
||||
model.AddItem(commandId, item.Text);
|
||||
CommandItem commandItem = new CommandItem();
|
||||
commandItem.id = commandId;
|
||||
commandItem.item = item;
|
||||
commandItems.Add(commandItem);
|
||||
commandId++;
|
||||
}
|
||||
}
|
||||
|
||||
base.OnBeforeContextMenu(browser, frame, state, model);
|
||||
|
||||
}
|
||||
|
||||
protected override bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags)
|
||||
{
|
||||
foreach (CommandItem commItem in commandItems)
|
||||
{
|
||||
if (commItem.id == commandId)
|
||||
{
|
||||
commItem.item.PerformClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return base.OnContextMenuCommand(browser, frame, state, commandId, eventFlags);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CommandItem
|
||||
{
|
||||
public int id;
|
||||
public MenuItem item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
|
||||
namespace Sashulin.common
|
||||
{
|
||||
class CwbRenderHandler : CefRenderHandler
|
||||
{
|
||||
private ChromeWebBrowser webBrowser;
|
||||
public CwbRenderHandler(ChromeWebBrowser browser)
|
||||
{
|
||||
webBrowser = browser;
|
||||
}
|
||||
|
||||
protected override bool GetRootScreenRect(CefBrowser browser, ref CefRectangle rect)
|
||||
{
|
||||
return base.GetRootScreenRect(browser, ref rect);
|
||||
}
|
||||
protected override void OnScrollOffsetChanged(CefBrowser browser, double x, double y)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void OnCursorChange(CefBrowser browser, IntPtr cursorHandle, CefCursorType type, CefCursorInfo customCursorInfo)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override void OnPopupSize(CefBrowser browser, CefRectangle rect)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override bool GetScreenInfo(CefBrowser browser, CefScreenInfo screenInfo)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
using System.Collections.Specialized;
|
||||
namespace Sashulin.common
|
||||
{
|
||||
class CwbRequestHandler : CefRequestHandler
|
||||
{
|
||||
private ChromeWebBrowser webBrowser;
|
||||
public CwbRequestHandler(ChromeWebBrowser browser)
|
||||
{
|
||||
webBrowser = browser;
|
||||
}
|
||||
protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool isRedirect)
|
||||
{
|
||||
NameValueCollection map = request.GetHeaderMap();
|
||||
request.SetHeaderMap(map);
|
||||
|
||||
webBrowser.selfRequest = request;
|
||||
return base.OnBeforeBrowse(browser, frame, request, isRedirect);
|
||||
}
|
||||
|
||||
protected override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request,CefRequestCallback callback)
|
||||
{
|
||||
return base.OnBeforeResourceLoad(browser, frame, request, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
namespace Sashulin.common
|
||||
{
|
||||
class CwbStringVisitor : CefStringVisitor
|
||||
{
|
||||
internal string source = string.Empty;
|
||||
protected override void Visit(string value)
|
||||
{
|
||||
source = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
namespace Sashulin.common
|
||||
{
|
||||
class FileDownloadHandler : CefDownloadHandler
|
||||
{
|
||||
private ChromeWebBrowser webBrowser;
|
||||
public FileDownloadHandler(ChromeWebBrowser browser)
|
||||
{
|
||||
webBrowser = browser;
|
||||
}
|
||||
|
||||
protected override void OnBeforeDownload(CefBrowser browser, CefDownloadItem downloadItem, string suggestedName, CefBeforeDownloadCallback callback)
|
||||
{
|
||||
callback.Continue(suggestedName, true);
|
||||
base.OnBeforeDownload(browser, downloadItem, suggestedName, callback);
|
||||
webBrowser.OnBeforeDownload();
|
||||
}
|
||||
|
||||
protected override void OnDownloadUpdated(CefBrowser browser, CefDownloadItem downloadItem, CefDownloadItemCallback callback)
|
||||
{
|
||||
base.OnDownloadUpdated(browser, downloadItem, callback);
|
||||
webBrowser.OnDownloading(downloadItem.TotalBytes,
|
||||
downloadItem.ReceivedBytes,
|
||||
downloadItem.CurrentSpeed,
|
||||
downloadItem.PercentComplete,
|
||||
downloadItem.Url,
|
||||
downloadItem.SuggestedFileName,
|
||||
downloadItem.MimeType,
|
||||
downloadItem.IsComplete,
|
||||
downloadItem.IsInProgress);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
|
||||
namespace Sashulin.common
|
||||
{
|
||||
class RenderProcessHandler : CefRenderProcessHandler
|
||||
{
|
||||
private ChromeWebBrowser webBrowser;
|
||||
protected override bool OnProcessMessageReceived(CefBrowser browser, CefProcessId sourceProcess, CefProcessMessage message)
|
||||
{
|
||||
string[] items = message.Name.Split(new char[] {'|'} );
|
||||
if (items.Length == 0) return false;
|
||||
|
||||
switch (items[0])
|
||||
{
|
||||
case "GetElementValue":
|
||||
{
|
||||
string elementID = items[1];
|
||||
long[] frameIDs = browser.GetFrameIdentifiers();
|
||||
foreach (long frameID in frameIDs)
|
||||
{
|
||||
CefFrame frame = browser.GetFrame(frameID);
|
||||
if (frame == null) continue;
|
||||
frame.VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsGetElementValue, elementID));
|
||||
}
|
||||
browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsGetElementValue, elementID));
|
||||
return true;
|
||||
}
|
||||
case "SetElementValue":
|
||||
{
|
||||
string elementID = items[1];
|
||||
string elementValue = items[2];
|
||||
long[] frameIDs = browser.GetFrameIdentifiers();
|
||||
foreach (long frameID in frameIDs)
|
||||
{
|
||||
CefFrame frame = browser.GetFrame(frameID);
|
||||
if (frame == null) continue;
|
||||
frame.VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsGetElementValue, elementID, elementValue));
|
||||
}
|
||||
browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsSetElementValue, elementID, elementValue));
|
||||
return true;
|
||||
}
|
||||
case "EvaluateScript":
|
||||
{
|
||||
CefV8Value value = CefV8Value.CreateString("t");
|
||||
CefV8Exception exp;
|
||||
browser.GetMainFrame().V8Context.TryEval(items[1], out value, out exp);
|
||||
Global.JsEvaResult = null;
|
||||
if (value.IsString)
|
||||
{
|
||||
Global.JsEvaResult = value.GetStringValue();
|
||||
}
|
||||
if (value.IsInt)
|
||||
{
|
||||
Global.JsEvaResult = value.GetIntValue();
|
||||
}
|
||||
if (value.IsDouble)
|
||||
{
|
||||
Global.JsEvaResult = value.GetDoubleValue();
|
||||
}
|
||||
if (value.IsBool)
|
||||
{
|
||||
Global.JsEvaResult = value.GetBoolValue();
|
||||
}
|
||||
if (value.IsDate)
|
||||
{
|
||||
Global.JsEvaResult = value.GetDateValue();
|
||||
}
|
||||
Global.flag = true;
|
||||
return true;
|
||||
}
|
||||
case "AppendListener":
|
||||
{
|
||||
CwbBusinStyle cbStyle = CwbBusinStyle.bsAddElementEvent;
|
||||
if (items.Length > 2)
|
||||
cbStyle = CwbBusinStyle.bsAttachElementEvent;
|
||||
string elementID = items[1];
|
||||
long[] frameIDs = browser.GetFrameIdentifiers();
|
||||
foreach (long frameID in frameIDs)
|
||||
{
|
||||
CefFrame frame = browser.GetFrame(frameID);
|
||||
if (frame == null) continue;
|
||||
frame.VisitDom(new CwbDOMVisitor(browser, cbStyle, webBrowser.getEventListener(elementID)));
|
||||
}
|
||||
browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, cbStyle, webBrowser.getEventListener(elementID)));
|
||||
return true;
|
||||
}
|
||||
case "GetDocument":
|
||||
{
|
||||
browser.GetMainFrame().VisitDom(new CwbDOMVisitor(browser, CwbBusinStyle.bsVisitDocument, ""));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context)
|
||||
{
|
||||
/*缓存数据库*/
|
||||
string extensionCode =
|
||||
"var cachedb;" +
|
||||
"if(!cachedb)" +
|
||||
" cachedb={};" +
|
||||
"(function() {" +
|
||||
" cachedb.Connect = function(dbName) {" +
|
||||
" native function Connect(dbName);" +
|
||||
" return Connect(dbName);" +
|
||||
" };" +
|
||||
|
||||
" cachedb.Execute = function(commandText) {" +
|
||||
" native function Execute(commandText);" +
|
||||
" return Execute(commandText);" +
|
||||
" };" +
|
||||
|
||||
" cachedb.Query = function(commandText) {" +
|
||||
" native function Query(commandText);" +
|
||||
" return Query(commandText);" +
|
||||
" };" +
|
||||
|
||||
" cachedb.Close = function() {" +
|
||||
" native function Close();" +
|
||||
" return Close();" +
|
||||
" };"+
|
||||
|
||||
"})();";
|
||||
CefV8Handler ExtendsionHandler = new CwbJsExtendHandler(browser);
|
||||
CefRuntime.RegisterExtension("v8/cachedb", extensionCode, ExtendsionHandler);
|
||||
|
||||
/*屏幕分辨率设置*/
|
||||
int w = webBrowser.screenWidth;
|
||||
int h = webBrowser.screenHeight;
|
||||
if (w > 0 && h > 0)
|
||||
{
|
||||
string jscode =
|
||||
"Object.defineProperty(window.screen, 'height', {" +
|
||||
" get: function() {"+
|
||||
" return "+h+";"+
|
||||
" }"+
|
||||
"});"+
|
||||
"Object.defineProperty(window.screen, 'width', {"+
|
||||
" get: function() {"+
|
||||
" return "+w+";"+
|
||||
" }"+
|
||||
"});";
|
||||
frame.ExecuteJavaScript(jscode,frame.Url,0);
|
||||
}
|
||||
/*注册执行C#方法*/
|
||||
CefV8Value globalValue = context.GetGlobal();
|
||||
CefV8Handler callHandler = new CwbJsExtendHandler(browser);
|
||||
CefV8Value callMethod = CefV8Value.CreateFunction("CallCSharpMethod", callHandler);
|
||||
globalValue.SetValue("CallCSharpMethod", callMethod, CefV8PropertyAttribute.None);
|
||||
|
||||
callHandler = new CwbJsExtendHandler(browser);
|
||||
callMethod = CefV8Value.CreateFunction("PageFinished", callHandler);
|
||||
globalValue.SetValue("PageFinished", callMethod, CefV8PropertyAttribute.None);
|
||||
base.OnContextCreated(browser, frame, context);
|
||||
|
||||
}
|
||||
|
||||
protected override CefLoadHandler GetLoadHandler()
|
||||
{
|
||||
|
||||
return base.GetLoadHandler();
|
||||
}
|
||||
|
||||
protected override void OnWebKitInitialized()
|
||||
{
|
||||
base.OnWebKitInitialized();
|
||||
}
|
||||
|
||||
protected override void OnBrowserCreated(CefBrowser browser)
|
||||
{
|
||||
base.OnBrowserCreated(browser);
|
||||
}
|
||||
|
||||
protected override bool OnBeforeNavigation(CefBrowser browser, CefFrame frame, CefRequest request, CefNavigationType navigation_type, bool isRedirect)
|
||||
{
|
||||
return base.OnBeforeNavigation(browser, frame, request, navigation_type, isRedirect);
|
||||
}
|
||||
|
||||
public void SetBrowserControl(ChromeWebBrowser browser)
|
||||
{
|
||||
webBrowser = browser;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Cef3;
|
||||
|
||||
namespace Sashulin.common
|
||||
{
|
||||
|
||||
internal sealed class RequestResourceHandler : CefResourceHandler
|
||||
{
|
||||
private static int _requestNo;
|
||||
|
||||
private byte[] responseData;
|
||||
private int pos;
|
||||
|
||||
|
||||
protected override bool ProcessRequest(CefRequest request, CefCallback callback)
|
||||
{
|
||||
var requestNo = Interlocked.Increment(ref _requestNo);
|
||||
|
||||
var response = new StringBuilder();
|
||||
|
||||
response.AppendFormat("<pre>\n");
|
||||
response.AppendFormat("Requests processed by DemoAppResourceHandler: {0}\n", requestNo);
|
||||
|
||||
response.AppendFormat("Method: {0}\n", request.Method);
|
||||
response.AppendFormat("URL: {0}\n", request.Url);
|
||||
|
||||
response.AppendLine();
|
||||
response.AppendLine("Headers:");
|
||||
var headers = request.GetHeaderMap();
|
||||
foreach (string key in headers)
|
||||
{
|
||||
foreach (var value in headers.GetValues(key))
|
||||
{
|
||||
response.AppendFormat("{0}: {1}\n", key, value);
|
||||
}
|
||||
}
|
||||
response.AppendLine();
|
||||
|
||||
response.AppendFormat("</pre>\n");
|
||||
|
||||
responseData = Encoding.UTF8.GetBytes(response.ToString());
|
||||
|
||||
callback.Continue();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
|
||||
{
|
||||
response.MimeType = "text/html";
|
||||
response.Status = 200;
|
||||
response.StatusText = "OK, hello from handler!";
|
||||
|
||||
var headers = new NameValueCollection(StringComparer.InvariantCultureIgnoreCase);
|
||||
headers.Add("Cache-Control", "private");
|
||||
response.SetHeaderMap(headers);
|
||||
|
||||
responseLength = responseData.LongLength;
|
||||
redirectUrl = null;
|
||||
}
|
||||
|
||||
protected override bool ReadResponse(Stream response, int bytesToRead, out int bytesRead, CefCallback callback)
|
||||
{
|
||||
if (bytesToRead == 0 || pos >= responseData.Length)
|
||||
{
|
||||
bytesRead = 0;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Write(responseData, pos, bytesToRead);
|
||||
pos += bytesToRead;
|
||||
bytesRead = bytesToRead;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool CanGetCookie(CefCookie cookie)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override bool CanSetCookie(CefCookie cookie)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void Cancel()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{0662C0B7-3F67-4831-B09B-6C67A212DCBE}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>cwber</RootNamespace>
|
||||
<AssemblyName>cwber</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\引用DLL\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\output\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>cwber.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
<HintPath>..\output\Microsoft.mshtml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SQLite, Version=1.0.77.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\引用DLL\System.Data.SQLite.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CacheDB.cs" />
|
||||
<Compile Include="ChromeWebBrowser.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ChromeWebBrowser.Designer.cs">
|
||||
<DependentUpon>ChromeWebBrowser.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="common\AppSchemeHandlerFactory.cs" />
|
||||
<Compile Include="common\BrowserProcessHandler.cs" />
|
||||
<Compile Include="common\ClientApp.cs" />
|
||||
<Compile Include="common\ClientBrowser.cs" />
|
||||
<Compile Include="common\CwbCookieTask.cs" />
|
||||
<Compile Include="common\CwbCookieVisitor.cs" />
|
||||
<Compile Include="common\CwbDOMVisitor.cs" />
|
||||
<Compile Include="common\CwbJsExtendHandler.cs" />
|
||||
<Compile Include="common\CwbListenerItem.cs" />
|
||||
<Compile Include="common\CwbMenuHandler.cs" />
|
||||
<Compile Include="common\CwbRenderHandler.cs" />
|
||||
<Compile Include="common\CwbStringVisitor.cs" />
|
||||
<Compile Include="common\FileDownloadHandler.cs" />
|
||||
<Compile Include="common\RenderProcessHandler.cs" />
|
||||
<Compile Include="common\RequestResourceHandler.cs" />
|
||||
<Compile Include="common\CwbDisplayHandler.cs" />
|
||||
<Compile Include="common\CwbKeyboardHandler.cs" />
|
||||
<Compile Include="common\CwbLifeSpanHandler.cs" />
|
||||
<Compile Include="common\CwbLoadHandler.cs" />
|
||||
<Compile Include="common\CwbRequestHandler.cs" />
|
||||
<Compile Include="Core\CwbCookie.cs" />
|
||||
<Compile Include="Core\CwbDocument.cs" />
|
||||
<Compile Include="Core\CwbElement.cs" />
|
||||
<Compile Include="cwber_types.cs" />
|
||||
<Compile Include="CwbGlobal.cs" />
|
||||
<Compile Include="JsMethodCall.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="WinApi.cs" />
|
||||
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="ChromeWebBrowser.resx">
|
||||
<DependentUpon>ChromeWebBrowser.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="a.ico" />
|
||||
<Content Include="cwber.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Cef3.24\Cef3.24.csproj">
|
||||
<Project>{9936e27c-dd01-4914-9543-59ce8a5382a1}</Project>
|
||||
<Name>Cef3.24</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 766 B |
@@ -0,0 +1,261 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Cef3;
|
||||
namespace Sashulin
|
||||
{
|
||||
public class CSharpBrowserSettings
|
||||
{
|
||||
public string CachePath;
|
||||
public string Locale;
|
||||
public string LocaleDirPath;
|
||||
public string UserAgent;
|
||||
public string DefaultUrl = "about:blank";
|
||||
}
|
||||
public class TitleEventArgs : EventArgs
|
||||
{
|
||||
private string _title = string.Empty;
|
||||
public TitleEventArgs(string title)
|
||||
{
|
||||
this._title = title;
|
||||
}
|
||||
public string Title
|
||||
{
|
||||
set
|
||||
{
|
||||
_title = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class UrlChangeEventArgs : EventArgs
|
||||
{
|
||||
private string _url = string.Empty;
|
||||
public UrlChangeEventArgs(string url)
|
||||
{
|
||||
this._url = url;
|
||||
}
|
||||
public string Url
|
||||
{
|
||||
set
|
||||
{
|
||||
_url = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return _url;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class NewWindowEventArgs : EventArgs
|
||||
{
|
||||
private string _newurl = string.Empty;
|
||||
private string _title = string.Empty;
|
||||
private object _request = null;
|
||||
public NewWindowEventArgs(string url,object request)
|
||||
{
|
||||
_newurl = url;
|
||||
_request = request;
|
||||
}
|
||||
public string NewUrl
|
||||
{
|
||||
set
|
||||
{
|
||||
_newurl = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return _newurl;
|
||||
}
|
||||
}
|
||||
public object Request
|
||||
{
|
||||
set
|
||||
{
|
||||
_request = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return _request;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class LoadErrorEventArgs : EventArgs
|
||||
{
|
||||
private CefErrorCode _errorCode;
|
||||
private string _errorText;
|
||||
private string _failedUrl;
|
||||
|
||||
public LoadErrorEventArgs(CefErrorCode code,string text,string url)
|
||||
{
|
||||
_errorCode = code;
|
||||
_errorText = text;
|
||||
_failedUrl = url;
|
||||
}
|
||||
|
||||
public CefErrorCode ErrorCode
|
||||
{
|
||||
get { return _errorCode; }
|
||||
set { _errorCode = value;}
|
||||
}
|
||||
public string ErrorText
|
||||
{
|
||||
get { return _errorText; }
|
||||
set { _errorText = value;}
|
||||
}
|
||||
|
||||
public string FailedUrl
|
||||
{
|
||||
get { return _failedUrl; }
|
||||
set { _failedUrl = value;}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class BrowserKeyDownEventArgs
|
||||
{
|
||||
private bool _alt;
|
||||
private bool _ctrl;
|
||||
private bool _shift;
|
||||
private bool _FocusOnEditableField;
|
||||
private System.Windows.Forms.Keys _keyCode;
|
||||
private char _key;
|
||||
|
||||
public BrowserKeyDownEventArgs(bool bAlt,bool bCtrl,bool bShift,bool OnEditor,
|
||||
int keyCode,char key)
|
||||
{
|
||||
_alt = bAlt;
|
||||
_ctrl = bCtrl;
|
||||
_shift = bShift;
|
||||
_FocusOnEditableField = OnEditor;
|
||||
_keyCode = (System.Windows.Forms.Keys)keyCode;
|
||||
_key = key;
|
||||
}
|
||||
|
||||
public bool Alt
|
||||
{
|
||||
get { return _alt; }
|
||||
set { _alt = value; }
|
||||
}
|
||||
|
||||
public bool Ctrl
|
||||
{
|
||||
get { return _ctrl; }
|
||||
set { _ctrl = value; }
|
||||
}
|
||||
|
||||
public bool Shift
|
||||
{
|
||||
get { return _shift; }
|
||||
set { _shift = value; }
|
||||
}
|
||||
|
||||
public bool FocusOnEditableField
|
||||
{
|
||||
get { return _FocusOnEditableField; }
|
||||
set { _FocusOnEditableField = value; }
|
||||
}
|
||||
|
||||
public System.Windows.Forms.Keys KeyCode
|
||||
{
|
||||
get { return _keyCode; }
|
||||
set { _keyCode = value; }
|
||||
}
|
||||
|
||||
public char Key
|
||||
{
|
||||
get { return _key; }
|
||||
set { _key = value; }
|
||||
}
|
||||
|
||||
}
|
||||
public class FileDownloadEventArgs
|
||||
{
|
||||
private long _totalSize;
|
||||
private long _loadSize;
|
||||
private long _speedSize;
|
||||
private int _percentComplete;
|
||||
private string _fileUrl;
|
||||
private string _fileName;
|
||||
private string _mimeType;
|
||||
private bool _IsComplete;
|
||||
private bool _IsInProgress;
|
||||
public FileDownloadEventArgs(long totalSize,
|
||||
long loadSize,
|
||||
long speedSize,
|
||||
int percent,
|
||||
string fileUrl,
|
||||
string fileName,
|
||||
string mimeType,
|
||||
bool isComplete,
|
||||
bool isInProgress)
|
||||
{
|
||||
_totalSize = totalSize;
|
||||
_loadSize = loadSize;
|
||||
_speedSize = speedSize;
|
||||
_percentComplete = percent;
|
||||
_fileUrl = fileUrl;
|
||||
_fileName = fileName;
|
||||
_mimeType = mimeType;
|
||||
_IsComplete = isComplete;
|
||||
_IsInProgress = isInProgress;
|
||||
}
|
||||
|
||||
public long TotalSize
|
||||
{
|
||||
get { return _totalSize; }
|
||||
}
|
||||
|
||||
public long LoadSize
|
||||
{
|
||||
get { return _loadSize; }
|
||||
}
|
||||
|
||||
public long SpeedSize
|
||||
{
|
||||
get { return _speedSize; }
|
||||
}
|
||||
|
||||
public int PercentComplete
|
||||
{
|
||||
get { return _percentComplete; }
|
||||
}
|
||||
|
||||
public string FileUrl
|
||||
{
|
||||
get { return _fileUrl; }
|
||||
}
|
||||
|
||||
public string FileName
|
||||
{
|
||||
get { return _fileName; }
|
||||
}
|
||||
|
||||
public string MimeType
|
||||
{
|
||||
get { return _mimeType; }
|
||||
}
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
get { return _IsComplete; }
|
||||
}
|
||||
|
||||
public bool IsInProgress
|
||||
{
|
||||
get { return _IsInProgress; }
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void FrameLoadErrorHandler(object sender, LoadErrorEventArgs e);
|
||||
public delegate void NewWindowEventHandler(object sender, NewWindowEventArgs e);
|
||||
public delegate void TitleChangeEventHandler(object sender, TitleEventArgs e);
|
||||
public delegate void UrlChangeEventHandler(object sender, UrlChangeEventArgs e);
|
||||
public delegate void PreviewKeyDownEventHandler(object sender, BrowserKeyDownEventArgs e);
|
||||
public delegate void DownloadingEventHandler(object sender, FileDownloadEventArgs e);
|
||||
}
|
||||
Reference in New Issue
Block a user