org.chromium.chrome.browser.tabmodel.document.DocumentTabModel.Entry Java Examples

The following examples show how to use org.chromium.chrome.browser.tabmodel.document.DocumentTabModel.Entry. 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: ActivityDelegateImpl.java    From AndroidChromium 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 #3
Source File: ActivityDelegateImpl.java    From 365browser 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 #4
Source File: StorageDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Update tab entries based on metadata.
 * @param metadataBytes Metadata from last time Chrome was alive.
 * @param entryMap Map to fill with {@link DocumentTabModel.Entry}s about Tabs.
 * @param recentlyClosedTabIdList List to fill with IDs of recently closed tabs.
 */
private void updateTabEntriesFromMetadata(byte[] metadataBytes, SparseArray<Entry> entryMap,
        List<Integer> recentlyClosedTabIdList) {
    if (metadataBytes != null) {
        DocumentList list = null;
        try {
            list = MessageNano.mergeFrom(new DocumentList(), metadataBytes);
        } catch (IOException e) {
            Log.e(TAG, "I/O exception", e);
        }
        if (list == null) return;

        for (int i = 0; i < list.entries.length; i++) {
            DocumentEntry savedEntry = list.entries[i];
            int tabId = savedEntry.tabId;

            // If the tab ID isn't in the list, it must have been closed after Chrome died.
            if (entryMap.indexOfKey(tabId) < 0) {
                recentlyClosedTabIdList.add(tabId);
                continue;
            }

            // Restore information about the Tab.
            entryMap.get(tabId).canGoBack = savedEntry.canGoBack;
        }
    }
}
 
Example #5
Source File: StorageDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs the DocumentTabModel's entries by combining the tasks currently listed in Android
 * with information stored out in a metadata file.
 * @param isIncognito               Whether to build an Incognito tab list.
 * @param activityDelegate          Interacts with the Activitymanager.
 * @param entryMap                  Map to fill with {@link DocumentTabModel.Entry}s about Tabs.
 * @param tabIdList                 List to fill with live Tab IDs.
 * @param recentlyClosedTabIdList   List to fill with IDs of recently closed tabs.
 */
