Chromium Code Reviews| 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/observer_list.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "components/favicon/core/favicon_driver_observer.h" | |
| 11 | 12 |
| 12 class GURL; | 13 class GURL; |
| 13 | 14 |
| 14 namespace gfx { | 15 namespace gfx { |
| 15 class Image; | 16 class Image; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace favicon { | 19 namespace favicon { |
| 19 | 20 |
| 20 class FaviconDriverObserver; | |
| 21 | |
| 22 // Interface that allows favicon core code to obtain information about the | 21 // Interface that allows favicon core code to obtain information about the |
| 23 // current page. This is partially implemented by FaviconDriverImpl, and | 22 // current page. This is partially implemented by FaviconDriverImpl, and |
| 24 // concrete implementation should be based on that class instead of directly | 23 // concrete implementation should be based on that class instead of directly |
| 25 // subclassing FaviconDriver. | 24 // subclassing FaviconDriver. |
| 26 class FaviconDriver { | 25 class FaviconDriver { |
| 27 public: | 26 public: |
| 28 // Adds/Removes an observer. | 27 // Adds/Removes an observer. |
| 29 void AddObserver(FaviconDriverObserver* observer); | 28 void AddObserver(FaviconDriverObserver* observer); |
| 30 void RemoveObserver(FaviconDriverObserver* observer); | 29 void RemoveObserver(FaviconDriverObserver* observer); |
| 31 | 30 |
| 32 // Initiates loading the favicon for the specified url. | 31 // Initiates loading the favicon for the specified url. |
| 33 virtual void FetchFavicon(const GURL& url) = 0; | 32 virtual void FetchFavicon(const GURL& url) = 0; |
| 34 | 33 |
| 35 // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does | 34 // 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 | 35 // not have a favicon. The default implementation uses the current navigation |
| 37 // entry. Returns an empty bitmap if there are no navigation entries, which | 36 // entry. Returns an empty bitmap if there are no navigation entries, which |
| 38 // should rarely happen. | 37 // should rarely happen. |
| 39 virtual gfx::Image GetFavicon() const = 0; | 38 virtual gfx::Image GetFavicon() const = 0; |
| 40 | 39 |
| 40 // Returns the URL of the favicon for the page. | |
| 41 virtual GURL GetFaviconURL() const = 0; | |
|
sky
2015/11/20 00:44:26
I'm worried about the timing of this. Why is it ne
pkotwicz
2015/11/20 03:13:29
I think that it is reasonable for a caller to be a
sky
2015/11/20 16:03:59
I don't like adding code just for a test, especial
pkotwicz
2015/11/21 23:04:08
Done.
| |
| 42 | |
| 41 // Returns true if we have the favicon for the page. | 43 // Returns true if we have the favicon for the page. |
| 42 virtual bool FaviconIsValid() const = 0; | 44 virtual bool FaviconIsValid() const = 0; |
| 43 | 45 |
| 44 // Starts the download for the given favicon. When finished, the driver | 46 // Starts the download for the given favicon. When finished, the driver |
| 45 // will call OnDidDownloadFavicon() with the results. | 47 // will call OnDidDownloadFavicon() with the results. |
| 46 // Returns the unique id of the download request. The id will be passed | 48 // Returns the unique id of the download request. The id will be passed |
| 47 // in OnDidDownloadFavicon(). | 49 // in OnDidDownloadFavicon(). |
| 48 // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out | 50 // Bitmaps with pixel sizes larger than |max_bitmap_size| are filtered out |
| 49 // from the bitmap results. If there are no bitmap results <= | 51 // from the bitmap results. If there are no bitmap results <= |
| 50 // |max_bitmap_size|, the smallest bitmap is resized to |max_bitmap_size| and | 52 // |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. | 53 // 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 virtual int StartDownload(const GURL& url, int max_bitmap_size) = 0; |
| 53 | 55 |
| 54 // Returns whether the user is operating in an off-the-record context. | 56 // Returns whether the user is operating in an off-the-record context. |
| 55 virtual bool IsOffTheRecord() = 0; | 57 virtual bool IsOffTheRecord() = 0; |
| 56 | 58 |
| 57 // Returns whether |url| is bookmarked. | 59 // Returns whether |url| is bookmarked. |
| 58 virtual bool IsBookmarked(const GURL& url) = 0; | 60 virtual bool IsBookmarked(const GURL& url) = 0; |
| 59 | 61 |
| 60 // Returns the URL of the current page, if any. Returns an invalid URL | 62 // Returns the URL of the current page, if any. Returns an invalid URL |
| 61 // otherwise. | 63 // otherwise. |
| 62 virtual GURL GetActiveURL() = 0; | 64 virtual GURL GetActiveURL() = 0; |
| 63 | 65 |
| 64 // Sets whether the page's favicon is valid (if false, the default favicon is | 66 // Notifies the driver that the favicon image has been updated. |
| 65 // being used). | 67 // See comment for FaviconDriverObserver::OnFaviconUpdated() for more details. |
| 66 virtual void SetActiveFaviconValidity(bool valid) = 0; | 68 virtual void OnFaviconUpdated( |
| 67 | 69 const GURL& page_url, |
| 68 // Returns the URL of the current page's favicon. | 70 FaviconDriverObserver::NotificationIconType notification_icon_type, |
| 69 virtual GURL GetActiveFaviconURL() = 0; | 71 const GURL& icon_url, |
| 70 | 72 bool icon_url_changed, |
| 71 // Sets the URL of the favicon's bitmap. | 73 const gfx::Image& image) = 0; |
| 72 virtual void SetActiveFaviconURL(const GURL& url) = 0; | |
| 73 | |
| 74 // Sets the bitmap of the current page's favicon. | |
| 75 virtual void SetActiveFaviconImage(const gfx::Image& image) = 0; | |
| 76 | |
| 77 // Notifies the driver a favicon image is available. |image| is not | |
| 78 // necessarily 16x16. |icon_url| is the url the image is from. If | |
| 79 // |is_active_favicon| is true the image corresponds to the favicon | |
| 80 // (possibly empty) of the page. | |
| 81 virtual void OnFaviconAvailable(const GURL& page_url, | |
| 82 const GURL& icon_url, | |
| 83 const gfx::Image& image, | |
| 84 bool is_active_favicon) = 0; | |
| 85 | 74 |
| 86 // Returns whether the driver is waiting for a download to complete or for | 75 // Returns whether the driver is waiting for a download to complete or for |
| 87 // data from the FaviconService. Reserved for testing. | 76 // data from the FaviconService. Reserved for testing. |
| 88 virtual bool HasPendingTasksForTest() = 0; | 77 virtual bool HasPendingTasksForTest() = 0; |
| 89 | 78 |
| 90 protected: | 79 protected: |
| 91 FaviconDriver(); | 80 FaviconDriver(); |
| 92 virtual ~FaviconDriver(); | 81 virtual ~FaviconDriver(); |
| 93 | 82 |
| 94 // Informs FaviconDriverObservers that favicon |image| has been retrieved from | 83 // Notifies FaviconDriverObservers that the favicon image has been updated. |
| 95 // either website or cached storage. | 84 void NotifyFaviconUpdatedObservers( |
| 96 void NotifyFaviconAvailable(const gfx::Image& image); | 85 FaviconDriverObserver::NotificationIconType notification_icon_type, |
| 86 const GURL& icon_url, | |
| 87 bool icon_url_changed, | |
| 88 const gfx::Image& image); | |
| 97 | 89 |
| 98 // Informs FaviconDriverObservers that favicon has changed for the current | |
| 99 // page. |icon_url_changed| is true if the favicon URL has also changed since | |
| 100 // the last call. | |
| 101 virtual void NotifyFaviconUpdated(bool icon_url_changed); | |
| 102 | 90 |
| 103 private: | 91 private: |
| 104 base::ObserverList<FaviconDriverObserver> observer_list_; | 92 base::ObserverList<FaviconDriverObserver> observer_list_; |
| 105 | 93 |
| 106 DISALLOW_COPY_AND_ASSIGN(FaviconDriver); | 94 DISALLOW_COPY_AND_ASSIGN(FaviconDriver); |
| 107 }; | 95 }; |
| 108 | 96 |
| 109 } // namespace favicon | 97 } // namespace favicon |
| 110 | 98 |
| 111 #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_ | 99 #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_ |
| OLD | NEW |