| 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 "base/bind.h" |
| 7 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" | 8 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" |
| 9 #include "chrome/browser/android/shortcut_helper.h" |
| 10 #include "chrome/browser/banners/app_banner_debug_log.h" |
| 8 #include "chrome/browser/banners/app_banner_metrics.h" | 11 #include "chrome/browser/banners/app_banner_metrics.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
| 13 #include "chrome/browser/manifest/manifest_icon_downloader.h" |
| 14 #include "chrome/browser/manifest/manifest_icon_selector.h" |
| 10 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" | 15 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" |
| 11 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/gfx/screen.h" |
| 12 | 18 |
| 13 namespace banners { | 19 namespace banners { |
| 14 | 20 |
| 15 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid( | 21 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid( |
| 16 content::WebContents* web_contents, | 22 content::WebContents* web_contents, |
| 17 base::WeakPtr<Delegate> weak_delegate, | 23 base::WeakPtr<Delegate> weak_delegate, |
| 18 int ideal_icon_size) | 24 int ideal_splash_image_size_in_dp, |
| 19 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size) { | 25 int ideal_icon_size_in_dp) |
| 26 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size_in_dp), |
| 27 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp) { |
| 20 } | 28 } |
| 21 | 29 |
| 22 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() { | 30 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() { |
| 23 } | 31 } |
| 24 | 32 |
| 25 std::string AppBannerDataFetcherAndroid::GetBannerType() { | 33 std::string AppBannerDataFetcherAndroid::GetBannerType() { |
| 26 return native_app_data_.is_null() | 34 return native_app_data_.is_null() |
| 27 ? AppBannerDataFetcher::GetBannerType() : "android"; | 35 ? AppBannerDataFetcher::GetBannerType() : "android"; |
| 28 } | 36 } |
| 29 | 37 |
| 30 bool AppBannerDataFetcherAndroid::ContinueFetching( | 38 bool AppBannerDataFetcherAndroid::ContinueFetching( |
| 31 const base::string16& app_title, | 39 const base::string16& app_title, |
| 32 const std::string& app_package, | 40 const std::string& app_package, |
| 33 base::android::ScopedJavaLocalRef<jobject> app_data, | 41 base::android::ScopedJavaLocalRef<jobject> app_data, |
| 34 const GURL& image_url) { | 42 const GURL& image_url) { |
| 35 set_app_title(app_title); | 43 set_app_title(app_title); |
| 36 native_app_package_ = app_package; | 44 native_app_package_ = app_package; |
| 37 native_app_data_.Reset(app_data); | 45 native_app_data_.Reset(app_data); |
| 38 return FetchAppIcon(GetWebContents(), image_url); | 46 return FetchAppIcon(GetWebContents(), image_url); |
| 39 } | 47 } |
| 40 | 48 |
| 41 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() { | 49 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() { |
| 42 return native_app_data_.is_null() | 50 return native_app_data_.is_null() |
| 43 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_; | 51 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_; |
| 44 } | 52 } |
| 45 | 53 |
| 54 void AppBannerDataFetcherAndroid::FetchWebappSplashScreenImage( |
| 55 const std::string& webapp_id) { |
| 56 content::WebContents* web_contents = GetWebContents(); |
| 57 DCHECK(web_contents); |
| 58 |
| 59 GURL image_url = ManifestIconSelector::FindBestMatchingIcon( |
| 60 web_app_data().icons, |
| 61 ideal_splash_image_size_in_dp_, |
| 62 gfx::Screen::GetScreenFor(web_contents->GetNativeView())); |
| 63 |
| 64 ShortcutHelper::FetchSplashScreenImage( |
| 65 web_contents, image_url, ideal_splash_image_size_in_dp_, webapp_id); |
| 66 } |
| 67 |
| 46 void AppBannerDataFetcherAndroid::ShowBanner(const SkBitmap* icon, | 68 void AppBannerDataFetcherAndroid::ShowBanner(const SkBitmap* icon, |
| 47 const base::string16& title, | 69 const base::string16& title, |
| 48 const std::string& referrer) { | 70 const std::string& referrer) { |
| 49 content::WebContents* web_contents = GetWebContents(); | 71 content::WebContents* web_contents = GetWebContents(); |
| 50 DCHECK(web_contents); | 72 DCHECK(web_contents); |
| 51 | 73 |
| 52 infobars::InfoBar* infobar = nullptr; | 74 infobars::InfoBar* infobar = nullptr; |
| 53 if (native_app_data_.is_null()) { | 75 if (native_app_data_.is_null()) { |
| 54 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 76 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 55 new AppBannerInfoBarDelegateAndroid( | 77 new AppBannerInfoBarDelegateAndroid( |
| 56 event_request_id(), title, new SkBitmap(*icon), web_app_data())); | 78 event_request_id(), this, title, new SkBitmap(*icon), |
| 79 web_app_data())); |
| 57 | 80 |
| 58 infobar = | 81 infobar = |
| 59 new AppBannerInfoBarAndroid(delegate.Pass(), web_app_data().start_url); | 82 new AppBannerInfoBarAndroid(delegate.Pass(), web_app_data().start_url); |
| 60 if (infobar) { | 83 if (infobar) { |
| 61 RecordDidShowBanner("AppBanner.WebApp.Shown"); | 84 RecordDidShowBanner("AppBanner.WebApp.Shown"); |
| 62 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); | 85 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); |
| 63 } | 86 } |
| 64 } else { | 87 } else { |
| 65 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 88 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 66 new AppBannerInfoBarDelegateAndroid( | 89 new AppBannerInfoBarDelegateAndroid( |
| 67 event_request_id(), title, new SkBitmap(*icon), native_app_data_, | 90 event_request_id(), title, new SkBitmap(*icon), native_app_data_, |
| 68 native_app_package_, referrer)); | 91 native_app_package_, referrer)); |
| 69 infobar = new AppBannerInfoBarAndroid(delegate.Pass(), native_app_data_); | 92 infobar = new AppBannerInfoBarAndroid(delegate.Pass(), native_app_data_); |
| 70 if (infobar) { | 93 if (infobar) { |
| 71 RecordDidShowBanner("AppBanner.NativeApp.Shown"); | 94 RecordDidShowBanner("AppBanner.NativeApp.Shown"); |
| 72 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); | 95 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); |
| 73 } | 96 } |
| 74 } | 97 } |
| 75 InfoBarService::FromWebContents(web_contents) | 98 InfoBarService::FromWebContents(web_contents) |
| 76 ->AddInfoBar(make_scoped_ptr(infobar)); | 99 ->AddInfoBar(make_scoped_ptr(infobar)); |
| 77 } | 100 } |
| 78 | 101 |
| 79 } // namespace banners | 102 } // namespace banners |
| OLD | NEW |