Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Unified Diff: chrome/browser/android/webapps/add_to_homescreen_manager.cc

Issue 2290603005: Trigger app banner when add to homescreen is pressed and WebAPKs are enabled. (Closed)
Patch Set: Remove InstallWebApk from infobar. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 3a12112402710a0d24e4708b9e6d850ddc4df50d..d8175e06d05d9c9cdea9e31ca918a34aedb67010 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"
@@ -149,13 +153,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);
@@ -166,6 +172,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())
@@ -177,6 +188,37 @@ void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info,
AddShortcut(info, icon);
}
+void AddToHomescreenManager::CreateInfoBarForWebAPK(const ShortcutInfo& info,
+ const SkBitmap& icon) {
+ std::unique_ptr<ShortcutInfo> info_ptr(new ShortcutInfo(info));
dominickn 2016/09/01 05:29:02 Inline these construction calls into line 195 usin
Xi Han 2016/09/01 18:44:14 Done.
+ 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) {
+ 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;
+ }
+
+ InfoBarService::FromWebContents(web_contents)->AddInfoBar(
+ base::WrapUnique(infobar));
dominickn 2016/09/01 05:29:02 WrapUnique is dispreferred as of a few weeks ago.
Xi Han 2016/09/01 18:44:14 Done.
+
+ static_cast<banners::AppBannerInfoBarDelegateAndroid*>(infobar->delegate())
gone 2016/08/31 21:07:39 Longer term, you're probably going to need to add
Xi Han 2016/09/01 18:44:14 Done.
+ ->InstallWebApk(web_contents);
+}
+
SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground(
const SkBitmap& bitmap,
const GURL& url,

Powered by Google App Engine
This is Rietveld 408576698