| 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" | |
| 8 #include "chrome/browser/favicon/favicon_handler.h" | 7 #include "chrome/browser/favicon/favicon_handler.h" |
| 9 #include "chrome/browser/favicon/favicon_service_factory.h" | 8 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 10 #include "chrome/browser/favicon/favicon_util.h" | 9 #include "chrome/browser/favicon/favicon_util.h" |
| 11 #include "chrome/browser/history/history.h" | 10 #include "chrome/browser/history/history.h" |
| 12 #include "chrome/browser/history/history_service_factory.h" | 11 #include "chrome/browser/history/history_service_factory.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/icon_messages.h" | |
| 17 #include "content/public/browser/favicon_status.h" | 15 #include "content/public/browser/favicon_status.h" |
| 18 #include "content/public/browser/invalidate_type.h" | 16 #include "content/public/browser/invalidate_type.h" |
| 19 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 20 #include "content/public/browser/navigation_details.h" | 18 #include "content/public/browser/navigation_details.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_contents_delegate.h" | 23 #include "content/public/browser/web_contents_delegate.h" |
| 26 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
| 27 #include "ui/gfx/codec/png_codec.h" | 25 #include "ui/gfx/codec/png_codec.h" |
| 28 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
| 29 #include "ui/gfx/image/image_skia.h" | 27 #include "ui/gfx/image/image_skia.h" |
| 30 #include "ui/gfx/image/image_skia_rep.h" | 28 #include "ui/gfx/image/image_skia_rep.h" |
| 31 | 29 |
| 32 using content::FaviconStatus; | 30 using content::FaviconStatus; |
| 33 using content::NavigationController; | 31 using content::NavigationController; |
| 34 using content::NavigationEntry; | 32 using content::NavigationEntry; |
| 35 using content::WebContents; | 33 using content::WebContents; |
| 36 | 34 |
| 37 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper) | 35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FaviconTabHelper) |
| 38 | 36 |
| 39 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) | 37 FaviconTabHelper::FaviconTabHelper(WebContents* web_contents) |
| 40 : content::WebContentsObserver(web_contents), | 38 : content::WebContentsObserver(web_contents), |
| 41 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { | 39 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { |
| 42 favicon_download_helper_.reset(new FaviconDownloadHelper(web_contents, this)); | |
| 43 favicon_handler_.reset(new FaviconHandler(profile_, this, | 40 favicon_handler_.reset(new FaviconHandler(profile_, this, |
| 44 FaviconHandler::FAVICON)); | 41 FaviconHandler::FAVICON)); |
| 45 if (chrome::kEnableTouchIcon) | 42 if (chrome::kEnableTouchIcon) |
| 46 touch_icon_handler_.reset(new FaviconHandler(profile_, this, | 43 touch_icon_handler_.reset(new FaviconHandler(profile_, this, |
| 47 FaviconHandler::TOUCH)); | 44 FaviconHandler::TOUCH)); |
| 48 } | 45 } |
| 49 | 46 |
| 50 FaviconTabHelper::~FaviconTabHelper() { | 47 FaviconTabHelper::~FaviconTabHelper() { |
| 51 } | 48 } |
| 52 | 49 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const NavigationController& controller = web_contents()->GetController(); | 85 const NavigationController& controller = web_contents()->GetController(); |
| 89 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry()) | 86 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry()) |
| 90 return true; | 87 return true; |
| 91 | 88 |
| 92 content::WebUI* web_ui = web_contents()->GetWebUIForCurrentState(); | 89 content::WebUI* web_ui = web_contents()->GetWebUIForCurrentState(); |
| 93 if (web_ui) | 90 if (web_ui) |
| 94 return !web_ui->ShouldHideFavicon(); | 91 return !web_ui->ShouldHideFavicon(); |
| 95 return true; | 92 return true; |
| 96 } | 93 } |
| 97 | 94 |
| 98 void FaviconTabHelper::OnUpdateFaviconURL( | |
| 99 int32 page_id, | |
| 100 const std::vector<FaviconURL>& candidates) { | |
| 101 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); | |
| 102 if (touch_icon_handler_.get()) | |
| 103 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); | |
| 104 } | |
| 105 | |
| 106 void FaviconTabHelper::SaveFavicon() { | 95 void FaviconTabHelper::SaveFavicon() { |
| 107 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); | 96 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); |
| 108 if (!entry || entry->GetURL().is_empty()) | 97 if (!entry || entry->GetURL().is_empty()) |
| 109 return; | 98 return; |
| 110 | 99 |
| 111 // Make sure the page is in history, otherwise adding the favicon does | 100 // Make sure the page is in history, otherwise adding the favicon does |
| 112 // nothing. | 101 // nothing. |
| 113 HistoryService* history = HistoryServiceFactory::GetForProfile( | 102 HistoryService* history = HistoryServiceFactory::GetForProfile( |
| 114 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); | 103 profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); |
| 115 if (!history) | 104 if (!history) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 127 } | 116 } |
| 128 service->SetFavicons(entry->GetURL(), favicon.url, history::FAVICON, | 117 service->SetFavicons(entry->GetURL(), favicon.url, history::FAVICON, |
| 129 favicon.image); | 118 favicon.image); |
| 130 } | 119 } |
| 131 | 120 |
| 132 NavigationEntry* FaviconTabHelper::GetActiveEntry() { | 121 NavigationEntry* FaviconTabHelper::GetActiveEntry() { |
| 133 return web_contents()->GetController().GetActiveEntry(); | 122 return web_contents()->GetController().GetActiveEntry(); |
| 134 } | 123 } |
| 135 | 124 |
| 136 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { | 125 int FaviconTabHelper::StartDownload(const GURL& url, int image_size) { |
| 137 return favicon_download_helper_->DownloadFavicon(url, image_size); | 126 return web_contents()->DownloadFavicon(url, image_size, |
| 127 base::Bind(&FaviconTabHelper::DidDownloadFavicon, |
| 128 base::Unretained(this))); |
| 138 } | 129 } |
| 139 | 130 |
| 140 void FaviconTabHelper::NotifyFaviconUpdated() { | 131 void FaviconTabHelper::NotifyFaviconUpdated() { |
| 141 content::NotificationService::current()->Notify( | 132 content::NotificationService::current()->Notify( |
| 142 chrome::NOTIFICATION_FAVICON_UPDATED, | 133 chrome::NOTIFICATION_FAVICON_UPDATED, |
| 143 content::Source<WebContents>(web_contents()), | 134 content::Source<WebContents>(web_contents()), |
| 144 content::NotificationService::NoDetails()); | 135 content::NotificationService::NoDetails()); |
| 145 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 136 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| 146 } | 137 } |
| 147 | 138 |
| 148 void FaviconTabHelper::NavigateToPendingEntry( | 139 void FaviconTabHelper::NavigateToPendingEntry( |
| 149 const GURL& url, | 140 const GURL& url, |
| 150 NavigationController::ReloadType reload_type) { | 141 NavigationController::ReloadType reload_type) { |
| 151 if (reload_type != NavigationController::NO_RELOAD && | 142 if (reload_type != NavigationController::NO_RELOAD && |
| 152 !profile_->IsOffTheRecord()) { | 143 !profile_->IsOffTheRecord()) { |
| 153 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 144 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 154 profile_, Profile::IMPLICIT_ACCESS); | 145 profile_, Profile::IMPLICIT_ACCESS); |
| 155 if (favicon_service) | 146 if (favicon_service) |
| 156 favicon_service->SetFaviconOutOfDateForPage(url); | 147 favicon_service->SetFaviconOutOfDateForPage(url); |
| 157 } | 148 } |
| 158 } | 149 } |
| 159 | 150 |
| 160 void FaviconTabHelper::DidNavigateMainFrame( | 151 void FaviconTabHelper::DidNavigateMainFrame( |
| 161 const content::LoadCommittedDetails& details, | 152 const content::LoadCommittedDetails& details, |
| 162 const content::FrameNavigateParams& params) { | 153 const content::FrameNavigateParams& params) { |
| 163 // Get the favicon, either from history or request it from the net. | 154 // Get the favicon, either from history or request it from the net. |
| 164 FetchFavicon(details.entry->GetURL()); | 155 FetchFavicon(details.entry->GetURL()); |
| 165 } | 156 } |
| 166 | 157 |
| 167 void FaviconTabHelper::OnDidDownloadFavicon( | 158 void FaviconTabHelper::DidUpdateFaviconURL( |
| 159 int32 page_id, |
| 160 const std::vector<content::FaviconURL>& candidates) { |
| 161 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); |
| 162 if (touch_icon_handler_.get()) |
| 163 touch_icon_handler_->OnUpdateFaviconURL(page_id, candidates); |
| 164 } |
| 165 |
| 166 void FaviconTabHelper::DidDownloadFavicon( |
| 168 int id, | 167 int id, |
| 169 const GURL& image_url, | 168 const GURL& image_url, |
| 170 bool errored, | 169 bool errored, |
| 171 int requested_size, | 170 int requested_size, |
| 172 const std::vector<SkBitmap>& bitmaps) { | 171 const std::vector<SkBitmap>& bitmaps) { |
| 173 favicon_handler_->OnDidDownloadFavicon( | 172 favicon_handler_->OnDidDownloadFavicon( |
| 174 id, image_url, errored, requested_size, bitmaps); | 173 id, image_url, errored, requested_size, bitmaps); |
| 175 if (touch_icon_handler_.get()) { | 174 if (touch_icon_handler_.get()) { |
| 176 touch_icon_handler_->OnDidDownloadFavicon( | 175 touch_icon_handler_->OnDidDownloadFavicon( |
| 177 id, image_url, errored, requested_size, bitmaps); | 176 id, image_url, errored, requested_size, bitmaps); |
| 178 } | 177 } |
| 179 } | 178 } |
| OLD | NEW |