OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/bookmark_app_helper.h" | 5 #include "chrome/browser/extensions/bookmark_app_helper.h" |
6 | 6 |
7 #include <cctype> | 7 #include <cctype> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 } | 428 } |
429 return false; | 429 return false; |
430 } | 430 } |
431 | 431 |
432 // static | 432 // static |
433 std::map<int, BookmarkAppHelper::BitmapAndSource> | 433 std::map<int, BookmarkAppHelper::BitmapAndSource> |
434 BookmarkAppHelper::ResizeIconsAndGenerateMissing( | 434 BookmarkAppHelper::ResizeIconsAndGenerateMissing( |
435 std::vector<BookmarkAppHelper::BitmapAndSource> icons, | 435 std::vector<BookmarkAppHelper::BitmapAndSource> icons, |
436 std::set<int> sizes_to_generate, | 436 std::set<int> sizes_to_generate, |
437 WebApplicationInfo* web_app_info) { | 437 WebApplicationInfo* web_app_info) { |
438 // Add the downloaded icons. Extensions only allow certain icon sizes. First | 438 // Resize provided icons to make sure we have versions for each size in |
439 // populate icons that match the allowed sizes exactly and then downscale | 439 // |sizes_to_generate|. |
440 // remaining icons to the closest allowed size that doesn't yet have an icon. | 440 std::map<int, BitmapAndSource> resized_bitmaps( |
441 std::set<int> allowed_sizes(extension_misc::kExtensionIconSizes, | 441 ConstrainBitmapsToSizes(icons, sizes_to_generate)); |
442 extension_misc::kExtensionIconSizes + | |
443 extension_misc::kNumExtensionIconSizes); | |
444 | 442 |
445 // If there are icons that don't match the accepted icon sizes, find the | 443 // Also add all provided icon sizes. |
446 // closest bigger icon to the accepted sizes and resize the icon to it. | 444 for (const BitmapAndSource& icon : icons) { |
447 std::map<int, BitmapAndSource> resized_bitmaps( | 445 if (resized_bitmaps.find(icon.bitmap.width()) == resized_bitmaps.end()) |
448 ConstrainBitmapsToSizes(icons, allowed_sizes)); | 446 resized_bitmaps.insert(std::make_pair(icon.bitmap.width(), icon)); |
447 } | |
449 | 448 |
450 // Determine the color that will be used for the icon's background. For this | 449 // Determine the color that will be used for the icon's background. For this |
451 // the dominant color of the first icon found is used. | 450 // the dominant color of the first icon found is used. |
452 if (resized_bitmaps.size()) { | 451 if (resized_bitmaps.size()) { |
453 color_utils::GridSampler sampler; | 452 color_utils::GridSampler sampler; |
454 web_app_info->generated_icon_color = | 453 web_app_info->generated_icon_color = |
455 color_utils::CalculateKMeanColorOfBitmap( | 454 color_utils::CalculateKMeanColorOfBitmap( |
456 resized_bitmaps.begin()->second.bitmap); | 455 resized_bitmaps.begin()->second.bitmap); |
457 } | 456 } |
458 | 457 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 if (!extension->from_bookmark()) { | 769 if (!extension->from_bookmark()) { |
771 callback.Run(WebApplicationInfo()); | 770 callback.Run(WebApplicationInfo()); |
772 return; | 771 return; |
773 } | 772 } |
774 | 773 |
775 WebApplicationInfo web_app_info; | 774 WebApplicationInfo web_app_info; |
776 web_app_info.app_url = AppLaunchInfo::GetLaunchWebURL(extension); | 775 web_app_info.app_url = AppLaunchInfo::GetLaunchWebURL(extension); |
777 web_app_info.title = base::UTF8ToUTF16(extension->non_localized_name()); | 776 web_app_info.title = base::UTF8ToUTF16(extension->non_localized_name()); |
778 web_app_info.description = base::UTF8ToUTF16(extension->description()); | 777 web_app_info.description = base::UTF8ToUTF16(extension->description()); |
779 | 778 |
779 const ExtensionIconSet& icon_set = extensions::IconsInfo::GetIcons(extension); | |
780 std::vector<extensions::ImageLoader::ImageRepresentation> info_list; | 780 std::vector<extensions::ImageLoader::ImageRepresentation> info_list; |
781 for (size_t i = 0; i < extension_misc::kNumExtensionIconSizes; ++i) { | 781 for (const auto& iter : icon_set.map()) { |
782 int size = extension_misc::kExtensionIconSizes[i]; | 782 int size = iter.first; |
783 extensions::ExtensionResource resource = | 783 extensions::ExtensionResource resource = |
784 extensions::IconsInfo::GetIconResource( | 784 extensions::IconsInfo::GetIconResource( |
785 extension, size, ExtensionIconSet::MATCH_EXACTLY); | 785 extension, size, ExtensionIconSet::MATCH_EXACTLY); |
Devlin
2015/12/07 20:37:19
I'm pretty sure this is the same as
resource = ext
Evan Stade
2015/12/07 20:52:48
seems true, changed.
| |
786 if (!resource.empty()) { | 786 if (!resource.empty()) { |
787 info_list.push_back(extensions::ImageLoader::ImageRepresentation( | 787 info_list.push_back(extensions::ImageLoader::ImageRepresentation( |
788 resource, | 788 resource, |
789 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, | 789 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, |
790 gfx::Size(size, size), | 790 gfx::Size(size, size), |
791 ui::SCALE_FACTOR_100P)); | 791 ui::SCALE_FACTOR_100P)); |
792 } | 792 } |
793 } | 793 } |
794 | 794 |
795 extensions::ImageLoader::Get(browser_context)->LoadImageFamilyAsync( | 795 extensions::ImageLoader::Get(browser_context)->LoadImageFamilyAsync( |
796 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback)); | 796 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback)); |
797 } | 797 } |
798 | 798 |
799 bool IsValidBookmarkAppUrl(const GURL& url) { | 799 bool IsValidBookmarkAppUrl(const GURL& url) { |
800 URLPattern origin_only_pattern(Extension::kValidBookmarkAppSchemes); | 800 URLPattern origin_only_pattern(Extension::kValidBookmarkAppSchemes); |
801 origin_only_pattern.SetMatchAllURLs(true); | 801 origin_only_pattern.SetMatchAllURLs(true); |
802 return url.is_valid() && origin_only_pattern.MatchesURL(url); | 802 return url.is_valid() && origin_only_pattern.MatchesURL(url); |
803 } | 803 } |
804 | 804 |
805 } // namespace extensions | 805 } // namespace extensions |
OLD | NEW |