| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 content::BrowserContext* browser_context, | 71 content::BrowserContext* browser_context, |
| 72 const ShortcutInfo& info, | 72 const ShortcutInfo& info, |
| 73 const std::string& webapp_id, | 73 const std::string& webapp_id, |
| 74 const SkBitmap& icon_bitmap, | 74 const SkBitmap& icon_bitmap, |
| 75 const base::Closure& splash_image_callback) { | 75 const base::Closure& splash_image_callback) { |
| 76 if (info.display == blink::WebDisplayModeStandalone || | 76 if (info.display == blink::WebDisplayModeStandalone || |
| 77 info.display == blink::WebDisplayModeFullscreen) { | 77 info.display == blink::WebDisplayModeFullscreen) { |
| 78 AddWebappWithSkBitmap(info, webapp_id, icon_bitmap, splash_image_callback); | 78 AddWebappWithSkBitmap(info, webapp_id, icon_bitmap, splash_image_callback); |
| 79 return; | 79 return; |
| 80 } | 80 } |
| 81 AddShortcutWithSkBitmap(info, icon_bitmap); | 81 AddShortcutWithSkBitmap(info, webapp_id, icon_bitmap); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // static | 84 // static |
| 85 void ShortcutHelper::InstallWebApkWithSkBitmap( | 85 void ShortcutHelper::InstallWebApkWithSkBitmap( |
| 86 content::BrowserContext* browser_context, | 86 content::BrowserContext* browser_context, |
| 87 const ShortcutInfo& info, | 87 const ShortcutInfo& info, |
| 88 const SkBitmap& icon_bitmap, | 88 const SkBitmap& icon_bitmap, |
| 89 const WebApkInstaller::FinishCallback& callback) { | 89 const WebApkInstaller::FinishCallback& callback) { |
| 90 WebApkInstallService::Get(browser_context) | 90 WebApkInstallService::Get(browser_context) |
| 91 ->InstallAsync(info, icon_bitmap, callback); | 91 ->InstallAsync(info, icon_bitmap, callback); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback)); | 126 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback)); |
| 127 | 127 |
| 128 Java_ShortcutHelper_addWebapp( | 128 Java_ShortcutHelper_addWebapp( |
| 129 env, java_webapp_id, java_url, java_scope_url, java_user_title, java_name, | 129 env, java_webapp_id, java_url, java_scope_url, java_user_title, java_name, |
| 130 java_short_name, java_best_primary_icon_url, java_bitmap, info.display, | 130 java_short_name, java_best_primary_icon_url, java_bitmap, info.display, |
| 131 info.orientation, info.source, info.theme_color, info.background_color, | 131 info.orientation, info.source, info.theme_color, info.background_color, |
| 132 callback_pointer); | 132 callback_pointer); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void ShortcutHelper::AddShortcutWithSkBitmap(const ShortcutInfo& info, | 135 void ShortcutHelper::AddShortcutWithSkBitmap(const ShortcutInfo& info, |
| 136 const std::string& id, |
| 136 const SkBitmap& icon_bitmap) { | 137 const SkBitmap& icon_bitmap) { |
| 137 JNIEnv* env = base::android::AttachCurrentThread(); | 138 JNIEnv* env = base::android::AttachCurrentThread(); |
| 139 ScopedJavaLocalRef<jstring> java_id = |
| 140 base::android::ConvertUTF8ToJavaString(env, id); |
| 138 ScopedJavaLocalRef<jstring> java_url = | 141 ScopedJavaLocalRef<jstring> java_url = |
| 139 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 142 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
| 140 ScopedJavaLocalRef<jstring> java_user_title = | 143 ScopedJavaLocalRef<jstring> java_user_title = |
| 141 base::android::ConvertUTF16ToJavaString(env, info.user_title); | 144 base::android::ConvertUTF16ToJavaString(env, info.user_title); |
| 142 ScopedJavaLocalRef<jobject> java_bitmap; | 145 ScopedJavaLocalRef<jobject> java_bitmap; |
| 143 if (icon_bitmap.getSize()) | 146 if (icon_bitmap.getSize()) |
| 144 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 147 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
| 145 | 148 |
| 146 Java_ShortcutHelper_addShortcut(env, java_url, java_user_title, java_bitmap, | 149 Java_ShortcutHelper_addShortcut(env, java_id, java_url, java_user_title, |
| 147 info.source); | 150 java_bitmap, info.source); |
| 148 } | 151 } |
| 149 | 152 |
| 150 void ShortcutHelper::ShowWebApkInstallInProgressToast() { | 153 void ShortcutHelper::ShowWebApkInstallInProgressToast() { |
| 151 Java_ShortcutHelper_showWebApkInstallInProgressToast( | 154 Java_ShortcutHelper_showWebApkInstallInProgressToast( |
| 152 base::android::AttachCurrentThread()); | 155 base::android::AttachCurrentThread()); |
| 153 } | 156 } |
| 154 | 157 |
| 155 int ShortcutHelper::GetIdealHomescreenIconSizeInPx() { | 158 int ShortcutHelper::GetIdealHomescreenIconSizeInPx() { |
| 156 if (g_ideal_homescreen_icon_size == -1) | 159 if (g_ideal_homescreen_icon_size == -1) |
| 157 GetHomescreenIconAndSplashImageSizes(); | 160 GetHomescreenIconAndSplashImageSizes(); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 350 |
| 348 ShortcutHelper::WebApkInfoCallback* webapk_list_callback = | 351 ShortcutHelper::WebApkInfoCallback* webapk_list_callback = |
| 349 reinterpret_cast<ShortcutHelper::WebApkInfoCallback*>(jcallback_pointer); | 352 reinterpret_cast<ShortcutHelper::WebApkInfoCallback*>(jcallback_pointer); |
| 350 webapk_list_callback->Run(webapk_list); | 353 webapk_list_callback->Run(webapk_list); |
| 351 delete webapk_list_callback; | 354 delete webapk_list_callback; |
| 352 } | 355 } |
| 353 | 356 |
| 354 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 357 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| 355 return RegisterNativesImpl(env); | 358 return RegisterNativesImpl(env); |
| 356 } | 359 } |
| OLD | NEW |