예제 #1
0
        /// Example_Init_Set_Chrome_Proxy_config_Service
        /// [0823/080932.106:VERBOSE1:pref_proxy_config_tracker_impl.cc(184)] 08D386F8: set chrome proxy config service to 08D388A0
        /// [0823/080932.379:VERBOSE1:pref_proxy_config_tracker_impl.cc(184)] 0C357958: set chrome proxy config service to 08DCED88



        public static void Example_Init_Set_Chrome_Proxy_config_Service()
        {
            #region Example_Init_Set_Chrome_Proxy_config_Service


            /// [0823/080932.106:VERBOSE1:pref_proxy_config_tracker_impl.cc(184)] 08D386F8: set chrome proxy config service to 08D388A0
            /// [0823/080932.379:VERBOSE1:pref_proxy_config_tracker_impl.cc(184)] 0C357958: set chrome proxy config service to 08DCED88



            WinForms.CefSettings settings = new WinForms.CefSettings();


            var proxy = ProxyConfig.GetProxyInformation();
            switch (proxy.AccessType)
            {
            case InternetOpenType.Direct:
            {
                //Don't use a proxy server, always make direct connections.
                settings.CefCommandLineArgs.Add("no-proxy-server", "1");
                break;
            }

            case InternetOpenType.Proxy:
            {
                settings.CefCommandLineArgs.Add("proxy-server", proxy.ProxyAddress);
                break;
            }

            case InternetOpenType.PreConfig:
            {
                settings.CefCommandLineArgs.Add("proxy-auto-detect", "1");
                break;
            }
            }



            Cef.Initialize(settings);

            #endregion


            #region (Not)

            // public static void Example_Init_Set_Chrome_Proxy_config_Service (AbstractCefSettings settings, IBrowserProcessHandler browserProcessHandler) {


            #endregion
        }
 public Form1() { InitializeComponent();

            WinForms.CefSettings settings = new WinForms.CefSettings();

            ///
            ///    Start Browser
            /// 

            // Set Google API keys, used for Geolocation requests sans GPS.  See http://www.chromium.org/developers/how-tos/api-keys
            Environment.SetEnvironmentVariable("GOOGLE_API_KEY", "AIzaSyBS-qjz0jmK4jvZy06Rq4DLs0_AITqo7lw");
            Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", "888034971568-kmdju8hjiem3mqqi3kgjmals6p0l0te4.apps.googleusercontent.com");
            Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET", "6fa_ZYlY8KxDd_KDOz1SdENV");


            CefSharpSettings.LegacyJavascriptBindingEnabled = true; //true
            CefSharpSettings.ConcurrentTaskExecution = true; //true
            CefSharpSettings.FocusedNodeChangedEnabled = true;
            CefSharpSettings.WcfEnabled = true; //true


            // AcceptLanguageList
            settings.AcceptLanguageList = "en-US,ru,ar,zh-CN,zh-TW,ko,ja,en-GB";
            
            Cef.Initialize(settings);

           ///
           ///
           ///

            Text = "CefSharp Chromium Web Browser";
            toolStripTextBoxAddress.Text = "chrome://version";
            ChromiumWebBrowser ChromiumWebBrowser = new ChromiumWebBrowser(toolStripTextBoxAddress.Text) { BrowserSettings =
            { DefaultEncoding = "UTF-8", Databases = CefState.Disabled, JavascriptDomPaste = CefState.Disabled, Javascript = CefState.Enabled, ApplicationCache = CefState.Disabled, FileAccessFromFileUrls = CefState.Enabled, TabToLinks = CefState.Default, UniversalAccessFromFileUrls = CefState.Default, WebSecurity = CefState.Enabled, LocalStorage = CefState.Disabled, ImageLoading = CefState.Default, TextAreaResize = CefState.Default, JavascriptAccessClipboard = CefState.Enabled, ImageShrinkStandaloneToFit = CefState.Default, Plugins = CefState.Enabled, WebGl = CefState.Disabled } };

            ChromiumWebBrowser.Dock = DockStyle.Fill;
           /// ChromiumWebBrowser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
           /// ChromiumWebBrowser.LoadingStateChanged += OnLoadingStateChanged;

            ChromiumWebBrowser.TitleChanged += OnBrowserTitleChanged;
            ChromiumWebBrowser.AddressChanged += OnBrowserAddressChanged;
            ChromiumWebBrowser.LoadError += BrowserLoadError;
            ChromiumWebBrowser.StatusMessage += OnStatusMessageChanged;

            // ChromiumWebBrowser.StatusMessage += OnBrowserStatusMessage;
            // ChromiumWebBrowser.LoadingStateChanged += BrowserLoadingStateChanged;


            TabPage tpage = new TabPage(); tpage.Text = " Ultimate Browser Version "; tpage.Show(); browserTabControl.Controls.Add(tpage); ChromiumWebBrowser.Parent = tpage;
            ChromiumWebBrowser.FocusHandler = null;

            /* Customize Handler */
            ChromiumWebBrowser.DownloadHandler = new ChromiumApplication.Main.Handler.DownloadHandler();
            ChromiumWebBrowser.DisplayHandler = new ChromiumApplication.Main.Handler.DisplayHandler();
            ChromiumWebBrowser.MenuHandler = new ChromiumApplication.Main.Handler.Example.MenuHandler();
            ChromiumWebBrowser.RequestHandler = new RequestHandler();
            ChromiumWebBrowser.RequestHandler = new WinFormsRequestHandler(openNewTab);
          
            /* Customize Handler */
            ChromiumWebBrowser.LifeSpanHandler = new ChromiumApplication.Main.Handler.LifeSpanHandler();
              ChromiumWebBrowser.RenderProcessMessageHandler = new RenderProcessMessageHandler();
            /// ChromiumWebBrowser.KeyboardHandler = new KeyboardHandler();
            ///  ChromiumWebBrowser.MenuHandler = new CustomMenuHandler();
            /// ChromiumWebBrowser.JsDialogHandler = new ChromiumApplication.Main.Handlers.JsDialogHandler();

            RequestContextSettings requestContextSettings = new RequestContextSettings();
            requestContextSettings.AcceptLanguageList = "en-US,ru,ar,zh-CN,zh-TW,ko,ja,en-GB";
            requestContextSettings.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.AppPathProfileUserDataCefSharp";
            requestContextSettings.PersistSessionCookies = true;
            requestContextSettings.PersistUserPreferences = true;
            requestContextSettings.IgnoreCertificateErrors = true;
            requestContextSettings.EnableNetSecurityExpiration = true;
            ChromiumWebBrowser.RequestContext = new  RequestContext(requestContextSettings);



            ChromiumWebBrowser.JavascriptObjectRepository.Register("bound", new BoundObject(), isAsync: false, options: BindingOptions.DefaultBinder);
            ChromiumWebBrowser.JavascriptObjectRepository.Register("boundAsync", new BoundObject.AsyncBoundObject(), isAsync: true, options: BindingOptions.DefaultBinder);

            //If you call CefSharp.BindObjectAsync in javascript and pass in the name of an object which is not yet
            //bound, then ResolveObject will be called, you can then register it
            ChromiumWebBrowser.JavascriptObjectRepository.ResolveObject += (sender, e) =>
            {
                var repo = e.ObjectRepository;
                if (e.ObjectName == "boundAsync2")
                {
                    repo.Register("boundAsync2", new BoundObject.AsyncBoundObject(), isAsync: true, options: BindingOptions.DefaultBinder);
                }
            };
            /// ChromiumWebBrowser.CreateControl();
            settings.RegisterExtension(new V8Extension("showModalDialog", Resources.showModalDialog)); ///CefExtension


            //   settings.RegisterExtension(new CefExtension("showModalDialog", Resources.showModalDialog)); ///CefExtension

            GETExample.RegisterTestResources(ChromiumWebBrowser);
           // ChromiumWebBrowser.RegisterJsObject("bound", new BoundObject());
           // BindingOptions options = null;
           // ChromiumWebBrowser.JavascriptObjectRepository.Register("boundAsync", new BoundObject(), true, options);

            // ChromiumWebBrowser.JsDialogHandler = new ChromiumApplication.Main.Handlers.JsDialogHandler();
            // ChromiumWebBrowser.KeyboardHandler = new KeyboardHandler();


            // ChromiumWebBrowser.DisplayHandler = new ChromiumApplication.Main.Handler.DisplayHandler();
            // Load += Form1_Load;

            //Only perform layout when control has completly finished resizing
            /// ResizeBegin += (s, e) => SuspendLayout();
            ///  ResizeEnd += (s, e) => ResumeLayout(true);

            this.multiThreadedMessageLoopEnabled = multiThreadedMessageLoopEnabled;

            //    ChromiumWebBrowser.NewTabClicked += control_NewTabClicked;
            //  uiBrowserTabControl.SelectedIndexChange += uiBrowserTabControl_SelectedIndexChange;
            // uiBrowserTabControl.Closed += UiBrowserTabControl_Closed;
          //// CefExample.RegisterTestResources(ChromiumWebBrowser);


            var bitness = Environment.Is64BitProcess ? "x64" : "x86";
            var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}, Environment: {3}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion, bitness);