String searchUrl = newUrl;
// search backwards through the resources until
// we find the main ResourceSendRequest
while (startCopyIndex == -1 && index >= 0) {
EventRecord aRecord = eventRecords.get(index);
if (aRecord.getType() == EventRecordType.NETWORK_REQUEST_WILL_BE_SENT) {
// see if there's a redirect
NetworkRequestWillBeSentEvent request = aRecord.cast();
String redirectUrl = request.getRedirectUrl();
if(redirectUrl != null) {
// if so, keep searching for the original URL request
searchUrl = redirectUrl;
}
}
if (aRecord.getType() == EventRecordType.RESOURCE_SEND_REQUEST) {
// check if we've found a matching URL
ResourceWillSendEvent event = aRecord.cast();
String thisUrl = event.getUrl();
if(thisUrl.equals(searchUrl)) {
startCopyIndex = index;
}
}
index--;
}
// did not find the matching URL
// should this be an assert or are there cases where it will happen?
if(startCopyIndex < 0) {
return;
}
for (int k = startCopyIndex; k < eventRecords.size(); k++) {
EventRecord copyRecord = eventRecords.get(k);
// don't re-dispatch the tab change event
if (copyRecord.getType() == EventRecordType.TAB_CHANGED) {
continue;
}
newState.getDataDispatcher().getNetworkEventDispatcher().onEventRecord(copyRecord);
}
}