summaryrefslogtreecommitdiffstats
path: root/WebKit/android/jni/WebHistory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/android/jni/WebHistory.cpp')
-rw-r--r--WebKit/android/jni/WebHistory.cpp89
1 files changed, 26 insertions, 63 deletions
diff --git a/WebKit/android/jni/WebHistory.cpp b/WebKit/android/jni/WebHistory.cpp
index 0d469b4..191f818 100644
--- a/WebKit/android/jni/WebHistory.cpp
+++ b/WebKit/android/jni/WebHistory.cpp
@@ -90,7 +90,7 @@ static void WebHistoryClose(JNIEnv* env, jobject obj, jint frame)
list->removeItem(entries[i].get());
// Add the current item back to the list.
if (current) {
- current->setBridge(NULL);
+ current->setBridge(0);
// addItem will update the children to match the newly created bridge
list->addItem(current);
@@ -174,10 +174,9 @@ static void WebHistoryInflate(JNIEnv* env, jobject obj, jint frame, jbyteArray d
// Inflate the history tree into one HistoryItem or null if the inflation
// failed.
RefPtr<WebCore::HistoryItem> newItem = WebCore::HistoryItem::create();
-#ifdef ANDROID_HISTORY_CLIENT
RefPtr<WebHistoryItem> bridge = new WebHistoryItem(env, obj, newItem.get());
newItem->setBridge(bridge.get());
-#endif
+
// Inflate the item recursively. If it fails, that is ok. We'll have an
// incomplete HistoryItem but that is better than crashing due to a null
// item.
@@ -187,28 +186,19 @@ static void WebHistoryInflate(JNIEnv* env, jobject obj, jint frame, jbyteArray d
const char* ptr = reinterpret_cast<const char*>(bytes);
read_item_recursive(newItem.get(), &ptr, (int)size);
env->ReleaseByteArrayElements(data, const_cast<jbyte*>(bytes), JNI_ABORT);
-#ifdef ANDROID_HISTORY_CLIENT
bridge->setActive();
-#endif
// Add the new item to the back/forward list.
WebCore::Frame* pFrame = (WebCore::Frame*)frame;
pFrame->page()->backForwardList()->addItem(newItem);
-#ifdef ANDROID_HISTORY_CLIENT
// Update the item.
bridge->updateHistoryItem(newItem.get());
-#endif
}
// 6 empty strings + no document state + children count = 8 unsigned values
-// 1 char for isTargetItem
-// ANDROID_HISTORY_CLIENT adds 1 int for scale.
-#ifdef ANDROID_HISTORY_CLIENT
+// 1 char for isTargetItem and 1 char is for scale.
#define HISTORY_MIN_SIZE ((int)(sizeof(unsigned) * 9 + sizeof(char)))
-#else
-#define HISTORY_MIN_SIZE ((int)(sizeof(unsigned) * 8 + sizeof(char)))
-#endif
jbyteArray WebHistory::Flatten(JNIEnv* env, WTF::Vector<char>& v, WebCore::HistoryItem* item)
{
@@ -220,9 +210,7 @@ jbyteArray WebHistory::Flatten(JNIEnv* env, WTF::Vector<char>& v, WebCore::Histo
// Write the top-level history item and then write all the children
// recursively.
-#ifdef ANDROID_HISTORY_CLIENT
LOG_ASSERT(item->bridge(), "Why don't we have a bridge object here?");
-#endif
write_item(v, item);
write_children_recursive(v, item);
@@ -238,32 +226,31 @@ jbyteArray WebHistory::Flatten(JNIEnv* env, WTF::Vector<char>& v, WebCore::Histo
WebHistoryItem::WebHistoryItem(JNIEnv* env, jobject obj,
WebCore::HistoryItem* item) {
- mObject = adoptGlobalRef(env, obj);
- mScale = 100;
- mActive = false;
- mParent = NULL;
- mHistoryItem = item;
+ m_object = adoptGlobalRef(env, obj);
+ m_parent = 0;
+ m_scale = 100;
+ m_active = false;
+ m_historyItem = item;
}
WebHistoryItem::~WebHistoryItem() {
- if (mObject) {
+ if (m_object) {
JNIEnv* env = JSC::Bindings::getJNIEnv();
if (!env)
return;
- env->DeleteGlobalRef(mObject);
+ env->DeleteGlobalRef(m_object);
}
}
void WebHistoryItem::updateHistoryItem(WebCore::HistoryItem* item) {
-#ifdef ANDROID_HISTORY_CLIENT
// Do not want to update during inflation.
- if (!mActive)
+ if (!m_active)
return;
WebHistoryItem* webItem = this;
// Now we need to update the top-most WebHistoryItem based on the top-most
// HistoryItem.
- if (mParent) {
- webItem = mParent.get();
+ if (m_parent) {
+ webItem = m_parent.get();
if (webItem->hasOneRef()) {
// if the parent only has one ref, it is from this WebHistoryItem.
// This means that the matching WebCore::HistoryItem has been freed.
@@ -280,7 +267,7 @@ void WebHistoryItem::updateHistoryItem(WebCore::HistoryItem* item) {
return;
// Don't do anything if the item has been gc'd already
- AutoJObject realItem = getRealObject(env, webItem->mObject);
+ AutoJObject realItem = getRealObject(env, webItem->m_object);
if (!realItem.get())
return;
@@ -325,21 +312,17 @@ void WebHistoryItem::updateHistoryItem(WebCore::HistoryItem* item) {
if (favicon)
env->DeleteLocalRef(favicon);
env->DeleteLocalRef(array);
-#endif
}
static void historyItemChanged(WebCore::HistoryItem* item) {
-#ifdef ANDROID_HISTORY_CLIENT
- LOG_ASSERT(item,
- "historyItemChanged called with a null item");
+ LOG_ASSERT(item, "historyItemChanged called with a null item");
+
if (item->bridge())
item->bridge()->updateHistoryItem(item);
-#endif
}
void WebHistory::AddItem(const AutoJObject& list, WebCore::HistoryItem* item)
{
-#ifdef ANDROID_HISTORY_CLIENT
LOG_ASSERT(item, "newItem must take a valid HistoryItem!");
// Item already added. Should only happen when we are inflating the list.
if (item->bridge() || !list.get())
@@ -364,7 +347,6 @@ void WebHistory::AddItem(const AutoJObject& list, WebCore::HistoryItem* item)
// Delete our local reference.
env->DeleteLocalRef(newItem);
-#endif
}
void WebHistory::RemoveItem(const AutoJObject& list, int index)
@@ -434,14 +416,12 @@ static void write_item(WTF::Vector<char>& v, WebCore::HistoryItem* item)
// Target
write_string(v, item->target());
-#ifdef ANDROID_HISTORY_CLIENT
- WebHistoryItem* bridge = item->bridge();
+ AndroidWebHistoryBridge* bridge = item->bridge();
LOG_ASSERT(bridge, "We should have a bridge here!");
// Screen scale
int scale = bridge->scale();
LOGV("Writing scale %d", scale);
v.append((char*)&scale, sizeof(int));
-#endif
// Document state
const WTF::Vector<WebCore::String>& docState = item->documentState();
@@ -469,23 +449,23 @@ static void write_children_recursive(WTF::Vector<char>& v, WebCore::HistoryItem*
WebCore::HistoryItemVector::const_iterator end = children.end();
for (WebCore::HistoryItemVector::const_iterator i = children.begin(); i != end; ++i) {
WebCore::HistoryItem* item = (*i).get();
-#ifdef ANDROID_HISTORY_CLIENT
LOG_ASSERT(parent->bridge(),
"The parent item should have a bridge object!");
if (!item->bridge()) {
- WebHistoryItem* bridge = new WebHistoryItem(parent->bridge());
+ WebHistoryItem* bridge = new WebHistoryItem(static_cast<WebHistoryItem*>(parent->bridge()));
item->setBridge(bridge);
bridge->setActive();
} else {
// The only time this item's parent may not be the same as the
// parent's bridge is during history close. In that case, the
// parent must not have a parent bridge.
- LOG_ASSERT(parent->bridge()->parent() == NULL ||
- item->bridge()->parent() == parent->bridge(),
+ WebHistoryItem* bridge = static_cast<WebHistoryItem*>(item->bridge());
+ WebHistoryItem* parentBridge = static_cast<WebHistoryItem*>(parent->bridge());
+ LOG_ASSERT(parentBridge->parent() == 0 ||
+ bridge->parent() == parentBridge,
"Somehow this item has an incorrect parent");
- item->bridge()->setParent(parent->bridge());
+ bridge->setParent(parentBridge);
}
-#endif
write_item(v, item);
write_children_recursive(v, item);
}
@@ -615,8 +595,7 @@ static bool read_item_recursive(WebCore::HistoryItem* newItem,
if (end - data < sizeofUnsigned)
return false;
-#ifdef ANDROID_HISTORY_CLIENT
- WebHistoryItem* bridge = newItem->bridge();
+ AndroidWebHistoryBridge* bridge = newItem->bridge();
LOG_ASSERT(bridge, "There should be a bridge object during inflate");
// Read the screen scale
memcpy(&l, data, sizeofUnsigned);
@@ -625,7 +604,6 @@ static bool read_item_recursive(WebCore::HistoryItem* newItem,
data += sizeofUnsigned;
if (end - data < sizeofUnsigned)
return false;
-#endif
// Read the document state
memcpy(&l, data, sizeofUnsigned);
@@ -685,18 +663,14 @@ static bool read_item_recursive(WebCore::HistoryItem* newItem,
// No need to check the length each time because read_item_recursive
// will return null if there isn't enough data left to parse.
WTF::PassRefPtr<WebCore::HistoryItem> child = WebCore::HistoryItem::create();
-#ifdef ANDROID_HISTORY_CLIENT
// Set a bridge that will not call into java.
- child->setBridge(new WebHistoryItem(bridge));
-#endif
+ child->setBridge(new WebHistoryItem(static_cast<WebHistoryItem*>(bridge)));
// Read the child item.
if (!read_item_recursive(child.get(), pData, end - data)) {
child.clear();
return false;
}
-#ifdef ANDROID_HISTORY_CLIENT
child->bridge()->setActive();
-#endif
newItem->addChildItem(child);
}
}
@@ -717,9 +691,7 @@ static void unit_test()
const char* test1 = new char[0];
WTF::RefPtr<WebCore::HistoryItem> item = WebCore::HistoryItem::create();
WebCore::HistoryItem* testItem = item.get();
-#ifdef ANDROID_HISTORY_CLIENT
- testItem->setBridge(new WebHistoryItem(NULL));
-#endif
+ testItem->setBridge(new WebHistoryItem(0));
LOG_ASSERT(!read_item_recursive(testItem, &test1, 0), "0 length array should fail!");
delete[] test1;
const char* test2 = new char[2];
@@ -762,9 +734,7 @@ static void unit_test()
ptr = (const char*)test3;
*(int*)(test3 + offset) = 4000;
LOG_ASSERT(!read_item_recursive(testItem, &ptr, HISTORY_MIN_SIZE), "4000 length target should fail!");
-#ifdef ANDROID_HISTORY_CLIENT
offset += 4; // Scale
-#endif
// Document state
offset += 4;
memset(test3, 0, HISTORY_MIN_SIZE);
@@ -783,12 +753,7 @@ static void unit_test()
ptr = (const char*)test3;
*(int*)(test3 + offset) = 4000;
LOG_ASSERT(!read_item_recursive(testItem, &ptr, HISTORY_MIN_SIZE), "4000 kids should fail!");
-
-#ifdef ANDROID_HISTORY_CLIENT
offset = 36;
-#else
- offset = 28;
-#endif
// Test document state
delete[] test3;
test3 = new char[HISTORY_MIN_SIZE + sizeof(unsigned)];
@@ -826,10 +791,8 @@ static JNINativeMethod gWebHistoryItemMethods[] = {
int register_webhistory(JNIEnv* env)
{
-#ifdef ANDROID_HISTORY_CLIENT
// Get notified of all changes to history items.
WebCore::notifyHistoryItemChanged = historyItemChanged;
-#endif
#ifdef UNIT_TEST
unit_test();
#endif