| Index: components/favicon_base/large_icon_url_parser.cc
|
| diff --git a/components/favicon_base/large_icon_url_parser.cc b/components/favicon_base/large_icon_url_parser.cc
|
| index 9f1a9ac80a4e2014e3ebdb6fe5db53fecafb5cb8..7150393df9a464047553fe4063bfe5dc10d75553 100644
|
| --- a/components/favicon_base/large_icon_url_parser.cc
|
| +++ b/components/favicon_base/large_icon_url_parser.cc
|
| @@ -2,42 +2,65 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "components/favicon_base/large_icon_url_parser.h"
|
|
|
| #include "base/logging.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_split.h"
|
| #include "base/strings/string_util.h"
|
| +#include "components/favicon_base/fallback_icon_url_parser.h"
|
| +#include "components/favicon_base/large_icon_url_parser.h"
|
| #include "third_party/skia/include/utils/SkParse.h"
|
| #include "ui/gfx/favicon_size.h"
|
|
|
| +using chrome::ParsedFallbackIconPath;
|
| +
|
| +const char kFallbackIconParameter[] = "fallback/";
|
| +
|
| LargeIconUrlParser::LargeIconUrlParser() : size_in_pixels_(48) {
|
| }
|
|
|
| LargeIconUrlParser::~LargeIconUrlParser() {
|
| }
|
|
|
| -bool LargeIconUrlParser::Parse(base::StringPiece path) {
|
| +bool LargeIconUrlParser::Parse(std::string path) {
|
| if (path.empty())
|
| return false;
|
|
|
| size_t slash = path.find("/", 0); // |path| does not start with '/'.
|
| - if (slash == base::StringPiece::npos)
|
| + if (slash == std::string::npos)
|
| return false;
|
| - base::StringPiece size_str = path.substr(0, slash);
|
| +
|
| + std::string size_str = path.substr(0, slash);
|
| // Disallow empty, non-numeric, or non-positive sizes.
|
| - if (size_str.empty() ||
|
| - !base::StringToInt(size_str, &size_in_pixels_) ||
|
| + if (size_str.empty() || !base::StringToInt(size_str, &size_in_pixels_) ||
|
| size_in_pixels_ <= 0)
|
| return false;
|
|
|
| + path_index_ = slash + 1;
|
| + // If the content of |kFallbackIconParameter| goes after the size, parse the
|
| + // parameters of an fallback icon. Example:
|
| + // 'chrome://large-icon/16/fallback/,777,FFF,0.625,0.4/http://google.com'.
|
| + if (path.compare(path_index_, strlen(kFallbackIconParameter),
|
| + kFallbackIconParameter) == 0) {
|
| + path_index_ += strlen(kFallbackIconParameter);
|
| + slash = path.find("/", path_index_);
|
| + // The size of icon was set before. Ignore output of ParseSpecs.
|
| + int ignored_icon_size;
|
| + if (slash == std::string::npos ||
|
| + !ParsedFallbackIconPath::ParseSpecs(
|
| + path.substr(path_index_, slash - path_index_), &ignored_icon_size,
|
| + &fallback_icon_style_)) {
|
| + return false;
|
| + }
|
| + path_index_ = slash + 1;
|
| + }
|
| +
|
| // Need to store the index of the URL field, so Instant Extended can translate
|
| // large icon URLs using advanced parameters.
|
| // Example:
|
| // "chrome-search://large-icon/48/<renderer-id>/<most-visited-id>"
|
| // would be translated to:
|
| // "chrome-search://large-icon/48/<most-visited-item-with-given-id>".
|
| - path_index_ = slash + 1;
|
| - url_string_ = path.substr(path_index_).as_string();
|
| + url_string_ = path.substr(path_index_);
|
| return true;
|
| }
|
|
|