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);
}
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);