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_context.h" | |
15 #include "content/public/browser/browser_thread.h" | |
16 #include "jni/WebApkUpdateManager_jni.h" | |
17 #include "third_party/skia/include/core/SkBitmap.h" | |
18 #include "ui/gfx/android/java_bitmap.h" | |
19 #include "url/gurl.h" | |
20 | |
21 using base::android::JavaParamRef; | |
22 | |
23 // static | |
24 bool WebApkUpdateManager::Register(JNIEnv* env) { | |
25 return RegisterNativesImpl(env); | |
26 } | |
27 | |
28 // static | |
29 void WebApkUpdateManager::OnBuiltWebApk(const std::string& webapk_package, | |
30 bool success) { | |
31 JNIEnv* env = base::android::AttachCurrentThread(); | |
32 | |
33 if (success) { | |
34 DVLOG(1) | |
35 << "Sent request to update WebAPK to server. Seems to have worked."; | |
36 } else { | |
37 LOG(WARNING) << "Server request to update WebAPK failed."; | |
38 } | |
39 | |
40 base::android::ScopedJavaLocalRef<jstring> java_webapk_package = | |
41 base::android::ConvertUTF8ToJavaString(env, webapk_package); | |
42 Java_WebApkUpdateManager_onBuiltWebApk(env, success, | |
43 java_webapk_package.obj()); | |
44 } | |
45 | |
46 // static JNI method. | |
47 static void UpdateAsync(JNIEnv* env, | |
48 const JavaParamRef<jclass>& clazz, | |
49 const JavaParamRef<jstring>& java_start_url, | |
50 const JavaParamRef<jstring>& java_scope, | |
51 const JavaParamRef<jstring>& java_name, | |
52 const JavaParamRef<jstring>& java_short_name, | |
53 const JavaParamRef<jstring>& java_icon_url, | |
54 const JavaParamRef<jobject>& java_icon_bitmap, | |
55 jint java_display_mode, | |
56 jint java_orientation, | |
57 jlong java_theme_color, | |
58 jlong java_background_color, | |
59 const JavaParamRef<jstring>& java_web_manifest_url, | |
60 const JavaParamRef<jstring>& java_webapk_package, | |
61 jint java_webapk_version) { | |
62 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
pkotwicz
2016/08/11 22:02:45
Nit: I don't think that the DCHECK is useful (ever
Xi Han
2016/08/15 21:38:46
I would prefer to keep it since ProfileManager::Ge
| |
63 | |
64 GURL start_url(ConvertJavaStringToUTF8(env, java_start_url)); | |
65 GURL scope(ConvertJavaStringToUTF8(env, java_scope)); | |
66 GURL web_manifest_url(ConvertJavaStringToUTF8(env, java_web_manifest_url)); | |
67 GURL icon_url(ConvertJavaStringToUTF8(env, java_icon_url)); | |
68 ShortcutInfo info(start_url); | |
69 info.scope = scope; | |
70 info.name = ConvertJavaStringToUTF16(env, java_name); | |
71 info.short_name = ConvertJavaStringToUTF16(env, java_short_name); | |
72 info.display = static_cast<blink::WebDisplayMode>(java_display_mode); | |
73 info.orientation = | |
74 static_cast<blink::WebScreenOrientationLockType>(java_orientation); | |
75 info.theme_color = (long)java_theme_color; | |
76 info.background_color = (long)java_background_color; | |
77 info.icon_url = icon_url; | |
78 info.manifest_url = web_manifest_url; | |
79 | |
80 gfx::JavaBitmap java_bitmap_lock(java_icon_bitmap); | |
81 SkBitmap icon_bitmap = gfx::CreateSkBitmapFromJavaBitmap(java_bitmap_lock); | |
82 icon_bitmap.setImmutable(); | |
83 | |
84 std::string webapk_package; | |
85 ConvertJavaStringToUTF8(env, java_webapk_package, &webapk_package); | |
86 | |
87 Profile* profile = ProfileManager::GetLastUsedProfile(); | |
88 if (profile == nullptr) { | |
Yaron
2016/08/12 21:16:17
nit: you should do early-outs (precontions) first
Xi Han
2016/08/15 21:38:45
Done.
| |
89 NOTREACHED() << "Profile not found."; | |
90 return; | |
91 } | |
92 | |
93 WebApkInstaller* installer = new WebApkInstaller(info, icon_bitmap); | |
94 installer->UpdateAsync( | |
95 static_cast<content::BrowserContext*>(profile), | |
pkotwicz
2016/08/11 22:02:45
Is the static_cast necessary?
Xi Han
2016/08/15 21:38:46
It seems it isn't anymore. I am sure it is needed
| |
96 base::Bind(&WebApkUpdateManager::OnBuiltWebApk, webapk_package), | |
97 webapk_package, java_webapk_version); | |
98 } | |
OLD | NEW |