use of org.chromium.chrome.browser.document.DocumentActivity in project AndroidChromium by JackyAndroid.
the class DocumentTabModelImpl method getTabAt.
@Override
public Tab getTabAt(int index) {
if (index < 0 || index >= getCount())
return null;
// Return a live tab if the corresponding DocumentActivity is currently alive.
int tabId = mTabIdList.get(index);
List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
for (WeakReference<Activity> activityRef : activities) {
Activity activity = activityRef.get();
if (!(activity instanceof DocumentActivity) || !mActivityDelegate.isValidActivity(isIncognito(), activity.getIntent())) {
continue;
}
Tab tab = ((DocumentActivity) activity).getActivityTab();
int documentId = tab == null ? Tab.INVALID_TAB_ID : tab.getId();
if (documentId == tabId)
return tab;
}
// Try to create a Tab that will hold the Tab's info.
Entry entry = mEntryMap.get(tabId);
assert entry != null;
// If a tab has already been initialized, use that.
if (entry.placeholderTab != null && entry.placeholderTab.isInitialized()) {
return entry.placeholderTab;
}
// Create a frozen Tab if we are capable, or if the previous Tab is just a placeholder.
if (entry.getTabState() != null && isNativeInitialized() && (entry.placeholderTab == null || !entry.placeholderTab.isInitialized())) {
entry.placeholderTab = getTabCreator(isIncognito()).createFrozenTab(entry.getTabState(), entry.tabId, TabModel.INVALID_TAB_INDEX);
entry.placeholderTab.initializeNative();
}
// Create a placeholder Tab that just has the ID.
if (entry.placeholderTab == null) {
entry.placeholderTab = new Tab(tabId, isIncognito(), null);
}
return entry.placeholderTab;
}
Aggregations