OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/android/webapps/add_to_homescreen_dialog_helper.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_dialog_helper.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 if (add_shortcut_pending_) | 78 if (add_shortcut_pending_) |
79 AddShortcut(info, icon); | 79 AddShortcut(info, icon); |
80 } | 80 } |
81 | 81 |
82 void AddToHomescreenDialogHelper::Destroy(JNIEnv* env, jobject obj) { | 82 void AddToHomescreenDialogHelper::Destroy(JNIEnv* env, jobject obj) { |
83 delete this; | 83 delete this; |
84 } | 84 } |
85 | 85 |
86 SkBitmap AddToHomescreenDialogHelper::FinalizeLauncherIcon( | 86 SkBitmap AddToHomescreenDialogHelper::FinalizeLauncherIcon( |
87 const SkBitmap& bitmap, | 87 const SkBitmap& bitmap, |
88 const GURL& url) { | 88 const GURL& url, |
| 89 bool* is_generated) { |
89 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 90 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
90 | 91 |
91 // Determine a single color to use for the favicon if the favicon that is | 92 return ShortcutHelper::FinalizeLauncherIcon(bitmap, url, is_generated); |
92 // returned it is too low quality. | |
93 SkColor color = color_utils::CalculateKMeanColorOfBitmap(bitmap); | |
94 int dominant_red = SkColorGetR(color); | |
95 int dominant_green = SkColorGetG(color); | |
96 int dominant_blue = SkColorGetB(color); | |
97 | |
98 // Make the icon acceptable for the Android launcher. | |
99 JNIEnv* env = base::android::AttachCurrentThread(); | |
100 ScopedJavaLocalRef<jstring> java_url = | |
101 base::android::ConvertUTF8ToJavaString(env, url.spec()); | |
102 ScopedJavaLocalRef<jobject> java_bitmap; | |
103 if (bitmap.getSize()) | |
104 java_bitmap = gfx::ConvertToJavaBitmap(&bitmap); | |
105 | |
106 base::android::ScopedJavaLocalRef<jobject> ref = | |
107 Java_AddToHomescreenDialogHelper_finalizeLauncherIcon(env, | |
108 java_url.obj(), | |
109 java_bitmap.obj(), | |
110 dominant_red, | |
111 dominant_green, | |
112 dominant_blue); | |
113 return gfx::CreateSkBitmapFromJavaBitmap(gfx::JavaBitmap(ref.obj())); | |
114 } | 93 } |
115 | 94 |
116 void AddToHomescreenDialogHelper::AddShortcut(JNIEnv* env, | 95 void AddToHomescreenDialogHelper::AddShortcut(JNIEnv* env, |
117 jobject obj, | 96 jobject obj, |
118 jstring j_user_title) { | 97 jstring j_user_title) { |
119 add_shortcut_pending_ = true; | 98 add_shortcut_pending_ = true; |
120 | 99 |
121 base::string16 user_title = | 100 base::string16 user_title = |
122 base::android::ConvertJavaStringToUTF16(env, j_user_title); | 101 base::android::ConvertJavaStringToUTF16(env, j_user_title); |
123 if (!user_title.empty()) | 102 if (!user_title.empty()) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 content::WebContents* web_contents = data_fetcher_->web_contents(); | 141 content::WebContents* web_contents = data_fetcher_->web_contents(); |
163 if (!web_contents) | 142 if (!web_contents) |
164 return; | 143 return; |
165 | 144 |
166 AppBannerSettingsHelper::RecordBannerEvent( | 145 AppBannerSettingsHelper::RecordBannerEvent( |
167 web_contents, web_contents->GetURL(), | 146 web_contents, web_contents->GetURL(), |
168 data_fetcher_->shortcut_info().url.spec(), | 147 data_fetcher_->shortcut_info().url.spec(), |
169 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 148 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
170 base::Time::Now()); | 149 base::Time::Now()); |
171 } | 150 } |
OLD | NEW |