blob: a93baae496e99653f666210bd0f99349c519164a [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,
mastiz62a06efa2017-09-11 18:14:1631 history::HistoryService* history_service);
sdefresne70a04802015-04-09 14:00:1732
33 // FaviconDriver implementation.
sdefresne70a04802015-04-09 14:00:1734 gfx::Image GetFavicon() const override;
35 bool FaviconIsValid() const override;
sdefresne70a04802015-04-09 14:00:1736 GURL GetActiveURL() override;
mastiz16aeb9f2017-03-01 08:33:2337
38 // FaviconHandler::Delegate implementation.
39 int DownloadImage(const GURL& url,
40 int max_image_size,
41 ImageDownloadCallback callback) override;
mastizf5a564cc2017-05-18 13:15:1842 void DownloadManifest(const GURL& url,
43 ManifestDownloadCallback callback) override;
mastiz16aeb9f2017-03-01 08:33:2344 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,
mastiz62a06efa2017-09-11 18:14:1657 history::HistoryService* history_service);
sdefresne70a04802015-04-09 14:00:1758
59 // web::WebStateObserver implementation.
Sylvain Defresne3212e2a2017-10-18 21:32:4960 void DidStartNavigation(web::WebState* web_state,
61 web::NavigationContext* navigation_context) override;
62 void DidFinishNavigation(web::WebState* web_state,
63 web::NavigationContext* navigation_context) override;
jyquinn92d84da2015-04-15 18:36:4364 void FaviconUrlUpdated(
Sylvain Defresne3212e2a2017-10-18 21:32:4965 web::WebState* web_state,
sdefresne70a04802015-04-09 14:00:1766 const std::vector<web::FaviconURL>& candidates) override;
67
Sylvain Defresne8db59b92017-10-03 08:21:5868 // Invoked when new favicon URL candidates are received.
69 void FaviconUrlUpdatedInternal(
70 const std::vector<favicon::FaviconURL>& candidates);
pkotwicz38c2b85c2015-09-28 19:30:5071
gambardea69b872017-02-14 14:05:5672 // Image Fetcher used to fetch favicon.
73 image_fetcher::IOSImageDataFetcherWrapper image_fetcher_;
74
Sylvain Defresne8db59b92017-10-03 08:21:5875 // Caches the favicon URLs candidates for same-document navigations.
76 std::vector<favicon::FaviconURL> candidates_;
77
sdefresne70a04802015-04-09 14:00:1778 DISALLOW_COPY_AND_ASSIGN(WebFaviconDriver);
79};
80
81} // namespace favicon
82
83#endif // COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_