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..78ad3912ca75164d3096b320936e273ef6d064ef 100644 |
| --- a/chrome/browser/android/banners/app_banner_infobar_delegate_android.cc |
| +++ b/chrome/browser/android/banners/app_banner_infobar_delegate_android.cc |
| @@ -37,13 +37,35 @@ using base::android::ConvertUTF16ToJavaString; |
| using base::android::JavaParamRef; |
| using base::android::ScopedJavaLocalRef; |
| +namespace { |
| + |
| +bool isInfoEmpty(const ShortcutInfo* info) { |
|
dominickn
2016/09/02 01:00:58
Nit: capital "I" in "Is" (C++ naming convention)
Xi Han
2016/09/02 13:58:23
Done.
|
| + return !info || info->url.is_empty(); |
| +} |
| + |
| +std::unique_ptr<ShortcutInfo> CreateShortcutInfo( |
| + const GURL& manifest_url, |
| + const content::Manifest& manifest, |
| + const GURL& icon_url) { |
| + std::unique_ptr<ShortcutInfo> info_ptr(new ShortcutInfo(GURL::EmptyGURL())); |
| + if (manifest.IsEmpty()) |
|
dominickn
2016/09/02 01:00:58
Nit (save a return statement):
if (!manifest.IsEm
Xi Han
2016/09/02 13:58:23
Done.
|
| + return info_ptr; |
| + info_ptr->UpdateFromManifest(manifest); |
| + info_ptr->manifest_url = manifest_url; |
| + info_ptr->icon_url = icon_url; |
| + info_ptr->UpdateSource(ShortcutInfo::SOURCE_APP_BANNER); |
| + return info_ptr; |
| +} |
| + |
| +} // anonymous namespace |
| + |
| namespace banners { |
| AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| base::WeakPtr<AppBannerManager> weak_manager, |
| const base::string16& app_title, |
| const GURL& manifest_url, |
| - const content::Manifest& manifest, |
| + std::unique_ptr<ShortcutInfo> shortcut_info, |
| const GURL& icon_url, |
| std::unique_ptr<SkBitmap> icon, |
| int event_request_id, |
| @@ -51,18 +73,33 @@ AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| : weak_manager_(weak_manager), |
| app_title_(app_title), |
| manifest_url_(manifest_url), |
| - manifest_(manifest), |
| + shortcut_info_(std::move(shortcut_info)), |
| icon_url_(icon_url), |
| 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(); |
| } |
| 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<SkBitmap> icon, |
| + int event_request_id, |
| + bool is_webapk) |
| + : AppBannerInfoBarDelegateAndroid( |
| + weak_manager, app_title, manifest_url, |
| + CreateShortcutInfo(manifest_url, manifest, icon_url), |
| + icon_url, std::move(icon), event_request_id, is_webapk) { |
| +} |
| + |
| +AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| const base::string16& app_title, |
| const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
| std::unique_ptr<SkBitmap> icon, |
| @@ -87,7 +124,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 +191,16 @@ void AppBannerInfoBarDelegateAndroid::OnInstallFinished( |
| } |
| } |
| +void AppBannerInfoBarDelegateAndroid::InstallWebApk( |
| + content::WebContents* web_contents) { |
| + if (!web_contents) { |
| + 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 +244,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 +307,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 +329,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 +342,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 +354,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 +419,11 @@ bool AppBannerInfoBarDelegateAndroid::LinkClicked( |
| return true; |
| } |
| +AppBannerInfoBarDelegateAndroid* |
| +AppBannerInfoBarDelegateAndroid::AsAppBannerInfoBarDelegateAndroid() { |
| + return this; |
| +} |
| + |
| bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
| return RegisterNativesImpl(env); |
| } |