sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 1 | // 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 | |
avi | bc5337b | 2015-12-25 23:16:33 | [diff] [blame] | 8 | #include "base/macros.h" |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 9 | #include "components/favicon/core/favicon_driver_impl.h" |
gambard | ea69b87 | 2017-02-14 14:05:56 | [diff] [blame] | 10 | #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" |
Eugene But | bef79e4 | 2019-09-10 17:17:14 | [diff] [blame] | 11 | #include "ios/web/public/web_state_observer.h" |
| 12 | #import "ios/web/public/web_state_user_data.h" |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 13 | |
| 14 | namespace web { |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 15 | class WebState; |
| 16 | } |
| 17 | |
| 18 | namespace 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. |
| 23 | class WebFaviconDriver : public web::WebStateObserver, |
| 24 | public web::WebStateUserData<WebFaviconDriver>, |
| 25 | public FaviconDriverImpl { |
| 26 | public: |
avi | d6d85694 | 2017-04-28 15:49:20 | [diff] [blame] | 27 | ~WebFaviconDriver() override; |
| 28 | |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 29 | static void CreateForWebState(web::WebState* web_state, |
Mohamed Amir Yosef | b2ff4051 | 2018-08-05 09:40:26 | [diff] [blame] | 30 | FaviconService* favicon_service); |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 31 | |
| 32 | // FaviconDriver implementation. |
| 33 | gfx::Image GetFavicon() const override; |
| 34 | bool FaviconIsValid() const override; |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 35 | GURL GetActiveURL() override; |
mastiz | 16aeb9f | 2017-03-01 08:33:23 | [diff] [blame] | 36 | |
| 37 | // FaviconHandler::Delegate implementation. |
| 38 | int DownloadImage(const GURL& url, |
| 39 | int max_image_size, |
| 40 | ImageDownloadCallback callback) override; |
mastiz | f5a564cc | 2017-05-18 13:15:18 | [diff] [blame] | 41 | void DownloadManifest(const GURL& url, |
| 42 | ManifestDownloadCallback callback) override; |
mastiz | 16aeb9f | 2017-03-01 08:33:23 | [diff] [blame] | 43 | bool IsOffTheRecord() override; |
pkotwicz | 7e8e893 | 2015-11-23 17:35:46 | [diff] [blame] | 44 | 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 Astiz | dad5b48 | 2017-11-02 08:55:43 | [diff] [blame] | 50 | void OnFaviconDeleted(const GURL& page_url, |
| 51 | FaviconDriverObserver::NotificationIconType |
| 52 | notification_icon_type) override; |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | friend class web::WebStateUserData<WebFaviconDriver>; |
| 56 | |
Mohamed Amir Yosef | b2ff4051 | 2018-08-05 09:40:26 | [diff] [blame] | 57 | WebFaviconDriver(web::WebState* web_state, FaviconService* favicon_service); |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 58 | |
| 59 | // web::WebStateObserver implementation. |
Sylvain Defresne | 3212e2a | 2017-10-18 21:32:49 | [diff] [blame] | 60 | void DidFinishNavigation(web::WebState* web_state, |
| 61 | web::NavigationContext* navigation_context) override; |
jyquinn | 92d84da | 2015-04-15 18:36:43 | [diff] [blame] | 62 | void FaviconUrlUpdated( |
Sylvain Defresne | 3212e2a | 2017-10-18 21:32:49 | [diff] [blame] | 63 | web::WebState* web_state, |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 64 | const std::vector<web::FaviconURL>& candidates) override; |
Sylvain Defresne | a7c39cd | 2017-11-13 16:06:39 | [diff] [blame] | 65 | void WebStateDestroyed(web::WebState* web_state) override; |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 66 | |
Sylvain Defresne | 8db59b9 | 2017-10-03 08:21:58 | [diff] [blame] | 67 | // Invoked when new favicon URL candidates are received. |
| 68 | void FaviconUrlUpdatedInternal( |
| 69 | const std::vector<favicon::FaviconURL>& candidates); |
pkotwicz | 38c2b85c | 2015-09-28 19:30:50 | [diff] [blame] | 70 | |
gambard | ea69b87 | 2017-02-14 14:05:56 | [diff] [blame] | 71 | // Image Fetcher used to fetch favicon. |
| 72 | image_fetcher::IOSImageDataFetcherWrapper image_fetcher_; |
| 73 | |
Sylvain Defresne | a7c39cd | 2017-11-13 16:06:39 | [diff] [blame] | 74 | // The WebState this instance is observing. Will be null after |
| 75 | // WebStateDestroyed has been called. |
| 76 | web::WebState* web_state_ = nullptr; |
| 77 | |
Francois Doray | 2d8ae68 | 2019-02-20 16:52:02 | [diff] [blame] | 78 | WEB_STATE_USER_DATA_KEY_DECL(); |
| 79 | |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 80 | DISALLOW_COPY_AND_ASSIGN(WebFaviconDriver); |
| 81 | }; |
| 82 | |
| 83 | } // namespace favicon |
| 84 | |
| 85 | #endif // COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_ |