void CreateBrowser() { if (!isCefRuntimeInitialized) { InitializeCefRuntime(); } if (isCefRuntimeInitialized) { this.viewSize = GetNeededSize(); var windowInfo = CefWindowInfo.Create(); windowInfo.SetAsWindowless(IntPtr.Zero, false); var client = new WebClient(this); var settings = new CefBrowserSettings { // AuthorAndUserStylesDisabled = false, }; CefBrowserHost.CreateBrowser(windowInfo, client, settings, !string.IsNullOrEmpty(StartURL) ? StartURL : "about:blank"); if (!string.IsNullOrEmpty(startUrl)) { LoadURL(startUrl); } } }
public BaseCEFClient CreateBrowser(BaseCEFClient client = null, string url = null) { if (!initialized) { return(null); } if (client == null) { client = new BaseCEFClient(BrowserPageWidth, BrowserPageHeight); } var browserSettings = new CefBrowserSettings() { JavaScript = JSRunnable? CefState.Enabled : CefState.Disabled, WindowlessFrameRate = frameRate }; var windowSettings = CefWindowInfo.Create(); windowSettings.SetAsWindowless(IntPtr.Zero, false); if (url != null) { CefBrowserHost.CreateBrowser(windowSettings, client, browserSettings, url); } else { CefBrowserHost.CreateBrowser(windowSettings, client, browserSettings); } registeredClients.Add(client); return(client); }
public void HandleAfterCreated(CefBrowser browser) { int width = 0, height = 0; bool hasAlreadyBeenInitialized = false; _mainUiDispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate { if (_browser != null) { hasAlreadyBeenInitialized = true; } else { _browser = browser; _browserHost = _browser.GetHost(); _App.Associate(_browser, this); // _browserHost.SetFocus(IsFocused); width = (int)_browserWidth; height = (int)_browserHeight; } })); // Make sure we don't initialize ourselves more than once. That seems to break things. if (hasAlreadyBeenInitialized) { return; } if (width > 0 && height > 0) { _browserHost.WasResized(); } }
/// <summary> /// 加载Cef相关的资源 /// </summary> public MainUIRender(GraphicsDevice gd, IntPtr handle, uint windwosWidth, uint windowsHeight) { _gd = gd; _windowsHeight = windowsHeight; _windowsWidth = windwosWidth; CefWindowInfo cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsWindowless(handle, true); CefBrowserSettings cefBrowserSettings = new CefBrowserSettings() { BackgroundColor = new CefColor(0, 60, 85, 115), JavaScript = CefState.Enabled, JavaScriptAccessClipboard = CefState.Disabled, JavaScriptCloseWindows = CefState.Disabled, JavaScriptDomPaste = CefState.Disabled, //JavaScriptOpenWindows = CefState.Disabled, LocalStorage = CefState.Disabled }; // Initialize some of the custom interactions with the browser process. this.cefClient = new CefOSRClient(this); // Start up the browser instance. CefBrowserHost.CreateBrowser(cefWindowInfo, this.cefClient, cefBrowserSettings, string.IsNullOrEmpty(this.url) ? "http://www.google.com" : this.url); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (_browserPageImage != null) { _browserPageImage.Source = null; _browserPageImage = null; } if (_browserPageBitmap != null) { _browserPageBitmap = null; } // TODO: What's the right way of disposing the browser instance? if (_browserHost != null) { _browserHost.CloseBrowser(); _browserHost = null; } if (_browser != null) { _browser.Dispose(); _browser = null; } } }
private void CreateBrowser() { var windowInfo = CefWindowInfo.Create(); windowInfo.SetTransparentPainting(true); windowInfo.SetAsOffScreen(IntPtr.Zero); windowInfo.Width = this.Width; windowInfo.Height = this.Height; var browserSettings = new CefBrowserSettings { AcceleratedCompositing = CefState.Disabled, FileAccessFromFileUrls = CefState.Enabled, Java = CefState.Disabled, JavaScriptAccessClipboard = CefState.Disabled, JavaScriptCloseWindows = CefState.Disabled, WebGL = CefState.Disabled, }; CefBrowserHost.CreateBrowser( client: this, windowInfo: windowInfo, settings: browserSettings, requestContext: CefRequestContext.CreateContext(new RequestContextHandler(this.CookieDirectory))); }
public DevTools(CefBrowserHost host) { this.host = host; this.window = WindowManager.CreateWindow("Dev Tools"); this.window.SizeAllocated += WindowOnSizeAllocated; this.window.Destroyed += (_, _) => Dispose(); }
/// <summary> /// 创建一个web browser 对象,并打开一个新的空白页 /// </summary> private void CreateNewWebBrowser() { var autoSet = new AutoResetEvent(false); // Instruct CEF to not render to a window at all. CefWindowInfo cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsWindowless(IntPtr.Zero, true); // Settings for the browser window itself (e.g. should JavaScript be enabled?). var cefBrowserSettings = new CefBrowserSettings(); // Initialize some the cust interactions with the browser process. // The browser window will be 1280 x 720 (pixels). var cefClient = new HeadLessCefClient(1024, 720); var loader = cefClient.GetCurrentLoadHandler(); loader.BrowserCreated += (s, e) => { //事件通知 当cef browser 创建完毕 //创建完毕后 保存 browser 对象的实例 this.WebBrowser = e.Browser; this._is_cef_browser_has_created = true; //发送终止信号 autoSet.Set(); }; //注册 加载完毕事件handler loader.LoadEnd += this.OnWebBrowserLoadEnd; // Start up the browser instance. string url = "about:blank"; CefBrowserHost.CreateBrowser(cefWindowInfo, cefClient, cefBrowserSettings, url); //等待结束信号 autoSet.WaitOne(); }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); if (DesignMode) { if (!_handleCreated) { Paint += PaintInDesignMode; } } else { var windowInfo = CefWindowInfo.Create(); windowInfo.SetAsChild(Handle, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height }); var client = new CefWebClient(this); var settings = new CefBrowserSettings { // AuthorAndUserStylesDisabled = false, }; CefBrowserHost.CreateBrowser(windowInfo, client, settings, StartUrl); } _handleCreated = true; }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); if (DesignMode) { if (!_handleCreated) { Paint += PaintInDesignMode; } } else { var windowInfo = CefWindowInfo.Create(); windowInfo.SetAsChild(Handle, new CefRectangle { X = 0, Y = 0, Width = Width, Height = Height }); var client = CreateWebClient(); var settings = BrowserSettings; if (settings == null) { settings = new CefBrowserSettings { } } ; CefBrowserHost.CreateBrowser(windowInfo, client, settings, StartUrl); } _handleCreated = true; }
internal void Attach(CefBrowser browser) { FBrowser = browser; FBrowserHost = browser.GetHost(); FBrowserHost.SetMouseCursorChangeDisabled(true); FBrowserAttachedEvent.Set(); }
internal void CreateBrowser(IntPtr hostHandle, IntPtr winXID) { if (_client == null) { _client = CreateClient(); } if (_settings == null) { _settings = new CefBrowserSettings(); } _settings.DefaultEncoding = "UTF-8"; _settings.FileAccessFromFileUrls = CefState.Enabled; _settings.UniversalAccessFromFileUrls = CefState.Enabled; _settings.WebSecurity = CefState.Disabled; HostHandle = hostHandle; var windowInfo = CefWindowInfo.Create(); windowInfo.SetAsChild(winXID, new CefRectangle(0, 0, _config.WindowOptions.Size.Width, _config.WindowOptions.Size.Height)); Address = _config.StartUrl; StartUrl = _config.StartUrl; CefBrowserHost.CreateBrowser(windowInfo, _client, _settings, StartUrl); }
/// <summary> /// Creates the browser. /// </summary> /// <param name="handle">The handle.</param> /// <param name="position">The position.</param> protected void CreateBrowser(IntPtr handle, CefRectangle position) { Application.Current.EnsureCefThread(); if (IsBrowserCreated) { throw new InvalidOperationException("Browser already created."); } Logger.Info("Creating browser."); var cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsChild(handle, position); var cefClient = new Client(); cefClient.BrowserCreated += (sender, e) => { CefBrowser = e.CefBrowser; if (BrowserCreated != null) { BrowserCreated(this, e); } }; var cefSettings = new CefBrowserSettings(); CefBrowserHost.CreateBrowser(cefWindowInfo, cefClient, cefSettings, Application.Current.GetContentUrl(View)); IsBrowserCreated = true; Logger.Info("Browser created."); }
private Task <IWebBrowserWindowProvider> InitTask(string fullpath, IWebSessionLogger logger) { TaskCompletionSource <IWebBrowserWindowProvider> tcs = new TaskCompletionSource <IWebBrowserWindowProvider>(); Task.Run(async() => { var cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsWindowless(IntPtr.Zero, true); //// Settings for the browser window itself (e.g. enable JavaScript?). var cefBrowserSettings = new CefBrowserSettings(); // Initialize some the cust interactions with the browser process. var cefClient = new TestCefClient(); // Start up the browser instance. CefBrowserHost.CreateBrowser(cefWindowInfo, cefClient, cefBrowserSettings, fullpath); _CefBrowser = await cefClient.GetLoadedBrowserAsync(); _CefFrame = _CefBrowser.GetMainFrame(); _TestCefGlueHTMLWindowProvider = new TestCefGlueHTMLWindowProvider(_CefFrame, cefClient); tcs.SetResult(_TestCefGlueHTMLWindowProvider); }); return(tcs.Task); }
/// <summary> /// Initialization /// </summary> /// <param name="width">Browser rect width</param> /// <param name="height">Browser rect height</param> /// <param name="starturl"></param> public void Init(int width, int height, string starturl) { RegisterMessageRouter(); CefWindowInfo cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsWindowless(IntPtr.Zero, false); var cefBrowserSettings = new CefBrowserSettings { JavaScript = CefState.Enabled, TabToLinks = CefState.Enabled, WebSecurity = CefState.Disabled, WebGL = CefState.Enabled, WindowlessFrameRate = 30 }; _client = new WorkerCefClient(width, height, this); string url = "http://www.yandex.ru/"; if (starturl != "") { url = starturl; } CefBrowserHost.CreateBrowser(cefWindowInfo, _client, cefBrowserSettings, url); _initialized = true; }
/// <summary> /// Create a new texture renderer. /// </summary> /// <param name="logger">The logger to log to.</param> /// <param name="frameRate"> /// The maximum rate in frames per second (fps) that CefRenderHandler::OnPaint will /// be called for a windowless browser. The actual fps may be lower if the browser /// cannot generate frames at the requested rate. The minimum value is 1 and the /// maximum value is 60 (default 30). /// </param> public HTMLTextureRenderer(ILogger logger, int frameRate) { Logger = logger; FrameRate = VMath.Clamp(frameRate, MIN_FRAME_RATE, MAX_FRAME_RATE); FLoaded = false; var settings = new CefBrowserSettings(); settings.FileAccessFromFileUrls = CefState.Enabled; settings.Plugins = CefState.Enabled; settings.RemoteFonts = CefState.Enabled; settings.UniversalAccessFromFileUrls = CefState.Enabled; settings.WebGL = CefState.Enabled; settings.WebSecurity = CefState.Disabled; settings.WindowlessFrameRate = frameRate; var windowInfo = CefWindowInfo.Create(); windowInfo.SetAsWindowless(IntPtr.Zero, true); FWebClient = new WebClient(this); // See http://magpcss.org/ceforum/viewtopic.php?f=6&t=5901 // We need to maintain different request contexts in order to have different zoom levels // See https://bitbucket.org/chromiumembedded/cef/issues/1314 var rcSettings = new CefRequestContextSettings() { IgnoreCertificateErrors = true }; FRequestContext = CefRequestContext.CreateContext(rcSettings, new WebClient.RequestContextHandler()); CefBrowserHost.CreateBrowser(windowInfo, FWebClient, settings, FRequestContext); // Block until browser is created FBrowserAttachedEvent.WaitOne(); }
public void HandleAfterCreated(CefBrowser browser) { if (_browser == null) { _browser = browser; _browserHost = _browser.GetHost(); } }
public void CreateBrowser(CefWindowInfo windowInfo) { if (BrowserClient == null) { BrowserClient = new BrowserClient(Owner); } CefBrowserHost.CreateBrowser(windowInfo, BrowserClient, _settings, _startUrl); }
public async Task Create(CefWindowInfo windowInfo) { var settings = new CefBrowserSettings { WindowlessFrameRate = 5 }; CefBrowserHost.CreateBrowser(windowInfo, this.client, settings, string.Empty); await this.initializedCompletionSource.Task.ConfigureAwait(false); }
public void Create(CefWindowInfo windowInfo) { if (_client == null) { _client = new WebClient(this); } CefBrowserHost.CreateBrowser(windowInfo, _client, _settings, StartUrl); }
public void Create(CefWindowInfo windowInfo) { if (Client == null) { Client = new WebClient(this); } CefBrowserHost.CreateBrowser(windowInfo, Client, Host.Config.CefBrowserSettings, StartUrl); }
protected override void OnAfterCreated(CefBrowser browser) { MainBrowser = browser; MainBrowserHost = browser.GetHost(); //scroll // CefFrame frame = MainBrowser.GetMainFrame(); // frame.ExecuteJavaScript("window.ScrollTo(" + _mainWorker.ClientX + "," + _mainWorker.ClientY + ");", frame.Url, 0); }
/// <summary> /// 创建浏览器 /// </summary> private void CreateBrowser() { var windowInfo = CefWindowInfo.Create(); windowInfo.SetAsChild(Handle, new CefRectangle(0, 0, Width, Height)); var client = new WebClient(this); var settings = new CefBrowserSettings(); CefBrowserHost.CreateBrowser(windowInfo, client, settings, Url ?? "about:blank"); }
public void Shutdown() { if (this.sHost != null) { Debug.Log("Host Cleanup"); this.sHost.CloseBrowser(true); this.sHost.Dispose(); this.sHost = null; } }
/// <summary> /// The create. /// </summary> /// <param name="windowInfo"> /// The window info. /// </param> public void Create(CefWindowInfo windowInfo) { if (this.mClient == null) { IoC.RegisterInstance(typeof(CefGlueBrowser), typeof(CefGlueBrowser).FullName, this); this.mClient = new CefGlueClient(CefGlueClientParams.Create(this)); } CefBrowserHost.CreateBrowser(windowInfo, this.mClient, this.mSettings, this.StartUrl); }
private void StartCef() { #if UNITY_EDITOR CefRuntime.Load(Path.Combine(Application.dataPath, "Plugins", "Cef", "Windows")); #else CefRuntime.Load(); #endif var cefMainArgs = new CefMainArgs(new string[] { }); var cefApp = new OffscreenCEFClient.OffscreenCEFApp(); // This is where the code path diverges for child processes. if (CefRuntime.ExecuteProcess(cefMainArgs, cefApp, IntPtr.Zero) != -1) { Debug.LogError("Could not start the secondary process."); } var cefSettings = new CefSettings { //ExternalMessagePump = true, MultiThreadedMessageLoop = false, SingleProcess = true, LogSeverity = CefLogSeverity.Verbose, LogFile = "cef.log", WindowlessRenderingEnabled = true, NoSandbox = true }; // Start the browser process (a child process). CefRuntime.Initialize(cefMainArgs, cefSettings, cefApp, IntPtr.Zero); // Instruct CEF to not render to a window. CefWindowInfo cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsWindowless(IntPtr.Zero, true); // Settings for the browser window itself (e.g. enable JavaScript?). CefBrowserSettings cefBrowserSettings = new CefBrowserSettings() { }; Debug.Log("Start with window: " + this.windowWidth + ", " + this.windowHeight); // Initialize some of the custom interactions with the browser process. this.cefClient = new OffscreenCEFClient( this.windowWidth, this.windowHeight, this.hideScrollbars, this.BrowserTexture, this ); // Start up the browser instance. CefBrowserHost.CreateBrowser(cefWindowInfo, this.cefClient, cefBrowserSettings, string.IsNullOrEmpty(this.overlayUrl) ? "http://www.google.com" : this.overlayUrl); }
public Menu( CefApp menuCeffApp, CefMainArgs mainArgs, InputProcessor inputProcessor, MenuBrowserClient browserClient, StateManager stateManager, EventBus eventBus ) { // State Initialization _buttons = (GameControllerButton[])Enum.GetValues(typeof(GameControllerButton)); _analogs = (GameControllerAnalog[])Enum.GetValues(typeof(GameControllerAnalog)); _eventTokenList = new List <SubscriptionToken>(); _eventBus = eventBus; #if (DEBUG) var logSeverity = CefLogSeverity.Error; #else var logSeverity = CefLogSeverity.Error; #endif var settings = new CefSettings { WindowlessRenderingEnabled = true, LogSeverity = logSeverity, NoSandbox = true }; CefRuntime.Initialize(mainArgs, settings, menuCeffApp, IntPtr.Zero); // Instruct CEF to not render to a window at all. var cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsWindowless(IntPtr.Zero, false); var browserSettings = new CefBrowserSettings() { WindowlessFrameRate = 60, }; _inputProcessor = inputProcessor; _browserClient = browserClient; _browser = CefBrowserHost.CreateBrowserSync( cefWindowInfo, _browserClient, browserSettings, "http://localhost:4200" ); _eventTokenList.Add(_eventBus.Subscribe <OpenMenuEvent>(OnOpenMenuEvent)); _eventTokenList.Add(_eventBus.Subscribe <CloseMenuEvent>(OnCloseMenuEvent)); var game = stateManager.GetGameById("Super Mario World (USA)"); eventBus.Publish(new LoadGameEvent(game)); }
//private ScriptableObjectProvider _provider; //private ScriptableObjectProvider Provider //{ // get // { // if (_provider == null && BrowserObject != null) // _provider = new ScriptableObjectProvider(BrowserObject.GetMainFrame()); // return _provider; // } //} //public Window GetWindow() //{ // return new Window(Provider.GetGlobal(), Provider); //} /// <summary> /// Send a notification to the browser that the screen info has changed.<para/> /// This function is only used when window rendering is disabled. /// </summary> /// <remarks> /// The browser will then call <see cref="CefRenderHandler.GetScreenInfo"/> /// to update the screen information with the new values. This simulates moving /// the webview window from one display to another, or changing the properties /// of the current display. /// </remarks> public void NotifyScreenInfoChanged() { CefBrowserHost browserHost = this.BrowserObject?.Host; if (browserHost is null || !browserHost.IsWindowRenderingDisabled) { return; } browserHost.NotifyScreenInfoChanged(); }
/// <summary> /// Call this function each time the mouse is moved across the web view during /// a drag operation. /// <para/>This function is only used when window rendering is disabled. /// </summary> public void SendDragOverEvent(int x, int y, CefEventFlags modifiers, CefDragOperationsMask allowedOps) { CefBrowserHost browserHost = this.BrowserObject?.Host; if (browserHost is null) { return; } InitMouseEvent(x, y, modifiers); browserHost.DragTargetDragOver(_mouseEventProxy, allowedOps); }
/// <summary> /// Call this function when the user completes the drag operation by dropping /// the object onto the web view. The object being dropped is |dragData|, given /// as an argument to the previous <see cref="SendDragEnterEvent"/> call. /// <para/>This function is only used when window rendering is disabled. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="modifiers"></param> public void SendDragDropEvent(int x, int y, CefEventFlags modifiers) { CefBrowserHost browserHost = this.BrowserObject?.Host; if (browserHost is null) { return; } InitMouseEvent(x, y, modifiers); browserHost.DragTargetDrop(_mouseEventProxy); }