private void Test2Button_Click(object sender, EventArgs e) { // This is demonstration of async browser construction. // .Load method raises exception with message 'CefBrowser is not ready.', cause underlying CefBrowser doesn't created. // I propose to that .Load method locks internally and wait for CefBrowser (AfterHandleCreated message). // But note, that lock also lock main message loop (if called from UI thread), or we can got inifinite lock, if no message arrived - so some timeout required. // If we have plans to support singlethreaded cef message loop - we must process cef message loop. // We can give name for event AfterHandleCreated as BrowserReady or Ready. // Note, that this is event only signals, that browser constructed, - this is NOT DocumentReady or Navigated. // Also .BrowserReady event is good, but method to perform sync operation also can be useful. PrepareTest(); browser = new CefWebBrowser(); browser.Parent = panel; browser.Dock = DockStyle.Fill; try { browser.Load("http://google.com"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void InitWebPage(string url) { var webbrowser = new CefWebBrowser(); webbrowser.StartUrl = url; webbrowser.Dock = DockStyle.Fill; webbrowser.TitleChanged += (s, e) => { BeginInvoke(new Action(() => { if (webbrowser.Title == null || webbrowser.Title == "" || webbrowser.Title == "index.html") { return; } string title = webbrowser.Title; this.Text = title; CefBrowser browser = webbrowser.Browser; CefFrame frame = webbrowser.Browser.GetMainFrame(); //CefV8Value obj = // Execute JS code without result // CefBrowser browser = webbrowser.Browser; // CefFrame frame = webbrowser.Browser.GetMainFrame(); // frame.ExecuteJavaScript("alert('Hi!');", frame.Url, 0); })); }; this.Controls.Add(webbrowser); }
protected void AddTab() { var tabPage = new TabPage(); tabPage.Text = "blank"; var browser = new CefWebBrowser(); browser.Dock = DockStyle.Fill; tabPage.DockPadding.Top = 25; tabPage.Dock = DockStyle.Fill; // add a handler showing how to view the DOM //browser.DocumentCompleted += (s, e) => TestQueryingOfDom(browser); // add a handler showing how to modify the DOM. //browser.DocumentCompleted += (s, e) => TestModifyingDom(browser); AddToolbarAndBrowserToTab(tabPage, browser); m_tabControl.TabPages.Add(tabPage); tabPage.Show(); m_tabControl.SelectedTab = tabPage; // Uncomment this to stop links from navigating. // browser.DomClick += StopLinksNavigating; }
protected override void OnCreate(ref CreateWindowPacket packet) { try { CefRuntime.Load(); } catch (Exception ex) { throw ex; } var mainArgs = new CefMainArgs(HostConfig.AppArgs); var app = new CefWebApp(HostConfig); var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero); if (exitCode != -1) { return; } var codeBase = Assembly.GetExecutingAssembly().CodeBase; var localFolder = Path.GetDirectoryName(new Uri(codeBase).LocalPath); var localesDirPath = Path.Combine(localFolder, "locales"); var settings = new CefSettings { LocalesDirPath = localesDirPath, Locale = HostConfig.Locale, SingleProcess = false, MultiThreadedMessageLoop = true, LogSeverity = (CefLogSeverity)HostConfig.LogSeverity, LogFile = HostConfig.LogFile, ResourcesDirPath = Path.GetDirectoryName(new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath), NoSandbox = true }; // Update configuration settings settings.Update(HostConfig.CustomSettings); CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero); RegisterSchemeHandlers(); RegisterMessageRouters(); CefBrowserConfig browserConfig = new CefBrowserConfig(); browserConfig.StartUrl = HostConfig.StartUrl; browserConfig.ParentHandle = Handle; browserConfig.AppArgs = HostConfig.AppArgs; browserConfig.CefRectangle = new CefRectangle { X = 0, Y = 0, Width = HostConfig.HostWidth, Height = HostConfig.HostHeight }; m_browser = new CefWebBrowser(browserConfig); base.OnCreate(ref packet); Log.Info("Cef browser successfully created."); }
private void Form1_Load(object sender, EventArgs e) { string url = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), @"Htmls\Main.html"); url = "local" + url.Replace(":", string.Empty); string debug = System.Configuration.ConfigurationManager.AppSettings["Debug"]; if (!string.IsNullOrWhiteSpace(debug) && bool.Parse(debug) == true) { txtUrl.Text = url; panel1.Visible = true; } browser = new CefWebBrowser(); browser.StartUrl = "localapp/" + this.GetType().Namespace + "/Htmls/Main.html"; browser.Dock = DockStyle.Fill; browser.BackColor = Color.White; browser.ProcessMessageReceived += Browser_ProcessMessageReceived; panel2.Controls.Add(browser); }
private void PrepareTest() { if (browser != null) { browser.Dispose(); browser = null; } }
void BrowserWindow_Loaded(object sender, RoutedEventArgs e) { _browser = new CefWebBrowser(this._initUrl); this._browser.AutoSize = true; this.xWinFormHost.Child = this._browser; this.Unloaded += BrowserWindow_Unloaded; }
private void browserCloseMenuItem_Click(object sender, EventArgs e) { if (this.browser != null) { this.browser.Dispose(); this.browser = null; } }
private void NewTab(string startUrl) { var page = new TabPage(); page.Padding = new Padding(0, 0, 0, 0); var browser = new CefWebBrowser(); browser.BrowserSettings = new CefBrowserSettings { //控制文件的URL是否将有机会获得其他的文件的URL FileAccessFromFileUrls = CefState.Enabled, //控制的JavaScript是否可以访问剪贴板 JavaScriptAccessClipboard = CefState.Enabled, //控制是否网络安全限制,是否禁止跨站脚本 WebSecurity = CefState.Disabled, //控制文件的URL是否可以访问所有的URL UniversalAccessFromFileUrls = CefState.Enabled, //应用程序的缓存是否可以使用 ApplicationCache = CefState.Enabled, //控制光标的位置是否将被绘制 CaretBrowsing = CefState.Enabled, //是否可以使用数据库 Databases = CefState.Enabled, //硬件加速 AcceleratedCompositing = CefState.Enabled, //控制本地存储是否可以使用 LocalStorage = CefState.Enabled, //3D计算机图形的技术 WebGL = CefState.Enabled, }; browser.StartUrl = startUrl; browser.Dock = DockStyle.Fill; //browser.TitleChanged += (s, e) => // { // BeginInvoke(new Action(() => // { // string title = browser.Title; // if (tabControl.SelectedTab == page) // { // Text = browser.Title + " - " + _mainTitle; // } // page.ToolTipText = title; // if (title.Length > 18) // { // title = title.Substring(0, 18) + "..."; // } // page.Text = title; // })); // }; //browser.AddressChanged += // (s, e) => { BeginInvoke(new Action(() => { addressTextBox.Text = browser.Address; })); }; // browser.StatusMessage += (s, e) => { BeginInvoke(new Action(() => { statusLabel.Text = e.Value; })); }; this.Controls.Add(browser); //page.Controls.Add(browser); //tabControl.TabPages.Add(page); //tabControl.SelectedTab = page; }
public MainForm() { InitializeComponent(); CefWebBrowser cb = new CefWebBrowser(); cb.StartUrl = "http://localhost:1795/index.html"; this.Controls.Add(cb); cb.Dock = DockStyle.Fill; }
public void HandleBeforeResourceLoad(CefWebBrowser browserControl, IRequestResponse requestResponse) { IRequest request = requestResponse.Request; if (request.Url.StartsWith(testPagesBaseUrl)) { var url = request.Url.Substring(testPagesBaseUrl.Length); var stream = GetStream(url); requestResponse.RespondWith(stream, "text/html"); } }
public Window(HostBase application, ChromelyConfiguration hostConfig) : base(hostConfig.HostTitle, hostConfig.HostWidth, hostConfig.HostHeight, hostConfig.HostIconFile) { m_hostConfig = hostConfig; m_core = new CefWebBrowser(this, new CefBrowserSettings(), hostConfig.StartUrl); m_core.Created += new EventHandler(BrowserCreated); m_application = application; ShowWindow(); }
void MainForm_Shown(object sender, EventArgs e) { WebBrowser = new CefWebBrowser("http://google.com"); WebBrowser.Parent = MainForm; WebBrowser.Dock = DockStyle.Fill; WebBrowser.WaitForLoadCompletion(); WebBrowser.BeforeResourceLoadHandler = this; waitCreated.Set(); }
public Browser() { InitializeComponent(); Text = "CefSharp"; _browserControl = new CefWebBrowser(cefSharpHomeUrl); _browserControl.Dock = DockStyle.Fill; _browserControl.PropertyChanged += HandleBrowserPropertyChanged; _browserControl.ConsoleMessage += HandleConsoleMessage; _browserControl.BeforeResourceLoadHandler = this; toolStripContainer.ContentPanel.Controls.Add(_browserControl); }
public void HandleBeforeResourceLoad(CefWebBrowser browserControl, IRequestResponse requestResponse) { IRequest request = requestResponse.Request; if(request.Url.StartsWith("http://test/resource/load")) { Stream resourceStream = new MemoryStream(Encoding.UTF8.GetBytes( "<html><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p></body></html>")); requestResponse.RespondWith(resourceStream, "text/html"); } Console.WriteLine(request.Url); }
public CefWebMedia(RegionOptions options) : base(options.width, options.height, options.top, options.left) { // Collect some options from the Region Options passed in // and store them in member variables. _options = options; // Set the file path _filePath = ApplicationSettings.Default.LibraryPath + @"\" + _options.mediaid + ".htm"; Color backgroundColor = ColorTranslator.FromHtml(_options.backgroundColor); CefBrowserSettings settings = new CefBrowserSettings(); settings.BackgroundColor = new CefColor(backgroundColor.A, backgroundColor.R, backgroundColor.G, backgroundColor.B); // Create the web view we will use _webView = new CefWebBrowser(); _webView.BrowserSettings = settings; _webView.Dock = DockStyle.Fill; _webView.BrowserCreated += _webView_BrowserCreated; _webView.LoadEnd += _webView_LoadEnd; _webView.Size = Size; // Check to see if the HTML is ready for us. if (HtmlReady()) { // Write to temporary file ReadControlMeta(); _startWhenReady = true; } else { RefreshFromXmds(); } // We need to come up with a way of setting this control to Visible = false here and still kicking // off the webbrowser. // I think we can do this by hacking some bits into the Cef.WinForms dll. // Currently if we set this to false a browser isn't initialised by the library because it initializes it in OnHandleCreated // We also need a way to protect against the web browser never being created for some reason. // If it isn't then the control will never exipre (we might need to start the timer and then reset it). // Maybe: // Start the timer and then base.RestartTimer() in _webview_LoadEnd //base.StartTimer(); //_webView.Visible = false; Controls.Add(_webView); // Show the control Show(); }
private void Form1_Load(object sender, EventArgs e) { browser = new CefWebBrowser { Visible = true, //StartUrl = "http://www.google.com", Dock = DockStyle.Fill, Parent = this }; Controls.Add(browser); browser.BrowserCreated += BrowserOnBrowserCreated; }
private void Test1Button_Click(object sender, EventArgs e) { // This is "default" usage of control. // We don't call CEF.Initialization - it's called implicitly by CefWebBrowser constructor. // Note, that CEF.Shutdown must called explicitly. // Also, CEF.Shutdown now is safe to call, even if CEF.Initialization not called before. PrepareTest(); browser = new CefWebBrowser("http://google.com"); browser.Parent = panel; browser.Dock = DockStyle.Fill; }
public void HandleBeforeResourceLoad(CefWebBrowser browserControl, IRequestResponse requestResponse) { IRequest request = requestResponse.Request; if (request.Url.StartsWith("http://test/resource/load")) { Stream resourceStream = new MemoryStream(Encoding.UTF8.GetBytes( "<html><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p></body></html>")); requestResponse.RespondWith(resourceStream, "text/html"); } Console.WriteLine(request.Url); }
private void NewTab(string startUrl) { var page = new TabPage("New Tab"); page.Padding = new Padding(0, 0, 0, 0); var browser = new CefWebBrowser(); browser.IsCanShowContextMenu = true; //是否显示右键菜单 browser.IsCanShowPopWindow = false; //是否弹窗 browser.StartUrl = startUrl; browser.Dock = DockStyle.Fill; this.panelContainer.Controls.Add(browser); }
public MainForm() { InitializeComponent(); // Create the new CefWebBrowser control. this.c_WebBrowser = new CefWebBrowser("application://termkit/index.html"); this.c_WebBrowser.Dock = DockStyle.Fill; this.c_WebBrowser.Visible = true; this.c_WebBrowser.BeforeResourceLoadHandler = this; this.c_WebBrowser.ConsoleMessage += new ConsoleMessageEventHandler(c_WebBrowser_ConsoleMessage); this.Controls.Add(this.c_WebBrowser); // Register the schemes. CEF.RegisterScheme("application", new ApplicationProtocolFactory()); CEF.RegisterScheme("termkit-icon-preview", new TermKitIconPreviewProtocolFactory()); CEF.RegisterScheme("termkit-icon-default", new TermKitIconDefaultProtocolFactory()); }
private void CreateBrowserControl() { this.browser = new CefWebBrowser(browserSettings, homeUrl); browser.Dock = DockStyle.Fill; browser.BackColor = Color.White; browser.CanGoBackChanged += new EventHandler(browser_CanGoBackChanged); browser.CanGoForwardChanged += new EventHandler(browser_CanGoForwardChanged); browser.AddressChanged += new EventHandler(browser_AddressChanged); browser.TitleChanged += new EventHandler(browser_TitleChanged); // TODO: browser.StatusMessage += new EventHandler<StatusMessageEventArgs>(browser_StatusMessage); browser.ConsoleMessage += new EventHandler <ConsoleMessageEventArgs>(browser_ConsoleMessage); // TODO: browser.IsLoadingChanged += new EventHandler(browser_IsLoadingChanged); browser.Parent = this; browser.BringToFront(); }
private void NewTab(string startUrl) { var page = new TabPage("New Tab"); page.Padding = new Padding(0, 0, 0, 0); var browser = new CefWebBrowser(); browser.StartUrl = startUrl; browser.Dock = DockStyle.Fill; browser.TitleChanged += (s, e) => { BeginInvoke(new Action(() => { var title = browser.Title; if (tabControl.SelectedTab == page) { title = Text = browser.Title + " - " + _mainTitle; } page.ToolTipText = title; if (title.Length > 18) { title = title.Substring(0, 18) + "..."; } page.Text = title; })); }; browser.AddressChanged += (s, e) => { BeginInvoke(new Action(() => { addressTextBox.Text = browser.Address; })); }; browser.StatusMessage += (s, e) => { BeginInvoke(new Action(() => { statusLabel.Text = e.Value; })); }; page.Controls.Add(browser); tabControl.TabPages.Add(page); tabControl.SelectedTab = page; }
public bool InitializeBrowser() { AllocConsole(); CefRuntime.Load(); var settings = new CefSettings(); settings.MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows; settings.ReleaseDCheckEnabled = true; settings.LogSeverity = CefLogSeverity.Info; settings.LogFile = "cef.log"; //settings.ResourcesDirPath = System.IO.Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath); settings.RemoteDebuggingPort = 20480; settings.Locale = "zh-CN"; var a = Config.JsFunctionAssembly; var mainArgs = new CefMainArgs(new string[0]); var app = new DemoCefApp(); var exitCode = CefRuntime.ExecuteProcess(mainArgs, app); Console.WriteLine("CefRuntime.ExecuteProcess() returns {0}", exitCode); //返回值-1为成功 if (exitCode != -1) { return(false); } //初始化 CefRuntime.Initialize(mainArgs, settings, app); CefRuntime.RegisterSchemeHandlerFactory("http", DumpRequestDomain, new DemoAppSchemeHandlerFactory()); browserCtl = new CefWebBrowser(); browserCtl.Parent = this.panel1; browserCtl.Dock = DockStyle.Fill; browserCtl.BringToFront(); var browser = browserCtl.WebBrowser; browser.StartUrl = HomeUrl; //navBox.Attach(browser); return(true); }
private void addBrowser() { #region BrowserSettings browserSettings = new BrowserSettings(); browserSettings.FileAccessFromFileUrlsAllowed = true; browserSettings.UniversalAccessFromFileUrlsAllowed = true; browserSettings.TextAreaResizeDisabled = true; browserSettings.DefaultEncoding = "utf-8"; //browserSettings.cef this._browser = new CefWebBrowser(""); this._browser.BrowserSettings = browserSettings; this._browser.Dock = DockStyle.Fill; this.Controls.Add(this._browser); //将c#定义的对象映射到js中 this._browser.RegisterJsObject("appHandler", AppHandler.Intance); #endregion }
public void Startup() { WebAppLogger.Log(WebAppLogLevel.Info, "Chromium Startup"); _browserContainer.Dock = DockStyle.Fill; _browser = new CefWebBrowser(this, this.Width, this.Height); _browser.OnProcessMessage += ProcessMessage; _browser.BrowserReady += BrowserReady; _browser.BackColor = Color.DarkRed; _browser.StartUrl = "https://google.com"; _browser.Dock = DockStyle.Fill; _browserContainer.Controls.Add(_browser); Controls.Add(_browserContainer); //Opacity = 0; //Show(); //Hide(); //Opacity = 1; }
public SparkleEventLog() { InitializeComponent (); Program.TranslateWinForm (this); this.Icon = Icons.sparkleshare; this.change_sets = Program.Controller.GetLog (null); GenerateHTML (); _browserControl = new CefWebBrowser ("application://sparkleshare/eventlog"); _browserControl.Dock = DockStyle.Fill; //_browserControl.PropertyChanged += HandleBrowserPropertyChanged; //_browserControl.ConsoleMessage += HandleConsoleMessage; _browserControl.BeforeResourceLoadHandler = this; WebViewPanel.Controls.Add (_browserControl); UpdateChooser (); }
public void HandleBeforeResourceLoad(CefWebBrowser browserControl, IRequestResponse requestResponse) { IRequest request = requestResponse.Request; Console.WriteLine ("{0} {1}", request.Method, request.Url); if (request.Url.StartsWith ("application://sparkleshare/eventlog")) { Stream resourceStream; if (HTML != null) resourceStream = new MemoryStream (Encoding.UTF8.GetPreamble ().Concat (Encoding.UTF8.GetBytes (HTML)).ToArray ()); else resourceStream = new MemoryStream (); requestResponse.RespondWith (resourceStream, "text/html"); } else if (request.Url.StartsWith ("application://file/")) { string Filename = request.Url.Substring ("application://file/".Length); Filename = Uri.UnescapeDataString (Filename); Filename = Filename.Replace ("/", "\\"); if (Filename.StartsWith(SparkleConfig.DefaultConfig.FoldersPath)) System.Diagnostics.Process.Start (Filename); } }
private void NewTab(string startUrl) { var page = new TabPage("New Tab"); page.Padding = new Padding(0, 0, 0, 0); var browser = new CefWebBrowser(); browser.IsCanShowContextMenu = true;//是否显示右键菜单 //browser.IsCanShowPopWindow = false;//是否弹窗 //设定其存储Cookie的路径 //var ckManager = CefCookieManager.GetGlobal(null); ; //ckManager.SetStoragePath(CookieStorgePath, true,null); browser.StartUrl = startUrl; browser.Dock = DockStyle.Fill; browser.TitleChanged += (s, e) => { BeginInvoke(new Action(() => { var title = browser.Title; if (tabControl.SelectedTab == page) { Text = browser.Title + " - " + _mainTitle; } page.ToolTipText = title; if (null != title && title.Length > 18) { title = title.Substring(0, 18) + "..."; } page.Text = title; })); }; browser.AddressChanged += (s, e) => { BeginInvoke(new Action(() => { addressTextBox.Text = browser.Address; })); }; browser.StatusMessage += (s, e) => { BeginInvoke(new Action(() => { statusLabel.Text = e.Value; })); }; //文档加载完毕后触发的事件 browser.LoadEnd += (s, e) => { int x = e.HttpStatusCode; }; //弹出窗口的处理 browser.BeforePopup += (s, e) => { string targetUrl = e.TargetUrl; if (string.IsNullOrEmpty(targetUrl)) { return; } }; // page.Tag = browser;//tabpage 绑定浏览器对象 page.Controls.Add(browser); tabControl.TabPages.Add(page); tabControl.SelectedTab = page; }
public CefWebLoadHandler(CefWebBrowser core) { _core = core; }
public CefWebRequestHandler(CefWebBrowser core) { _core = core; }
public CefGlueBrowserHost(ChromelyConfiguration hostConfig) { HostConfig = hostConfig; m_browser = null; ServiceAssemblies = new List <Assembly>(); }
public void HandleBeforeResourceLoad(CefWebBrowser browserControl, IRequestResponse requestResponse) { System.Diagnostics.Debugger.Log(1, "Resource", "The resource " + requestResponse.Request.Url + " was requested.\r\n"); }
private void NewTab(string startUrl) { var page = new TabPage("New Tab"); page.Padding = new Padding(0, 0, 0, 0); var browser = new CefWebBrowser(); browser.StartUrl = startUrl; browser.Dock = DockStyle.Fill; browser.TitleChanged += (s, e) => { BeginInvoke(new Action(() => { var title = browser.Title; if (tabControl.SelectedTab == page) { borrowTitle = browser.Title; Text = browser.Title + " - " + _mainTitle; } page.ToolTipText = title; if (title.Length > 18) { title = title.Substring(0, 18) + "..."; } page.Text = title; })); }; browser.AddressChanged += (s, e) => { BeginInvoke(new Action(() => { addressTextBox.Text = browser.Address; })); }; browser.StatusMessage += (s, e) => { BeginInvoke(new Action(() => { // statusLabel.Text = e.Value; })); }; browser.LoadEnd += (s, e) => { BeginInvoke(new Action(() => { statusLabel.Text = "status:" + e.HttpStatusCode.ToString(); //InitZfbSQ(); //Init_tb_reg(); //tbV3_Init_reg(); //IsInit_wapshop(); // OnPageLoaded_TB_Shopping(s, e); // OnPageLoaded_163_Reg(s, e); // OnPageLoaded_zfb_Reg(s, e); // OnPageLoaded_pp_Ads(s, e); // OnPageLoaded_JiShi(); // InitAuto();//装载自动的相关步骤 })); }; //在此注册 //弹出 // browser.BeforePopup += browser_BeforePopup; browser.BeforePopup += (s, e) => { BeginInvoke(new Action(() => { //if (Common.FileHelper1.read("//config//chromeconfig.txt")[0] == "true") { // e.Handled = true; //} if (e.TargetUrl != "http://mobile.alipay.com/index.htm") { browser.Browser.GetMainFrame().LoadUrl(e.TargetUrl); } //e.Frame.LoadUrl(e.TargetUrl); })); }; // page.Controls.Add(browser); tabControl.TabPages.Add(page); tabControl.SelectedTab = page; }
public HomePageCefWebClient(CefWebBrowser cefWebBrowser) : base(cefWebBrowser) { this.cefWebBrowser = cefWebBrowser; }
public CefTesteClient(CefWebBrowser cefWebBrowser) : base(cefWebBrowser) { this.cefWebBrowser = cefWebBrowser; }