favicon_types.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_FAVICON_BASE_FAVICON_TYPES_H_
  5. #define COMPONENTS_FAVICON_BASE_FAVICON_TYPES_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include "base/containers/flat_set.h"
  9. #include "base/memory/ref_counted_memory.h"
  10. #include "ui/gfx/geometry/size.h"
  11. #include "ui/gfx/image/image.h"
  12. #include "url/gurl.h"
  13. namespace favicon_base {
  14. struct FallbackIconStyle;
  15. using FaviconID = int64_t;
  16. // Defines the icon types.
  17. //
  18. // IMPORTANT: these values must stay in sync with the FaviconType enum in
  19. // tools/metrics/histograms/enum.xml.
  20. // When you update the types please also check if it needs to be reflected in
  21. // blink::mojom::FaviconIconType enums
  22. //
  23. // The values of the IconTypes are used to select the priority in which favicon
  24. // data is returned.
  25. //
  26. // A Java counterpart will be generated for this enum.
  27. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.favicon
  28. enum class IconType {
  29. kInvalid = 0,
  30. kFavicon,
  31. kTouchIcon,
  32. kTouchPrecomposedIcon,
  33. kWebManifestIcon,
  34. kMax = kWebManifestIcon,
  35. kCount
  36. };
  37. using IconTypeSet = base::flat_set<IconType>;
  38. // Defines a gfx::Image of size desired_size_in_dip composed of image
  39. // representations for each of the desired scale factors.
  40. struct FaviconImageResult {
  41. FaviconImageResult();
  42. ~FaviconImageResult();
  43. // The resulting image.
  44. gfx::Image image;
  45. // The URL of the favicon which contains all of the image representations of
  46. // |image|.
  47. // TODO(pkotwicz): Return multiple |icon_urls| to allow |image| to have
  48. // representations from several favicons once content::FaviconStatus supports
  49. // multiple URLs.
  50. GURL icon_url;
  51. };
  52. // Defines a favicon bitmap which best matches the desired DIP size and one of
  53. // the desired scale factors.
  54. struct FaviconRawBitmapResult {
  55. FaviconRawBitmapResult();
  56. FaviconRawBitmapResult(const FaviconRawBitmapResult& other);
  57. ~FaviconRawBitmapResult();
  58. // Returns true if |bitmap_data| contains a valid bitmap.
  59. bool is_valid() const { return bitmap_data.get() && bitmap_data->size(); }
  60. // Indicates whether |bitmap_data| is expired.
  61. bool expired;
  62. // The bits of the bitmap.
  63. scoped_refptr<base::RefCountedMemory> bitmap_data;
  64. // The pixel dimensions of |bitmap_data|.
  65. gfx::Size pixel_size;
  66. // The URL of the containing favicon.
  67. GURL icon_url;
  68. // The icon type of the containing favicon.
  69. IconType icon_type;
  70. // Indicates whether the bitmap was fetched upon visiting a page. Value
  71. // false means that it was fetched on-demand by the UI of chrome, without
  72. // visiting the page.
  73. bool fetched_because_of_page_visit;
  74. };
  75. // Define type with same structure as FaviconRawBitmapResult for passing data to
  76. // HistoryBackend::SetFavicons().
  77. using FaviconRawBitmapData = FaviconRawBitmapResult;
  78. // Result returned by LargeIconService::GetLargeIconOrFallbackStyle(). Contains
  79. // either the bitmap data if the favicon database has a sufficiently large
  80. // favicon bitmap and the style of the fallback icon otherwise.
  81. struct LargeIconResult {
  82. explicit LargeIconResult(const FaviconRawBitmapResult& bitmap_in);
  83. // Takes ownership of |fallback_icon_style_in|.
  84. explicit LargeIconResult(FallbackIconStyle* fallback_icon_style_in);
  85. ~LargeIconResult();
  86. // The bitmap from the favicon database if the database has a sufficiently
  87. // large one.
  88. FaviconRawBitmapResult bitmap;
  89. // The fallback icon style if a sufficiently large icon isn't available. This
  90. // uses the dominant color of a smaller icon as the background if available.
  91. std::unique_ptr<FallbackIconStyle> fallback_icon_style;
  92. };
  93. // Result returned by LargeIconService::GetLargeIconImageOrFallbackStyle().
  94. // Contains either the gfx::Image if the favicon database has a sufficiently
  95. // large favicon bitmap and the style of the fallback icon otherwise.
  96. struct LargeIconImageResult {
  97. explicit LargeIconImageResult(const gfx::Image& image_in,
  98. const GURL& icon_url_in);
  99. // Takes ownership of |fallback_icon_style_in|.
  100. explicit LargeIconImageResult(FallbackIconStyle* fallback_icon_style_in);
  101. ~LargeIconImageResult();
  102. // The image from the favicon database if the database has a sufficiently
  103. // large one.
  104. gfx::Image image;
  105. // The URL of the containing favicon. Specified only if |image| is not empty.
  106. GURL icon_url;
  107. // The fallback icon style if a sufficiently large icon isn't available. This
  108. // uses the dominant color of a smaller icon as the background if available.
  109. std::unique_ptr<FallbackIconStyle> fallback_icon_style;
  110. };
  111. // Enumeration listing all possible outcomes for fetch attempts from Google
  112. // favicon server. Used for UMA enum GoogleFaviconServerRequestStatus, so do not
  113. // change existing values. Insert new values at the end, and update the
  114. // histogram definition.
  115. enum class GoogleFaviconServerRequestStatus {
  116. // Request sent out and the favicon successfully fetched.
  117. SUCCESS = 0,
  118. // Request sent out and a connection error occurred (no valid HTTP response
  119. // recevied).
  120. FAILURE_CONNECTION_ERROR = 1,
  121. // Request sent out and a HTTP error received.
  122. FAILURE_HTTP_ERROR = 2,
  123. // Request not sent out (previous HTTP error in cache).
  124. FAILURE_HTTP_ERROR_CACHED = 3,
  125. // Request sent out and favicon fetched but writing to database failed.
  126. FAILURE_ON_WRITE = 4,
  127. // Request not sent out (the request or the fetcher was invalid).
  128. DEPRECATED_FAILURE_INVALID = 5,
  129. // Request not sent out (the target URL was an IP address or its scheme was
  130. // not http(s)).
  131. FAILURE_TARGET_URL_SKIPPED = 6,
  132. // Request not sent out (the target URL was not valid).
  133. FAILURE_TARGET_URL_INVALID = 7,
  134. // Request not sent out (the server URL was not valid).
  135. FAILURE_SERVER_URL_INVALID = 8,
  136. // Request not sent out (as there already is an icon in the local favicon
  137. // database that prevents a new one to be stored).
  138. FAILURE_ICON_EXISTS_IN_DB = 9,
  139. // Insert new values here.
  140. COUNT
  141. };
  142. } // namespace favicon_base
  143. #endif // COMPONENTS_FAVICON_BASE_FAVICON_TYPES_H_