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/webapps/add_to_homescreen_data_fetcher.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 manifest.icons, ideal_icon_size_in_dp_, minimum_icon_size_in_dp_); | 119 manifest.icons, ideal_icon_size_in_dp_, minimum_icon_size_in_dp_); |
| 120 | 120 |
| 121 // If fetching the Manifest icon fails, fallback to the best favicon | 121 // If fetching the Manifest icon fails, fallback to the best favicon |
| 122 // for the page. | 122 // for the page. |
| 123 if (!ManifestIconDownloader::Download( | 123 if (!ManifestIconDownloader::Download( |
| 124 web_contents(), | 124 web_contents(), |
| 125 icon_src, | 125 icon_src, |
| 126 ideal_icon_size_in_dp_, | 126 ideal_icon_size_in_dp_, |
| 127 minimum_icon_size_in_dp_, | 127 minimum_icon_size_in_dp_, |
| 128 base::Bind(&AddToHomescreenDataFetcher::OnManifestIconFetched, | 128 base::Bind(&AddToHomescreenDataFetcher::OnManifestIconFetched, |
| 129 this))) { | 129 this, icon_src))) { |
| 130 FetchFavicon(); | 130 FetchFavicon(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Save the splash screen URL for the later download. | 133 // Save the splash screen URL for the later download. |
| 134 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( | 134 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( |
| 135 manifest.icons, ideal_splash_image_size_in_dp_, | 135 manifest.icons, ideal_splash_image_size_in_dp_, |
| 136 minimum_splash_image_size_in_dp_); | 136 minimum_splash_image_size_in_dp_); |
| 137 | 137 |
| 138 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); | 138 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); |
| 139 | 139 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 &icon_bitmap); | 229 &icon_bitmap); |
| 230 } | 230 } |
| 231 | 231 |
| 232 bool is_generated = false; | 232 bool is_generated = false; |
| 233 if (weak_observer_) { | 233 if (weak_observer_) { |
| 234 icon_bitmap = weak_observer_->FinalizeLauncherIcon(icon_bitmap, | 234 icon_bitmap = weak_observer_->FinalizeLauncherIcon(icon_bitmap, |
| 235 shortcut_info_.url, | 235 shortcut_info_.url, |
| 236 &is_generated); | 236 &is_generated); |
| 237 } | 237 } |
| 238 | 238 |
| 239 GURL icon_url = is_generated ? GURL() : bitmap_result.icon_url; | |
| 239 content::BrowserThread::PostTask( | 240 content::BrowserThread::PostTask( |
| 240 content::BrowserThread::UI, | 241 content::BrowserThread::UI, FROM_HERE, |
| 241 FROM_HERE, | 242 base::Bind(&AddToHomescreenDataFetcher::NotifyObserver, this, icon_url, |
| 242 base::Bind(&AddToHomescreenDataFetcher::NotifyObserver, | 243 icon_bitmap)); |
| 243 this, | |
| 244 icon_bitmap, | |
| 245 is_generated)); | |
| 246 } | 244 } |
| 247 | 245 |
|
dominickn
2016/06/16 21:16:36
Instead of passing icon_url through OnManifestIcon
| |
| 248 void AddToHomescreenDataFetcher::OnManifestIconFetched(const SkBitmap& icon) { | 246 void AddToHomescreenDataFetcher::OnManifestIconFetched(const GURL& icon_url, |
| 247 const SkBitmap& icon) { | |
| 249 if (icon.drawsNothing()) { | 248 if (icon.drawsNothing()) { |
| 250 FetchFavicon(); | 249 FetchFavicon(); |
| 251 return; | 250 return; |
| 252 } | 251 } |
| 253 NotifyObserver(icon, false); | 252 NotifyObserver(icon_url, icon); |
| 254 } | 253 } |
| 255 | 254 |
| 256 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& bitmap, | 255 void AddToHomescreenDataFetcher::NotifyObserver(const GURL& icon_url, |
| 257 bool is_generated) { | 256 const SkBitmap& bitmap) { |
| 258 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 257 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 259 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 258 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
| 260 return; | 259 return; |
| 261 | 260 |
| 262 is_icon_saved_ = true; | 261 is_icon_saved_ = true; |
| 262 shortcut_icon_url_ = icon_url; | |
| 263 shortcut_icon_ = bitmap; | 263 shortcut_icon_ = bitmap; |
| 264 shortcut_info_.is_icon_generated = is_generated; | |
| 265 is_ready_ = true; | 264 is_ready_ = true; |
| 266 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); | 265 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_url_, |
| 266 shortcut_icon_); | |
| 267 } | 267 } |
| 268 | 268 |
| 269 GURL AddToHomescreenDataFetcher::GetShortcutUrl(const GURL& actual_url) { | 269 GURL AddToHomescreenDataFetcher::GetShortcutUrl(const GURL& actual_url) { |
| 270 GURL original_url = | 270 GURL original_url = |
| 271 dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); | 271 dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); |
| 272 | 272 |
| 273 // If URL points to an offline content, get original URL. | 273 // If URL points to an offline content, get original URL. |
| 274 GURL online_url = | 274 GURL online_url = |
| 275 offline_pages::OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( | 275 offline_pages::OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( |
| 276 web_contents()->GetBrowserContext(), original_url); | 276 web_contents()->GetBrowserContext(), original_url); |
| 277 if (online_url.is_valid()) | 277 if (online_url.is_valid()) |
| 278 return online_url; | 278 return online_url; |
| 279 | 279 |
| 280 return original_url; | 280 return original_url; |
| 281 } | 281 } |
| OLD | NEW |