blob: 8bb464d82c04dca7fc29e905d0c0398b9014d307 [file] [log] [blame]
[email protected]b8da3a32013-01-22 23:54:081// 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
avide7d5c22015-12-20 05:48:448#include <stdint.h>
9
[email protected]b8da3a32013-01-22 23:54:0810#include <string>
Takuto Ikuta8332bf9d2019-01-05 03:58:0011#include <unordered_set>
avide7d5c22015-12-20 05:48:4412
[email protected]971b2e92014-04-30 12:10:5813#include "base/containers/hash_tables.h"
avide7d5c22015-12-20 05:48:4414#include "base/macros.h"
toyoshim0df1d3a2016-09-09 09:52:4815#include "content/public/browser/reload_type.h"
[email protected]b8da3a32013-01-22 23:54:0816#include "content/public/browser/web_contents_observer.h"
[email protected]492c64c2013-07-19 10:39:4617#include "url/gurl.h"
[email protected]b8da3a32013-01-22 23:54:0818
19class SkBitmap;
20
21namespace content {
22struct FaviconURL;
23}
24
[email protected]263cb08f2013-09-18 00:26:3025namespace gfx {
26class Size;
27}
28
[email protected]b8da3a32013-01-22 23:54:0829namespace android_webview {
30
31// A helper that observes favicon changes for Webview.
32class IconHelper : public content::WebContentsObserver {
33 public:
34 class Listener {
35 public:
[email protected]8cbb1e552013-10-04 23:21:2636 virtual bool ShouldDownloadFavicon(const GURL& icon_url) = 0;
[email protected]492c64c2013-07-19 10:39:4637 virtual void OnReceivedIcon(const GURL& icon_url,
38 const SkBitmap& bitmap) = 0;
[email protected]b8da3a32013-01-22 23:54:0839 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);
dcheng996c125c2015-02-04 02:25:4946 ~IconHelper() override;
[email protected]b8da3a32013-01-22 23:54:0847
48 void SetListener(Listener* listener);
49
50 // From WebContentsObserver
dcheng996c125c2015-02-04 02:25:4951 void DidUpdateFaviconURL(
mostynbd731a4912014-10-07 13:36:1152 const std::vector<content::FaviconURL>& candidates) override;
dcheng996c125c2015-02-04 02:25:4953 void DidStartNavigationToPendingEntry(
[email protected]971b2e92014-04-30 12:10:5854 const GURL& url,
toyoshim0df1d3a2016-09-09 09:52:4855 content::ReloadType reload_type) override;
[email protected]b8da3a32013-01-22 23:54:0856
[email protected]263cb08f2013-09-18 00:26:3057 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]b8da3a32013-01-22 23:54:0863
64 private:
[email protected]971b2e92014-04-30 12:10:5865 void MarkUnableToDownloadFavicon(const GURL& icon_url);
66 bool WasUnableToDownloadFavicon(const GURL& icon_url) const;
67 void ClearUnableToDownloadFavicons();
68
[email protected]b8da3a32013-01-22 23:54:0869 Listener* listener_;
70
avide7d5c22015-12-20 05:48:4471 typedef uint32_t MissingFaviconURLHash;
Takuto Ikuta8332bf9d2019-01-05 03:58:0072 std::unordered_set<MissingFaviconURLHash> missing_favicon_urls_;
[email protected]971b2e92014-04-30 12:10:5873
[email protected]b8da3a32013-01-22 23:54:0874 DISALLOW_COPY_AND_ASSIGN(IconHelper);
75};
76
77} // namespace android_webview
78
79#endif // ANDROID_WEBVIEW_BROWSER_ICON_HELPER_H_