Upstream ContentView.getNavigationHistory()

This function was added to support WebView.copyBackForwardList(). It
basically copies much of the content of the view's NavigationController
into the appropriate Java data structures.

BUG=138478


Review URL: https://chromiumcodereview.appspot.com/10836155

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151155 0039d316-1c4b-4281-b951-d872f2087c98
parent a5249243
......@@ -18,7 +18,9 @@
#include "content/browser/renderer_host/render_widget_host_view_android.h"
#include "content/browser/web_contents/navigation_controller_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
......@@ -28,6 +30,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEventFactory.h"
#include "ui/gfx/android/java_bitmap.h"
#include "webkit/glue/webmenuitem.h"
using base::android::AttachCurrentThread;
......@@ -396,6 +399,39 @@ void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env,
ConvertJavaStringToUTF16(env, name));
}
int ContentViewCoreImpl::GetNavigationHistory(JNIEnv* env,
jobject obj,
jobject context) {
// Iterate through navigation entries to populate the list
const NavigationController& controller = web_contents_->GetController();
int count = controller.GetEntryCount();
for (int i = 0; i < count; ++i) {
NavigationEntry* entry = controller.GetEntryAtIndex(i);
// Get the details of the current entry
ScopedJavaLocalRef<jstring> j_url = ConvertUTF8ToJavaString(env,
entry->GetURL().spec());
ScopedJavaLocalRef<jstring> j_virtual_url = ConvertUTF8ToJavaString(env,
entry->GetVirtualURL().spec());
ScopedJavaLocalRef<jstring> j_original_url = ConvertUTF8ToJavaString(env,
entry->GetOriginalRequestURL().spec());
ScopedJavaLocalRef<jstring> j_title = ConvertUTF16ToJavaString(env,
entry->GetTitle());
ScopedJavaLocalRef<jobject> j_bitmap;
const FaviconStatus& status = entry->GetFavicon();
if (status.valid && status.image.ToSkBitmap()->getSize() > 0) {
j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap());
}
// Add the item to the list
Java_ContentViewCore_addToNavigationHistory(env, obj, context, j_url.obj(),
j_virtual_url.obj(), j_original_url.obj(), j_title.obj(),
j_bitmap.obj());
}
return controller.GetCurrentEntryIndex();
}
// --------------------------------------------------------------------------
// Methods called from native code
// --------------------------------------------------------------------------
......
......@@ -119,6 +119,7 @@ class ContentViewCoreImpl : public ContentViewCore,
jstring name,
jboolean require_annotation);
void RemoveJavascriptInterface(JNIEnv* env, jobject obj, jstring name);
int GetNavigationHistory(JNIEnv* env, jobject obj, jobject context);
// --------------------------------------------------------------------------
// Public methods that call to Java via JNI
......
......@@ -6,6 +6,7 @@ package org.chromium.content.browser;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Build;
import android.os.Bundle;
......@@ -1108,6 +1109,26 @@ public class ContentViewCore implements MotionEventDelegate {
mAccessibilityInjector.setScriptEnabled(state);
}
/**
* Callback factory method for nativeGetNavigationHistory().
*/
@CalledByNative
private void addToNavigationHistory(Object history, String url, String virtualUrl,
String originalUrl, String title, Bitmap favicon) {
NavigationEntry entry = new NavigationEntry(url, virtualUrl, originalUrl, title, favicon);
((NavigationHistory) history).addEntry(entry);
}
/**
* Get a copy of the navigation history of the view.
*/
public NavigationHistory getNavigationHistory() {
NavigationHistory history = new NavigationHistory();
int currentIndex = nativeGetNavigationHistory(mNativeContentViewCore, history);
history.setCurrentEntryIndex(currentIndex);
return history;
}
// The following methods are implemented at native side.
/**
......@@ -1204,4 +1225,6 @@ public class ContentViewCore implements MotionEventDelegate {
String name, boolean requireAnnotation);
private native void nativeRemoveJavascriptInterface(int nativeContentViewCoreImpl, String name);
private native int nativeGetNavigationHistory(int nativeContentViewCoreImpl, Object context);
}
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content.browser;
import android.graphics.Bitmap;
/**
* Represents one entry in the navigation history of a page.
*/
public class NavigationEntry {
private String mUrl;
private String mOriginalUrl;
private String mVirtualUrl;
private String mTitle;
private Bitmap mFavicon;
/**
* Default constructor.
*/
/* package */ NavigationEntry(String url, String virtualUrl, String originalUrl, String title,
Bitmap favicon) {
mUrl = url;
mVirtualUrl = virtualUrl;
mOriginalUrl = originalUrl;
mTitle = title;
mFavicon = favicon;
}
/**
* @return The actual URL of the page. For some about pages, this may be a
* scary data: URL or something like that. Use GetVirtualURL() for
* showing to the user.
*/
public String getUrl() {
return mUrl;
}
/**
* @return The virtual URL, when nonempty, will override the actual URL of
* the page when we display it to the user. This allows us to have
* nice and friendly URLs that the user sees for things like about:
* URLs, but actually feed the renderer a data URL that results in
* the content loading.
* <p/>
* GetVirtualURL() will return the URL to display to the user in all
* cases, so if there is no overridden display URL, it will return
* the actual one.
*/
public String getVirtualUrl() {
return mVirtualUrl;
}
/**
* @return The URL that caused this NavigationEntry to be created.
*/
public String getOriginalUrl() {
return mOriginalUrl;
}
/**
* @return The title as set by the page. This will be empty if there is no
* title set. The caller is responsible for detecting when there is
* no title and displaying the appropriate "Untitled" label if this
* is being displayed to the user.
*/
public String getTitle() {
return mTitle;
}
/**
* @return The favicon of the page. This may be null.
*/
public Bitmap getFavicon() {
return mFavicon;
}
}
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content.browser;
import java.util.ArrayList;
/**
* {@link NavigationHistory} captures a snapshot of the navigation history of a
* {@link ContentView}. It is a copy and will not be updated as navigation
* occurs on the source {@link ContentView}.
*/
public class NavigationHistory {
private ArrayList<NavigationEntry> entries = new ArrayList<NavigationEntry>();
private int mCurrentEntryIndex;
/* package */ void addEntry(NavigationEntry entry) {
entries.add(entry);
}
/* package */ void setCurrentEntryIndex(int currentEntryIndex) {
mCurrentEntryIndex = currentEntryIndex;
}
/**
* @return The number of entries in the history.
*/
public int getEntryCount() {
return entries.size();
}
/**
* Returns the {@link NavigationEntry} for the given index.
*/
public NavigationEntry getEntryAtIndex(int index) {
return entries.get(index);
}
/**
* Returns the index of the entry the {@link ContentView} was navigated to
* when the history was fetched.
*/
public int getCurrentEntryIndex() {
return mCurrentEntryIndex;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment