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" |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 11 | #include "ios/web/public/web_state/web_state_observer.h" |
| 12 | #include "ios/web/public/web_state/web_state_user_data.h" |
| 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, |
| 30 | FaviconService* favicon_service, |
| 31 | history::HistoryService* history_service, |
| 32 | bookmarks::BookmarkModel* bookmark_model); |
| 33 | |
| 34 | // FaviconDriver implementation. |
pkotwicz | 38c2b85c | 2015-09-28 19:30:50 | [diff] [blame] | 35 | void FetchFavicon(const GURL& url) override; |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 36 | gfx::Image GetFavicon() const override; |
| 37 | bool FaviconIsValid() const override; |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 38 | GURL GetActiveURL() override; |
mastiz | 16aeb9f | 2017-03-01 08:33:23 | [diff] [blame] | 39 | |
| 40 | // FaviconHandler::Delegate implementation. |
| 41 | int DownloadImage(const GURL& url, |
| 42 | int max_image_size, |
| 43 | ImageDownloadCallback callback) override; |
| 44 | bool IsOffTheRecord() override; |
pkotwicz | 7e8e893 | 2015-11-23 17:35:46 | [diff] [blame] | 45 | void OnFaviconUpdated( |
| 46 | const GURL& page_url, |
| 47 | FaviconDriverObserver::NotificationIconType notification_icon_type, |
| 48 | const GURL& icon_url, |
| 49 | bool icon_url_changed, |
| 50 | const gfx::Image& image) override; |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | friend class web::WebStateUserData<WebFaviconDriver>; |
| 54 | |
| 55 | WebFaviconDriver(web::WebState* web_state, |
| 56 | FaviconService* favicon_service, |
| 57 | history::HistoryService* history_service, |
| 58 | bookmarks::BookmarkModel* bookmark_model); |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 59 | |
| 60 | // web::WebStateObserver implementation. |
jyquinn | 92d84da | 2015-04-15 18:36:43 | [diff] [blame] | 61 | void FaviconUrlUpdated( |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 62 | const std::vector<web::FaviconURL>& candidates) override; |
| 63 | |
pkotwicz | 38c2b85c | 2015-09-28 19:30:50 | [diff] [blame] | 64 | // The URL passed to FetchFavicon(). |
| 65 | GURL fetch_favicon_url_; |
| 66 | |
gambard | ea69b87 | 2017-02-14 14:05:56 | [diff] [blame] | 67 | // Image Fetcher used to fetch favicon. |
| 68 | image_fetcher::IOSImageDataFetcherWrapper image_fetcher_; |
| 69 | |
sdefresne | 70a0480 | 2015-04-09 14:00:17 | [diff] [blame] | 70 | DISALLOW_COPY_AND_ASSIGN(WebFaviconDriver); |
| 71 | }; |
| 72 | |
| 73 | } // namespace favicon |
| 74 | |
| 75 | #endif // COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_ |