Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/android/navigation_popup.h" | |
| 6 | |
| 7 #include "base/android/jni_string.h" | |
| 8 #include "base/android/scoped_java_ref.h" | |
| 9 #include "base/bind.h" | |
| 10 #include "chrome/browser/browser_process.h" | |
| 11 #include "chrome/browser/favicon/favicon_service.h" | |
| 12 #include "chrome/browser/favicon/favicon_service_factory.h" | |
| 13 #include "chrome/browser/history/history_types.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/browser/profiles/profile_manager.h" | |
| 16 #include "googleurl/src/gurl.h" | |
| 17 #include "grit/ui_resources.h" | |
| 18 #include "jni/NavigationPopup_jni.h" | |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | |
| 20 #include "ui/base/resource/resource_bundle.h" | |
| 21 #include "ui/gfx/android/java_bitmap.h" | |
| 22 #include "ui/gfx/favicon_size.h" | |
| 23 #include "ui/gfx/image/image.h" | |
| 24 | |
| 25 using base::android::ScopedJavaLocalRef; | |
| 26 | |
| 27 NavigationPopup::NavigationPopup(JNIEnv* env, jobject obj) | |
| 28 : weak_jobject_(env, obj) { | |
| 29 } | |
| 30 | |
| 31 NavigationPopup::~NavigationPopup() { | |
| 32 } | |
| 33 | |
| 34 void NavigationPopup::Destroy(JNIEnv* env, jobject obj) { | |
| 35 delete this; | |
| 36 } | |
| 37 | |
| 38 void NavigationPopup::FetchFaviconForUrl(JNIEnv* env, | |
| 39 jobject obj, | |
| 40 jstring jurl) { | |
| 41 Profile* profile = g_browser_process->profile_manager()->GetLastUsedProfile(); | |
| 42 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | |
| 43 profile, Profile::EXPLICIT_ACCESS); | |
| 44 if (!favicon_service) | |
| 45 return; | |
| 46 GURL url = GURL(base::android::ConvertJavaStringToUTF16(env, jurl)); | |
| 47 favicon_service->GetFaviconImageForURL( | |
| 48 FaviconService::FaviconForURLParams(profile, | |
| 49 url, | |
| 50 history::FAVICON, | |
| 51 gfx::kFaviconSize), | |
| 52 base::Bind(&NavigationPopup::OnFaviconDataAvailable, | |
| 53 base::Unretained(this), | |
| 54 url), | |
| 55 &cancelable_task_tracker_); | |
| 56 } | |
| 57 | |
| 58 void NavigationPopup::OnFaviconDataAvailable( | |
| 59 GURL navigation_entry_url, | |
| 60 const history::FaviconImageResult& image_result) { | |
| 61 gfx::Image image = image_result.image; | |
| 62 if (image.IsEmpty()) { | |
| 63 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 64 image = rb.GetImageNamed(IDR_DEFAULT_FAVICON); | |
| 65 } | |
| 66 | |
| 67 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 68 ScopedJavaLocalRef<jobject> obj = weak_jobject_.get(env); | |
| 69 if (!obj.obj()) | |
| 70 return; | |
| 71 | |
| 72 ScopedJavaLocalRef<jstring> jurl = | |
|
David Trainor- moved to gerrit
2013/01/03 18:57:31
For things like this use jurl(base::android::Conve
Ted C
2013/01/03 19:56:41
Done. Updated everywhere that I saw.
| |
| 73 base::android::ConvertUTF8ToJavaString(env, navigation_entry_url.spec()); | |
| 74 | |
| 75 Java_NavigationPopup_onFaviconUpdated( | |
| 76 env, | |
| 77 obj.obj(), | |
| 78 jurl.obj(), | |
| 79 gfx::ConvertToJavaBitmap(image.ToSkBitmap()).obj()); | |
| 80 } | |
| 81 | |
| 82 static jint Init(JNIEnv* env, jobject obj) { | |
| 83 NavigationPopup* popup = new NavigationPopup(env, obj); | |
| 84 return reinterpret_cast<jint>(popup); | |
| 85 } | |
| 86 | |
| 87 // static | |
| 88 bool NavigationPopup::RegisterNavigationPopup(JNIEnv* env) { | |
| 89 return RegisterNativesImpl(env); | |
| 90 } | |
| OLD | NEW |