Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4389)

Unified Diff: chrome/browser/android/tab_android.cc

Issue 364793005: Implementation of GetFavicon for current tab. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed as per suggested Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/tab_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/tab_android.cc
diff --git a/chrome/browser/android/tab_android.cc b/chrome/browser/android/tab_android.cc
index f175c0f92587ebb466db9a01ec39c4323ecce6c8..8b77755d785cdeb0b8b983ab8e5431959730c76e 100644
--- a/chrome/browser/android/tab_android.cc
+++ b/chrome/browser/android/tab_android.cc
@@ -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;
@@ -572,6 +579,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)
« no previous file with comments | « chrome/browser/android/tab_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698