summaryrefslogtreecommitdiffstats
path: root/components/favicon_base/fallback_icon_url_parser.h
blob: 5d5971e808f32b042cb4f25c60824c58914d69fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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.

#ifndef COMPONENTS_FAVICON_BASE_FALLBACK_ICON_URL_PARSER_H_
#define COMPONENTS_FAVICON_BASE_FALLBACK_ICON_URL_PARSER_H_

#include <string>

#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "components/favicon_base/fallback_icon_style.h"
#include "third_party/skia/include/core/SkColor.h"

namespace chrome {

class ParsedFallbackIconPath {
 public:
  ParsedFallbackIconPath();
  ~ParsedFallbackIconPath();

  const std::string& url_string() const { return url_string_; }

  int size_in_pixels() const { return size_in_pixels_; }

  const favicon_base::FallbackIconStyle& style() const { return style_; }

  size_t path_index() const { return path_index_; }

  // Parses |path|, which should be in the format described at the top of the
  // file "chrome/browser/ui/webui/fallback_icon_source.h".
  bool Parse(const std::string& path);

 private:
  // Parses |specs_str|, which should be the comma-separated value portion
  // in the format described at the top of the file
  // "chrome/browser/ui/webui/fallback_icon_source.h".
  static bool ParseSpecs(const std::string& specs_str,
                         int *size,
                         favicon_base::FallbackIconStyle* style);

  // Helper to parse color string (e.g., "red", "#f00", "#aB0137"). On success,
  // returns true and writes te result to |*color|.
  static bool ParseColor(const std::string& color_str, SkColor* color);

  friend class FallbackIconUrlParserTest;
  FRIEND_TEST_ALL_PREFIXES(FallbackIconUrlParserTest, ParseColorSuccess);
  FRIEND_TEST_ALL_PREFIXES(FallbackIconUrlParserTest, ParseColorFailure);
  FRIEND_TEST_ALL_PREFIXES(FallbackIconUrlParserTest, ParseSpecsEmpty);
  FRIEND_TEST_ALL_PREFIXES(FallbackIconUrlParserTest, ParseSpecsPartial);
  FRIEND_TEST_ALL_PREFIXES(FallbackIconUrlParserTest, ParseSpecsFull);
  FRIEND_TEST_ALL_PREFIXES(FallbackIconUrlParserTest, ParseSpecsFailure);

  // The page URL string the fallback icon is requested for.
  std::string url_string_;

  // The size of the requested fallback icon in pixels.
  int size_in_pixels_;

  // Styling specifications of fallback icon.
  favicon_base::FallbackIconStyle style_;

  // The index of the first character (relative to the path) where the the URL
  // from which the fallback icon is being requested is located.
  size_t path_index_;

  DISALLOW_COPY_AND_ASSIGN(ParsedFallbackIconPath);
};

}  // namespace chrome

#endif  // COMPONENTS_FAVICON_BASE_FALLBACK_ICON_URL_PARSER_H_