| 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 "chrome/browser/android/banners/app_banner_data_fetcher_android.h" | 5 #include "chrome/browser/android/banners/app_banner_data_fetcher_android.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/command_line.h" |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" | 13 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" |
| 13 #include "chrome/browser/android/shortcut_helper.h" | 14 #include "chrome/browser/android/shortcut_helper.h" |
| 14 #include "chrome/browser/banners/app_banner_metrics.h" | 15 #include "chrome/browser/banners/app_banner_metrics.h" |
| 15 #include "chrome/browser/infobars/infobar_service.h" | 16 #include "chrome/browser/infobars/infobar_service.h" |
| 16 #include "chrome/browser/manifest/manifest_icon_selector.h" | 17 #include "chrome/browser/manifest/manifest_icon_selector.h" |
| 17 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" | 18 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" |
| 19 #include "chrome/common/chrome_switches.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 | 21 |
| 20 namespace banners { | 22 namespace banners { |
| 21 | 23 |
| 22 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid( | 24 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid( |
| 23 content::WebContents* web_contents, | 25 content::WebContents* web_contents, |
| 24 base::WeakPtr<Delegate> weak_delegate, | 26 base::WeakPtr<Delegate> weak_delegate, |
| 25 int ideal_icon_size_in_dp, | 27 int ideal_icon_size_in_dp, |
| 26 int minimum_icon_size_in_dp, | 28 int minimum_icon_size_in_dp, |
| 27 int ideal_splash_image_size_in_dp, | 29 int ideal_splash_image_size_in_dp, |
| 28 int minimum_splash_image_size_in_dp, | 30 int minimum_splash_image_size_in_dp, |
| 29 bool is_debug_mode) | 31 bool is_debug_mode) |
| 30 : AppBannerDataFetcher(web_contents, | 32 : AppBannerDataFetcher(web_contents, |
| 31 weak_delegate, | 33 weak_delegate, |
| 32 ideal_icon_size_in_dp, | 34 ideal_icon_size_in_dp, |
| 33 minimum_icon_size_in_dp, | 35 minimum_icon_size_in_dp, |
| 34 is_debug_mode), | 36 is_debug_mode), |
| 37 webapp_type_(ShortcutInfo::Type::OTHER), |
| 35 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp), | 38 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp), |
| 36 minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp) {} | 39 minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp) {} |
| 37 | 40 |
| 38 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() { | 41 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() { |
| 39 } | 42 } |
| 40 | 43 |
| 41 std::string AppBannerDataFetcherAndroid::GetBannerType() { | 44 std::string AppBannerDataFetcherAndroid::GetBannerType() { |
| 42 return native_app_data_.is_null() | 45 return native_app_data_.is_null() |
| 43 ? AppBannerDataFetcher::GetBannerType() : "android"; | 46 ? AppBannerDataFetcher::GetBannerType() : "android"; |
| 44 } | 47 } |
| 45 | 48 |
| 46 bool AppBannerDataFetcherAndroid::ContinueFetching( | 49 bool AppBannerDataFetcherAndroid::ContinueFetching( |
| 47 const base::string16& app_title, | 50 const base::string16& app_title, |
| 48 const std::string& app_package, | 51 const std::string& app_package, |
| 49 const base::android::JavaRef<jobject>& app_data, | 52 const base::android::JavaRef<jobject>& app_data, |
| 50 const GURL& image_url) { | 53 const GURL& image_url) { |
| 51 set_app_title(app_title); | 54 set_app_title(app_title); |
| 52 native_app_package_ = app_package; | 55 native_app_package_ = app_package; |
| 53 native_app_data_.Reset(app_data); | 56 native_app_data_.Reset(app_data); |
| 54 return FetchAppIcon(GetWebContents(), image_url); | 57 return FetchAppIcon(GetWebContents(), image_url); |
| 55 } | 58 } |
| 56 | 59 |
| 60 bool AppBannerDataFetcherAndroid::CheckManifest( |
| 61 const content::Manifest& manifest, |
| 62 OutputDeveloperMessageCode* code) { |
| 63 bool manifest_valid_for_webapp = |
| 64 AppBannerDataFetcher::CheckManifest(manifest, code); |
| 65 if (manifest_valid_for_webapp) { |
| 66 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 67 webapp_type_ = command_line->HasSwitch(switches::kEnableWebApk) |
| 68 ? ShortcutInfo::Type::WEBAPK |
| 69 : ShortcutInfo::Type::WEBAPP; |
| 70 } |
| 71 return manifest_valid_for_webapp; |
| 72 } |
| 73 |
| 57 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() { | 74 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() { |
| 58 return native_app_data_.is_null() | 75 return native_app_data_.is_null() |
| 59 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_; | 76 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_; |
| 60 } | 77 } |
| 61 | 78 |
| 62 base::Closure AppBannerDataFetcherAndroid::FetchWebappSplashScreenImageCallback( | 79 base::Closure AppBannerDataFetcherAndroid::FetchWebappSplashScreenImageCallback( |
| 63 const std::string& webapp_id) { | 80 const std::string& webapp_id) { |
| 64 content::WebContents* web_contents = GetWebContents(); | 81 content::WebContents* web_contents = GetWebContents(); |
| 65 DCHECK(web_contents); | 82 DCHECK(web_contents); |
| 66 | 83 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 const base::string16& title, | 94 const base::string16& title, |
| 78 const std::string& referrer) { | 95 const std::string& referrer) { |
| 79 content::WebContents* web_contents = GetWebContents(); | 96 content::WebContents* web_contents = GetWebContents(); |
| 80 DCHECK(web_contents); | 97 DCHECK(web_contents); |
| 81 | 98 |
| 82 infobars::InfoBar* infobar = nullptr; | 99 infobars::InfoBar* infobar = nullptr; |
| 83 if (native_app_data_.is_null()) { | 100 if (native_app_data_.is_null()) { |
| 84 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 101 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 85 new AppBannerInfoBarDelegateAndroid(event_request_id(), this, title, | 102 new AppBannerInfoBarDelegateAndroid(event_request_id(), this, title, |
| 86 new SkBitmap(*icon), | 103 new SkBitmap(*icon), |
| 87 web_app_data())); | 104 web_app_data(), webapp_type_)); |
| 88 | 105 |
| 89 infobar = new AppBannerInfoBarAndroid(std::move(delegate), | 106 infobar = new AppBannerInfoBarAndroid(std::move(delegate), |
| 90 web_app_data().start_url); | 107 web_app_data().start_url); |
| 91 if (infobar) { | 108 if (infobar) { |
| 92 RecordDidShowBanner("AppBanner.WebApp.Shown"); | 109 RecordDidShowBanner("AppBanner.WebApp.Shown"); |
| 93 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); | 110 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); |
| 94 } | 111 } |
| 95 } else { | 112 } else { |
| 96 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 113 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 97 new AppBannerInfoBarDelegateAndroid( | 114 new AppBannerInfoBarDelegateAndroid( |
| 98 event_request_id(), title, new SkBitmap(*icon), native_app_data_, | 115 event_request_id(), title, new SkBitmap(*icon), native_app_data_, |
| 99 native_app_package_, referrer)); | 116 native_app_package_, referrer)); |
| 100 infobar = | 117 infobar = |
| 101 new AppBannerInfoBarAndroid(std::move(delegate), native_app_data_); | 118 new AppBannerInfoBarAndroid(std::move(delegate), native_app_data_); |
| 102 if (infobar) { | 119 if (infobar) { |
| 103 RecordDidShowBanner("AppBanner.NativeApp.Shown"); | 120 RecordDidShowBanner("AppBanner.NativeApp.Shown"); |
| 104 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); | 121 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); |
| 105 } | 122 } |
| 106 } | 123 } |
| 107 InfoBarService::FromWebContents(web_contents) | 124 InfoBarService::FromWebContents(web_contents) |
| 108 ->AddInfoBar(base::WrapUnique(infobar)); | 125 ->AddInfoBar(base::WrapUnique(infobar)); |
| 109 } | 126 } |
| 110 | 127 |
| 111 } // namespace banners | 128 } // namespace banners |
| OLD | NEW |