Class SelectedBrowser


  • public class SelectedBrowser
    extends Object
    This class selects the browser based on various criteria. The selection can be enforced using the style parameter or setting the corresponding system property.

    The edge integration has some trouble, especially "evaluate" inside a BrowserFunction. Therefore BrowserFunctions should be created via this class which makes these calls asynchronous.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.eclipse.swt.browser.Browser browser
      The selected and wrapped browser.
      protected boolean fixEdge
      Whether Edge is the selected browser which requires asynchronous calls for fixing the execution of BrowserFunctions.
    • Constructor Summary

      Constructors 
      Constructor Description
      SelectedBrowser​(org.eclipse.swt.widgets.Composite parent)
      Creates a new browser with the designated Composite as parent.
      SelectedBrowser​(org.eclipse.swt.widgets.Composite parent, int style)
      Creates a new browser with the designated Composite as parent and the designated style.
    • Field Detail

      • browser

        protected final org.eclipse.swt.browser.Browser browser
        The selected and wrapped browser.
      • fixEdge

        protected final boolean fixEdge
        Whether Edge is the selected browser which requires asynchronous calls for fixing the execution of BrowserFunctions.
        See Also:
        "evaluate" inside a BrowserFunction
    • Constructor Detail

      • SelectedBrowser

        public SelectedBrowser​(org.eclipse.swt.widgets.Composite parent)
        Creates a new browser with the designated Composite as parent.
        Parameters:
        parent - The parent of the created browser.
      • SelectedBrowser

        public SelectedBrowser​(org.eclipse.swt.widgets.Composite parent,
                               int style)
        Creates a new browser with the designated Composite as parent and the designated style.
        Parameters:
        parent - The parent of the created browser.
        style - The style of the created browser.
    • Method Detail

      • selectBrowser

        protected static int selectBrowser​(int style)
        Selects the browser by adapting the style appropriately. If the designated style contains the browser or the corresponding system property is set, no adaption will take place.
        Currently Edge will be selected on Windows.
        Parameters:
        style - The style to use for the browser.
        Returns:
        The possibly adapted style containing the default browser (if not specified otherwise).
      • getBrowser

        public org.eclipse.swt.browser.Browser getBrowser()
        Gets the selected and wrapped browser.
        Returns:
        The selected and wrapped browser.
      • createBrowserFunction

        public org.eclipse.swt.browser.BrowserFunction createBrowserFunction​(String name,
                                                                             Consumer<Object[]> function)
        Creates a new BrowserFunction for the selected browser with the designated name and calling the designated consumer. Due to problems with Edge, only asynchronous calls are possible, i. e. only functions without return value. However, other browsers will execute the function synchronously.
        Parameters:
        name - The name of the browser function.
        function - The function (Consumer) to be called (asynchronously).
        Returns:
        The created BrowserFunction.
      • createBrowserFunction

        public org.eclipse.swt.browser.BrowserFunction createBrowserFunction​(String name,
                                                                             Runnable function)
        Creates a new BrowserFunction for the selected browser with the designated name and executing the designated runnable. Due to problems with Edge, the runnable will be executed asynchronously with Edge (but not with other browsers.
        Parameters:
        name - The name of the browser function.
        function - The function (Runnable) to be called (asynchronously).
        Returns:
        The created BrowserFunction.