Пример #1
0
        static void Main()
        {
            if (Environment.OSVersion.Version.Major >= 6)
            {
                SetProcessDPIAware();
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var result = Bootstrap.Load(settings =>
            {
                settings.AcceptLanguageList = "zh-CN; en-US";
                settings.LogSeverity        = Chromium.CfxLogSeverity.Disable;
            }, commandline =>
            {
                commandline.AppendSwitch("disable-web-security");
            });

            if (result)
            {
                Bootstrap.RegisterAssemblyResources(System.Reflection.Assembly.GetExecutingAssembly(), "WebUI");
                Bootstrap.RegisterFolderResources(Application.StartupPath);
                var factory = new CfxSchemeHandlerFactory();
                factory.Create += (_, args) =>
                {
                    if (args.SchemeName == "http" && args.Browser != null)
                    {
                        var wb      = BrowserCore.GetBrowser(args.Browser.Identifier);
                        var handler = new MemResourceHandler("", wb, "");
                        args.SetReturnValue(handler);
                    }
                };

                Bootstrap.RegisterCustomScheme("http", "memres.app.local", factory);

                var factoryZip = new CfxSchemeHandlerFactory();
                factoryZip.Create += (_, args) =>
                {
                    if (args.SchemeName == "http" && args.Browser != null)
                    {
                        var wb      = BrowserCore.GetBrowser(args.Browser.Identifier);
                        var handler = new ZipResourceHandler(Application.StartupPath + "\\res.zip", wb, "zip.app.local");
                        args.SetReturnValue(handler);
                    }
                };
                Bootstrap.RegisterCustomScheme("http", "zip.app.local", factoryZip);
                Application.Run(new MainUI());
                Application.Exit();
            }
        }
Пример #2
0
        public static void RegisterAssemblyResources(System.Reflection.Assembly assembly,
                                                     string domainName = "res.app.local")
        {
            var factory  = new CfxSchemeHandlerFactory();
            var gchandle = GCHandle.Alloc(factory);

            factory.Create += (_, args) =>
            {
                if (args.SchemeName == "http" && args.Browser != null)
                {
                    var wb      = BrowserCore.GetBrowser(args.Browser.Identifier);
                    var handler = new ResourceHandler.AssemblyResourceHandler(assembly, wb, domainName);
                    args.SetReturnValue(handler);
                }
            };
            RegisterCustomScheme("http", domainName, factory);
        }
Пример #3
0
        void RenderProcessHandler_OnContextCreated(object sender, CfrOnContextCreatedEventArgs e)
        {
            var wb = BrowserCore.GetBrowser(e.Browser.Identifier);

            if (wb != null)
            {
                if (e.Frame.IsMain)
                {
                    SetProperties(e.Context, wb.GlobalObject);
                }
                else
                {
                    JSObject obj;
                    if (wb.frameGlobalObjects.TryGetValue(e.Frame.Name, out obj))
                    {
                        SetProperties(e.Context, obj);
                    }
                }
                wb.RaiseOnV8ContextCreated(e);
            }
        }
Пример #4
0
        void RenderProcessHandler_OnBrowserCreated(object sender, CfrOnBrowserCreatedEventArgs e)
        {
            var id = e.Browser.Identifier;
            var wb = BrowserCore.GetBrowser(id);

            if (wb != null)
            {
                var rp = wb.remoteProcess;
                if (rp != null && rp != this.remoteProcess)
                {
                    // A new process has been created for the browser.
                    // The old process is still alive, but probably it gets
                    // killed soon after this callback returns.
                    // So we suspend all callbacks from the old process.
                    // If there are currently executing callbacks,
                    // this call will block until they are finished.
                    // When this call returns, it should be safe to
                    // continue execution and let the old process die.
                    CfxRemoteCallbackManager.SuspendCallbacks(rp.RemoteProcessId);
                }

                wb.SetRemoteBrowser(e.Browser, remoteProcess);
            }
        }