| 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | package org.chromium.content.browser; |
| 6 | |
| 7 | import java.util.ArrayList; |
| 8 | |
| 9 | /** |
| 10 | * {@link NavigationHistory} captures a snapshot of the navigation history of a |
| 11 | * {@link ContentView}. It is a copy and will not be updated as navigation |
| 12 | * occurs on the source {@link ContentView}. |
| 13 | */ |
| 14 | public class NavigationHistory { |
| 15 | |
| 16 | private ArrayList<NavigationEntry> entries = new ArrayList<NavigationEntry>(); |
| 17 | private int mCurrentEntryIndex; |
| 18 | |
| 19 | protected void addEntry(NavigationEntry entry) { |
| 20 | entries.add(entry); |
| 21 | } |
| 22 | |
| 23 | /* package */ void setCurrentEntryIndex(int currentEntryIndex) { |
| 24 | mCurrentEntryIndex = currentEntryIndex; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @return The number of entries in the history. |
| 29 | */ |
| 30 | public int getEntryCount() { |
| 31 | return entries.size(); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Returns the {@link NavigationEntry} for the given index. |
| 36 | */ |
| 37 | public NavigationEntry getEntryAtIndex(int index) { |
| 38 | return entries.get(index); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns the index of the entry the {@link ContentView} was navigated to |
| 43 | * when the history was fetched. |
| 44 | */ |
| 45 | public int getCurrentEntryIndex() { |
| 46 | return mCurrentEntryIndex; |
| 47 | } |
| 48 | |
| 49 | } |