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

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
gone 2015/09/14 23:03:32 "launcher" or "Home screen"
Lalit Maganti 2015/09/15 16:59:03 Done.
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.
gone 2015/09/14 23:03:32 Assert that the array size is correct to loosely e
Lalit Maganti 2015/09/15 16:59:03 Done.
42 kIdealIconSize = size_vector[0];
43 kMinimumIconSize = size_vector[1];
44 kIdealSplashImageSize = size_vector[2];
45 kMinimumSplashImageSize = size_vector[3];
46 }
47 } // namespace
48
23 // static 49 // static
24 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( 50 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap(
25 const ShortcutInfo& info, 51 const ShortcutInfo& info,
26 const std::string& webapp_id, 52 const std::string& webapp_id,
27 const SkBitmap& icon_bitmap) { 53 const SkBitmap& icon_bitmap) {
28 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 54 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
29 55
30 // Send the data to the Java side to create the shortcut. 56 // Send the data to the Java side to create the shortcut.
31 JNIEnv* env = base::android::AttachCurrentThread(); 57 JNIEnv* env = base::android::AttachCurrentThread();
32 ScopedJavaLocalRef<jstring> java_webapp_id = 58 ScopedJavaLocalRef<jstring> java_webapp_id =
(...skipping 19 matching lines...) Expand all
52 java_name.obj(), 78 java_name.obj(),
53 java_short_name.obj(), 79 java_short_name.obj(),
54 java_bitmap.obj(), 80 java_bitmap.obj(),
55 info.display == blink::WebDisplayModeStandalone, 81 info.display == blink::WebDisplayModeStandalone,
56 info.orientation, 82 info.orientation,
57 info.source, 83 info.source,
58 info.theme_color, 84 info.theme_color,
59 info.background_color); 85 info.background_color);
60 } 86 }
61 87
88 int ShortcutHelper::GetIdealSplashImageSizeInDp() {
89 if (kIdealIconSize == -1)
90 GetIconAndSplashImageSizes();
91 return kIdealIconSize;
92 }
93
94 int ShortcutHelper::GetMinimumSplashImageSizeInDp() {
95 if (kMinimumIconSize == -1)
96 GetIconAndSplashImageSizes();
97 return kMinimumIconSize;
98 }
99
100 int ShortcutHelper::GetIdealIconSizeInDp() {
101 if (kIdealSplashImageSize == -1)
102 GetIconAndSplashImageSizes();
103 return kIdealSplashImageSize;
104 }
105
106 int ShortcutHelper::GetMinimumIconSizeInDp() {
107 if (kMinimumSplashImageSize == -1)
108 GetIconAndSplashImageSizes();
109 return kMinimumSplashImageSize;
110 }
111
62 // static 112 // static
63 void ShortcutHelper::FetchSplashScreenImage( 113 void ShortcutHelper::FetchSplashScreenImage(
64 content::WebContents* web_contents, 114 content::WebContents* web_contents,
65 const GURL& image_url, 115 const GURL& image_url,
66 const int ideal_splash_image_size_in_dp, 116 const int ideal_splash_image_size_in_dp,
117 const int minimum_splash_image_size_in_dp,
67 const std::string& webapp_id) { 118 const std::string& webapp_id) {
68 // This is a fire and forget task. It is not vital for the splash screen image 119 // 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. 120 // to be downloaded so if the downloader returns false there is no fallback.
70 ManifestIconDownloader::Download( 121 ManifestIconDownloader::Download(
71 web_contents, 122 web_contents,
72 image_url, 123 image_url,
73 ideal_splash_image_size_in_dp, 124 ideal_splash_image_size_in_dp,
125 minimum_splash_image_size_in_dp,
74 base::Bind(&ShortcutHelper::StoreWebappData, webapp_id)); 126 base::Bind(&ShortcutHelper::StoreWebappData, webapp_id));
75 } 127 }
76 128
77 // static 129 // static
78 void ShortcutHelper::StoreWebappData( 130 void ShortcutHelper::StoreWebappData(
79 const std::string& webapp_id, 131 const std::string& webapp_id,
80 const SkBitmap& splash_image) { 132 const SkBitmap& splash_image) {
81 if (splash_image.drawsNothing()) 133 if (splash_image.drawsNothing())
82 return; 134 return;
83 135
84 JNIEnv* env = base::android::AttachCurrentThread(); 136 JNIEnv* env = base::android::AttachCurrentThread();
85 ScopedJavaLocalRef<jstring> java_webapp_id = 137 ScopedJavaLocalRef<jstring> java_webapp_id =
86 base::android::ConvertUTF8ToJavaString(env, webapp_id); 138 base::android::ConvertUTF8ToJavaString(env, webapp_id);
87 ScopedJavaLocalRef<jobject> java_splash_image = 139 ScopedJavaLocalRef<jobject> java_splash_image =
88 gfx::ConvertToJavaBitmap(&splash_image); 140 gfx::ConvertToJavaBitmap(&splash_image);
89 141
90 Java_ShortcutHelper_storeWebappData( 142 Java_ShortcutHelper_storeWebappData(
91 env, 143 env,
92 base::android::GetApplicationContext(), 144 base::android::GetApplicationContext(),
93 java_webapp_id.obj(), 145 java_webapp_id.obj(),
94 java_splash_image.obj()); 146 java_splash_image.obj());
95 } 147 }
96 148
97 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 149 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
98 return RegisterNativesImpl(env); 150 return RegisterNativesImpl(env);
99 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698