Exemple #1
0
        protected List <BrowserTab> ListTabs(AutomationElement root, Process process, string windowName)
        {
            List <BrowserTab> result    = new List <BrowserTab>();
            Condition         condition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem);
            var tabs = root.FindAll(TreeScope.Descendants, condition);

            Console.WriteLine($"Active tab: {root.Current.Name}");
            //var elmUrlBar = root.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));

            //var buttons = root.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button));

            foreach (AutomationElement tabitem in tabs)
            {
                Console.WriteLine(tabitem.Current.Name);

                BrowserTab tab = new BrowserTab
                {
                    Name         = tabitem.Current.Name,
                    Url          = windowName.Contains(tabitem.Current.Name) ? FindWindowUrl(process) : string.Empty,
                    IsCurrentTab = windowName.Contains(tabitem.Current.Name)
                };

                result.Add(tab);
            }

            return(result);
        }
        /// <summary>
        /// Manages the browser tabs
        /// </summary>
        private void ManageTabs()
        {
            // Close the app in case all tabs are closed
            this.browserTabControl.TabClosed += (object sender, EventArgs e) =>
            {
                if (this.browserTabControl.TabCount == 0)
                {
                    Environment.Exit(0);
                }
            };

            // Start with one tab (Homepage)
            var webBrowser = new ChromiumWebBrowser();

            webBrowser.BrowserSettings.FileAccessFromFileUrls = CefSharp.CefState.Enabled;      // Enable loading local files through the browser
            var        navigationBar = new NavigationBarControl();
            BrowserTab browserTab    = new BrowserTab(navigationBar, webBrowser);

            webBrowser.Address = GetInitialUrl();
            Grid tabContent = CreateGrid(navigationBar, webBrowser);

            this.browserTabControl.AddTab(webBrowser, "Home page", tabContent);

            // Enable tab adding
            this.browserTabControl.NewTabButtonClick += (object sender, EventArgs e) =>
            {
                this.AddNewTab();
            };
        }
        public BrowserTab GetNewTab(string URL)
        {
            BrowserTab browserTab = new BrowserTab(URL);

            browserTab.NewPopUpEvent += OnNewPopUp;
            browserTab.TabCloseEvent += OnTabClose;
            return(browserTab);
        }
        public void AddNewTab(string address = "")
        {
            var webBrowser = new ChromiumWebBrowser();

            // In case no address was given use the default new tab address mentioned in user settings
            if (String.IsNullOrEmpty(address))
            {
                address = UserSettings.Load().NewTabPage;
            }
            webBrowser.BrowserSettings.FileAccessFromFileUrls = CefSharp.CefState.Enabled;  // Enable loading local files through the browser
            var navigationBar = new NavigationBarControl();
            var browserTab    = new BrowserTab(navigationBar, webBrowser);

            webBrowser.Address = address;
            Grid tabContent = CreateGrid(navigationBar, webBrowser);

            this.browserTabControl.AddTab(webBrowser, "New Tab", tabContent);
        }
Exemple #5
0
 private List<BrowserScript> getBrowserScripts(Assembly asm, BrowserTab bt, bool checkDisabledSystemScripts)
 {
     List<BrowserScript> result = new List<BrowserScript>();
     Type[] types = asm.GetTypes();
     bool initSystemScriptNames = (checkDisabledSystemScripts && _systemScriptsNames.Count == 0);
     foreach (Type t in types)
     {
         if (t.IsClass && (t.BaseType == typeof(BrowserScript)))
         {
             if (checkDisabledSystemScripts && !Properties.Settings.Default.DisabledSystemScripts.Contains(t.Name))
             {
                 ConstructorInfo constructor = t.GetConstructor(new Type[] { typeof(BrowserTab), typeof(Utils.BasePlugin.Plugin), typeof(WebBrowser), typeof(Framework.Interfaces.ICore) });
                 if (constructor != null)
                 {
                     object[] parameters = new object[] { bt, this.OwnerPlugin, bt.Browser, Core };
                     BrowserScript obj = (BrowserScript)constructor.Invoke(parameters);
                     result.Add(obj);
                 }
             }
             if (initSystemScriptNames)
             {
                 _systemScriptsNames.Add(t.Name);
             }
         }
     }
     return result;
 }
Exemple #6
0
        private BrowserTab newTab(string url, NewWindow2EventArgs e)
        {
            if (tabControl1.TabPages.Count == 0)
            {
                setBrowserEmulationMode(System.IO.Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location));
#if DEBUG
                setBrowserEmulationMode(System.IO.Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location).Replace(".exe",".vshost.exe"));
