Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / favicon / chrome_fallback_icon_client.cc
blob292625e9779484492704f2511e44fd45cfefa7c6
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
3 // found in the LICENSE file.
5 #include "chrome/browser/favicon/chrome_fallback_icon_client.h"
7 #include "base/i18n/case_conversion.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "grit/platform_locale_settings.h"
10 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "url/gurl.h"
14 namespace {
15 const char* kFallbackIconTextForIP = "IP";
16 } // namespace
18 ChromeFallbackIconClient::ChromeFallbackIconClient() {
19 #if defined(OS_CHROMEOS)
20 font_list_.push_back("Noto Sans");
21 #elif defined(OS_IOS)
22 font_list_.push_back("Helvetica Neue");
23 #else
24 font_list_.push_back(l10n_util::GetStringUTF8(IDS_SANS_SERIF_FONT_FAMILY));
25 #endif
28 ChromeFallbackIconClient::~ChromeFallbackIconClient() {
31 const std::vector<std::string>& ChromeFallbackIconClient::GetFontNameList()
32 const {
33 return font_list_;
36 // Returns a single character to represent |url|. To do this we take the first
37 // letter in a domain's name and make it upper case.
38 base::string16 ChromeFallbackIconClient::GetFallbackIconText(const GURL& url)
39 const {
40 if (url.is_empty())
41 return base::string16();
42 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
43 url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
44 if (domain.empty()) { // E.g., http://localhost/ or http://192.168.0.1/
45 if (url.HostIsIPAddress())
46 return base::ASCIIToUTF16(kFallbackIconTextForIP);
47 domain = url.host();
49 if (domain.empty())
50 return base::string16();
51 // TODO(huangs): Handle non-ASCII ("xn--") domain names.
52 return base::i18n::ToUpper(base::ASCIIToUTF16(domain.substr(0, 1)));