Ejemplo n.º 1
0
        /// <summary>
        /// This function should be called on the main application thread to initialize
        /// CEF when the application is started.
        /// </summary>
        /// <param name="settings"></param>
        /// <exception cref="Exception"></exception>
        public static void Initialize(CefSettings settings, CefApp app = null)
        {
            if (IsInitialized)
            {
                throw new CefException("CEF already initialized.");
            }
#if DIAGNOSTICS
            cef_string_t.OnCreate = (ptr, str) =>
            {
                if (string.IsNullOrEmpty(str))
                {
                    Cef.Logger.Trace(LogTarget.CefString, IntPtr.Zero, LogOperation.Create, "Empty.");
                }
                else
                {
                    Cef.Logger.Trace(LogTarget.CefString, ptr, LogOperation.Create, "Value=[{0}].",
                                     str.Length <= 1024 ? str : (str.Substring(0, 1024) + "...")
                                     );
                }
            };
            cef_string_t.OnDispose = (ptr) =>
            {
                Cef.Logger.Trace(LogTarget.CefString, ptr, LogOperation.Dispose);
            };

            Logger.SetAllTargets(true);
            Logger.Trace(LogTarget.Default, "Initialize");
#endif

            var n_settings = settings.CreateNative();
            var n_app      = app == null ? null : app.GetNativePointerAndAddRef();

            // FIXME: not sure if application should be null
            var initialized = NativeMethods.cef_initialize(n_settings, n_app) != 0;
            cef_settings_t.Free(n_settings);

            if (!initialized)
            {
                throw new CefException("CEF failed to initialize.");
            }

            CurrentSettings = settings;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This function should be called on the main application thread to initialize
        /// CEF when the application is started.
        /// </summary>
        /// <param name="settings"></param>
        /// <exception cref="Exception"></exception>
        public static void Initialize(CefSettings settings, CefApp app = null)
        {
            if (IsInitialized) throw new CefException("CEF already initialized.");
            #if DIAGNOSTICS
            cef_string_t.OnCreate = (ptr, str) =>
            {
                if (string.IsNullOrEmpty(str))
                {
                    Cef.Logger.Trace(LogTarget.CefString, IntPtr.Zero, LogOperation.Create, "Empty.");
                }
                else
                {
                    Cef.Logger.Trace(LogTarget.CefString, ptr, LogOperation.Create, "Value=[{0}].",
                        str.Length <= 1024 ? str : (str.Substring(0, 1024) + "...")
                        );
                }
            };
            cef_string_t.OnDispose = (ptr) =>
            {
                Cef.Logger.Trace(LogTarget.CefString, ptr, LogOperation.Dispose);
            };

            Logger.SetAllTargets(true);
            Logger.Trace(LogTarget.Default, "Initialize");
            #endif

            var n_settings = settings.CreateNative();
            var n_app = app == null ? null : app.GetNativePointerAndAddRef();

            // FIXME: not sure if application should be null
            var initialized = NativeMethods.cef_initialize(n_settings, n_app) != 0;
            cef_settings_t.Free(n_settings);

            if (!initialized) throw new CefException("CEF failed to initialize.");

            CurrentSettings = settings;
        }