diff options
author | arv@google.com <arv@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 21:56:48 +0000 |
---|---|---|
committer | arv@google.com <arv@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 21:56:48 +0000 |
commit | 0189bc72c90fab03afab623d0b2d8be3d35af3e7 (patch) | |
tree | a1962c2ecddcaf1eb1f1a27f6dde6991d19a9b07 /chrome/browser/dom_ui | |
parent | 34a6418e00deca16a311b331ab4b2f257c674d74 (diff) | |
download | chromium_src-0189bc72c90fab03afab623d0b2d8be3d35af3e7.zip chromium_src-0189bc72c90fab03afab623d0b2d8be3d35af3e7.tar.gz chromium_src-0189bc72c90fab03afab623d0b2d8be3d35af3e7.tar.bz2 |
Adds a FaviconService class tied to the profile.
Original issue: http://codereview.chromium.org/115212/show
The favicons service is the entry point to getting favicons.
Make the DOMUIFactory handle the favicons of DOMUI pages so since DOMUI pages
are never added to the history.
BUG=5840
TEST=Open a new window and open history and downloads (Ctrl+H and Ctrl+J) in
this window. Then close the window and open the NTP. The recently closed
windows/tabs should show the favicons for the hsitroy and downloads page.
Review URL: http://codereview.chromium.org/178001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24806 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_factory.cc | 15 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_factory.h | 7 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_favicon_source.cc | 22 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_favicon_source.h | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_ui.cc | 7 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_ui.h | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/history_ui.cc | 7 | ||||
-rw-r--r-- | chrome/browser/dom_ui/history_ui.h | 4 |
8 files changed, 58 insertions, 12 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc index 8b5a1c2..f776baa 100644 --- a/chrome/browser/dom_ui/dom_ui_factory.cc +++ b/chrome/browser/dom_ui/dom_ui_factory.cc @@ -137,3 +137,18 @@ DOMUI* DOMUIFactory::CreateDOMUIForURL(TabContents* tab_contents, return NULL; return dom_ui; } + +// static +bool DOMUIFactory::GetFaviconResourceBytes(const GURL& page_url, + std::vector<unsigned char>* bytes) { + if (!HasDOMUIScheme(page_url)) + return false; + + if (page_url.host() == chrome::kChromeUIHistoryHost) + return HistoryUI::GetFaviconResourceBytes(bytes); + + if (page_url.host() == chrome::kChromeUIDownloadsHost) + return DownloadsUI::GetFaviconResourceBytes(bytes); + + return false; +} diff --git a/chrome/browser/dom_ui/dom_ui_factory.h b/chrome/browser/dom_ui/dom_ui_factory.h index 8644f64..e4e36c3 100644 --- a/chrome/browser/dom_ui/dom_ui_factory.h +++ b/chrome/browser/dom_ui/dom_ui_factory.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_DOM_UI_DOM_UI_FACTORY_H_ #define CHROME_BROWSER_DOM_UI_DOM_UI_FACTORY_H_ +#include <vector> + class DOMUI; class GURL; class TabContents; @@ -25,6 +27,11 @@ class DOMUIFactory { // the returned pointer is passed to the caller. static DOMUI* CreateDOMUIForURL(TabContents* tab_contents, const GURL& url); + // Gets the data for the favicon for a DOMUI page. Returns false if the DOMUI + // does not have a favicon. + static bool GetFaviconResourceBytes(const GURL& page_url, + std::vector<unsigned char>* bytes); + private: // Class is for scoping only. DOMUIFactory() {}; diff --git a/chrome/browser/dom_ui/dom_ui_favicon_source.cc b/chrome/browser/dom_ui/dom_ui_favicon_source.cc index bb7b9f0..d117b784 100644 --- a/chrome/browser/dom_ui/dom_ui_favicon_source.cc +++ b/chrome/browser/dom_ui/dom_ui_favicon_source.cc @@ -16,36 +16,38 @@ DOMUIFavIconSource::DOMUIFavIconSource(Profile* profile) void DOMUIFavIconSource::StartDataRequest(const std::string& path, int request_id) { - HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (hs) { - HistoryService::Handle handle; + FaviconService* favicon_service = + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); + if (favicon_service) { + FaviconService::Handle handle; if (path.size() > 8 && path.substr(0, 8) == "iconurl/") { - handle = hs->GetFavIcon( + handle = favicon_service->GetFavicon( GURL(path.substr(8)), &cancelable_consumer_, NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable)); } else { - handle = hs->GetFavIconForURL( + handle = favicon_service->GetFaviconForURL( GURL(path), &cancelable_consumer_, NewCallback(this, &DOMUIFavIconSource::OnFavIconDataAvailable)); } // Attach the ChromeURLDataManager request ID to the history request. - cancelable_consumer_.SetClientData(hs, handle, request_id); + cancelable_consumer_.SetClientData(favicon_service, handle, request_id); } else { SendResponse(request_id, NULL); } } void DOMUIFavIconSource::OnFavIconDataAvailable( - HistoryService::Handle request_handle, + FaviconService::Handle request_handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, GURL icon_url) { - HistoryService* hs = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - int request_id = cancelable_consumer_.GetClientData(hs, request_handle); + FaviconService* favicon_service = + profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); + int request_id = cancelable_consumer_.GetClientData(favicon_service, + request_handle); if (know_favicon && data.get() && !data->data.empty()) { // Forward the data along to the networking system. diff --git a/chrome/browser/dom_ui/dom_ui_favicon_source.h b/chrome/browser/dom_ui/dom_ui_favicon_source.h index 42d770c..5e53754 100644 --- a/chrome/browser/dom_ui/dom_ui_favicon_source.h +++ b/chrome/browser/dom_ui/dom_ui_favicon_source.h @@ -10,7 +10,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" -#include "chrome/browser/history/history.h" +#include "chrome/browser/favicon_service.h" class GURL; class Profile; @@ -33,7 +33,7 @@ class DOMUIFavIconSource : public ChromeURLDataManager::DataSource { } // Called when favicon data is available from the history backend. - void OnFavIconDataAvailable(HistoryService::Handle request_handle, + void OnFavIconDataAvailable(FaviconService::Handle request_handle, bool know_favicon, scoped_refptr<RefCountedBytes> data, bool expired, diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc index 5ef1d0d..deb5ef1 100644 --- a/chrome/browser/dom_ui/downloads_ui.cc +++ b/chrome/browser/dom_ui/downloads_ui.cc @@ -18,6 +18,7 @@ #include "chrome/common/url_constants.h" #include "grit/browser_resources.h" #include "grit/generated_resources.h" +#include "grit/theme_resources.h" #if defined(OS_WIN) // TODO(port): re-enable when download_util is ported @@ -136,3 +137,9 @@ DownloadsUI::DownloadsUI(TabContents* contents) : DOMUI(contents) { &ChromeURLDataManager::AddDataSource, html_source)); } + +// static +bool DownloadsUI::GetFaviconResourceBytes(std::vector<unsigned char>* bytes) { + return ResourceBundle::GetSharedInstance(). + LoadImageResourceBytes(IDR_DOWNLOADS_FAVICON, bytes); +} diff --git a/chrome/browser/dom_ui/downloads_ui.h b/chrome/browser/dom_ui/downloads_ui.h index a24e07b..c7ebcdb 100644 --- a/chrome/browser/dom_ui/downloads_ui.h +++ b/chrome/browser/dom_ui/downloads_ui.h @@ -5,12 +5,16 @@ #ifndef CHROME_BROWSER_DOM_UI_DOWNLOADS_UI_H_ #define CHROME_BROWSER_DOM_UI_DOWNLOADS_UI_H_ +#include <vector> + #include "chrome/browser/dom_ui/dom_ui.h" class DownloadsUI : public DOMUI { public: explicit DownloadsUI(TabContents* contents); + static bool GetFaviconResourceBytes(std::vector<unsigned char>* bytes); + private: DISALLOW_COPY_AND_ASSIGN(DownloadsUI); }; diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc index 62e2e5d..c3eb8ad 100644 --- a/chrome/browser/dom_ui/history_ui.cc +++ b/chrome/browser/dom_ui/history_ui.cc @@ -29,6 +29,7 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" +#include "grit/theme_resources.h" // Maximum number of search results to return in a given search. We should // eventually remove this. @@ -377,3 +378,9 @@ const GURL HistoryUI::GetHistoryURLWithSearchText(const std::wstring& text) { return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + EscapeQueryParamValue(WideToUTF8(text))); } + +// static +bool HistoryUI::GetFaviconResourceBytes(std::vector<unsigned char>* bytes) { + return ResourceBundle::GetSharedInstance(). + LoadImageResourceBytes(IDR_HISTORY_FAVICON, bytes); +} diff --git a/chrome/browser/dom_ui/history_ui.h b/chrome/browser/dom_ui/history_ui.h index 0a47120..48b055b 100644 --- a/chrome/browser/dom_ui/history_ui.h +++ b/chrome/browser/dom_ui/history_ui.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_DOM_UI_HISTORY_UI_H_ #define CHROME_BROWSER_DOM_UI_HISTORY_UI_H_ +#include <vector> + #include "base/scoped_ptr.h" #include "chrome/browser/browsing_data_remover.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" @@ -93,6 +95,8 @@ class HistoryUI : public DOMUI { // Return the URL for a given search term. static const GURL GetHistoryURLWithSearchText(const std::wstring& text); + static bool GetFaviconResourceBytes(std::vector<unsigned char>* bytes); + private: DISALLOW_COPY_AND_ASSIGN(HistoryUI); }; |