OLD | NEW |
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 #include "chrome/browser/favicon_helper.h" | 5 #include "chrome/browser/favicon_helper.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 135 |
136 entry->favicon().set_url(icon_url); | 136 entry->favicon().set_url(icon_url); |
137 | 137 |
138 if (got_favicon_from_history_) | 138 if (got_favicon_from_history_) |
139 DownloadFaviconOrAskHistory(entry); | 139 DownloadFaviconOrAskHistory(entry); |
140 } | 140 } |
141 | 141 |
142 bool FaviconHelper::OnMessageReceived(const IPC::Message& message) { | 142 bool FaviconHelper::OnMessageReceived(const IPC::Message& message) { |
143 bool handled = true; | 143 bool handled = true; |
144 IPC_BEGIN_MESSAGE_MAP(FaviconHelper, message) | 144 IPC_BEGIN_MESSAGE_MAP(FaviconHelper, message) |
145 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFavIconURL, OnUpdateFaviconURL) | 145 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
146 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDownloadFavIcon, OnDidDownloadFavicon) | 146 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) |
147 IPC_MESSAGE_UNHANDLED(handled = false) | 147 IPC_MESSAGE_UNHANDLED(handled = false) |
148 IPC_END_MESSAGE_MAP() | 148 IPC_END_MESSAGE_MAP() |
149 return handled; | 149 return handled; |
150 } | 150 } |
151 | 151 |
152 void FaviconHelper::OnDidDownloadFavicon(int id, | 152 void FaviconHelper::OnDidDownloadFavicon(int id, |
153 const GURL& image_url, | 153 const GURL& image_url, |
154 bool errored, | 154 bool errored, |
155 const SkBitmap& image) { | 155 const SkBitmap& image) { |
156 DownloadRequests::iterator i = download_requests_.find(id); | 156 DownloadRequests::iterator i = download_requests_.find(id); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 FaviconService::Handle handle, | 256 FaviconService::Handle handle, |
257 bool know_favicon, | 257 bool know_favicon, |
258 scoped_refptr<RefCountedMemory> data, | 258 scoped_refptr<RefCountedMemory> data, |
259 bool expired, | 259 bool expired, |
260 GURL icon_url) { | 260 GURL icon_url) { |
261 NavigationEntry* entry = GetEntry(); | 261 NavigationEntry* entry = GetEntry(); |
262 if (!entry) | 262 if (!entry) |
263 return; | 263 return; |
264 | 264 |
265 // No need to update the favicon url. By the time we get here | 265 // No need to update the favicon url. By the time we get here |
266 // UpdateFavIconURL will have set the favicon url. | 266 // UpdateFaviconURL will have set the favicon url. |
267 | 267 |
268 if (know_favicon && data.get() && data->size()) { | 268 if (know_favicon && data.get() && data->size()) { |
269 // There is a favicon, set it now. If expired we'll download the current | 269 // There is a favicon, set it now. If expired we'll download the current |
270 // one again, but at least the user will get some icon instead of the | 270 // one again, but at least the user will get some icon instead of the |
271 // default and most likely the current one is fine anyway. | 271 // default and most likely the current one is fine anyway. |
272 UpdateFavicon(entry, data); | 272 UpdateFavicon(entry, data); |
273 } | 273 } |
274 | 274 |
275 if (!know_favicon || expired) { | 275 if (!know_favicon || expired) { |
276 // We don't know the favicon, or it is out of date. Request the current one. | 276 // We don't know the favicon, or it is out of date. Request the current one. |
277 ScheduleDownload(entry->url(), entry->favicon().url(), kFaviconSize, NULL); | 277 ScheduleDownload(entry->url(), entry->favicon().url(), kFaviconSize, NULL); |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
281 int FaviconHelper::ScheduleDownload(const GURL& url, | 281 int FaviconHelper::ScheduleDownload(const GURL& url, |
282 const GURL& image_url, | 282 const GURL& image_url, |
283 int image_size, | 283 int image_size, |
284 ImageDownloadCallback* callback) { | 284 ImageDownloadCallback* callback) { |
285 const int download_id = tab_contents()->render_view_host()->DownloadFavIcon( | 285 const int download_id = tab_contents()->render_view_host()->DownloadFavicon( |
286 image_url, image_size); | 286 image_url, image_size); |
287 | 287 |
288 if (download_id) { | 288 if (download_id) { |
289 // Download ids should be unique. | 289 // Download ids should be unique. |
290 DCHECK(download_requests_.find(download_id) == download_requests_.end()); | 290 DCHECK(download_requests_.find(download_id) == download_requests_.end()); |
291 download_requests_[download_id] = DownloadRequest(url, image_url, callback); | 291 download_requests_[download_id] = DownloadRequest(url, image_url, callback); |
292 } | 292 } |
293 | 293 |
294 return download_id; | 294 return download_id; |
295 } | 295 } |
(...skipping 11 matching lines...) Expand all Loading... |
307 } | 307 } |
308 | 308 |
309 bool FaviconHelper::ShouldSaveFavicon(const GURL& url) { | 309 bool FaviconHelper::ShouldSaveFavicon(const GURL& url) { |
310 if (!profile()->IsOffTheRecord()) | 310 if (!profile()->IsOffTheRecord()) |
311 return true; | 311 return true; |
312 | 312 |
313 // Otherwise store the favicon if the page is bookmarked. | 313 // Otherwise store the favicon if the page is bookmarked. |
314 BookmarkModel* bookmark_model = profile()->GetBookmarkModel(); | 314 BookmarkModel* bookmark_model = profile()->GetBookmarkModel(); |
315 return bookmark_model && bookmark_model->IsBookmarked(url); | 315 return bookmark_model && bookmark_model->IsBookmarked(url); |
316 } | 316 } |
OLD | NEW |