| 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/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/history/history.h" | 8 #include "chrome/browser/history/history.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
| 11 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "chrome/common/icon_messages.h" | 12 #include "chrome/common/icon_messages.h" |
| 13 #include "content/browser/renderer_host/render_view_host.h" | 13 #include "content/browser/renderer_host/render_view_host.h" |
| 14 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
| 15 #include "content/browser/webui/web_ui.h" | 15 #include "content/browser/webui/web_ui.h" |
| 16 #include "content/public/browser/favicon_status.h" | 16 #include "content/public/browser/favicon_status.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/navigation_details.h" | 18 #include "content/public/browser/navigation_details.h" |
| 19 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/web_contents_delegate.h" | 21 #include "content/public/browser/web_contents_delegate.h" |
| 22 #include "ui/gfx/codec/png_codec.h" | 22 #include "ui/gfx/codec/png_codec.h" |
| 23 #include "ui/gfx/image/image.h" | 23 #include "ui/gfx/image/image.h" |
| 24 | 24 |
| 25 using content::FaviconStatus; | 25 using content::FaviconStatus; |
| 26 using content::NavigationController; |
| 26 using content::NavigationEntry; | 27 using content::NavigationEntry; |
| 27 using content::WebContents; | 28 using content::WebContents; |
| 28 | 29 |
| 29 FaviconTabHelper::FaviconTabHelper(TabContents* tab_contents) | 30 FaviconTabHelper::FaviconTabHelper(TabContents* tab_contents) |
| 30 : content::WebContentsObserver(tab_contents), | 31 : content::WebContentsObserver(tab_contents), |
| 31 profile_(Profile::FromBrowserContext(tab_contents->GetBrowserContext())) { | 32 profile_(Profile::FromBrowserContext(tab_contents->GetBrowserContext())) { |
| 32 favicon_handler_.reset(new FaviconHandler(profile_, this, | 33 favicon_handler_.reset(new FaviconHandler(profile_, this, |
| 33 FaviconHandler::FAVICON)); | 34 FaviconHandler::FAVICON)); |
| 34 if (chrome::kEnableTouchIcon) | 35 if (chrome::kEnableTouchIcon) |
| 35 touch_icon_handler_.reset(new FaviconHandler(profile_, this, | 36 touch_icon_handler_.reset(new FaviconHandler(profile_, this, |
| 36 FaviconHandler::TOUCH)); | 37 FaviconHandler::TOUCH)); |
| 37 } | 38 } |
| 38 | 39 |
| 39 FaviconTabHelper::~FaviconTabHelper() { | 40 FaviconTabHelper::~FaviconTabHelper() { |
| 40 } | 41 } |
| 41 | 42 |
| 42 void FaviconTabHelper::FetchFavicon(const GURL& url) { | 43 void FaviconTabHelper::FetchFavicon(const GURL& url) { |
| 43 favicon_handler_->FetchFavicon(url); | 44 favicon_handler_->FetchFavicon(url); |
| 44 if (touch_icon_handler_.get()) | 45 if (touch_icon_handler_.get()) |
| 45 touch_icon_handler_->FetchFavicon(url); | 46 touch_icon_handler_->FetchFavicon(url); |
| 46 } | 47 } |
| 47 | 48 |
| 48 SkBitmap FaviconTabHelper::GetFavicon() const { | 49 SkBitmap FaviconTabHelper::GetFavicon() const { |
| 49 // Like GetTitle(), we also want to use the favicon for the last committed | 50 // Like GetTitle(), we also want to use the favicon for the last committed |
| 50 // entry rather than a pending navigation entry. | 51 // entry rather than a pending navigation entry. |
| 51 const content::NavigationController& controller = | 52 const NavigationController& controller = web_contents()->GetController(); |
| 52 web_contents()->GetController(); | |
| 53 NavigationEntry* entry = controller.GetTransientEntry(); | 53 NavigationEntry* entry = controller.GetTransientEntry(); |
| 54 if (entry) | 54 if (entry) |
| 55 return entry->GetFavicon().bitmap; | 55 return entry->GetFavicon().bitmap; |
| 56 | 56 |
| 57 entry = controller.GetLastCommittedEntry(); | 57 entry = controller.GetLastCommittedEntry(); |
| 58 if (entry) | 58 if (entry) |
| 59 return entry->GetFavicon().bitmap; | 59 return entry->GetFavicon().bitmap; |
| 60 return SkBitmap(); | 60 return SkBitmap(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool FaviconTabHelper::FaviconIsValid() const { | 63 bool FaviconTabHelper::FaviconIsValid() const { |
| 64 const content::NavigationController& controller = | 64 const NavigationController& controller = web_contents()->GetController(); |
| 65 web_contents()->GetController(); | |
| 66 NavigationEntry* entry = controller.GetTransientEntry(); | 65 NavigationEntry* entry = controller.GetTransientEntry(); |
| 67 if (entry) | 66 if (entry) |
| 68 return entry->GetFavicon().valid; | 67 return entry->GetFavicon().valid; |
| 69 | 68 |
| 70 entry = controller.GetLastCommittedEntry(); | 69 entry = controller.GetLastCommittedEntry(); |
| 71 if (entry) | 70 if (entry) |
| 72 return entry->GetFavicon().valid; | 71 return entry->GetFavicon().valid; |
| 73 | 72 |
| 74 return false; | 73 return false; |
| 75 } | 74 } |
| 76 | 75 |
| 77 bool FaviconTabHelper::ShouldDisplayFavicon() { | 76 bool FaviconTabHelper::ShouldDisplayFavicon() { |
| 78 // Always display a throbber during pending loads. | 77 // Always display a throbber during pending loads. |
| 79 const content::NavigationController& controller = | 78 const NavigationController& controller = web_contents()->GetController(); |
| 80 web_contents()->GetController(); | |
| 81 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry()) | 79 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry()) |
| 82 return true; | 80 return true; |
| 83 | 81 |
| 84 WebUI* web_ui = web_contents()->GetWebUIForCurrentState(); | 82 WebUI* web_ui = web_contents()->GetWebUIForCurrentState(); |
| 85 if (web_ui) | 83 if (web_ui) |
| 86 return !web_ui->hide_favicon(); | 84 return !web_ui->hide_favicon(); |
| 87 return true; | 85 return true; |
| 88 } | 86 } |
| 89 | 87 |
| 90 void FaviconTabHelper::SaveFavicon() { | 88 void FaviconTabHelper::SaveFavicon() { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 void FaviconTabHelper::NotifyFaviconUpdated() { | 147 void FaviconTabHelper::NotifyFaviconUpdated() { |
| 150 content::NotificationService::current()->Notify( | 148 content::NotificationService::current()->Notify( |
| 151 chrome::NOTIFICATION_FAVICON_UPDATED, | 149 chrome::NOTIFICATION_FAVICON_UPDATED, |
| 152 content::Source<WebContents>(web_contents()), | 150 content::Source<WebContents>(web_contents()), |
| 153 content::NotificationService::NoDetails()); | 151 content::NotificationService::NoDetails()); |
| 154 web_contents()->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); | 152 web_contents()->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); |
| 155 } | 153 } |
| 156 | 154 |
| 157 void FaviconTabHelper::NavigateToPendingEntry( | 155 void FaviconTabHelper::NavigateToPendingEntry( |
| 158 const GURL& url, | 156 const GURL& url, |
| 159 content::NavigationController::ReloadType reload_type) { | 157 NavigationController::ReloadType reload_type) { |
| 160 if (reload_type != content::NavigationController::NO_RELOAD && | 158 if (reload_type != NavigationController::NO_RELOAD && |
| 161 !profile_->IsOffTheRecord()) { | 159 !profile_->IsOffTheRecord()) { |
| 162 FaviconService* favicon_service = | 160 FaviconService* favicon_service = |
| 163 profile_->GetFaviconService(Profile::IMPLICIT_ACCESS); | 161 profile_->GetFaviconService(Profile::IMPLICIT_ACCESS); |
| 164 if (favicon_service) | 162 if (favicon_service) |
| 165 favicon_service->SetFaviconOutOfDateForPage(url); | 163 favicon_service->SetFaviconOutOfDateForPage(url); |
| 166 } | 164 } |
| 167 } | 165 } |
| 168 | 166 |
| 169 void FaviconTabHelper::DidNavigateMainFrame( | 167 void FaviconTabHelper::DidNavigateMainFrame( |
| 170 const content::LoadCommittedDetails& details, | 168 const content::LoadCommittedDetails& details, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 185 | 183 |
| 186 void FaviconTabHelper::OnDidDownloadFavicon(int id, | 184 void FaviconTabHelper::OnDidDownloadFavicon(int id, |
| 187 const GURL& image_url, | 185 const GURL& image_url, |
| 188 bool errored, | 186 bool errored, |
| 189 const SkBitmap& image) { | 187 const SkBitmap& image) { |
| 190 gfx::Image favicon(new SkBitmap(image)); | 188 gfx::Image favicon(new SkBitmap(image)); |
| 191 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 189 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
| 192 if (touch_icon_handler_.get()) | 190 if (touch_icon_handler_.get()) |
| 193 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 191 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
| 194 } | 192 } |
| OLD | NEW |