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_android.h" | |
14 #include "content/public/browser/browser_context.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 // static | |
21 bool WebApkUpdateManager::Register(JNIEnv* env) { | |
22 return RegisterNativesImpl(env); | |
23 } | |
24 | |
25 // static | |
26 void WebApkUpdateManager::OnBuiltWebApk(bool success, | |
27 const std::string& webapk_package) { | |
28 JNIEnv* env = base::android::AttachCurrentThread(); | |
29 | |
30 if (success) { | |
31 LOG(WARNING) | |
32 << "Sent request to update WebAPK to server. Seems to have worked."; | |
33 } else { | |
34 LOG(WARNING) << "Server request to update WebAPK failed."; | |
35 } | |
36 | |
37 ScopedJavaLocalRef<jstring> java_webapk_package = | |
38 base::android::ConvertUTF8ToJavaString(env, webapk_package); | |
39 Java_WebApkUpdateManager_onBuiltWebApk( | |
40 env, success, java_webapk_package.obj()); | |
41 } | |
42 | |
43 // static JNI method. | |
44 static void UpdateAsync( | |
45 JNIEnv* env, | |
46 const JavaParamRef<jclass>& clazz, | |
47 const JavaParamRef<jobject>& java_profile, | |
48 const JavaParamRef<jstring>& java_webapk_package, | |
49 const JavaParamRef<jstring>& java_url, | |
50 const JavaParamRef<jstring>& java_scope, | |
51 const JavaParamRef<jstring>& java_name, | |
52 const JavaParamRef<jstring>& java_short_name, | |
53 jint java_display_mode, | |
54 jint java_orientation, | |
55 jlong java_theme_color, | |
56 jlong java_background_color, | |
57 const JavaParamRef<jstring>& java_web_manifest_url, | |
58 const JavaParamRef<jstring>& java_icon_url, | |
59 const JavaParamRef<jobject>& java_icon_bitmap) { | |
60 Profile* profile = ProfileAndroid::FromProfileAndroid(java_profile); | |
61 | |
62 GURL url(ConvertJavaStringToUTF8(env, java_url)); | |
63 GURL scope(ConvertJavaStringToUTF8(env, java_scope)); | |
64 GURL web_manifest_url(ConvertJavaStringToUTF8(env, java_web_manifest_url)); | |
65 GURL icon_url(ConvertJavaStringToUTF8(env, java_icon_url)); | |
66 ShortcutInfo info(url); | |
67 info.scope = scope; | |
68 info.name = ConvertJavaStringToUTF16(env, java_name); | |
69 info.short_name = ConvertJavaStringToUTF16(env, java_short_name); | |
70 info.display = (blink::WebDisplayMode) java_display_mode; | |
71 info.orientation = (blink::WebScreenOrientationLockType) java_orientation; | |
72 info.theme_color = (long) java_theme_color; | |
73 info.background_color = (long) java_background_color; | |
74 info.icon_url = icon_url; | |
75 | |
76 gfx::JavaBitmap java_bitmap_lock(java_icon_bitmap); | |
77 SkBitmap icon_bitmap = gfx::CreateSkBitmapFromJavaBitmap(java_bitmap_lock); | |
78 icon_bitmap.setImmutable(); | |
79 | |
80 std::string webapk_package; | |
81 ConvertJavaStringToUTF8(env, java_webapk_package, &webapk_package); | |
82 | |
83 WebApkInstaller* installer = new WebApkInstaller( | |
84 static_cast<content::BrowserContext*>(profile), info, | |
85 icon_bitmap, webapk_package); | |
86 installer->UpdateAsync(base::Bind(&WebApkUpdateManager::OnBuiltWebApk)); | |
pkotwicz
2016/08/03 01:07:06
Does WebApkInstaller::FinishCallback need to pass
Xi Han
2016/08/03 17:30:05
Yes, we could, updated.
| |
87 } | |
OLD | NEW |