OLD | NEW |
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_array.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 kMinimumSplashImageSize = sizes[3]; | 57 kMinimumSplashImageSize = sizes[3]; |
58 | 58 |
59 // Try to ensure that the data returned is sane. | 59 // Try to ensure that the data returned is sane. |
60 DCHECK(kMinimumHomescreenIconSize <= kIdealHomescreenIconSize); | 60 DCHECK(kMinimumHomescreenIconSize <= kIdealHomescreenIconSize); |
61 DCHECK(kMinimumSplashImageSize <= kIdealSplashImageSize); | 61 DCHECK(kMinimumSplashImageSize <= kIdealSplashImageSize); |
62 } | 62 } |
63 | 63 |
64 } // anonymous namespace | 64 } // anonymous namespace |
65 | 65 |
66 // static | 66 // static |
67 void ShortcutHelper::AddToLauncherInBackgroundWithSkBitmap( | 67 void ShortcutHelper::AddToLauncherWithSkBitmap( |
68 content::BrowserContext* browser_context, | 68 content::BrowserContext* browser_context, |
69 const ShortcutInfo& info, | 69 const ShortcutInfo& info, |
70 const std::string& webapp_id, | 70 const std::string& webapp_id, |
71 const SkBitmap& icon_bitmap, | 71 const SkBitmap& icon_bitmap, |
72 const base::Closure& splash_image_callback) { | 72 const base::Closure& splash_image_callback) { |
73 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
74 | |
75 if (info.display == blink::WebDisplayModeStandalone || | 73 if (info.display == blink::WebDisplayModeStandalone || |
76 info.display == blink::WebDisplayModeFullscreen) { | 74 info.display == blink::WebDisplayModeFullscreen) { |
77 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 75 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
78 switches::kEnableWebApk)) { | 76 switches::kEnableWebApk)) { |
79 InstallWebApkInBackgroundWithSkBitmap(browser_context, info, icon_bitmap); | 77 InstallWebApkWithSkBitmap(browser_context, info, icon_bitmap); |
80 return; | 78 return; |
81 } | 79 } |
82 AddWebappInBackgroundWithSkBitmap(info, webapp_id, icon_bitmap, | 80 AddWebappWithSkBitmap(info, webapp_id, icon_bitmap, splash_image_callback); |
83 splash_image_callback); | |
84 return; | 81 return; |
85 } | 82 } |
86 AddShortcutInBackgroundWithSkBitmap(info, icon_bitmap); | 83 AddShortcutWithSkBitmap(info, icon_bitmap); |
87 } | 84 } |
88 | 85 |
89 // static | 86 // static |
90 void ShortcutHelper::InstallWebApkInBackgroundWithSkBitmap( | 87 void ShortcutHelper::InstallWebApkWithSkBitmap( |
91 content::BrowserContext* browser_context, | 88 content::BrowserContext* browser_context, |
92 const ShortcutInfo& info, | 89 const ShortcutInfo& info, |
93 const SkBitmap& icon_bitmap) { | 90 const SkBitmap& icon_bitmap) { |
94 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
95 // WebApkInstaller destroys itself when it is done. | 91 // WebApkInstaller destroys itself when it is done. |
96 WebApkInstaller* installer = new WebApkInstaller(info, icon_bitmap); | 92 WebApkInstaller* installer = new WebApkInstaller(info, icon_bitmap); |
97 installer->InstallAsync(browser_context, | 93 installer->InstallAsync(browser_context, |
98 base::Bind(&ShortcutHelper::OnBuiltWebApk)); | 94 base::Bind(&ShortcutHelper::OnBuiltWebApk)); |
99 } | 95 } |
100 | 96 |
101 // static | 97 // static |
102 void ShortcutHelper::AddWebappInBackgroundWithSkBitmap( | 98 void ShortcutHelper::AddWebappWithSkBitmap( |
103 const ShortcutInfo& info, | 99 const ShortcutInfo& info, |
104 const std::string& webapp_id, | 100 const std::string& webapp_id, |
105 const SkBitmap& icon_bitmap, | 101 const SkBitmap& icon_bitmap, |
106 const base::Closure& splash_image_callback) { | 102 const base::Closure& splash_image_callback) { |
107 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
108 | |
109 // Send the data to the Java side to create the shortcut. | 103 // Send the data to the Java side to create the shortcut. |
110 JNIEnv* env = base::android::AttachCurrentThread(); | 104 JNIEnv* env = base::android::AttachCurrentThread(); |
111 ScopedJavaLocalRef<jstring> java_webapp_id = | 105 ScopedJavaLocalRef<jstring> java_webapp_id = |
112 base::android::ConvertUTF8ToJavaString(env, webapp_id); | 106 base::android::ConvertUTF8ToJavaString(env, webapp_id); |
113 ScopedJavaLocalRef<jstring> java_url = | 107 ScopedJavaLocalRef<jstring> java_url = |
114 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 108 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
115 ScopedJavaLocalRef<jstring> java_scope_url = | 109 ScopedJavaLocalRef<jstring> java_scope_url = |
116 base::android::ConvertUTF8ToJavaString(env, info.scope.spec()); | 110 base::android::ConvertUTF8ToJavaString(env, info.scope.spec()); |
117 ScopedJavaLocalRef<jstring> java_user_title = | 111 ScopedJavaLocalRef<jstring> java_user_title = |
118 base::android::ConvertUTF16ToJavaString(env, info.user_title); | 112 base::android::ConvertUTF16ToJavaString(env, info.user_title); |
(...skipping 25 matching lines...) Expand all Loading... |
144 java_icon_url.obj(), | 138 java_icon_url.obj(), |
145 java_bitmap.obj(), | 139 java_bitmap.obj(), |
146 info.display, | 140 info.display, |
147 info.orientation, | 141 info.orientation, |
148 info.source, | 142 info.source, |
149 info.theme_color, | 143 info.theme_color, |
150 info.background_color, | 144 info.background_color, |
151 callback_pointer); | 145 callback_pointer); |
152 } | 146 } |
153 | 147 |
154 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( | 148 void ShortcutHelper::AddShortcutWithSkBitmap( |
155 const ShortcutInfo& info, | 149 const ShortcutInfo& info, |
156 const SkBitmap& icon_bitmap) { | 150 const SkBitmap& icon_bitmap) { |
157 JNIEnv* env = base::android::AttachCurrentThread(); | 151 JNIEnv* env = base::android::AttachCurrentThread(); |
158 ScopedJavaLocalRef<jstring> java_url = | 152 ScopedJavaLocalRef<jstring> java_url = |
159 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 153 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
160 ScopedJavaLocalRef<jstring> java_user_title = | 154 ScopedJavaLocalRef<jstring> java_user_title = |
161 base::android::ConvertUTF16ToJavaString(env, info.user_title); | 155 base::android::ConvertUTF16ToJavaString(env, info.user_title); |
162 ScopedJavaLocalRef<jobject> java_bitmap; | 156 ScopedJavaLocalRef<jobject> java_bitmap; |
163 if (icon_bitmap.getSize()) | 157 if (icon_bitmap.getSize()) |
164 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 158 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 JNIEnv* env = base::android::AttachCurrentThread(); | 282 JNIEnv* env = base::android::AttachCurrentThread(); |
289 ScopedJavaLocalRef<jstring> java_url = | 283 ScopedJavaLocalRef<jstring> java_url = |
290 base::android::ConvertUTF8ToJavaString(env, url.spec()); | 284 base::android::ConvertUTF8ToJavaString(env, url.spec()); |
291 ScopedJavaLocalRef<jstring> java_scope_url = | 285 ScopedJavaLocalRef<jstring> java_scope_url = |
292 Java_ShortcutHelper_getScopeFromUrl(env, java_url.obj()); | 286 Java_ShortcutHelper_getScopeFromUrl(env, java_url.obj()); |
293 return GURL(base::android::ConvertJavaStringToUTF16(env, java_scope_url)); | 287 return GURL(base::android::ConvertJavaStringToUTF16(env, java_scope_url)); |
294 } | 288 } |
295 | 289 |
296 // Callback used by Java when the shortcut has been created. | 290 // Callback used by Java when the shortcut has been created. |
297 // |splash_image_callback| is a pointer to a base::Closure allocated in | 291 // |splash_image_callback| is a pointer to a base::Closure allocated in |
298 // AddShortcutInBackgroundWithSkBitmap, so reinterpret_cast it back and run it. | 292 // AddShortcutWithSkBitmap, so reinterpret_cast it back and run it. |
299 // | 293 // |
300 // This callback should only ever be called when the shortcut was for a | 294 // This callback should only ever be called when the shortcut was for a |
301 // webapp-capable site; otherwise, |splash_image_callback| will have never been | 295 // webapp-capable site; otherwise, |splash_image_callback| will have never been |
302 // allocated and doesn't need to be run or deleted. | 296 // allocated and doesn't need to be run or deleted. |
303 void OnWebappDataStored(JNIEnv* env, | 297 void OnWebappDataStored(JNIEnv* env, |
304 const JavaParamRef<jclass>& clazz, | 298 const JavaParamRef<jclass>& clazz, |
305 jlong jsplash_image_callback) { | 299 jlong jsplash_image_callback) { |
306 DCHECK(jsplash_image_callback); | 300 DCHECK(jsplash_image_callback); |
307 base::Closure* splash_image_callback = | 301 base::Closure* splash_image_callback = |
308 reinterpret_cast<base::Closure*>(jsplash_image_callback); | 302 reinterpret_cast<base::Closure*>(jsplash_image_callback); |
309 splash_image_callback->Run(); | 303 splash_image_callback->Run(); |
310 delete splash_image_callback; | 304 delete splash_image_callback; |
311 } | 305 } |
312 | 306 |
313 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 307 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
314 return RegisterNativesImpl(env); | 308 return RegisterNativesImpl(env); |
315 } | 309 } |
OLD | NEW |