blob: 59cfca2e2d074931cee773c3cdc780679366205a [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:
27 static void CreateForWebState(web::WebState* web_state,
28 FaviconService* favicon_service,
29 history::HistoryService* history_service,
30 bookmarks::BookmarkModel* bookmark_model);
31
32 // FaviconDriver implementation.
pkotwicz38c2b85c2015-09-28 19:30:5033 void FetchFavicon(const GURL& url) override;
sdefresne70a04802015-04-09 14:00:1734 gfx::Image GetFavicon() const override;
35 bool FaviconIsValid() const override;
36 int StartDownload(const GURL& url, int max_bitmap_size) override;
37 bool IsOffTheRecord() override;
38 GURL GetActiveURL() override;
pkotwicz7e8e8932015-11-23 17:35:4639 void OnFaviconUpdated(
40 const GURL& page_url,
41 FaviconDriverObserver::NotificationIconType notification_icon_type,
42 const GURL& icon_url,
43 bool icon_url_changed,
44 const gfx::Image& image) override;
sdefresne70a04802015-04-09 14:00:1745
46 private:
47 friend class web::WebStateUserData<WebFaviconDriver>;
48
49 WebFaviconDriver(web::WebState* web_state,
50 FaviconService* favicon_service,
51 history::HistoryService* history_service,
52 bookmarks::BookmarkModel* bookmark_model);
53 ~WebFaviconDriver() override;
54
55 // web::WebStateObserver implementation.
jyquinn92d84da2015-04-15 18:36:4356 void FaviconUrlUpdated(
sdefresne70a04802015-04-09 14:00:1757 const std::vector<web::FaviconURL>& candidates) override;
58
pkotwicz38c2b85c2015-09-28 19:30:5059 // The URL passed to FetchFavicon().
60 GURL fetch_favicon_url_;
61
gambardea69b872017-02-14 14:05:5662 // Image Fetcher used to fetch favicon.
63 image_fetcher::IOSImageDataFetcherWrapper image_fetcher_;
64
sdefresne70a04802015-04-09 14:00:1765 DISALLOW_COPY_AND_ASSIGN(WebFaviconDriver);
66};
67
68} // namespace favicon
69
70#endif // COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_