1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
* Copyright (C) 2006 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;
import android.graphics.Bitmap;
/**
* A convenience class for accessing fields in an entry in the back/forward list
* of a WebView. Each WebHistoryItem is a snapshot of the requested history
* item. Each history item may be updated during the load of a page.
* @see WebBackForwardList
*/
public class WebHistoryItem implements Cloneable {
// Global identifier count.
private static int sNextId = 0;
// Unique identifier.
private final int mId;
// The title of this item's document.
private String mTitle;
// The base url of this item.
private String mUrl;
// The original requested url of this item.
private String mOriginalUrl;
// The favicon for this item.
private Bitmap mFavicon;
// The pre-flattened data used for saving the state.
private byte[] mFlattenedData;
/**
* Basic constructor that assigns a unique id to the item. Called by JNI
* only.
*/
private WebHistoryItem() {
synchronized (WebHistoryItem.class) {
mId = sNextId++;
}
}
/**
* Construct a new WebHistoryItem with initial flattened data.
* @param data The pre-flattened data coming from restoreState.
*/
/*package*/ WebHistoryItem(byte[] data) {
mUrl = null; // This will be updated natively
mFlattenedData = data;
synchronized (WebHistoryItem.class) {
mId = sNextId++;
}
}
/**
* Construct a clone of a WebHistoryItem from the given item.
* @param item The history item to clone.
*/
private WebHistoryItem(WebHistoryItem item) {
mUrl = item.mUrl;
mTitle = item.mTitle;
mFlattenedData = item.mFlattenedData;
mFavicon = item.mFavicon;
mId = item.mId;
}
/**
* Return an identifier for this history item. If an item is a copy of
* another item, the identifiers will be the same even if they are not the
* same object.
* @return The id for this item.
*/
public int getId() {
return mId;
}
/**
* Return the url of this history item. The url is the base url of this
* history item. See getTargetUrl() for the url that is the actual target of
* this history item.
* @return The base url of this history item.
* Note: The VM ensures 32-bit atomic read/write operations so we don't have
* to synchronize this method.
*/
public String getUrl() {
return mUrl;
}
/**
* Return the original url of this history item. This was the requested
* url, the final url may be different as there might have been
* redirects while loading the site.
* @return The original url of this history item.
*
* @hide pending API Council approval
*/
public String getOriginalUrl() {
return mOriginalUrl;
}
/**
* Return the document title of this history item.
* @return The document title of this history item.
* Note: The VM ensures 32-bit atomic read/write operations so we don't have
* to synchronize this method.
*/
public String getTitle() {
return mTitle;
}
/**
* Return the favicon of this history item or null if no favicon was found.
* @return A Bitmap containing the favicon for this history item or null.
* Note: The VM ensures 32-bit atomic read/write operations so we don't have
* to synchronize this method.
*/
public Bitmap getFavicon() {
return mFavicon;
}
/**
* Set the favicon.
* @param icon A Bitmap containing the favicon for this history item.
* Note: The VM ensures 32-bit atomic read/write operations so we don't have
* to synchronize this method.
*/
/*package*/ void setFavicon(Bitmap icon) {
mFavicon = icon;
}
/**
* Get the pre-flattened data.
* Note: The VM ensures 32-bit atomic read/write operations so we don't have
* to synchronize this method.
*/
/*package*/ byte[] getFlattenedData() {
return mFlattenedData;
}
/**
* Inflate this item.
* Note: The VM ensures 32-bit atomic read/write operations so we don't have
* to synchronize this method.
*/
/*package*/ void inflate(int nativeFrame) {
inflate(nativeFrame, mFlattenedData);
}
/**
* Clone the history item for use by clients of WebView.
*/
protected synchronized WebHistoryItem clone() {
return new WebHistoryItem(this);
}
/* Natively inflate this item, this method is called in the WebCore thread.
*/
private native void inflate(int nativeFrame, byte[] data);
/* Called by jni when the item is updated */
private void update(String url, String originalUrl, String title,
Bitmap favicon, byte[] data) {
mUrl = url;
mOriginalUrl = originalUrl;
mTitle = title;
mFavicon = favicon;
mFlattenedData = data;
}
}
|