FileDocCategorySizeDatePackage
WebBackForwardList.javaAPI DocAndroid 1.5 API6434Wed May 06 22:41:56 BST 2009android.webkit

WebBackForwardList

public class WebBackForwardList extends Object implements Serializable, Cloneable
This class contains the back/forward list for a WebView. WebView.copyBackForwardList() will return a copy of this class used to inspect the entries in the list.

Fields Summary
private int
mCurrentIndex
private ArrayList
mArray
private boolean
mClearPending
Constructors Summary
WebBackForwardList()
Construct a back/forward list used by clients of WebView.

        mCurrentIndex = -1;
        mArray = new ArrayList<WebHistoryItem>();
    
Methods Summary
synchronized voidaddHistoryItem(WebHistoryItem item)
Add a new history item to the list. This will remove all items after the current item and append the new item to the end of the list. Called from the WebCore thread only. Synchronized because the UI thread may be reading the array or the current index.

param
item A new history item.

        // Update the current position because we are going to add the new item
        // in that slot.
        ++mCurrentIndex;
        // If the current position is not at the end, remove all history items
        // after the current item.
        final int size = mArray.size();
        final int newPos = mCurrentIndex;
        if (newPos != size) {
            for (int i = size - 1; i >= newPos; i--) {
                final WebHistoryItem h = mArray.remove(i);
            }
        }
        // Add the item to the list.
        mArray.add(item);
    
protected synchronized android.webkit.WebBackForwardListclone()
Clone the entire object to be used in the UI thread by clients of WebView. This creates a copy that should never be modified by any of the webkit package classes.

        WebBackForwardList l = new WebBackForwardList();
        if (mClearPending) {
            // If a clear is pending, return a copy with only the current item.
            l.addHistoryItem(getCurrentItem());
            return l;
        }
        l.mCurrentIndex = mCurrentIndex;
        int size = getSize();
        l.mArray = new ArrayList<WebHistoryItem>(size);
        for (int i = 0; i < size; i++) {
            // Add a copy of each WebHistoryItem
            l.mArray.add(mArray.get(i).clone());
        }
        return l;
    
synchronized voidclose(int nativeFrame)
Clear the back/forward list. Called from the WebCore thread.

        // Clear the array first because nativeClose will call addHistoryItem
        // with the current item.
        mArray.clear();
        mCurrentIndex = -1;
        nativeClose(nativeFrame);
        // Reset the clear flag
        mClearPending = false;
    
synchronized booleangetClearPending()
Return the status of the clear flag. This is used on the UI side to determine if the list is valid for checking things like canGoBack.

        return mClearPending;
    
public synchronized intgetCurrentIndex()
Get the index of the current history item. This index can be used to directly index into the array list.

return
The current index from 0...n or -1 if the list is empty.

        return mCurrentIndex;
    
public synchronized WebHistoryItemgetCurrentItem()
Return the current history item. This method returns null if the list is empty.

return
The current history item.

        return getItemAtIndex(mCurrentIndex);
    
public synchronized WebHistoryItemgetItemAtIndex(int index)
Get the history item at the given index. The index range is from 0...n where 0 is the first item and n is the last item.

param
index The index to retrieve.

        if (index < 0 || index >= getSize()) {
            return null;
        }
        return mArray.get(index);
    
public synchronized intgetSize()
Get the total size of the back/forward list.

return
The size of the list.

        return mArray.size();
    
private static native voidnativeClose(int nativeFrame)

private synchronized voidremoveHistoryItem(int index)

        // XXX: This is a special case. Since the callback is only triggered
        // when removing the first item, we can assert that the index is 0.
        // This lets us change the current index without having to query the
        // native BackForwardList.
        if (Config.DEBUG && (index != 0)) {
            throw new AssertionError();
        }
        final WebHistoryItem h = mArray.remove(index);
        // XXX: If we ever add another callback for removing history items at
        // any index, this will no longer be valid.
        mCurrentIndex--;
    
static native synchronized voidrestoreIndex(int nativeFrame, int index)
Restore the history index.

synchronized voidsetClearPending()
Mark the back/forward list as having a pending clear. This is used on the UI side to mark the list as being invalid during the clearHistory method.

        mClearPending = true;
    
synchronized voidsetCurrentIndex(int newIndex)
Set the new history index.

param
newIndex The new history index.

        mCurrentIndex = newIndex;