Chromium Code Reviews| Index: chrome/browser/android/banners/app_banner_infobar_delegate_android.cc |
| diff --git a/chrome/browser/android/banners/app_banner_infobar_delegate_android.cc b/chrome/browser/android/banners/app_banner_infobar_delegate_android.cc |
| index 1e2e973cbef929860fbd4ce586fd014ffe1bb2ee..93a4913f60ee1d92b80269243168c8cb04fbf943 100644 |
| --- a/chrome/browser/android/banners/app_banner_infobar_delegate_android.cc |
| +++ b/chrome/browser/android/banners/app_banner_infobar_delegate_android.cc |
| @@ -37,28 +37,32 @@ using base::android::ConvertUTF16ToJavaString; |
| using base::android::JavaParamRef; |
| using base::android::ScopedJavaLocalRef; |
| +namespace { |
| + |
| +bool IsInfoEmpty(const ShortcutInfo* info) { |
| + return !info || info->url.is_empty(); |
| +} |
| + |
| +} // anonymous namespace |
| + |
| namespace banners { |
| AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| base::WeakPtr<AppBannerManager> weak_manager, |
| const base::string16& app_title, |
| - const GURL& manifest_url, |
| - const content::Manifest& manifest, |
| - const GURL& icon_url, |
| + std::unique_ptr<ShortcutInfo> shortcut_info, |
| std::unique_ptr<SkBitmap> icon, |
| int event_request_id, |
| bool is_webapk) |
| : weak_manager_(weak_manager), |
| app_title_(app_title), |
| - manifest_url_(manifest_url), |
| - manifest_(manifest), |
| - icon_url_(icon_url), |
| + shortcut_info_(std::move(shortcut_info)), |
| icon_(std::move(icon)), |
| event_request_id_(event_request_id), |
| has_user_interaction_(false), |
| is_webapk_(is_webapk), |
| weak_ptr_factory_(this) { |
| - DCHECK(!manifest.IsEmpty()); |
| + DCHECK(!IsInfoEmpty(shortcut_info_.get())); |
| CreateJavaDelegate(); |
| } |
| @@ -87,7 +91,7 @@ AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { |
| if (!has_user_interaction_) { |
| if (!native_app_data_.is_null()) |
| TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); |
| - else if (!manifest_.IsEmpty()) |
| + else if (!IsInfoEmpty(shortcut_info_.get())) |
| TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); |
| } |
| @@ -154,6 +158,16 @@ void AppBannerInfoBarDelegateAndroid::OnInstallFinished( |
| } |
| } |
| +void AppBannerInfoBarDelegateAndroid::InstallWebApk( |
|
Peter Kasting
2016/09/06 19:31:23
Nit: This function just wraps AcceptWebApk(). Mak
Xi Han
2016/09/07 15:53:17
Done.
|
| + content::WebContents* web_contents) { |
| + if (!web_contents) { |
|
Peter Kasting
2016/09/06 19:31:23
Will callers ever pass you null? If not, do nothi
Xi Han
2016/09/07 15:53:17
Move the extra logic to the callers.
|
| + LOG(ERROR) << "Failed to create infobar to install the WebAPK: " |
| + << "the associated WebContents is null."; |
| + return; |
| + } |
| + AcceptWebApk(web_contents); |
| +} |
| + |
| void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() { |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| java_delegate_.Reset(Java_AppBannerInfoBarDelegateAndroid_create( |
| @@ -197,10 +211,10 @@ void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { |
| TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); |
| AppBannerSettingsHelper::RecordBannerDismissEvent( |
| web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE); |
| - } else if (!manifest_.IsEmpty()) { |
| + } else if (!IsInfoEmpty(shortcut_info_.get())) { |
| TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); |
| AppBannerSettingsHelper::RecordBannerDismissEvent( |
| - web_contents, manifest_.start_url.spec(), |
| + web_contents, shortcut_info_->url.spec(), |
| AppBannerSettingsHelper::WEB); |
| } |
| } |
| @@ -260,24 +274,19 @@ bool AppBannerInfoBarDelegateAndroid::AcceptNativeApp( |
| bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( |
| content::WebContents* web_contents) { |
| - if (manifest_.IsEmpty()) |
| + if (IsInfoEmpty(shortcut_info_.get())) |
| return true; |
| TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| AppBannerSettingsHelper::RecordBannerInstallEvent( |
| - web_contents, manifest_.start_url.spec(), |
| + web_contents, shortcut_info_->url.spec(), |
| AppBannerSettingsHelper::WEB); |
| if (weak_manager_) { |
| - ShortcutInfo info(GURL::EmptyGURL()); |
| - info.UpdateFromManifest(manifest_); |
| - info.manifest_url = manifest_url_; |
| - info.icon_url = icon_url_; |
| - info.UpdateSource(ShortcutInfo::SOURCE_APP_BANNER); |
| - |
| const std::string& uid = base::GenerateGUID(); |
| ShortcutHelper::AddToLauncherWithSkBitmap( |
| - web_contents->GetBrowserContext(), info, uid, *icon_.get(), |
| + web_contents->GetBrowserContext(), |
| + *shortcut_info_.get(), uid, *icon_.get(), |
| weak_manager_->FetchWebappSplashScreenImageCallback(uid)); |
| } |
| @@ -287,7 +296,7 @@ bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( |
| bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( |
| content::WebContents* web_contents) { |
| - if (manifest_.IsEmpty()) |
| + if (IsInfoEmpty(shortcut_info_.get())) |
| return true; |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| @@ -300,15 +309,9 @@ bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( |
| TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); |
| AppBannerSettingsHelper::RecordBannerInstallEvent( |
| - web_contents, manifest_.start_url.spec(), |
| + web_contents, shortcut_info_->url.spec(), |
| AppBannerSettingsHelper::WEB); |
| - ShortcutInfo info(GURL::EmptyGURL()); |
| - info.UpdateFromManifest(manifest_); |
| - info.manifest_url = manifest_url_; |
| - info.icon_url = icon_url_; |
| - info.UpdateSource(ShortcutInfo::SOURCE_APP_BANNER); |
| - |
| Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
| env, java_delegate_, true); |
| UpdateInstallState(env, nullptr); |
| @@ -318,7 +321,8 @@ bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( |
| weak_ptr_factory_.GetWeakPtr()); |
| DVLOG(1) << "Trigger the installation of the WebAPK."; |
| ShortcutHelper::InstallWebApkWithSkBitmap( |
| - web_contents->GetBrowserContext(), info, *icon_.get(), callback); |
| + web_contents->GetBrowserContext(), *shortcut_info_.get(), |
| + *icon_.get(), callback); |
| SendBannerAccepted(web_contents, "web"); |
| // Returns false to prevent the infobar from disappearing. |
| @@ -382,6 +386,11 @@ bool AppBannerInfoBarDelegateAndroid::LinkClicked( |
| return true; |
| } |
| +AppBannerInfoBarDelegateAndroid* |
| +AppBannerInfoBarDelegateAndroid::AsAppBannerInfoBarDelegateAndroid() { |
| + return this; |
| +} |
| + |
| bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
| return RegisterNativesImpl(env); |
| } |