if (m.getPages().size() == 0) {
throw new WebDriverException(m.getPages().size() + " new pages.");
}
// TODO there can be more than one 'new' UIWebView, picking the max one for now.
WebkitPage newOne = Collections.max(m.getPages());
pages.addAll(m.getPages());
driver.setPages(pages);
if (driver.getPages().size() == 0) {
//log.fine("first page. Nothing to do.");
} else if (newOne.isITunesAd()) {
//log.fine("itunes ad - ignoring it.");
} else {
WebkitPage focus = newOne;
if (session != null) {
waitForWindowSwitchingAnimation();
driver.switchTo(focus);
} else {
driver.switchTo(focus);
}
}
// a page disappeared, the driver needs to know.
} else if (change < 0) {
List<WebkitPage> old = new ArrayList<WebkitPage>();
old.addAll(driver.getPages());
for (WebkitPage p : m.getPages()) {
old.remove(p);
}
// TODO freynaud problem here.How to handle a window disappearing without loosing the state
// of the currently selected page. driver.getPages() may need to become mutable again.
// in the normal case, this is the page with the focus that is closed, so loosing the state
// is ok. But for the extra window automatically closed ( ie the "there is an app for that
// page, downlaod it on itune" page header, the header disappears when driver.get navigates
// to a new page. The header disapeearing shouldn't impact the current state.
for (WebkitPage p : old) {
log.fine(
"the page " + p + " has been deleted and must be removed from the driver cache");
int currentFocus = driver.getCurrentPageID();
if (p.getPageId() == currentFocus) {
log.fine("the page deleted is the one with the focus.");
} else {
driver.setPages(m.getPages());
}
}
}
sync.signalSimSentPages();
} else {
driver.setPages(messagePages);
if (messagePages.size() > 0) {
if (session != null) {
waitForWindowSwitchingAnimation();
}
WebkitPage focus = selectPage(driver.getPages());
if (focus != null) {
driver.switchTo(focus);
}
}
sync.signalSimSentPages();