Search in sources :

Example 56 with Tab

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

the class TabPersistentStore method restoreTab.

private void restoreTab(TabRestoreDetails tabToRestore, TabState tabState, boolean setAsActive) {
    // If we don't have enough information about the Tab, bail out.
    boolean isIncognito = isIncognitoTabBeingRestored(tabToRestore, tabState);
    if (tabState == null) {
        if (tabToRestore.isIncognito == null) {
            Log.w(TAG, "Failed to restore tab: not enough info about its type was available.");
            return;
        } else if (isIncognito) {
            Log.i(TAG, "Failed to restore Incognito tab: its TabState could not be restored.");
            return;
        }
    }
    TabModel model = mTabModelSelector.getModel(isIncognito);
    SparseIntArray restoredTabs = isIncognito ? mIncognitoTabsRestored : mNormalTabsRestored;
    int restoredIndex = 0;
    if (tabToRestore.fromMerge) {
        // Put any tabs being merged into this list at the end.
        restoredIndex = mTabModelSelector.getModel(isIncognito).getCount();
    } else if (restoredTabs.size() > 0 && tabToRestore.originalIndex > restoredTabs.keyAt(restoredTabs.size() - 1)) {
        // If the tab's index is too large, restore it at the end of the list.
        restoredIndex = restoredTabs.size();
    } else {
        // Otherwise try to find the tab we should restore before, if any.
        for (int i = 0; i < restoredTabs.size(); i++) {
            if (restoredTabs.keyAt(i) > tabToRestore.originalIndex) {
                Tab nextTabByIndex = TabModelUtils.getTabById(model, restoredTabs.valueAt(i));
                restoredIndex = nextTabByIndex != null ? model.indexOf(nextTabByIndex) : -1;
                break;
            }
        }
    }
    int tabId = tabToRestore.id;
    if (tabState != null) {
        mTabCreatorManager.getTabCreator(isIncognito).createFrozenTab(tabState, tabToRestore.id, restoredIndex);
    } else {
        Log.w(TAG, "Failed to restore TabState; creating Tab with last known URL.");
        Tab fallbackTab = mTabCreatorManager.getTabCreator(isIncognito).createNewTab(new LoadUrlParams(tabToRestore.url), TabModel.TabLaunchType.FROM_RESTORE, null);
        tabId = fallbackTab.getId();
        model.moveTab(tabId, restoredIndex);
    }
    // was selected in the other model before the merge should be selected after the merge.
    if (setAsActive || (tabToRestore.fromMerge && restoredIndex == 0)) {
        boolean wasIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();
        int selectedModelTabCount = mTabModelSelector.getCurrentModel().getCount();
        TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, tabId));
        boolean isIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();
        // view on tablets).
        if (tabToRestore.fromMerge && wasIncognitoTabModelSelected != isIncognitoTabModelSelected && selectedModelTabCount != 0) {
            mTabModelSelector.selectModel(wasIncognitoTabModelSelected);
        }
    }
    restoredTabs.put(tabToRestore.originalIndex, tabId);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) SparseIntArray(android.util.SparseIntArray) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Example 57 with Tab

use of org.chromium.chrome.browser.tab.Tab 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;
}
Also used : DocumentActivity(org.chromium.chrome.browser.document.DocumentActivity) Tab(org.chromium.chrome.browser.tab.Tab) WeakReference(java.lang.ref.WeakReference) DocumentActivity(org.chromium.chrome.browser.document.DocumentActivity) Activity(android.app.Activity)

Example 58 with Tab

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

the class CustomTabToolbar method onLongClick.

@Override
public boolean onLongClick(View v) {
    if (v == mCloseButton) {
        return showAccessibilityToast(v, getResources().getString(R.string.close_tab));
    } else if (v == mCustomActionButton) {
        return showAccessibilityToast(v, mCustomActionButton.getContentDescription());
    } else if (v == mTitleUrlContainer) {
        ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        Tab tab = getCurrentTab();
        if (tab == null)
            return false;
        String url = tab.getOriginalUrl();
        ClipData clip = ClipData.newPlainText("url", url);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getContext(), R.string.url_copied, Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
Also used : ClipboardManager(android.content.ClipboardManager) Tab(org.chromium.chrome.browser.tab.Tab) ClipData(android.content.ClipData)

Example 59 with Tab

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

the class ToolbarManager method destroy.

/**
     * Call to tear down all of the toolbar dependencies.
     */
public void destroy() {
    Tab currentTab = mToolbarModel.getTab();
    if (currentTab != null)
        currentTab.removeObserver(mTabObserver);
    mFindToolbarObservers.clear();
    mToolbar.destroy();
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 60 with Tab

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

the class ToolbarManager method updateLoadProgress.

private void updateLoadProgress(int progress) {
    // If it's a native page, progress bar is already hidden or being hidden, so don't update
    // the value.
    // TODO(kkimlabs): Investigate back/forward navigation with native page & web content and
    //                 figure out the correct progress bar presentation.
    Tab tab = mToolbarModel.getTab();
    if (NativePageFactory.isNativePageUrl(tab.getUrl(), tab.isIncognito()))
        return;
    progress = Math.max(progress, MINIMUM_LOAD_PROGRESS);
    mToolbar.setLoadProgress(progress / 100f);
    if (progress == 100)
        finishLoadProgress(true);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

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