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

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: Fix test failure 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
26 static int kIdealHomescreenIconSize = -1;
27 static int kMinimumHomescreenIconSize = -1;
28 static int kIdealSplashImageSize = -1;
29 static int kMinimumSplashImageSize = -1;
30
31 // Retrieves and caches the ideal and minimum sizes of the Home screen icon
32 // and the splash screen image.
33 void GetHomescreenIconAndSplashImageSizes() {
34 JNIEnv* env = base::android::AttachCurrentThread();
35 ScopedJavaLocalRef<jintArray> java_size_array =
36 Java_ShortcutHelper_getHomescreenIconAndSplashImageSizes(env,
37 base::android::GetApplicationContext());
38 std::vector<int> sizes;
39 base::android::JavaIntArrayToIntVector(
40 env, java_size_array.obj(), &sizes);
41
42 // Check that the size returned is what is expected.
43 DCHECK(sizes.size() == 4);
44
45 // This ordering must be kept up to date with the Java ShortcutHelper.
46 kIdealHomescreenIconSize = sizes[0];
47 kMinimumHomescreenIconSize = sizes[1];
48 kIdealSplashImageSize = sizes[2];
49 kMinimumSplashImageSize = sizes[3];
50
51 // Try to ensure that the data returned is sane.
52 DCHECK(kMinimumHomescreenIconSize <= kIdealHomescreenIconSize);
53 DCHECK(kMinimumSplashImageSize <= kIdealSplashImageSize);
54 }
55
56 } // anonymous namespace
57
23 // static 58 // static
24 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( 59 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap(
25 const ShortcutInfo& info, 60 const ShortcutInfo& info,
26 const std::string& webapp_id, 61 const std::string& webapp_id,
27 const SkBitmap& icon_bitmap) { 62 const SkBitmap& icon_bitmap) {
28 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 63 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
29 64
30 // Send the data to the Java side to create the shortcut. 65 // Send the data to the Java side to create the shortcut.
31 JNIEnv* env = base::android::AttachCurrentThread(); 66 JNIEnv* env = base::android::AttachCurrentThread();
32 ScopedJavaLocalRef<jstring> java_webapp_id = 67 ScopedJavaLocalRef<jstring> java_webapp_id =
(...skipping 19 matching lines...) Expand all
52 java_name.obj(), 87 java_name.obj(),
53 java_short_name.obj(), 88 java_short_name.obj(),
54 java_bitmap.obj(), 89 java_bitmap.obj(),
55 info.display == blink::WebDisplayModeStandalone, 90 info.display == blink::WebDisplayModeStandalone,
56 info.orientation, 91 info.orientation,
57 info.source, 92 info.source,
58 info.theme_color, 93 info.theme_color,
59 info.background_color); 94 info.background_color);
60 } 95 }
61 96
97 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() {
98 if (kIdealHomescreenIconSize == -1)
99 GetHomescreenIconAndSplashImageSizes();
100 return kIdealHomescreenIconSize;
101 }
102
103 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() {
104 if (kMinimumHomescreenIconSize == -1)
105 GetHomescreenIconAndSplashImageSizes();
106 return kMinimumHomescreenIconSize;
107 }
108
109 int ShortcutHelper::GetIdealSplashImageSizeInDp() {
110 if (kIdealSplashImageSize == -1)
111 GetHomescreenIconAndSplashImageSizes();
112 return kIdealSplashImageSize;
113 }
114
115 int ShortcutHelper::GetMinimumSplashImageSizeInDp() {
116 if (kMinimumSplashImageSize == -1)
117 GetHomescreenIconAndSplashImageSizes();
118 return kMinimumSplashImageSize;
119 }
120
62 // static 121 // static
63 void ShortcutHelper::FetchSplashScreenImage( 122 void ShortcutHelper::FetchSplashScreenImage(
64 content::WebContents* web_contents, 123 content::WebContents* web_contents,
65 const GURL& image_url, 124 const GURL& image_url,
66 const int ideal_splash_image_size_in_dp, 125 const int ideal_splash_image_size_in_dp,
126 const int minimum_splash_image_size_in_dp,
67 const std::string& webapp_id) { 127 const std::string& webapp_id) {
68 // This is a fire and forget task. It is not vital for the splash screen image 128 // 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. 129 // to be downloaded so if the downloader returns false there is no fallback.
70 ManifestIconDownloader::Download( 130 ManifestIconDownloader::Download(
71 web_contents, 131 web_contents,
72 image_url, 132 image_url,
73 ideal_splash_image_size_in_dp, 133 ideal_splash_image_size_in_dp,
134 minimum_splash_image_size_in_dp,
74 base::Bind(&ShortcutHelper::StoreWebappData, webapp_id)); 135 base::Bind(&ShortcutHelper::StoreWebappData, webapp_id));
75 } 136 }
76 137
77 // static 138 // static
78 void ShortcutHelper::StoreWebappData( 139 void ShortcutHelper::StoreWebappData(
79 const std::string& webapp_id, 140 const std::string& webapp_id,
80 const SkBitmap& splash_image) { 141 const SkBitmap& splash_image) {
81 if (splash_image.drawsNothing()) 142 if (splash_image.drawsNothing())
82 return; 143 return;
83 144
84 JNIEnv* env = base::android::AttachCurrentThread(); 145 JNIEnv* env = base::android::AttachCurrentThread();
85 ScopedJavaLocalRef<jstring> java_webapp_id = 146 ScopedJavaLocalRef<jstring> java_webapp_id =
86 base::android::ConvertUTF8ToJavaString(env, webapp_id); 147 base::android::ConvertUTF8ToJavaString(env, webapp_id);
87 ScopedJavaLocalRef<jobject> java_splash_image = 148 ScopedJavaLocalRef<jobject> java_splash_image =
88 gfx::ConvertToJavaBitmap(&splash_image); 149 gfx::ConvertToJavaBitmap(&splash_image);
89 150
90 Java_ShortcutHelper_storeWebappData( 151 Java_ShortcutHelper_storeWebappData(
91 env, 152 env,
92 base::android::GetApplicationContext(), 153 base::android::GetApplicationContext(),
93 java_webapp_id.obj(), 154 java_webapp_id.obj(),
94 java_splash_image.obj()); 155 java_splash_image.obj());
95 } 156 }
96 157
97 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 158 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
98 return RegisterNativesImpl(env); 159 return RegisterNativesImpl(env);
99 } 160 }
OLDNEW
« no previous file with comments | « chrome/browser/android/shortcut_helper.h ('k') | chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698