diff options
author | blundell <blundell@chromium.org> | 2015-07-08 03:07:45 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-08 10:08:22 +0000 |
commit | ee0ade20e42f6ff67ec7402c80610e3d0b7f960a (patch) | |
tree | 60056d8d047c4bf82f6bf31ce0ec8ca286ef268c /components/favicon_base/large_icon_url_parser.cc | |
parent | 0c714f7ca6d4f027501aa8ef8ae91ebc99788b62 (diff) | |
download | chromium_src-ee0ade20e42f6ff67ec7402c80610e3d0b7f960a.zip chromium_src-ee0ade20e42f6ff67ec7402c80610e3d0b7f960a.tar.gz chromium_src-ee0ade20e42f6ff67ec7402c80610e3d0b7f960a.tar.bz2 |
Componentize //chrome/common/favicon
This code is used by iOS; move it into //components/favicon_base.
TBR=sky, rdsmith
Review URL: https://codereview.chromium.org/1223603002
Cr-Commit-Position: refs/heads/master@{#337794}
Diffstat (limited to 'components/favicon_base/large_icon_url_parser.cc')
-rw-r--r-- | components/favicon_base/large_icon_url_parser.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/components/favicon_base/large_icon_url_parser.cc b/components/favicon_base/large_icon_url_parser.cc new file mode 100644 index 0000000..9f1a9ac --- /dev/null +++ b/components/favicon_base/large_icon_url_parser.cc @@ -0,0 +1,43 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// 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 "third_party/skia/include/utils/SkParse.h" +#include "ui/gfx/favicon_size.h" + +LargeIconUrlParser::LargeIconUrlParser() : size_in_pixels_(48) { +} + +LargeIconUrlParser::~LargeIconUrlParser() { +} + +bool LargeIconUrlParser::Parse(base::StringPiece path) { + if (path.empty()) + return false; + + size_t slash = path.find("/", 0); // |path| does not start with '/'. + if (slash == base::StringPiece::npos) + return false; + base::StringPiece 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_) || + size_in_pixels_ <= 0) + return false; + + // 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(); + return true; +} |