blob: 9a06a975083382ed20bbd0c6ebf9501d044c8198 [file] [log] [blame]
sdefresne70a04802015-04-09 14:00:171// 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.
4
5#ifndef COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_
6#define COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_
7
avibc5337b2015-12-25 23:16:338#include "base/macros.h"
sdefresne70a04802015-04-09 14:00:179#include "components/favicon/core/favicon_driver_impl.h"
gambardea69b872017-02-14 14:05:5610#import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h"
Eugene Butbef79e42019-09-10 17:17:1411#include "ios/web/public/web_state_observer.h"
12#import "ios/web/public/web_state_user_data.h"
sdefresne70a04802015-04-09 14:00:1713
14namespace web {
sdefresne70a04802015-04-09 14:00:1715class WebState;
16}
17
18namespace favicon {
19
20// WebFaviconDriver is an implementation of FaviconDriver that listen to
21// WebState events to start download of favicons and to get informed when the
22// favicon download has completed.
23class WebFaviconDriver : public web::WebStateObserver,
24 public web::WebStateUserData<WebFaviconDriver>,
25 public FaviconDriverImpl {
26 public:
avid6d856942017-04-28 15:49:2027 ~WebFaviconDriver() override;
28
sdefresne70a04802015-04-09 14:00:1729 static void CreateForWebState(web::WebState* web_state,
Mohamed Amir Yosefb2ff40512018-08-05 09:40:2630 FaviconService* favicon_service);
sdefresne70a04802015-04-09 14:00:1731
32 // FaviconDriver implementation.
33 gfx::Image GetFavicon() const override;
34 bool FaviconIsValid() const override;
sdefresne70a04802015-04-09 14:00:1735 GURL GetActiveURL() override;
mastiz16aeb9f2017-03-01 08:33:2336
37 // FaviconHandler::Delegate implementation.
38 int DownloadImage(const GURL& url,
39 int max_image_size,
40 ImageDownloadCallback callback) override;
mastizf5a564cc2017-05-18 13:15:1841 void DownloadManifest(const GURL& url,
42 ManifestDownloadCallback callback) override;
mastiz16aeb9f2017-03-01 08:33:2343 bool IsOffTheRecord() override;
pkotwicz7e8e8932015-11-23 17:35:4644 void OnFaviconUpdated(
45 const GURL& page_url,
46 FaviconDriverObserver::NotificationIconType notification_icon_type,
47 const GURL& icon_url,
48 bool icon_url_changed,
49 const gfx::Image& image) override;
Mikel Astizdad5b482017-11-02 08:55:4350 void OnFaviconDeleted(const GURL& page_url,
51 FaviconDriverObserver::NotificationIconType
52 notification_icon_type) override;
sdefresne70a04802015-04-09 14:00:1753
54 private:
55 friend class web::WebStateUserData<WebFaviconDriver>;
56
Mohamed Amir Yosefb2ff40512018-08-05 09:40:2657 WebFaviconDriver(web::WebState* web_state, FaviconService* favicon_service);
sdefresne70a04802015-04-09 14:00:1758
59 // web::WebStateObserver implementation.
Sylvain Defresne3212e2a2017-10-18 21:32:4960 void DidFinishNavigation(web::WebState* web_state,
61 web::NavigationContext* navigation_context) override;
jyquinn92d84da2015-04-15 18:36:4362 void FaviconUrlUpdated(
Sylvain Defresne3212e2a2017-10-18 21:32:4963 web::WebState* web_state,
sdefresne70a04802015-04-09 14:00:1764 const std::vector<web::FaviconURL>& candidates) override;
Sylvain Defresnea7c39cd2017-11-13 16:06:3965 void WebStateDestroyed(web::WebState* web_state) override;
sdefresne70a04802015-04-09 14:00:1766
Sylvain Defresne8db59b92017-10-03 08:21:5867 // Invoked when new favicon URL candidates are received.
68 void FaviconUrlUpdatedInternal(
69 const std::vector<favicon::FaviconURL>& candidates);
pkotwicz38c2b85c2015-09-28 19:30:5070
gambardea69b872017-02-14 14:05:5671 // Image Fetcher used to fetch favicon.
72 image_fetcher::IOSImageDataFetcherWrapper image_fetcher_;
73
Sylvain Defresnea7c39cd2017-11-13 16:06:3974 // The WebState this instance is observing. Will be null after
75 // WebStateDestroyed has been called.
76 web::WebState* web_state_ = nullptr;
77
Francois Doray2d8ae682019-02-20 16:52:0278 WEB_STATE_USER_DATA_KEY_DECL();
79
sdefresne70a04802015-04-09 14:00:1780 DISALLOW_COPY_AND_ASSIGN(WebFaviconDriver);
81};
82
83} // namespace favicon
84
85#endif // COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_