use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.
the class TabModelImpl method removeTabAndSelectNext.
/**
* Removes the given tab from the tab model and selects a new tab.
*/
private void removeTabAndSelectNext(Tab tab, TabSelectionType selectionType, boolean pauseMedia, boolean updateRewoundList) {
assert selectionType == TabSelectionType.FROM_CLOSE || selectionType == TabSelectionType.FROM_EXIT;
final int closingTabId = tab.getId();
final int closingTabIndex = indexOf(tab);
Tab currentTab = TabModelUtils.getCurrentTab(this);
Tab adjacentTab = getTabAt(closingTabIndex == 0 ? 1 : closingTabIndex - 1);
Tab nextTab = getNextTabIfClosed(closingTabId);
// TODO(dtrainor): Update the list of undoable tabs instead of committing it.
if (updateRewoundList)
commitAllTabClosures();
// Cancel or mute any media currently playing.
if (pauseMedia) {
WebContents webContents = tab.getWebContents();
if (webContents != null) {
webContents.suspendAllMediaPlayers();
webContents.setAudioMuted(true);
}
}
mTabs.remove(tab);
boolean nextIsIncognito = nextTab == null ? false : nextTab.isIncognito();
int nextTabId = nextTab == null ? Tab.INVALID_TAB_ID : nextTab.getId();
int nextTabIndex = nextTab == null ? INVALID_TAB_INDEX : TabModelUtils.getTabIndexById(mModelDelegate.getModel(nextIsIncognito), nextTabId);
if (nextTab != currentTab) {
if (nextIsIncognito != isIncognito())
mIndex = indexOf(adjacentTab);
TabModel nextModel = mModelDelegate.getModel(nextIsIncognito);
nextModel.setIndex(nextTabIndex, selectionType);
} else {
mIndex = nextTabIndex;
}
if (updateRewoundList)
mRewoundList.resetRewoundState();
}
use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.
the class TabModelImpl method cancelTabClosure.
@Override
public void cancelTabClosure(int tabId) {
Tab tab = mRewoundList.getPendingRewindTab(tabId);
if (tab == null)
return;
tab.setClosing(false);
// Find a valid previous tab entry so we know what tab to insert after. With the following
// example, calling cancelTabClosure(4) would need to know to insert after 2. So we have to
// track across mRewoundTabs and mTabs and see what the last valid mTabs entry was (2) when
// we hit the 4 in the rewound list. An insertIndex of -1 represents the beginning of the
// list, as this is the index of tab to insert after.
// mTabs: 0 2 5
// mRewoundTabs 0 1 2 3 4 5
int prevIndex = -1;
final int stopIndex = mRewoundList.indexOf(tab);
for (int rewoundIndex = 0; rewoundIndex < stopIndex; rewoundIndex++) {
Tab rewoundTab = mRewoundList.getTabAt(rewoundIndex);
if (prevIndex == mTabs.size() - 1)
break;
if (rewoundTab == mTabs.get(prevIndex + 1))
prevIndex++;
}
// Figure out where to insert the tab. Just add one to prevIndex, as -1 represents the
// beginning of the list, so we'll insert at 0.
int insertIndex = prevIndex + 1;
if (mIndex >= insertIndex)
mIndex++;
mTabs.add(insertIndex, tab);
WebContents webContents = tab.getWebContents();
if (webContents != null)
webContents.setAudioMuted(false);
boolean activeModel = mModelDelegate.getCurrentModel() == this;
if (mIndex == INVALID_TAB_INDEX) {
// set mIndex but don't kick off everything that happens when calling setIndex().
if (activeModel) {
TabModelUtils.setIndex(this, insertIndex);
} else {
mIndex = insertIndex;
}
}
// Re-save the tab list now that it is being kept.
mTabSaver.saveTabListAsynchronously();
for (TabModelObserver obs : mObservers) obs.tabClosureUndone(tab);
}
use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.
the class LocationBarLayout method loadUrlFromOmniboxMatch.
private void loadUrlFromOmniboxMatch(String url, int transition, int matchPosition, int type) {
// loadUrl modifies AutocompleteController's state clearing the native
// AutocompleteResults needed by onSuggestionsSelected. Therefore,
// loadUrl should should be invoked last.
Tab currentTab = getCurrentTab();
String currentPageUrl = getCurrentTabUrl();
WebContents webContents = currentTab != null ? currentTab.getWebContents() : null;
long elapsedTimeSinceModified = mNewOmniboxEditSessionTimestamp > 0 ? (SystemClock.elapsedRealtime() - mNewOmniboxEditSessionTimestamp) : -1;
mAutocomplete.onSuggestionSelected(matchPosition, type, currentPageUrl, mUrlFocusedFromFakebox, elapsedTimeSinceModified, mUrlBar.getAutocompleteLength(), webContents);
loadUrl(url, transition);
}
use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.
the class SingleWebsitePreferences method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
getActivity().setTitle(R.string.prefs_site_settings);
ListView listView = (ListView) getView().findViewById(android.R.id.list);
listView.setDivider(null);
Object extraSite = getArguments().getSerializable(EXTRA_SITE);
Object extraOrigin = getArguments().getSerializable(EXTRA_ORIGIN);
getArguments().setClassLoader(WebContents.class.getClassLoader());
Object webContents = getArguments().get(EXTRA_WEB_CONTENTS);
if (extraSite != null && extraOrigin == null) {
mSite = (Website) extraSite;
displaySitePermissions();
} else if (extraOrigin != null && extraSite == null) {
mSiteAddress = WebsiteAddress.create((String) extraOrigin);
WebsitePermissionsFetcher fetcher;
fetcher = new WebsitePermissionsFetcher(new SingleWebsitePermissionsPopulator((WebContents) webContents));
fetcher.fetchAllPreferences();
} else {
assert false : "Exactly one of EXTRA_SITE or EXTRA_SITE_ADDRESS must be provided.";
}
super.onActivityCreated(savedInstanceState);
}
use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.
the class Tab method unfreezeContents.
/**
* Restores the WebContents from its saved state. This should only be called if the tab is
* frozen with a saved TabState, and NOT if it was frozen for a lazy load.
* @return Whether or not the restoration was successful.
*/
protected boolean unfreezeContents() {
try {
TraceEvent.begin("Tab.unfreezeContents");
assert mFrozenContentsState != null;
assert getContentViewCore() == null;
WebContents webContents = mFrozenContentsState.restoreContentsFromByteBuffer(isHidden());
if (webContents == null) {
// State restore failed, just create a new empty web contents as that is the best
// that can be done at this point. TODO(jcivelli) http://b/5910521 - we should show
// an error page instead of a blank page in that case (and the last loaded URL).
webContents = WebContentsFactory.createWebContents(isIncognito(), isHidden());
mTabUma = new TabUma(TabCreationState.FROZEN_ON_RESTORE_FAILED);
mFailedToRestore = true;
}
mFrozenContentsState = null;
initContentViewCore(webContents);
if (mFailedToRestore) {
String url = TextUtils.isEmpty(mUrl) ? UrlConstants.NTP_URL : mUrl;
loadUrl(new LoadUrlParams(url, PageTransition.GENERATED));
}
return !mFailedToRestore;
} finally {
TraceEvent.end("Tab.unfreezeContents");
}
}
Aggregations