Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / manifest / manifest_icon_selector.h
bloba2b5c24d5d8963a79410cfccaf569da4ec76151f
1 // Copyright 2015 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.
5 #ifndef CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_
6 #define CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_
8 #include "base/basictypes.h"
9 #include "content/public/common/manifest.h"
10 #include "url/gurl.h"
12 namespace content {
13 class WebContents;
14 } // namespace content
16 namespace IPC {
17 class Message;
18 } // namespace IPC
20 namespace gfx {
21 class Screen;
24 // Selects the icon most closely matching the size constraints. This follows
25 // very basic heuristics -- improvements are welcome.
26 class ManifestIconSelector {
27 public:
28 // Runs the algorithm to find the best matching icon in the icons listed in
29 // the Manifest.
31 // Size is defined in Android's density-independent pixels (dp):
32 // http://developer.android.com/guide/practices/screens_support.html
33 // If/when this class is generalized, it may be a good idea to switch this to
34 // taking in pixels, instead.
36 // Any icon returned will be close as possible to |ideal_icon_size_in_dp|
37 // with a size not less than |minimum_icon_size_in_dp|.
39 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
40 static GURL FindBestMatchingIcon(
41 const std::vector<content::Manifest::Icon>& icons,
42 int ideal_icon_size_in_dp,
43 int minimum_icon_size_in_dp,
44 const gfx::Screen* screen);
46 private:
47 ManifestIconSelector(int ideal_icon_size_in_px,
48 int minimum_icon_size_in_px);
49 virtual ~ManifestIconSelector() {}
51 // Runs the algorithm to find the best matching icon in the icons listed in
52 // the Manifest.
53 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
54 int FindBestMatchingIcon(
55 const std::vector<content::Manifest::Icon>& icons,
56 float density);
58 // Runs an algorithm only based on icon declared sizes. It will try to find
59 // size that is the closest to preferred_icon_size_in_pixels_ but bigger than
60 // preferred_icon_size_in_pixels_ if possible.
61 // Returns the index of a suitable icon if one is found. -1 otherwise.
62 int FindBestMatchingIconForDensity(
63 const std::vector<content::Manifest::Icon>& icons,
64 float density);
66 // Returns whether the |preferred_icon_size_in_pixels_| is in |sizes|.
67 bool IconSizesContainsPreferredSize(const std::vector<gfx::Size>& sizes);
69 // Returns whether a size bigger than |minimun_icon_size_in_pixels_| is in
70 // |sizes|.
71 bool IconSizesContainsBiggerThanMinimumSize(
72 const std::vector<gfx::Size>& sizes);
74 // Returns an array containing the items in |icons| without the unsupported
75 // image MIME types.
76 static std::vector<content::Manifest::Icon> FilterIconsByType(
77 const std::vector<content::Manifest::Icon>& icons);
79 // Returns whether the 'any' (ie. gfx::Size(0,0)) is in |sizes|.
80 static bool IconSizesContainsAny(const std::vector<gfx::Size>& sizes);
82 const int ideal_icon_size_in_px_;
83 const int minimum_icon_size_in_px_;
85 friend class ManifestIconSelectorTest;
87 DISALLOW_COPY_AND_ASSIGN(ManifestIconSelector);
90 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_