Search in sources :

Example 31 with Tab

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

the class StripLayoutHelper method bringSelectedTabToVisibleArea.

/**
     * Scrolls to the selected tab if it's not fully visible.
     */
private void bringSelectedTabToVisibleArea(long time, boolean animate) {
    // The selected tab is always visible in the CascadingStripStacker.
    if (mShouldCascadeTabs)
        return;
    Tab selectedTab = mModel.getTabAt(mModel.index());
    if (selectedTab == null)
        return;
    StripLayoutTab selectedLayoutTab = findTabById(selectedTab.getId());
    if (isSelectedTabCompletelyVisible(selectedLayoutTab))
        return;
    float delta = calculateOffsetToMakeTabVisible(selectedLayoutTab, true, true, true);
    setScrollForScrollingTabStacker(delta, animate, time);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 32 with Tab

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

the class IncognitoToggleButtonTablet method setTabModelSelector.

/**
     * Sets the {@link TabModelSelector} that will be queried for information about the state of
     * the system.
     * @param selector A {@link TabModelSelector} that represents the state of the system.
     */
public void setTabModelSelector(TabModelSelector selector) {
    mTabModelSelector = selector;
    if (selector != null) {
        updateButtonResource();
        updateButtonVisibility();
        mTabModelSelectorObserver = new EmptyTabModelSelectorObserver() {

            @Override
            public void onTabModelSelected(TabModel newModel, TabModel oldModel) {
                updateButtonResource();
            }
        };
        mTabModelSelector.addObserver(mTabModelSelectorObserver);
        mTabModelObserver = new EmptyTabModelObserver() {

            @Override
            public void didAddTab(Tab tab, TabLaunchType type) {
                updateButtonVisibility();
            }

            @Override
            public void willCloseTab(Tab tab, boolean animate) {
                updateButtonVisibility();
            }

            @Override
            public void tabRemoved(Tab tab) {
                updateButtonVisibility();
            }
        };
        for (TabModel model : mTabModelSelector.getModels()) {
            model.addObserver(mTabModelObserver);
        }
    }
}
Also used : EmptyTabModelSelectorObserver(org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver) Tab(org.chromium.chrome.browser.tab.Tab) TabLaunchType(org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType) TabModel(org.chromium.chrome.browser.tabmodel.TabModel) EmptyTabModelObserver(org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver)

Example 33 with Tab

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

the class WebappLauncherActivity method bringWebappToFront.

/**
     * Brings a live WebappActivity back to the foreground if one exists for the given tab ID.
     * @param tabId ID of the Tab to bring back to the foreground.
     * @return True if a live WebappActivity was found, false otherwise.
     */
public static boolean bringWebappToFront(int tabId) {
    if (tabId == Tab.INVALID_TAB_ID)
        return false;
    for (WeakReference<Activity> activityRef : ApplicationStatus.getRunningActivities()) {
        Activity activity = activityRef.get();
        if (activity == null || !(activity instanceof WebappActivity))
            continue;
        WebappActivity webappActivity = (WebappActivity) activity;
        if (webappActivity.getActivityTab() != null && webappActivity.getActivityTab().getId() == tabId) {
            Tab tab = webappActivity.getActivityTab();
            tab.getTabWebContentsDelegateAndroid().activateContents();
            return true;
        }
    }
    return false;
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) ChromeLauncherActivity(org.chromium.chrome.browser.document.ChromeLauncherActivity) Activity(android.app.Activity)

Example 34 with Tab

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

the class CustomTabActivity method openCurrentUrlInBrowser.

/**
     * Opens the URL currently being displayed in the Custom Tab in the regular browser.
     * @param forceReparenting Whether tab reparenting should be forced for testing.
     *
     * @return Whether or not the tab was sent over successfully.
     */
boolean openCurrentUrlInBrowser(boolean forceReparenting) {
    Tab tab = getActivityTab();
    if (tab == null)
        return false;
    String url = tab.getUrl();
    if (DomDistillerUrlUtils.isDistilledPage(url)) {
        url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
    }
    if (TextUtils.isEmpty(url))
        url = getUrlToLoad();
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false);
    boolean willChromeHandleIntent = getIntentDataProvider().isOpenedByChrome();
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    StrictMode.allowThreadDiskWrites();
    try {
        willChromeHandleIntent |= ExternalNavigationDelegateImpl.willChromeHandleIntent(this, intent, true);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
    Bundle startActivityOptions = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.abc_fade_in, R.anim.abc_fade_out).toBundle();
    if (willChromeHandleIntent || forceReparenting) {
        Runnable finalizeCallback = new Runnable() {

            @Override
            public void run() {
                finishAndClose();
            }
        };
        mMainTab = null;
        tab.detachAndStartReparenting(intent, startActivityOptions, finalizeCallback);
    } else {
        // Temporarily allowing disk access while fixing. TODO: http://crbug.com/581860
        StrictMode.allowThreadDiskReads();
        StrictMode.allowThreadDiskWrites();
        try {
            startActivity(intent, startActivityOptions);
        } finally {
            StrictMode.setThreadPolicy(oldPolicy);
        }
    }
    return true;
}
Also used : StrictMode(android.os.StrictMode) Tab(org.chromium.chrome.browser.tab.Tab) Bundle(android.os.Bundle) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 35 with Tab

use of org.chromium.chrome.browser.tab.Tab 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);
    WebContents webContents = customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl);
    mHasPrerendered = webContents != null;
    if (!mHasPrerendered) {
        webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
    }
    if (webContents == null)
        webContents = WebContentsFactory.createWebContents(false, false);
    tab.initialize(webContents, getTabContentManager(), new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding(), mIntentDataProvider.isOpenedByChrome()), false, false);
    initializeMainTab(tab);
    return tab;
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) Tab(org.chromium.chrome.browser.tab.Tab) Referrer(org.chromium.content_public.common.Referrer)

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