Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManagerAndroid); | 34 DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManagerAndroid); |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 const char kPlayPlatform[] = "play"; | 38 const char kPlayPlatform[] = "play"; |
| 39 const char kReferrerName[] = "referrer"; | 39 const char kReferrerName[] = "referrer"; |
| 40 const char kIdName[] = "id"; | 40 const char kIdName[] = "id"; |
| 41 const char kPlayInlineReferrer[] = "playinline=chrome_inline"; | 41 const char kPlayInlineReferrer[] = "playinline=chrome_inline"; |
| 42 | 42 |
| 43 std::unique_ptr<ShortcutInfo> CreateShortcutInfo( | |
| 44 const GURL& manifest_url, | |
| 45 const content::Manifest& manifest, | |
| 46 const GURL& icon_url) { | |
| 47 std::unique_ptr<ShortcutInfo> info_ptr(new ShortcutInfo(GURL::EmptyGURL())); | |
|
Peter Kasting
2016/09/06 19:31:23
Don't use EmptyGURL() just because you want to pas
Xi Han
2016/09/07 15:53:17
Done.
| |
| 48 if (!manifest.IsEmpty()) { | |
| 49 info_ptr->UpdateFromManifest(manifest); | |
| 50 info_ptr->manifest_url = manifest_url; | |
| 51 info_ptr->icon_url = icon_url; | |
| 52 info_ptr->UpdateSource(ShortcutInfo::SOURCE_APP_BANNER); | |
| 53 } | |
| 54 return info_ptr; | |
| 55 } | |
| 56 | |
| 43 } // anonymous namespace | 57 } // anonymous namespace |
| 44 | 58 |
| 45 namespace banners { | 59 namespace banners { |
| 46 | 60 |
| 47 AppBannerManagerAndroid::AppBannerManagerAndroid( | 61 AppBannerManagerAndroid::AppBannerManagerAndroid( |
| 48 content::WebContents* web_contents) | 62 content::WebContents* web_contents) |
| 49 : AppBannerManager(web_contents) { | 63 : AppBannerManager(web_contents) { |
| 50 CreateJavaBannerManager(); | 64 CreateJavaBannerManager(); |
| 51 } | 65 } |
| 52 | 66 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 | 197 |
| 184 void AppBannerManagerAndroid::ShowBanner() { | 198 void AppBannerManagerAndroid::ShowBanner() { |
| 185 content::WebContents* contents = web_contents(); | 199 content::WebContents* contents = web_contents(); |
| 186 DCHECK(contents); | 200 DCHECK(contents); |
| 187 | 201 |
| 188 infobars::InfoBar* infobar = nullptr; | 202 infobars::InfoBar* infobar = nullptr; |
| 189 if (native_app_data_.is_null()) { | 203 if (native_app_data_.is_null()) { |
| 190 bool is_webapk = ChromeWebApkHost::AreWebApkEnabled(); | 204 bool is_webapk = ChromeWebApkHost::AreWebApkEnabled(); |
| 191 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 205 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 192 new AppBannerInfoBarDelegateAndroid( | 206 new AppBannerInfoBarDelegateAndroid( |
| 193 GetWeakPtr(), app_title_, manifest_url_, manifest_, icon_url_, | 207 GetWeakPtr(), app_title_, |
| 208 CreateShortcutInfo(manifest_url_, manifest_, icon_url_), | |
| 194 std::move(icon_), event_request_id(), is_webapk)); | 209 std::move(icon_), event_request_id(), is_webapk)); |
| 195 | 210 |
| 196 infobar = new AppBannerInfoBarAndroid( | 211 infobar = new AppBannerInfoBarAndroid( |
| 197 std::move(delegate), manifest_.start_url, is_webapk); | 212 std::move(delegate), manifest_.start_url, is_webapk); |
| 198 if (infobar) { | 213 if (infobar) { |
| 199 RecordDidShowBanner("AppBanner.WebApp.Shown"); | 214 RecordDidShowBanner("AppBanner.WebApp.Shown"); |
|
Peter Kasting
2016/09/06 19:31:23
The fact that these blocks are basically duplicate
Xi Han
2016/09/07 15:53:17
Updated. Make the Create return a bool, and only l
| |
| 200 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); | 215 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); |
| 201 ReportStatus(contents, SHOWING_WEB_APP_BANNER); | 216 ReportStatus(contents, SHOWING_WEB_APP_BANNER); |
| 202 } else { | 217 } else { |
| 203 ReportStatus(contents, FAILED_TO_CREATE_BANNER); | 218 ReportStatus(contents, FAILED_TO_CREATE_BANNER); |
| 204 } | 219 } |
| 205 } else { | 220 } else { |
| 206 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 221 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 207 new AppBannerInfoBarDelegateAndroid( | 222 new AppBannerInfoBarDelegateAndroid( |
| 208 app_title_, native_app_data_, std::move(icon_), native_app_package_, | 223 app_title_, native_app_data_, std::move(icon_), native_app_package_, |
| 209 referrer_, event_request_id())); | 224 referrer_, event_request_id())); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 } | 346 } |
| 332 | 347 |
| 333 // static | 348 // static |
| 334 void SetTimeDeltaForTesting(JNIEnv* env, | 349 void SetTimeDeltaForTesting(JNIEnv* env, |
| 335 const JavaParamRef<jclass>& clazz, | 350 const JavaParamRef<jclass>& clazz, |
| 336 jint days) { | 351 jint days) { |
| 337 AppBannerManager::SetTimeDeltaForTesting(days); | 352 AppBannerManager::SetTimeDeltaForTesting(days); |
| 338 } | 353 } |
| 339 | 354 |
| 340 } // namespace banners | 355 } // namespace banners |
| OLD | NEW |