| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/installable/installable_manager.h" | 5 #include "chrome/browser/installable/installable_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/bind.h" | 7 #include "base/bind.h" |
| 10 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 12 #include "chrome/browser/manifest/manifest_icon_downloader.h" | 10 #include "chrome/browser/manifest/manifest_icon_downloader.h" |
| 13 #include "chrome/browser/manifest/manifest_icon_selector.h" | 11 #include "chrome/browser/manifest/manifest_icon_selector.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ssl/security_state_tab_helper.h" | 13 #include "chrome/browser/ssl/security_state_tab_helper.h" |
| 16 #include "components/security_state/core/security_state.h" | 14 #include "components/security_state/core/security_state.h" |
| 17 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 void InstallableManager::CheckAndFetchBestIcon(const IconParams& params) { | 430 void InstallableManager::CheckAndFetchBestIcon(const IconParams& params) { |
| 433 DCHECK(!manifest().IsEmpty()); | 431 DCHECK(!manifest().IsEmpty()); |
| 434 | 432 |
| 435 int ideal_icon_size_in_px = std::get<0>(params); | 433 int ideal_icon_size_in_px = std::get<0>(params); |
| 436 int minimum_icon_size_in_px = std::get<1>(params); | 434 int minimum_icon_size_in_px = std::get<1>(params); |
| 437 IconPurpose icon_purpose = std::get<2>(params); | 435 IconPurpose icon_purpose = std::get<2>(params); |
| 438 | 436 |
| 439 IconProperty& icon = icons_[params]; | 437 IconProperty& icon = icons_[params]; |
| 440 icon.fetched = true; | 438 icon.fetched = true; |
| 441 | 439 |
| 442 // Filter by icon purpose. | |
| 443 std::vector<content::Manifest::Icon> filtered_icons; | |
| 444 std::copy_if(manifest().icons.begin(), manifest().icons.end(), | |
| 445 std::back_inserter(filtered_icons), | |
| 446 [icon_purpose](const content::Manifest::Icon& icon) { | |
| 447 return base::ContainsValue(icon.purpose, icon_purpose); | |
| 448 }); | |
| 449 | |
| 450 GURL icon_url = ManifestIconSelector::FindBestMatchingIcon( | 440 GURL icon_url = ManifestIconSelector::FindBestMatchingIcon( |
| 451 filtered_icons, ideal_icon_size_in_px, minimum_icon_size_in_px); | 441 manifest().icons, ideal_icon_size_in_px, minimum_icon_size_in_px, |
| 442 icon_purpose); |
| 452 | 443 |
| 453 if (icon_url.is_empty()) { | 444 if (icon_url.is_empty()) { |
| 454 icon.error = NO_ACCEPTABLE_ICON; | 445 icon.error = NO_ACCEPTABLE_ICON; |
| 455 } else { | 446 } else { |
| 456 bool can_download_icon = ManifestIconDownloader::Download( | 447 bool can_download_icon = ManifestIconDownloader::Download( |
| 457 GetWebContents(), icon_url, ideal_icon_size_in_px, | 448 GetWebContents(), icon_url, ideal_icon_size_in_px, |
| 458 minimum_icon_size_in_px, | 449 minimum_icon_size_in_px, |
| 459 base::Bind(&InstallableManager::OnIconFetched, | 450 base::Bind(&InstallableManager::OnIconFetched, |
| 460 weak_factory_.GetWeakPtr(), icon_url, params)); | 451 weak_factory_.GetWeakPtr(), icon_url, params)); |
| 461 if (can_download_icon) | 452 if (can_download_icon) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 return manifest_->url; | 491 return manifest_->url; |
| 501 } | 492 } |
| 502 | 493 |
| 503 const content::Manifest& InstallableManager::manifest() const { | 494 const content::Manifest& InstallableManager::manifest() const { |
| 504 return manifest_->manifest; | 495 return manifest_->manifest; |
| 505 } | 496 } |
| 506 | 497 |
| 507 bool InstallableManager::is_installable() const { | 498 bool InstallableManager::is_installable() const { |
| 508 return installable_->installable; | 499 return installable_->installable; |
| 509 } | 500 } |
| OLD | NEW |