blob: 0be7bcef3a2e24ac91fa6c2abb6ec9648c02fed3 [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
8#include "components/favicon/core/favicon_driver_impl.h"
9#include "ios/web/public/web_state/web_state_observer.h"
10#include "ios/web/public/web_state/web_state_user_data.h"
11
12namespace web {
13struct FaviconStatus;
14class WebState;
15}
16
17namespace favicon {
18
19// WebFaviconDriver is an implementation of FaviconDriver that listen to
20// WebState events to start download of favicons and to get informed when the
21// favicon download has completed.
22class WebFaviconDriver : public web::WebStateObserver,
23 public web::WebStateUserData<WebFaviconDriver>,
24 public FaviconDriverImpl {
25 public:
26 static void CreateForWebState(web::WebState* web_state,
27 FaviconService* favicon_service,
28 history::HistoryService* history_service,
29 bookmarks::BookmarkModel* bookmark_model);
30
31 // FaviconDriver implementation.
pkotwicz38c2b85c2015-09-28 19:30:5032 void FetchFavicon(const GURL& url) override;
sdefresne70a04802015-04-09 14:00:1733 gfx::Image GetFavicon() const override;
34 bool FaviconIsValid() const override;
35 int StartDownload(const GURL& url, int max_bitmap_size) override;
36 bool IsOffTheRecord() override;
37 GURL GetActiveURL() override;
sdefresne70a04802015-04-09 14:00:1738 bool GetActiveFaviconValidity() override;
39 void SetActiveFaviconValidity(bool valid) override;
40 GURL GetActiveFaviconURL() override;
41 void SetActiveFaviconURL(const GURL& url) override;
sdefresne70a04802015-04-09 14:00:1742 void SetActiveFaviconImage(const gfx::Image& image) override;
43
44 private:
45 friend class web::WebStateUserData<WebFaviconDriver>;
46
47 WebFaviconDriver(web::WebState* web_state,
48 FaviconService* favicon_service,
49 history::HistoryService* history_service,
50 bookmarks::BookmarkModel* bookmark_model);
51 ~WebFaviconDriver() override;
52
pkotwicz38c2b85c2015-09-28 19:30:5053 // Returns whether the active URL has changed since FetchFavicon() was called.
54 bool ActiveURLChangedSinceFetchFavicon();
55
sdefresne70a04802015-04-09 14:00:1756 // web::WebStateObserver implementation.
jyquinn92d84da2015-04-15 18:36:4357 void FaviconUrlUpdated(
sdefresne70a04802015-04-09 14:00:1758 const std::vector<web::FaviconURL>& candidates) override;
59
60 // Returns the active navigation entry's favicon.
61 web::FaviconStatus& GetFaviconStatus();
62
pkotwicz38c2b85c2015-09-28 19:30:5063 // The URL passed to FetchFavicon().
64 GURL fetch_favicon_url_;
65
sdefresne70a04802015-04-09 14:00:1766 DISALLOW_COPY_AND_ASSIGN(WebFaviconDriver);
67};
68
69} // namespace favicon
70
71#endif // COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_