Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Unified Diff: chrome/common/favicon/fallback_icon_url_parser.cc

Issue 989183003: Revert of [Fallback icons] Change "explicit flow" interface so color hex strings don't use "#". Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/favicon/fallback_icon_url_parser.cc
diff --git a/chrome/common/favicon/fallback_icon_url_parser.cc b/chrome/common/favicon/fallback_icon_url_parser.cc
index 3f6105d4ba2087f38eed3e1d6fb70253aab1d969..418617f46fec37ecc6fc13fa3289667f45ccbaea 100644
--- a/chrome/common/favicon/fallback_icon_url_parser.cc
+++ b/chrome/common/favicon/fallback_icon_url_parser.cc
@@ -7,25 +7,8 @@
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
-#include "base/strings/string_util.h"
#include "third_party/skia/include/utils/SkParse.h"
#include "ui/gfx/favicon_size.h"
-
-namespace {
-
-// Returns whether |color_str| is a valid CSS color in hex format if we prepend
-// '#', i.e., whether |color_str| matches /^[0-9A-Fa-f]{3,4,6,8}$/.
-bool IsHexColorString(const std::string& color_str) {
- size_t len = color_str.length();
- if (len != 3 && len != 4 && len != 6 && len != 8)
- return false;
- for (auto ch : color_str)
- if (!IsHexDigit(ch))
- return false;
- return true;
-}
-
-} // namespace
namespace chrome {
@@ -93,23 +76,9 @@
// static
bool ParsedFallbackIconPath::ParseColor(const std::string& color_str,
SkColor* color) {
- // Exclude empty case. Also disallow '#' prefix since '#' is used to specify
- // ref fragment in an URL, and so we want to avoid using it.
- if (color_str.empty() || color_str[0] == '#')
- return false;
- // Force alpha = 0xFF since SkParse::FindColor() preserves unspecified alpha.
- SkColor temp_color = SK_ColorWHITE;
- // Prepend '#' if color hex string is given. This is unambiguous because no
- // named color consists of leters 'a' to 'f' only.
- const char* end = IsHexColorString(color_str) ?
- SkParse::FindColor(("#" + color_str).c_str(), &temp_color) :
- SkParse::FindColor(color_str.c_str(), &temp_color);
- // Successful if FindColor() succeeds and |color_str| is completely consumed.
- if (end && !*end) {
- *color = temp_color;
- return true;
- }
- return false;
+ const char* end = SkParse::FindColor(color_str.c_str(), color);
+ // Return true if FindColor() succeeds and |color_str| is entirely consumed.
+ return end && !*end;
}
} // namespace chrome
« no previous file with comments | « chrome/common/favicon/fallback_icon_url_parser.h ('k') | chrome/common/favicon/fallback_icon_url_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698