cc: Fix high/low res scale collisions
[chromium-blink-merge.git] / components / favicon / core / favicon_driver.h
blobfbd4c6e341a3de19958f58011d55f415b56ea45c
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 // Saves the favicon for the current page.
36 virtual void SaveFavicon() = 0;
38 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does
39 // not have a favicon. The default implementation uses the current navigation
40 // entry. Returns an empty bitmap if there are no navigation entries, which
41 // should rarely happen.
42 virtual gfx::Image GetFavicon() const = 0;
44 // Returns true if we have the favicon for the page.
45 virtual bool FaviconIsValid() const = 0;
47 // Starts the download for the given favicon. When finished, the driver
48 // will call OnDidDownloadFavicon() with the results.
49 // Returns the unique id of the download request. The id will be passed
50 // in OnDidDownloadFavicon().
51 // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out
52 // from the bitmap results. If there are no bitmap results <=
53 // |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size| and
54 // is the only result. A |max_bitmap_size| of 0 means unlimited.
55 virtual int StartDownload(const GURL& url, int max_bitmap_size) = 0;
57 // Returns whether the user is operating in an off-the-record context.
58 virtual bool IsOffTheRecord() = 0;
60 // Returns whether |url| is bookmarked.
61 virtual bool IsBookmarked(const GURL& url) = 0;
63 // Returns the URL of the current page, if any. Returns an invalid URL
64 // otherwise.
65 virtual GURL GetActiveURL() = 0;
67 // Returns the title of the current page. Requires GetActiveURL() to be valid.
68 virtual base::string16 GetActiveTitle() = 0;
70 // Returns whether the page's favicon is valid (returns false if the default
71 // favicon is being used). Requires GetActiveURL() to be valid.
72 virtual bool GetActiveFaviconValidity() = 0;
74 // Sets whether the page's favicon is valid (if false, the default favicon is
75 // being used).
76 virtual void SetActiveFaviconValidity(bool valid) = 0;
78 // Returns the URL of the current page's favicon. Requires GetActiveURL() to
79 // be valid.
80 virtual GURL GetActiveFaviconURL() = 0;
82 // Sets the URL of the favicon's bitmap.
83 virtual void SetActiveFaviconURL(const GURL& url) = 0;
85 // Returns the bitmap of the current page's favicon. Requires GetActiveURL()
86 // to be valid.
87 virtual gfx::Image GetActiveFaviconImage() = 0;
89 // Sets the bitmap of the current page's favicon.
90 virtual void SetActiveFaviconImage(const gfx::Image& image) = 0;
92 // Notifies the driver a favicon image is available. |image| is not
93 // necessarily 16x16. |icon_url| is the url the image is from. If
94 // |is_active_favicon| is true the image corresponds to the favicon
95 // (possibly empty) of the page.
96 virtual void OnFaviconAvailable(const gfx::Image& image,
97 const GURL& icon_url,
98 bool is_active_favicon) = 0;
100 // Returns whether the driver is waiting for a download to complete or for
101 // data from the FaviconService. Reserved for testing.
102 virtual bool HasPendingTasksForTest() = 0;
104 protected:
105 FaviconDriver();
106 virtual ~FaviconDriver();
108 // Informs FaviconDriverObservers that favicon |image| has been retrieved from
109 // either website or cached storage.
110 void NotifyFaviconAvailable(const gfx::Image& image);
112 // Informs FaviconDriverObservers that favicon has changed for the current
113 // page. |icon_url_changed| is true if the favicon URL has also changed since
114 // the last call.
115 virtual void NotifyFaviconUpdated(bool icon_url_changed);
117 private:
118 base::ObserverList<FaviconDriverObserver> observer_list_;
120 DISALLOW_COPY_AND_ASSIGN(FaviconDriver);
123 } // namespace favicon
125 #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_