blob: d7e9455a3925cf9c1fc3964a391dd30103e44d88 [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"
sdefresne70a04802015-04-09 14:00:1711#include "ios/web/public/web_state/web_state_observer.h"
12#include "ios/web/public/web_state/web_state_user_data.h"
13
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,
30 FaviconService* favicon_service,
31 history::HistoryService* history_service,
32 bookmarks::BookmarkModel* bookmark_model);
33
34 // FaviconDriver implementation.
pkotwicz38c2b85c2015-09-28 19:30:5035 void FetchFavicon(const GURL& url) override;
sdefresne70a04802015-04-09 14:00:1736 gfx::Image GetFavicon() const override;
37 bool FaviconIsValid() const override;
sdefresne70a04802015-04-09 14:00:1738 GURL GetActiveURL() override;
mastiz16aeb9f2017-03-01 08:33:2339
40 // FaviconHandler::Delegate implementation.
41 int DownloadImage(const GURL& url,
42 int max_image_size,
43 ImageDownloadCallback callback) override;
44 bool IsOffTheRecord() override;
pkotwicz7e8e8932015-11-23 17:35:4645 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;
sdefresne70a04802015-04-09 14:00:1751
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);
sdefresne70a04802015-04-09 14:00:1759
60 // web::WebStateObserver implementation.
jyquinn92d84da2015-04-15 18:36:4361 void FaviconUrlUpdated(
sdefresne70a04802015-04-09 14:00:1762 const std::vector<web::FaviconURL>& candidates) override;
63
pkotwicz38c2b85c2015-09-28 19:30:5064 // The URL passed to FetchFavicon().
65 GURL fetch_favicon_url_;
66
gambardea69b872017-02-14 14:05:5667 // Image Fetcher used to fetch favicon.
68 image_fetcher::IOSImageDataFetcherWrapper image_fetcher_;
69
sdefresne70a04802015-04-09 14:00:1770 DISALLOW_COPY_AND_ASSIGN(WebFaviconDriver);
71};
72
73} // namespace favicon
74
75#endif // COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_