[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 1 | // Copyright (c) 2013 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 | |||||
5 | #ifndef ANDROID_WEBVIEW_BROWSER_ICON_HELPER_H_ | ||||
6 | #define ANDROID_WEBVIEW_BROWSER_ICON_HELPER_H_ | ||||
7 | |||||
avi | de7d5c2 | 2015-12-20 05:48:44 | [diff] [blame] | 8 | #include <stdint.h> |
9 | |||||
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 10 | #include <string> |
Takuto Ikuta | 8332bf9d | 2019-01-05 03:58:00 | [diff] [blame^] | 11 | #include <unordered_set> |
avi | de7d5c2 | 2015-12-20 05:48:44 | [diff] [blame] | 12 | |
[email protected] | 971b2e9 | 2014-04-30 12:10:58 | [diff] [blame] | 13 | #include "base/containers/hash_tables.h" |
avi | de7d5c2 | 2015-12-20 05:48:44 | [diff] [blame] | 14 | #include "base/macros.h" |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 15 | #include "content/public/browser/reload_type.h" |
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 16 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | 492c64c | 2013-07-19 10:39:46 | [diff] [blame] | 17 | #include "url/gurl.h" |
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 18 | |
19 | class SkBitmap; | ||||
20 | |||||
21 | namespace content { | ||||
22 | struct FaviconURL; | ||||
23 | } | ||||
24 | |||||
[email protected] | 263cb08f | 2013-09-18 00:26:30 | [diff] [blame] | 25 | namespace gfx { |
26 | class Size; | ||||
27 | } | ||||
28 | |||||
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 29 | namespace android_webview { |
30 | |||||
31 | // A helper that observes favicon changes for Webview. | ||||
32 | class IconHelper : public content::WebContentsObserver { | ||||
33 | public: | ||||
34 | class Listener { | ||||
35 | public: | ||||
[email protected] | 8cbb1e55 | 2013-10-04 23:21:26 | [diff] [blame] | 36 | virtual bool ShouldDownloadFavicon(const GURL& icon_url) = 0; |
[email protected] | 492c64c | 2013-07-19 10:39:46 | [diff] [blame] | 37 | virtual void OnReceivedIcon(const GURL& icon_url, |
38 | const SkBitmap& bitmap) = 0; | ||||
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 39 | virtual void OnReceivedTouchIconUrl(const std::string& url, |
40 | const bool precomposed) = 0; | ||||
41 | protected: | ||||
42 | virtual ~Listener() {} | ||||
43 | }; | ||||
44 | |||||
45 | explicit IconHelper(content::WebContents* web_contents); | ||||
dcheng | 996c125c | 2015-02-04 02:25:49 | [diff] [blame] | 46 | ~IconHelper() override; |
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 47 | |
48 | void SetListener(Listener* listener); | ||||
49 | |||||
50 | // From WebContentsObserver | ||||
dcheng | 996c125c | 2015-02-04 02:25:49 | [diff] [blame] | 51 | void DidUpdateFaviconURL( |
mostynb | d731a491 | 2014-10-07 13:36:11 | [diff] [blame] | 52 | const std::vector<content::FaviconURL>& candidates) override; |
dcheng | 996c125c | 2015-02-04 02:25:49 | [diff] [blame] | 53 | void DidStartNavigationToPendingEntry( |
[email protected] | 971b2e9 | 2014-04-30 12:10:58 | [diff] [blame] | 54 | const GURL& url, |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 55 | content::ReloadType reload_type) override; |
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 56 | |
[email protected] | 263cb08f | 2013-09-18 00:26:30 | [diff] [blame] | 57 | void DownloadFaviconCallback( |
58 | int id, | ||||
59 | int http_status_code, | ||||
60 | const GURL& image_url, | ||||
61 | const std::vector<SkBitmap>& bitmaps, | ||||
62 | const std::vector<gfx::Size>& original_bitmap_sizes); | ||||
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 63 | |
64 | private: | ||||
[email protected] | 971b2e9 | 2014-04-30 12:10:58 | [diff] [blame] | 65 | void MarkUnableToDownloadFavicon(const GURL& icon_url); |
66 | bool WasUnableToDownloadFavicon(const GURL& icon_url) const; | ||||
67 | void ClearUnableToDownloadFavicons(); | ||||
68 | |||||
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 69 | Listener* listener_; |
70 | |||||
avi | de7d5c2 | 2015-12-20 05:48:44 | [diff] [blame] | 71 | typedef uint32_t MissingFaviconURLHash; |
Takuto Ikuta | 8332bf9d | 2019-01-05 03:58:00 | [diff] [blame^] | 72 | std::unordered_set<MissingFaviconURLHash> missing_favicon_urls_; |
[email protected] | 971b2e9 | 2014-04-30 12:10:58 | [diff] [blame] | 73 | |
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 74 | DISALLOW_COPY_AND_ASSIGN(IconHelper); |
75 | }; | ||||
76 | |||||
77 | } // namespace android_webview | ||||
78 | |||||
79 | #endif // ANDROID_WEBVIEW_BROWSER_ICON_HELPER_H_ |