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

Side by Side Diff: chrome/browser/android/shortcut_helper.cc

Issue 2773353002: Make minimum PWA icon size the same accross all device densities
Patch Set: Merge branch 'master' into min_size Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/shortcut_helper.h" 5 #include "chrome/browser/android/shortcut_helper.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
11 #include "base/android/jni_array.h" 11 #include "base/android/jni_array.h"
12 #include "base/android/jni_string.h" 12 #include "base/android/jni_string.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/guid.h" 15 #include "base/guid.h"
16 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/threading/sequenced_worker_pool.h" 18 #include "base/threading/sequenced_worker_pool.h"
19 #include "chrome/browser/android/webapk/chrome_webapk_host.h" 19 #include "chrome/browser/android/webapk/chrome_webapk_host.h"
20 #include "chrome/browser/android/webapk/webapk_install_service.h" 20 #include "chrome/browser/android/webapk/webapk_install_service.h"
21 #include "chrome/browser/android/webapk/webapk_metrics.h" 21 #include "chrome/browser/android/webapk/webapk_metrics.h"
22 #include "chrome/browser/installable/installable_manager.h"
22 #include "chrome/browser/manifest/manifest_icon_downloader.h" 23 #include "chrome/browser/manifest/manifest_icon_downloader.h"
23 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 #include "jni/ShortcutHelper_jni.h" 27 #include "jni/ShortcutHelper_jni.h"
27 #include "ui/gfx/android/java_bitmap.h" 28 #include "ui/gfx/android/java_bitmap.h"
28 #include "ui/gfx/color_analysis.h" 29 #include "ui/gfx/color_analysis.h"
29 #include "url/gurl.h" 30 #include "url/gurl.h"
30 31
31 using base::android::JavaParamRef; 32 using base::android::JavaParamRef;
32 using base::android::ScopedJavaLocalRef; 33 using base::android::ScopedJavaLocalRef;
33 using content::Manifest; 34 using content::Manifest;
34 35
35 namespace { 36 namespace {
36 37
37 int g_ideal_homescreen_icon_size = -1; 38 int g_ideal_homescreen_icon_size = -1;
38 int g_minimum_homescreen_icon_size = -1;
39 int g_ideal_splash_image_size = -1; 39 int g_ideal_splash_image_size = -1;
40 int g_minimum_splash_image_size = -1;
41 int g_ideal_badge_icon_size = -1; 40 int g_ideal_badge_icon_size = -1;
42 41
43 int g_default_rgb_icon_value = 145; 42 int g_default_rgb_icon_value = 145;
44 43
45 // Retrieves and caches the ideal and minimum sizes of the Home screen icon 44 // Retrieves and caches the ideal and minimum sizes of the Home screen icon
46 // and the splash screen image. 45 // and the splash screen image.
47 void GetHomescreenIconAndSplashImageSizes() { 46 void GetHomescreenIconAndSplashImageSizes() {
48 JNIEnv* env = base::android::AttachCurrentThread(); 47 JNIEnv* env = base::android::AttachCurrentThread();
49 ScopedJavaLocalRef<jintArray> java_size_array = 48 ScopedJavaLocalRef<jintArray> java_size_array =
50 Java_ShortcutHelper_getHomeScreenIconAndSplashImageSizes(env); 49 Java_ShortcutHelper_getHomeScreenIconAndSplashImageSizes(env);
51 std::vector<int> sizes; 50 std::vector<int> sizes;
52 base::android::JavaIntArrayToIntVector(env, java_size_array.obj(), &sizes); 51 base::android::JavaIntArrayToIntVector(env, java_size_array.obj(), &sizes);
53 52
54 // Check that the size returned is what is expected. 53 // Check that the size returned is what is expected.
55 DCHECK(sizes.size() == 5); 54 DCHECK(sizes.size() == 3);
56 55
57 // This ordering must be kept up to date with the Java ShortcutHelper. 56 // This ordering must be kept up to date with the Java ShortcutHelper.
58 g_ideal_homescreen_icon_size = sizes[0]; 57 g_ideal_homescreen_icon_size =
59 g_minimum_homescreen_icon_size = sizes[1]; 58 std::max(sizes[0], InstallableManager::GetMinimumIconSizeInPx());
60 g_ideal_splash_image_size = sizes[2]; 59 g_ideal_splash_image_size =
61 g_minimum_splash_image_size = sizes[3]; 60 std::max(sizes[1], InstallableManager::GetMinimumIconSizeInPx());
62 g_ideal_badge_icon_size = sizes[4]; 61 g_ideal_badge_icon_size = sizes[2];
63
64 // Try to ensure that the data returned is sane.
65 DCHECK(g_minimum_homescreen_icon_size <= g_ideal_homescreen_icon_size);
66 DCHECK(g_minimum_splash_image_size <= g_ideal_splash_image_size);
67 } 62 }
68 63
69 // Adds a shortcut which opens in a fullscreen window to the launcher. 64 // Adds a shortcut which opens in a fullscreen window to the launcher.
70 // |splash_image_callback| will be invoked once the Java-side operation has 65 // |splash_image_callback| will be invoked once the Java-side operation has
71 // completed. This is necessary as Java will asynchronously create and 66 // completed. This is necessary as Java will asynchronously create and
72 // populate a WebappDataStorage object for standalone-capable sites. This must 67 // populate a WebappDataStorage object for standalone-capable sites. This must
73 // exist before the splash image can be stored. 68 // exist before the splash image can be stored.
74 void AddWebappWithSkBitmap(const ShortcutInfo& info, 69 void AddWebappWithSkBitmap(const ShortcutInfo& info,
75 const std::string& webapp_id, 70 const std::string& webapp_id,
76 const SkBitmap& icon_bitmap, 71 const SkBitmap& icon_bitmap,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 content::WebContents* web_contents, 131 content::WebContents* web_contents,
137 const ShortcutInfo& info, 132 const ShortcutInfo& info,
138 const SkBitmap& icon_bitmap) { 133 const SkBitmap& icon_bitmap) {
139 std::string webapp_id = base::GenerateGUID(); 134 std::string webapp_id = base::GenerateGUID();
140 if (info.display == blink::WebDisplayModeStandalone || 135 if (info.display == blink::WebDisplayModeStandalone ||
141 info.display == blink::WebDisplayModeFullscreen) { 136 info.display == blink::WebDisplayModeFullscreen) {
142 AddWebappWithSkBitmap( 137 AddWebappWithSkBitmap(
143 info, webapp_id, icon_bitmap, 138 info, webapp_id, icon_bitmap,
144 base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents, 139 base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents,
145 info.splash_image_url, info.ideal_splash_image_size_in_px, 140 info.splash_image_url, info.ideal_splash_image_size_in_px,
146 info.minimum_splash_image_size_in_px, webapp_id)); 141 webapp_id));
147 GooglePlayInstallState state = 142 GooglePlayInstallState state =
148 ChromeWebApkHost::GetGooglePlayInstallState(); 143 ChromeWebApkHost::GetGooglePlayInstallState();
149 if (state != GooglePlayInstallState::SUPPORTED) 144 if (state != GooglePlayInstallState::SUPPORTED)
150 webapk::TrackGooglePlayInstallState(state); 145 webapk::TrackGooglePlayInstallState(state);
151 return; 146 return;
152 } 147 }
153 AddShortcutWithSkBitmap(info, webapp_id, icon_bitmap); 148 AddShortcutWithSkBitmap(info, webapp_id, icon_bitmap);
154 } 149 }
155 150
156 // static 151 // static
(...skipping 16 matching lines...) Expand all
173 Java_ShortcutHelper_showWebApkInstallInProgressToast( 168 Java_ShortcutHelper_showWebApkInstallInProgressToast(
174 base::android::AttachCurrentThread()); 169 base::android::AttachCurrentThread());
175 } 170 }
176 171
177 int ShortcutHelper::GetIdealHomescreenIconSizeInPx() { 172 int ShortcutHelper::GetIdealHomescreenIconSizeInPx() {
178 if (g_ideal_homescreen_icon_size == -1) 173 if (g_ideal_homescreen_icon_size == -1)
179 GetHomescreenIconAndSplashImageSizes(); 174 GetHomescreenIconAndSplashImageSizes();
180 return g_ideal_homescreen_icon_size; 175 return g_ideal_homescreen_icon_size;
181 } 176 }
182 177
183 int ShortcutHelper::GetMinimumHomescreenIconSizeInPx() {
184 if (g_minimum_homescreen_icon_size == -1)
185 GetHomescreenIconAndSplashImageSizes();
186 return g_minimum_homescreen_icon_size;
187 }
188
189 int ShortcutHelper::GetIdealSplashImageSizeInPx() { 178 int ShortcutHelper::GetIdealSplashImageSizeInPx() {
190 if (g_ideal_splash_image_size == -1) 179 if (g_ideal_splash_image_size == -1)
191 GetHomescreenIconAndSplashImageSizes(); 180 GetHomescreenIconAndSplashImageSizes();
192 return g_ideal_splash_image_size; 181 return g_ideal_splash_image_size;
193 } 182 }
194 183
195 int ShortcutHelper::GetMinimumSplashImageSizeInPx() {
196 if (g_minimum_splash_image_size == -1)
197 GetHomescreenIconAndSplashImageSizes();
198 return g_minimum_splash_image_size;
199 }
200
201 int ShortcutHelper::GetIdealBadgeIconSizeInPx() { 184 int ShortcutHelper::GetIdealBadgeIconSizeInPx() {
202 if (g_ideal_badge_icon_size == -1) 185 if (g_ideal_badge_icon_size == -1)
203 GetHomescreenIconAndSplashImageSizes(); 186 GetHomescreenIconAndSplashImageSizes();
204 return g_ideal_badge_icon_size; 187 return g_ideal_badge_icon_size;
205 } 188 }
206 189
207 // static 190 // static
208 void ShortcutHelper::FetchSplashScreenImage( 191 void ShortcutHelper::FetchSplashScreenImage(
209 content::WebContents* web_contents, 192 content::WebContents* web_contents,
210 const GURL& image_url, 193 const GURL& image_url,
211 const int ideal_splash_image_size_in_px, 194 const int ideal_splash_image_size_in_px,
212 const int minimum_splash_image_size_in_px,
213 const std::string& webapp_id) { 195 const std::string& webapp_id) {
214 // This is a fire and forget task. It is not vital for the splash screen image 196 // This is a fire and forget task. It is not vital for the splash screen image
215 // to be downloaded so if the downloader returns false there is no fallback. 197 // to be downloaded so if the downloader returns false there is no fallback.
216 ManifestIconDownloader::Download( 198 ManifestIconDownloader::Download(
217 web_contents, image_url, ideal_splash_image_size_in_px, 199 web_contents, image_url, ideal_splash_image_size_in_px,
218 minimum_splash_image_size_in_px, 200 InstallableManager::GetMinimumIconSizeInPx(),
219 base::Bind(&ShortcutHelper::StoreWebappSplashImage, webapp_id)); 201 base::Bind(&ShortcutHelper::StoreWebappSplashImage, webapp_id));
220 } 202 }
221 203
222 // static 204 // static
223 void ShortcutHelper::StoreWebappSplashImage(const std::string& webapp_id, 205 void ShortcutHelper::StoreWebappSplashImage(const std::string& webapp_id,
224 const SkBitmap& splash_image) { 206 const SkBitmap& splash_image) {
225 if (splash_image.drawsNothing()) 207 if (splash_image.drawsNothing())
226 return; 208 return;
227 209
228 JNIEnv* env = base::android::AttachCurrentThread(); 210 JNIEnv* env = base::android::AttachCurrentThread();
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 395
414 ShortcutHelper::WebApkInfoCallback* webapk_list_callback = 396 ShortcutHelper::WebApkInfoCallback* webapk_list_callback =
415 reinterpret_cast<ShortcutHelper::WebApkInfoCallback*>(jcallback_pointer); 397 reinterpret_cast<ShortcutHelper::WebApkInfoCallback*>(jcallback_pointer);
416 webapk_list_callback->Run(webapk_list); 398 webapk_list_callback->Run(webapk_list);
417 delete webapk_list_callback; 399 delete webapk_list_callback;
418 } 400 }
419 401
420 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 402 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
421 return RegisterNativesImpl(env); 403 return RegisterNativesImpl(env);
422 } 404 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698