Example #1
0
 /// <summary>
 /// Shuts down CEF
 /// </summary>
 /// <param name="reason"></param>
 public void Shutdown(string reason)
 {
     if (ParagonRuntime.IsInitialized)
     {
         ParagonRuntime.Shutdown(reason);
     }
 }
        void ICefWebBrowserInternal.OnBrowserAfterCreated(CefBrowser browser)
        {
            this.DispatchIfRequired(() =>
            {
                try
                {
                    if (_browser != null)
                    {
                        return;
                    }

                    _browser = browser;
                    using (var browserHost = _browser.GetHost())
                    {
                        _browserWindowHandle = browserHost.GetWindowHandle();
                        if (_browserWindowHandle != IntPtr.Zero)
                        {
                            OnHandleCreated();
                            _widgetWindowZOrderHandler = new WidgetWindowZOrderHandler(_browserWindowHandle);
                        }
                    }

                    if (!IsPopup)
                    {
                        if (BrowserAfterCreated != null)
                        {
                            BrowserAfterCreated(this, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        var parent = ParagonRuntime.FindBrowser <CefWebBrowser>(_parentBrowserId);
                        if (parent == null)
                        {
                            Close();
                        }
                        else
                        {
                            var ea = parent.RaiseShowPopup(this);
                            if (ea == null || !ea.Shown)
                            {
                                Close();
                            }
                        }
                    }

                    SetBrowserZoomLevel();
                }
                catch (Exception ex)
                {
                    Logger.Error("Error in OnBrowserAfterCreated : {0}", ex);
                    throw;
                }
            }, true);
        }
 public CefWebBrowser()
 {
     KeyboardNavigation.SetIsTabStop(this, false);
     KeyboardNavigation.SetTabNavigation(this, KeyboardNavigationMode.Cycle);
     KeyboardNavigation.SetDirectionalNavigation(this, KeyboardNavigationMode.Cycle);
     _disablePopups      = false;
     _disableContextMenu = false;
     Loaded += OnLoaded;
     ParagonRuntime.AddBrowser(this);
     _allowedProtocols.AddRange(CefBrowserApplication.AllowedProtocols);
 }
        public override void CreateControl()
        {
            base.CreateControl();

            if (!_controlCreated && !DesignMode)
            {
                if (!ParagonRuntime.IsInitialized)
                {
                    ParagonRuntime.Initialize();
                }

                _client = new CefWebClient(this);

                if (!IsPopup && _browser == null)
                {
                    var settings = new CefBrowserSettings
                    {
                        Java = CefState.Disabled
                    };

                    using (AutoStopwatch.TimeIt("Creating browser"))
                    {
                        var info = CefWindowInfo.Create();
                        var ea   = new BrowserCreateEventArgs();

                        using (AutoStopwatch.TimeIt("Raising BeforeBrowserCreate event"))
                        {
                            BeforeBrowserCreate.Raise(this, ea);
                        }

                        _router     = ea.Router;
                        _currentUrl = _sourceUrl;

                        if (IntPtr.Zero != ParentHandle)
                        {
                            RECT rect = new RECT();
                            Win32Api.GetClientRect(ParentHandle, ref rect);
                            info.SetAsChild(ParentHandle, new CefRectangle(rect.Left, rect.Top, rect.Width, rect.Height));
                        }

                        Logger.Info(string.Format("OnHandleCreated - Creating a browser with url {0}", _currentUrl));
                        CefBrowserHost.CreateBrowser(info, _client, settings, _currentUrl);
                    }
                }

                _controlCreated = true;
            }
        }
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (_browser != null && disposing)
            {
                ParagonRuntime.RemoveBrowser(this);
                if (_widgetWindowZOrderHandler != null)
                {
                    _widgetWindowZOrderHandler.Dispose();
                    _widgetWindowZOrderHandler = null;
                }
                if (_containerWindowMoveListener != null)
                {
                    _containerWindowMoveListener.Dispose();
                    _containerWindowMoveListener = null;
                }
                if (_client != null)
                {
                    _client.Dispose();
                    _client = null;
                }
                if (_router != null)
                {
                    // Router should not be disposed here since it is shared by all cefwebbrowsers
                    //_router.Dispose();
                    _router = null;
                }
                if (_browser != null)
                {
                    _browser.Dispose();
                    _browser = null;
                }
                _browserWindowHandle = IntPtr.Zero;
            }
        }
Example #6
0
        /// <summary>
        /// Launch the first application in the host process
        /// </summary>
        /// <param name="package"></param>
        /// <param name="metadata"></param>
        public void RunApplication(ParagonCommandLineParser cmdLine, IApplicationPackage package, ApplicationMetadata metadata)
        {
            if (IsInitialized)
            {
                throw new Exception("Application manger is already initialized");
            }

            var manifest = package.Manifest;

            // Initialize the following from the first application manifest
            ProcessGroup         = manifest.ProcessGroup ?? string.Empty;
            CacheFolder          = Path.Combine(_paragonFolder, string.IsNullOrEmpty(manifest.ProcessGroup) ? manifest.Id : manifest.ProcessGroup);
            Environment          = metadata.Environment;
            DisableSpellChecking = manifest.DisableSpellChecking;

            // set browser language from manifest - default is en-US
            // "automatic" will set browser language to os culture info
            if (!string.IsNullOrEmpty(manifest.BrowserLanguage))
            {
                if (string.Equals(manifest.BrowserLanguage, "Automatic", StringComparison.InvariantCultureIgnoreCase))
                {
                    BrowserLanguage = CultureInfo.CurrentCulture.Name;
                }
                else
                {
                    //verify specified culture
                    CultureInfo cultureInfo = null;
                    try
                    {
                        cultureInfo = new CultureInfo(manifest.BrowserLanguage);
                    }
                    catch (Exception)
                    {
                        Logger.Error("Manifest browser language is not valid. Using default browser language en-US");
                    }

                    BrowserLanguage = (cultureInfo != null) ? (cultureInfo.Name) : (BrowserLanguage);
                }

                Logger.Info(string.Format("Browser language being used is {0}", BrowserLanguage));
            }

            string auth_server_whitelist   = null;
            string auth_delegate_whitelist = null;

            if (cmdLine != null)
            {
                cmdLine.GetValue("auth-server-whitelist", out auth_server_whitelist);
                Logger.Info(string.Format("auth-server-whitelist [{0}]", auth_server_whitelist));
                cmdLine.GetValue("auth-delegate-whitelist", out auth_delegate_whitelist);
                Logger.Info(string.Format("auth-delegate-whitelist [{0}]", auth_delegate_whitelist));
            }

            // Initialize CEF
            using (AutoStopwatch.TimeIt("CEF initialization"))
            {
                ParagonRuntime.Initialize(
                    CacheFolder,
                    null,
                    BrowserLanguage,
                    auth_server_whitelist,
                    auth_delegate_whitelist,
                    DisableSpellChecking,
                    Environment == ApplicationEnvironment.Development);
            }

            RunApplicationInternal(cmdLine, package, metadata);
        }