| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/android/navigation_popup.h" | 5 #include "chrome/browser/ui/android/navigation_popup.h" |
| 6 | 6 |
| 7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/favicon/favicon_service.h" | 11 #include "chrome/browser/favicon/favicon_service.h" |
| 12 #include "chrome/browser/favicon/favicon_service_factory.h" | 12 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 13 #include "chrome/browser/history/history_types.h" | 13 #include "chrome/browser/history/history_types.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "grit/ui_resources.h" | 17 #include "grit/ui_resources.h" |
| 18 #include "jni/NavigationPopup_jni.h" | 18 #include "jni/NavigationPopup_jni.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/android/java_bitmap.h" | 21 #include "ui/gfx/android/java_bitmap.h" |
| 22 #include "ui/gfx/favicon_size.h" | |
| 23 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 24 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 25 | 24 |
| 26 using base::android::ConvertUTF8ToJavaString; | 25 using base::android::ConvertUTF8ToJavaString; |
| 27 using base::android::ScopedJavaLocalRef; | 26 using base::android::ScopedJavaLocalRef; |
| 28 | 27 |
| 29 NavigationPopup::NavigationPopup(JNIEnv* env, jobject obj) | 28 NavigationPopup::NavigationPopup(JNIEnv* env, jobject obj) |
| 30 : weak_jobject_(env, obj) { | 29 : weak_jobject_(env, obj) { |
| 31 } | 30 } |
| 32 | 31 |
| 33 NavigationPopup::~NavigationPopup() { | 32 NavigationPopup::~NavigationPopup() { |
| 34 } | 33 } |
| 35 | 34 |
| 36 void NavigationPopup::Destroy(JNIEnv* env, jobject obj) { | 35 void NavigationPopup::Destroy(JNIEnv* env, jobject obj) { |
| 37 delete this; | 36 delete this; |
| 38 } | 37 } |
| 39 | 38 |
| 40 void NavigationPopup::FetchFaviconForUrl(JNIEnv* env, | 39 void NavigationPopup::FetchFaviconForUrl(JNIEnv* env, |
| 41 jobject obj, | 40 jobject obj, |
| 42 jstring jurl) { | 41 jstring jurl) { |
| 43 Profile* profile = g_browser_process->profile_manager()->GetLastUsedProfile(); | 42 Profile* profile = g_browser_process->profile_manager()->GetLastUsedProfile(); |
| 44 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 43 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 45 profile, Profile::EXPLICIT_ACCESS); | 44 profile, Profile::EXPLICIT_ACCESS); |
| 46 if (!favicon_service) | 45 if (!favicon_service) |
| 47 return; | 46 return; |
| 48 GURL url(base::android::ConvertJavaStringToUTF16(env, jurl)); | 47 GURL url(base::android::ConvertJavaStringToUTF16(env, jurl)); |
| 49 // TODO(tedchoc): Request higher favicons based on screen density instead of | 48 // TODO(tedchoc): Request higher favicons based on screen density instead of |
| 50 // hardcoding kFaviconSize. | 49 // hardcoding kFaviconSize. |
| 51 favicon_service->GetFaviconImageForPageURL( | 50 favicon_service->GetFaviconImageForPageURL( |
| 52 FaviconService::FaviconForPageURLParams( | 51 url, |
| 53 url, favicon_base::FAVICON, gfx::kFaviconSize), | |
| 54 base::Bind(&NavigationPopup::OnFaviconDataAvailable, | 52 base::Bind(&NavigationPopup::OnFaviconDataAvailable, |
| 55 base::Unretained(this), | 53 base::Unretained(this), |
| 56 url), | 54 url), |
| 57 &cancelable_task_tracker_); | 55 &cancelable_task_tracker_); |
| 58 } | 56 } |
| 59 | 57 |
| 60 void NavigationPopup::OnFaviconDataAvailable( | 58 void NavigationPopup::OnFaviconDataAvailable( |
| 61 GURL navigation_entry_url, | 59 GURL navigation_entry_url, |
| 62 const favicon_base::FaviconImageResult& image_result) { | 60 const favicon_base::FaviconImageResult& image_result) { |
| 63 gfx::Image image(image_result.image); | 61 gfx::Image image(image_result.image); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 87 | 85 |
| 88 static jlong Init(JNIEnv* env, jobject obj) { | 86 static jlong Init(JNIEnv* env, jobject obj) { |
| 89 NavigationPopup* popup = new NavigationPopup(env, obj); | 87 NavigationPopup* popup = new NavigationPopup(env, obj); |
| 90 return reinterpret_cast<intptr_t>(popup); | 88 return reinterpret_cast<intptr_t>(popup); |
| 91 } | 89 } |
| 92 | 90 |
| 93 // static | 91 // static |
| 94 bool NavigationPopup::RegisterNavigationPopup(JNIEnv* env) { | 92 bool NavigationPopup::RegisterNavigationPopup(JNIEnv* env) { |
| 95 return RegisterNativesImpl(env); | 93 return RegisterNativesImpl(env); |
| 96 } | 94 } |
| OLD | NEW |