Java Code Examples for org.chromium.chrome.browser.tab.Tab#INVALID_TAB_ID

The following examples show how to use org.chromium.chrome.browser.tab.Tab#INVALID_TAB_ID . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivityDelegateImpl.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public List<Entry> getTasksFromRecents(boolean isIncognito) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    List<Entry> entries = new ArrayList<Entry>();
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (!isValidActivity(isIncognito, intent)) continue;

        int tabId = getTabIdFromIntent(intent);
        if (tabId == Tab.INVALID_TAB_ID) continue;

        String initialUrl = getInitialUrlForDocument(intent);
        entries.add(new Entry(tabId, initialUrl));
    }
    return entries;
}
 
Example 2
Source File: WebappLauncherActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: ActivityDelegate.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Check whether or not the Intent contains an ID for document mode.
 * @param intent Intent to check.
 * @return ID for the document that has the given intent as base intent, or
 *         {@link Tab.INVALID_TAB_ID} if it couldn't be retrieved.
 */
public static int getTabIdFromIntent(Intent intent) {
    if (intent == null || intent.getData() == null) return Tab.INVALID_TAB_ID;

    // Avoid AsyncTabCreationParams related flows early returning here.
    if (AsyncTabParamsManager.hasParamsWithTabToReparent()) {
        return IntentUtils.safeGetIntExtra(
                intent, IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
    }

    Uri data = intent.getData();
    if (!TextUtils.equals(data.getScheme(), UrlConstants.DOCUMENT_SCHEME)) {
        return Tab.INVALID_TAB_ID;
    }

    try {
        return Integer.parseInt(data.getHost());
    } catch (NumberFormatException e) {
        return Tab.INVALID_TAB_ID;
    }
}
 
Example 4
Source File: Layout.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * To be called when the transition out of the view mode is done.
 * This is currently called by the renderer when all the animation are done while hiding.
 */
public void doneHiding() {
    mIsHiding = false;
    if (mNextTabId != Tab.INVALID_TAB_ID) {
        TabModel model = mTabModelSelector.getModelForTabId(mNextTabId);
        if (model != null) {
            TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, mNextTabId));
        }
        mNextTabId = Tab.INVALID_TAB_ID;
    }
    mUpdateHost.doneHiding();
}
 
Example 5
Source File: StackLayout.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onTabSelecting(long time, int tabId) {
    commitOutstandingModelState(time);
    if (tabId == Tab.INVALID_TAB_ID) tabId = mTabModelSelector.getCurrentTabId();
    super.onTabSelecting(time, tabId);
    mStacks[getTabStackIndex()].tabSelectingEffect(time, tabId);
    startMarginAnimation(false);
    startYOffsetAnimation(false);
    finishScrollStacks();
}
 
Example 6
Source File: TabPersistentStore.java    From delion with Apache License 2.0 5 votes vote down vote up
private void startPrefetchActiveTabTask() {
    final int activeTabId = mPreferences.getInt(PREF_ACTIVE_TAB_ID, Tab.INVALID_TAB_ID);
    if (activeTabId == Tab.INVALID_TAB_ID) return;
    mPrefetchActiveTabTask = new AsyncTask<Void, Void, TabState>() {
        @Override
        protected TabState doInBackground(Void... params) {
            return TabState.restoreTabState(getStateDirectory(), activeTabId);
        }
    }.executeOnExecutor(getPrefetchExecutor());
}
 
Example 7
Source File: TabPersistentStore.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes {@code selector} to a byte array, copying out the data pertaining to tab ordering
 * and selected indices.
 * @param selector          The {@link TabModelSelector} to serialize.
 * @param tabsBeingRestored Tabs that are in the process of being restored.
 * @return                  {@code byte[]} containing the serialized state of {@code selector}.
 */
