Index: chrome/browser/android/webapps/add_to_homescreen_manager.cc |
diff --git a/chrome/browser/android/webapps/add_to_homescreen_manager.cc b/chrome/browser/android/webapps/add_to_homescreen_manager.cc |
index d7e5929cce20b287d60081bf160abd4bde2a3244..666945efb6fa25ab39cac8e4cccccfd9331a3b49 100644 |
--- a/chrome/browser/android/webapps/add_to_homescreen_manager.cc |
+++ b/chrome/browser/android/webapps/add_to_homescreen_manager.cc |
@@ -8,11 +8,15 @@ |
#include "base/android/jni_string.h" |
#include "base/guid.h" |
#include "base/location.h" |
+#include "base/memory/ptr_util.h" |
#include "base/strings/string16.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" |
#include "chrome/browser/android/shortcut_helper.h" |
#include "chrome/browser/android/webapk/chrome_webapk_host.h" |
#include "chrome/browser/banners/app_banner_settings_helper.h" |
+#include "chrome/browser/infobars/infobar_service.h" |
+#include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/origin_util.h" |
@@ -129,13 +133,15 @@ void AddToHomescreenManager::RecordAddToHomescreen() { |
void AddToHomescreenManager::OnDidDetermineWebApkCompatibility( |
bool is_webapk_compatible) { |
- // TODO(pkotwicz): Select whether to use dialog or not based on |
- // |is_webapk_compatible|. |
- ShowDialog(); |
+ is_webapk_compatible_ = is_webapk_compatible; |
+ if (!is_webapk_compatible) |
+ ShowDialog(); |
} |
void AddToHomescreenManager::OnUserTitleAvailable( |
const base::string16& user_title) { |
+ if (is_webapk_compatible_) |
+ return; |
JNIEnv* env = base::android::AttachCurrentThread(); |
ScopedJavaLocalRef<jstring> j_user_title = |
base::android::ConvertUTF16ToJavaString(env, user_title); |
@@ -146,6 +152,11 @@ void AddToHomescreenManager::OnUserTitleAvailable( |
void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, |
const SkBitmap& icon) { |
+ if (is_webapk_compatible_) { |
+ CreateInfoBarForWebAPK(info, icon); |
+ return; |
+ } |
+ |
JNIEnv* env = base::android::AttachCurrentThread(); |
ScopedJavaLocalRef<jobject> java_bitmap; |
if (icon.getSize()) |
@@ -157,6 +168,37 @@ void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, |
AddShortcut(info, icon); |
} |
+void AddToHomescreenManager::CreateInfoBarForWebAPK(const ShortcutInfo& info, |
+ const SkBitmap& icon) { |
+ std::unique_ptr<banners::AppBannerInfoBarDelegateAndroid> delegate_ptr = |
+ base::MakeUnique<banners::AppBannerInfoBarDelegateAndroid>( |
+ nullptr, info.user_title, base::MakeUnique<ShortcutInfo>(info), |
+ base::MakeUnique<SkBitmap>(icon), |
+ -1 /* event_request_id */, true /* is_webapk */); |
+ |
+ std::unique_ptr<infobars::InfoBar> infobar_ptr = |
+ base::MakeUnique<AppBannerInfoBarAndroid>( |
+ std::move(delegate_ptr), data_fetcher_->shortcut_info().url, true); |
+ if (!infobar_ptr.get()) { |
+ LOG(ERROR) << "Failed to create infobar to install the WebAPK."; |
+ return; |
+ } |
+ |
+ content::WebContents* web_contents = data_fetcher_->web_contents(); |
+ if (!web_contents) { |
+ LOG(ERROR) << "Failed to create infobar to install the WebAPK: " |
+ << "the associated WebContents is null."; |
+ return; |
+ } |
+ |
+ banners::AppBannerInfoBarDelegateAndroid* delegate = |
+ infobar_ptr.get()->delegate()->AsAppBannerInfoBarDelegateAndroid(); |
Peter Kasting
2016/09/06 19:31:23
Don't add this function. You don't need it and we
Xi Han
2016/09/07 15:53:17
Thanks for all the suggestions. I will be more car
|
+ |
+ InfoBarService::FromWebContents(web_contents)->AddInfoBar( |
+ std::move(infobar_ptr)); |
+ delegate->InstallWebApk(web_contents); |
+} |
+ |
SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( |
const SkBitmap& bitmap, |
const GURL& url, |