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 "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, |
| 24 int ideal_splash_icon_size, | |
| 18 int ideal_icon_size) | 25 int ideal_icon_size) |
| 19 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size) { | 26 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size), |
| 27 ideal_splash_icon_size_(ideal_splash_icon_size) { | |
| 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::FetchWebappSplashscreenIcon( | |
| 55 const std::string& webapp_id) { | |
| 56 content::WebContents* web_contents = GetWebContents(); | |
| 57 DCHECK(web_contents); | |
| 58 | |
| 59 GURL icon_url = | |
| 60 ManifestIconSelector::FindBestMatchingIcon( | |
| 61 web_app_data().icons, | |
| 62 ideal_splash_icon_size_, | |
| 63 gfx::Screen::GetScreenFor(web_contents->GetNativeView())); | |
| 64 | |
| 65 // This is a fire and forget task. It is not vital for the splashscreen icon | |
| 66 // to be downloaded so the result of the download is not checked and neither | |
| 67 // is there any fallback option. | |
|
gone
2015/08/26 02:01:19
You explicitly check if the icon was downloaded in
Lalit Maganti
2015/08/26 13:11:56
Moved to shortcuthelper and clarified there.
| |
| 68 ManifestIconDownloader::Download( | |
| 69 web_contents, | |
| 70 icon_url, | |
| 71 ideal_splash_icon_size_, | |
| 72 base::Bind(&ShortcutHelper::AddSplashscreenIconToWebappData, | |
| 73 webapp_id)); | |
| 74 } | |
| 75 | |
| 46 void AppBannerDataFetcherAndroid::ShowBanner(const SkBitmap* icon, | 76 void AppBannerDataFetcherAndroid::ShowBanner(const SkBitmap* icon, |
| 47 const base::string16& title, | 77 const base::string16& title, |
| 48 const std::string& referrer) { | 78 const std::string& referrer) { |
| 49 content::WebContents* web_contents = GetWebContents(); | 79 content::WebContents* web_contents = GetWebContents(); |
| 50 DCHECK(web_contents); | 80 DCHECK(web_contents); |
| 51 | 81 |
| 52 infobars::InfoBar* infobar = nullptr; | 82 infobars::InfoBar* infobar = nullptr; |
| 53 if (native_app_data_.is_null()) { | 83 if (native_app_data_.is_null()) { |
| 54 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 84 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 55 new AppBannerInfoBarDelegateAndroid( | 85 new AppBannerInfoBarDelegateAndroid( |
| 56 event_request_id(), title, new SkBitmap(*icon), web_app_data())); | 86 event_request_id(), this, title, new SkBitmap(*icon), |
| 87 web_app_data())); | |
| 57 | 88 |
| 58 infobar = | 89 infobar = |
| 59 new AppBannerInfoBarAndroid(delegate.Pass(), web_app_data().start_url); | 90 new AppBannerInfoBarAndroid(delegate.Pass(), web_app_data().start_url); |
| 60 if (infobar) { | 91 if (infobar) { |
| 61 RecordDidShowBanner("AppBanner.WebApp.Shown"); | 92 RecordDidShowBanner("AppBanner.WebApp.Shown"); |
| 62 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); | 93 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); |
| 63 } | 94 } |
| 64 } else { | 95 } else { |
| 65 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 96 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 66 new AppBannerInfoBarDelegateAndroid( | 97 new AppBannerInfoBarDelegateAndroid( |
| 67 event_request_id(), title, new SkBitmap(*icon), native_app_data_, | 98 event_request_id(), title, new SkBitmap(*icon), native_app_data_, |
| 68 native_app_package_, referrer)); | 99 native_app_package_, referrer)); |
| 69 infobar = new AppBannerInfoBarAndroid(delegate.Pass(), native_app_data_); | 100 infobar = new AppBannerInfoBarAndroid(delegate.Pass(), native_app_data_); |
| 70 if (infobar) { | 101 if (infobar) { |
| 71 RecordDidShowBanner("AppBanner.NativeApp.Shown"); | 102 RecordDidShowBanner("AppBanner.NativeApp.Shown"); |
| 72 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); | 103 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); |
| 73 } | 104 } |
| 74 } | 105 } |
| 75 InfoBarService::FromWebContents(web_contents) | 106 InfoBarService::FromWebContents(web_contents) |
| 76 ->AddInfoBar(make_scoped_ptr(infobar)); | 107 ->AddInfoBar(make_scoped_ptr(infobar)); |
| 77 } | 108 } |
| 78 | 109 |
| 79 } // namespace banners | 110 } // namespace banners |
| OLD | NEW |