Index: chrome/browser/favicon_helper.h |
diff --git a/chrome/browser/favicon_helper.h b/chrome/browser/favicon_helper.h |
index 0c10ff4db9d782cdc418025bc91c3fc789d1687d..a9b89ed72d8d257c67614de52225678c878fc2d5 100644 |
--- a/chrome/browser/favicon_helper.h |
+++ b/chrome/browser/favicon_helper.h |
@@ -12,6 +12,7 @@ |
#include "base/callback.h" |
#include "base/ref_counted.h" |
#include "chrome/browser/favicon_service.h" |
+#include "chrome/common/icon_messages.h" |
#include "chrome/common/ref_counted_util.h" |
#include "content/browser/cancelable_request.h" |
#include "content/browser/tab_contents/tab_contents_observer.h" |
@@ -67,7 +68,14 @@ class TabContents; |
class FaviconHelper : public TabContentsObserver { |
public: |
- explicit FaviconHelper(TabContents* tab_contents); |
+ // |icon_types| defines this FaviconHelper supported icon types. It can be the |
sky
2011/03/22 19:48:48
|icon_types| is a bitmask of the supported icon ty
michaelbai
2011/03/22 23:59:03
Done.
|
+ // combination of icon types. |preferred_icon_size| indicates the preferred |
+ // icon size, the preferred icon is fetched from network and converted if the |
+ // size is not matched; It can be 0 if there is no preference, the icon from |
sky
2011/03/22 19:48:48
; -> . or It -> it
michaelbai
2011/03/22 23:59:03
Done.
|
+ // network will be left as it. |
+ FaviconHelper(TabContents* tab_contents, |
+ int icon_types, |
sky
2011/03/22 19:48:48
I don't think it makes sense to let folks specify
michaelbai
2011/03/22 23:59:03
Done.
|
+ int preferred_icon_size); |
virtual ~FaviconHelper(); |
// Initiates loading the favicon for the specified url. |
@@ -81,28 +89,41 @@ class FaviconHelper : public TabContentsObserver { |
// downloaded image is not resized to the given image_size. If 0 is passed, |
// the first frame of the image is returned. |
typedef Callback3<int, bool, const SkBitmap&>::Type ImageDownloadCallback; |
- int DownloadImage(const GURL& image_url, int image_size, |
+ int DownloadImage(const GURL& image_url, |
+ int image_size, |
+ history::IconType icon_type, |
ImageDownloadCallback* callback); |
// Message Handler. Must be public, because also called from |
// PrerenderContents. |
- void OnUpdateFaviconURL(int32 page_id, const GURL& icon_url); |
+ void OnUpdateFaviconURL(int32 page_id, |
+ std::vector<FaviconURL> candidates); |
sky
2011/03/22 19:48:48
const std::vector<>&
michaelbai
2011/03/22 23:59:03
Done.
|
private: |
struct DownloadRequest { |
DownloadRequest() {} |
sky
2011/03/22 19:48:48
initialize icon_type and callback here.
michaelbai
2011/03/22 23:59:03
Done.
|
DownloadRequest(const GURL& url, |
const GURL& image_url, |
- ImageDownloadCallback* callback) |
+ ImageDownloadCallback* callback, |
+ history::IconType icon_type) |
: url(url), |
image_url(image_url), |
- callback(callback) { } |
+ callback(callback), |
+ icon_type(icon_type) { } |
sky
2011/03/22 19:48:48
{ } -> {}
michaelbai
2011/03/22 23:59:03
Done.
|
GURL url; |
GURL image_url; |
ImageDownloadCallback* callback; |
+ history::IconType icon_type; |
}; |
+ static bool IsSameFaviconURL(const FaviconURL& favicon_url, |
sky
2011/03/22 19:48:48
This should be unix_hacker_style. Also, the name i
michaelbai
2011/03/22 23:59:03
Done.
|
+ const GURL& url, |
+ history::IconType icon_type) { |
+ return favicon_url.icon_url == url && |
+ favicon_url.icon_type == static_cast<IconType>(icon_type); |
+ } |
+ |
// TabContentsObserver implementation. |
virtual bool OnMessageReceived(const IPC::Message& message); |
@@ -126,7 +147,9 @@ class FaviconHelper : public TabContentsObserver { |
// If the favicon has expired, asks the renderer to download the favicon. |
// Otherwise asks history to update the mapping between page url and icon |
// url with a callback to OnFaviconData when done. |
- void DownloadFaviconOrAskHistory(NavigationEntry* entry); |
+ void DownloadFaviconOrAskHistory(const GURL& page_url, |
+ const GURL& icon_url, |
+ history::IconType icon_type); |
// See description above class for details. |
void OnFaviconData(FaviconService::Handle handle, |
@@ -134,14 +157,21 @@ class FaviconHelper : public TabContentsObserver { |
// Schedules a download for the specified entry. This adds the request to |
// download_requests_. |
- int ScheduleDownload(const GURL& url, const GURL& image_url, int image_size, |
+ int ScheduleDownload(const GURL& url, |
+ const GURL& image_url, |
+ int image_size, |
+ history::IconType icon_type, |
ImageDownloadCallback* callback); |
// Sets the image data for the favicon. This is invoked asynchronously after |
// we request the TabContents to download the favicon. |
- void SetFavicon(const GURL& url, const GURL& icon_url, const SkBitmap& image); |
+ void SetFavicon(const GURL& url, |
+ const GURL& icon_url, |
+ const SkBitmap& image, |
+ history::IconType icon_type); |
- // Converts the image data to an SkBitmap and sets it on the NavigationEntry. |
+ // Converts the FAVICON's image data to an SkBitmap and sets it on the |
+ // NavigationEntry. |
// If the TabContents has a delegate, it is notified of the new favicon |
// (INVALIDATE_FAVICON). |
void UpdateFavicon(NavigationEntry* entry, |
@@ -155,16 +185,18 @@ class FaviconHelper : public TabContentsObserver { |
// Returns true if the favicon should be saved. |
bool ShouldSaveFavicon(const GURL& url); |
+ // Return the current candidate if any. |
+ FaviconURL* candidate() { |
sky
2011/03/22 19:48:48
current_candidate()
michaelbai
2011/03/22 23:59:03
Done.
|
+ return (favicon_candidates_.size() > current_candidate_idx_) ? |
+ &favicon_candidates_[current_candidate_idx_] : NULL; |
+ } |
+ |
// Used for history requests. |
CancelableRequestConsumer cancelable_consumer_; |
// URL of the page we're requesting the favicon for. |
GURL url_; |
- // Whether we got the url for the page back from the renderer. |
- // See "Favicon Details" in tab_contents.cc for more details. |
- bool got_favicon_url_; |
- |
// Whether we got the initial response for the favicon back from the renderer. |
// See "Favicon Details" in tab_contents.cc for more details. |
bool got_favicon_from_history_; |
@@ -179,6 +211,21 @@ class FaviconHelper : public TabContentsObserver { |
typedef std::map<int, DownloadRequest> DownloadRequests; |
DownloadRequests download_requests_; |
+ // The combination of the supported icon types. |
+ const int icon_types_; |
+ |
+ // The prioritized favicon candidates from the page back from the renderer. |
+ std::vector<FaviconURL> favicon_candidates_; |
sky
2011/03/22 19:48:48
How about naming this urls_ ? If you change it, up
michaelbai
2011/03/22 23:59:03
Done.
|
+ |
+ // The current candidate's index in favicon_candidates_. |
+ size_t current_candidate_idx_; |
sky
2011/03/22 19:48:48
idx -> index
michaelbai
2011/03/22 23:59:03
Done.
|
+ |
+ // The FaviconData from history. |
+ history::FaviconData history_icon_; |
+ |
+ // The preferred icon size for supported icon types. |
+ int preferred_icon_size_; |
+ |
DISALLOW_COPY_AND_ASSIGN(FaviconHelper); |
}; |