Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4897)

Unified Diff: chrome/browser/favicon_helper.h

Issue 6672065: Support touch icon in FaviconHelper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only update the FAVICON data to the NavigationEntry. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/favicon_helper.h
diff --git a/chrome/browser/favicon_helper.h b/chrome/browser/favicon_helper.h
index 0c10ff4db9d782cdc418025bc91c3fc789d1687d..c1bc7946f95205607f2645e6745e26f9bda159b3 100644
--- a/chrome/browser/favicon_helper.h
+++ b/chrome/browser/favicon_helper.h
@@ -14,6 +14,7 @@
#include "chrome/browser/favicon_service.h"
#include "chrome/common/ref_counted_util.h"
#include "content/browser/cancelable_request.h"
+#include "content/browser/tab_contents/navigation_entry.h"
#include "content/browser/tab_contents/tab_contents_observer.h"
#include "googleurl/src/gurl.h"
@@ -65,13 +66,31 @@ class TabContents;
// at which point we update the favicon of the NavigationEntry and notify
// the database to save the favicon.
+// The Favicon candidate from the loaded page.
+// Is there any good file to put 'FaviconCandidate'?
+struct FaviconCandidate {
sky 2011/03/18 17:33:37 This should exist in src/chrome/common/icon_messag
michaelbai 2011/03/22 18:14:13 Done.
+ FaviconCandidate();
+ ~FaviconCandidate();
+
+ bool is_same(const GURL& url, history::IconType type);
+ // The url of the icon.
sky 2011/03/18 17:33:37 newline between 75 and 76.
michaelbai 2011/03/22 18:14:13 Done.
+ GURL icon_url;
+
+ // The type of the icon
+ history::IconType icon_type;
sky 2011/03/18 17:33:37 The renderer shouldn't use history types, so you'l
michaelbai 2011/03/22 18:14:13 Done.
+};
+
class FaviconHelper : public TabContentsObserver {
public:
- explicit FaviconHelper(TabContents* tab_contents);
+ // |supported_icon_types| defines this FaviconHelper supported icon types. It
+ // can be the combination of icon types.
+ FaviconHelper(TabContents* tab_contents,
+ int supported_icon_types,
+ FaviconDelegate* delegate);
virtual ~FaviconHelper();
// Initiates loading the favicon for the specified url.
- void FetchFavicon(const GURL& url);
+ void FetchFavicon(const GURL& url, int icon_types);
sky 2011/03/18 17:33:37 Why does Fetch need to take icon_types when the co
michaelbai 2011/03/22 18:14:13 Removed
// Initiates loading an image from given |image_url|. Returns a download id
// for caller to track the request. When download completes, |callback| is
@@ -81,26 +100,32 @@ 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<FaviconCandidate>& candidates);
sky 2011/03/18 17:33:37 References passed to methods need to be const.
michaelbai 2011/03/22 18:14:13 tried, got the compile error in, No std::vectors a
private:
struct DownloadRequest {
DownloadRequest() {}
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) { }
GURL url;
GURL image_url;
ImageDownloadCallback* callback;
+ history::IconType icon_type;
};
// TabContentsObserver implementation.
@@ -126,7 +151,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,37 +161,34 @@ 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);
-
- // Converts the 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,
- scoped_refptr<RefCountedMemory> data);
- void UpdateFavicon(NavigationEntry* entry, const SkBitmap& image);
-
- // Scales the image such that either the width and/or height is 16 pixels
- // wide. Does nothing if the image is empty.
- SkBitmap ConvertToFaviconSize(const SkBitmap& image);
+ void SetFavicon(const GURL& url,
+ const GURL& icon_url,
+ const SkBitmap& image,
+ history::IconType icon_type);
// Returns true if the favicon should be saved.
bool ShouldSaveFavicon(const GURL& url);
+ // Return the current candidate if any.
+ FaviconCandidate* Candidate() {
sky 2011/03/18 17:33:37 candidate()
michaelbai 2011/03/22 18:14:13 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 +203,27 @@ class FaviconHelper : public TabContentsObserver {
typedef std::map<int, DownloadRequest> DownloadRequests;
DownloadRequests download_requests_;
+ // The combination of the supported icon types.
+ const int supported_icon_types_;
sky 2011/03/18 17:33:37 No need for supported, just icon_types_.
michaelbai 2011/03/22 18:14:13 Done.
+
+ // The prioritized favicon candidates from the page back from the renderer.
+ std::vector<FaviconCandidate> favicon_candidates_;
+
+ // The current candidate's index in favicon_candidates_.
+ int current_candidate_idx_;
sky 2011/03/18 17:33:37 size_t
michaelbai 2011/03/22 18:14:13 Done.
+
+ // Indicates whether the IPC::Message is handled
+ bool message_handled_;
+
+ // The FaviconData from history.
+ history::FaviconData history_icon_;
+
+ // The FaviconDelegate of this FavIconHelper
+ scoped_ptr<FaviconDelegate> favicon_delegate_;
+
+ // The preferred icon size for supported icon types.
+ const int preferred_icon_size_;
+
DISALLOW_COPY_AND_ASSIGN(FaviconHelper);
};

Powered by Google App Engine
This is Rietveld 408576698