/// <summary> /// Required for designer support - this method cannot be inlined as the designer /// will attempt to load libcef.dll and will subsiquently throw an exception. /// TODO: Still not happy with this method name, need something better /// </summary> private void InitializeFieldsAndCefIfRequired() { if (!_initialized) { if (!Cef.IsInitialized && !Cef.Initialize(_settings)) { throw new InvalidOperationException("Cef::Initialize() failed"); } Cef.AddDisposable(this); if (ResourceRequestHandlerFactory == null) { ResourceRequestHandlerFactory = new ResourceRequestHandlerFactory(); } if (_browserSettings == null) { _browserSettings = CefSharpBrowserSettings.Create(true); } _managedCefBrowserAdapter = ManagedCefBrowserAdapter.Create(this, false); _initialized = true; } }
public FrmRestrictedWebBrowser() { InitializeComponent(); try { //webBrowser.StatusTextChanged += WebBrowser_StatusTextChanged; //webBrowser.ProgressChanged += WebBrowser_ProgressChanged; cwb.Dock = DockStyle.Fill; cwb.ContextMenu = null; cwb.ConsoleMessage += Cwb_ConsoleMessage; cwb.StatusMessage += Cwb_StatusMessage; cwb.NavStateChanged += Cwb_NavStateChanged; cwb.LoadError += Cwb_LoadError; CefSharp.BrowserSettings cbs = new CefSharp.BrowserSettings(); cbs.ApplicationCacheDisabled = true; cbs.FileAccessFromFileUrlsAllowed = false; cbs.JavaScriptCloseWindowsDisabled = true; cbs.PluginsDisabled = true; cbs.WebSecurityDisabled = false; cwb.BrowserSettings = cbs; CefSharp.CefSettings cs = new CefSharp.CefSettings(); cs.IgnoreCertificateErrors = true; cs.UserAgent = GlobalSettings.RestrictedBrowserUserAgent; cwb.AllowDrop = false; this.Controls.Add(cwb); } catch (Exception) { throw; } }
public MainForm() { CefSettings settings = new CefSettings(); settings.UserAgent = "SMART-TV; Tizen 4.0"; settings.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\YouTubeTV\cache"; CefSharp.Cef.Initialize(settings); InitializeComponent(); this.BackColor = Color.FromArgb(40, 40, 40); Text = String.Format(Text, Settings.Version, Cef.ChromiumVersion, Cef.CefVersion); var browserSettings = new CefSharp.BrowserSettings(); browserSettings.BackgroundColor = Cef.ColorSetARGB(255, 40, 40, 40); browser = new ChromiumWebBrowser("https://youtube.com/tv"); browser.BrowserSettings = browserSettings; browser.Dock = DockStyle.Fill; browser.BackColor = Color.FromArgb(40, 40, 40); browser.KeyUp += Browser_KeyUp; Controls.Add(browser); }
internal void StartBrowser(int width, int height) { var cefWindowInfo = new CefSharp.WindowInfo(); cefWindowInfo.SetAsWindowless(IntPtr.Zero); cefWindowInfo.Width = width; cefWindowInfo.Height = height; var cefBrowserSettings = new CefSharp.BrowserSettings(); cefBrowserSettings.WindowlessFrameRate = 60; cefBrowserSettings.FileAccessFromFileUrls = CefState.Enabled; cefBrowserSettings.UniversalAccessFromFileUrls = CefState.Enabled; cefBrowserSettings.WebSecurity = CefState.Enabled; cefBrowserSettings.Javascript = CefState.Enabled; cefBrowserSettings.LocalStorage = CefState.Enabled; cefBrowserSettings.Plugins = CefState.Disabled; CefBrowser.CreateBrowser(cefWindowInfo, cefBrowserSettings); }
/// <summary> /// Lets mark such methods with some special tag, like: /// /// #ExtraInit MainWebView /// /// so we would be able to locate them, if necessary, with text search. /// </summary> protected override void InitializeComponent() //TODO: why override and where that initialization should really happen, here!? { base.InitializeComponent(); //some extra initialization, seciffic to current task only //this.AutomaticUpdater = new wyDay.Controls.AutomaticUpdater(); //((System.ComponentModel.ISupportInitialize)(this.automaticUpdater)).BeginInit(); //this.SuspendLayout(); // // webBrowser // //AutoValidate = System.Windows.Forms.AutoValidate.Disable; BrowserSettings = new CefSharp.BrowserSettings() { FileAccessFromFileUrlsAllowed = true, UniversalAccessFromFileUrlsAllowed = true, TextAreaResizeDisabled = true }; BackColor = System.Drawing.SystemColors.Window; //BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; CausesValidation = false; //Cursor = System.Windows.Forms.Cursors.Hand; Dock = System.Windows.Forms.DockStyle.Fill; Location = new System.Drawing.Point(0, 0); //Size = new System.Drawing.Size(300, 400); Name = "webBrowser"; RightToLeft = System.Windows.Forms.RightToLeft.No; TabIndex = 0; //Address = ViewUrl.ToString(); //this.ResumeLayout(false); //this.PerformLayout(); ContextMenu = null; MenuHandler = new MenuHandlerToDisableContextMenu(); loadMainViewUrlOnceOnInitialization = new Action(this.Load); }
/// <summary> /// Lets mark such methods with some special tag, like: /// /// #ExtraInit MainWebView /// /// so we would be able to locate them, if necessary, with text search. /// </summary> protected override void InitializeComponent() {//TODO: why override and where that initialization should really happen, here!? base.InitializeComponent(); //some extra initialization, seciffic to current task only //this.AutomaticUpdater = new wyDay.Controls.AutomaticUpdater(); //((System.ComponentModel.ISupportInitialize)(this.automaticUpdater)).BeginInit(); //this.SuspendLayout(); // // webBrowser // //AutoValidate = System.Windows.Forms.AutoValidate.Disable; BrowserSettings = new CefSharp.BrowserSettings() { FileAccessFromFileUrlsAllowed = true, UniversalAccessFromFileUrlsAllowed = true, TextAreaResizeDisabled = true }; BackColor = System.Drawing.SystemColors.Window; //BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; CausesValidation = false; //Cursor = System.Windows.Forms.Cursors.Hand; Dock = System.Windows.Forms.DockStyle.Fill; Location = new System.Drawing.Point(0, 0); //Size = new System.Drawing.Size(300, 400); Name = "webBrowser"; RightToLeft = System.Windows.Forms.RightToLeft.No; TabIndex = 0; //Address = ViewUrl.ToString(); //this.ResumeLayout(false); //this.PerformLayout(); ContextMenu = null; MenuHandler = new MenuHandlerToDisableContextMenu(); loadMainViewUrlOnceOnInitialization = new Action(this.Load); }
private void SetWebBrowserAttr() { try { this.strPrevFileName = ""; this.strPrevTotalText = ""; // ファイル名が有効ならば、それをWebBrowserでナビゲート var strStartFileName = Hm.Edit.FilePath ?? ""; if (wb == null) { if (!Cef.IsInitialized) { var settings = new CefSharp.CefSettings(); // By default CEF uses an in memory cache, to save cached data e.g. passwords you need to specify a cache path // NOTE: The executing user must have sufficient privileges to write to this folder. //settings.CachePath = @"C:\Users\0300002167\AppData\Local\Google\Chrome\User Data"; settings.LocalesDirPath = Hm.Macro.Var["currentmacrodirectory"] + @"\Locales"; settings.AcceptLanguageList = "ja-JP"; settings.Locale = "ja"; CefSharp.Cef.Initialize(settings); } wb = new CefSharp.WinForms.ChromiumWebBrowser(strStartFileName); CefSharp.BrowserSettings bs = new CefSharp.BrowserSettings { LocalStorage = CefSharp.CefState.Enabled, FileAccessFromFileUrls = CefSharp.CefState.Enabled, UniversalAccessFromFileUrls = CefSharp.CefState.Enabled, ApplicationCache = CefSharp.CefState.Enabled, AcceptLanguageList = "ja-JP", }; wb.BrowserSettings = bs; wb.Dock = DockStyle.Fill; wb.LoadingStateChanged += wb_LoadingStateChanged; wb.AddressChanged += wb_AddressChanged; if (strStartFileName == "") { wb_LoadHtml(Hm.Edit.TotalText); } this.Controls.Add(wb); } else { if (strStartFileName == "") { wb.ResetText(); wb_LoadHtml(Hm.Edit.TotalText); } else { wb.ResetText(); wb.Load(strStartFileName); wb.Refresh(); } } } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.Message); } }