use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.
the class UmaSessionStats method recordPageLoadStats.
private void recordPageLoadStats(Tab tab) {
WebContents webContents = tab.getWebContents();
boolean isDesktopUserAgent = webContents != null && webContents.getNavigationController().getUseDesktopUserAgent();
nativeRecordPageLoaded(isDesktopUserAgent);
if (mKeyboardConnected) {
nativeRecordPageLoadedWithKeyboard();
}
// possible since the TabSelector is needed to figure out the current number of open tabs.
if (mTabModelSelector == null)
return;
TabModel regularModel = mTabModelSelector.getModel(false);
nativeRecordTabCountPerLoad(getTabCountFromModel(regularModel));
}
use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.
the class OfflinePageUtils method saveBookmarkOffline.
/*
* Save an offline copy for the bookmarked page asynchronously.
*
* @param bookmarkId The ID of the page to save an offline copy.
* @param tab A {@link Tab} object.
* @param callback The callback to be invoked when the offline copy is saved.
*/
public static void saveBookmarkOffline(BookmarkId bookmarkId, Tab tab) {
// If bookmark ID is missing there is nothing to save here.
if (bookmarkId == null)
return;
// Making sure the feature is enabled.
if (!OfflinePageBridge.isOfflineBookmarksEnabled())
return;
// Making sure tab is worth keeping.
if (shouldSkipSavingTabOffline(tab))
return;
OfflinePageBridge offlinePageBridge = getInstance().getOfflinePageBridge(tab.getProfile());
if (offlinePageBridge == null)
return;
WebContents webContents = tab.getWebContents();
ClientId clientId = ClientId.createClientIdForBookmarkId(bookmarkId);
// TODO(fgorski): Ensure that request is queued if the model is not loaded.
offlinePageBridge.savePage(webContents, clientId, new OfflinePageBridge.SavePageCallback() {
@Override
public void onSavePageDone(int savePageResult, String url, long offlineId) {
// TODO(fgorski): Decide if we need to do anything with result.
// Perhaps some UMA reporting, but that can really happen someplace else.
}
});
}
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 WarmupManager method takeSpareWebContents.
/**
* Returns a spare WebContents or null, depending on the availability of one.
*
* The parameters are the same as for {@link WebContentsFactory#createWebContents()}.
*
* @return a WebContents, or null.
*/
public WebContents takeSpareWebContents(boolean incognito, boolean initiallyHidden) {
ThreadUtils.assertOnUiThread();
if (incognito || initiallyHidden)
return null;
WebContents result = mSpareWebContents;
mSpareWebContents = null;
return result;
}
use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.
the class CustomTabActivity method createMainTab.
private Tab createMainTab() {
CustomTabsConnection customTabsConnection = CustomTabsConnection.getInstance(getApplication());
String url = getUrlToLoad();
// Get any referrer that has been explicitly set by the app.
String referrerUrl = IntentHandler.getReferrerUrlIncludingExtraHeaders(getIntent(), this);
if (referrerUrl == null) {
Referrer referrer = customTabsConnection.getReferrerForSession(mSession);
if (referrer != null)
referrerUrl = referrer.getUrl();
}
Tab tab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID), Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_EXTERNAL_APP, null, null);
tab.setAppAssociatedWith(customTabsConnection.getClientPackageNameForSession(mSession));
mPrerenderedUrl = customTabsConnection.getPrerenderedUrl(mSession);
int webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS;
WebContents webContents = customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl);
mHasPrerendered = webContents != null;
if (mHasPrerendered)
webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS;
if (!mHasPrerendered) {
webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
if (webContents != null)
webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS;
}
RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebcontentsStateOnLaunch", webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX);
if (webContents == null)
webContents = WebContentsFactory.createWebContents(false, false);
if (!mHasPrerendered) {
customTabsConnection.resetPostMessageHandlerForSession(mSession, webContents);
}
tab.initialize(webContents, getTabContentManager(), new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding(), mIntentDataProvider.isOpenedByChrome(), getFullscreenManager().getBrowserVisibilityDelegate()), false, false);
initializeMainTab(tab);
return tab;
}
Aggregations