Commit a72f0b2c authored by jif@chromium.org's avatar jif@chromium.org

Replace content's faviconURL with components/favicon's

BUG=359586

Review URL: https://codereview.chromium.org/285293005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271367 0039d316-1c4b-4281-b951-d872f2087c98
parent dc437832
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_util.h" #include "ui/gfx/image/image_util.h"
using content::FaviconURL; using favicon::FaviconURL;
namespace { namespace {
...@@ -29,22 +29,6 @@ namespace { ...@@ -29,22 +29,6 @@ namespace {
// the apple touch icon for iPad. // the apple touch icon for iPad.
const int kTouchIconSize = 144; const int kTouchIconSize = 144;
// Returns favicon_base::IconType the given icon_type corresponds to.
favicon_base::IconType ToChromeIconType(FaviconURL::IconType icon_type) {
switch (icon_type) {
case FaviconURL::FAVICON:
return favicon_base::FAVICON;
case FaviconURL::TOUCH_ICON:
return favicon_base::TOUCH_ICON;
case FaviconURL::TOUCH_PRECOMPOSED_ICON:
return favicon_base::TOUCH_PRECOMPOSED_ICON;
case FaviconURL::INVALID_ICON:
return favicon_base::INVALID_ICON;
}
NOTREACHED();
return favicon_base::INVALID_ICON;
}
// Get the maximal icon size in pixels for a icon of type |icon_type| for the // Get the maximal icon size in pixels for a icon of type |icon_type| for the
// current platform. // current platform.
int GetMaximalIconSize(favicon_base::IconType icon_type) { int GetMaximalIconSize(favicon_base::IconType icon_type) {
...@@ -68,8 +52,7 @@ int GetMaximalIconSize(favicon_base::IconType icon_type) { ...@@ -68,8 +52,7 @@ int GetMaximalIconSize(favicon_base::IconType icon_type) {
bool DoUrlAndIconMatch(const FaviconURL& favicon_url, bool DoUrlAndIconMatch(const FaviconURL& favicon_url,
const GURL& url, const GURL& url,
favicon_base::IconType icon_type) { favicon_base::IconType icon_type) {
return favicon_url.icon_url == url && return favicon_url.icon_url == url && favicon_url.icon_type == icon_type;
ToChromeIconType(favicon_url.icon_type) == icon_type;
} }
// Returns true if all of the icon URLs and icon types in |bitmap_results| are // Returns true if all of the icon URLs and icon types in |bitmap_results| are
...@@ -81,8 +64,7 @@ bool DoUrlsAndIconsMatch( ...@@ -81,8 +64,7 @@ bool DoUrlsAndIconsMatch(
if (bitmap_results.empty()) if (bitmap_results.empty())
return false; return false;
const favicon_base::IconType icon_type = const favicon_base::IconType icon_type = favicon_url.icon_type;
ToChromeIconType(favicon_url.icon_type);
for (size_t i = 0; i < bitmap_results.size(); ++i) { for (size_t i = 0; i < bitmap_results.size(); ++i) {
if (favicon_url.icon_url != bitmap_results[i].icon_url || if (favicon_url.icon_url != bitmap_results[i].icon_url ||
...@@ -393,7 +375,7 @@ void FaviconHandler::ProcessCurrentUrl() { ...@@ -393,7 +375,7 @@ void FaviconHandler::ProcessCurrentUrl() {
if (PageChangedSinceFaviconWasRequested() || !current_candidate()) if (PageChangedSinceFaviconWasRequested() || !current_candidate())
return; return;
if (current_candidate()->icon_type == FaviconURL::FAVICON) { if (current_candidate()->icon_type == favicon_base::FAVICON) {
if (!favicon_expired_or_incomplete_ && if (!favicon_expired_or_incomplete_ &&
driver_->GetActiveFaviconValidity() && driver_->GetActiveFaviconValidity() &&
DoUrlAndIconMatch(*current_candidate(), DoUrlAndIconMatch(*current_candidate(),
...@@ -407,10 +389,9 @@ void FaviconHandler::ProcessCurrentUrl() { ...@@ -407,10 +389,9 @@ void FaviconHandler::ProcessCurrentUrl() {
} }
if (got_favicon_from_history_) if (got_favicon_from_history_)
DownloadFaviconOrAskFaviconService( DownloadFaviconOrAskFaviconService(driver_->GetActiveURL(),
driver_->GetActiveURL(), current_candidate()->icon_url,
current_candidate()->icon_url, current_candidate()->icon_type);
ToChromeIconType(current_candidate()->icon_type));
} }
void FaviconHandler::OnDidDownloadFavicon( void FaviconHandler::OnDidDownloadFavicon(
...@@ -592,19 +573,17 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( ...@@ -592,19 +573,17 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
// Mapping in the database is wrong. DownloadFavIconOrAskHistory will // Mapping in the database is wrong. DownloadFavIconOrAskHistory will
// update the mapping for this url and download the favicon if we don't // update the mapping for this url and download the favicon if we don't
// already have it. // already have it.
DownloadFaviconOrAskFaviconService( DownloadFaviconOrAskFaviconService(driver_->GetActiveURL(),
driver_->GetActiveURL(), current_candidate()->icon_url,
current_candidate()->icon_url, current_candidate()->icon_type);
ToChromeIconType(current_candidate()->icon_type));
} }
} else if (current_candidate()) { } else if (current_candidate()) {
// We know the official url for the favicon, but either don't have the // We know the official url for the favicon, but either don't have the
// favicon or it's expired. Continue on to DownloadFaviconOrAskHistory to // favicon or it's expired. Continue on to DownloadFaviconOrAskHistory to
// either download or check history again. // either download or check history again.
DownloadFaviconOrAskFaviconService( DownloadFaviconOrAskFaviconService(driver_->GetActiveURL(),
driver_->GetActiveURL(), current_candidate()->icon_url,
current_candidate()->icon_url, current_candidate()->icon_type);
ToChromeIconType(current_candidate()->icon_type));
} }
// else we haven't got the icon url. When we get it we'll ask the // else we haven't got the icon url. When we get it we'll ask the
// renderer to download the icon. // renderer to download the icon.
...@@ -669,7 +648,7 @@ void FaviconHandler::OnFaviconData(const std::vector< ...@@ -669,7 +648,7 @@ void FaviconHandler::OnFaviconData(const std::vector<
// one got from page. Request the current one. // one got from page. Request the current one.
ScheduleDownload(driver_->GetActiveURL(), ScheduleDownload(driver_->GetActiveURL(),
current_candidate()->icon_url, current_candidate()->icon_url,
ToChromeIconType(current_candidate()->icon_type)); current_candidate()->icon_type);
} }
history_results_ = favicon_bitmap_results; history_results_ = favicon_bitmap_results;
} }
...@@ -699,7 +678,7 @@ void FaviconHandler::SortAndPruneImageUrls() { ...@@ -699,7 +678,7 @@ void FaviconHandler::SortAndPruneImageUrls() {
++i; ++i;
continue; continue;
} }
int max_size = GetMaximalIconSize(ToChromeIconType(i->icon_type)); int max_size = GetMaximalIconSize(i->icon_type);
int index = GetLargestSizeIndex(i->icon_sizes, max_size * max_size); int index = GetLargestSizeIndex(i->icon_sizes, max_size * max_size);
if (index == -1) { if (index == -1) {
i = image_urls_.erase(i); i = image_urls_.erase(i);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "base/task/cancelable_task_tracker.h" #include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/favicon/favicon_tab_helper.h"
#include "content/public/common/favicon_url.h" #include "components/favicon/core/favicon_url.h"
#include "ui/gfx/favicon_size.h" #include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -92,7 +92,7 @@ class FaviconHandler { ...@@ -92,7 +92,7 @@ class FaviconHandler {
// Message Handler. Must be public, because also called from // Message Handler. Must be public, because also called from
// PrerenderContents. Collects the |image_urls| list. // PrerenderContents. Collects the |image_urls| list.
void OnUpdateFaviconURL(const std::vector<content::FaviconURL>& candidates); void OnUpdateFaviconURL(const std::vector<favicon::FaviconURL>& candidates);
// Processes the current image_irls_ entry, requesting the image from the // Processes the current image_irls_ entry, requesting the image from the
// history / download service. // history / download service.
...@@ -110,7 +110,7 @@ class FaviconHandler { ...@@ -110,7 +110,7 @@ class FaviconHandler {
const std::vector<gfx::Size>& original_bitmap_sizes); const std::vector<gfx::Size>& original_bitmap_sizes);
// For testing. // For testing.
const std::vector<content::FaviconURL>& image_urls() const { const std::vector<favicon::FaviconURL>& image_urls() const {
return image_urls_; return image_urls_;
} }
...@@ -229,7 +229,7 @@ class FaviconHandler { ...@@ -229,7 +229,7 @@ class FaviconHandler {
void SetFaviconOnActivePage(const GURL& icon_url, const gfx::Image& image); void SetFaviconOnActivePage(const GURL& icon_url, const gfx::Image& image);
// Return the current candidate if any. // Return the current candidate if any.
content::FaviconURL* current_candidate() { favicon::FaviconURL* current_candidate() {
return (!image_urls_.empty()) ? &image_urls_.front() : NULL; return (!image_urls_.empty()) ? &image_urls_.front() : NULL;
} }
...@@ -275,7 +275,7 @@ class FaviconHandler { ...@@ -275,7 +275,7 @@ class FaviconHandler {
const bool download_largest_icon_; const bool download_largest_icon_;
// The prioritized favicon candidates from the page back from the renderer. // The prioritized favicon candidates from the page back from the renderer.
std::vector<content::FaviconURL> image_urls_; std::vector<favicon::FaviconURL> image_urls_;
// The FaviconBitmapResults from history. // The FaviconBitmapResults from history.
std::vector<favicon_base::FaviconBitmapResult> history_results_; std::vector<favicon_base::FaviconBitmapResult> history_results_;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "components/bookmarks/core/browser/bookmark_model.h" #include "components/bookmarks/core/browser/bookmark_model.h"
#include "components/favicon_base/favicon_types.h"
#include "content/public/browser/favicon_status.h" #include "content/public/browser/favicon_status.h"
#include "content/public/browser/invalidate_type.h" #include "content/public/browser/invalidate_type.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
...@@ -25,6 +26,7 @@ ...@@ -25,6 +26,7 @@
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/favicon_url.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
...@@ -222,14 +224,40 @@ void FaviconTabHelper::DidNavigateMainFrame( ...@@ -222,14 +224,40 @@ void FaviconTabHelper::DidNavigateMainFrame(
FetchFavicon(details.entry->GetURL()); FetchFavicon(details.entry->GetURL());
} }
// Returns favicon_base::IconType the given icon_type corresponds to.
// TODO(jif): Move function to /components/favicon_base/content/
// crbug.com/374281.
favicon_base::IconType ToChromeIconType(
content::FaviconURL::IconType icon_type) {
switch (icon_type) {
case content::FaviconURL::FAVICON:
return favicon_base::FAVICON;
case content::FaviconURL::TOUCH_ICON:
return favicon_base::TOUCH_ICON;
case content::FaviconURL::TOUCH_PRECOMPOSED_ICON:
return favicon_base::TOUCH_PRECOMPOSED_ICON;
case content::FaviconURL::INVALID_ICON:
return favicon_base::INVALID_ICON;
}
NOTREACHED();
return favicon_base::INVALID_ICON;
}
void FaviconTabHelper::DidUpdateFaviconURL( void FaviconTabHelper::DidUpdateFaviconURL(
const std::vector<content::FaviconURL>& candidates) { const std::vector<content::FaviconURL>& candidates) {
DCHECK(!candidates.empty()); DCHECK(!candidates.empty());
favicon_urls_ = candidates; favicon_urls_ = candidates;
std::vector<favicon::FaviconURL> favicon_urls;
favicon_handler_->OnUpdateFaviconURL(candidates); for (size_t i = 0; i < candidates.size(); i++) {
const content::FaviconURL& candidate = candidates[i];
favicon_urls.push_back(
favicon::FaviconURL(candidate.icon_url,
ToChromeIconType(candidate.icon_type),
candidate.icon_sizes));
}
favicon_handler_->OnUpdateFaviconURL(favicon_urls);
if (touch_icon_handler_.get()) if (touch_icon_handler_.get())
touch_icon_handler_->OnUpdateFaviconURL(candidates); touch_icon_handler_->OnUpdateFaviconURL(favicon_urls);
} }
FaviconService* FaviconTabHelper::GetFaviconService() { FaviconService* FaviconTabHelper::GetFaviconService() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment