OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_ | 5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_ |
6 #define COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_ | 6 #define COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/observer_list.h" |
9 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
10 | 11 |
11 class GURL; | 12 class GURL; |
12 | 13 |
13 namespace gfx { | 14 namespace gfx { |
14 class Image; | 15 class Image; |
15 } | 16 } |
16 | 17 |
17 namespace favicon { | 18 namespace favicon { |
18 | 19 |
19 // Interface that allows Favicon core code to interact with its driver (i.e., | 20 class FaviconDriverObserver; |
20 // obtain information from it and give information to it). A concrete | 21 |
21 // implementation must be provided by the driver. | 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. |
22 class FaviconDriver { | 26 class FaviconDriver { |
23 public: | 27 public: |
| 28 // Adds/Removes an observer. |
| 29 void AddObserver(FaviconDriverObserver* observer); |
| 30 void RemoveObserver(FaviconDriverObserver* observer); |
| 31 |
| 32 // Initiates loading the favicon for the specified url. |
| 33 virtual void FetchFavicon(const GURL& url) = 0; |
| 34 |
| 35 // Saves the favicon for the current page. |
| 36 virtual void SaveFavicon() = 0; |
| 37 |
| 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; |
| 43 |
| 44 // Returns true if we have the favicon for the page. |
| 45 virtual bool FaviconIsValid() const = 0; |
| 46 |
24 // Starts the download for the given favicon. When finished, the driver | 47 // Starts the download for the given favicon. When finished, the driver |
25 // will call OnDidDownloadFavicon() with the results. | 48 // will call OnDidDownloadFavicon() with the results. |
26 // Returns the unique id of the download request. The id will be passed | 49 // Returns the unique id of the download request. The id will be passed |
27 // in OnDidDownloadFavicon(). | 50 // in OnDidDownloadFavicon(). |
28 // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out | 51 // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out |
29 // from the bitmap results. If there are no bitmap results <= | 52 // from the bitmap results. If there are no bitmap results <= |
30 // |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size| and | 53 // |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size| and |
31 // is the only result. A |max_bitmap_size| of 0 means unlimited. | 54 // is the only result. A |max_bitmap_size| of 0 means unlimited. |
32 virtual int StartDownload(const GURL& url, int max_bitmap_size) = 0; | 55 virtual int StartDownload(const GURL& url, int max_bitmap_size) = 0; |
33 | 56 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 virtual void SetActiveFaviconImage(const gfx::Image& image) = 0; | 90 virtual void SetActiveFaviconImage(const gfx::Image& image) = 0; |
68 | 91 |
69 // Notifies the driver a favicon image is available. |image| is not | 92 // Notifies the driver a favicon image is available. |image| is not |
70 // necessarily 16x16. |icon_url| is the url the image is from. If | 93 // necessarily 16x16. |icon_url| is the url the image is from. If |
71 // |is_active_favicon| is true the image corresponds to the favicon | 94 // |is_active_favicon| is true the image corresponds to the favicon |
72 // (possibly empty) of the page. | 95 // (possibly empty) of the page. |
73 virtual void OnFaviconAvailable(const gfx::Image& image, | 96 virtual void OnFaviconAvailable(const gfx::Image& image, |
74 const GURL& icon_url, | 97 const GURL& icon_url, |
75 bool is_active_favicon) = 0; | 98 bool is_active_favicon) = 0; |
76 | 99 |
77 // Sends notification that the current page favicon has changed. | 100 // Returns whether the driver is waiting for a download to complete or for |
78 // |icon_url_changed| is true if the URL of the favicon changed in addition to | 101 // data from the FaviconService. Reserved for testing. |
79 // the favicon image. | 102 virtual bool HasPendingTasksForTest() = 0; |
80 virtual void NotifyFaviconUpdated(bool icon_url_changed) = 0; | |
81 | 103 |
82 protected: | 104 protected: |
83 FaviconDriver() {} | 105 FaviconDriver(); |
84 virtual ~FaviconDriver() {} | 106 virtual ~FaviconDriver(); |
| 107 |
| 108 // Informs FaviconDriverObservers that favicon |image| has been retrieved from |
| 109 // either website or cached storage. |
| 110 void NotifyFaviconAvailable(const gfx::Image& image); |
| 111 |
| 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); |
85 | 116 |
86 private: | 117 private: |
| 118 ObserverList<FaviconDriverObserver> observer_list_; |
| 119 |
87 DISALLOW_COPY_AND_ASSIGN(FaviconDriver); | 120 DISALLOW_COPY_AND_ASSIGN(FaviconDriver); |
88 }; | 121 }; |
89 | 122 |
90 } // namespace favicon | 123 } // namespace favicon |
91 | 124 |
92 #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_ | 125 #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_ |
OLD | NEW |