| 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/navigation_controller.h" | |
| 15 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
| 16 #include "content/browser/webui/web_ui.h" | 15 #include "content/browser/webui/web_ui.h" |
| 17 #include "content/public/browser/favicon_status.h" | 16 #include "content/public/browser/favicon_status.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::NavigationEntry; | 26 using content::NavigationEntry; |
| 27 using content::WebContents; | 27 using content::WebContents; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 void FaviconTabHelper::FetchFavicon(const GURL& url) { | 42 void FaviconTabHelper::FetchFavicon(const GURL& url) { |
| 43 favicon_handler_->FetchFavicon(url); | 43 favicon_handler_->FetchFavicon(url); |
| 44 if (touch_icon_handler_.get()) | 44 if (touch_icon_handler_.get()) |
| 45 touch_icon_handler_->FetchFavicon(url); | 45 touch_icon_handler_->FetchFavicon(url); |
| 46 } | 46 } |
| 47 | 47 |
| 48 SkBitmap FaviconTabHelper::GetFavicon() const { | 48 SkBitmap FaviconTabHelper::GetFavicon() const { |
| 49 // Like GetTitle(), we also want to use the favicon for the last committed | 49 // Like GetTitle(), we also want to use the favicon for the last committed |
| 50 // entry rather than a pending navigation entry. | 50 // entry rather than a pending navigation entry. |
| 51 const NavigationController& controller = web_contents()->GetController(); | 51 const content::NavigationController& controller = |
| 52 web_contents()->GetController(); |
| 52 NavigationEntry* entry = controller.GetTransientEntry(); | 53 NavigationEntry* entry = controller.GetTransientEntry(); |
| 53 if (entry) | 54 if (entry) |
| 54 return entry->GetFavicon().bitmap; | 55 return entry->GetFavicon().bitmap; |
| 55 | 56 |
| 56 entry = controller.GetLastCommittedEntry(); | 57 entry = controller.GetLastCommittedEntry(); |
| 57 if (entry) | 58 if (entry) |
| 58 return entry->GetFavicon().bitmap; | 59 return entry->GetFavicon().bitmap; |
| 59 return SkBitmap(); | 60 return SkBitmap(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 bool FaviconTabHelper::FaviconIsValid() const { | 63 bool FaviconTabHelper::FaviconIsValid() const { |
| 63 const NavigationController& controller = web_contents()->GetController(); | 64 const content::NavigationController& controller = |
| 65 web_contents()->GetController(); |
| 64 NavigationEntry* entry = controller.GetTransientEntry(); | 66 NavigationEntry* entry = controller.GetTransientEntry(); |
| 65 if (entry) | 67 if (entry) |
| 66 return entry->GetFavicon().valid; | 68 return entry->GetFavicon().valid; |
| 67 | 69 |
| 68 entry = controller.GetLastCommittedEntry(); | 70 entry = controller.GetLastCommittedEntry(); |
| 69 if (entry) | 71 if (entry) |
| 70 return entry->GetFavicon().valid; | 72 return entry->GetFavicon().valid; |
| 71 | 73 |
| 72 return false; | 74 return false; |
| 73 } | 75 } |
| 74 | 76 |
| 75 bool FaviconTabHelper::ShouldDisplayFavicon() { | 77 bool FaviconTabHelper::ShouldDisplayFavicon() { |
| 76 // Always display a throbber during pending loads. | 78 // Always display a throbber during pending loads. |
| 77 const NavigationController& controller = web_contents()->GetController(); | 79 const content::NavigationController& controller = |
| 80 web_contents()->GetController(); |
| 78 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry()) | 81 if (controller.GetLastCommittedEntry() && controller.GetPendingEntry()) |
| 79 return true; | 82 return true; |
| 80 | 83 |
| 81 WebUI* web_ui = web_contents()->GetWebUIForCurrentState(); | 84 WebUI* web_ui = web_contents()->GetWebUIForCurrentState(); |
| 82 if (web_ui) | 85 if (web_ui) |
| 83 return !web_ui->hide_favicon(); | 86 return !web_ui->hide_favicon(); |
| 84 return true; | 87 return true; |
| 85 } | 88 } |
| 86 | 89 |
| 87 void FaviconTabHelper::SaveFavicon() { | 90 void FaviconTabHelper::SaveFavicon() { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 185 |
| 183 void FaviconTabHelper::OnDidDownloadFavicon(int id, | 186 void FaviconTabHelper::OnDidDownloadFavicon(int id, |
| 184 const GURL& image_url, | 187 const GURL& image_url, |
| 185 bool errored, | 188 bool errored, |
| 186 const SkBitmap& image) { | 189 const SkBitmap& image) { |
| 187 gfx::Image favicon(new SkBitmap(image)); | 190 gfx::Image favicon(new SkBitmap(image)); |
| 188 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 191 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
| 189 if (touch_icon_handler_.get()) | 192 if (touch_icon_handler_.get()) |
| 190 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); | 193 touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon); |
| 191 } | 194 } |
| OLD | NEW |