Search in sources :

Example 1 with BrowserMessageListener

use of com.biglybt.core.messenger.browser.listeners.BrowserMessageListener in project BiglyBT by BiglySoftware.

the class MessageDispatcherSWT method addListener.

/**
 * Registers the given listener for the given ID.
 *
 * @param id unique identifier used when dispatching messages
 * @param listener receives messages targetted at the given ID
 *
 * @throws IllegalStateException
 *              if another listener is already registered under the same ID
 */
@Override
public synchronized void addListener(BrowserMessageListener listener) {
    String id = listener.getId();
    BrowserMessageListener registered = listeners.get(id);
    if (registered != null) {
        if (registered != listener) {
            throw new IllegalStateException("Listener " + registered.getClass().getName() + " already registered for ID " + id);
        }
    } else {
        listener.setContext(context);
        listeners.put(id, listener);
    }
}
Also used : BrowserMessageListener(com.biglybt.core.messenger.browser.listeners.BrowserMessageListener)

Example 2 with BrowserMessageListener

use of com.biglybt.core.messenger.browser.listeners.BrowserMessageListener in project BiglyBT by BiglySoftware.

the class MessageDispatcherSWT method dispatch.

// @see com.biglybt.ui.swt.browser.msg.MessageDispatcher#dispatch(com.biglybt.core.messenger.browser.BrowserMessage)
@Override
public void dispatch(final BrowserMessage message) {
    if (message == null) {
        return;
    }
    String referer = message.getReferer();
    if (referer != null && !UrlFilter.getInstance().urlCanRPC(referer)) {
        context.debug("blocked " + message + "\n  " + referer);
        return;
    }
    context.debug("Received " + message);
    if (browser != null && !browser.isDisposed() && Utils.isThisThreadSWT()) {
        context.debug("   browser url: " + browser.getUrl());
    }
    // handle messages for dispatcher and context regardless of sequence number
    String listenerId = message.getListenerId();
    if ("lightbox-browser".equals(listenerId)) {
        listenerId = "display";
    }
    final BrowserMessageListener listener = getListener(listenerId);
    if (listener == null) {
        context.debug("No listener registered with ID " + listenerId);
    } else {
        new AEThread2("dispatch for " + listenerId, true) {

            @Override
            public void run() {
                listener.handleMessage(message);
                message.complete(true, true, null);
            }
        }.start();
    }
}
Also used : AEThread2(com.biglybt.core.util.AEThread2) BrowserMessageListener(com.biglybt.core.messenger.browser.listeners.BrowserMessageListener)

Aggregations

BrowserMessageListener (com.biglybt.core.messenger.browser.listeners.BrowserMessageListener)2 AEThread2 (com.biglybt.core.util.AEThread2)1