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;
        }
        private int on_before_popup(cef_life_span_handler_t* self, cef_browser_t* browser, cef_frame_t* frame, cef_string_t* target_url, cef_string_t* target_frame_name, cef_popup_features_t* popupFeatures, cef_window_info_t* windowInfo, cef_client_t** client, cef_browser_settings_t* settings, int* no_javascript_access)
        {
            CheckSelf(self);

            var m_browser = CefBrowser.FromNative(browser);
            var m_frame = CefFrame.FromNative(frame);
            var m_targetUrl = cef_string_t.ToString(target_url);
            var m_targetFrameName = cef_string_t.ToString(target_frame_name);
            var m_popupFeatures = new CefPopupFeatures(popupFeatures);
            var m_windowInfo = CefWindowInfo.FromNative(windowInfo);
            var m_client = CefClient.FromNative(*client);
            var m_settings = new CefBrowserSettings(settings);
            var m_noJavascriptAccess = (*no_javascript_access) != 0;

            var o_client = m_client;
            var result = OnBeforePopup(m_browser, m_frame, m_targetUrl, m_targetFrameName, m_popupFeatures, m_windowInfo, ref m_client, m_settings, ref m_noJavascriptAccess);

            if ((object)o_client != m_client && m_client != null)
            {
                *client = m_client.ToNative();
            }

            *no_javascript_access = m_noJavascriptAccess ? 1 : 0;

            m_popupFeatures.Dispose();
            m_windowInfo.Dispose();
            m_settings.Dispose();

            return result ? 1 : 0;
        }
Exemplo n.º 3
0
        protected override bool OnBeforePopup( CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess )
        {
            var e = new BeforePopupEventArgs( frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings,
                     noJavascriptAccess );

            this.owner.OnBeforePopup( e );

            client = e.Client;
            noJavascriptAccess = e.NoJavascriptAccess;

            return e.Handled;
        }
        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();
        }
Exemplo n.º 5
0
        public BeforePopupEventArgs(
			CefFrame frame,
			string targetUrl,
			string targetFrameName,
			CefPopupFeatures popupFeatures,
			CefWindowInfo windowInfo,
			CefClient client,
			CefBrowserSettings settings,
			bool noJavascriptAccess)
        {
            Frame = frame;
            TargetUrl = targetUrl;
            TargetFrameName = targetFrameName;
            PopupFeatures = popupFeatures;
            WindowInfo = windowInfo;
            Client = client;
            Settings = settings;
            NoJavascriptAccess = noJavascriptAccess;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a new browser window using the window parameters specified by
        /// |windowInfo|. This method can only be called on the browser process UI
        /// thread.
        /// </summary>
        public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, string url)
        {
            if (windowInfo == null) throw new ArgumentNullException("windowInfo");
            if (client == null) throw new ArgumentNullException("client");
            if (settings == null) throw new ArgumentNullException("settings");
            // TODO: [ApiUsage] if windowInfo.WindowRenderingDisabled && client doesn't provide RenderHandler implementation -> throw exception

            var n_windowInfo = windowInfo.ToNative();
            var n_client = client.ToNative();
            var n_settings = settings.ToNative();

            fixed (char* url_ptr = url)
            {
                cef_string_t n_url = new cef_string_t(url_ptr, url != null ? url.Length : 0);
                var n_browser = cef_browser_host_t.create_browser_sync(n_windowInfo, n_client, &n_url, n_settings);
                return CefBrowser.FromNative(n_browser);
            }

            // TODO: free n_ structs ?
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create a new browser window using the window parameters specified by
        /// |windowInfo|. All values will be copied internally and the actual window
        /// will be created on the UI thread. If |request_context| is empty the
        /// global request context will be used. This method can be called on any
        /// browser process thread and will not block.
        /// </summary>
        public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, string url, CefRequestContext requestContext)
        {
            if (windowInfo == null) throw new ArgumentNullException("windowInfo");
            if (client == null) throw new ArgumentNullException("client");
            if (settings == null) throw new ArgumentNullException("settings");
            // TODO: [ApiUsage] if windowInfo.WindowRenderingDisabled && client doesn't provide RenderHandler implementation -> throw exception

            var n_windowInfo = windowInfo.ToNative();
            var n_client = client.ToNative();
            var n_settings = settings.ToNative();
            var n_requestContext = requestContext != null ? requestContext.ToNative() : null;

            fixed (char* url_ptr = url)
            {
                cef_string_t n_url = new cef_string_t(url_ptr, url != null ? url.Length : 0);
                var n_success = cef_browser_host_t.create_browser(n_windowInfo, n_client, &n_url, n_settings, n_requestContext);
                if (n_success != 1) throw ExceptionBuilder.FailedToCreateBrowser();
            }

            // TODO: free n_ structs ?
        }
        public XiboCefWebBrowser()
        {
            SetStyle(
                ControlStyles.ContainerControl
                | ControlStyles.ResizeRedraw
                | ControlStyles.FixedWidth
                | ControlStyles.FixedHeight
                | ControlStyles.StandardClick
                | ControlStyles.UserMouse
                | ControlStyles.SupportsTransparentBackColor
                | ControlStyles.StandardDoubleClick
                | ControlStyles.OptimizedDoubleBuffer
                | ControlStyles.CacheText
                | ControlStyles.EnableNotifyMessage
                | ControlStyles.DoubleBuffer
                | ControlStyles.OptimizedDoubleBuffer
                | ControlStyles.UseTextForAccessibility
                | ControlStyles.Opaque,
                false);

            SetStyle(
                ControlStyles.UserPaint
                | ControlStyles.AllPaintingInWmPaint
                | ControlStyles.Selectable,
                true);

            StartUrl = "about:blank";

            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);
        }
