File: favicon_types.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (182 lines) | stat: -rw-r--r-- 6,227 bytes parent folder | download | duplicates (6)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_FAVICON_BASE_FAVICON_TYPES_H_
#define COMPONENTS_FAVICON_BASE_FAVICON_TYPES_H_

#include <stdint.h>

#include <memory>

#include "base/containers/flat_set.h"
#include "base/memory/ref_counted_memory.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h"
#include "url/gurl.h"

namespace favicon_base {

struct FallbackIconStyle;

using FaviconID = int64_t;

// Defines the icon types.
//
// IMPORTANT: these values must stay in sync with the FaviconType enum in
// tools/metrics/histograms/enums.xml.
// When you update the types please also check if it needs to be reflected in
// blink::mojom::FaviconIconType enums
//
// The values of the IconTypes are used to select the priority in which favicon
// data is returned.
//
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.favicon
enum class IconType {
  kInvalid = 0,
  kFavicon,
  kTouchIcon,
  kTouchPrecomposedIcon,
  kWebManifestIcon,
  kMax = kWebManifestIcon,
  kCount
};

using IconTypeSet = base::flat_set<IconType>;

// Defines a gfx::Image of size desired_size_in_dip composed of image
// representations for each of the desired scale factors.
struct FaviconImageResult {
  FaviconImageResult();
  ~FaviconImageResult();

  // The resulting image.
  gfx::Image image;

  // The URL of the favicon which contains all of the image representations of
  // |image|.
  // TODO(pkotwicz): Return multiple |icon_urls| to allow |image| to have
  // representations from several favicons once content::FaviconStatus supports
  // multiple URLs.
  GURL icon_url;
};

// Defines a favicon bitmap which best matches the desired DIP size and one of
// the desired scale factors.
struct FaviconRawBitmapResult {
  FaviconRawBitmapResult();
  FaviconRawBitmapResult(const FaviconRawBitmapResult& other);
  ~FaviconRawBitmapResult();

  // Returns true if |bitmap_data| contains a valid bitmap.
  bool is_valid() const { return bitmap_data.get() && bitmap_data->size(); }

  // Indicates whether |bitmap_data| is expired.
  bool expired;

  // The bits of the bitmap.
  scoped_refptr<base::RefCountedMemory> bitmap_data;

  // The pixel dimensions of |bitmap_data|.
  gfx::Size pixel_size;

  // The URL of the containing favicon.
  GURL icon_url;

  // The icon type of the containing favicon.
  IconType icon_type;

  // Indicates whether the bitmap was fetched upon visiting a page. Value
  // false means that it was fetched on-demand by the UI of chrome, without
  // visiting the page.
  bool fetched_because_of_page_visit;
};

// Define type with same structure as FaviconRawBitmapResult for passing data to
// HistoryBackend::SetFavicons().
using FaviconRawBitmapData = FaviconRawBitmapResult;

// Result returned by LargeIconService::GetLargeIconOrFallbackStyle(). Contains
// either the bitmap data if the favicon database has a sufficiently large
// favicon bitmap and the style of the fallback icon otherwise.
struct LargeIconResult {
  explicit LargeIconResult(const FaviconRawBitmapResult& bitmap_in);

  explicit LargeIconResult(
      std::unique_ptr<FallbackIconStyle> fallback_icon_style_in);

  ~LargeIconResult();

  LargeIconResult(LargeIconResult&& result);

  // The bitmap from the favicon database if the database has a sufficiently
  // large one.
  FaviconRawBitmapResult bitmap;

  // The fallback icon style if a sufficiently large icon isn't available. This
  // uses the dominant color of a smaller icon as the background if available.
  std::unique_ptr<FallbackIconStyle> fallback_icon_style;
};

// Result returned by LargeIconService::GetLargeIconImageOrFallbackStyle().
// Contains either the gfx::Image if the favicon database has a sufficiently
// large favicon bitmap and the style of the fallback icon otherwise.
struct LargeIconImageResult {
  explicit LargeIconImageResult(const gfx::Image& image_in,
                                const GURL& icon_url_in);

  // Takes ownership of |fallback_icon_style_in|.
  explicit LargeIconImageResult(
      std::unique_ptr<FallbackIconStyle> fallback_icon_style_in);

  ~LargeIconImageResult();

  // The image from the favicon database if the database has a sufficiently
  // large one.
  gfx::Image image;

  // The URL of the containing favicon. Specified only if |image| is not empty.
  GURL icon_url;

  // The fallback icon style if a sufficiently large icon isn't available. This
  // uses the dominant color of a smaller icon as the background if available.
  std::unique_ptr<FallbackIconStyle> fallback_icon_style;
};

// Enumeration listing all possible outcomes for fetch attempts from Google
// favicon server. Used for UMA enum GoogleFaviconServerRequestStatus, so do not
// change existing values. Insert new values at the end, and update the
// histogram definition.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.favicon
enum class GoogleFaviconServerRequestStatus {
  // Request sent out and the favicon successfully fetched.
  SUCCESS = 0,
  // Request sent out and a connection error occurred (no valid HTTP response
  // recevied).
  FAILURE_CONNECTION_ERROR = 1,
  // Request sent out and a HTTP error received.
  FAILURE_HTTP_ERROR = 2,
  // Request not sent out (previous HTTP error in cache).
  FAILURE_HTTP_ERROR_CACHED = 3,
  // Request sent out and favicon fetched but writing to database failed.
  FAILURE_ON_WRITE = 4,
  // Request not sent out (the request or the fetcher was invalid).
  DEPRECATED_FAILURE_INVALID = 5,
  // Request not sent out (the target URL was an IP address or its scheme was
  // not http(s)).
  FAILURE_TARGET_URL_SKIPPED = 6,
  // Request not sent out (the target URL was not valid).
  FAILURE_TARGET_URL_INVALID = 7,
  // Request not sent out (the server URL was not valid).
  FAILURE_SERVER_URL_INVALID = 8,
  // Request not sent out (as there already is an icon in the local favicon
  // database that prevents a new one to be stored).
  FAILURE_ICON_EXISTS_IN_DB = 9,
  // Insert new values here.
  COUNT
};

}  // namespace favicon_base

#endif  // COMPONENTS_FAVICON_BASE_FAVICON_TYPES_H_