| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/favicon_tab_helper.h" | 5 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 6 | 6 |
| 7 #include "chrome/browser/favicon/favicon_handler.h" | 7 #include "chrome/browser/favicon/favicon_handler.h" |
| 8 #include "chrome/browser/favicon/favicon_service_factory.h" | 8 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 9 #include "chrome/browser/favicon/favicon_util.h" | 9 #include "chrome/browser/favicon/favicon_util.h" |
| 10 #include "chrome/browser/history/history_service.h" | 10 #include "chrome/browser/history/history_service.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 service->SetFavicons(entry->GetURL(), favicon.url, history::FAVICON, | 129 service->SetFavicons(entry->GetURL(), favicon.url, history::FAVICON, |
| 130 favicon.image); | 130 favicon.image); |
| 131 } | 131 } |
| 132 | 132 |
| 133 NavigationEntry* FaviconTabHelper::GetActiveEntry() { | 133 NavigationEntry* FaviconTabHelper::GetActiveEntry() { |
| 134 return web_contents()->GetController().GetActiveEntry(); | 134 return web_contents()->GetController().GetActiveEntry(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { | 137 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { |
| 138 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 139 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); |
| 140 if (favicon_service && favicon_service->WasUnableToDownloadFavicon(url)) { |
| 141 DVLOG(1) << "Skip Failed FavIcon: " << url; |
| 142 return 0; |
| 143 } |
| 144 |
| 138 return web_contents()->DownloadImage( | 145 return web_contents()->DownloadImage( |
| 139 url, | 146 url, |
| 140 true, | 147 true, |
| 141 image_size, | 148 image_size, |
| 142 base::Bind(&FaviconTabHelper::DidDownloadFavicon,base::Unretained(this))); | 149 base::Bind(&FaviconTabHelper::DidDownloadFavicon,base::Unretained(this))); |
| 143 } | 150 } |
| 144 | 151 |
| 145 void FaviconTabHelper::NotifyFaviconUpdated(bool icon_url_changed) { | 152 void FaviconTabHelper::NotifyFaviconUpdated(bool icon_url_changed) { |
| 146 content::NotificationService::current()->Notify( | 153 content::NotificationService::current()->Notify( |
| 147 chrome::NOTIFICATION_FAVICON_UPDATED, | 154 chrome::NOTIFICATION_FAVICON_UPDATED, |
| 148 content::Source<WebContents>(web_contents()), | 155 content::Source<WebContents>(web_contents()), |
| 149 content::Details<bool>(&icon_url_changed)); | 156 content::Details<bool>(&icon_url_changed)); |
| 150 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 157 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| 151 } | 158 } |
| 152 | 159 |
| 153 void FaviconTabHelper::NavigateToPendingEntry( | 160 void FaviconTabHelper::NavigateToPendingEntry( |
| 154 const GURL& url, | 161 const GURL& url, |
| 155 NavigationController::ReloadType reload_type) { | 162 NavigationController::ReloadType reload_type) { |
| 156 if (reload_type != NavigationController::NO_RELOAD && | 163 if (reload_type != NavigationController::NO_RELOAD && |
| 157 !profile_->IsOffTheRecord()) { | 164 !profile_->IsOffTheRecord()) { |
| 158 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 165 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 159 profile_, Profile::IMPLICIT_ACCESS); | 166 profile_, Profile::IMPLICIT_ACCESS); |
| 160 if (favicon_service) | 167 if (favicon_service) { |
| 161 favicon_service->SetFaviconOutOfDateForPage(url); | 168 favicon_service->SetFaviconOutOfDateForPage(url); |
| 169 if (reload_type == NavigationController::RELOAD_IGNORING_CACHE) |
| 170 favicon_service->ClearUnableToDownloadFavicons(); |
| 171 } |
| 162 } | 172 } |
| 163 } | 173 } |
| 164 | 174 |
| 165 void FaviconTabHelper::DidNavigateMainFrame( | 175 void FaviconTabHelper::DidNavigateMainFrame( |
| 166 const content::LoadCommittedDetails& details, | 176 const content::LoadCommittedDetails& details, |
| 167 const content::FrameNavigateParams& params) { | 177 const content::FrameNavigateParams& params) { |
| 168 // Get the favicon, either from history or request it from the net. | 178 // Get the favicon, either from history or request it from the net. |
| 169 FetchFavicon(details.entry->GetURL()); | 179 FetchFavicon(details.entry->GetURL()); |
| 170 } | 180 } |
| 171 | 181 |
| 172 void FaviconTabHelper::DidUpdateFaviconURL( | 182 void FaviconTabHelper::DidUpdateFaviconURL( |
| 173 int32 page_id, | 183 int32 page_id, |
| 174 const std::vector<content::FaviconURL>& candidates) { | 184 const std::vector<content::FaviconURL>& candidates) { |
| 175 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); | 185 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); |
| 176 if (touch_icon_handler_.get()) | 186 if (touch_icon_handler_.get()) |
| 177 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); | 187 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); |
| 178 } | 188 } |
| 179 | 189 |
| 180 void FaviconTabHelper::DidDownloadFavicon( | 190 void FaviconTabHelper::DidDownloadFavicon( |
| 181 int id, | 191 int id, |
| 192 int http_status_code, |
| 182 const GURL& image_url, | 193 const GURL& image_url, |
| 183 int requested_size, | 194 int requested_size, |
| 184 const std::vector<SkBitmap>& bitmaps) { | 195 const std::vector<SkBitmap>& bitmaps) { |
| 196 |
| 197 if (bitmaps.empty() && http_status_code == 404) { |
| 198 DVLOG(1) << "Failed to Download Favicon:" << image_url; |
| 199 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 200 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); |
| 201 if (favicon_service) |
| 202 favicon_service->UnableToDownloadFavicon(image_url); |
| 203 } |
| 204 |
| 185 favicon_handler_->OnDidDownloadFavicon( | 205 favicon_handler_->OnDidDownloadFavicon( |
| 186 id, image_url, requested_size, bitmaps); | 206 id, image_url, requested_size, bitmaps); |
| 187 if (touch_icon_handler_.get()) { | 207 if (touch_icon_handler_.get()) { |
| 188 touch_icon_handler_->OnDidDownloadFavicon( | 208 touch_icon_handler_->OnDidDownloadFavicon( |
| 189 id, image_url, requested_size, bitmaps); | 209 id, image_url, requested_size, bitmaps); |
| 190 } | 210 } |
| 191 } | 211 } |
| OLD | NEW |