[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 | |
avi | de7d5c2 | 2015-12-20 05:48:44 | [diff] [blame] | 13 | #include "base/macros.h" |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 14 | #include "content/public/browser/reload_type.h" |
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 15 | #include "content/public/browser/web_contents_observer.h" |
Miyoung Shin | 5709ab0 | 2020-02-19 06:50:41 | [diff] [blame] | 16 | #include "third_party/blink/public/mojom/favicon/favicon_url.mojom-forward.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 | |||||
[email protected] | 263cb08f | 2013-09-18 00:26:30 | [diff] [blame] | 21 | namespace gfx { |
22 | class Size; | ||||
23 | } | ||||
24 | |||||
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 25 | namespace android_webview { |
26 | |||||
27 | // A helper that observes favicon changes for Webview. | ||||
28 | class IconHelper : public content::WebContentsObserver { | ||||
29 | public: | ||||
30 | class Listener { | ||||
31 | public: | ||||
[email protected] | 8cbb1e55 | 2013-10-04 23:21:26 | [diff] [blame] | 32 | virtual bool ShouldDownloadFavicon(const GURL& icon_url) = 0; |
[email protected] | 492c64c | 2013-07-19 10:39:46 | [diff] [blame] | 33 | virtual void OnReceivedIcon(const GURL& icon_url, |
34 | const SkBitmap& bitmap) = 0; | ||||
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 35 | virtual void OnReceivedTouchIconUrl(const std::string& url, |
36 | const bool precomposed) = 0; | ||||
37 | protected: | ||||
38 | virtual ~Listener() {} | ||||
39 | }; | ||||
40 | |||||
41 | explicit IconHelper(content::WebContents* web_contents); | ||||
dcheng | 996c125c | 2015-02-04 02:25:49 | [diff] [blame] | 42 | ~IconHelper() override; |
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 43 | |
44 | void SetListener(Listener* listener); | ||||
45 | |||||
46 | // From WebContentsObserver | ||||
dcheng | 996c125c | 2015-02-04 02:25:49 | [diff] [blame] | 47 | void DidUpdateFaviconURL( |
Yuzu Saijo | 0c263c70 | 2020-06-08 03:41:24 | [diff] [blame] | 48 | content::RenderFrameHost* render_frame_host, |
Miyoung Shin | 5709ab0 | 2020-02-19 06:50:41 | [diff] [blame] | 49 | const std::vector<blink::mojom::FaviconURLPtr>& candidates) override; |
Alexander Timin | c4f7017 | 2020-05-13 22:32:42 | [diff] [blame] | 50 | void DidStartNavigation(content::NavigationHandle* navigation) override; |
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 51 | |
[email protected] | 263cb08f | 2013-09-18 00:26:30 | [diff] [blame] | 52 | void DownloadFaviconCallback( |
53 | int id, | ||||
54 | int http_status_code, | ||||
55 | const GURL& image_url, | ||||
56 | const std::vector<SkBitmap>& bitmaps, | ||||
57 | const std::vector<gfx::Size>& original_bitmap_sizes); | ||||
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 58 | |
59 | private: | ||||
[email protected] | 971b2e9 | 2014-04-30 12:10:58 | [diff] [blame] | 60 | void MarkUnableToDownloadFavicon(const GURL& icon_url); |
61 | bool WasUnableToDownloadFavicon(const GURL& icon_url) const; | ||||
62 | void ClearUnableToDownloadFavicons(); | ||||
63 | |||||
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 64 | Listener* listener_; |
65 | |||||
Daniel Cheng | 9a59e46 | 2019-11-18 22:47:30 | [diff] [blame] | 66 | using MissingFaviconURLHash = size_t; |
Takuto Ikuta | 8332bf9d | 2019-01-05 03:58:00 | [diff] [blame] | 67 | std::unordered_set<MissingFaviconURLHash> missing_favicon_urls_; |
[email protected] | 971b2e9 | 2014-04-30 12:10:58 | [diff] [blame] | 68 | |
[email protected] | b8da3a3 | 2013-01-22 23:54:08 | [diff] [blame] | 69 | DISALLOW_COPY_AND_ASSIGN(IconHelper); |
70 | }; | ||||
71 | |||||
72 | } // namespace android_webview | ||||
73 | |||||
74 | #endif // ANDROID_WEBVIEW_BROWSER_ICON_HELPER_H_ |