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" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "ui/gfx/android/java_bitmap.h" | 31 #include "ui/gfx/android/java_bitmap.h" |
32 #include "url/gurl.h" | 32 #include "url/gurl.h" |
33 | 33 |
34 using base::android::ConvertJavaStringToUTF8; | 34 using base::android::ConvertJavaStringToUTF8; |
35 using base::android::ConvertJavaStringToUTF16; | 35 using base::android::ConvertJavaStringToUTF16; |
36 using base::android::ConvertUTF8ToJavaString; | 36 using base::android::ConvertUTF8ToJavaString; |
37 using base::android::ConvertUTF16ToJavaString; | 37 using base::android::ConvertUTF16ToJavaString; |
38 using base::android::JavaParamRef; | 38 using base::android::JavaParamRef; |
39 using base::android::ScopedJavaLocalRef; | 39 using base::android::ScopedJavaLocalRef; |
40 | 40 |
41 // TODO(zpeng): Reorganize control flow to allow itemized metrics. | |
dominickn
2016/09/28 02:10:25
Nit: don't have a TODO without a crbug link.
F
2016/09/30 18:02:01
Done. Thanks for the information!
| |
42 | |
41 namespace { | 43 namespace { |
42 | 44 |
43 bool IsInfoEmpty(const std::unique_ptr<ShortcutInfo>& info) { | 45 bool IsInfoEmpty(const std::unique_ptr<ShortcutInfo>& info) { |
44 return !info || info->url.is_empty(); | 46 return !info || info->url.is_empty(); |
45 } | 47 } |
46 | 48 |
47 } // anonymous namespace | 49 } // anonymous namespace |
48 | 50 |
49 namespace banners { | 51 namespace banners { |
50 | 52 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 // Open the WebAPK. | 189 // Open the WebAPK. |
188 ScopedJavaLocalRef<jstring> java_webapk_package_name = | 190 ScopedJavaLocalRef<jstring> java_webapk_package_name = |
189 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); | 191 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); |
190 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, | 192 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_, |
191 java_webapk_package_name); | 193 java_webapk_package_name); |
192 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); | 194 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); |
193 SendBannerAccepted(web_contents, "web"); | 195 SendBannerAccepted(web_contents, "web"); |
194 return true; | 196 return true; |
195 } | 197 } |
196 | 198 |
197 // Request install the WebAPK. | 199 // Check whether the WebAPK has been installed. |
198 install_state_ = INSTALLING; | 200 std::string installed_webapk_package_name = |
199 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 201 ShortcutHelper::QueryWebApkPackage(web_contents->GetLastCommittedURL()); |
200 AppBannerSettingsHelper::RecordBannerInstallEvent( | 202 if (installed_webapk_package_name.empty()) { |
201 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | 203 // Request install the WebAPK. |
204 install_state_ = INSTALLING; | |
205 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | |
206 AppBannerSettingsHelper::RecordBannerInstallEvent( | |
207 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); | |
202 | 208 |
203 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | 209 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
204 env, java_delegate_, true); | 210 env, java_delegate_, true); |
205 UpdateInstallState(env, nullptr); | 211 UpdateInstallState(env, nullptr); |
206 WebApkInstaller::FinishCallback callback = | 212 WebApkInstaller::FinishCallback callback = |
207 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, | 213 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, |
208 weak_ptr_factory_.GetWeakPtr()); | 214 weak_ptr_factory_.GetWeakPtr()); |
209 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), | 215 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), |
210 *shortcut_info_, | 216 *shortcut_info_, |
211 *icon_.get(), callback); | 217 *icon_.get(), callback); |
212 SendBannerAccepted(web_contents, "web"); | 218 SendBannerAccepted(web_contents, "web"); |
213 | 219 |
214 // Prevent the infobar from disappearing, because the infobar will show | 220 // Prevent the infobar from disappearing, because the infobar will show |
215 // "Adding" during the installation process. | 221 // "Adding" during the installation process. |
216 return false; | 222 return false; |
223 } else { | |
dominickn
2016/09/28 02:10:25
Nit: remove the else clause (no else after return)
F
2016/09/30 18:02:01
Done. Thanks for the information!
| |
224 // Bypass the installation process. | |
225 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | |
pkotwicz
2016/09/29 14:18:54
Shouldn't you log:
webapk::TrackUserAction(webapk:
F
2016/09/30 18:02:01
Resolved in offline discussion. Filed new issue ht
| |
226 weak_ptr_factory_.GetWeakPtr()->OnWebApkInstallFinished( | |
227 true, installed_webapk_package_name); | |
pkotwicz
2016/09/29 14:18:54
Calling AppBannerInfoBarDelegateAndroid::OnWebApkI
F
2016/09/30 18:02:01
Resolved in offline discussion. See above.
| |
228 return false; | |
229 } | |
217 } | 230 } |
218 | 231 |
219 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 232 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
220 base::WeakPtr<AppBannerManager> weak_manager, | 233 base::WeakPtr<AppBannerManager> weak_manager, |
221 const base::string16& app_title, | 234 const base::string16& app_title, |
222 std::unique_ptr<ShortcutInfo> shortcut_info, | 235 std::unique_ptr<ShortcutInfo> shortcut_info, |
223 std::unique_ptr<SkBitmap> icon, | 236 std::unique_ptr<SkBitmap> icon, |
224 int event_request_id, | 237 int event_request_id, |
225 bool is_webapk) | 238 bool is_webapk) |
226 : weak_manager_(weak_manager), | 239 : weak_manager_(weak_manager), |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 void AppBannerInfoBarDelegateAndroid::TrackWebApkInstallationDismissEvents( | 418 void AppBannerInfoBarDelegateAndroid::TrackWebApkInstallationDismissEvents( |
406 InstallState install_state) { | 419 InstallState install_state) { |
407 if (install_state == INSTALL_NOT_STARTED) { | 420 if (install_state == INSTALL_NOT_STARTED) { |
408 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_BEFORE_INSTALLATION); | 421 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_BEFORE_INSTALLATION); |
409 } else if (install_state == INSTALLING) { | 422 } else if (install_state == INSTALLING) { |
410 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_DURING_INSTALLATION); | 423 webapk::TrackInstallEvent(webapk::INFOBAR_DISMISSED_DURING_INSTALLATION); |
411 } else if (install_state == INSTALLED) { | 424 } else if (install_state == INSTALLED) { |
412 // When |install_state| is INSTALLED, the install Event will be recorded in | 425 // When |install_state| is INSTALLED, the install Event will be recorded in |
413 // OnWebApkInstallFinished(). | 426 // OnWebApkInstallFinished(). |
414 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN_DISMISS); | 427 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN_DISMISS); |
415 } | 428 } |
pkotwicz
2016/09/29 14:18:54
According to the TODO in https://cs.chromium.org/c
F
2016/09/30 18:02:01
Resolved in offline discussion. See above.
| |
416 } | 429 } |
417 | 430 |
418 bool AppBannerInfoBarDelegateAndroid::LinkClicked( | 431 bool AppBannerInfoBarDelegateAndroid::LinkClicked( |
419 WindowOpenDisposition disposition) { | 432 WindowOpenDisposition disposition) { |
420 if (native_app_data_.is_null()) | 433 if (native_app_data_.is_null()) |
421 return false; | 434 return false; |
422 | 435 |
423 // Try to show the details for the native app. | 436 // Try to show the details for the native app. |
424 JNIEnv* env = base::android::AttachCurrentThread(); | 437 JNIEnv* env = base::android::AttachCurrentThread(); |
425 | 438 |
426 content::WebContents* web_contents = | 439 content::WebContents* web_contents = |
427 InfoBarService::WebContentsFromInfoBar(infobar()); | 440 InfoBarService::WebContentsFromInfoBar(infobar()); |
428 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | 441 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
429 DCHECK(tab); | 442 DCHECK(tab); |
430 | 443 |
431 Java_AppBannerInfoBarDelegateAndroid_showAppDetails( | 444 Java_AppBannerInfoBarDelegateAndroid_showAppDetails( |
432 env, java_delegate_, tab->GetJavaObject(), native_app_data_); | 445 env, java_delegate_, tab->GetJavaObject(), native_app_data_); |
433 | 446 |
434 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 447 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
435 return true; | 448 return true; |
436 } | 449 } |
437 | 450 |
438 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 451 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
439 return RegisterNativesImpl(env); | 452 return RegisterNativesImpl(env); |
440 } | 453 } |
441 | 454 |
442 } // namespace banners | 455 } // namespace banners |
OLD | NEW |