| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 // static | 66 // static |
| 67 void ShortcutHelper::AddToLauncherWithSkBitmap( | 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 if (info.display == blink::WebDisplayModeStandalone || | 73 if (info.display == blink::WebDisplayModeStandalone || |
| 74 info.display == blink::WebDisplayModeFullscreen) { | 74 info.display == blink::WebDisplayModeFullscreen) { |
| 75 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 76 if (Java_ShortcutHelper_areWebApksEnabled(env)) { | |
| 77 InstallWebApkWithSkBitmap(browser_context, info, icon_bitmap); | |
| 78 return; | |
| 79 } | |
| 80 AddWebappWithSkBitmap(info, webapp_id, icon_bitmap, splash_image_callback); | 75 AddWebappWithSkBitmap(info, webapp_id, icon_bitmap, splash_image_callback); |
| 81 return; | 76 return; |
| 82 } | 77 } |
| 83 AddShortcutWithSkBitmap(info, icon_bitmap); | 78 AddShortcutWithSkBitmap(info, icon_bitmap); |
| 84 } | 79 } |
| 85 | 80 |
| 86 // static | 81 // static |
| 87 void ShortcutHelper::InstallWebApkWithSkBitmap( | 82 void ShortcutHelper::InstallWebApkWithSkBitmap( |
| 88 content::BrowserContext* browser_context, | 83 content::BrowserContext* browser_context, |
| 89 const ShortcutInfo& info, | 84 const ShortcutInfo& info, |
| 90 const SkBitmap& icon_bitmap) { | 85 const SkBitmap& icon_bitmap, |
| 86 const WebApkPackageNameAvailableCallback& callback) { |
| 91 // WebApkInstaller destroys itself when it is done. | 87 // WebApkInstaller destroys itself when it is done. |
| 92 WebApkInstaller* installer = new WebApkInstaller(info, icon_bitmap); | 88 WebApkInstaller* installer = new WebApkInstaller(info, icon_bitmap); |
| 93 installer->InstallAsync(browser_context, | 89 installer->InstallAsync(browser_context, callback, |
| 94 base::Bind(&ShortcutHelper::OnBuiltWebApk)); | 90 base::Bind(&ShortcutHelper::OnBuiltWebApk)); |
| 95 } | 91 } |
| 96 | 92 |
| 97 // static | 93 // static |
| 98 void ShortcutHelper::AddWebappWithSkBitmap( | 94 void ShortcutHelper::AddWebappWithSkBitmap( |
| 99 const ShortcutInfo& info, | 95 const ShortcutInfo& info, |
| 100 const std::string& webapp_id, | 96 const std::string& webapp_id, |
| 101 const SkBitmap& icon_bitmap, | 97 const SkBitmap& icon_bitmap, |
| 102 const base::Closure& splash_image_callback) { | 98 const base::Closure& splash_image_callback) { |
| 103 // Send the data to the Java side to create the shortcut. | 99 // Send the data to the Java side to create the shortcut. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 DCHECK(jsplash_image_callback); | 283 DCHECK(jsplash_image_callback); |
| 288 base::Closure* splash_image_callback = | 284 base::Closure* splash_image_callback = |
| 289 reinterpret_cast<base::Closure*>(jsplash_image_callback); | 285 reinterpret_cast<base::Closure*>(jsplash_image_callback); |
| 290 splash_image_callback->Run(); | 286 splash_image_callback->Run(); |
| 291 delete splash_image_callback; | 287 delete splash_image_callback; |
| 292 } | 288 } |
| 293 | 289 |
| 294 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 290 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| 295 return RegisterNativesImpl(env); | 291 return RegisterNativesImpl(env); |
| 296 } | 292 } |
| OLD | NEW |