Commit 2b99deca authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Extract GetLetterForIcon util and use SizesToGenerate utility function.

In WebAppDataRetriver.

Bug: 901226
Change-Id: I4db47a0e51c6f6aa89fbfe0fa502e08aeb4036aa
Reviewed-on: https://chromium-review.googlesource.com/c/1341285
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609170}
parent 6bdcbcc1
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/web_applications/components/web_app_data_retriever.h" #include "chrome/browser/web_applications/components/web_app_data_retriever.h"
#include <memory> #include <memory>
#include <set>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
#include "chrome/browser/installable/installable_data.h" #include "chrome/browser/installable/installable_data.h"
#include "chrome/browser/installable/installable_manager.h" #include "chrome/browser/installable/installable_manager.h"
#include "chrome/browser/web_applications/components/web_app_icon_generator.h" #include "chrome/browser/web_applications/components/web_app_icon_generator.h"
#include "chrome/browser/web_applications/components/web_app_install_utils.h"
#include "chrome/common/chrome_render_frame.mojom.h" #include "chrome/common/chrome_render_frame.mojom.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
...@@ -26,6 +28,29 @@ ...@@ -26,6 +28,29 @@
namespace web_app { namespace web_app {
namespace {
char GetLetterForIcon(const GURL& app_url) {
char icon_letter = ' ';
std::string domain_and_registry(
net::registry_controlled_domains::GetDomainAndRegistry(
app_url,
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
// TODO(crbug.com/867311): Decode the app URL or the domain before retrieving
// the first character, otherwise we generate an icon with "x" if the domain
// or app URL starts with a UTF-8 character.
if (!domain_and_registry.empty()) {
icon_letter = domain_and_registry[0];
} else if (app_url.has_host()) {
icon_letter = app_url.host_piece()[0];
}
DCHECK(icon_letter >= '!' && icon_letter <= '~');
return icon_letter;
}
} // namespace
WebAppDataRetriever::WebAppDataRetriever() = default; WebAppDataRetriever::WebAppDataRetriever() = default;
WebAppDataRetriever::~WebAppDataRetriever() = default; WebAppDataRetriever::~WebAppDataRetriever() = default;
...@@ -90,31 +115,11 @@ void WebAppDataRetriever::GetIcons(const GURL& app_url, ...@@ -90,31 +115,11 @@ void WebAppDataRetriever::GetIcons(const GURL& app_url,
GetIconsCallback callback) { GetIconsCallback callback) {
// TODO(crbug.com/864904): Download icons using |icon_urls|. // TODO(crbug.com/864904): Download icons using |icon_urls|.
// Generate missing icons. const char icon_letter = GetLetterForIcon(app_url);
static constexpr int kIconSizesToGenerate[] = { const std::set<int> sizes_to_generate = SizesToGenerate();
icon_size::k32, icon_size::k64, icon_size::k48,
icon_size::k96, icon_size::k128, icon_size::k256,
};
// Get the letter to use in the generated icon.
char icon_letter = ' ';
std::string domain_and_registry(
net::registry_controlled_domains::GetDomainAndRegistry(
app_url,
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
// TODO(crbug.com/867311): Decode the app URL or the domain before retrieving
// the first character, otherwise we generate an icon with "x" if the domain
// or app URL starts with a UTF-8 character.
if (!domain_and_registry.empty()) {
icon_letter = domain_and_registry[0];
} else if (app_url.has_host()) {
icon_letter = app_url.host_piece()[0];
}
DCHECK(icon_letter >= '!' && icon_letter <= '~');
std::vector<WebApplicationInfo::IconInfo> icons; std::vector<WebApplicationInfo::IconInfo> icons;
for (int size : kIconSizesToGenerate) { for (int size : sizes_to_generate) {
WebApplicationInfo::IconInfo icon_info; WebApplicationInfo::IconInfo icon_info;
icon_info.width = size; icon_info.width = size;
icon_info.height = size; icon_info.height = size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment