Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ |
| 6 #define CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ | 6 #define CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 class FaviconClient; | 23 class FaviconClient; |
| 24 class FaviconDriver; | 24 class FaviconDriver; |
| 25 class SkBitmap; | 25 class SkBitmap; |
| 26 | 26 |
| 27 namespace base { | 27 namespace base { |
| 28 class RefCountedMemory; | 28 class RefCountedMemory; |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace content { | 31 // FaviconHandler works with FaviconDriver to fetch the specific type of |
| 32 class NavigationEntry; | |
| 33 } | |
| 34 | |
| 35 // FaviconHandler works with FaviconTabHelper to fetch the specific type of | |
| 36 // favicon. | 32 // favicon. |
| 37 // | 33 // |
| 38 // FetchFavicon requests the favicon from the favicon service which in turn | 34 // FetchFavicon requests the favicon from the favicon service which in turn |
| 39 // requests the favicon from the history database. At this point | 35 // requests the favicon from the history database. At this point |
| 40 // we only know the URL of the page, and not necessarily the url of the | 36 // we only know the URL of the page, and not necessarily the url of the |
| 41 // favicon. To ensure we handle reloading stale favicons as well as | 37 // favicon. To ensure we handle reloading stale favicons as well as |
| 42 // reloading a favicon on page reload we always request the favicon from | 38 // reloading a favicon on page reload we always request the favicon from |
| 43 // history regardless of whether the NavigationEntry has a favicon. | 39 // history regardless of whether the active favicon is valid. |
| 44 // | 40 // |
| 45 // After the navigation two types of events are delivered (which is | 41 // After the navigation two types of events are delivered (which is |
| 46 // first depends upon who is faster): notification from the history | 42 // first depends upon who is faster): notification from the history |
| 47 // db on our request for the favicon | 43 // db on our request for the favicon |
| 48 // (OnFaviconDataForInitialURLFromFaviconService), or a message from the | 44 // (OnFaviconDataForInitialURLFromFaviconService), or a message from the |
| 49 // renderer giving us the URL of the favicon for the page (SetFaviconURL). | 45 // renderer giving us the URL of the favicon for the page (SetFaviconURL). |
| 50 // . If the history db has a valid up to date favicon for the page, we update | 46 // . If the history db has a valid up to date favicon for the page, we update |
| 51 // the NavigationEntry and use the favicon. | 47 // the NavigationEntry and use the favicon. |
|
blundell
2014/05/12 07:52:19
s/NavigationEntry/current page
jif
2014/05/12 18:07:41
Done.
| |
| 52 // . When we receive the favicon url if it matches that of the NavigationEntry | 48 // . When we receive the favicon url if it matches that of the NavigationEntry |
| 53 // and the NavigationEntry's favicon is set, we do nothing (everything is | 49 // and the NavigationEntry's favicon is set, we do nothing (everything is |
| 54 // ok). | 50 // ok). |
| 55 // . On the other hand if the database does not know the favicon for url, or | 51 // . On the other hand if the database does not know the favicon for url, or |
| 56 // the favicon is out date, or the URL from the renderer does not match that | 52 // the favicon is out date, or the URL from the renderer does not match that |
| 57 // NavigationEntry we proceed to DownloadFaviconOrAskHistory. Before we | 53 // of the current page we proceed to DownloadFaviconOrAskHistory. Before we |
| 58 // invoke DownloadFaviconOrAskHistory we wait until we've received both | 54 // invoke DownloadFaviconOrAskHistory we wait until we've received both |
| 59 // the favicon url and the callback from history. We wait to ensure we | 55 // the favicon url and the callback from history. We wait to ensure we |
| 60 // truly know both the favicon url and the state of the database. | 56 // truly know both the favicon url and the state of the database. |
| 61 // | 57 // |
| 62 // DownloadFaviconOrAskHistory does the following: | 58 // DownloadFaviconOrAskHistory does the following: |
| 63 // . If we have a valid favicon, but it is expired we ask the renderer to | 59 // . If we have a valid favicon, but it is expired we ask the renderer to |
| 64 // download the favicon. | 60 // download the favicon. |
| 65 // . Otherwise we ask the history database to update the mapping from | 61 // . Otherwise we ask the history database to update the mapping from |
| 66 // page url to favicon url and call us back with the favicon. Remember, it is | 62 // page url to favicon url and call us back with the favicon. Remember, it is |
| 67 // possible for the db to already have the favicon, just not the mapping | 63 // possible for the db to already have the favicon, just not the mapping |
| 68 // between page to favicon url. The callback for this is OnFaviconData. | 64 // between page to favicon url. The callback for this is OnFaviconData. |
| 69 // | 65 // |
| 70 // OnFaviconData either updates the favicon of the NavigationEntry (if the | 66 // OnFaviconData either updates the favicon of the NavigationEntry (if the |
| 71 // db knew about the favicon), or requests the renderer to download the | 67 // db knew about the favicon), or requests the renderer to download the |
| 72 // favicon. | 68 // favicon. |
| 73 // | 69 // |
| 74 // When the renderer downloads favicons, it considers the entire list of | 70 // When the renderer downloads favicons, it considers the entire list of |
| 75 // favicon candidates, if |download_largest_favicon_| is true, the largest | 71 // favicon candidates, if |download_largest_favicon_| is true, the largest |
| 76 // favicon will be used, otherwise the one that best matches the preferred size | 72 // favicon will be used, otherwise the one that best matches the preferred size |
| 77 // is chosen (or the first one if there is no preferred size). Once the | 73 // is chosen (or the first one if there is no preferred size). Once the |
| 78 // matching favicon has been determined, SetFavicon is called which updates | 74 // matching favicon has been determined, SetFavicon is called which updates |
| 79 // the favicon of the NavigationEntry and notifies the database to save the | 75 // the page's favicon and notifies the database to save the favicon. |
| 80 // favicon. | |
| 81 | 76 |
| 82 class FaviconHandler { | 77 class FaviconHandler { |
| 83 public: | 78 public: |
| 84 enum Type { | 79 enum Type { |
| 85 FAVICON, | 80 FAVICON, |
| 86 TOUCH, | 81 TOUCH, |
| 87 }; | 82 }; |
| 88 | 83 |
| 89 FaviconHandler(FaviconClient* client, | 84 FaviconHandler(FaviconClient* client, |
| 90 FaviconDriver* driver, | 85 FaviconDriver* driver, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 116 | 111 |
| 117 // For testing. | 112 // For testing. |
| 118 const std::vector<content::FaviconURL>& image_urls() const { | 113 const std::vector<content::FaviconURL>& image_urls() const { |
| 119 return image_urls_; | 114 return image_urls_; |
| 120 } | 115 } |
| 121 | 116 |
| 122 protected: | 117 protected: |
| 123 // These virtual methods make FaviconHandler testable and are overridden by | 118 // These virtual methods make FaviconHandler testable and are overridden by |
| 124 // TestFaviconHandler. | 119 // TestFaviconHandler. |
| 125 | 120 |
| 126 // Return the NavigationEntry for the active entry, or NULL if the active | |
| 127 // entries URL does not match that of the URL last passed to FetchFavicon. | |
| 128 virtual content::NavigationEntry* GetEntry(); | |
| 129 | |
| 130 // Asks the render to download favicon, returns the request id. | 121 // Asks the render to download favicon, returns the request id. |
| 131 virtual int DownloadFavicon(const GURL& image_url, int max_bitmap_size); | 122 virtual int DownloadFavicon(const GURL& image_url, int max_bitmap_size); |
| 132 | 123 |
| 133 // Ask the favicon from history | 124 // Ask the favicon from history |
| 134 virtual void UpdateFaviconMappingAndFetch( | 125 virtual void UpdateFaviconMappingAndFetch( |
| 135 const GURL& page_url, | 126 const GURL& page_url, |
| 136 const GURL& icon_url, | 127 const GURL& icon_url, |
| 137 favicon_base::IconType icon_type, | 128 favicon_base::IconType icon_type, |
| 138 const FaviconService::FaviconResultsCallback& callback, | 129 const FaviconService::FaviconResultsCallback& callback, |
| 139 base::CancelableTaskTracker* tracker); | 130 base::CancelableTaskTracker* tracker); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 const gfx::Image& image, | 216 const gfx::Image& image, |
| 226 float score, | 217 float score, |
| 227 favicon_base::IconType icon_type); | 218 favicon_base::IconType icon_type); |
| 228 | 219 |
| 229 // Sets the image data for the favicon. | 220 // Sets the image data for the favicon. |
| 230 void SetFavicon(const GURL& url, | 221 void SetFavicon(const GURL& url, |
| 231 const GURL& icon_url, | 222 const GURL& icon_url, |
| 232 const gfx::Image& image, | 223 const gfx::Image& image, |
| 233 favicon_base::IconType icon_type); | 224 favicon_base::IconType icon_type); |
| 234 | 225 |
| 235 // Sets the favicon's data on the NavigationEntry. | 226 // Sets the favicon's data. |
| 236 // If the WebContents has a delegate, it is invalidated (INVALIDATE_TYPE_TAB). | 227 void SetFaviconOnActivePage(const std::vector< |
| 237 void SetFaviconOnNavigationEntry( | 228 favicon_base::FaviconBitmapResult>& favicon_bitmap_results); |
| 238 content::NavigationEntry* entry, | 229 void SetFaviconOnActivePage(const GURL& icon_url, const gfx::Image& image); |
| 239 const std::vector<favicon_base::FaviconBitmapResult>& | |
| 240 favicon_bitmap_results); | |
| 241 void SetFaviconOnNavigationEntry(content::NavigationEntry* entry, | |
| 242 const GURL& icon_url, | |
| 243 const gfx::Image& image); | |
| 244 | 230 |
| 245 // Return the current candidate if any. | 231 // Return the current candidate if any. |
| 246 content::FaviconURL* current_candidate() { | 232 content::FaviconURL* current_candidate() { |
| 247 return (!image_urls_.empty()) ? &image_urls_.front() : NULL; | 233 return (!image_urls_.empty()) ? &image_urls_.front() : NULL; |
| 248 } | 234 } |
| 249 | 235 |
| 236 // Returns wheter the page's url changed since the favicon was requested. | |
|
blundell
2014/05/12 07:52:19
s/wheter/whether
jif
2014/05/12 18:07:41
Done.
| |
| 237 bool PageChangedSinceFaviconWasRequested(); | |
| 238 | |
| 250 // Returns the preferred size of the image. 0 means no preference (any size | 239 // Returns the preferred size of the image. 0 means no preference (any size |
| 251 // will do). | 240 // will do). |
| 252 int preferred_icon_size() const { | 241 int preferred_icon_size() const { |
| 253 if (download_largest_icon_) | 242 if (download_largest_icon_) |
| 254 return 0; | 243 return 0; |
| 255 return icon_types_ == favicon_base::FAVICON ? gfx::kFaviconSize : 0; | 244 return icon_types_ == favicon_base::FAVICON ? gfx::kFaviconSize : 0; |
| 256 } | 245 } |
| 257 | 246 |
| 258 // Sorts the entries in |image_urls_| by icon size in descending order. | 247 // Sorts the entries in |image_urls_| by icon size in descending order. |
| 259 // Additionally removes any entries whose sizes are all greater than the max | 248 // Additionally removes any entries whose sizes are all greater than the max |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 // Best image we've seen so far. As images are downloaded from the page they | 289 // Best image we've seen so far. As images are downloaded from the page they |
| 301 // are stored here. When there is an exact match, or no more images are | 290 // are stored here. When there is an exact match, or no more images are |
| 302 // available the favicon service and the NavigationEntry are updated (assuming | 291 // available the favicon service and the NavigationEntry are updated (assuming |
| 303 // the image is for a favicon). | 292 // the image is for a favicon). |
| 304 FaviconCandidate best_favicon_candidate_; | 293 FaviconCandidate best_favicon_candidate_; |
| 305 | 294 |
| 306 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); | 295 DISALLOW_COPY_AND_ASSIGN(FaviconHandler); |
| 307 }; | 296 }; |
| 308 | 297 |
| 309 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ | 298 #endif // CHROME_BROWSER_FAVICON_FAVICON_HANDLER_H_ |
| OLD | NEW |