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 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "chrome/browser/android/webapk/chrome_webapk_host.h" | 17 #include "chrome/browser/android/webapk/chrome_webapk_host.h" |
18 #include "chrome/browser/android/webapk/webapk_installer.h" | |
dominickn
2016/08/25 04:25:56
Don't you still need this header since you're inst
Xi Han
2016/08/26 17:04:17
You are right, add it back.
| |
19 #include "chrome/browser/manifest/manifest_icon_downloader.h" | 18 #include "chrome/browser/manifest/manifest_icon_downloader.h" |
20 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
21 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
23 #include "jni/ShortcutHelper_jni.h" | 22 #include "jni/ShortcutHelper_jni.h" |
24 #include "ui/gfx/android/java_bitmap.h" | 23 #include "ui/gfx/android/java_bitmap.h" |
25 #include "ui/gfx/color_analysis.h" | 24 #include "ui/gfx/color_analysis.h" |
26 #include "url/gurl.h" | 25 #include "url/gurl.h" |
27 | 26 |
28 using base::android::JavaParamRef; | 27 using base::android::JavaParamRef; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 | 65 |
67 // static | 66 // static |
68 void ShortcutHelper::AddToLauncherWithSkBitmap( | 67 void ShortcutHelper::AddToLauncherWithSkBitmap( |
69 content::BrowserContext* browser_context, | 68 content::BrowserContext* browser_context, |
70 const ShortcutInfo& info, | 69 const ShortcutInfo& info, |
71 const std::string& webapp_id, | 70 const std::string& webapp_id, |
72 const SkBitmap& icon_bitmap, | 71 const SkBitmap& icon_bitmap, |
73 const base::Closure& splash_image_callback) { | 72 const base::Closure& splash_image_callback) { |
74 if (info.display == blink::WebDisplayModeStandalone || | 73 if (info.display == blink::WebDisplayModeStandalone || |
75 info.display == blink::WebDisplayModeFullscreen) { | 74 info.display == blink::WebDisplayModeFullscreen) { |
76 if (ChromeWebApkHost::AreWebApkEnabled()) { | |
pkotwicz
2016/08/25 22:23:15
It is worth mentioning in the CL description that
Xi Han
2016/08/26 17:04:17
Done.
| |
77 InstallWebApkWithSkBitmap(browser_context, info, icon_bitmap); | |
78 return; | |
79 } | |
80 AddWebappWithSkBitmap(info, webapp_id, icon_bitmap, splash_image_callback); | 75 AddWebappWithSkBitmap(info, webapp_id, icon_bitmap, splash_image_callback); |
81 return; | 76 return; |
82 } | 77 } |
83 AddShortcutWithSkBitmap(info, icon_bitmap); | 78 AddShortcutWithSkBitmap(info, icon_bitmap); |
84 } | 79 } |
85 | 80 |
86 // static | 81 // static |
87 void ShortcutHelper::InstallWebApkWithSkBitmap( | 82 void ShortcutHelper::InstallWebApkWithSkBitmap( |
88 content::BrowserContext* browser_context, | 83 content::BrowserContext* browser_context, |
89 const ShortcutInfo& info, | 84 const ShortcutInfo& info, |
90 const SkBitmap& icon_bitmap) { | 85 const SkBitmap& icon_bitmap, |
86 const WebApkInstaller::FinishCallback& callback) { | |
91 // WebApkInstaller destroys itself when it is done. | 87 // WebApkInstaller destroys itself when it is done. |
92 WebApkInstaller* installer = new WebApkInstaller(info, icon_bitmap); | 88 WebApkInstaller* installer = new WebApkInstaller(info, icon_bitmap); |
93 installer->InstallAsync(browser_context, | 89 installer->InstallAsync(browser_context, callback); |
94 base::Bind(&ShortcutHelper::OnBuiltWebApk)); | |
95 } | 90 } |
96 | 91 |
97 // static | 92 // static |
98 void ShortcutHelper::AddWebappWithSkBitmap( | 93 void ShortcutHelper::AddWebappWithSkBitmap( |
99 const ShortcutInfo& info, | 94 const ShortcutInfo& info, |
100 const std::string& webapp_id, | 95 const std::string& webapp_id, |
101 const SkBitmap& icon_bitmap, | 96 const SkBitmap& icon_bitmap, |
102 const base::Closure& splash_image_callback) { | 97 const base::Closure& splash_image_callback) { |
103 // Send the data to the Java side to create the shortcut. | 98 // Send the data to the Java side to create the shortcut. |
104 JNIEnv* env = base::android::AttachCurrentThread(); | 99 JNIEnv* env = base::android::AttachCurrentThread(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 ScopedJavaLocalRef<jstring> java_user_title = | 138 ScopedJavaLocalRef<jstring> java_user_title = |
144 base::android::ConvertUTF16ToJavaString(env, info.user_title); | 139 base::android::ConvertUTF16ToJavaString(env, info.user_title); |
145 ScopedJavaLocalRef<jobject> java_bitmap; | 140 ScopedJavaLocalRef<jobject> java_bitmap; |
146 if (icon_bitmap.getSize()) | 141 if (icon_bitmap.getSize()) |
147 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); | 142 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); |
148 | 143 |
149 Java_ShortcutHelper_addShortcut(env, java_url, java_user_title, java_bitmap, | 144 Java_ShortcutHelper_addShortcut(env, java_url, java_user_title, java_bitmap, |
150 info.source); | 145 info.source); |
151 } | 146 } |
152 | 147 |
153 void ShortcutHelper::OnBuiltWebApk(bool success) { | |
154 if (success) { | |
155 DVLOG(1) << "Sent request to install WebAPK. Seems to have worked."; | |
156 } else { | |
157 LOG(ERROR) << "WebAPK install failed."; | |
158 } | |
159 // TODO(pkotwicz): Figure out what to do when installing WebAPK fails. | |
160 // (crbug.com/626950) | |
161 } | |
162 | |
163 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { | 148 int ShortcutHelper::GetIdealHomescreenIconSizeInDp() { |
164 if (kIdealHomescreenIconSize == -1) | 149 if (kIdealHomescreenIconSize == -1) |
165 GetHomescreenIconAndSplashImageSizes(); | 150 GetHomescreenIconAndSplashImageSizes(); |
166 return kIdealHomescreenIconSize; | 151 return kIdealHomescreenIconSize; |
167 } | 152 } |
168 | 153 |
169 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { | 154 int ShortcutHelper::GetMinimumHomescreenIconSizeInDp() { |
170 if (kMinimumHomescreenIconSize == -1) | 155 if (kMinimumHomescreenIconSize == -1) |
171 GetHomescreenIconAndSplashImageSizes(); | 156 GetHomescreenIconAndSplashImageSizes(); |
172 return kMinimumHomescreenIconSize; | 157 return kMinimumHomescreenIconSize; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 DCHECK(jsplash_image_callback); | 272 DCHECK(jsplash_image_callback); |
288 base::Closure* splash_image_callback = | 273 base::Closure* splash_image_callback = |
289 reinterpret_cast<base::Closure*>(jsplash_image_callback); | 274 reinterpret_cast<base::Closure*>(jsplash_image_callback); |
290 splash_image_callback->Run(); | 275 splash_image_callback->Run(); |
291 delete splash_image_callback; | 276 delete splash_image_callback; |
292 } | 277 } |
293 | 278 |
294 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 279 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
295 return RegisterNativesImpl(env); | 280 return RegisterNativesImpl(env); |
296 } | 281 } |
OLD | NEW |