| 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_download_helper.h" |
| 7 #include "chrome/browser/favicon/favicon_handler.h" | 8 #include "chrome/browser/favicon/favicon_handler.h" |
| 8 #include "chrome/browser/favicon/favicon_service_factory.h" | 9 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 9 #include "chrome/browser/favicon/favicon_util.h" | 10 #include "chrome/browser/favicon/favicon_util.h" |
| 10 #include "chrome/browser/history/history.h" | 11 #include "chrome/browser/history/history.h" |
| 11 #include "chrome/browser/history/history_service_factory.h" | 12 #include "chrome/browser/history/history_service_factory.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/common/icon_messages.h" | 16 #include "chrome/common/icon_messages.h" |
| 16 #include "content/public/browser/favicon_status.h" | 17 #include "content/public/browser/favicon_status.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 31 using content::FaviconStatus; | 32 using content::FaviconStatus; |
| 32 using content::NavigationController; | 33 using content::NavigationController; |
| 33 using content::NavigationEntry; | 34 using content::NavigationEntry; |
| 34 using content::WebContents; | 35 using content::WebContents; |
| 35 | 36 |
| 36 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper) | 37 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper) |
| 37 | 38 |
| 38 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) | 39 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) |
| 39 : content::WebContentsObserver(web_contents), | 40 : content::WebContentsObserver(web_contents), |
| 40 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { | 41 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { |
| 42 favicon_download_helper_.reset(new FaviconDownloadHelper(web_contents, this)); |
| 41 favicon_handler_.reset(new FaviconHandler(profile_, this, | 43 favicon_handler_.reset(new FaviconHandler(profile_, this, |
| 42 FaviconHandler::FAVICON)); | 44 FaviconHandler::FAVICON)); |
| 43 if (chrome::kEnableTouchIcon) | 45 if (chrome::kEnableTouchIcon) |
| 44 touch_icon_handler_.reset(new FaviconHandler(profile_, this, | 46 touch_icon_handler_.reset(new FaviconHandler(profile_, this, |
| 45 FaviconHandler::TOUCH)); | 47 FaviconHandler::TOUCH)); |
| 46 } | 48 } |
| 47 | 49 |
| 48 FaviconTabHelper::~FaviconTabHelper() { | 50 FaviconTabHelper::~FaviconTabHelper() { |
| 49 } | 51 } |
| 50 | 52 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); | 140 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); |
| 139 if (touch_icon_handler_.get()) | 141 if (touch_icon_handler_.get()) |
| 140 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); | 142 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); |
| 141 } | 143 } |
| 142 | 144 |
| 143 NavigationEntry* FaviconTabHelper::GetActiveEntry() { | 145 NavigationEntry* FaviconTabHelper::GetActiveEntry() { |
| 144 return web_contents()->GetController().GetActiveEntry(); | 146 return web_contents()->GetController().GetActiveEntry(); |
| 145 } | 147 } |
| 146 | 148 |
| 147 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { | 149 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { |
| 148 content::RenderViewHost* host = web_contents()->GetRenderViewHost(); | 150 return favicon_download_helper_->DownloadFavicon(url, image_size); |
| 149 int id = FaviconUtil::DownloadFavicon(host, url, image_size); | |
| 150 return id; | |
| 151 } | 151 } |
| 152 | 152 |
| 153 void FaviconTabHelper::NotifyFaviconUpdated() { | 153 void FaviconTabHelper::NotifyFaviconUpdated() { |
| 154 content::NotificationService::current()->Notify( | 154 content::NotificationService::current()->Notify( |
| 155 chrome::NOTIFICATION_FAVICON_UPDATED, | 155 chrome::NOTIFICATION_FAVICON_UPDATED, |
| 156 content::Source<WebContents>(web_contents()), | 156 content::Source<WebContents>(web_contents()), |
| 157 content::NotificationService::NoDetails()); | 157 content::NotificationService::NoDetails()); |
| 158 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 158 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void FaviconTabHelper::NavigateToPendingEntry( | 161 void FaviconTabHelper::NavigateToPendingEntry( |
| 162 const GURL& url, | 162 const GURL& url, |
| 163 NavigationController::ReloadType reload_type) { | 163 NavigationController::ReloadType reload_type) { |
| 164 if (reload_type != NavigationController::NO_RELOAD && | 164 if (reload_type != NavigationController::NO_RELOAD && |
| 165 !profile_->IsOffTheRecord()) { | 165 !profile_->IsOffTheRecord()) { |
| 166 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 166 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 167 profile_, Profile::IMPLICIT_ACCESS); | 167 profile_, Profile::IMPLICIT_ACCESS); |
| 168 if (favicon_service) | 168 if (favicon_service) |
| 169 favicon_service->SetFaviconOutOfDateForPage(url); | 169 favicon_service->SetFaviconOutOfDateForPage(url); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 void FaviconTabHelper::DidNavigateMainFrame( | 173 void FaviconTabHelper::DidNavigateMainFrame( |
| 174 const content::LoadCommittedDetails& details, | 174 const content::LoadCommittedDetails& details, |
| 175 const content::FrameNavigateParams& params) { | 175 const content::FrameNavigateParams& params) { |
| 176 // Get the favicon, either from history or request it from the net. | 176 // Get the favicon, either from history or request it from the net. |
| 177 FetchFavicon(details.entry->GetURL()); | 177 FetchFavicon(details.entry->GetURL()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool FaviconTabHelper::OnMessageReceived(const IPC::Message& message) { | |
| 181 bool message_handled = false; // Allow other handlers to receive these. | |
| 182 IPC_BEGIN_MESSAGE_MAP(FaviconTabHelper, message) | |
| 183 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon) | |
| 184 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | |
| 185 IPC_MESSAGE_UNHANDLED(message_handled = false) | |
| 186 IPC_END_MESSAGE_MAP() | |
| 187 return message_handled; | |
| 188 } | |
| 189 | |
| 190 void FaviconTabHelper::OnDidDownloadFavicon( | 180 void FaviconTabHelper::OnDidDownloadFavicon( |
| 191 int id, | 181 int id, |
| 192 const GURL& image_url, | 182 const GURL& image_url, |
| 193 bool errored, | 183 bool errored, |
| 194 int requested_size, | 184 int requested_size, |
| 195 const std::vector<SkBitmap>& bitmaps) { | 185 const std::vector<SkBitmap>& bitmaps) { |
| 196 favicon_handler_->OnDidDownloadFavicon( | 186 favicon_handler_->OnDidDownloadFavicon( |
| 197 id, image_url, errored, requested_size, bitmaps); | 187 id, image_url, errored, requested_size, bitmaps); |
| 198 if (touch_icon_handler_.get()) { | 188 if (touch_icon_handler_.get()) { |
| 199 touch_icon_handler_->OnDidDownloadFavicon( | 189 touch_icon_handler_->OnDidDownloadFavicon( |
| 200 id, image_url, errored, requested_size, bitmaps); | 190 id, image_url, errored, requested_size, bitmaps); |
| 201 } | 191 } |
| 202 } | 192 } |
| OLD | NEW |