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