@VisibleForTesting
public static byte[] serializeTabModelSelector(TabModelSelector selector,
        List<TabRestoreDetails> tabsBeingRestored) throws IOException {
    ThreadUtils.assertOnUiThread();

    TabModel incognitoModel = selector.getModel(true);
    TabModelMetadata incognitoInfo = new TabModelMetadata(incognitoModel.index());
    for (int i = 0; i < incognitoModel.getCount(); i++) {
        incognitoInfo.ids.add(incognitoModel.getTabAt(i).getId());
        incognitoInfo.urls.add(incognitoModel.getTabAt(i).getUrl());
    }

    TabModel normalModel = selector.getModel(false);
    TabModelMetadata normalInfo = new TabModelMetadata(normalModel.index());
    for (int i = 0; i < normalModel.getCount(); i++) {
        normalInfo.ids.add(normalModel.getTabAt(i).getId());
        normalInfo.urls.add(normalModel.getTabAt(i).getUrl());
    }

    // Cache the active tab id to be pre-loaded next launch.
    int activeTabId = Tab.INVALID_TAB_ID;
    int activeIndex = normalModel.index();
    if (activeIndex != TabList.INVALID_TAB_INDEX) {
        activeTabId = normalModel.getTabAt(activeIndex).getId();
    }
    // Always override the existing value in case there is no active tab.
    ContextUtils.getAppSharedPreferences().edit().putInt(
            PREF_ACTIVE_TAB_ID, activeTabId).apply();

    return serializeMetadata(normalInfo, incognitoInfo, tabsBeingRestored);
}
 
Example 8
Source File: SearchActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void finishNativeInitialization() {
    super.finishNativeInitialization();

    mTab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID),
            Tab.INVALID_TAB_ID, false, this, getWindowAndroid(),
            TabLaunchType.FROM_EXTERNAL_APP, null, null);
    mTab.initialize(WebContentsFactory.createWebContents(false, false), null,
            new TabDelegateFactory(), false, false);
    mTab.loadUrl(new LoadUrlParams("about:blank"));

    mSearchBoxDataProvider.onNativeLibraryReady(mTab);
    mSearchBox.onNativeLibraryReady();

    // Force the user to choose a search engine if they have to.
    final Callback<Boolean> deferredCallback = new Callback<Boolean>() {
        @Override
        public void onResult(Boolean result) {
            if (result == null || !result.booleanValue()) {
                Log.e(TAG, "User failed to select a default search engine.");
                finish();
                return;
            }

            finishDeferredInitialization();
        }
    };
    if (!getActivityDelegate().showSearchEngineDialogIfNeeded(this, deferredCallback)) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                finishDeferredInitialization();
            }
        });
    }
}
 
Example 9
Source File: Layout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * To be called when the transition out of the view mode is done.
 * This is currently called by the renderer when all the animation are done while hiding.
 */
public void doneHiding() {
    mIsHiding = false;
    if (mNextTabId != Tab.INVALID_TAB_ID) {
        TabModel model = mTabModelSelector.getModelForTabId(mNextTabId);
        if (model != null) {
            TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, mNextTabId));
        }
        mNextTabId = Tab.INVALID_TAB_ID;
    }
    mUpdateHost.doneHiding();
    if (mRenderHost != null && mRenderHost.getResourceManager() != null) {
        mRenderHost.getResourceManager().clearTintedResourceCache();
    }
}
 
Example 10
Source File: TabPersistentStore.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes {@code selector} to a byte array, copying out the data pertaining to tab ordering
 * and selected indices.
 * @param selector          The {@link TabModelSelector} to serialize.
 * @param tabsBeingRestored Tabs that are in the process of being restored.
 * @return                  {@code byte[]} containing the serialized state of {@code selector}.
 */
@VisibleForTesting
public static byte[] serializeTabModelSelector(TabModelSelector selector,
        List<TabRestoreDetails> tabsBeingRestored) throws IOException {
    ThreadUtils.assertOnUiThread();

    TabModel incognitoModel = selector.getModel(true);
    TabModelMetadata incognitoInfo = new TabModelMetadata(incognitoModel.index());
    for (int i = 0; i < incognitoModel.getCount(); i++) {
        incognitoInfo.ids.add(incognitoModel.getTabAt(i).getId());
        incognitoInfo.urls.add(incognitoModel.getTabAt(i).getUrl());
    }

    TabModel normalModel = selector.getModel(false);
    TabModelMetadata normalInfo = new TabModelMetadata(normalModel.index());
    for (int i = 0; i < normalModel.getCount(); i++) {
        normalInfo.ids.add(normalModel.getTabAt(i).getId());
        normalInfo.urls.add(normalModel.getTabAt(i).getUrl());
    }

    // Cache the active tab id to be pre-loaded next launch.
    int activeTabId = Tab.INVALID_TAB_ID;
    int activeIndex = normalModel.index();
    if (activeIndex != TabList.INVALID_TAB_INDEX) {
        activeTabId = normalModel.getTabAt(activeIndex).getId();
    }
    // Always override the existing value in case there is no active tab.
    ContextUtils.getAppSharedPreferences().edit().putInt(
            PREF_ACTIVE_TAB_ID, activeTabId).apply();

    return serializeMetadata(normalInfo, incognitoInfo, tabsBeingRestored);
}
 
