Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / favicon / core / favicon_driver.h
blob986ad391c46902c3a2befb72ac1321edb02e3a4e
1 // Copyright 2014 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.
5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_
6 #define COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_
8 #include "base/macros.h"
9 #include "base/observer_list.h"
10 #include "base/strings/string16.h"
12 class GURL;
14 namespace gfx {
15 class Image;
18 namespace favicon {
20 class FaviconDriverObserver;
22 // Interface that allows favicon core code to obtain information about the
23 // current page. This is partially implemented by FaviconDriverImpl, and
24 // concrete implementation should be based on that class instead of directly
25 // subclassing FaviconDriver.
26 class FaviconDriver {
27 public:
28 // Adds/Removes an observer.
29 void AddObserver(FaviconDriverObserver* observer);
30 void RemoveObserver(FaviconDriverObserver* observer);
32 // Initiates loading the favicon for the specified url.
33 virtual void FetchFavicon(const GURL& url) = 0;
35 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does
36 // not have a favicon. The default implementation uses the current navigation
37 // entry. Returns an empty bitmap if there are no navigation entries, which
38 // should rarely happen.
39 virtual gfx::Image GetFavicon() const = 0;
41 // Returns true if we have the favicon for the page.
42 virtual bool FaviconIsValid() const = 0;
44 // Starts the download for the given favicon. When finished, the driver
45 // will call OnDidDownloadFavicon() with the results.
46 // Returns the unique id of the download request. The id will be passed
47 // in OnDidDownloadFavicon().
48 // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out
49 // from the bitmap results. If there are no bitmap results <=
50 // |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size| and
51 // is the only result. A |max_bitmap_size| of 0 means unlimited.
52 virtual int StartDownload(const GURL& url, int max_bitmap_size) = 0;
54 // Returns whether the user is operating in an off-the-record context.
55 virtual bool IsOffTheRecord() = 0;
57 // Returns whether |url| is bookmarked.
58 virtual bool IsBookmarked(const GURL& url) = 0;
60 // Returns the URL of the current page, if any. Returns an invalid URL
61 // otherwise.
62 virtual GURL GetActiveURL() = 0;
64 // Returns whether the page's favicon is valid (returns false if the default
65 // favicon is being used). Requires GetActiveURL() to be valid.
66 virtual bool GetActiveFaviconValidity() = 0;
68 // Sets whether the page's favicon is valid (if false, the default favicon is
69 // being used).
70 virtual void SetActiveFaviconValidity(bool valid) = 0;
72 // Returns the URL of the current page's favicon. Requires GetActiveURL() to
73 // be valid.
74 virtual GURL GetActiveFaviconURL() = 0;
76 // Sets the URL of the favicon's bitmap.
77 virtual void SetActiveFaviconURL(const GURL& url) = 0;
79 // Sets the bitmap of the current page's favicon.
80 virtual void SetActiveFaviconImage(const gfx::Image& image) = 0;
82 // Notifies the driver a favicon image is available. |image| is not
83 // necessarily 16x16. |icon_url| is the url the image is from. If
84 // |is_active_favicon| is true the image corresponds to the favicon
85 // (possibly empty) of the page.
86 virtual void OnFaviconAvailable(const gfx::Image& image,
87 const GURL& icon_url,
88 bool is_active_favicon) = 0;
90 // Returns whether the driver is waiting for a download to complete or for
91 // data from the FaviconService. Reserved for testing.
92 virtual bool HasPendingTasksForTest() = 0;
94 protected:
95 FaviconDriver();
96 virtual ~FaviconDriver();
98 // Informs FaviconDriverObservers that favicon |image| has been retrieved from
99 // either website or cached storage.
100 void NotifyFaviconAvailable(const gfx::Image& image);
102 // Informs FaviconDriverObservers that favicon has changed for the current
103 // page. |icon_url_changed| is true if the favicon URL has also changed since
104 // the last call.
105 virtual void NotifyFaviconUpdated(bool icon_url_changed);
107 private:
108 base::ObserverList<FaviconDriverObserver> observer_list_;
110 DISALLOW_COPY_AND_ASSIGN(FaviconDriver);
113 } // namespace favicon
115 #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_