blob: c0c582d729c26cf2440f97cedfa247aed36ea4f5 (
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
73
74
75
76
77
78
79
|
// 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 CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_
#define CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_
#include "base/basictypes.h"
#include "content/public/common/manifest.h"
#include "url/gurl.h"
namespace content {
class WebContents;
} // namespace content
namespace IPC {
class Message;
} // namespace IPC
namespace gfx {
class Screen;
}
// Selects the icon most closely matching the size constraints. This follows
// very basic heuristics -- improvements are welcome.
class ManifestIconSelector {
public:
// Runs the algorithm to find the best matching icon in the icons listed in
// the Manifest.
//
// Size is defined in Android's density-independent pixels (dp):
// http://developer.android.com/guide/practices/screens_support.html
// If/when this class is generalized, it may be a good idea to switch this to
// taking in pixels, instead.
//
// Returns the icon url if a suitable icon is found. An empty URL otherwise.
static GURL FindBestMatchingIcon(
const std::vector<content::Manifest::Icon>& icons,
float preferred_icon_size_in_dp,
const gfx::Screen* screen);
private:
explicit ManifestIconSelector(float preferred_icon_size_in_pixels);
virtual ~ManifestIconSelector() {}
// Runs the algorithm to find the best matching icon in the icons listed in
// the Manifest.
// Returns the icon url if a suitable icon is found. An empty URL otherwise.
GURL FindBestMatchingIcon(
const std::vector<content::Manifest::Icon>& icons,
float density);
// Runs an algorithm only based on icon declared sizes. It will try to find
// size that is the closest to preferred_icon_size_in_pixels_ but bigger than
// preferred_icon_size_in_pixels_ if possible.
// Returns the icon url if a suitable icon is found. An empty URL otherwise.
GURL FindBestMatchingIconForDensity(
const std::vector<content::Manifest::Icon>& icons,
float density);
// Returns whether the |preferred_icon_size_in_pixels_| is in |sizes|.
bool IconSizesContainsPreferredSize(const std::vector<gfx::Size>& sizes);
// Returns an array containing the items in |icons| without the unsupported
// image MIME types.
static std::vector<content::Manifest::Icon> FilterIconsByType(
const std::vector<content::Manifest::Icon>& icons);
// Returns whether the 'any' (ie. gfx::Size(0,0)) is in |sizes|.
static bool IconSizesContainsAny(const std::vector<gfx::Size>& sizes);
const int preferred_icon_size_in_pixels_;
friend class ManifestIconSelectorTest;
DISALLOW_COPY_AND_ASSIGN(ManifestIconSelector);
};
#endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_
|