Example 11
Source File: StackLayout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onTabSelecting(long time, int tabId) {
    commitOutstandingModelState(time);
    if (tabId == Tab.INVALID_TAB_ID) tabId = mTabModelSelector.getCurrentTabId();
    super.onTabSelecting(time, tabId);
    mStacks[getTabStackIndex()].tabSelectingEffect(time, tabId);
    startMarginAnimation(false);
    startYOffsetAnimation(false);
    finishScrollStacks();
}
 
Example 12
Source File: StackLayout.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onTabSelecting(long time, int tabId) {
    commitOutstandingModelState(time);
    if (tabId == Tab.INVALID_TAB_ID) tabId = mTabModelSelector.getCurrentTabId();
    super.onTabSelecting(time, tabId);
    mStacks[getTabStackIndex()].tabSelectingEffect(time, tabId);
    startMarginAnimation(false);
    startYOffsetAnimation(false);
    finishScrollStacks();
}
 
Example 13
Source File: StackLayout.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Get the tab stack state for the specified tab id.
 *
 * @param tabId The id of the tab to lookup.
 * @return The tab stack index for the given tab id.
 * @VisibleForTesting
 */
protected int getTabStackIndex(int tabId) {
    if (tabId == Tab.INVALID_TAB_ID) {
        boolean incognito = mTemporarySelectedStack != null
                ? mTemporarySelectedStack
                : mTabModelSelector.isIncognitoSelected();
        return incognito ? 1 : 0;
    } else {
        return TabModelUtils.getTabById(mTabModelSelector.getModel(true), tabId) != null ? 1
                                                                                         : 0;
    }
}
 
Example 14
Source File: StackLayout.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Get the tab stack state for the specified tab id.
 *
 * @param tabId The id of the tab to lookup.
 * @return The tab stack index for the given tab id.
 * @VisibleForTesting
 */
protected int getTabStackIndex(int tabId) {
    if (tabId == Tab.INVALID_TAB_ID) {
        boolean incognito = mTemporarySelectedStack != null
                ? mTemporarySelectedStack
                : mTabModelSelector.isIncognitoSelected();
        return incognito ? 1 : 0;
    } else {
        return TabModelUtils.getTabById(mTabModelSelector.getModel(true), tabId) != null ? 1
                                                                                         : 0;
    }
}
 
Example 15
Source File: ReaderModeManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
public ReaderModeManager(TabModelSelector selector, ChromeActivity activity) {
    super(selector);
    mTabId = Tab.INVALID_TAB_ID;
    mTabModelSelector = selector;
    mChromeActivity = activity;
    mTabStatusMap = new HashMap<>();
    mIsReaderHeuristicAlwaysTrue = isDistillerHeuristicAlwaysTrue();
}
 
Example 16
Source File: TabModelSelectorBase.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public int getCurrentTabId() {
    Tab tab = getCurrentTab();
    return tab != null ? tab.getId() : Tab.INVALID_TAB_ID;
}
 
Example 17
Source File: ReaderModeManager.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * 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);

                    // It is possible that the tab was destroyed before this callback happens.
                    // TODO(wychen/mdjones): Remove the callback when a Tab/WebContents is
                    // 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);
}
 
Example 18
Source File: BottomSheet.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public int getParentId() {
    return Tab.INVALID_TAB_ID;
}
 
Example 19
Source File: CustomTabActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 20
Source File: LayoutManagerChrome.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void tabClosed(int tabId, boolean incognito, boolean tabRemoved) {
    Tab currentTab =
            getTabModelSelector() != null ? getTabModelSelector().getCurrentTab() : null;
    int nextTabId = currentTab != null ? currentTab.getId() : Tab.INVALID_TAB_ID;
    tabClosed(tabId, nextTabId, incognito, tabRemoved);
}