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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_HELPER_H__ 5 #ifndef CHROME_BROWSER_FAVICON_HELPER_H__
6 #define CHROME_BROWSER_FAVICON_HELPER_H__ 6 #define CHROME_BROWSER_FAVICON_HELPER_H__
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
14 #include "chrome/browser/favicon_service.h" 14 #include "chrome/browser/favicon_service.h"
15 #include "chrome/common/ref_counted_util.h" 15 #include "chrome/common/ref_counted_util.h"
16 #include "content/browser/cancelable_request.h" 16 #include "content/browser/cancelable_request.h"
17 #include "content/browser/tab_contents/navigation_entry.h"
17 #include "content/browser/tab_contents/tab_contents_observer.h" 18 #include "content/browser/tab_contents/tab_contents_observer.h"
18 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
19 20
20 class NavigationEntry; 21 class NavigationEntry;
21 class Profile; 22 class Profile;
22 class RefCountedMemory; 23 class RefCountedMemory;
23 class SkBitmap; 24 class SkBitmap;
24 class TabContents; 25 class TabContents;
25 26
26 // FaviconHelper is used to fetch the favicon for TabContents. 27 // FaviconHelper is used to fetch the favicon for TabContents.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // between page to favicon url. The callback for this is OnFaviconData. 59 // between page to favicon url. The callback for this is OnFaviconData.
59 // 60 //
60 // OnFaviconData either updates the favicon of the NavigationEntry (if the 61 // OnFaviconData either updates the favicon of the NavigationEntry (if the
61 // db knew about the favicon), or requests the renderer to download the 62 // db knew about the favicon), or requests the renderer to download the
62 // favicon. 63 // favicon.
63 // 64 //
64 // When the renderer downloads the favicon SetFaviconImageData is invoked, 65 // When the renderer downloads the favicon SetFaviconImageData is invoked,
65 // at which point we update the favicon of the NavigationEntry and notify 66 // at which point we update the favicon of the NavigationEntry and notify
66 // the database to save the favicon. 67 // the database to save the favicon.
67 68
69 // The Favicon candidate from the loaded page.
70 // Is there any good file to put 'FaviconCandidate'?
71 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.
72 FaviconCandidate();
73 ~FaviconCandidate();
74
75 bool is_same(const GURL& url, history::IconType type);
76 // 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.
77 GURL icon_url;
78
79 // The type of the icon
80 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.
81 };
82
68 class FaviconHelper : public TabContentsObserver { 83 class FaviconHelper : public TabContentsObserver {
69 public: 84 public:
70 explicit FaviconHelper(TabContents* tab_contents); 85 // |supported_icon_types| defines this FaviconHelper supported icon types. It
86 // can be the combination of icon types.
87 FaviconHelper(TabContents* tab_contents,
88 int supported_icon_types,
89 FaviconDelegate* delegate);
71 virtual ~FaviconHelper(); 90 virtual ~FaviconHelper();
72 91
73 // Initiates loading the favicon for the specified url. 92 // Initiates loading the favicon for the specified url.
74 void FetchFavicon(const GURL& url); 93 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
75 94
76 // Initiates loading an image from given |image_url|. Returns a download id 95 // Initiates loading an image from given |image_url|. Returns a download id
77 // for caller to track the request. When download completes, |callback| is 96 // for caller to track the request. When download completes, |callback| is
78 // called with the three params: the download_id, a boolean flag to indicate 97 // called with the three params: the download_id, a boolean flag to indicate
79 // whether the download succeeds and a SkBitmap as the downloaded image. 98 // whether the download succeeds and a SkBitmap as the downloaded image.
80 // Note that |image_size| is a hint for images with multiple sizes. The 99 // Note that |image_size| is a hint for images with multiple sizes. The
81 // downloaded image is not resized to the given image_size. If 0 is passed, 100 // downloaded image is not resized to the given image_size. If 0 is passed,
82 // the first frame of the image is returned. 101 // the first frame of the image is returned.
83 typedef Callback3<int, bool, const SkBitmap&>::Type ImageDownloadCallback; 102 typedef Callback3<int, bool, const SkBitmap&>::Type ImageDownloadCallback;
84 int DownloadImage(const GURL& image_url, int image_size, 103 int DownloadImage(const GURL& image_url,
104 int image_size,
105 history::IconType icon_type,
85 ImageDownloadCallback* callback); 106 ImageDownloadCallback* callback);
86 107
87 // Message Handler. Must be public, because also called from 108 // Message Handler. Must be public, because also called from
88 // PrerenderContents. 109 // PrerenderContents.
89 void OnUpdateFaviconURL(int32 page_id, const GURL& icon_url); 110 void OnUpdateFaviconURL(int32 page_id,
111 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
90 112
91 private: 113 private:
92 struct DownloadRequest { 114 struct DownloadRequest {
93 DownloadRequest() {} 115 DownloadRequest() {}
94 DownloadRequest(const GURL& url, 116 DownloadRequest(const GURL& url,
95 const GURL& image_url, 117 const GURL& image_url,
96 ImageDownloadCallback* callback) 118 ImageDownloadCallback* callback,
119 history::IconType icon_type)
97 : url(url), 120 : url(url),
98 image_url(image_url), 121 image_url(image_url),
99 callback(callback) { } 122 callback(callback),
123 icon_type(icon_type) { }
100 124
101 GURL url; 125 GURL url;
102 GURL image_url; 126 GURL image_url;
103 ImageDownloadCallback* callback; 127 ImageDownloadCallback* callback;
128 history::IconType icon_type;
104 }; 129 };
105 130
106 // TabContentsObserver implementation. 131 // TabContentsObserver implementation.
107 virtual bool OnMessageReceived(const IPC::Message& message); 132 virtual bool OnMessageReceived(const IPC::Message& message);
108 133
109 void OnDidDownloadFavicon(int id, 134 void OnDidDownloadFavicon(int id,
110 const GURL& image_url, 135 const GURL& image_url,
111 bool errored, 136 bool errored,
112 const SkBitmap& image); 137 const SkBitmap& image);
113 138
114 // Return the NavigationEntry for the active entry, or NULL if the active 139 // Return the NavigationEntry for the active entry, or NULL if the active
115 // entries URL does not match that of the URL last passed to FetchFavicon. 140 // entries URL does not match that of the URL last passed to FetchFavicon.
116 NavigationEntry* GetEntry(); 141 NavigationEntry* GetEntry();
117 142
118 Profile* profile(); 143 Profile* profile();
119 144
120 FaviconService* GetFaviconService(); 145 FaviconService* GetFaviconService();
121 146
122 // See description above class for details. 147 // See description above class for details.
123 void OnFaviconDataForInitialURL(FaviconService::Handle handle, 148 void OnFaviconDataForInitialURL(FaviconService::Handle handle,
124 history::FaviconData favicon); 149 history::FaviconData favicon);
125 150
126 // If the favicon has expired, asks the renderer to download the favicon. 151 // If the favicon has expired, asks the renderer to download the favicon.
127 // Otherwise asks history to update the mapping between page url and icon 152 // Otherwise asks history to update the mapping between page url and icon
128 // url with a callback to OnFaviconData when done. 153 // url with a callback to OnFaviconData when done.
129 void DownloadFaviconOrAskHistory(NavigationEntry* entry); 154 void DownloadFaviconOrAskHistory(const GURL& page_url,
155 const GURL& icon_url,
156 history::IconType icon_type);
130 157
131 // See description above class for details. 158 // See description above class for details.
132 void OnFaviconData(FaviconService::Handle handle, 159 void OnFaviconData(FaviconService::Handle handle,
133 history::FaviconData favicon); 160 history::FaviconData favicon);
134 161
135 // Schedules a download for the specified entry. This adds the request to 162 // Schedules a download for the specified entry. This adds the request to
136 // download_requests_. 163 // download_requests_.
137 int ScheduleDownload(const GURL& url, const GURL& image_url, int image_size, 164 int ScheduleDownload(const GURL& url,
165 const GURL& image_url,
166 int image_size,
167 history::IconType icon_type,
138 ImageDownloadCallback* callback); 168 ImageDownloadCallback* callback);
139 169
140 // Sets the image data for the favicon. This is invoked asynchronously after 170 // Sets the image data for the favicon. This is invoked asynchronously after
141 // we request the TabContents to download the favicon. 171 // we request the TabContents to download the favicon.
142 void SetFavicon(const GURL& url, const GURL& icon_url, const SkBitmap& image); 172 void SetFavicon(const GURL& url,
143 173 const GURL& icon_url,
144 // Converts the image data to an SkBitmap and sets it on the NavigationEntry. 174 const SkBitmap& image,
145 // If the TabContents has a delegate, it is notified of the new favicon 175 history::IconType icon_type);
146 // (INVALIDATE_FAVICON).
147 void UpdateFavicon(NavigationEntry* entry,
148 scoped_refptr<RefCountedMemory> data);
149 void UpdateFavicon(NavigationEntry* entry, const SkBitmap& image);
150
151 // Scales the image such that either the width and/or height is 16 pixels
152 // wide. Does nothing if the image is empty.
153 SkBitmap ConvertToFaviconSize(const SkBitmap& image);
154 176
155 // Returns true if the favicon should be saved. 177 // Returns true if the favicon should be saved.
156 bool ShouldSaveFavicon(const GURL& url); 178 bool ShouldSaveFavicon(const GURL& url);
157 179
180 // Return the current candidate if any.
181 FaviconCandidate* Candidate() {
sky 2011/03/18 17:33:37 candidate()
michaelbai 2011/03/22 18:14:13 Done.
182 return favicon_candidates_.size() > current_candidate_idx_?
183 favicon_candidates_[current_candidate_idx_] : NULL;
184 }
185
158 // Used for history requests. 186 // Used for history requests.
159 CancelableRequestConsumer cancelable_consumer_; 187 CancelableRequestConsumer cancelable_consumer_;
160 188
161 // URL of the page we're requesting the favicon for. 189 // URL of the page we're requesting the favicon for.
162 GURL url_; 190 GURL url_;
163 191
164 // Whether we got the url for the page back from the renderer.
165 // See "Favicon Details" in tab_contents.cc for more details.
166 bool got_favicon_url_;
167
168 // Whether we got the initial response for the favicon back from the renderer. 192 // Whether we got the initial response for the favicon back from the renderer.
169 // See "Favicon Details" in tab_contents.cc for more details. 193 // See "Favicon Details" in tab_contents.cc for more details.
170 bool got_favicon_from_history_; 194 bool got_favicon_from_history_;
171 195
172 // Whether the favicon is out of date. If true, it means history knows about 196 // Whether the favicon is out of date. If true, it means history knows about
173 // the favicon, but we need to download the favicon because the icon has 197 // the favicon, but we need to download the favicon because the icon has
174 // expired. 198 // expired.
175 // See "Favicon Details" in tab_contents.cc for more details. 199 // See "Favicon Details" in tab_contents.cc for more details.
176 bool favicon_expired_; 200 bool favicon_expired_;
177 201
178 // Requests to the renderer to download favicons. 202 // Requests to the renderer to download favicons.
179 typedef std::map<int, DownloadRequest> DownloadRequests; 203 typedef std::map<int, DownloadRequest> DownloadRequests;
180 DownloadRequests download_requests_; 204 DownloadRequests download_requests_;
181 205
206 // The combination of the supported icon types.
207 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.
208
209 // The prioritized favicon candidates from the page back from the renderer.
210 std::vector<FaviconCandidate> favicon_candidates_;
211
212 // The current candidate's index in favicon_candidates_.
213 int current_candidate_idx_;
sky 2011/03/18 17:33:37 size_t
michaelbai 2011/03/22 18:14:13 Done.
214
215 // Indicates whether the IPC::Message is handled
216 bool message_handled_;
217
218 // The FaviconData from history.
219 history::FaviconData history_icon_;
220
221 // The FaviconDelegate of this FavIconHelper
222 scoped_ptr<FaviconDelegate> favicon_delegate_;
223
224 // The preferred icon size for supported icon types.
225 const int preferred_icon_size_;
226
182 DISALLOW_COPY_AND_ASSIGN(FaviconHelper); 227 DISALLOW_COPY_AND_ASSIGN(FaviconHelper);
183 }; 228 };
184 229
185 #endif // CHROME_BROWSER_FAVICON_HELPER_H__ 230 #endif // CHROME_BROWSER_FAVICON_HELPER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698