| 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_tab_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 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_model.h" | 13 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
| 16 #include "content/browser/renderer_host/render_view_host.h" | 16 #include "content/browser/renderer_host/render_view_host.h" |
| 17 #include "content/browser/tab_contents/navigation_controller.h" | 17 #include "content/browser/tab_contents/navigation_controller.h" |
| 18 #include "content/browser/tab_contents/navigation_entry.h" | 18 #include "content/browser/tab_contents/navigation_entry.h" |
| 19 #include "content/browser/tab_contents/tab_contents_delegate.h" | 19 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 20 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
| 21 #include "content/browser/webui/web_ui.h" |
| 21 #include "skia/ext/image_operations.h" | 22 #include "skia/ext/image_operations.h" |
| 22 #include "ui/gfx/codec/png_codec.h" | 23 #include "ui/gfx/codec/png_codec.h" |
| 23 #include "ui/gfx/favicon_size.h" | 24 #include "ui/gfx/favicon_size.h" |
| 24 | 25 |
| 25 FaviconHelper::FaviconHelper(TabContents* tab_contents) | 26 FaviconTabHelper::FaviconTabHelper(TabContents* tab_contents) |
| 26 : TabContentsObserver(tab_contents), | 27 : TabContentsObserver(tab_contents), |
| 27 got_favicon_url_(false), | 28 got_favicon_url_(false), |
| 28 got_favicon_from_history_(false), | 29 got_favicon_from_history_(false), |
| 29 favicon_expired_(false) { | 30 favicon_expired_(false) { |
| 30 } | 31 } |
| 31 | 32 |
| 32 FaviconHelper::~FaviconHelper() { | 33 FaviconTabHelper::~FaviconTabHelper() { |
| 33 SkBitmap empty_image; | 34 SkBitmap empty_image; |
| 34 | 35 |
| 35 // Call pending download callbacks with error to allow caller to clean up. | 36 // Call pending download callbacks with error to allow caller to clean up. |
| 36 for (DownloadRequests::iterator i = download_requests_.begin(); | 37 for (DownloadRequests::iterator i = download_requests_.begin(); |
| 37 i != download_requests_.end(); ++i) { | 38 i != download_requests_.end(); ++i) { |
| 38 if (i->second.callback) { | 39 if (i->second.callback) { |
| 39 i->second.callback->Run(i->first, true, empty_image); | 40 i->second.callback->Run(i->first, true, empty_image); |
| 40 } | 41 } |
| 41 } | 42 } |
| 42 } | 43 } |
| 43 | 44 |
| 44 void FaviconHelper::FetchFavicon(const GURL& url) { | 45 SkBitmap FaviconTabHelper::GetFavicon() const { |
| 46 // Like GetTitle(), we also want to use the favicon for the last committed |
| 47 // entry rather than a pending navigation entry. |
| 48 NavigationEntry* entry = tab_contents()->controller().GetTransientEntry(); |
| 49 if (entry) |
| 50 return entry->favicon().bitmap(); |
| 51 |
| 52 entry = tab_contents()->controller().GetLastCommittedEntry(); |
| 53 if (entry) |
| 54 return entry->favicon().bitmap(); |
| 55 return SkBitmap(); |
| 56 } |
| 57 |
| 58 bool FaviconTabHelper::FaviconIsValid() const { |
| 59 const NavigationController& controller = tab_contents()->controller(); |
| 60 NavigationEntry* entry = controller.GetTransientEntry(); |
| 61 if (entry) |
| 62 return entry->favicon().is_valid(); |
| 63 |
| 64 entry = controller.GetLastCommittedEntry(); |
| 65 if (entry) |
| 66 return entry->favicon().is_valid(); |
| 67 |
| 68 return false; |
| 69 } |
| 70 |
| 71 bool FaviconTabHelper::ShouldDisplayFavicon() { |
| 72 // Always display a throbber during pending loads. |
| 73 const NavigationController& controller = tab_contents()->controller(); |
| 74 if (controller.GetLastCommittedEntry() && controller.pending_entry()) |
| 75 return true; |
| 76 |
| 77 WebUI* web_ui = tab_contents()->GetWebUIForCurrentState(); |
| 78 if (web_ui) |
| 79 return !web_ui->hide_favicon(); |
| 80 return true; |
| 81 } |
| 82 |
| 83 void FaviconTabHelper::FetchFavicon(const GURL& url) { |
| 45 cancelable_consumer_.CancelAllRequests(); | 84 cancelable_consumer_.CancelAllRequests(); |
| 46 | 85 |
| 47 url_ = url; | 86 url_ = url; |
| 48 | 87 |
| 49 favicon_expired_ = got_favicon_from_history_ = got_favicon_url_ = false; | 88 favicon_expired_ = got_favicon_from_history_ = got_favicon_url_ = false; |
| 50 | 89 |
| 51 // Request the favicon from the history service. In parallel to this the | 90 // Request the favicon from the history service. In parallel to this the |
| 52 // renderer is going to notify us (well TabContents) when the favicon url is | 91 // renderer is going to notify us (well TabContents) when the favicon url is |
| 53 // available. | 92 // available. |
| 54 if (GetFaviconService()) { | 93 if (GetFaviconService()) { |
| 55 GetFaviconService()->GetFaviconForURL(url_, history::FAVICON, | 94 GetFaviconService()->GetFaviconForURL(url_, history::FAVICON, |
| 56 &cancelable_consumer_, | 95 &cancelable_consumer_, |
| 57 NewCallback(this, &FaviconHelper::OnFaviconDataForInitialURL)); | 96 NewCallback(this, &FaviconTabHelper::OnFaviconDataForInitialURL)); |
| 58 } | 97 } |
| 59 } | 98 } |
| 60 | 99 |
| 61 int FaviconHelper::DownloadImage(const GURL& image_url, | 100 int FaviconTabHelper::DownloadImage(const GURL& image_url, |
| 62 int image_size, | 101 int image_size, |
| 63 ImageDownloadCallback* callback) { | 102 ImageDownloadCallback* callback) { |
| 64 DCHECK(callback); // Must provide a callback. | 103 DCHECK(callback); // Must provide a callback. |
| 65 return ScheduleDownload(GURL(), image_url, image_size, callback); | 104 return ScheduleDownload(GURL(), image_url, image_size, callback); |
| 66 } | 105 } |
| 67 | 106 |
| 68 Profile* FaviconHelper::profile() { | 107 FaviconService* FaviconTabHelper::GetFaviconService() { |
| 69 return tab_contents()->profile(); | 108 return tab_contents()->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 70 } | 109 } |
| 71 | 110 |
| 72 FaviconService* FaviconHelper::GetFaviconService() { | 111 void FaviconTabHelper::SetFavicon( |
| 73 return profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); | |
| 74 } | |
| 75 | |
| 76 void FaviconHelper::SetFavicon( | |
| 77 const GURL& url, | 112 const GURL& url, |
| 78 const GURL& image_url, | 113 const GURL& image_url, |
| 79 const SkBitmap& image) { | 114 const SkBitmap& image) { |
| 80 const SkBitmap& sized_image = | 115 const SkBitmap& sized_image = |
| 81 (image.width() == kFaviconSize && image.height() == kFaviconSize) | 116 (image.width() == kFaviconSize && image.height() == kFaviconSize) |
| 82 ? image : ConvertToFaviconSize(image); | 117 ? image : ConvertToFaviconSize(image); |
| 83 | 118 |
| 84 if (GetFaviconService() && ShouldSaveFavicon(url)) { | 119 if (GetFaviconService() && ShouldSaveFavicon(url)) { |
| 85 std::vector<unsigned char> image_data; | 120 std::vector<unsigned char> image_data; |
| 86 gfx::PNGCodec::EncodeBGRASkBitmap(sized_image, false, &image_data); | 121 gfx::PNGCodec::EncodeBGRASkBitmap(sized_image, false, &image_data); |
| 87 GetFaviconService()->SetFavicon(url, image_url, image_data, | 122 GetFaviconService()->SetFavicon(url, image_url, image_data, |
| 88 history::FAVICON); | 123 history::FAVICON); |
| 89 } | 124 } |
| 90 | 125 |
| 91 if (url == url_) { | 126 if (url == url_) { |
| 92 NavigationEntry* entry = GetEntry(); | 127 NavigationEntry* entry = GetEntry(); |
| 93 if (entry) | 128 if (entry) |
| 94 UpdateFavicon(entry, sized_image); | 129 UpdateFavicon(entry, sized_image); |
| 95 } | 130 } |
| 96 } | 131 } |
| 97 | 132 |
| 98 void FaviconHelper::UpdateFavicon(NavigationEntry* entry, | 133 void FaviconTabHelper::SaveFavicon() { |
| 99 scoped_refptr<RefCountedMemory> data) { | 134 NavigationEntry* entry = tab_contents()->controller().GetActiveEntry(); |
| 135 if (!entry || entry->url().is_empty()) |
| 136 return; |
| 137 |
| 138 // Make sure the page is in history, otherwise adding the favicon does |
| 139 // nothing. |
| 140 HistoryService* history = |
| 141 tab_contents()->profile()->GetOriginalProfile()->GetHistoryService( |
| 142 Profile::IMPLICIT_ACCESS); |
| 143 if (!history) |
| 144 return; |
| 145 history->AddPageNoVisitForBookmark(entry->url()); |
| 146 |
| 147 FaviconService* service = tab_contents()->profile()-> |
| 148 GetOriginalProfile()->GetFaviconService(Profile::IMPLICIT_ACCESS); |
| 149 if (!service) |
| 150 return; |
| 151 const NavigationEntry::FaviconStatus& favicon(entry->favicon()); |
| 152 if (!favicon.is_valid() || favicon.url().is_empty() || |
| 153 favicon.bitmap().empty()) { |
| 154 return; |
| 155 } |
| 156 std::vector<unsigned char> image_data; |
| 157 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data); |
| 158 service->SetFavicon( |
| 159 entry->url(), favicon.url(), image_data, history::FAVICON); |
| 160 } |
| 161 |
| 162 void FaviconTabHelper::UpdateFavicon(NavigationEntry* entry, |
| 163 scoped_refptr<RefCountedMemory> data) { |
| 100 SkBitmap image; | 164 SkBitmap image; |
| 101 gfx::PNGCodec::Decode(data->front(), data->size(), &image); | 165 gfx::PNGCodec::Decode(data->front(), data->size(), &image); |
| 102 UpdateFavicon(entry, image); | 166 UpdateFavicon(entry, image); |
| 103 } | 167 } |
| 104 | 168 |
| 105 void FaviconHelper::UpdateFavicon(NavigationEntry* entry, | 169 void FaviconTabHelper::UpdateFavicon(NavigationEntry* entry, |
| 106 const SkBitmap& image) { | 170 const SkBitmap& image) { |
| 107 // No matter what happens, we need to mark the favicon as being set. | 171 // No matter what happens, we need to mark the favicon as being set. |
| 108 entry->favicon().set_is_valid(true); | 172 entry->favicon().set_is_valid(true); |
| 109 | 173 |
| 110 if (image.empty()) | 174 if (image.empty()) |
| 111 return; | 175 return; |
| 112 | 176 |
| 113 entry->favicon().set_bitmap(image); | 177 entry->favicon().set_bitmap(image); |
| 114 tab_contents()->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); | 178 tab_contents()->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); |
| 115 } | 179 } |
| 116 | 180 |
| 117 void FaviconHelper::OnUpdateFaviconURL(int32 page_id, const GURL& icon_url) { | 181 void FaviconTabHelper::OnUpdateFaviconURL(int32 page_id, const GURL& icon_url) { |
| 118 // TODO(davemoore) Should clear on empty url. Currently we ignore it. | 182 // TODO(davemoore) Should clear on empty url. Currently we ignore it. |
| 119 // This appears to be what FF does as well. | 183 // This appears to be what FF does as well. |
| 120 if (icon_url.is_empty()) | 184 if (icon_url.is_empty()) |
| 121 return; | 185 return; |
| 122 | 186 |
| 123 NavigationEntry* entry = GetEntry(); | 187 NavigationEntry* entry = GetEntry(); |
| 124 if (!entry) | 188 if (!entry) |
| 125 return; | 189 return; |
| 126 | 190 |
| 127 got_favicon_url_ = true; | 191 got_favicon_url_ = true; |
| 128 | 192 |
| 129 if (!GetFaviconService()) | 193 if (!GetFaviconService()) |
| 130 return; | 194 return; |
| 131 | 195 |
| 132 if (!favicon_expired_ && entry->favicon().is_valid() && | 196 if (!favicon_expired_ && entry->favicon().is_valid() && |
| 133 entry->favicon().url() == icon_url) { | 197 entry->favicon().url() == icon_url) { |
| 134 // We already have the icon, no need to proceed. | 198 // We already have the icon, no need to proceed. |
| 135 return; | 199 return; |
| 136 } | 200 } |
| 137 | 201 |
| 138 entry->favicon().set_url(icon_url); | 202 entry->favicon().set_url(icon_url); |
| 139 | 203 |
| 140 if (got_favicon_from_history_) | 204 if (got_favicon_from_history_) |
| 141 DownloadFaviconOrAskHistory(entry); | 205 DownloadFaviconOrAskHistory(entry); |
| 142 } | 206 } |
| 143 | 207 |
| 144 bool FaviconHelper::OnMessageReceived(const IPC::Message& message) { | 208 void FaviconTabHelper::NavigateToPendingEntry( |
| 209 const GURL& url, |
| 210 NavigationController::ReloadType reload_type) { |
| 211 if (reload_type != NavigationController::NO_RELOAD && |
| 212 !tab_contents()->profile()->IsOffTheRecord()) { |
| 213 FaviconService* favicon_service = |
| 214 tab_contents()->profile()->GetFaviconService(Profile::IMPLICIT_ACCESS); |
| 215 if (favicon_service) |
| 216 favicon_service->SetFaviconOutOfDateForPage(url); |
| 217 } |
| 218 } |
| 219 |
| 220 void FaviconTabHelper::DidNavigateMainFramePostCommit( |
| 221 const NavigationController::LoadCommittedDetails& details, |
| 222 const ViewHostMsg_FrameNavigate_Params& /*params*/) { |
| 223 // Get the favicon, either from history or request it from the net. |
| 224 FetchFavicon(details.entry->url()); |
| 225 } |
| 226 |
| 227 bool FaviconTabHelper::OnMessageReceived(const IPC::Message& message) { |
| 145 bool handled = true; | 228 bool handled = true; |
| 146 IPC_BEGIN_MESSAGE_MAP(FaviconHelper, message) | 229 IPC_BEGIN_MESSAGE_MAP(FaviconTabHelper, message) |
| 147 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | 230 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
| 148 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) | 231 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) |
| 149 IPC_MESSAGE_UNHANDLED(handled = false) | 232 IPC_MESSAGE_UNHANDLED(handled = false) |
| 150 IPC_END_MESSAGE_MAP() | 233 IPC_END_MESSAGE_MAP() |
| 151 return handled; | 234 return handled; |
| 152 } | 235 } |
| 153 | 236 |
| 154 void FaviconHelper::OnDidDownloadFavicon(int id, | 237 void FaviconTabHelper::OnDidDownloadFavicon(int id, |
| 155 const GURL& image_url, | 238 const GURL& image_url, |
| 156 bool errored, | 239 bool errored, |
| 157 const SkBitmap& image) { | 240 const SkBitmap& image) { |
| 158 DownloadRequests::iterator i = download_requests_.find(id); | 241 DownloadRequests::iterator i = download_requests_.find(id); |
| 159 if (i == download_requests_.end()) { | 242 if (i == download_requests_.end()) { |
| 160 // Currently TabContents notifies us of ANY downloads so that it is | 243 // Currently TabContents notifies us of ANY downloads so that it is |
| 161 // possible to get here. | 244 // possible to get here. |
| 162 return; | 245 return; |
| 163 } | 246 } |
| 164 | 247 |
| 165 if (i->second.callback) { | 248 if (i->second.callback) { |
| 166 i->second.callback->Run(id, errored, image); | 249 i->second.callback->Run(id, errored, image); |
| 167 } else if (!errored) { | 250 } else if (!errored) { |
| 168 SetFavicon(i->second.url, image_url, image); | 251 SetFavicon(i->second.url, image_url, image); |
| 169 } | 252 } |
| 170 | 253 |
| 171 download_requests_.erase(i); | 254 download_requests_.erase(i); |
| 172 } | 255 } |
| 173 | 256 |
| 174 NavigationEntry* FaviconHelper::GetEntry() { | 257 NavigationEntry* FaviconTabHelper::GetEntry() { |
| 175 NavigationEntry* entry = tab_contents()->controller().GetActiveEntry(); | 258 NavigationEntry* entry = tab_contents()->controller().GetActiveEntry(); |
| 176 if (entry && entry->url() == url_ && | 259 if (entry && entry->url() == url_ && |
| 177 tab_contents()->IsActiveEntry(entry->page_id())) { | 260 tab_contents()->IsActiveEntry(entry->page_id())) { |
| 178 return entry; | 261 return entry; |
| 179 } | 262 } |
| 180 // If the URL has changed out from under us (as will happen with redirects) | 263 // If the URL has changed out from under us (as will happen with redirects) |
| 181 // return NULL. | 264 // return NULL. |
| 182 return NULL; | 265 return NULL; |
| 183 } | 266 } |
| 184 | 267 |
| 185 void FaviconHelper::OnFaviconDataForInitialURL( | 268 void FaviconTabHelper::OnFaviconDataForInitialURL( |
| 186 FaviconService::Handle handle, | 269 FaviconService::Handle handle, |
| 187 history::FaviconData favicon) { | 270 history::FaviconData favicon) { |
| 188 NavigationEntry* entry = GetEntry(); | 271 NavigationEntry* entry = GetEntry(); |
| 189 if (!entry) | 272 if (!entry) |
| 190 return; | 273 return; |
| 191 | 274 |
| 192 got_favicon_from_history_ = true; | 275 got_favicon_from_history_ = true; |
| 193 | 276 |
| 194 favicon_expired_ = (favicon.known_icon && favicon.expired); | 277 favicon_expired_ = (favicon.known_icon && favicon.expired); |
| 195 | 278 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 215 } else if (got_favicon_url_) { | 298 } else if (got_favicon_url_) { |
| 216 // We know the official url for the favicon, by either don't have the | 299 // We know the official url for the favicon, by either don't have the |
| 217 // favicon or its expired. Continue on to DownloadFaviconOrAskHistory to | 300 // favicon or its expired. Continue on to DownloadFaviconOrAskHistory to |
| 218 // either download or check history again. | 301 // either download or check history again. |
| 219 DownloadFaviconOrAskHistory(entry); | 302 DownloadFaviconOrAskHistory(entry); |
| 220 } | 303 } |
| 221 // else we haven't got the icon url. When we get it we'll ask the | 304 // else we haven't got the icon url. When we get it we'll ask the |
| 222 // renderer to download the icon. | 305 // renderer to download the icon. |
| 223 } | 306 } |
| 224 | 307 |
| 225 void FaviconHelper::DownloadFaviconOrAskHistory(NavigationEntry* entry) { | 308 void FaviconTabHelper::DownloadFaviconOrAskHistory(NavigationEntry* entry) { |
| 226 DCHECK(entry); // We should only get here if entry is valid. | 309 DCHECK(entry); // We should only get here if entry is valid. |
| 227 if (favicon_expired_) { | 310 if (favicon_expired_) { |
| 228 // We have the mapping, but the favicon is out of date. Download it now. | 311 // We have the mapping, but the favicon is out of date. Download it now. |
| 229 ScheduleDownload(entry->url(), entry->favicon().url(), kFaviconSize, NULL); | 312 ScheduleDownload(entry->url(), entry->favicon().url(), kFaviconSize, NULL); |
| 230 } else if (GetFaviconService()) { | 313 } else if (GetFaviconService()) { |
| 231 // We don't know the favicon, but we may have previously downloaded the | 314 // We don't know the favicon, but we may have previously downloaded the |
| 232 // favicon for another page that shares the same favicon. Ask for the | 315 // favicon for another page that shares the same favicon. Ask for the |
| 233 // favicon given the favicon URL. | 316 // favicon given the favicon URL. |
| 234 if (profile()->IsOffTheRecord()) { | 317 if (tab_contents()->profile()->IsOffTheRecord()) { |
| 235 GetFaviconService()->GetFavicon( | 318 GetFaviconService()->GetFavicon( |
| 236 entry->favicon().url(), | 319 entry->favicon().url(), |
| 237 history::FAVICON, | 320 history::FAVICON, |
| 238 &cancelable_consumer_, | 321 &cancelable_consumer_, |
| 239 NewCallback(this, &FaviconHelper::OnFaviconData)); | 322 NewCallback(this, &FaviconTabHelper::OnFaviconData)); |
| 240 } else { | 323 } else { |
| 241 // Ask the history service for the icon. This does two things: | 324 // Ask the history service for the icon. This does two things: |
| 242 // 1. Attempts to fetch the favicon data from the database. | 325 // 1. Attempts to fetch the favicon data from the database. |
| 243 // 2. If the favicon exists in the database, this updates the database to | 326 // 2. If the favicon exists in the database, this updates the database to |
| 244 // include the mapping between the page url and the favicon url. | 327 // include the mapping between the page url and the favicon url. |
| 245 // This is asynchronous. The history service will call back when done. | 328 // This is asynchronous. The history service will call back when done. |
| 246 // Issue the request and associate the current page ID with it. | 329 // Issue the request and associate the current page ID with it. |
| 247 GetFaviconService()->UpdateFaviconMappingAndFetch( | 330 GetFaviconService()->UpdateFaviconMappingAndFetch( |
| 248 entry->url(), | 331 entry->url(), |
| 249 entry->favicon().url(), | 332 entry->favicon().url(), |
| 250 history::FAVICON, | 333 history::FAVICON, |
| 251 &cancelable_consumer_, | 334 &cancelable_consumer_, |
| 252 NewCallback(this, &FaviconHelper::OnFaviconData)); | 335 NewCallback(this, &FaviconTabHelper::OnFaviconData)); |
| 253 } | 336 } |
| 254 } | 337 } |
| 255 } | 338 } |
| 256 | 339 |
| 257 void FaviconHelper::OnFaviconData( | 340 void FaviconTabHelper::OnFaviconData( |
| 258 FaviconService::Handle handle, | 341 FaviconService::Handle handle, |
| 259 history::FaviconData favicon) { | 342 history::FaviconData favicon) { |
| 260 NavigationEntry* entry = GetEntry(); | 343 NavigationEntry* entry = GetEntry(); |
| 261 if (!entry) | 344 if (!entry) |
| 262 return; | 345 return; |
| 263 | 346 |
| 264 // No need to update the favicon url. By the time we get here | 347 // No need to update the favicon url. By the time we get here |
| 265 // UpdateFaviconURL will have set the favicon url. | 348 // UpdateFaviconURL will have set the favicon url. |
| 266 | 349 |
| 267 if (favicon.is_valid()) { | 350 if (favicon.is_valid()) { |
| 268 // There is a favicon, set it now. If expired we'll download the current | 351 // There is a favicon, set it now. If expired we'll download the current |
| 269 // one again, but at least the user will get some icon instead of the | 352 // one again, but at least the user will get some icon instead of the |
| 270 // default and most likely the current one is fine anyway. | 353 // default and most likely the current one is fine anyway. |
| 271 UpdateFavicon(entry, favicon.image_data); | 354 UpdateFavicon(entry, favicon.image_data); |
| 272 } | 355 } |
| 273 | 356 |
| 274 if (!favicon.known_icon || favicon.expired) { | 357 if (!favicon.known_icon || favicon.expired) { |
| 275 // We don't know the favicon, or it is out of date. Request the current one. | 358 // We don't know the favicon, or it is out of date. Request the current one. |
| 276 ScheduleDownload(entry->url(), entry->favicon().url(), kFaviconSize, NULL); | 359 ScheduleDownload(entry->url(), entry->favicon().url(), kFaviconSize, NULL); |
| 277 } | 360 } |
| 278 } | 361 } |
| 279 | 362 |
| 280 int FaviconHelper::ScheduleDownload(const GURL& url, | 363 int FaviconTabHelper::ScheduleDownload(const GURL& url, |
| 281 const GURL& image_url, | 364 const GURL& image_url, |
| 282 int image_size, | 365 int image_size, |
| 283 ImageDownloadCallback* callback) { | 366 ImageDownloadCallback* callback) { |
| 284 const int download_id = tab_contents()->render_view_host()->DownloadFavicon( | 367 const int download_id = tab_contents()->render_view_host()->DownloadFavicon( |
| 285 image_url, image_size); | 368 image_url, image_size); |
| 286 | 369 |
| 287 if (download_id) { | 370 if (download_id) { |
| 288 // Download ids should be unique. | 371 // Download ids should be unique. |
| 289 DCHECK(download_requests_.find(download_id) == download_requests_.end()); | 372 DCHECK(download_requests_.find(download_id) == download_requests_.end()); |
| 290 download_requests_[download_id] = DownloadRequest(url, image_url, callback); | 373 download_requests_[download_id] = DownloadRequest(url, image_url, callback); |
| 291 } | 374 } |
| 292 | 375 |
| 293 return download_id; | 376 return download_id; |
| 294 } | 377 } |
| 295 | 378 |
| 296 SkBitmap FaviconHelper::ConvertToFaviconSize(const SkBitmap& image) { | 379 SkBitmap FaviconTabHelper::ConvertToFaviconSize(const SkBitmap& image) { |
| 297 int width = image.width(); | 380 int width = image.width(); |
| 298 int height = image.height(); | 381 int height = image.height(); |
| 299 if (width > 0 && height > 0) { | 382 if (width > 0 && height > 0) { |
| 300 calc_favicon_target_size(&width, &height); | 383 calc_favicon_target_size(&width, &height); |
| 301 return skia::ImageOperations::Resize( | 384 return skia::ImageOperations::Resize( |
| 302 image, skia::ImageOperations::RESIZE_LANCZOS3, | 385 image, skia::ImageOperations::RESIZE_LANCZOS3, |
| 303 width, height); | 386 width, height); |
| 304 } | 387 } |
| 305 return image; | 388 return image; |
| 306 } | 389 } |
| 307 | 390 |
| 308 bool FaviconHelper::ShouldSaveFavicon(const GURL& url) { | 391 bool FaviconTabHelper::ShouldSaveFavicon(const GURL& url) { |
| 309 if (!profile()->IsOffTheRecord()) | 392 if (!tab_contents()->profile()->IsOffTheRecord()) |
| 310 return true; | 393 return true; |
| 311 | 394 |
| 312 // Otherwise store the favicon if the page is bookmarked. | 395 // Otherwise store the favicon if the page is bookmarked. |
| 313 BookmarkModel* bookmark_model = profile()->GetBookmarkModel(); | 396 BookmarkModel* bookmark_model = tab_contents()->profile()->GetBookmarkModel(); |
| 314 return bookmark_model && bookmark_model->IsBookmarked(url); | 397 return bookmark_model && bookmark_model->IsBookmarked(url); |
| 315 } | 398 } |
| OLD | NEW |