public void restoreTabEntries(final boolean isIncognito, ActivityDelegate activityDelegate,
        final SparseArray<Entry> entryMap, List<Integer> tabIdList,
        final List<Integer> recentlyClosedTabIdList) {
    assert entryMap.size() == 0;
    assert tabIdList.isEmpty();
    assert recentlyClosedTabIdList.isEmpty();

    // Run through Android's Overview to see what Chrome tabs are still listed.
    List<Entry> entries = activityDelegate.getTasksFromRecents(isIncognito);
    for (Entry entry : entries) {
        int tabId = entry.tabId;
        if (tabId != Tab.INVALID_TAB_ID) {
            if (!tabIdList.contains(tabId)) tabIdList.add(tabId);
            entryMap.put(tabId, entry);
        }

        // Prevent these tabs from being retargeted until we have had the opportunity to load
        // more information about them.
        entry.canGoBack = true;
    }

    new AsyncTask<Void, Void, byte[]>() {
        @Override
        protected byte[] doInBackground(Void... params) {
            return readMetadataFileBytes(isIncognito);
        }

        @Override
        protected void onPostExecute(byte[] metadataBytes) {
            updateTabEntriesFromMetadata(metadataBytes, entryMap, recentlyClosedTabIdList);
        }
    // Run on serial executor to ensure that this is done before other start-up tasks.
    }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
 
Example #6
Source File: StorageDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Update tab entries based on metadata.
 * @param metadataBytes Metadata from last time Chrome was alive.
 * @param entryMap Map to fill with {@link DocumentTabModel.Entry}s about Tabs.
 * @param recentlyClosedTabIdList List to fill with IDs of recently closed tabs.
 */
private void updateTabEntriesFromMetadata(byte[] metadataBytes, SparseArray<Entry> entryMap,
        List<Integer> recentlyClosedTabIdList) {
    if (metadataBytes != null) {
        DocumentList list = null;
        try {
            list = MessageNano.mergeFrom(new DocumentList(), metadataBytes);
        } catch (IOException e) {
            Log.e(TAG, "I/O exception", e);
        }
        if (list == null) return;

        for (int i = 0; i < list.entries.length; i++) {
            DocumentEntry savedEntry = list.entries[i];
            int tabId = savedEntry.tabId;

            // If the tab ID isn't in the list, it must have been closed after Chrome died.
            if (entryMap.indexOfKey(tabId) < 0) {
                recentlyClosedTabIdList.add(tabId);
                continue;
            }

            // Restore information about the Tab.
            entryMap.get(tabId).canGoBack = savedEntry.canGoBack;
        }
    }
}
 
Example #7
Source File: StorageDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs the DocumentTabModel's entries by combining the tasks currently listed in Android
 * with information stored out in a metadata file.
 * @param isIncognito               Whether to build an Incognito tab list.
 * @param activityDelegate          Interacts with the Activitymanager.
 * @param entryMap                  Map to fill with {@link DocumentTabModel.Entry}s about Tabs.
 * @param tabIdList                 List to fill with live Tab IDs.
 * @param recentlyClosedTabIdList   List to fill with IDs of recently closed tabs.
 */
public void restoreTabEntries(final boolean isIncognito, ActivityDelegate activityDelegate,
        final SparseArray<Entry> entryMap, List<Integer> tabIdList,
        final List<Integer> recentlyClosedTabIdList) {
    assert entryMap.size() == 0;
    assert tabIdList.isEmpty();
    assert recentlyClosedTabIdList.isEmpty();

    // Run through Android's Overview to see what Chrome tabs are still listed.
    List<Entry> entries = activityDelegate.getTasksFromRecents(isIncognito);
    for (Entry entry : entries) {
        int tabId = entry.tabId;
        if (tabId != Tab.INVALID_TAB_ID) {
            if (!tabIdList.contains(tabId)) tabIdList.add(tabId);
            entryMap.put(tabId, entry);
        }

        // Prevent these tabs from being retargeted until we have had the opportunity to load
        // more information about them.
        entry.canGoBack = true;
    }

    new AsyncTask<Void, Void, byte[]>() {
        @Override
        protected byte[] doInBackground(Void... params) {
            return readMetadataFileBytes(isIncognito);
        }

        @Override
        protected void onPostExecute(byte[] metadataBytes) {
            updateTabEntriesFromMetadata(metadataBytes, entryMap, recentlyClosedTabIdList);
        }
    // Run on serial executor to ensure that this is done before other start-up tasks.
    }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
 
Example #8
Source File: StorageDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Update tab entries based on metadata.
 * @param metadataBytes Metadata from last time Chrome was alive.
 * @param entryMap Map to fill with {@link DocumentTabModel.Entry}s about Tabs.
 * @param recentlyClosedTabIdList List to fill with IDs of recently closed tabs.
 */
private void updateTabEntriesFromMetadata(byte[] metadataBytes, SparseArray<Entry> entryMap,
        List<Integer> recentlyClosedTabIdList) {
    if (metadataBytes != null) {
        DocumentList list = null;
        try {
            list = MessageNano.mergeFrom(new DocumentList(), metadataBytes);
        } catch (IOException e) {
            Log.e(TAG, "I/O exception", e);
        }
        if (list == null) return;

        for (int i = 0; i < list.entries.length; i++) {
            DocumentEntry savedEntry = list.entries[i];
            int tabId = savedEntry.tabId;

            // If the tab ID isn't in the list, it must have been closed after Chrome died.
            if (entryMap.indexOfKey(tabId) < 0) {
                recentlyClosedTabIdList.add(tabId);
                continue;
            }

            // Restore information about the Tab.
            entryMap.get(tabId).canGoBack = savedEntry.canGoBack;
        }
    }
}
 
Example #9
Source File: StorageDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs the DocumentTabModel's entries by combining the tasks currently listed in Android
 * with information stored out in a metadata file.
 * @param isIncognito               Whether to build an Incognito tab list.
 * @param activityDelegate          Interacts with the Activitymanager.
 * @param entryMap                  Map to fill with {@link DocumentTabModel.Entry}s about Tabs.
 * @param tabIdList                 List to fill with live Tab IDs.
 * @param recentlyClosedTabIdList   List to fill with IDs of recently closed tabs.
 */
public void restoreTabEntries(final boolean isIncognito, ActivityDelegate activityDelegate,
        final SparseArray<Entry> entryMap, List<Integer> tabIdList,
        final List<Integer> recentlyClosedTabIdList) {
    assert entryMap.size() == 0;
    assert tabIdList.isEmpty();
    assert recentlyClosedTabIdList.isEmpty();

    // Run through Android's Overview to see what Chrome tabs are still listed.
    List<Entry> entries = activityDelegate.getTasksFromRecents(isIncognito);
    for (Entry entry : entries) {
        int tabId = entry.tabId;
        if (tabId != Tab.INVALID_TAB_ID) {
            if (!tabIdList.contains(tabId)) tabIdList.add(tabId);
            entryMap.put(tabId, entry);
        }

        // Prevent these tabs from being retargeted until we have had the opportunity to load
        // more information about them.
        entry.canGoBack = true;
    }

    new AsyncTask<Void, Void, byte[]>() {
        @Override
        protected byte[] doInBackground(Void... params) {
            return readMetadataFileBytes(isIncognito);
        }

        @Override
        protected void onPostExecute(byte[] metadataBytes) {
            updateTabEntriesFromMetadata(metadataBytes, entryMap, recentlyClosedTabIdList);
        }
    // Run on serial executor to ensure that this is done before other start-up tasks.
    }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
 
Example #10
Source File: ActivityDelegate.java    From delion with Apache License 2.0 2 votes vote down vote up
/**
 * Get a map of the Chrome tasks displayed by Android's Recents.
 * @param isIncognito Whether or not the TabList is managing incognito tabs.
 */
public abstract List<Entry> getTasksFromRecents(boolean isIncognito);
 
Example #11
Source File: ActivityDelegate.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * Get a map of the Chrome tasks displayed by Android's Recents.
 * @param isIncognito Whether or not the TabList is managing incognito tabs.
 */
public abstract List<Entry> getTasksFromRecents(boolean isIncognito);
 
Example #12
Source File: ActivityDelegate.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Get a map of the Chrome tasks displayed by Android's Recents.
 * @param isIncognito Whether or not the TabList is managing incognito tabs.
 */
public abstract List<Entry> getTasksFromRecents(boolean isIncognito);