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

Side by Side Diff: chrome/browser/android/banners/app_banner_manager_android.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 <utility> 5 #include <utility>
6 6
7 #include "chrome/browser/android/banners/app_banner_manager_android.h" 7 #include "chrome/browser/android/banners/app_banner_manager_android.h"
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" 13 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h"
14 #include "chrome/browser/android/shortcut_helper.h" 14 #include "chrome/browser/android/shortcut_helper.h"
15 #include "chrome/browser/android/shortcut_info.h"
15 #include "chrome/browser/android/webapk/chrome_webapk_host.h" 16 #include "chrome/browser/android/webapk/chrome_webapk_host.h"
16 #include "chrome/browser/android/webapk/webapk_web_manifest_checker.h" 17 #include "chrome/browser/android/webapk/webapk_web_manifest_checker.h"
17 #include "chrome/browser/banners/app_banner_metrics.h" 18 #include "chrome/browser/banners/app_banner_metrics.h"
18 #include "chrome/browser/infobars/infobar_service.h" 19 #include "chrome/browser/infobars/infobar_service.h"
19 #include "chrome/browser/manifest/manifest_icon_downloader.h" 20 #include "chrome/browser/manifest/manifest_icon_downloader.h"
20 #include "chrome/browser/manifest/manifest_icon_selector.h" 21 #include "chrome/browser/manifest/manifest_icon_selector.h"
21 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" 22 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h"
22 #include "chrome/common/chrome_constants.h" 23 #include "chrome/common/chrome_constants.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/frame_navigate_params.h" 25 #include "content/public/common/frame_navigate_params.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 SendBannerPromptRequest(); 182 SendBannerPromptRequest();
182 } 183 }
183 184
184 void AppBannerManagerAndroid::ShowBanner() { 185 void AppBannerManagerAndroid::ShowBanner() {
185 content::WebContents* contents = web_contents(); 186 content::WebContents* contents = web_contents();
186 DCHECK(contents); 187 DCHECK(contents);
187 188
188 infobars::InfoBar* infobar = nullptr; 189 infobars::InfoBar* infobar = nullptr;
189 if (native_app_data_.is_null()) { 190 if (native_app_data_.is_null()) {
190 bool is_webapk = ChromeWebApkHost::AreWebApkEnabled(); 191 bool is_webapk = ChromeWebApkHost::AreWebApkEnabled();
192 std::unique_ptr<ShortcutInfo> info = CreateShortcutInfo();
191 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( 193 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate(
192 new AppBannerInfoBarDelegateAndroid( 194 new AppBannerInfoBarDelegateAndroid(
193 GetWeakPtr(), app_title_, manifest_url_, manifest_, icon_url_, 195 GetWeakPtr(), app_title_, manifest_url_, std::move(info), icon_url_,
194 std::move(icon_), event_request_id(), is_webapk)); 196 std::move(icon_), event_request_id(), is_webapk));
195 197
196 infobar = new AppBannerInfoBarAndroid( 198 infobar = new AppBannerInfoBarAndroid(
197 std::move(delegate), manifest_.start_url, is_webapk); 199 std::move(delegate), manifest_.start_url, is_webapk);
198 if (infobar) { 200 if (infobar) {
199 RecordDidShowBanner("AppBanner.WebApp.Shown"); 201 RecordDidShowBanner("AppBanner.WebApp.Shown");
200 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); 202 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED);
201 ReportStatus(contents, SHOWING_WEB_APP_BANNER); 203 ReportStatus(contents, SHOWING_WEB_APP_BANNER);
202 } else { 204 } else {
203 ReportStatus(contents, FAILED_TO_CREATE_BANNER); 205 ReportStatus(contents, FAILED_TO_CREATE_BANNER);
(...skipping 13 matching lines...) Expand all
217 ReportStatus(contents, FAILED_TO_CREATE_BANNER); 219 ReportStatus(contents, FAILED_TO_CREATE_BANNER);
218 } 220 }
219 } 221 }
220 222
221 if (infobar) { 223 if (infobar) {
222 InfoBarService::FromWebContents(contents)->AddInfoBar( 224 InfoBarService::FromWebContents(contents)->AddInfoBar(
223 base::WrapUnique(infobar)); 225 base::WrapUnique(infobar));
224 } 226 }
225 } 227 }
226 228
229 std::unique_ptr<ShortcutInfo> AppBannerManagerAndroid::CreateShortcutInfo() {
dominickn 2016/09/01 05:22:00 Put this method in the anonymous namespace in AppB
Xi Han 2016/09/01 18:44:14 Done.
230 std::unique_ptr<ShortcutInfo> info_ptr(new ShortcutInfo(GURL::EmptyGURL()));
231 if (manifest_.IsEmpty())
232 return info_ptr;
233 info_ptr->UpdateFromManifest(manifest_);
234 info_ptr->manifest_url = manifest_url_;
235 info_ptr->icon_url = icon_url_;
236 info_ptr->UpdateSource(ShortcutInfo::SOURCE_APP_BANNER);
237 return info_ptr;
238 }
239
227 bool AppBannerManagerAndroid::CanHandleNonWebApp(const std::string& platform, 240 bool AppBannerManagerAndroid::CanHandleNonWebApp(const std::string& platform,
228 const GURL& url, 241 const GURL& url,
229 const std::string& id) { 242 const std::string& id) {
230 if (!CheckPlatformAndId(platform, id)) 243 if (!CheckPlatformAndId(platform, id))
231 return false; 244 return false;
232 245
233 banners::TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_REQUESTED); 246 banners::TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_REQUESTED);
234 247
235 // Send the info to the Java side to get info about the app. 248 // Send the info to the Java side to get info about the app.
236 JNIEnv* env = base::android::AttachCurrentThread(); 249 JNIEnv* env = base::android::AttachCurrentThread();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 } 344 }
332 345
333 // static 346 // static
334 void SetTimeDeltaForTesting(JNIEnv* env, 347 void SetTimeDeltaForTesting(JNIEnv* env,
335 const JavaParamRef<jclass>& clazz, 348 const JavaParamRef<jclass>& clazz,
336 jint days) { 349 jint days) {
337 AppBannerManager::SetTimeDeltaForTesting(days); 350 AppBannerManager::SetTimeDeltaForTesting(days);
338 } 351 }
339 352
340 } // namespace banners 353 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698