OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 |
2 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 4 // found in the LICENSE file. |
4 | 5 |
5 #include "chrome/browser/android/webapps/add_to_homescreen_dialog_helper.h" | 6 #include "chrome/browser/android/webapps/add_to_homescreen_dialog_helper.h" |
6 | 7 |
7 #include <jni.h> | 8 #include <jni.h> |
8 | 9 |
9 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 if (add_shortcut_pending_) | 79 if (add_shortcut_pending_) |
79 AddShortcut(info, icon); | 80 AddShortcut(info, icon); |
80 } | 81 } |
81 | 82 |
82 void AddToHomescreenDialogHelper::Destroy(JNIEnv* env, jobject obj) { | 83 void AddToHomescreenDialogHelper::Destroy(JNIEnv* env, jobject obj) { |
83 delete this; | 84 delete this; |
84 } | 85 } |
85 | 86 |
86 SkBitmap AddToHomescreenDialogHelper::FinalizeLauncherIcon( | 87 SkBitmap AddToHomescreenDialogHelper::FinalizeLauncherIcon( |
87 const SkBitmap& bitmap, | 88 const SkBitmap& bitmap, |
88 const GURL& url) { | 89 const GURL& url, |
| 90 bool* generated) { |
89 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 91 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
90 | 92 |
91 // Determine a single color to use for the favicon if the favicon that is | 93 return ShortcutHelper::FinalizeLauncherIcon(bitmap, url, 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 } | 94 } |
115 | 95 |
116 void AddToHomescreenDialogHelper::AddShortcut(JNIEnv* env, | 96 void AddToHomescreenDialogHelper::AddShortcut(JNIEnv* env, |
117 jobject obj, | 97 jobject obj, |
118 jstring j_user_title) { | 98 jstring j_user_title) { |
119 add_shortcut_pending_ = true; | 99 add_shortcut_pending_ = true; |
120 | 100 |
121 base::string16 user_title = | 101 base::string16 user_title = |
122 base::android::ConvertJavaStringToUTF16(env, j_user_title); | 102 base::android::ConvertJavaStringToUTF16(env, j_user_title); |
123 if (!user_title.empty()) | 103 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(); | 142 content::WebContents* web_contents = data_fetcher_->web_contents(); |
163 if (!web_contents) | 143 if (!web_contents) |
164 return; | 144 return; |
165 | 145 |
166 AppBannerSettingsHelper::RecordBannerEvent( | 146 AppBannerSettingsHelper::RecordBannerEvent( |
167 web_contents, web_contents->GetURL(), | 147 web_contents, web_contents->GetURL(), |
168 data_fetcher_->shortcut_info().url.spec(), | 148 data_fetcher_->shortcut_info().url.spec(), |
169 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 149 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
170 base::Time::Now()); | 150 base::Time::Now()); |
171 } | 151 } |
OLD | NEW |