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 ba09a565efab1f64eda6267b95439ae14d5d377a..ba0fcdfa916cc35933bbbbe4d624daf42203ee65 100644 |
--- a/chrome/browser/android/webapps/add_to_homescreen_manager.cc |
+++ b/chrome/browser/android/webapps/add_to_homescreen_manager.cc |
@@ -8,12 +8,16 @@ |
#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/installable/installable_manager.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" |
@@ -112,9 +116,9 @@ void AddToHomescreenManager::OnGotWebApkCompatibilityData( |
void AddToHomescreenManager::OnDeterminedWebApkCompatibility( |
content::WebContents* web_contents, |
bool is_compatible) { |
- // TODO(pkotwicz): Select whether to use dialog or not based on |
- // |is_compatible|. |
- ShowDialog(); |
+ is_compatible_ = is_compatible; |
+ if (!is_compatible) |
+ ShowDialog(); |
StartFetchingInfoForShortcut(web_contents); |
} |
@@ -167,6 +171,8 @@ void AddToHomescreenManager::RecordAddToHomescreen() { |
void AddToHomescreenManager::OnUserTitleAvailable( |
const base::string16& user_title) { |
+ if (is_compatible_) |
+ return; |
JNIEnv* env = base::android::AttachCurrentThread(); |
ScopedJavaLocalRef<jstring> j_user_title = |
base::android::ConvertUTF16ToJavaString(env, user_title); |
@@ -177,6 +183,11 @@ void AddToHomescreenManager::OnUserTitleAvailable( |
void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, |
const SkBitmap& icon) { |
+ if (is_compatible_) { |
+ CreateInfobar(info, icon); |
+ return; |
+ } |
+ |
JNIEnv* env = base::android::AttachCurrentThread(); |
ScopedJavaLocalRef<jobject> java_bitmap; |
if (icon.getSize()) |
@@ -188,6 +199,31 @@ void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, |
AddShortcut(info, icon); |
} |
+void AddToHomescreenManager::CreateInfobar(const ShortcutInfo& info, |
+ const SkBitmap& icon) { |
+ std::unique_ptr<ShortcutInfo> info_ptr(new ShortcutInfo(info)); |
+ std::unique_ptr<SkBitmap> icon_ptr(new SkBitmap(icon)); |
+ std::unique_ptr<banners::AppBannerInfoBarDelegateAndroid> delegate( |
+ new banners::AppBannerInfoBarDelegateAndroid( |
+ nullptr, info.user_title, info.manifest_url, std::move(info_ptr), |
+ info.icon_url, std::move(icon_ptr), -1 /* event_request_id */, |
+ true)); |
+ |
+ infobars::InfoBar* infobar = new AppBannerInfoBarAndroid( |
+ std::move(delegate), data_fetcher_->shortcut_info().url, true); |
+ if (infobar) { |
gone
2016/08/31 18:12:45
if (!infobar)
return;
saves you a level of inde
Xi Han
2016/08/31 20:11:48
I will be more careful and use early exist as much
|
+ 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; |
+ } |
+ InfoBarService::FromWebContents(web_contents)->AddInfoBar( |
+ base::WrapUnique(infobar)); |
+ static_cast<AppBannerInfoBarAndroid*>(infobar)->InstallWebApk(web_contents); |
+ } |
+} |
+ |
SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( |
const SkBitmap& bitmap, |
const GURL& url, |