OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/banners/app_banner_infobar_delegate_android.h" | 5 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/android/shortcut_helper.h" | 14 #include "chrome/browser/android/shortcut_helper.h" |
15 #include "chrome/browser/android/shortcut_info.h" | 15 #include "chrome/browser/android/shortcut_info.h" |
16 #include "chrome/browser/android/tab_android.h" | 16 #include "chrome/browser/android/tab_android.h" |
17 #include "chrome/browser/android/webapk/webapk_installer.h" | 17 #include "chrome/browser/android/webapk/webapk_installer.h" |
18 #include "chrome/browser/android/webapk/webapk_metrics.h" | |
19 #include "chrome/browser/banners/app_banner_manager.h" | 18 #include "chrome/browser/banners/app_banner_manager.h" |
20 #include "chrome/browser/banners/app_banner_metrics.h" | 19 #include "chrome/browser/banners/app_banner_metrics.h" |
21 #include "chrome/browser/banners/app_banner_settings_helper.h" | 20 #include "chrome/browser/banners/app_banner_settings_helper.h" |
22 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/infobars/infobar_service.h" | 22 #include "chrome/browser/infobars/infobar_service.h" |
24 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" | 23 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" |
25 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/render_messages.h" |
26 #include "components/rappor/rappor_utils.h" | 25 #include "components/rappor/rappor_utils.h" |
27 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
28 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
(...skipping 21 matching lines...) Expand all Loading... |
50 | 49 |
51 // static | 50 // static |
52 bool AppBannerInfoBarDelegateAndroid::Create( | 51 bool AppBannerInfoBarDelegateAndroid::Create( |
53 content::WebContents* web_contents, | 52 content::WebContents* web_contents, |
54 base::WeakPtr<AppBannerManager> weak_manager, | 53 base::WeakPtr<AppBannerManager> weak_manager, |
55 const base::string16& app_title, | 54 const base::string16& app_title, |
56 std::unique_ptr<ShortcutInfo> shortcut_info, | 55 std::unique_ptr<ShortcutInfo> shortcut_info, |
57 std::unique_ptr<SkBitmap> icon, | 56 std::unique_ptr<SkBitmap> icon, |
58 int event_request_id, | 57 int event_request_id, |
59 bool is_webapk, | 58 bool is_webapk, |
60 bool start_install_webapk) { | 59 webapk::InstallSource webapk_install_source) { |
61 const GURL& url = shortcut_info->url; | 60 const GURL& url = shortcut_info->url; |
62 auto infobar_delegate = | 61 auto infobar_delegate = |
63 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( | 62 base::WrapUnique(new banners::AppBannerInfoBarDelegateAndroid( |
64 weak_manager, app_title, std::move(shortcut_info), std::move(icon), | 63 weak_manager, app_title, std::move(shortcut_info), std::move(icon), |
65 event_request_id, is_webapk)); | 64 event_request_id, is_webapk, webapk_install_source)); |
66 auto raw_delegate = infobar_delegate.get(); | 65 auto raw_delegate = infobar_delegate.get(); |
67 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( | 66 auto infobar = base::MakeUnique<AppBannerInfoBarAndroid>( |
68 std::move(infobar_delegate), url, is_webapk); | 67 std::move(infobar_delegate), url, is_webapk); |
69 if (!InfoBarService::FromWebContents(web_contents) | 68 if (!InfoBarService::FromWebContents(web_contents) |
70 ->AddInfoBar(std::move(infobar))) | 69 ->AddInfoBar(std::move(infobar))) |
71 return false; | 70 return false; |
72 | 71 |
73 if (is_webapk) { | 72 if (is_webapk) { |
74 if (start_install_webapk) { | 73 if (webapk_install_source == webapk::INSTALL_SOURCE_MENU) { |
75 raw_delegate->AcceptWebApk(web_contents); | 74 raw_delegate->Accept(); |
76 webapk::TrackInstallInfoBarShown(webapk::WEBAPK_INFOBAR_SHOWN_FROM_MENU); | 75 webapk::TrackInstallInfoBarShown(webapk::WEBAPK_INFOBAR_SHOWN_FROM_MENU); |
77 webapk::TrackInstallSource(webapk::INSTALL_SOURCE_MENU); | |
78 } else { | 76 } else { |
79 webapk::TrackInstallInfoBarShown( | 77 webapk::TrackInstallInfoBarShown( |
80 webapk::WEBAPK_INFOBAR_SHOWN_FROM_BANNER); | 78 webapk::WEBAPK_INFOBAR_SHOWN_FROM_BANNER); |
81 } | 79 } |
82 } | 80 } |
83 | 81 |
84 return true; | 82 return true; |
85 } | 83 } |
86 | 84 |
87 // static | 85 // static |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_COMPLETED); | 165 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_COMPLETED); |
168 UpdateInstallState(env, obj); | 166 UpdateInstallState(env, obj); |
169 } else if (infobar()->owner()) { | 167 } else if (infobar()->owner()) { |
170 TrackDismissEvent(DISMISS_EVENT_INSTALL_TIMEOUT); | 168 TrackDismissEvent(DISMISS_EVENT_INSTALL_TIMEOUT); |
171 infobar()->owner()->RemoveInfoBar(infobar()); | 169 infobar()->owner()->RemoveInfoBar(infobar()); |
172 } | 170 } |
173 } | 171 } |
174 | 172 |
175 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( | 173 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( |
176 content::WebContents* web_contents) { | 174 content::WebContents* web_contents) { |
177 has_user_interaction_ = true; | |
178 if (IsInfoEmpty(shortcut_info_)) | 175 if (IsInfoEmpty(shortcut_info_)) |
179 return true; | 176 return true; |
180 | 177 |
181 JNIEnv* env = base::android::AttachCurrentThread(); | 178 JNIEnv* env = base::android::AttachCurrentThread(); |
182 // |webapk_package_name_| is set when the WebAPK has finished installing. | 179 // |webapk_package_name_| is set when the WebAPK has finished installing. |
183 // If the |webapk_package_name_| is empty, it means the "Add to Homescreen" | 180 // If the |webapk_package_name_| is empty, it means the "Add to Homescreen" |
184 // button is pressed, so request WebAPK installation. Otherwise, it means | 181 // button is pressed, so request WebAPK installation. Otherwise, it means |
185 // the "Open" button is pressed, so open the installed WebAPK. | 182 // the "Open" button is pressed, so open the installed WebAPK. |
186 if (!webapk_package_name_.empty()) { | 183 if (!webapk_package_name_.empty()) { |
187 // Open the WebAPK. | 184 // Open the WebAPK. |
188 ScopedJavaLocalRef<jstring> java_webapk_package_name = | 185 ScopedJavaLocalRef<jstring> java_webapk_package_name = |
189 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); | 186 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); |
190 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, | 187 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, |
191 java_webapk_package_name); | 188 java_webapk_package_name); |
192 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); | 189 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); |
193 SendBannerAccepted(web_contents, "web"); | 190 SendBannerAccepted(web_contents, "web"); |
194 return true; | 191 return true; |
195 } | 192 } |
196 | 193 |
197 // Request install the WebAPK. | 194 // Request install the WebAPK. |
198 install_state_ = INSTALLING; | 195 install_state_ = INSTALLING; |
199 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 196 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| 197 webapk::TrackInstallSource(webapk_install_source_); |
200 AppBannerSettingsHelper::RecordBannerInstallEvent( | 198 AppBannerSettingsHelper::RecordBannerInstallEvent( |
201 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 199 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); |
202 | 200 |
203 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | 201 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
204 env, java_delegate_, true); | 202 env, java_delegate_, true); |
205 UpdateInstallState(env, nullptr); | 203 UpdateInstallState(env, nullptr); |
206 WebApkInstaller::FinishCallback callback = | 204 WebApkInstaller::FinishCallback callback = |
207 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, | 205 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, |
208 weak_ptr_factory_.GetWeakPtr()); | 206 weak_ptr_factory_.GetWeakPtr()); |
209 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), | 207 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), |
210 *shortcut_info_, | 208 *shortcut_info_, |
211 *icon_.get(), callback); | 209 *icon_.get(), callback); |
212 SendBannerAccepted(web_contents, "web"); | 210 SendBannerAccepted(web_contents, "web"); |
213 | 211 |
214 // Prevent the infobar from disappearing, because the infobar will show | 212 // Prevent the infobar from disappearing, because the infobar will show |
215 // "Adding" during the installation process. | 213 // "Adding" during the installation process. |
216 return false; | 214 return false; |
217 } | 215 } |
218 | 216 |
219 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 217 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
220 base::WeakPtr<AppBannerManager> weak_manager, | 218 base::WeakPtr<AppBannerManager> weak_manager, |
221 const base::string16& app_title, | 219 const base::string16& app_title, |
222 std::unique_ptr<ShortcutInfo> shortcut_info, | 220 std::unique_ptr<ShortcutInfo> shortcut_info, |
223 std::unique_ptr<SkBitmap> icon, | 221 std::unique_ptr<SkBitmap> icon, |
224 int event_request_id, | 222 int event_request_id, |
225 bool is_webapk) | 223 bool is_webapk, |
| 224 webapk::InstallSource webapk_install_source) |
226 : weak_manager_(weak_manager), | 225 : weak_manager_(weak_manager), |
227 app_title_(app_title), | 226 app_title_(app_title), |
228 shortcut_info_(std::move(shortcut_info)), | 227 shortcut_info_(std::move(shortcut_info)), |
229 icon_(std::move(icon)), | 228 icon_(std::move(icon)), |
230 event_request_id_(event_request_id), | 229 event_request_id_(event_request_id), |
231 has_user_interaction_(false), | 230 has_user_interaction_(false), |
232 is_webapk_(is_webapk), | 231 is_webapk_(is_webapk), |
233 install_state_(INSTALL_NOT_STARTED), | 232 install_state_(INSTALL_NOT_STARTED), |
| 233 webapk_install_source_(webapk_install_source), |
234 weak_ptr_factory_(this) { | 234 weak_ptr_factory_(this) { |
235 DCHECK(!IsInfoEmpty(shortcut_info_)); | 235 DCHECK(!IsInfoEmpty(shortcut_info_)); |
236 CreateJavaDelegate(); | 236 CreateJavaDelegate(); |
237 } | 237 } |
238 | 238 |
239 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 239 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
240 const base::string16& app_title, | 240 const base::string16& app_title, |
241 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 241 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
242 std::unique_ptr<SkBitmap> icon, | 242 std::unique_ptr<SkBitmap> icon, |
243 const std::string& native_app_package, | 243 const std::string& native_app_package, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 content::WebContents* web_contents = | 318 content::WebContents* web_contents = |
319 InfoBarService::WebContentsFromInfoBar(infobar()); | 319 InfoBarService::WebContentsFromInfoBar(infobar()); |
320 if (!web_contents) { | 320 if (!web_contents) { |
321 TrackDismissEvent(DISMISS_EVENT_ERROR); | 321 TrackDismissEvent(DISMISS_EVENT_ERROR); |
322 return true; | 322 return true; |
323 } | 323 } |
324 | 324 |
325 if (!native_app_data_.is_null()) | 325 if (!native_app_data_.is_null()) |
326 return AcceptNativeApp(web_contents); | 326 return AcceptNativeApp(web_contents); |
327 | 327 |
328 if (is_webapk_) { | 328 if (is_webapk_) |
329 webapk::TrackInstallSource(webapk::INSTALL_SOURCE_BANNER); | |
330 return AcceptWebApk(web_contents); | 329 return AcceptWebApk(web_contents); |
331 } | |
332 | 330 |
333 return AcceptWebApp(web_contents); | 331 return AcceptWebApp(web_contents); |
334 } | 332 } |
335 | 333 |
336 bool AppBannerInfoBarDelegateAndroid::AcceptNativeApp( | 334 bool AppBannerInfoBarDelegateAndroid::AcceptNativeApp( |
337 content::WebContents* web_contents) { | 335 content::WebContents* web_contents) { |
338 TrackUserResponse(USER_RESPONSE_NATIVE_APP_ACCEPTED); | 336 TrackUserResponse(USER_RESPONSE_NATIVE_APP_ACCEPTED); |
339 JNIEnv* env = base::android::AttachCurrentThread(); | 337 JNIEnv* env = base::android::AttachCurrentThread(); |
340 | 338 |
341 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | 339 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 431 |
434 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 432 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
435 return true; | 433 return true; |
436 } | 434 } |
437 | 435 |
438 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 436 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
439 return RegisterNativesImpl(env); | 437 return RegisterNativesImpl(env); |
440 } | 438 } |
441 | 439 |
442 } // namespace banners | 440 } // namespace banners |
OLD | NEW |