Skip to main content

Using load listener

Sabre Red 360 Developer Toolkit provides capability to register listener by RedApp to track page loading events. Load listener has several method which are triggered during specific events when page is being loaded by webkit.

The following code snippet demonstrates sample load listener with all methods and how to register it.

Source code of ExampleWebkitLoadListener.java
package com.sabre.redapp.example.webkit.editor.listeners;

import java.util.Map;
import com.sabre.edge.platform.core.logging.ILoggerService;
import com.sabre.edge.platform.optional.webkit.editors.listeners.WebkitLoadListener;
import com.sabre.redapp.example.webkit.Activator;

/**
 * Webkit load listener handles all events during page loading.
 */
public class ExampleWebkitLoadListener extends WebkitLoadListener
{
    @Override
    public void onBeforeRedirect(Map <String, String> data) // (1)
    {
        ILoggerService log = Activator.getDefault().getLoggerService();
        log.info("ExampleWebkitLoadListener onBeforeRedirect");
    }

    @Override
    public void onBeforeURLRequest(Map <String, String> data) // (2)
    {
        ILoggerService log = Activator.getDefault().getLoggerService();
        log.info("ExampleWebkitLoadListener onBeforeURLRequest");
    }

    @Override
    public void onFailLoadingFrame() // (3)
    {
        ILoggerService log = Activator.getDefault().getLoggerService();
        log.info("ExampleWebkitLoadListener onFailLoadingFrame");
    }

    @Override
    public void onFinishLoadingFrame() // (4)
    {
        ILoggerService log = Activator.getDefault().getLoggerService();
        log.info("ExampleWebkitLoadListener onFinishLoadingFrame");
    }

    @Override
    public void onFinishLoadingFrame(Map <String, String> data) // (5)
    {
        ILoggerService log = Activator.getDefault().getLoggerService();
        log.info("ExampleWebkitLoadListener onFinishLoadingFrame (with params)");
    }

    @Override
    public void onStartLoadingFrame() // (6)
    {
        ILoggerService log = Activator.getDefault().getLoggerService();
        log.info("ExampleWebkitLoadListener onStartLoadingFrame");
    }
}
  1. Invoked before the redirect from current URL will be performed to location URL. Data holder to keep the context of loaded frame.

  2. Invoked before the requested URL will be processed by the browser. Data holder to keep the context of loaded frame.

  3. Invoked when browser failed loading a frame.

  4. Invoked when browser finishes loading a frame.

  5. Invoked when browser finishes loading a frame with reference to loaded data. Data holder to keep the context of loaded frame.

  6. Invoked when browser starts loading a frame.

Source code of ExampleBrowserEditor.java
package com.sabre.redapp.example.webkit.editor;

import com.sabre.edge.platform.optional.webkit.editors.DefaultWebkitEditor;
import com.sabre.redapp.example.webkit.editor.listeners.ExampleWebkitLoadListener;

/**
 * Browser editor implementation.
 */
public class ExampleBrowserEditor extends DefaultWebkitEditor
{
    @Override
    public void registerLoadListeners() // (1)
    {
        super.registerLoadListeners(); // (2)
        registerLoadListener(new ExampleWebkitLoadListener()); // (3)
    }
}
  1. This is parent method where listener can be added. It should be override by RedApp webkit editor class.

  2. Parent implementation should be invoked to add defined in parent listeners.

  3. Use registerLoadListener method to add new listener.