Search in sources :

Example 41 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ReaderModeManager method setDistillabilityCallback.

/**
     * Set the callback for updating reader mode status based on whether or not the page should
     * be viewed in reader mode.
     * @param tabId The ID of the tab having its callback set.
     */
private void setDistillabilityCallback(final int tabId) {
    if (tabId == Tab.INVALID_TAB_ID || mTabStatusMap.get(tabId).isCallbackSet()) {
        return;
    }
    if (mTabModelSelector == null)
        return;
    Tab currentTab = mTabModelSelector.getTabById(tabId);
    if (currentTab == null || currentTab.getWebContents() == null || currentTab.getContentViewCore() == null) {
        return;
    }
    DistillablePageUtils.setDelegate(currentTab.getWebContents(), new DistillablePageUtils.PageDistillableDelegate() {

        @Override
        public void onIsPageDistillableResult(boolean isDistillable, boolean isLast) {
            if (mTabModelSelector == null)
                return;
            ReaderModeTabInfo tabInfo = mTabStatusMap.get(tabId);
            Tab readerTab = mTabModelSelector.getTabById(tabId);
            // destroyed so that this never happens.
            if (readerTab == null || tabInfo == null)
                return;
            // Make sure the page didn't navigate while waiting for a response.
            if (!readerTab.getUrl().equals(tabInfo.getUrl()))
                return;
            if (isDistillable) {
                tabInfo.setStatus(POSSIBLE);
                // The user may have changed tabs.
                if (tabId == mTabModelSelector.getCurrentTabId()) {
                    // TODO(mdjones): Add reason DISTILLER_STATE_CHANGE.
                    requestReaderPanelShow(StateChangeReason.UNKNOWN);
                }
            } else {
                tabInfo.setStatus(NOT_POSSIBLE);
            }
            if (!mIsUmaRecorded && (tabInfo.getStatus() == POSSIBLE || isLast)) {
                mIsUmaRecorded = true;
                RecordHistogram.recordBooleanHistogram("DomDistiller.PageDistillable", tabInfo.getStatus() == POSSIBLE);
            }
        }
    });
    mTabStatusMap.get(tabId).setIsCallbackSet(true);
}
Also used : DistillablePageUtils(org.chromium.components.dom_distiller.content.DistillablePageUtils) Tab(org.chromium.chrome.browser.tab.Tab)

Example 42 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ContextReporter method reportUsageOfCurrentContextIfPossible.

