OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/android/webapk/webapk_update_manager.h" |
| 6 |
| 7 #include <jni.h> |
| 8 |
| 9 #include "base/android/jni_string.h" |
| 10 #include "base/bind.h" |
| 11 #include "chrome/browser/android/webapk/webapk_installer.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "jni/WebApkUpdateManager_jni.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/gfx/android/java_bitmap.h" |
| 18 #include "url/gurl.h" |
| 19 |
| 20 using base::android::JavaParamRef; |
| 21 |
| 22 // static |
| 23 bool WebApkUpdateManager::Register(JNIEnv* env) { |
| 24 return RegisterNativesImpl(env); |
| 25 } |
| 26 |
| 27 // static |
| 28 void WebApkUpdateManager::OnBuiltWebApk(const std::string& webapk_package, |
| 29 bool success) { |
| 30 JNIEnv* env = base::android::AttachCurrentThread(); |
| 31 |
| 32 if (success) { |
| 33 DVLOG(1) |
| 34 << "Sent request to update WebAPK to server. Seems to have worked."; |
| 35 } else { |
| 36 LOG(WARNING) << "Server request to update WebAPK failed."; |
| 37 } |
| 38 |
| 39 base::android::ScopedJavaLocalRef<jstring> java_webapk_package = |
| 40 base::android::ConvertUTF8ToJavaString(env, webapk_package); |
| 41 Java_WebApkUpdateManager_onBuiltWebApk(env, success, |
| 42 java_webapk_package.obj()); |
| 43 } |
| 44 |
| 45 // static JNI method. |
| 46 static void UpdateAsync(JNIEnv* env, |
| 47 const JavaParamRef<jclass>& clazz, |
| 48 const JavaParamRef<jstring>& java_start_url, |
| 49 const JavaParamRef<jstring>& java_scope, |
| 50 const JavaParamRef<jstring>& java_name, |
| 51 const JavaParamRef<jstring>& java_short_name, |
| 52 const JavaParamRef<jstring>& java_icon_url, |
| 53 const JavaParamRef<jobject>& java_icon_bitmap, |
| 54 jint java_display_mode, |
| 55 jint java_orientation, |
| 56 jlong java_theme_color, |
| 57 jlong java_background_color, |
| 58 const JavaParamRef<jstring>& java_web_manifest_url, |
| 59 const JavaParamRef<jstring>& java_webapk_package, |
| 60 jint java_webapk_version) { |
| 61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 62 |
| 63 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 64 if (profile == nullptr) { |
| 65 NOTREACHED() << "Profile not found."; |
| 66 return; |
| 67 } |
| 68 |
| 69 GURL start_url(ConvertJavaStringToUTF8(env, java_start_url)); |
| 70 GURL scope(ConvertJavaStringToUTF8(env, java_scope)); |
| 71 GURL web_manifest_url(ConvertJavaStringToUTF8(env, java_web_manifest_url)); |
| 72 GURL icon_url(ConvertJavaStringToUTF8(env, java_icon_url)); |
| 73 ShortcutInfo info(start_url); |
| 74 info.scope = scope; |
| 75 info.name = ConvertJavaStringToUTF16(env, java_name); |
| 76 info.short_name = ConvertJavaStringToUTF16(env, java_short_name); |
| 77 info.display = static_cast<blink::WebDisplayMode>(java_display_mode); |
| 78 info.orientation = |
| 79 static_cast<blink::WebScreenOrientationLockType>(java_orientation); |
| 80 info.theme_color = (long)java_theme_color; |
| 81 info.background_color = (long)java_background_color; |
| 82 info.icon_url = icon_url; |
| 83 info.manifest_url = web_manifest_url; |
| 84 |
| 85 gfx::JavaBitmap java_bitmap_lock(java_icon_bitmap); |
| 86 SkBitmap icon_bitmap = gfx::CreateSkBitmapFromJavaBitmap(java_bitmap_lock); |
| 87 icon_bitmap.setImmutable(); |
| 88 |
| 89 std::string webapk_package; |
| 90 ConvertJavaStringToUTF8(env, java_webapk_package, &webapk_package); |
| 91 |
| 92 WebApkInstaller* installer = new WebApkInstaller(info, icon_bitmap); |
| 93 installer->UpdateAsync( |
| 94 profile, |
| 95 base::Bind(&WebApkUpdateManager::OnBuiltWebApk, webapk_package), |
| 96 webapk_package, java_webapk_version); |
| 97 } |
OLD | NEW |