1 // Copyright (c) 2013-2014 Intel Corporation. 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.
5 package org.xwalk.core;
7 import java.io.Serializable;
9 import org.chromium.content.browser.NavigationHistory;
12 * This class represents a navigation history for a XWalkView instance.
13 * It's not thread-safe and should be only called on UI thread.
15 public final class XWalkNavigationHistory implements Cloneable, Serializable {
16 private NavigationHistory mHistory;
17 private XWalkView mXWalkView;
19 XWalkNavigationHistory(XWalkView view, NavigationHistory history) {
24 XWalkNavigationHistory(XWalkNavigationHistory history) {
25 mXWalkView = history.mXWalkView;
26 mHistory = history.mHistory;
30 * Total size of navigation history for the XWalkView.
31 * @return the size of total navigation items.
34 return mHistory.getEntryCount();
38 * Test whether there is an item at a specific index.
39 * @param index the given index.
40 * @return true if there is an item at the specific index.
42 public boolean hasItemAt(int index) {
43 return index >=0 && index <= size() - 1;
47 * Get a specific item given by index.
48 * @param index the given index.
49 * @return the navigation item for the given index.
51 public XWalkNavigationItem getItemAt(int index) {
52 return new XWalkNavigationItem(mHistory.getEntryAtIndex(index));
56 * Get the current item which XWalkView displays.
57 * @return the current navigation item.
59 public XWalkNavigationItem getCurrentItem() {
60 return getItemAt(getCurrentIndex());
64 * Test whether XWalkView can go back.
65 * @return true if it can go back.
67 public boolean canGoBack() {
68 return mXWalkView.canGoBack();
72 * Test whether XWalkView can go forward.
73 * @return true if it can go forward.
75 public boolean canGoForward() {
76 return mXWalkView.canGoForward();
80 * The direction for web page navigation.
82 public enum Direction {
83 /** The backward direction for web page navigation. */
85 /** The forward direction for web page navigation. */
90 * Navigates to the specified step from the current navigation item.
91 * Do nothing if the offset is out of bound.
92 * @param direction the direction of navigation.
93 * @param steps go back or foward with a given steps.
95 public void navigate(Direction direction, int steps) {
98 mXWalkView.navigateTo(steps);
101 mXWalkView.navigateTo(-steps);
109 * Get the index for current navigation item.
110 * @return current index in the navigation history.
112 public int getCurrentIndex() {
113 return mHistory.getCurrentEntryIndex();
117 * Clear all history owned by this XWalkView.
119 public void clear() {
120 mXWalkView.clearHistory();
123 protected synchronized XWalkNavigationHistory clone() {
124 return new XWalkNavigationHistory(this);