Exemplo n.º 9
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url, CefRequestContext requestContext)
 {
     CreateBrowser(windowInfo, client, settings, url.ToString(), requestContext);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Open developer tools in its own window.
 /// </summary>
 public void ShowDevTools(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings browserSettings)
 {
     cef_browser_host_t.show_dev_tools(_self, windowInfo.ToNative(), client.ToNative(), browserSettings.ToNative());
 }
Exemplo n.º 11
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings)
 {
     return CreateBrowserSync(windowInfo, client, settings, string.Empty);
 }
Exemplo n.º 12
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url)
 {
     return CreateBrowserSync(windowInfo, client, settings, url.ToString());
 }
Exemplo n.º 13
0
        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 );
            }
        }
Exemplo n.º 14
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings)
 {
     CreateBrowser(windowInfo, client, settings, string.Empty, null);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Open developer tools in its own window. If |inspect_element_at| is non-
 /// empty the element at the specified (x,y) location will be inspected.
 /// </summary>
 public void ShowDevTools(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings browserSettings, CefPoint inspectElementAt)
 {
     var n_inspectElementAt = new cef_point_t(inspectElementAt.X, inspectElementAt.Y);
     cef_browser_host_t.show_dev_tools(_self, windowInfo.ToNative(), client.ToNative(), browserSettings.ToNative(),
         &n_inspectElementAt);
 }
Exemplo n.º 16
0
 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);
 }
        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 MyCefClient(EmbeddedBrowser);

                var settings = BrowserSettings;
                if (settings == null)
                    settings = new CefBrowserSettings();

                CefBrowserHost.CreateBrowser(windowInfo, client, settings, EmbeddedBrowser.StartUrl);
            }

            handleCreated = true;
        }
