Implementation of GetFavicon for current tab.

This patch returns the bitmap of the current tab favicon.

BUG=

Review URL: https://codereview.chromium.org/364793005

Cr-Commit-Position: refs/heads/master@{#289275}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289275 0039d316-1c4b-4281-b951-d872f2087c98
parent 4b48da77
......@@ -139,6 +139,10 @@ public class Tab implements NavigationClient {
private boolean mIsClosing = false;
private Bitmap mFavicon = null;
private String mFaviconUrl = null;
/**
* A default {@link ChromeContextMenuItemDelegate} that supports some of the context menu
* functionality.
......@@ -885,10 +889,16 @@ public class Tab implements NavigationClient {
/**
* @return The bitmap of the favicon scaled to 16x16dp. null if no favicon
* is specified or it requires the default favicon.
* TODO(bauerb): Upstream implementation.
*/
public Bitmap getFavicon() {
return null;
if (mContentViewCore != null) {
if (mFavicon == null || !mContentViewCore.getUrl().equals(mFaviconUrl)) {
if (mNativeTabAndroid == 0) return null;
mFavicon = nativeGetFavicon(mNativeTabAndroid);
mFaviconUrl = mContentViewCore.getUrl();
}
}
return mFavicon;
}
/**
......@@ -1014,6 +1024,8 @@ public class Tab implements NavigationClient {
*/
@CalledByNative
protected void onFaviconUpdated() {
mFavicon = null;
mFaviconUrl = null;
for (TabObserver observer : mObservers) observer.onFaviconUpdated(this);
}
......@@ -1156,4 +1168,5 @@ public class Tab implements NavigationClient {
private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTabAndroid, String url,
String title);
private native boolean nativePrint(long nativeTabAndroid);
private native Bitmap nativeGetFavicon(long nativeTabAndroid);
}
......@@ -12,6 +12,7 @@
#include "chrome/browser/browser_about_handler.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/google/google_url_tracker_factory.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/prerender/prerender_contents.h"
......@@ -47,8 +48,14 @@
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "jni/Tab_jni.h"
#include "skia/ext/image_operations.h"
#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/window_open_disposition.h"
#include "ui/gfx/android/device_display_info.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image_skia.h"
using content::GlobalRequestID;
using content::NavigationController;
......@@ -589,6 +596,45 @@ bool TabAndroid::Print(JNIEnv* env, jobject obj) {
return true;
}
ScopedJavaLocalRef<jobject> TabAndroid::GetFavicon(JNIEnv* env, jobject obj) {
ScopedJavaLocalRef<jobject> bitmap;
FaviconTabHelper* favicon_tab_helper =
FaviconTabHelper::FromWebContents(web_contents_.get());
if (!favicon_tab_helper)
return bitmap;
if (!favicon_tab_helper->FaviconIsValid())
return bitmap;
SkBitmap favicon =
favicon_tab_helper->GetFavicon()
.AsImageSkia()
.GetRepresentation(
ResourceBundle::GetSharedInstance().GetMaxScaleFactor())
.sk_bitmap();
if (favicon.empty()) {
favicon = favicon_tab_helper->GetFavicon().AsBitmap();
}
if (!favicon.empty()) {
gfx::DeviceDisplayInfo device_info;
const float device_scale_factor = device_info.GetDIPScale();
int target_size_dip = device_scale_factor * gfx::kFaviconSize;
if (favicon.width() != target_size_dip ||
favicon.height() != target_size_dip) {
favicon =
skia::ImageOperations::Resize(favicon,
skia::ImageOperations::RESIZE_BEST,
target_size_dip,
target_size_dip);
}
bitmap = gfx::ConvertToJavaBitmap(&favicon);
}
return bitmap;
}
prerender::PrerenderManager* TabAndroid::GetPrerenderManager() const {
Profile* profile = GetProfile();
if (!profile)
......
......@@ -147,6 +147,10 @@ class TabAndroid : public CoreTabHelperDelegate,
jstring jurl,
jstring jtitle);
bool Print(JNIEnv* env, jobject obj);
// Called to get favicon of current tab, return null if no favicon is
// avaliable for current tab.
base::android::ScopedJavaLocalRef<jobject> GetFavicon(JNIEnv* env,
jobject obj);
// Register the Tab's native methods through JNI.
static bool RegisterTabAndroid(JNIEnv* env);
......
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