Example usage for com.google.gwt.chrome.crx.client.events SendResponse invoke

List of usage examples for com.google.gwt.chrome.crx.client.events SendResponse invoke

Introduction

In this page you can find the example usage for com.google.gwt.chrome.crx.client.events SendResponse invoke.

Prototype

public final native void invoke(JavaScriptObject response) ;

Source Link

Usage

From source file:com.google.speedtracer.client.BackgroundPage.java

License:Apache License

private void listenForExternalExtensions(final ExternalExtensionListener exListener) {
    // External extensions can also be used as data sources. Hook this up.
    Chrome.getExtension().getOnRequestExternalEvent().addListener(new RequestExternalEvent.Listener() {
        public void onRequestExternal(JavaScriptObject request, Sender sender, SendResponse sendResponse) {
            // Ensure the extension attempting to connect is not blacklisted.
            if (!ExternalExtensionDataInstance.isBlackListed(sender.getId())) {
                final ConnectRequest connectRequest = request.cast();
                final int browserId = connectRequest.getBrowserId();

                BrowserConnectionState connection = browserConnectionMap.get(browserId);

                if (connection == null) {
                    // If this is the first opened connection for this browser type,
                    // then we provision an entry for it in the browser map.
                    exListener.onBrowserConnected(browserId);
                }/*  w  ww  .  ja  v a2 s .com*/

                final int tabId = connectRequest.getTabId();
                final String portName = ExternalExtensionDataInstance.SPEED_TRACER_EXTERNAL_PORT + browserId
                        + "-" + tabId;

                // So we will now begin listening for connections on a dedicated
                // port name for this browser/tab combo.
                Chrome.getExtension().getOnConnectExternalEvent()
                        .addListener(new ConnectExternalEvent.Listener() {
                            public void onConnectExternal(Port port) {
                                if (portName.equals(port.getName())) {
                                    // Provision a DataInstance and a TabDescription.
                                    DataInstance dataInstance = ExternalExtensionDataInstance.create(port);
                                    TabDescription tabDescription = TabDescription.create(tabId,
                                            connectRequest.getTitle(), connectRequest.getUrl());

                                    // Now remember the DataInstance and TabDescription, and
                                    // open a Monitor.
                                    exListener.onTabMonitorStarted(browserId, tabDescription, dataInstance);
                                }
                            }
                        });

                // Send a response that tells the external extension what port
                // name to connect to.
                sendResponse.invoke(ExternalExtensionDataInstance.createResponse(portName));
            }
        }
    });
}