Exemplo n.º 18
0
 //Race condition? user calls createBrowser twice very quickly
 //Does CEF check for multiple uses of same handle?
 public void createBrowser()
 {
     Debug.WriteLine(DBGPREFIX + "createBrowser starting creation of CefBrowser");
     if (Browser == null)
     {
         var settings = new CefBrowserSettings { };
         CefBrowserHost.CreateBrowser(getCefWindowInfo(), CefClient, settings, StartUrl);
     }
     else
         Debug.WriteLine(DBGPREFIX + "createBrowser has already created CefBrowser instance for this control, request ignored.");
 }
        public bool CreateBrowser(BrowserSource browserSource, BrowserConfig browserConfig)
        {
            Debug.Assert(Status == BrowserStatus.Initial);

            InitClient(browserSource);

            Debug.Assert(browserClient != null);
            Debug.Assert(browserConfig != null);

            BrowserConfig = browserConfig;

            CefWindowInfo windowInfo = CefWindowInfo.Create();
            windowInfo.TransparentPainting = true;
            windowInfo.SetAsOffScreen(IntPtr.Zero);
            windowInfo.Width = (int)browserConfig.BrowserSourceSettings.Width;
            windowInfo.Height = (int)browserConfig.BrowserSourceSettings.Height;
            windowInfo.MenuHandle = IntPtr.Zero;
            windowInfo.ParentHandle = IntPtr.Zero;

            String base64EncodedDataUri = "data:text/css;charset=utf-8;base64,";
            String base64EncodedCss = Convert.ToBase64String(Encoding.UTF8.GetBytes(browserConfig.BrowserSourceSettings.CSS));

            BrowserInstanceSettings settings = AbstractSettings.DeepClone(BrowserSettings.Instance.InstanceSettings);
            settings.MergeWith(browserConfig.BrowserInstanceSettings);

            CefBrowserSettings browserSettings = new CefBrowserSettings {
                AcceleratedCompositing = settings.AcceleratedCompositing,
                ApplicationCache = settings.ApplicationCache,
                AuthorAndUserStyles = settings.AuthorAndUserStyles,
                CaretBrowsing = settings.CaretBrowsing,
                CursiveFontFamily = settings.CursiveFontFamily,
                Databases = settings.Databases,
                DefaultEncoding = settings.DefaultEncoding,
                DefaultFixedFontSize = settings.DefaultFixedFontSize,
                DefaultFontSize = settings.DefaultFontSize,
                DeveloperTools = settings.DeveloperTools,
                FantasyFontFamily = settings.FantasyFontFamily,
                FileAccessFromFileUrls = settings.FileAccessFromFileUrls,
                FixedFontFamily = settings.FixedFontFamily,
                ImageLoading = settings.ImageLoading,
                ImageShrinkStandaloneToFit = settings.ImageShrinkStandaloneToFit,
                Java = settings.Java,
                JavaScript = settings.JavaScript,
                JavaScriptAccessClipboard = settings.JavaScriptAccessClipboard,
                JavaScriptCloseWindows = settings.JavaScriptCloseWindows,
                JavaScriptDomPaste = settings.JavaScriptDomPaste,
                JavaScriptOpenWindows = settings.JavaScriptOpenWindows,
                LocalStorage = settings.LocalStorage,
                MinimumFontSize = settings.MinimumFontSize,
                MinimumLogicalFontSize = settings.MinimumLogicalFontSize,
                PageCache = settings.PageCache,
                Plugins = settings.Plugins,
                RemoteFonts = settings.RemoteFonts,
                SansSerifFontFamily = settings.SansSerifFontFamily,
                SerifFontFamily = settings.SerifFontFamily,
                StandardFontFamily = settings.StandardFontFamily,
                //TabToLinks = settings.TabToLinks,
                //TextAreaResize = settings.TextAreaResize,
                UniversalAccessFromFileUrls = settings.UniversalAccessFromFileUrls,
                UserStyleSheetLocation = base64EncodedDataUri + base64EncodedCss,
                WebGL = settings.WebGL,
                WebSecurity = settings.WebSecurity,
            };

            String url = browserConfig.BrowserSourceSettings.Url;

            if (browserConfig.BrowserSourceSettings.IsApplyingTemplate)
            {
                String resolvedTemplate = browserConfig.BrowserSourceSettings.Template;
                resolvedTemplate = resolvedTemplate.Replace("$(FILE)", browserConfig.BrowserSourceSettings.Url);
                resolvedTemplate = resolvedTemplate.Replace("$(WIDTH)", browserConfig.BrowserSourceSettings.Width.ToString());
                resolvedTemplate = resolvedTemplate.Replace("$(HEIGHT)", browserConfig.BrowserSourceSettings.Height.ToString());

                url = "http://absolute";
            }

            // must be sync invoke because wrapper can be destroyed before it is run

            try
            {
                // Since the event methods can be called before the next statement
                // set the status before we call it
                Status = BrowserStatus.Creating;
                CefBrowserHost.CreateBrowser(windowInfo, browserClient, browserSettings, url);
            }
            catch (InvalidOperationException e)
            {
                API.Instance.Log("BrowserWrapper::CreateBrowser failed; {0}", e.Message);
                UninitClient();
                return false;
            }

            BrowserManager.Instance.IncrementBrowserInstanceCount();

            return true;
        }
Exemplo n.º 20
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url)
 {
     CreateBrowser(windowInfo, client, settings, url, null);
 }
Exemplo n.º 21
0
 public static void CreateBrowser(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, CefRequestContext requestContext)
 {
     CreateBrowser(windowInfo, client, settings, string.Empty, requestContext);
 }
Exemplo n.º 22
0
        public void BeginRender(int width, int height, string url, int maxFrameRate = 30)
        {
            EndRender();

            var cefWindowInfo = CefWindowInfo.Create();
            cefWindowInfo.SetAsWindowless(IntPtr.Zero, true);

            var cefBrowserSettings = new CefBrowserSettings();
            cefBrowserSettings.WindowlessFrameRate = maxFrameRate;

            this.Client = new Client(this, width, height);

            CefBrowserHost.CreateBrowser(
                cefWindowInfo,
                this.Client,
                cefBrowserSettings,
                url);
        }
Exemplo n.º 23
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, string url)
 {
     return CreateBrowserSync(windowInfo, client, settings, url, null);
 }
Exemplo n.º 24
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, Uri url, CefRequestContext requestContext)
 {
     return CreateBrowserSync(windowInfo, client, settings, url.ToString(), requestContext);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Called on the IO thread before a new popup window is created. The |browser|
 /// and |frame| parameters represent the source of the popup request. The
 /// |target_url| and |target_frame_name| values may be empty if none were
 /// specified with the request. The |popupFeatures| structure contains
 /// information about the requested popup window. To allow creation of the
 /// popup window optionally modify |windowInfo|, |client|, |settings| and
 /// |no_javascript_access| and return false. To cancel creation of the popup
 /// window return true. The |client| and |settings| values will default to the
 /// source browser's values. The |no_javascript_access| value indicates whether
 /// the new browser window should be scriptable and in the same process as the
 /// source browser.
 /// </summary>
 protected virtual bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess)
 {
     return false;
 }
Exemplo n.º 26
0
 public static CefBrowser CreateBrowserSync(CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, CefRequestContext requestContext)
 {
     return CreateBrowserSync(windowInfo, client, settings, string.Empty, requestContext);
 }