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

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

Issue 1308533006: webapps: allow callers of icon downloader/selector to specify a minimum size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webapps-splashscreen-icon
Patch Set: Address review comments Created 5 years, 3 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 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.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"
12 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/manifest/manifest_icon_downloader.h" 15 #include "chrome/browser/manifest/manifest_icon_downloader.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "jni/ShortcutHelper_jni.h" 18 #include "jni/ShortcutHelper_jni.h"
18 #include "ui/gfx/android/java_bitmap.h" 19 #include "ui/gfx/android/java_bitmap.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 using content::Manifest; 22 using content::Manifest;
22 23
24 namespace {
25 static int kIdealIconSize = -1;
26 static int kMinimumIconSize = -1;
27 static int kIdealSplashImageSize = -1;
28 static int kMinimumSplashImageSize = -1;
29
30 // Retrieves and caches the ideal and minimum sizes of the Home screen icon
31 // and the splash screen image.
32 void GetIconAndSplashImageSizes() {
33 JNIEnv* env = base::android::AttachCurrentThread();
34 ScopedJavaLocalRef<jintArray> java_size_array =
35 Java_ShortcutHelper_getIconAndSplashImageSizes(env,
36 base::android::GetApplicationContext());
37 std::vector<int> size_vector;
38 base::android::JavaIntArrayToIntVector(
39 env, java_size_array.obj(), &size_vector);
40
41 // This ordering must be kept up to date with the Java ShortcutHelper.
42 kIdealIconSize = size_vector[0];
43 kMinimumIconSize = size_vector[1];
44 kIdealSplashImageSize = size_vector[2];
45 kMinimumSplashImageSize = size_vector[3];
46
47 // Try to ensure that the data returned is sane.
48 DCHECK(size_vector.size() == 4);
49 DCHECK(kMinimumIconSize <= kIdealIconSize);
50 DCHECK(kMinimumSplashImageSize <= kIdealSplashImageSize);
51 }
52 } // namespace
53
23 // static 54 // static
24 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( 55 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap(
25 const ShortcutInfo& info, 56 const ShortcutInfo& info,
26 const std::string& webapp_id, 57 const std::string& webapp_id,
27 const SkBitmap& icon_bitmap) { 58 const SkBitmap& icon_bitmap) {
28 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 59 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
29 60
30 // Send the data to the Java side to create the shortcut. 61 // Send the data to the Java side to create the shortcut.
31 JNIEnv* env = base::android::AttachCurrentThread(); 62 JNIEnv* env = base::android::AttachCurrentThread();
32 ScopedJavaLocalRef<jstring> java_webapp_id = 63 ScopedJavaLocalRef<jstring> java_webapp_id =
(...skipping 19 matching lines...) Expand all
52 java_name.obj(), 83 java_name.obj(),
53 java_short_name.obj(), 84 java_short_name.obj(),
54 java_bitmap.obj(), 85 java_bitmap.obj(),
55 info.display == blink::WebDisplayModeStandalone, 86 info.display == blink::WebDisplayModeStandalone,
56 info.orientation, 87 info.orientation,
57 info.source, 88 info.source,
58 info.theme_color, 89 info.theme_color,
59 info.background_color); 90 info.background_color);
60 } 91 }
61 92
93 int ShortcutHelper::GetIdealSplashImageSizeInDp() {
94 if (kIdealIconSize == -1)
95 GetIconAndSplashImageSizes();
96 return kIdealIconSize;
97 }
98
99 int ShortcutHelper::GetMinimumSplashImageSizeInDp() {
100 if (kMinimumIconSize == -1)
101 GetIconAndSplashImageSizes();
102 return kMinimumIconSize;
103 }
104
105 int ShortcutHelper::GetIdealIconSizeInDp() {
106 if (kIdealSplashImageSize == -1)
107 GetIconAndSplashImageSizes();
108 return kIdealSplashImageSize;
109 }
110
111 int ShortcutHelper::GetMinimumIconSizeInDp() {
112 if (kMinimumSplashImageSize == -1)
113 GetIconAndSplashImageSizes();
114 return kMinimumSplashImageSize;
115 }
116
62 // static 117 // static
63 void ShortcutHelper::FetchSplashScreenImage( 118 void ShortcutHelper::FetchSplashScreenImage(
64 content::WebContents* web_contents, 119 content::WebContents* web_contents,
65 const GURL& image_url, 120 const GURL& image_url,
66 const int ideal_splash_image_size_in_dp, 121 const int ideal_splash_image_size_in_dp,
122 const int minimum_splash_image_size_in_dp,
67 const std::string& webapp_id) { 123 const std::string& webapp_id) {
68 // This is a fire and forget task. It is not vital for the splash screen image 124 // This is a fire and forget task. It is not vital for the splash screen image
69 // to be downloaded so if the downloader returns false there is no fallback. 125 // to be downloaded so if the downloader returns false there is no fallback.
70 ManifestIconDownloader::Download( 126 ManifestIconDownloader::Download(
71 web_contents, 127 web_contents,
72 image_url, 128 image_url,
73 ideal_splash_image_size_in_dp, 129 ideal_splash_image_size_in_dp,
130 minimum_splash_image_size_in_dp,
74 base::Bind(&ShortcutHelper::StoreWebappData, webapp_id)); 131 base::Bind(&ShortcutHelper::StoreWebappData, webapp_id));
75 } 132 }
76 133
77 // static 134 // static
78 void ShortcutHelper::StoreWebappData( 135 void ShortcutHelper::StoreWebappData(
79 const std::string& webapp_id, 136 const std::string& webapp_id,
80 const SkBitmap& splash_image) { 137 const SkBitmap& splash_image) {
81 if (splash_image.drawsNothing()) 138 if (splash_image.drawsNothing())
82 return; 139 return;
83 140
84 JNIEnv* env = base::android::AttachCurrentThread(); 141 JNIEnv* env = base::android::AttachCurrentThread();
85 ScopedJavaLocalRef<jstring> java_webapp_id = 142 ScopedJavaLocalRef<jstring> java_webapp_id =
86 base::android::ConvertUTF8ToJavaString(env, webapp_id); 143 base::android::ConvertUTF8ToJavaString(env, webapp_id);
87 ScopedJavaLocalRef<jobject> java_splash_image = 144 ScopedJavaLocalRef<jobject> java_splash_image =
88 gfx::ConvertToJavaBitmap(&splash_image); 145 gfx::ConvertToJavaBitmap(&splash_image);
89 146
90 Java_ShortcutHelper_storeWebappData( 147 Java_ShortcutHelper_storeWebappData(
91 env, 148 env,
92 base::android::GetApplicationContext(), 149 base::android::GetApplicationContext(),
93 java_webapp_id.obj(), 150 java_webapp_id.obj(),
94 java_splash_image.obj()); 151 java_splash_image.obj());
95 } 152 }
96 153
97 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 154 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
98 return RegisterNativesImpl(env); 155 return RegisterNativesImpl(env);
99 } 156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698