Example #1
0
        public PenBrowser(Action <string, int, BroserSetting, string> openNewTab, string url, BroserSetting setting = null)
        {
            InitializeComponent();
            this.Setting = setting == null ? new BroserSetting() : setting;

            GlobalSettings.Init();
            var browser = new ChromiumWebBrowser(url)
            {
                Dock = DockStyle.Fill
            };

            browser.LifeSpanHandler             = new PenLifeSpanHandler(openNewTab, this.Setting);
            browser.RequestHandler              = new PenRequestHandler(openNewTab, this.Setting);
            browser.MenuHandler                 = new PenMenuHandler();
            browser.RenderProcessMessageHandler = new PenRenderProcessMessageHandler(OnContextCreated);

            browser.LoadingStateChanged += this.LoadingStateChanged;
            browser.FrameLoadStart      += this.FrameLoadStart;
            browser.FrameLoadEnd        += this.FrameLoadEnd;


            CefSharpSettings.LegacyJavascriptBindingEnabled             = true;
            browser.JavascriptObjectRepository.ObjectBoundInJavascript += ObjectBoundInJavascript;
            browser.JavascriptObjectRepository.Register("pen", new BoundObject(this.Setting.VisitorJsEvent == null ? this.DefaultVisitorJs : this.Setting.VisitorJsEvent), true);

            if (this.Setting.CookiesSetting != null && this.Setting.CookiesSetting.Cookies != null)
            {
                this.SetCookie(this.Setting.CookiesSetting.Cookies);
            }

            this.Browser = browser;
            this.browserPanel.Controls.Add(browser);
        }
Example #2
0
        public void AddTab(string url, int insertIndex = -1, BroserSetting setting = null, string title = "")
        {
            browserTabControl.SuspendLayout();

            var browser = new PenBrowser(AddTab, url, setting)
            {
                Dock = DockStyle.Fill
            };

            if (string.IsNullOrEmpty(title))
            {
                title = url;
            }
            if (title.Length > 15)
            {
                title = title.Substring(0, 15) + "...";
            }

            var tabPage = new TabPage(title + "   ");

            tabPage.Controls.Add(browser);
            if (insertIndex == -1)
            {
                browserTabControl.TabPages.Add(tabPage);
            }
            else
            {
                browserTabControl.TabPages.Insert(insertIndex, tabPage);
            }

            browserTabControl.SelectedTab = tabPage;
            browserTabControl.ResumeLayout(true);

            tabPage.Dock = DockStyle.Fill;
        }
Example #3
0
 public PenLifeSpanHandler(Action <string, int, BroserSetting, string> openNewTab, BroserSetting broserSetting)
 {
     this.openNewTab    = openNewTab;
     this.broserSetting = broserSetting;
 }