}
private static JavascriptVmEmbedder.ConnectionToRemote connect(Browser browser,
final TabSelector tabSelector) throws CoreException {
final TabFetcher tabFetcher;
try {
tabFetcher = browser.createTabFetcher();
} catch (UnsupportedVersionException e) {
throw newCoreException(e);
} catch (IOException e) {
throw newCoreException(e);
}
return new JavascriptVmEmbedder.ConnectionToRemote() {
public JavascriptVmEmbedder.VmConnector selectVm() throws CoreException {
Browser.TabConnector targetTabConnector;
try {
targetTabConnector = tabSelector.selectTab(tabFetcher);
} catch (IOException e) {
throw newCoreException("Failed to get tabs for debugging", e);
}
if (targetTabConnector == null) {
return null;
}
return new EmbeddingTabConnectorImpl(targetTabConnector);
}
public void disposeConnection() {
tabFetcher.dismiss();
}
};
}