diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-03 21:15:04 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-03 21:15:04 +0000 |
commit | b375c5d778c54e62bf74c5c51ce76edb3520e1dc (patch) | |
tree | 539128cf7124a4ec9587408276ca9524cabea227 /chrome/browser/favicon | |
parent | fc1dd7291703907024908821ad69b8d6903e96d8 (diff) | |
download | chromium_src-b375c5d778c54e62bf74c5c51ce76edb3520e1dc.zip chromium_src-b375c5d778c54e62bf74c5c51ce76edb3520e1dc.tar.gz chromium_src-b375c5d778c54e62bf74c5c51ce76edb3520e1dc.tar.bz2 |
Move favicon from TabContents to TabContentsWrapper.
BUG=71097
TEST=no visible change
Review URL: http://codereview.chromium.org/6909027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83966 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/favicon')
-rw-r--r-- | chrome/browser/favicon/favicon_tab_helper.cc | 91 | ||||
-rw-r--r-- | chrome/browser/favicon/favicon_tab_helper.h | 23 |
2 files changed, 113 insertions, 1 deletions
diff --git a/chrome/browser/favicon/favicon_tab_helper.cc b/chrome/browser/favicon/favicon_tab_helper.cc index f6908fb..ecaa29b 100644 --- a/chrome/browser/favicon/favicon_tab_helper.cc +++ b/chrome/browser/favicon/favicon_tab_helper.cc @@ -6,7 +6,12 @@ #include "chrome/browser/defaults.h" #include "chrome/browser/favicon/favicon_handler.h" +#include "chrome/browser/history/history.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/icon_messages.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/webui/web_ui.h" +#include "ui/gfx/codec/png_codec.h" FaviconTabHelper::FaviconTabHelper(TabContents* tab_contents) : TabContentsObserver(tab_contents) { @@ -26,6 +31,73 @@ void FaviconTabHelper::FetchFavicon(const GURL& url) { touch_icon_handler_->FetchFavicon(url); } +SkBitmap FaviconTabHelper::GetFavicon() const { + // Like GetTitle(), we also want to use the favicon for the last committed + // entry rather than a pending navigation entry. + const NavigationController& controller = tab_contents()->controller(); + NavigationEntry* entry = controller.GetTransientEntry(); + if (entry) + return entry->favicon().bitmap(); + + entry = controller.GetLastCommittedEntry(); + if (entry) + return entry->favicon().bitmap(); + return SkBitmap(); +} + +bool FaviconTabHelper::FaviconIsValid() const { + const NavigationController& controller = tab_contents()->controller(); + NavigationEntry* entry = controller.GetTransientEntry(); + if (entry) + return entry->favicon().is_valid(); + + entry = controller.GetLastCommittedEntry(); + if (entry) + return entry->favicon().is_valid(); + + return false; +} + +bool FaviconTabHelper::ShouldDisplayFavicon() { + // Always display a throbber during pending loads. + const NavigationController& controller = tab_contents()->controller(); + if (controller.GetLastCommittedEntry() && controller.pending_entry()) + return true; + + WebUI* web_ui = tab_contents()->GetWebUIForCurrentState(); + if (web_ui) + return !web_ui->hide_favicon(); + return true; +} + +void FaviconTabHelper::SaveFavicon() { + NavigationEntry* entry = tab_contents()->controller().GetActiveEntry(); + if (!entry || entry->url().is_empty()) + return; + + // Make sure the page is in history, otherwise adding the favicon does + // nothing. + HistoryService* history = tab_contents()->profile()-> + GetOriginalProfile()->GetHistoryService(Profile::IMPLICIT_ACCESS); + if (!history) + return; + history->AddPageNoVisitForBookmark(entry->url()); + + FaviconService* service = tab_contents()->profile()-> + GetOriginalProfile()->GetFaviconService(Profile::IMPLICIT_ACCESS); + if (!service) + return; + const NavigationEntry::FaviconStatus& favicon(entry->favicon()); + if (!favicon.is_valid() || favicon.url().is_empty() || + favicon.bitmap().empty()) { + return; + } + std::vector<unsigned char> image_data; + gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data); + service->SetFavicon( + entry->url(), favicon.url(), image_data, history::FAVICON); +} + int FaviconTabHelper::DownloadImage(const GURL& image_url, int image_size, history::IconType icon_type, @@ -39,6 +111,25 @@ int FaviconTabHelper::DownloadImage(const GURL& image_url, return 0; } +void FaviconTabHelper::NavigateToPendingEntry( + const GURL& url, + NavigationController::ReloadType reload_type) { + if (reload_type != NavigationController::NO_RELOAD && + !tab_contents()->profile()->IsOffTheRecord()) { + FaviconService* favicon_service = + tab_contents()->profile()->GetFaviconService(Profile::IMPLICIT_ACCESS); + if (favicon_service) + favicon_service->SetFaviconOutOfDateForPage(url); + } +} + +void FaviconTabHelper::DidNavigateMainFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) { + // Get the favicon, either from history or request it from the net. + FetchFavicon(details.entry->url()); +} + bool FaviconTabHelper::OnMessageReceived(const IPC::Message& message) { bool message_handled = true; IPC_BEGIN_MESSAGE_MAP(FaviconTabHelper, message) diff --git a/chrome/browser/favicon/favicon_tab_helper.h b/chrome/browser/favicon/favicon_tab_helper.h index 64064f4..a558848 100644 --- a/chrome/browser/favicon/favicon_tab_helper.h +++ b/chrome/browser/favicon/favicon_tab_helper.h @@ -15,7 +15,6 @@ class FaviconHandler; class NavigationEntry; -class Profile; class RefCountedMemory; class SkBitmap; class TabContents; @@ -37,6 +36,22 @@ class FaviconTabHelper : public TabContentsObserver { // Initiates loading the favicon for the specified url. void FetchFavicon(const GURL& url); + // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does + // not have a favicon. The default implementation uses the current navigation + // entry. This will return an isNull bitmap if there are no navigation + // entries, which should rarely happen. + SkBitmap GetFavicon() const; + + // Returns true if we are not using the default favicon. + bool FaviconIsValid() const; + + // Returns whether the favicon should be displayed. If this returns false, no + // space is provided for the favicon, and the favicon is never displayed. + virtual bool ShouldDisplayFavicon(); + + // Saves the favicon for the current page. + void SaveFavicon(); + // Initiates loading an image from given |image_url|. Returns a download id // for caller to track the request. When download completes, |callback| is // called with the three params: the download_id, a boolean flag to indicate @@ -57,6 +72,12 @@ class FaviconTabHelper : public TabContentsObserver { private: // TabContentsObserver overrides. + virtual void NavigateToPendingEntry( + const GURL& url, + NavigationController::ReloadType reload_type) OVERRIDE; + virtual void DidNavigateMainFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; void OnDidDownloadFavicon(int id, |