blob: 343d2be90a2fad7da98a5d3e4154b7e55688056d [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.
32 gfx::Image GetFavicon() const override;
33 bool FaviconIsValid() const override;
34 int StartDownload(const GURL& url, int max_bitmap_size) override;
35 bool IsOffTheRecord() override;
36 GURL GetActiveURL() override;
37 base::string16 GetActiveTitle() override;
38 bool GetActiveFaviconValidity() override;
39 void SetActiveFaviconValidity(bool valid) override;
40 GURL GetActiveFaviconURL() override;
41 void SetActiveFaviconURL(const GURL& url) override;
42 gfx::Image GetActiveFaviconImage() override;
43 void SetActiveFaviconImage(const gfx::Image& image) override;
44
45 private:
46 friend class web::WebStateUserData<WebFaviconDriver>;
47
48 WebFaviconDriver(web::WebState* web_state,
49 FaviconService* favicon_service,
50 history::HistoryService* history_service,
51 bookmarks::BookmarkModel* bookmark_model);
52 ~WebFaviconDriver() override;
53
54 // web::WebStateObserver implementation.
55 void FaviconURLUpdated(
56 const std::vector<web::FaviconURL>& candidates) override;
57
58 // Returns the active navigation entry's favicon.
59 web::FaviconStatus& GetFaviconStatus();
60
61 DISALLOW_COPY_AND_ASSIGN(WebFaviconDriver);
62};
63
64} // namespace favicon
65
66#endif // COMPONENTS_FAVICON_IOS_WEB_FAVICON_DRIVER_H_