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/banners/app_banner_debug_log.h" | |
| 8 #include "chrome/browser/banners/app_banner_metrics.h" | 10 #include "chrome/browser/banners/app_banner_metrics.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/manifest/manifest_icon_downloader.h" | |
| 13 #include "chrome/browser/manifest/manifest_icon_selector.h" | |
| 10 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" | 14 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" |
| 11 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 #include "ui/gfx/screen.h" | |
| 12 | 17 |
| 13 namespace banners { | 18 namespace banners { |
| 14 | 19 |
| 15 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid( | 20 AppBannerDataFetcherAndroid::AppBannerDataFetcherAndroid( |
| 16 content::WebContents* web_contents, | 21 content::WebContents* web_contents, |
| 17 base::WeakPtr<Delegate> weak_delegate, | 22 base::WeakPtr<Delegate> weak_delegate, |
| 23 int ideal_splash_icon_size, | |
| 18 int ideal_icon_size) | 24 int ideal_icon_size) |
| 19 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size) { | 25 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size), |
| 26 ideal_splash_icon_size_(ideal_splash_icon_size) { | |
| 20 } | 27 } |
| 21 | 28 |
| 22 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() { | 29 AppBannerDataFetcherAndroid::~AppBannerDataFetcherAndroid() { |
| 23 } | 30 } |
| 24 | 31 |
| 25 std::string AppBannerDataFetcherAndroid::GetBannerType() { | 32 std::string AppBannerDataFetcherAndroid::GetBannerType() { |
| 26 return native_app_data_.is_null() | 33 return native_app_data_.is_null() |
| 27 ? AppBannerDataFetcher::GetBannerType() : "android"; | 34 ? AppBannerDataFetcher::GetBannerType() : "android"; |
| 28 } | 35 } |
| 29 | 36 |
| 30 bool AppBannerDataFetcherAndroid::ContinueFetching( | 37 bool AppBannerDataFetcherAndroid::ContinueFetching( |
| 31 const base::string16& app_title, | 38 const base::string16& app_title, |
| 32 const std::string& app_package, | 39 const std::string& app_package, |
| 33 base::android::ScopedJavaLocalRef<jobject> app_data, | 40 base::android::ScopedJavaLocalRef<jobject> app_data, |
| 34 const GURL& image_url) { | 41 const GURL& image_url) { |
| 35 set_app_title(app_title); | 42 set_app_title(app_title); |
| 36 native_app_package_ = app_package; | 43 native_app_package_ = app_package; |
| 37 native_app_data_.Reset(app_data); | 44 native_app_data_.Reset(app_data); |
| 38 return FetchAppIcon(GetWebContents(), image_url); | 45 return FetchAppIcon(GetWebContents(), image_url); |
| 39 } | 46 } |
| 40 | 47 |
| 41 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() { | 48 std::string AppBannerDataFetcherAndroid::GetAppIdentifier() { |
| 42 return native_app_data_.is_null() | 49 return native_app_data_.is_null() |
| 43 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_; | 50 ? AppBannerDataFetcher::GetAppIdentifier() : native_app_package_; |
| 44 } | 51 } |
| 45 | 52 |
| 53 void AppBannerDataFetcherAndroid::OnHasServiceWorker( | |
| 54 content::WebContents* web_contents) { | |
| 55 // We intercept the data fetch flow and inject downloading of the splash | |
| 56 // screen icon at the point just before the app icon is downloaded. | |
| 57 GURL icon_url = | |
| 58 ManifestIconSelector::FindBestMatchingIcon( | |
| 59 web_app_data().icons, | |
| 60 ideal_splash_icon_size_, | |
| 61 gfx::Screen::GetScreenFor(web_contents->GetNativeView())); | |
| 62 | |
| 63 if (!ManifestIconDownloader::Download( | |
| 64 web_contents, | |
| 65 icon_url, | |
| 66 ideal_splash_icon_size_, | |
| 67 base::Bind(&AppBannerDataFetcherAndroid::OnSplashIconFetched, | |
| 68 this))) { | |
| 69 OutputDeveloperNotShownMessage(web_contents, | |
| 70 kCannotDetermineBestSplashIcon); | |
| 71 Cancel(); | |
|
mlamouri (slow - plz ping)
2015/08/24 16:43:54
see below.
Lalit Maganti
2015/08/25 11:38:44
Acknowledged.
| |
| 72 } | |
| 73 } | |
| 74 | |
| 75 void AppBannerDataFetcherAndroid::OnSplashIconFetched(const SkBitmap& bitmap) { | |
| 76 if (!is_active()) return; | |
| 77 | |
| 78 content::WebContents* web_contents = GetWebContents(); | |
| 79 if (!CheckFetcherIsStillAlive(web_contents)) { | |
| 80 Cancel(); | |
| 81 return; | |
| 82 } | |
| 83 if (bitmap.drawsNothing()) { | |
| 84 OutputDeveloperNotShownMessage(web_contents, kNoSplashIconAvailable); | |
| 85 Cancel(); | |
|
mlamouri (slow - plz ping)
2015/08/24 16:43:54
You are making the splashscreen icon a requirement
Lalit Maganti
2015/08/25 11:38:44
Changed according to our discussions.
| |
| 86 return; | |
| 87 } | |
| 88 | |
| 89 splash_icon_.reset(new SkBitmap(bitmap)); | |
| 90 | |
| 91 // Continue the fetch cycle as normal. | |
| 92 AppBannerDataFetcher::OnHasServiceWorker(web_contents); | |
|
mlamouri (slow - plz ping)
2015/08/24 16:43:54
Maybe you could do something like:
void AppBanner
Lalit Maganti
2015/08/25 11:38:44
This code has been redone completely.
| |
| 93 } | |
| 94 | |
| 46 void AppBannerDataFetcherAndroid::ShowBanner(const SkBitmap* icon, | 95 void AppBannerDataFetcherAndroid::ShowBanner(const SkBitmap* icon, |
| 47 const base::string16& title, | 96 const base::string16& title, |
| 48 const std::string& referrer) { | 97 const std::string& referrer) { |
| 49 content::WebContents* web_contents = GetWebContents(); | 98 content::WebContents* web_contents = GetWebContents(); |
| 50 DCHECK(web_contents); | 99 DCHECK(web_contents); |
| 51 | 100 |
| 52 infobars::InfoBar* infobar = nullptr; | 101 infobars::InfoBar* infobar = nullptr; |
| 53 if (native_app_data_.is_null()) { | 102 if (native_app_data_.is_null()) { |
| 54 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 103 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 55 new AppBannerInfoBarDelegateAndroid( | 104 new AppBannerInfoBarDelegateAndroid( |
| 56 event_request_id(), title, new SkBitmap(*icon), web_app_data())); | 105 event_request_id(), title, splash_icon_.release(), |
| 106 new SkBitmap(*icon), web_app_data())); | |
| 57 | 107 |
| 58 infobar = | 108 infobar = |
| 59 new AppBannerInfoBarAndroid(delegate.Pass(), web_app_data().start_url); | 109 new AppBannerInfoBarAndroid(delegate.Pass(), web_app_data().start_url); |
| 60 if (infobar) { | 110 if (infobar) { |
| 61 RecordDidShowBanner("AppBanner.WebApp.Shown"); | 111 RecordDidShowBanner("AppBanner.WebApp.Shown"); |
| 62 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); | 112 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); |
| 63 } | 113 } |
| 64 } else { | 114 } else { |
| 65 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 115 scoped_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 66 new AppBannerInfoBarDelegateAndroid( | 116 new AppBannerInfoBarDelegateAndroid( |
| 67 event_request_id(), title, new SkBitmap(*icon), native_app_data_, | 117 event_request_id(), title, new SkBitmap(*icon), native_app_data_, |
| 68 native_app_package_, referrer)); | 118 native_app_package_, referrer)); |
| 69 infobar = new AppBannerInfoBarAndroid(delegate.Pass(), native_app_data_); | 119 infobar = new AppBannerInfoBarAndroid(delegate.Pass(), native_app_data_); |
| 70 if (infobar) { | 120 if (infobar) { |
| 71 RecordDidShowBanner("AppBanner.NativeApp.Shown"); | 121 RecordDidShowBanner("AppBanner.NativeApp.Shown"); |
| 72 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); | 122 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); |
| 73 } | 123 } |
| 74 } | 124 } |
| 75 InfoBarService::FromWebContents(web_contents) | 125 InfoBarService::FromWebContents(web_contents) |
| 76 ->AddInfoBar(make_scoped_ptr(infobar)); | 126 ->AddInfoBar(make_scoped_ptr(infobar)); |
| 77 } | 127 } |
| 78 | 128 |
| 79 } // namespace banners | 129 } // namespace banners |
| OLD | NEW |