private void reportUsageOfCurrentContextIfPossible(Tab tab, boolean isTitleChange, @Nullable GSAContextDisplaySelection displaySelection) {
    Tab currentTab = mActivity.getActivityTab();
    if (currentTab == null || currentTab.isIncognito()) {
        if (currentTab == null) {
            reportStatus(STATUS_NO_TAB);
            Log.d(TAG, "Not reporting, tab is null");
        } else {
            reportStatus(STATUS_INCOGNITO);
            Log.d(TAG, "Not reporting, tab is incognito");
        }
        reportUsageEndedIfNecessary();
        return;
    }
    String currentUrl = currentTab.getUrl();
    if (TextUtils.isEmpty(currentUrl) || !(currentUrl.startsWith(UrlConstants.HTTP_SCHEME) || currentUrl.startsWith(UrlConstants.HTTPS_SCHEME))) {
        reportStatus(STATUS_INVALID_SCHEME);
        Log.d(TAG, "Not reporting, URL scheme is invalid");
        reportUsageEndedIfNecessary();
        return;
    }
    // Check whether this is a context change we would like to report.
    if (currentTab.getId() != tab.getId()) {
        reportStatus(STATUS_TAB_ID_MISMATCH);
        Log.d(TAG, "Not reporting, tab ID doesn't match");
        return;
    }
    if (isTitleChange && mLastContextWasTitleChange) {
        reportStatus(STATUS_DUP_TITLE_CHANGE);
        Log.d(TAG, "Not reporting, repeated title update");
        return;
    }
    reportUsageEndedIfNecessary();
    mDelegate.reportContext(currentTab.getUrl(), currentTab.getTitle(), displaySelection);
    mLastContextWasTitleChange = isTitleChange;
    mContextInUse.set(true);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 43 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ContextReporter method reportDisplaySelection.

/**
     * Reports that the given display selection has been established for the current tab.
     * @param displaySelection The information about the selection being displayed.
     */
private void reportDisplaySelection(@Nullable GSAContextDisplaySelection displaySelection) {
    Tab currentTab = mActivity.getActivityTab();
    reportUsageOfCurrentContextIfPossible(currentTab, false, displaySelection);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 44 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ChromeTabCreator method createFrozenTab.

@Override
public Tab createFrozenTab(TabState state, int id, int index) {
    Tab tab = Tab.createFrozenTabFromState(id, mActivity, state.isIncognito(), mNativeWindow, state.parentId, state);
    boolean selectTab = mOrderController.willOpenInForeground(TabLaunchType.FROM_RESTORE, state.isIncognito());
    tab.initialize(null, mTabContentManager, createDefaultTabDelegateFactory(), !selectTab, false);
    assert state.isIncognito() == mIncognito;
    mTabModel.addTab(tab, index, TabLaunchType.FROM_RESTORE);
    return tab;
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 45 with Tab

use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.

the class ChromeTabCreator method launchUrlFromExternalApp.

/**
     * Opens the specified URL into a tab, potentially reusing a tab. Typically if a user opens
     * several link from the same application, we reuse the same tab so as to not open too many
     * tabs.
     * @param url the URL to open
     * @param referer The referer url if provided, null otherwise.
     * @param headers HTTP headers to send alongside the URL.
     * @param appId the ID of the application that triggered that URL navigation.
     * @param forceNewTab whether the URL should be opened in a new tab. If false, an existing tab
     *                    already opened by the same app will be reused.
     * @param intent the source of url if it isn't null.
     * @param intentTimestamp the time the intent was received.
     * @return the tab the URL was opened in, could be a new tab or a reused one.
     */
public Tab launchUrlFromExternalApp(String url, String referer, String headers, String appId, boolean forceNewTab, Intent intent, long intentTimestamp) {
    assert !mIncognito;
    boolean isLaunchedFromChrome = TextUtils.equals(appId, mActivity.getPackageName());
    // pages when he or she could be served a Data Reduction Proxy preview page.
    if (url != null)
        url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(url);
    if (forceNewTab && !isLaunchedFromChrome) {
        // We don't associate the tab with that app ID, as it is assumed that if the
        // application wanted to open this tab as a new tab, it probably does not want it
        // reused either.
        LoadUrlParams loadUrlParams = new LoadUrlParams(url);
        loadUrlParams.setIntentReceivedTimestamp(intentTimestamp);
        loadUrlParams.setVerbatimHeaders(headers);
        if (referer != null) {
            loadUrlParams.setReferrer(new Referrer(referer, Referrer.REFERRER_POLICY_DEFAULT));
        }
        return createNewTab(loadUrlParams, TabLaunchType.FROM_EXTERNAL_APP, null, intent);
    }
    if (appId == null) {
        // If we have no application ID, we use a made-up one so that these tabs can be
        // reused.
        appId = TabModelImpl.UNKNOWN_APP_ID;
    }
    // Let's try to find an existing tab that was started by that app.
    for (int i = 0; i < mTabModel.getCount(); i++) {
        Tab tab = mTabModel.getTabAt(i);
        if (appId.equals(tab.getAppAssociatedWith())) {
            // We don't reuse the tab, we create a new one at the same index instead.
            // Reusing a tab would require clearing the navigation history and clearing the
            // contents (we would not want the previous content to show).
            LoadUrlParams loadUrlParams = new LoadUrlParams(url);
            loadUrlParams.setIntentReceivedTimestamp(intentTimestamp);
            Tab newTab = createNewTab(loadUrlParams, TabLaunchType.FROM_EXTERNAL_APP, null, i, intent);
            newTab.setAppAssociatedWith(appId);
            mTabModel.closeTab(tab, false, false, false);
            return newTab;
        }
    }
    // No tab for that app, we'll have to create a new one.
    Tab tab = launchUrl(url, TabLaunchType.FROM_EXTERNAL_APP, intent, intentTimestamp);
    tab.setAppAssociatedWith(appId);
    return tab;
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) Referrer(org.chromium.content_public.common.Referrer) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Aggregations

Tab (org.chromium.chrome.browser.tab.Tab)116 LayoutTab (org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)13 TabModel (org.chromium.chrome.browser.tabmodel.TabModel)10 LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)9 SuppressLint (android.annotation.SuppressLint)8 TabModelSelectorTabObserver (org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver)8 Intent (android.content.Intent)5 FrameLayout (android.widget.FrameLayout)4 ContentViewCore (org.chromium.content.browser.ContentViewCore)4 WebContents (org.chromium.content_public.browser.WebContents)4 Activity (android.app.Activity)3 Bitmap (android.graphics.Bitmap)3 TabLaunchType (org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType)3 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 Bundle (android.os.Bundle)2 StrictMode (android.os.StrictMode)2 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2