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

Side by Side 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, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/webapps/add_to_homescreen_manager.h" 5 #include "chrome/browser/android/webapps/add_to_homescreen_manager.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/memory/ptr_util.h"
11 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h"
13 #include "chrome/browser/android/shortcut_helper.h" 15 #include "chrome/browser/android/shortcut_helper.h"
14 #include "chrome/browser/android/webapk/chrome_webapk_host.h" 16 #include "chrome/browser/android/webapk/chrome_webapk_host.h"
15 #include "chrome/browser/banners/app_banner_settings_helper.h" 17 #include "chrome/browser/banners/app_banner_settings_helper.h"
18 #include "chrome/browser/infobars/infobar_service.h"
16 #include "chrome/browser/installable/installable_manager.h" 19 #include "chrome/browser/installable/installable_manager.h"
20 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h"
17 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/origin_util.h" 23 #include "content/public/common/origin_util.h"
20 #include "jni/AddToHomescreenManager_jni.h" 24 #include "jni/AddToHomescreenManager_jni.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/gfx/android/java_bitmap.h" 26 #include "ui/gfx/android/java_bitmap.h"
23 27
24 using base::android::JavaParamRef; 28 using base::android::JavaParamRef;
25 using base::android::ScopedJavaLocalRef; 29 using base::android::ScopedJavaLocalRef;
26 30
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 146
143 AppBannerSettingsHelper::RecordBannerEvent( 147 AppBannerSettingsHelper::RecordBannerEvent(
144 web_contents, web_contents->GetURL(), 148 web_contents, web_contents->GetURL(),
145 data_fetcher_->shortcut_info().url.spec(), 149 data_fetcher_->shortcut_info().url.spec(),
146 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, 150 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
147 base::Time::Now()); 151 base::Time::Now());
148 } 152 }
149 153
150 void AddToHomescreenManager::OnDidDetermineWebApkCompatibility( 154 void AddToHomescreenManager::OnDidDetermineWebApkCompatibility(
151 bool is_webapk_compatible) { 155 bool is_webapk_compatible) {
152 // TODO(pkotwicz): Select whether to use dialog or not based on 156 is_webapk_compatible_ = is_webapk_compatible;
153 // |is_webapk_compatible|. 157 if (!is_webapk_compatible)
154 ShowDialog(); 158 ShowDialog();
155 } 159 }
156 160
157 void AddToHomescreenManager::OnUserTitleAvailable( 161 void AddToHomescreenManager::OnUserTitleAvailable(
158 const base::string16& user_title) { 162 const base::string16& user_title) {
163 if (is_webapk_compatible_)
164 return;
159 JNIEnv* env = base::android::AttachCurrentThread(); 165 JNIEnv* env = base::android::AttachCurrentThread();
160 ScopedJavaLocalRef<jstring> j_user_title = 166 ScopedJavaLocalRef<jstring> j_user_title =
161 base::android::ConvertUTF16ToJavaString(env, user_title); 167 base::android::ConvertUTF16ToJavaString(env, user_title);
162 Java_AddToHomescreenManager_onUserTitleAvailable(env, 168 Java_AddToHomescreenManager_onUserTitleAvailable(env,
163 java_ref_, 169 java_ref_,
164 j_user_title); 170 j_user_title);
165 } 171 }
166 172
167 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, 173 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info,
168 const SkBitmap& icon) { 174 const SkBitmap& icon) {
175 if (is_webapk_compatible_) {
176 CreateInfoBarForWebAPK(info, icon);
177 return;
178 }
179
169 JNIEnv* env = base::android::AttachCurrentThread(); 180 JNIEnv* env = base::android::AttachCurrentThread();
170 ScopedJavaLocalRef<jobject> java_bitmap; 181 ScopedJavaLocalRef<jobject> java_bitmap;
171 if (icon.getSize()) 182 if (icon.getSize())
172 java_bitmap = gfx::ConvertToJavaBitmap(&icon); 183 java_bitmap = gfx::ConvertToJavaBitmap(&icon);
173 184
174 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap); 185 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap);
175 186
176 if (add_shortcut_pending_) 187 if (add_shortcut_pending_)
177 AddShortcut(info, icon); 188 AddShortcut(info, icon);
178 } 189 }
179 190
191 void AddToHomescreenManager::CreateInfoBarForWebAPK(const ShortcutInfo& info,
192 const SkBitmap& icon) {
193 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.
194 std::unique_ptr<SkBitmap> icon_ptr(new SkBitmap(icon));
195 std::unique_ptr<banners::AppBannerInfoBarDelegateAndroid> delegate(
196 new banners::AppBannerInfoBarDelegateAndroid(
197 nullptr, info.user_title, info.manifest_url, std::move(info_ptr),
198 info.icon_url, std::move(icon_ptr), -1 /* event_request_id */,
199 true));
200
201 infobars::InfoBar* infobar = new AppBannerInfoBarAndroid(
202 std::move(delegate), data_fetcher_->shortcut_info().url, true);
203 if (!infobar) {
204 LOG(ERROR) << "Failed to create infobar to install the WebAPK.";
205 return;
206 }
207
208 content::WebContents* web_contents = data_fetcher_->web_contents();
209 if (!web_contents) {
210 LOG(ERROR) << "Failed to create infobar to install the WebAPK: "
211 << "the associated WebContents is null.";
212 return;
213 }
214
215 InfoBarService::FromWebContents(web_contents)->AddInfoBar(
216 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.
217
218 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.
219 ->InstallWebApk(web_contents);
220 }
221
180 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( 222 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground(
181 const SkBitmap& bitmap, 223 const SkBitmap& bitmap,
182 const GURL& url, 224 const GURL& url,
183 bool* is_generated) { 225 bool* is_generated) {
184 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 226 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
185 227
186 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, 228 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url,
187 is_generated); 229 is_generated);
188 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698