Add a client for WebBackForwardList operations.
Provide a custom data slot in WebHistoryItem to store application data in the history item. A client of WebBackForwardList can insert their custom data into the item when created. In onIndexChanged, the custom data can be read by the client.
This commit is contained in:
@@ -69,6 +69,8 @@ class CallbackProxy extends Handler {
|
||||
private volatile int mLatestProgress = 100;
|
||||
// Back/Forward list
|
||||
private final WebBackForwardList mBackForwardList;
|
||||
// Back/Forward list client
|
||||
private volatile WebBackForwardListClient mWebBackForwardListClient;
|
||||
// Used to call startActivity during url override.
|
||||
private final Context mContext;
|
||||
|
||||
@@ -107,6 +109,8 @@ class CallbackProxy extends Handler {
|
||||
private static final int RECEIVED_TOUCH_ICON_URL = 132;
|
||||
private static final int GET_VISITED_HISTORY = 133;
|
||||
private static final int OPEN_FILE_CHOOSER = 134;
|
||||
private static final int ADD_HISTORY_ITEM = 135;
|
||||
private static final int HISTORY_INDEX_CHANGED = 136;
|
||||
|
||||
// Message triggered by the client to resume execution
|
||||
private static final int NOTIFY = 200;
|
||||
@@ -137,7 +141,7 @@ class CallbackProxy extends Handler {
|
||||
// Used to start a default activity.
|
||||
mContext = context;
|
||||
mWebView = w;
|
||||
mBackForwardList = new WebBackForwardList();
|
||||
mBackForwardList = new WebBackForwardList(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,6 +194,14 @@ class CallbackProxy extends Handler {
|
||||
return mBackForwardList;
|
||||
}
|
||||
|
||||
void setWebBackForwardListClient(WebBackForwardListClient client) {
|
||||
mWebBackForwardListClient = client;
|
||||
}
|
||||
|
||||
WebBackForwardListClient getWebBackForwardListClient() {
|
||||
return mWebBackForwardListClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the UI side. Calling overrideUrlLoading from the WebCore
|
||||
* side will post a message to call this method.
|
||||
@@ -700,6 +712,20 @@ class CallbackProxy extends Handler {
|
||||
mWebChromeClient.openFileChooser((UploadFile) msg.obj);
|
||||
}
|
||||
break;
|
||||
|
||||
case ADD_HISTORY_ITEM:
|
||||
if (mWebBackForwardListClient != null) {
|
||||
mWebBackForwardListClient.onNewHistoryItem(
|
||||
(WebHistoryItem) msg.obj);
|
||||
}
|
||||
break;
|
||||
|
||||
case HISTORY_INDEX_CHANGED:
|
||||
if (mWebBackForwardListClient != null) {
|
||||
mWebBackForwardListClient.onIndexChanged(
|
||||
(WebHistoryItem) msg.obj, msg.arg1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1400,4 +1426,20 @@ class CallbackProxy extends Handler {
|
||||
}
|
||||
return uploadFile.getResult();
|
||||
}
|
||||
|
||||
void onNewHistoryItem(WebHistoryItem item) {
|
||||
if (mWebBackForwardListClient == null) {
|
||||
return;
|
||||
}
|
||||
Message msg = obtainMessage(ADD_HISTORY_ITEM, item);
|
||||
sendMessage(msg);
|
||||
}
|
||||
|
||||
void onIndexChanged(WebHistoryItem item, int index) {
|
||||
if (mWebBackForwardListClient == null) {
|
||||
return;
|
||||
}
|
||||
Message msg = obtainMessage(HISTORY_INDEX_CHANGED, index, 0, item);
|
||||
sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,13 +31,16 @@ public class WebBackForwardList implements Cloneable, Serializable {
|
||||
private ArrayList<WebHistoryItem> mArray;
|
||||
// Flag to indicate that the list is invalid
|
||||
private boolean mClearPending;
|
||||
// CallbackProxy to issue client callbacks.
|
||||
private final CallbackProxy mCallbackProxy;
|
||||
|
||||
/**
|
||||
* Construct a back/forward list used by clients of WebView.
|
||||
*/
|
||||
/*package*/ WebBackForwardList() {
|
||||
/*package*/ WebBackForwardList(CallbackProxy proxy) {
|
||||
mCurrentIndex = -1;
|
||||
mArray = new ArrayList<WebHistoryItem>();
|
||||
mCallbackProxy = proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,6 +119,9 @@ public class WebBackForwardList implements Cloneable, Serializable {
|
||||
}
|
||||
// Add the item to the list.
|
||||
mArray.add(item);
|
||||
if (mCallbackProxy != null) {
|
||||
mCallbackProxy.onNewHistoryItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +158,7 @@ public class WebBackForwardList implements Cloneable, Serializable {
|
||||
* webkit package classes.
|
||||
*/
|
||||
protected synchronized WebBackForwardList clone() {
|
||||
WebBackForwardList l = new WebBackForwardList();
|
||||
WebBackForwardList l = new WebBackForwardList(null);
|
||||
if (mClearPending) {
|
||||
// If a clear is pending, return a copy with only the current item.
|
||||
l.addHistoryItem(getCurrentItem());
|
||||
@@ -174,6 +180,9 @@ public class WebBackForwardList implements Cloneable, Serializable {
|
||||
*/
|
||||
/*package*/ synchronized void setCurrentIndex(int newIndex) {
|
||||
mCurrentIndex = newIndex;
|
||||
if (mCallbackProxy != null) {
|
||||
mCallbackProxy.onIndexChanged(getItemAtIndex(newIndex), newIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
40
core/java/android/webkit/WebBackForwardListClient.java
Normal file
40
core/java/android/webkit/WebBackForwardListClient.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.webkit;
|
||||
|
||||
/**
|
||||
* Interface to receive notifications when items are added to the
|
||||
* {@link WebBackForwardList}.
|
||||
* {@hide}
|
||||
*/
|
||||
public abstract class WebBackForwardListClient {
|
||||
|
||||
/**
|
||||
* Notify the client that <var>item</var> has been added to the
|
||||
* WebBackForwardList.
|
||||
* @param item The newly created WebHistoryItem
|
||||
*/
|
||||
public void onNewHistoryItem(WebHistoryItem item) { }
|
||||
|
||||
/**
|
||||
* Notify the client that the <var>item</var> at <var>index</var> is now
|
||||
* the current history item.
|
||||
* @param item A WebHistoryItem
|
||||
* @param index The new history index
|
||||
*/
|
||||
public void onIndexChanged(WebHistoryItem item, int index) { }
|
||||
}
|
||||
@@ -41,6 +41,8 @@ public class WebHistoryItem implements Cloneable {
|
||||
private byte[] mFlattenedData;
|
||||
// The apple-touch-icon url for use when adding the site to the home screen
|
||||
private String mTouchIconUrl;
|
||||
// Custom client data that is not flattened or read by native code.
|
||||
private Object mCustomData;
|
||||
|
||||
/**
|
||||
* Basic constructor that assigns a unique id to the item. Called by JNI
|
||||
@@ -136,6 +138,28 @@ public class WebHistoryItem implements Cloneable {
|
||||
return mTouchIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the custom data provided by the client.
|
||||
* @hide
|
||||
*/
|
||||
public Object getCustomData() {
|
||||
return mCustomData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the custom data field.
|
||||
* @param data An Object containing any data the client wishes to associate
|
||||
* with the item.
|
||||
* @hide
|
||||
*/
|
||||
public void setCustomData(Object data) {
|
||||
// NOTE: WebHistoryItems are used in multiple threads. However, the
|
||||
// public facing apis are all getters with the exception of this one
|
||||
// api. Since this api is exclusive to clients, we don't make any
|
||||
// promises about thread safety.
|
||||
mCustomData = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the favicon.
|
||||
* @param icon A Bitmap containing the favicon for this history item.
|
||||
|
||||
@@ -2859,6 +2859,25 @@ public class WebView extends AbsoluteLayout
|
||||
return mCallbackProxy.getWebChromeClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the back/forward list client. This is an implementation of
|
||||
* WebBackForwardListClient for handling new items and changes in the
|
||||
* history index.
|
||||
* @param client An implementation of WebBackForwardListClient.
|
||||
* {@hide}
|
||||
*/
|
||||
public void setWebBackForwardListClient(WebBackForwardListClient client) {
|
||||
mCallbackProxy.setWebBackForwardListClient(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the WebBackForwardListClient.
|
||||
* {@hide}
|
||||
*/
|
||||
public WebBackForwardListClient getWebBackForwardListClient() {
|
||||
return mCallbackProxy.getWebBackForwardListClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Picture listener. This is an interface used to receive
|
||||
* notifications of a new Picture.
|
||||
|
||||
Reference in New Issue
Block a user