public Responder(WindowExt window, final String origin, final ResponseListener listener) { final boolean acceptAllOrigins = "*".equals(origin); remover = Event.addEventListener( "message", window, new EventListener() { public void handleEvent(Event event) { final Message e = event.cast(); if (acceptAllOrigins || origin.equals(e.getOrigin())) { listener.onMessageReceived(Responder.this, e); } } }); }
/** * Creates a new client channel. * * @param document the document in which to insert the iframe * @param url the url to the remote peer * @param listener a callback to be notified on channel events */ public Client(Document document, String url, final ClientListener listener) { origin = getDomain(url); frame = document.getBody().appendChild(createFrame(document, url)); receiver = new Responder(getCurrentWindow(), origin, listener); remover = Event.addEventListener( "load", frame, new EventListener() { public void handleEvent(Event event) { // This should never call synchronously. assert remover != null; assert !setConnected(true); listener.onConnected(Client.this); remover.remove(); } }); }