| 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" |
| 11 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
| 12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/guid.h" | 15 #include "base/guid.h" |
| 16 #include "base/strings/string16.h" | |
| 17 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
| 19 #include "chrome/browser/android/webapk/chrome_webapk_host.h" | 18 #include "chrome/browser/android/webapk/chrome_webapk_host.h" |
| 20 #include "chrome/browser/android/webapk/webapk_install_service.h" | 19 #include "chrome/browser/android/webapk/webapk_install_service.h" |
| 21 #include "chrome/browser/android/webapk/webapk_metrics.h" | 20 #include "chrome/browser/android/webapk/webapk_metrics.h" |
| 22 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 23 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/manifest_icon_downloader.h" | 23 #include "content/public/browser/manifest_icon_downloader.h" |
| 25 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 26 #include "jni/ShortcutHelper_jni.h" | 25 #include "jni/ShortcutHelper_jni.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 DCHECK(g_minimum_splash_image_size <= g_ideal_splash_image_size); | 65 DCHECK(g_minimum_splash_image_size <= g_ideal_splash_image_size); |
| 67 } | 66 } |
| 68 | 67 |
| 69 // Adds a shortcut which opens in a fullscreen window to the launcher. | 68 // Adds a shortcut which opens in a fullscreen window to the launcher. |
| 70 // |splash_image_callback| will be invoked once the Java-side operation has | 69 // |splash_image_callback| will be invoked once the Java-side operation has |
| 71 // completed. This is necessary as Java will asynchronously create and | 70 // completed. This is necessary as Java will asynchronously create and |
| 72 // populate a WebappDataStorage object for standalone-capable sites. This must | 71 // populate a WebappDataStorage object for standalone-capable sites. This must |
| 73 // exist before the splash image can be stored. | 72 // exist before the splash image can be stored. |
| 74 void AddWebappWithSkBitmap(const ShortcutInfo& info, | 73 void AddWebappWithSkBitmap(const ShortcutInfo& info, |
| 75 const std::string& webapp_id, | 74 const std::string& webapp_id, |
| 75 const base::string16& user_title, |
| 76 const SkBitmap& icon_bitmap, | 76 const SkBitmap& icon_bitmap, |
| 77 const base::Closure& splash_image_callback) { | 77 const base::Closure& splash_image_callback) { |
| 78 // Send the data to the Java side to create the shortcut. | 78 // Send the data to the Java side to create the shortcut. |
| 79 JNIEnv* env = base::android::AttachCurrentThread(); | 79 JNIEnv* env = base::android::AttachCurrentThread(); |
| 80 ScopedJavaLocalRef<jstring> java_webapp_id = | 80 ScopedJavaLocalRef<jstring> java_webapp_id = |
| 81 base::android::ConvertUTF8ToJavaString(env, webapp_id); | 81 base::android::ConvertUTF8ToJavaString(env, webapp_id); |
| 82 ScopedJavaLocalRef<jstring> java_user_title = |
| 83 base::android::ConvertUTF16ToJavaString(env, user_title); |
| 82 ScopedJavaLocalRef<jstring> java_url = | 84 ScopedJavaLocalRef<jstring> java_url = |
| 83 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 85 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
| 84 ScopedJavaLocalRef<jstring> java_scope_url = | 86 ScopedJavaLocalRef<jstring> java_scope_url = |
| 85 base::android::ConvertUTF8ToJavaString(env, info.scope.spec()); | 87 base::android::ConvertUTF8ToJavaString(env, info.scope.spec()); |
| 86 ScopedJavaLocalRef<jstring> java_user_title = | |
| 87 base::android::ConvertUTF16ToJavaString(env, info.user_title); | |
| 88 ScopedJavaLocalRef<jstring> java_name = | 88 ScopedJavaLocalRef<jstring> java_name = |
| 89 base::android::ConvertUTF16ToJavaString(env, info.name); | 89 base::android::ConvertUTF16ToJavaString(env, info.name); |
| 90 ScopedJavaLocalRef<jstring> java_short_name = | 90 ScopedJavaLocalRef<jstring> java_short_name = |
| 91 base::android::ConvertUTF16ToJavaString(env, info.short_name); | 91 base::android::ConvertUTF16ToJavaString(env, info.short_name); |
| 92 ScopedJavaLocalRef<jstring> java_best_primary_icon_url = | 92 ScopedJavaLocalRef<jstring> java_best_primary_icon_url = |
| 93 base::android::ConvertUTF8ToJavaString(env, | 93 base::android::ConvertUTF8ToJavaString(env, |
| 94 info.best_primary_icon_url.spec()); | 94 info.best_primary_icon_url.spec()); |
| 95 ScopedJavaLocalRef<jobject> java_bitmap; | 95 ScopedJavaLocalRef<jobject> java_bitmap; |
| 96 if (!icon_bitmap.drawsNothing()) | 96 if (!icon_bitmap.drawsNothing()) |
| 97 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 97 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
| 98 | 98 |
| 99 // The callback will need to be run after shortcut creation completes in order | 99 // The callback will need to be run after shortcut creation completes in order |
| 100 // to download the splash image and save it to the WebappDataStorage. Create a | 100 // to download the splash image and save it to the WebappDataStorage. Create a |
| 101 // copy of the callback here and send the pointer to Java, which will send it | 101 // copy of the callback here and send the pointer to Java, which will send it |
| 102 // back once the asynchronous shortcut creation process finishes. | 102 // back once the asynchronous shortcut creation process finishes. |
| 103 uintptr_t callback_pointer = | 103 uintptr_t callback_pointer = |
| 104 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback)); | 104 reinterpret_cast<uintptr_t>(new base::Closure(splash_image_callback)); |
| 105 | 105 |
| 106 Java_ShortcutHelper_addWebapp( | 106 Java_ShortcutHelper_addWebapp( |
| 107 env, java_webapp_id, java_url, java_scope_url, java_user_title, java_name, | 107 env, java_webapp_id, java_url, java_scope_url, java_user_title, java_name, |
| 108 java_short_name, java_best_primary_icon_url, java_bitmap, info.display, | 108 java_short_name, java_best_primary_icon_url, java_bitmap, info.display, |
| 109 info.orientation, info.source, info.theme_color, info.background_color, | 109 info.orientation, info.source, info.theme_color, info.background_color, |
| 110 callback_pointer); | 110 callback_pointer); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Adds a shortcut which opens in a browser tab to the launcher. | 113 // Adds a shortcut which opens in a browser tab to the launcher. |
| 114 void AddShortcutWithSkBitmap(const ShortcutInfo& info, | 114 void AddShortcutWithSkBitmap(const ShortcutInfo& info, |
| 115 const std::string& id, | 115 const std::string& id, |
| 116 const base::string16& user_title, |
| 116 const SkBitmap& icon_bitmap) { | 117 const SkBitmap& icon_bitmap) { |
| 117 JNIEnv* env = base::android::AttachCurrentThread(); | 118 JNIEnv* env = base::android::AttachCurrentThread(); |
| 118 ScopedJavaLocalRef<jstring> java_id = | 119 ScopedJavaLocalRef<jstring> java_id = |
| 119 base::android::ConvertUTF8ToJavaString(env, id); | 120 base::android::ConvertUTF8ToJavaString(env, id); |
| 121 ScopedJavaLocalRef<jstring> java_user_title = |
| 122 base::android::ConvertUTF16ToJavaString(env, user_title); |
| 120 ScopedJavaLocalRef<jstring> java_url = | 123 ScopedJavaLocalRef<jstring> java_url = |
| 121 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); | 124 base::android::ConvertUTF8ToJavaString(env, info.url.spec()); |
| 122 ScopedJavaLocalRef<jstring> java_user_title = | |
| 123 base::android::ConvertUTF16ToJavaString(env, info.user_title); | |
| 124 ScopedJavaLocalRef<jobject> java_bitmap; | 125 ScopedJavaLocalRef<jobject> java_bitmap; |
| 125 if (!icon_bitmap.drawsNothing()) | 126 if (!icon_bitmap.drawsNothing()) |
| 126 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 127 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
| 127 | 128 |
| 128 Java_ShortcutHelper_addShortcut(env, java_id, java_url, java_user_title, | 129 Java_ShortcutHelper_addShortcut(env, java_id, java_url, java_user_title, |
| 129 java_bitmap, info.source); | 130 java_bitmap, info.source); |
| 130 } | 131 } |
| 131 | 132 |
| 132 } // anonymous namespace | 133 } // anonymous namespace |
| 133 | 134 |
| 134 // static | 135 // static |
| 135 void ShortcutHelper::AddToLauncherWithSkBitmap( | 136 void ShortcutHelper::AddToLauncherWithSkBitmap( |
| 136 content::WebContents* web_contents, | 137 content::WebContents* web_contents, |
| 137 const ShortcutInfo& info, | 138 const ShortcutInfo& info, |
| 139 const base::string16& user_title, |
| 138 const SkBitmap& icon_bitmap) { | 140 const SkBitmap& icon_bitmap) { |
| 139 std::string webapp_id = base::GenerateGUID(); | 141 std::string webapp_id = base::GenerateGUID(); |
| 140 if (info.display == blink::kWebDisplayModeStandalone || | 142 if (info.display == blink::kWebDisplayModeStandalone || |
| 141 info.display == blink::kWebDisplayModeFullscreen) { | 143 info.display == blink::kWebDisplayModeFullscreen) { |
| 142 AddWebappWithSkBitmap( | 144 AddWebappWithSkBitmap( |
| 143 info, webapp_id, icon_bitmap, | 145 info, webapp_id, user_title, icon_bitmap, |
| 144 base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents, | 146 base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents, |
| 145 info.splash_image_url, info.ideal_splash_image_size_in_px, | 147 info.splash_image_url, info.ideal_splash_image_size_in_px, |
| 146 info.minimum_splash_image_size_in_px, webapp_id)); | 148 info.minimum_splash_image_size_in_px, webapp_id)); |
| 147 GooglePlayInstallState state = | 149 GooglePlayInstallState state = |
| 148 ChromeWebApkHost::GetGooglePlayInstallState(); | 150 ChromeWebApkHost::GetGooglePlayInstallState(); |
| 149 if (state != GooglePlayInstallState::SUPPORTED) | 151 if (state != GooglePlayInstallState::SUPPORTED) |
| 150 webapk::TrackGooglePlayInstallState(state); | 152 webapk::TrackGooglePlayInstallState(state); |
| 151 return; | 153 return; |
| 152 } | 154 } |
| 153 AddShortcutWithSkBitmap(info, webapp_id, icon_bitmap); | 155 AddShortcutWithSkBitmap(info, webapp_id, user_title, icon_bitmap); |
| 154 } | 156 } |
| 155 | 157 |
| 156 // static | 158 // static |
| 157 void ShortcutHelper::InstallWebApkWithSkBitmap( | 159 void ShortcutHelper::InstallWebApkWithSkBitmap( |
| 158 content::WebContents* web_contents, | 160 content::WebContents* web_contents, |
| 159 const ShortcutInfo& info, | 161 const ShortcutInfo& info, |
| 160 const SkBitmap& primary_icon_bitmap, | 162 const SkBitmap& primary_icon_bitmap, |
| 161 const SkBitmap& badge_icon_bitmap, | 163 const SkBitmap& badge_icon_bitmap, |
| 162 const WebApkInstallService::FinishCallback& callback) { | 164 const WebApkInstallService::FinishCallback& callback) { |
| 163 WebApkInstallService::Get(web_contents->GetBrowserContext()) | 165 WebApkInstallService::Get(web_contents->GetBrowserContext()) |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 | 411 |
| 410 ShortcutHelper::WebApkInfoCallback* webapk_list_callback = | 412 ShortcutHelper::WebApkInfoCallback* webapk_list_callback = |
| 411 reinterpret_cast<ShortcutHelper::WebApkInfoCallback*>(jcallback_pointer); | 413 reinterpret_cast<ShortcutHelper::WebApkInfoCallback*>(jcallback_pointer); |
| 412 webapk_list_callback->Run(webapk_list); | 414 webapk_list_callback->Run(webapk_list); |
| 413 delete webapk_list_callback; | 415 delete webapk_list_callback; |
| 414 } | 416 } |
| 415 | 417 |
| 416 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 418 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| 417 return RegisterNativesImpl(env); | 419 return RegisterNativesImpl(env); |
| 418 } | 420 } |
| OLD | NEW |