#endif
            }

            BrowserTab result = new BrowserTab(this);
            if (e != null)
            {
                e.PPDisp = (result.Browser as ExtendedWebBrowser).Application;
            }

            //scripting stuff
            result.ControlContainer = new FlowLayoutPanel();
            result.ControlContainer.Dock = DockStyle.Fill;
            result.ControlContainer.AutoScroll = true;
            result.ControlContainer.FlowDirection = FlowDirection.TopDown;
            result.Scripts = new List<BrowserScript>();
            result.Scripts.AddRange(getBrowserScripts(Assembly.GetExecutingAssembly(), result, true));
            if (_userScripts != null)
            {
                Assembly asm = _userScripts.CompiledAssembly;
                if (asm != null)
                {
                    result.Scripts.AddRange(getBrowserScripts(asm, result, false));
                }
            }
            foreach (BrowserScript bs in result.Scripts)
            {
                if (bs.HasControls)
                {
                    Label l = new Label();
                    l.Dock = DockStyle.Top;
                    l.AutoSize = false;
                    l.TextAlign = ContentAlignment.MiddleCenter;
                    l.BackColor = Color.LightCyan;
                    l.Text = Utils.LanguageSupport.Instance.GetTranslation(bs.Name);
                    result.ControlContainer.Controls.Add(l);
                    bs.CreateControls(result.ControlContainer.Controls);
                }
            }
            tabControl1_Selecting(this, null);
            tabControl1.TabPages.Add(result);
            tabControl1.SelectedIndex = tabControl1.TabPages.Count - 1;
            result.Browser.ScriptErrorsSuppressed = Properties.Settings.Default.ScriptErrorsSuppressed;
            result.Browser.StatusTextChanged += new EventHandler(Browser_StatusTextChanged);
            result.Browser.DocumentTitleChanged += new EventHandler(Browser_DocumentTitleChanged);
            result.Browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Browser_DocumentCompleted);
            result.Browser.CanGoBackChanged += new EventHandler(Browser_CanGoBackChanged);
            result.Browser.CanGoForwardChanged += new EventHandler(Browser_CanGoForwardChanged);
            (result.Browser as ExtendedWebBrowser).NewWindow2 +=new EventHandler<NewWindow2EventArgs>(WebbrowserForm_NewWindow2);
            result.Text = result.Browser.DocumentTitle;
            if (url != null)
            {
                comboBox1.Text = url;
                result.Browser.Navigate(url);
            }
            tabControl1_Selected(this, null);

            int max = 10;
            foreach (Control c in result.ControlContainer.Controls)
            {
                if (c.Width > max)
                {
                    max = c.Width;
                }
            }
            splitContainer1.SplitterDistance = max;
            button6.Enabled = true;

            return result;
        }
Exemple #7
0
        private BrowserTab newTab(string url, NewWindow2EventArgs e)
        {
            if (tabControl1.TabPages.Count == 0)
            {
                setBrowserEmulationMode(System.IO.Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location));
#if DEBUG
                setBrowserEmulationMode(System.IO.Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location).Replace(".exe", ".vshost.exe"));
#endif
            }

            BrowserTab result = new BrowserTab(this);
            if (e != null)
            {
                e.PPDisp = (result.Browser as ExtendedWebBrowser).Application;
            }

            //scripting stuff
            result.ControlContainer               = new FlowLayoutPanel();
            result.ControlContainer.Dock          = DockStyle.Fill;
            result.ControlContainer.AutoScroll    = true;
            result.ControlContainer.FlowDirection = FlowDirection.TopDown;
            result.Scripts = new List <BrowserScript>();
            result.Scripts.AddRange(getBrowserScripts(Assembly.GetExecutingAssembly(), result, true));
            if (_userScripts != null)
            {
                Assembly asm = _userScripts.CompiledAssembly;
                if (asm != null)
                {
                    result.Scripts.AddRange(getBrowserScripts(asm, result, false));
                }
            }
            foreach (BrowserScript bs in result.Scripts)
            {
                if (bs.HasControls)
                {
                    Label l = new Label();
                    l.Dock      = DockStyle.Top;
                    l.AutoSize  = false;
                    l.TextAlign = ContentAlignment.MiddleCenter;
                    l.BackColor = Color.LightCyan;
                    l.Text      = Utils.LanguageSupport.Instance.GetTranslation(bs.Name);
                    result.ControlContainer.Controls.Add(l);
                    bs.CreateControls(result.ControlContainer.Controls);
                }
            }
            tabControl1_Selecting(this, null);
            tabControl1.TabPages.Add(result);
            tabControl1.SelectedIndex                          = tabControl1.TabPages.Count - 1;
            result.Browser.ScriptErrorsSuppressed              = PluginSettings.Instance.ScriptErrorsSuppressed;
            result.Browser.StatusTextChanged                  += new EventHandler(Browser_StatusTextChanged);
            result.Browser.DocumentTitleChanged               += new EventHandler(Browser_DocumentTitleChanged);
            result.Browser.DocumentCompleted                  += new WebBrowserDocumentCompletedEventHandler(Browser_DocumentCompleted);
            result.Browser.CanGoBackChanged                   += new EventHandler(Browser_CanGoBackChanged);
            result.Browser.CanGoForwardChanged                += new EventHandler(Browser_CanGoForwardChanged);
            (result.Browser as ExtendedWebBrowser).NewWindow2 += new EventHandler <NewWindow2EventArgs>(WebbrowserForm_NewWindow2);
            result.Text = result.Browser.DocumentTitle;
            if (url != null)
            {
                comboBox1.Text = url;
                result.Browser.Navigate(url);
            }
            tabControl1_Selected(this, null);

            int max = 10;
            foreach (Control c in result.ControlContainer.Controls)
            {
                if (c.Width > max)
                {
                    max = c.Width;
                }
            }
            splitContainer1.SplitterDistance = max;
            button6.Enabled = true;

            return(result);
        }