Class UserTokenBrowserListener

java.lang.Object
velox.gui.browser.UserTokenBrowserListener
All Implemented Interfaces:
BrowserListener

public class UserTokenBrowserListener extends Object implements BrowserListener
BrowserListener that exposes a user identification API to the loaded page. After the page is loaded, it can call getUserToken() to obtain a token identifying the current user, see UserTokenHelper.generateToken(). The JS function definition injected into the page is in resources/browser/GetUserToken.js.

Not wired in by default. See BrowserSettings.setListener(BrowserListener).

Extensible. To expose more functions, override handleFunction(velox.gui.browser.Browser, java.lang.String, com.google.gson.JsonObject, java.util.function.Consumer<java.lang.String>) and handle your functions there, delegating to super.handleFunction for the rest. To inject the JS definitions of those functions, override onPageLoaded(velox.gui.browser.Browser, java.lang.String, int) and call super.onPageLoaded as well.

Message protocol: the page sends a JSON object with a functionName field plus function-specific arguments, and receives the result as JSON through the bmMessage callback.

  • Field Details

    • GSON

      protected static final com.google.gson.Gson GSON
  • Constructor Details

    • UserTokenBrowserListener

      public UserTokenBrowserListener()
  • Method Details

    • onPageLoaded

      public void onPageLoaded(Browser browser, String url, int statusCode)
      Specified by:
      onPageLoaded in interface BrowserListener
    • onMessage

      public void onMessage(Browser browser, String message, Consumer<String> callback)
      Description copied from interface: BrowserListener
      Called when the page sends a message by calling bmMessage(message, optional callback).
      Specified by:
      onMessage in interface BrowserListener
      Parameters:
      callback - used to send the response back to the page if it was set in bmMessage above. Otherwise, calling has no effect. Can be freely called from any thread at any time, but only once.
    • handleFunction

      protected boolean handleFunction(Browser browser, String functionName, com.google.gson.JsonObject message, Consumer<String> callback)
      Override to handle additional functions. The default implementation handles getUserToken.