Commit 3e9d7730 authored by jif@chromium.org's avatar jif@chromium.org

Removes usage of NavigationEntry from favicon_handler.*

BUG=359598

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269871 0039d316-1c4b-4281-b951-d872f2087c98
parent 6c9f5550
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
#include "chrome/browser/favicon/favicon_service_factory.h" #include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/favicon/favicon_util.h" #include "chrome/browser/favicon/favicon_util.h"
#include "components/favicon_base/select_favicon_frames.h" #include "components/favicon_base/select_favicon_frames.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/navigation_entry.h"
#include "skia/ext/image_operations.h" #include "skia/ext/image_operations.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"
...@@ -24,7 +22,6 @@ ...@@ -24,7 +22,6 @@
#include "ui/gfx/image/image_util.h" #include "ui/gfx/image/image_util.h"
using content::FaviconURL; using content::FaviconURL;
using content::NavigationEntry;
namespace { namespace {
...@@ -328,16 +325,13 @@ void FaviconHandler::SetFavicon(const GURL& url, ...@@ -328,16 +325,13 @@ void FaviconHandler::SetFavicon(const GURL& url,
SetHistoryFavicons(url, icon_url, icon_type, image); SetHistoryFavicons(url, icon_url, icon_type, image);
if (UrlMatches(url, url_) && icon_type == favicon_base::FAVICON) { if (UrlMatches(url, url_) && icon_type == favicon_base::FAVICON) {
NavigationEntry* entry = GetEntry(); if (!PageChangedSinceFaviconWasRequested())
if (entry) SetFaviconOnActivePage(icon_url, image);
SetFaviconOnNavigationEntry(entry, icon_url, image);
} }
} }
void FaviconHandler::SetFaviconOnNavigationEntry( void FaviconHandler::SetFaviconOnActivePage(const std::vector<
NavigationEntry* entry, favicon_base::FaviconBitmapResult>& favicon_bitmap_results) {
const std::vector<favicon_base::FaviconBitmapResult>&
favicon_bitmap_results) {
gfx::Image resized_image = FaviconUtil::SelectFaviconFramesFromPNGs( gfx::Image resized_image = FaviconUtil::SelectFaviconFramesFromPNGs(
favicon_bitmap_results, favicon_bitmap_results,
FaviconUtil::GetFaviconScaleFactors(), FaviconUtil::GetFaviconScaleFactors(),
...@@ -346,18 +340,16 @@ void FaviconHandler::SetFaviconOnNavigationEntry( ...@@ -346,18 +340,16 @@ void FaviconHandler::SetFaviconOnNavigationEntry(
// not matter which result we get the |icon_url| from. // not matter which result we get the |icon_url| from.
const GURL icon_url = favicon_bitmap_results.empty() ? const GURL icon_url = favicon_bitmap_results.empty() ?
GURL() : favicon_bitmap_results[0].icon_url; GURL() : favicon_bitmap_results[0].icon_url;
SetFaviconOnNavigationEntry(entry, icon_url, resized_image); SetFaviconOnActivePage(icon_url, resized_image);
} }
void FaviconHandler::SetFaviconOnNavigationEntry( void FaviconHandler::SetFaviconOnActivePage(const GURL& icon_url,
NavigationEntry* entry, const gfx::Image& image) {
const GURL& icon_url,
const gfx::Image& image) {
// No matter what happens, we need to mark the favicon as being set. // No matter what happens, we need to mark the favicon as being set.
entry->GetFavicon().valid = true; driver_->SetActiveFaviconValidity(true);
bool icon_url_changed = (entry->GetFavicon().url != icon_url); bool icon_url_changed = driver_->GetActiveFaviconURL() != icon_url;
entry->GetFavicon().url = icon_url; driver_->SetActiveFaviconURL(icon_url);
if (image.IsEmpty()) if (image.IsEmpty())
return; return;
...@@ -365,7 +357,7 @@ void FaviconHandler::SetFaviconOnNavigationEntry( ...@@ -365,7 +357,7 @@ void FaviconHandler::SetFaviconOnNavigationEntry(
gfx::Image image_with_adjusted_colorspace = image; gfx::Image image_with_adjusted_colorspace = image;
FaviconUtil::SetFaviconColorSpace(&image_with_adjusted_colorspace); FaviconUtil::SetFaviconColorSpace(&image_with_adjusted_colorspace);
entry->GetFavicon().image = image_with_adjusted_colorspace; driver_->SetActiveFaviconImage(image_with_adjusted_colorspace);
NotifyFaviconUpdated(icon_url_changed); NotifyFaviconUpdated(icon_url_changed);
} }
...@@ -396,17 +388,16 @@ void FaviconHandler::OnUpdateFaviconURL( ...@@ -396,17 +388,16 @@ void FaviconHandler::OnUpdateFaviconURL(
void FaviconHandler::ProcessCurrentUrl() { void FaviconHandler::ProcessCurrentUrl() {
DCHECK(!image_urls_.empty()); DCHECK(!image_urls_.empty());
NavigationEntry* entry = GetEntry();
// current_candidate() may return NULL if download_largest_icon_ is true and // current_candidate() may return NULL if download_largest_icon_ is true and
// all the sizes are larger than the max. // all the sizes are larger than the max.
if (!entry || !current_candidate()) if (PageChangedSinceFaviconWasRequested() || !current_candidate())
return; return;
if (current_candidate()->icon_type == FaviconURL::FAVICON) { if (current_candidate()->icon_type == FaviconURL::FAVICON) {
if (!favicon_expired_or_incomplete_ && entry->GetFavicon().valid && if (!favicon_expired_or_incomplete_ &&
driver_->GetActiveFaviconValidity() &&
DoUrlAndIconMatch(*current_candidate(), DoUrlAndIconMatch(*current_candidate(),
entry->GetFavicon().url, driver_->GetActiveFaviconURL(),
favicon_base::FAVICON)) favicon_base::FAVICON))
return; return;
} else if (!favicon_expired_or_incomplete_ && got_favicon_from_history_ && } else if (!favicon_expired_or_incomplete_ && got_favicon_from_history_ &&
...@@ -417,7 +408,8 @@ void FaviconHandler::ProcessCurrentUrl() { ...@@ -417,7 +408,8 @@ void FaviconHandler::ProcessCurrentUrl() {
if (got_favicon_from_history_) if (got_favicon_from_history_)
DownloadFaviconOrAskFaviconService( DownloadFaviconOrAskFaviconService(
entry->GetURL(), current_candidate()->icon_url, driver_->GetActiveURL(),
current_candidate()->icon_url,
ToChromeIconType(current_candidate()->icon_type)); ToChromeIconType(current_candidate()->icon_type));
} }
...@@ -474,7 +466,8 @@ void FaviconHandler::OnDidDownloadFavicon( ...@@ -474,7 +466,8 @@ void FaviconHandler::OnDidDownloadFavicon(
i->second.url, image_url, image, score, i->second.icon_type); i->second.url, image_url, image, score, i->second.icon_type);
} }
} }
if (request_next_icon && GetEntry() && image_urls_.size() > 1) { if (request_next_icon && !PageChangedSinceFaviconWasRequested() &&
image_urls_.size() > 1) {
// Remove the first member of image_urls_ and process the remaining. // Remove the first member of image_urls_ and process the remaining.
image_urls_.erase(image_urls_.begin()); image_urls_.erase(image_urls_.begin());
ProcessCurrentUrl(); ProcessCurrentUrl();
...@@ -493,14 +486,13 @@ void FaviconHandler::OnDidDownloadFavicon( ...@@ -493,14 +486,13 @@ void FaviconHandler::OnDidDownloadFavicon(
download_requests_.erase(i); download_requests_.erase(i);
} }
NavigationEntry* FaviconHandler::GetEntry() { bool FaviconHandler::PageChangedSinceFaviconWasRequested() {
NavigationEntry* entry = driver_->GetActiveEntry(); if (UrlMatches(driver_->GetActiveURL(), url_) && url_.is_valid()) {
if (entry && UrlMatches(entry->GetURL(), url_)) return false;
return entry; }
// If the URL has changed out from under us (as will happen with redirects) // If the URL has changed out from under us (as will happen with redirects)
// return NULL. // return true.
return NULL; return true;
} }
int FaviconHandler::DownloadFavicon(const GURL& image_url, int FaviconHandler::DownloadFavicon(const GURL& image_url,
...@@ -570,19 +562,15 @@ void FaviconHandler::NotifyFaviconUpdated(bool icon_url_changed) { ...@@ -570,19 +562,15 @@ void FaviconHandler::NotifyFaviconUpdated(bool icon_url_changed) {
void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
const std::vector<favicon_base::FaviconBitmapResult>& const std::vector<favicon_base::FaviconBitmapResult>&
favicon_bitmap_results) { favicon_bitmap_results) {
NavigationEntry* entry = GetEntry(); if (PageChangedSinceFaviconWasRequested())
if (!entry)
return; return;
got_favicon_from_history_ = true; got_favicon_from_history_ = true;
history_results_ = favicon_bitmap_results; history_results_ = favicon_bitmap_results;
bool has_results = !favicon_bitmap_results.empty(); bool has_results = !favicon_bitmap_results.empty();
favicon_expired_or_incomplete_ = has_results && HasExpiredOrIncompleteResult( favicon_expired_or_incomplete_ = has_results && HasExpiredOrIncompleteResult(
preferred_icon_size(), favicon_bitmap_results); preferred_icon_size(), favicon_bitmap_results);
if (has_results && icon_types_ == favicon_base::FAVICON && if (has_results && icon_types_ == favicon_base::FAVICON &&
!entry->GetFavicon().valid && !driver_->GetActiveFaviconValidity() &&
(!current_candidate() || (!current_candidate() ||
DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results))) { DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results))) {
if (HasValidResult(favicon_bitmap_results)) { if (HasValidResult(favicon_bitmap_results)) {
...@@ -590,7 +578,7 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( ...@@ -590,7 +578,7 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
// doesn't have an icon. Set the favicon now, and if the favicon turns out // doesn't have an icon. Set the favicon now, and if the favicon turns out
// to be expired (or the wrong url) we'll fetch later on. This way the // to be expired (or the wrong url) we'll fetch later on. This way the
// user doesn't see a flash of the default favicon. // user doesn't see a flash of the default favicon.
SetFaviconOnNavigationEntry(entry, favicon_bitmap_results); SetFaviconOnActivePage(favicon_bitmap_results);
} else { } else {
// If |favicon_bitmap_results| does not have any valid results, treat the // If |favicon_bitmap_results| does not have any valid results, treat the
// favicon as if it's expired. // favicon as if it's expired.
...@@ -598,7 +586,6 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( ...@@ -598,7 +586,6 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
favicon_expired_or_incomplete_ = true; favicon_expired_or_incomplete_ = true;
} }
} }
if (has_results && !favicon_expired_or_incomplete_) { if (has_results && !favicon_expired_or_incomplete_) {
if (current_candidate() && if (current_candidate() &&
!DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results)) { !DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results)) {
...@@ -606,7 +593,8 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( ...@@ -606,7 +593,8 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
// 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(
entry->GetURL(), current_candidate()->icon_url, driver_->GetActiveURL(),
current_candidate()->icon_url,
ToChromeIconType(current_candidate()->icon_type)); ToChromeIconType(current_candidate()->icon_type));
} }
} else if (current_candidate()) { } else if (current_candidate()) {
...@@ -614,7 +602,8 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( ...@@ -614,7 +602,8 @@ void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService(
// 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(
entry->GetURL(), current_candidate()->icon_url, driver_->GetActiveURL(),
current_candidate()->icon_url,
ToChromeIconType(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
...@@ -653,8 +642,7 @@ void FaviconHandler::DownloadFaviconOrAskFaviconService( ...@@ -653,8 +642,7 @@ void FaviconHandler::DownloadFaviconOrAskFaviconService(
void FaviconHandler::OnFaviconData(const std::vector< void FaviconHandler::OnFaviconData(const std::vector<
favicon_base::FaviconBitmapResult>& favicon_bitmap_results) { favicon_base::FaviconBitmapResult>& favicon_bitmap_results) {
NavigationEntry* entry = GetEntry(); if (PageChangedSinceFaviconWasRequested())
if (!entry)
return; return;
bool has_results = !favicon_bitmap_results.empty(); bool has_results = !favicon_bitmap_results.empty();
...@@ -666,19 +654,21 @@ void FaviconHandler::OnFaviconData(const std::vector< ...@@ -666,19 +654,21 @@ void FaviconHandler::OnFaviconData(const std::vector<
// There is a favicon, set it now. If expired we'll download the current // There is a favicon, set it now. If expired we'll download the current
// one again, but at least the user will get some icon instead of the // one again, but at least the user will get some icon instead of the
// default and most likely the current one is fine anyway. // default and most likely the current one is fine anyway.
SetFaviconOnNavigationEntry(entry, favicon_bitmap_results); SetFaviconOnActivePage(favicon_bitmap_results);
} }
if (has_expired_or_incomplete_result) { if (has_expired_or_incomplete_result) {
// The favicon is out of date. Request the current one. // The favicon is out of date. Request the current one.
ScheduleDownload( ScheduleDownload(driver_->GetActiveURL(),
entry->GetURL(), entry->GetFavicon().url, favicon_base::FAVICON); driver_->GetActiveFaviconURL(),
favicon_base::FAVICON);
} }
} else if (current_candidate() && } else if (current_candidate() &&
(!has_results || has_expired_or_incomplete_result || (!has_results || has_expired_or_incomplete_result ||
!(DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results)))) { !(DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results)))) {
// We don't know the favicon, it is out of date or its type is not same as // We don't know the favicon, it is out of date or its type is not same as
// one got from page. Request the current one. // one got from page. Request the current one.
ScheduleDownload(entry->GetURL(), current_candidate()->icon_url, ScheduleDownload(driver_->GetActiveURL(),
current_candidate()->icon_url,
ToChromeIconType(current_candidate()->icon_type)); ToChromeIconType(current_candidate()->icon_type));
} }
history_results_ = favicon_bitmap_results; history_results_ = favicon_bitmap_results;
......
...@@ -28,11 +28,7 @@ namespace base { ...@@ -28,11 +28,7 @@ namespace base {
class RefCountedMemory; class RefCountedMemory;
} }
namespace content { // FaviconHandler works with FaviconDriver to fetch the specific type of
class NavigationEntry;
}
// FaviconHandler works with FaviconTabHelper to fetch the specific type of
// favicon. // favicon.
// //
// FetchFavicon requests the favicon from the favicon service which in turn // FetchFavicon requests the favicon from the favicon service which in turn
...@@ -40,7 +36,7 @@ class NavigationEntry; ...@@ -40,7 +36,7 @@ class NavigationEntry;
// we only know the URL of the page, and not necessarily the url of the // we only know the URL of the page, and not necessarily the url of the
// favicon. To ensure we handle reloading stale favicons as well as // favicon. To ensure we handle reloading stale favicons as well as
// reloading a favicon on page reload we always request the favicon from // reloading a favicon on page reload we always request the favicon from
// history regardless of whether the NavigationEntry has a favicon. // history regardless of whether the active favicon is valid.
// //
// After the navigation two types of events are delivered (which is // After the navigation two types of events are delivered (which is
// first depends upon who is faster): notification from the history // first depends upon who is faster): notification from the history
...@@ -48,13 +44,13 @@ class NavigationEntry; ...@@ -48,13 +44,13 @@ class NavigationEntry;
// (OnFaviconDataForInitialURLFromFaviconService), or a message from the // (OnFaviconDataForInitialURLFromFaviconService), or a message from the
// renderer giving us the URL of the favicon for the page (SetFaviconURL). // renderer giving us the URL of the favicon for the page (SetFaviconURL).
// . If the history db has a valid up to date favicon for the page, we update // . If the history db has a valid up to date favicon for the page, we update
// the NavigationEntry and use the favicon. // the current page and use the favicon.
// . When we receive the favicon url if it matches that of the NavigationEntry // . When we receive the favicon url if it matches that of the current page
// and the NavigationEntry's favicon is set, we do nothing (everything is // and the current page's favicon is set, we do nothing (everything is
// ok). // ok).
// . On the other hand if the database does not know the favicon for url, or // . On the other hand if the database does not know the favicon for url, or
// the favicon is out date, or the URL from the renderer does not match that // the favicon is out date, or the URL from the renderer does not match that
// NavigationEntry we proceed to DownloadFaviconOrAskHistory. Before we // of the current page we proceed to DownloadFaviconOrAskHistory. Before we
// invoke DownloadFaviconOrAskHistory we wait until we've received both // invoke DownloadFaviconOrAskHistory we wait until we've received both
// the favicon url and the callback from history. We wait to ensure we // the favicon url and the callback from history. We wait to ensure we
// truly know both the favicon url and the state of the database. // truly know both the favicon url and the state of the database.
...@@ -67,7 +63,7 @@ class NavigationEntry; ...@@ -67,7 +63,7 @@ class NavigationEntry;
// possible for the db to already have the favicon, just not the mapping // possible for the db to already have the favicon, just not the mapping
// between page to favicon url. The callback for this is OnFaviconData. // between page to favicon url. The callback for this is OnFaviconData.
// //
// OnFaviconData either updates the favicon of the NavigationEntry (if the // OnFaviconData either updates the favicon of the current page (if the
// db knew about the favicon), or requests the renderer to download the // db knew about the favicon), or requests the renderer to download the
// favicon. // favicon.
// //
...@@ -76,8 +72,7 @@ class NavigationEntry; ...@@ -76,8 +72,7 @@ class NavigationEntry;
// favicon will be used, otherwise the one that best matches the preferred size // favicon will be used, otherwise the one that best matches the preferred size
// is chosen (or the first one if there is no preferred size). Once the // is chosen (or the first one if there is no preferred size). Once the
// matching favicon has been determined, SetFavicon is called which updates // matching favicon has been determined, SetFavicon is called which updates
// the favicon of the NavigationEntry and notifies the database to save the // the page's favicon and notifies the database to save the favicon.
// favicon.
class FaviconHandler { class FaviconHandler {
public: public:
...@@ -123,10 +118,6 @@ class FaviconHandler { ...@@ -123,10 +118,6 @@ class FaviconHandler {
// These virtual methods make FaviconHandler testable and are overridden by // These virtual methods make FaviconHandler testable and are overridden by
// TestFaviconHandler. // TestFaviconHandler.
// Return the NavigationEntry for the active entry, or NULL if the active
// entries URL does not match that of the URL last passed to FetchFavicon.
virtual content::NavigationEntry* GetEntry();
// Asks the render to download favicon, returns the request id. // Asks the render to download favicon, returns the request id.
virtual int DownloadFavicon(const GURL& image_url, int max_bitmap_size); virtual int DownloadFavicon(const GURL& image_url, int max_bitmap_size);
...@@ -232,21 +223,19 @@ class FaviconHandler { ...@@ -232,21 +223,19 @@ class FaviconHandler {
const gfx::Image& image, const gfx::Image& image,
favicon_base::IconType icon_type); favicon_base::IconType icon_type);
// Sets the favicon's data on the NavigationEntry. // Sets the favicon's data.
// If the WebContents has a delegate, it is invalidated (INVALIDATE_TYPE_TAB). void SetFaviconOnActivePage(const std::vector<
void SetFaviconOnNavigationEntry( favicon_base::FaviconBitmapResult>& favicon_bitmap_results);
content::NavigationEntry* entry, void SetFaviconOnActivePage(const GURL& icon_url, const gfx::Image& image);
const std::vector<favicon_base::FaviconBitmapResult>&
favicon_bitmap_results);
void SetFaviconOnNavigationEntry(content::NavigationEntry* entry,
const GURL& icon_url,
const gfx::Image& image);
// Return the current candidate if any. // Return the current candidate if any.
content::FaviconURL* current_candidate() { content::FaviconURL* current_candidate() {
return (!image_urls_.empty()) ? &image_urls_.front() : NULL; return (!image_urls_.empty()) ? &image_urls_.front() : NULL;
} }
// Returns whether the page's url changed since the favicon was requested.
bool PageChangedSinceFaviconWasRequested();
// Returns the preferred size of the image. 0 means no preference (any size // Returns the preferred size of the image. 0 means no preference (any size
// will do). // will do).
int preferred_icon_size() const { int preferred_icon_size() const {
...@@ -299,7 +288,7 @@ class FaviconHandler { ...@@ -299,7 +288,7 @@ class FaviconHandler {
// Best image we've seen so far. As images are downloaded from the page they // Best image we've seen so far. As images are downloaded from the page they
// are stored here. When there is an exact match, or no more images are // are stored here. When there is an exact match, or no more images are
// available the favicon service and the NavigationEntry are updated (assuming // available the favicon service and the current page are updated (assuming
// the image is for a favicon). // the image is for a favicon).
FaviconCandidate best_favicon_candidate_; FaviconCandidate best_favicon_candidate_;
......
...@@ -8,10 +8,6 @@ ...@@ -8,10 +8,6 @@
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/favicon_size.h" #include "ui/gfx/favicon_size.h"
...@@ -20,8 +16,6 @@ ...@@ -20,8 +16,6 @@
class TestFaviconHandler; class TestFaviconHandler;
using content::FaviconURL; using content::FaviconURL;
using content::NavigationEntry;
using content::WebContents;
namespace { namespace {
...@@ -191,18 +185,31 @@ class TestFaviconClient : public FaviconClient { ...@@ -191,18 +185,31 @@ class TestFaviconClient : public FaviconClient {
class TestFaviconDriver : public FaviconDriver { class TestFaviconDriver : public FaviconDriver {
public: public:
TestFaviconDriver() { TestFaviconDriver() : favicon_validity_(false) {}
}
virtual ~TestFaviconDriver() { virtual ~TestFaviconDriver() {
} }
virtual bool IsOffTheRecord() OVERRIDE { return false; } virtual bool IsOffTheRecord() OVERRIDE { return false; }
virtual NavigationEntry* GetActiveEntry() OVERRIDE { virtual const gfx::Image GetActiveFaviconImage() OVERRIDE { return image_; }
ADD_FAILURE() << "TestFaviconDriver::GetActiveEntry() "
<< "should never be called in tests."; virtual const GURL GetActiveFaviconURL() OVERRIDE { return favicon_url_; }
return NULL;
virtual bool GetActiveFaviconValidity() OVERRIDE { return favicon_validity_; }
virtual const GURL GetActiveURL() OVERRIDE { return url_; }
virtual void SetActiveFaviconImage(gfx::Image image) OVERRIDE {
image_ = image;
}
virtual void SetActiveFaviconURL(GURL favicon_url) OVERRIDE {
favicon_url_ = favicon_url;
}
virtual void SetActiveFaviconValidity(bool favicon_validity) OVERRIDE {
favicon_validity_ = favicon_validity;
} }
virtual int StartDownload(const GURL& url, virtual int StartDownload(const GURL& url,
...@@ -217,7 +224,13 @@ class TestFaviconDriver : public FaviconDriver { ...@@ -217,7 +224,13 @@ class TestFaviconDriver : public FaviconDriver {
<< "should never be called in tests."; << "should never be called in tests.";
} }
void SetActiveURL(GURL url) { url_ = url; }
private: private:
GURL favicon_url_;
GURL url_;
gfx::Image image_;
bool favicon_validity_;
DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver); DISALLOW_COPY_AND_ASSIGN(TestFaviconDriver);
}; };
...@@ -228,15 +241,13 @@ class TestFaviconHandler : public FaviconHandler { ...@@ -228,15 +241,13 @@ class TestFaviconHandler : public FaviconHandler {
public: public:
TestFaviconHandler(const GURL& page_url, TestFaviconHandler(const GURL& page_url,
FaviconClient* client, FaviconClient* client,
FaviconDriver* driver, TestFaviconDriver* driver,
Type type, Type type,
bool download_largest_icon) bool download_largest_icon)
: FaviconHandler(client, driver, type, : FaviconHandler(client, driver, type, download_largest_icon),
download_largest_icon),
entry_(NavigationEntry::Create()),
download_id_(0), download_id_(0),
num_favicon_updates_(0) { num_favicon_updates_(0) {
entry_->SetURL(page_url); driver->SetActiveURL(page_url);
download_handler_.reset(new DownloadHandler(this)); download_handler_.reset(new DownloadHandler(this));
} }
...@@ -265,10 +276,6 @@ class TestFaviconHandler : public FaviconHandler { ...@@ -265,10 +276,6 @@ class TestFaviconHandler : public FaviconHandler {
} }
// Methods to access favicon internals. // Methods to access favicon internals.
virtual NavigationEntry* GetEntry() OVERRIDE {
return entry_.get();
}
const std::vector<FaviconURL>& urls() { const std::vector<FaviconURL>& urls() {
return image_urls_; return image_urls_;
} }
...@@ -342,7 +349,6 @@ class TestFaviconHandler : public FaviconHandler { ...@@ -342,7 +349,6 @@ class TestFaviconHandler : public FaviconHandler {
GURL page_url_; GURL page_url_;
private: private:
scoped_ptr<NavigationEntry> entry_;
// The unique id of a download request. It will be returned to a // The unique id of a download request. It will be returned to a
// FaviconHandler. // FaviconHandler.
...@@ -491,8 +497,8 @@ TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { ...@@ -491,8 +497,8 @@ TEST_F(FaviconHandlerTest, GetFaviconFromHistory) {
// Send history response. // Send history response.
history_handler->InvokeCallback(); history_handler->InvokeCallback();
// Verify FaviconHandler status // Verify FaviconHandler status
EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); EXPECT_TRUE(driver.GetActiveFaviconValidity());
EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
// Simulates update favicon url. // Simulates update favicon url.
std::vector<FaviconURL> urls; std::vector<FaviconURL> urls;
...@@ -535,8 +541,8 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) { ...@@ -535,8 +541,8 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) {
// Send history response. // Send history response.
history_handler->InvokeCallback(); history_handler->InvokeCallback();
// Verify FaviconHandler status // Verify FaviconHandler status
EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); EXPECT_TRUE(driver.GetActiveFaviconValidity());
EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
// Simulates update favicon url. // Simulates update favicon url.
std::vector<FaviconURL> urls; std::vector<FaviconURL> urls;
...@@ -572,11 +578,10 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) { ...@@ -572,11 +578,10 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) {
EXPECT_EQ(page_url, history_handler->page_url_); EXPECT_EQ(page_url, history_handler->page_url_);
// Verify NavigationEntry. // Verify NavigationEntry.
content::FaviconStatus favicon_status = helper.GetEntry()->GetFavicon(); EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
EXPECT_EQ(icon_url, favicon_status.url); EXPECT_TRUE(driver.GetActiveFaviconValidity());
EXPECT_TRUE(favicon_status.valid); EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty());
EXPECT_FALSE(favicon_status.image.IsEmpty()); EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width());
EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width());
} }
TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
...@@ -603,8 +608,8 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { ...@@ -603,8 +608,8 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
// Send history response. // Send history response.
history_handler->InvokeCallback(); history_handler->InvokeCallback();
// Verify FaviconHandler status. // Verify FaviconHandler status.
EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); EXPECT_TRUE(driver.GetActiveFaviconValidity());
EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
// Reset the history_handler to verify whether new icon is requested from // Reset the history_handler to verify whether new icon is requested from
// history. // history.
...@@ -655,11 +660,10 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { ...@@ -655,11 +660,10 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
EXPECT_EQ(page_url, history_handler->page_url_); EXPECT_EQ(page_url, history_handler->page_url_);
// Verify NavigationEntry. // Verify NavigationEntry.
content::FaviconStatus favicon_status = helper.GetEntry()->GetFavicon(); EXPECT_EQ(new_icon_url, driver.GetActiveFaviconURL());
EXPECT_EQ(new_icon_url, favicon_status.url); EXPECT_TRUE(driver.GetActiveFaviconValidity());
EXPECT_TRUE(favicon_status.valid); EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty());
EXPECT_FALSE(favicon_status.image.IsEmpty()); EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width());
EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width());
} }
TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) {
...@@ -693,8 +697,8 @@ TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { ...@@ -693,8 +697,8 @@ TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) {
// Send history response. // Send history response.
history_handler->InvokeCallback(); history_handler->InvokeCallback();
// The NavigationEntry should not be set yet as the history data is invalid. // The NavigationEntry should not be set yet as the history data is invalid.
EXPECT_FALSE(helper.GetEntry()->GetFavicon().valid); EXPECT_FALSE(driver.GetActiveFaviconValidity());
EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); EXPECT_EQ(GURL(), driver.GetActiveFaviconURL());
// Reset the history_handler to verify whether new icon is requested from // Reset the history_handler to verify whether new icon is requested from
// history. // history.
...@@ -727,11 +731,10 @@ TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { ...@@ -727,11 +731,10 @@ TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) {
EXPECT_EQ(page_url, history_handler->page_url_); EXPECT_EQ(page_url, history_handler->page_url_);
// Verify NavigationEntry. // Verify NavigationEntry.
content::FaviconStatus favicon_status = helper.GetEntry()->GetFavicon(); EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
EXPECT_EQ(icon_url, favicon_status.url); EXPECT_TRUE(driver.GetActiveFaviconValidity());
EXPECT_TRUE(favicon_status.valid); EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty());
EXPECT_FALSE(favicon_status.image.IsEmpty()); EXPECT_EQ(gfx::kFaviconSize, driver.GetActiveFaviconImage().Width());
EXPECT_EQ(gfx::kFaviconSize, favicon_status.image.Width());
} }
TEST_F(FaviconHandlerTest, UpdateFavicon) { TEST_F(FaviconHandlerTest, UpdateFavicon) {
...@@ -757,8 +760,8 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) { ...@@ -757,8 +760,8 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) {
// Send history response. // Send history response.
history_handler->InvokeCallback(); history_handler->InvokeCallback();
// Verify FaviconHandler status. // Verify FaviconHandler status.
EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); EXPECT_TRUE(driver.GetActiveFaviconValidity());
EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); EXPECT_EQ(icon_url, driver.GetActiveFaviconURL());
// Reset the history_handler to verify whether new icon is requested from // Reset the history_handler to verify whether new icon is requested from
// history. // history.
...@@ -791,9 +794,9 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) { ...@@ -791,9 +794,9 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) {
EXPECT_FALSE(helper.download_handler()->HasDownload()); EXPECT_FALSE(helper.download_handler()->HasDownload());
// Verify the favicon status. // Verify the favicon status.
EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); EXPECT_EQ(new_icon_url, driver.GetActiveFaviconURL());
EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); EXPECT_TRUE(driver.GetActiveFaviconValidity());
EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty()); EXPECT_FALSE(driver.GetActiveFaviconImage().IsEmpty());
} }
TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) {
...@@ -820,8 +823,8 @@ TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { ...@@ -820,8 +823,8 @@ TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) {
// Send history response. // Send history response.
history_handler->InvokeCallback(); history_handler->InvokeCallback();
// Verify FaviconHandler status. // Verify FaviconHandler status.
EXPECT_FALSE(helper.GetEntry()->GetFavicon().valid); EXPECT_FALSE(driver.GetActiveFaviconValidity());
EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); EXPECT_EQ(GURL(), driver.GetActiveFaviconURL());
// Reset the history_handler to verify whether new icon is requested from // Reset the history_handler to verify whether new icon is requested from
// history. // history.
...@@ -934,8 +937,8 @@ TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { ...@@ -934,8 +937,8 @@ TEST_F(FaviconHandlerTest, UpdateDuringDownloading) {
// Send history response. // Send history response.
history_handler->InvokeCallback(); history_handler->InvokeCallback();
// Verify FaviconHandler status. // Verify FaviconHandler status.
EXPECT_FALSE(helper.GetEntry()->GetFavicon().valid); EXPECT_FALSE(driver.GetActiveFaviconValidity());
EXPECT_EQ(GURL(), helper.GetEntry()->GetFavicon().url); EXPECT_EQ(GURL(), driver.GetActiveFaviconURL());
// Reset the history_handler to verify whether new icon is requested from // Reset the history_handler to verify whether new icon is requested from
// history. // history.
...@@ -1067,16 +1070,15 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) { ...@@ -1067,16 +1070,15 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) {
kSourceIconURLs + arraysize(kSizes1)); kSourceIconURLs + arraysize(kSizes1));
DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1); DownloadTillDoneIgnoringHistory(&handler1, kPageURL, urls1, kSizes1);
content::FaviconStatus favicon_status1(handler1.GetEntry()->GetFavicon());
EXPECT_EQ(0u, handler1.image_urls().size()); EXPECT_EQ(0u, handler1.image_urls().size());
EXPECT_TRUE(favicon_status1.valid); EXPECT_TRUE(driver1.GetActiveFaviconValidity());
EXPECT_FALSE(favicon_status1.image.IsEmpty()); EXPECT_FALSE(driver1.GetActiveFaviconImage().IsEmpty());
EXPECT_EQ(gfx::kFaviconSize, favicon_status1.image.Width()); EXPECT_EQ(gfx::kFaviconSize, driver1.GetActiveFaviconImage().Width());
size_t expected_index = 2u; size_t expected_index = 2u;
EXPECT_EQ(32, kSizes1[expected_index]); EXPECT_EQ(32, kSizes1[expected_index]);
EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, EXPECT_EQ(kSourceIconURLs[expected_index].icon_url,
handler1.GetEntry()->GetFavicon().url); driver1.GetActiveFaviconURL());
// 2) Test that if there are several single resolution favicons to choose // 2) Test that if there are several single resolution favicons to choose
// from, the exact match is preferred even if it results in upsampling. // from, the exact match is preferred even if it results in upsampling.
...@@ -1088,11 +1090,11 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) { ...@@ -1088,11 +1090,11 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) {
std::vector<FaviconURL> urls2(kSourceIconURLs, std::vector<FaviconURL> urls2(kSourceIconURLs,
kSourceIconURLs + arraysize(kSizes2)); kSourceIconURLs + arraysize(kSizes2));
DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2); DownloadTillDoneIgnoringHistory(&handler2, kPageURL, urls2, kSizes2);
EXPECT_TRUE(handler2.GetEntry()->GetFavicon().valid); EXPECT_TRUE(driver2.GetActiveFaviconValidity());
expected_index = 0u; expected_index = 0u;
EXPECT_EQ(16, kSizes2[expected_index]); EXPECT_EQ(16, kSizes2[expected_index]);
EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, EXPECT_EQ(kSourceIconURLs[expected_index].icon_url,
handler2.GetEntry()->GetFavicon().url); driver2.GetActiveFaviconURL());
// 3) Test that favicons which need to be upsampled a little or downsampled // 3) Test that favicons which need to be upsampled a little or downsampled
// a little are preferred over huge favicons. // a little are preferred over huge favicons.
...@@ -1104,11 +1106,11 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) { ...@@ -1104,11 +1106,11 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) {
std::vector<FaviconURL> urls3(kSourceIconURLs, std::vector<FaviconURL> urls3(kSourceIconURLs,
kSourceIconURLs + arraysize(kSizes3)); kSourceIconURLs + arraysize(kSizes3));
DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3); DownloadTillDoneIgnoringHistory(&handler3, kPageURL, urls3, kSizes3);
EXPECT_TRUE(handler3.GetEntry()->GetFavicon().valid); EXPECT_TRUE(driver3.GetActiveFaviconValidity());
expected_index = 1u; expected_index = 1u;
EXPECT_EQ(48, kSizes3[expected_index]); EXPECT_EQ(48, kSizes3[expected_index]);
EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, EXPECT_EQ(kSourceIconURLs[expected_index].icon_url,
handler3.GetEntry()->GetFavicon().url); driver3.GetActiveFaviconURL());
TestFaviconDriver driver4; TestFaviconDriver driver4;
TestFaviconHandler handler4( TestFaviconHandler handler4(
...@@ -1118,11 +1120,11 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) { ...@@ -1118,11 +1120,11 @@ TEST_F(FaviconHandlerTest, MultipleFavicons) {
std::vector<FaviconURL> urls4(kSourceIconURLs, std::vector<FaviconURL> urls4(kSourceIconURLs,
kSourceIconURLs + arraysize(kSizes4)); kSourceIconURLs + arraysize(kSizes4));
DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4); DownloadTillDoneIgnoringHistory(&handler4, kPageURL, urls4, kSizes4);
EXPECT_TRUE(handler4.GetEntry()->GetFavicon().valid); EXPECT_TRUE(driver4.GetActiveFaviconValidity());
expected_index = 0u; expected_index = 0u;
EXPECT_EQ(17, kSizes4[expected_index]); EXPECT_EQ(17, kSizes4[expected_index]);
EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, EXPECT_EQ(kSourceIconURLs[expected_index].icon_url,
handler4.GetEntry()->GetFavicon().url); driver4.GetActiveFaviconURL());
} }
#endif #endif
......
...@@ -135,10 +135,6 @@ void FaviconTabHelper::SaveFavicon() { ...@@ -135,10 +135,6 @@ void FaviconTabHelper::SaveFavicon() {
entry->GetURL(), favicon.url, favicon_base::FAVICON, favicon.image); entry->GetURL(), favicon.url, favicon_base::FAVICON, favicon.image);
} }
NavigationEntry* FaviconTabHelper::GetActiveEntry() {
return web_contents()->GetController().GetActiveEntry();
}
int FaviconTabHelper::StartDownload(const GURL& url, int max_image_size) { int FaviconTabHelper::StartDownload(const GURL& url, int max_image_size) {
FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS); profile_->GetOriginalProfile(), Profile::IMPLICIT_ACCESS);
...@@ -167,6 +163,42 @@ bool FaviconTabHelper::IsOffTheRecord() { ...@@ -167,6 +163,42 @@ bool FaviconTabHelper::IsOffTheRecord() {
return web_contents()->GetBrowserContext()->IsOffTheRecord(); return web_contents()->GetBrowserContext()->IsOffTheRecord();
} }
const gfx::Image FaviconTabHelper::GetActiveFaviconImage() {
return GetFaviconStatus().image;
}
const GURL FaviconTabHelper::GetActiveFaviconURL() {
return GetFaviconStatus().url;
}
bool FaviconTabHelper::GetActiveFaviconValidity() {
return GetFaviconStatus().valid;
}
const GURL FaviconTabHelper::GetActiveURL() {
NavigationEntry* entry = web_contents()->GetController().GetActiveEntry();
if (!entry || entry->GetURL().is_empty())
return GURL();
return entry->GetURL();
}
void FaviconTabHelper::SetActiveFaviconImage(gfx::Image image) {
GetFaviconStatus().image = image;
}
void FaviconTabHelper::SetActiveFaviconURL(GURL url) {
GetFaviconStatus().url = url;
}
void FaviconTabHelper::SetActiveFaviconValidity(bool validity) {
GetFaviconStatus().valid = validity;
}
content::FaviconStatus& FaviconTabHelper::GetFaviconStatus() {
DCHECK(web_contents()->GetController().GetActiveEntry());
return web_contents()->GetController().GetActiveEntry()->GetFavicon();
}
void FaviconTabHelper::DidStartNavigationToPendingEntry( void FaviconTabHelper::DidStartNavigationToPendingEntry(
const GURL& url, const GURL& url,
NavigationController::ReloadType reload_type) { NavigationController::ReloadType reload_type) {
......
...@@ -19,6 +19,10 @@ namespace gfx { ...@@ -19,6 +19,10 @@ namespace gfx {
class Image; class Image;
} }
namespace content {
struct FaviconStatus;
}
class GURL; class GURL;
class FaviconHandler; class FaviconHandler;
class Profile; class Profile;
...@@ -68,10 +72,16 @@ class FaviconTabHelper : public content::WebContentsObserver, ...@@ -68,10 +72,16 @@ class FaviconTabHelper : public content::WebContentsObserver,
void SaveFavicon(); void SaveFavicon();
// FaviconDriver methods. // FaviconDriver methods.
virtual content::NavigationEntry* GetActiveEntry() OVERRIDE;
virtual int StartDownload(const GURL& url, int max_bitmap_size) OVERRIDE; virtual int StartDownload(const GURL& url, int max_bitmap_size) OVERRIDE;
virtual void NotifyFaviconUpdated(bool icon_url_changed) OVERRIDE; virtual void NotifyFaviconUpdated(bool icon_url_changed) OVERRIDE;
virtual bool IsOffTheRecord() OVERRIDE; virtual bool IsOffTheRecord() OVERRIDE;
virtual const gfx::Image GetActiveFaviconImage() OVERRIDE;
virtual const GURL GetActiveFaviconURL() OVERRIDE;
virtual bool GetActiveFaviconValidity() OVERRIDE;
virtual const GURL GetActiveURL() OVERRIDE;
virtual void SetActiveFaviconImage(gfx::Image image) OVERRIDE;
virtual void SetActiveFaviconURL(GURL url) OVERRIDE;
virtual void SetActiveFaviconValidity(bool validity) OVERRIDE;
// Favicon download callback. // Favicon download callback.
void DidDownloadFavicon( void DidDownloadFavicon(
...@@ -97,6 +107,9 @@ class FaviconTabHelper : public content::WebContentsObserver, ...@@ -97,6 +107,9 @@ class FaviconTabHelper : public content::WebContentsObserver,
const content::LoadCommittedDetails& details, const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) OVERRIDE; const content::FrameNavigateParams& params) OVERRIDE;
// Helper method that returns the active navigation entry's favicon.
content::FaviconStatus& GetFaviconStatus();
Profile* profile_; Profile* profile_;
std::vector<content::FaviconURL> favicon_urls_; std::vector<content::FaviconURL> favicon_urls_;
......
...@@ -7,9 +7,8 @@ ...@@ -7,9 +7,8 @@
class GURL; class GURL;
namespace content { namespace gfx {
// TODO(jif): Abstract the NavigationEntry (crbug.com/359598). class Image;
class NavigationEntry;
} }
// Interface that allows Favicon core code to interact with its driver (i.e., // Interface that allows Favicon core code to interact with its driver (i.e.,
...@@ -17,9 +16,6 @@ class NavigationEntry; ...@@ -17,9 +16,6 @@ class NavigationEntry;
// implementation must be provided by the driver. // implementation must be provided by the driver.
class FaviconDriver { class FaviconDriver {
public: public:
// Returns the current NavigationEntry.
// TODO(jif): Abstract the NavigationEntry (crbug.com/359598).
virtual content::NavigationEntry* GetActiveEntry() = 0;
// Starts the download for the given favicon. When finished, the driver // Starts the download for the given favicon. When finished, the driver
// will call OnDidDownloadFavicon() with the results. // will call OnDidDownloadFavicon() with the results.
...@@ -38,6 +34,33 @@ class FaviconDriver { ...@@ -38,6 +34,33 @@ class FaviconDriver {
// Returns whether the user is operating in an off-the-record context. // Returns whether the user is operating in an off-the-record context.
virtual bool IsOffTheRecord() = 0; virtual bool IsOffTheRecord() = 0;
// Returns the bitmap of the current page's favicon. Requires GetActiveURL()
// to be valid.
virtual const gfx::Image GetActiveFaviconImage() = 0;
// Returns the URL of the current page's favicon. Requires GetActiveURL() to
// be valid.
virtual const GURL GetActiveFaviconURL() = 0;
// Returns whether the page's favicon is valid (returns false if the default
// favicon is being used). Requires GetActiveURL() to be valid.
virtual bool GetActiveFaviconValidity() = 0;
// Returns the URL of the current page, if any. Returns an invalid
// URL otherwise.
virtual const GURL GetActiveURL() = 0;
// Sets the bitmap of the current page's favicon. Requires GetActiveURL() to
// be valid.
virtual void SetActiveFaviconImage(gfx::Image image) = 0;
// Sets the URL of the favicon's bitmap. Requires GetActiveURL() to be valid.
virtual void SetActiveFaviconURL(GURL url) = 0;
// Sets whether the page's favicon is valid (if false, the default favicon is
// being used). Requires GetActiveURL() to be valid.
virtual void SetActiveFaviconValidity(bool validity) = 0;
}; };
#endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_ #endif // COMPONENTS_FAVICON_CORE_FAVICON_DRIVER_H_
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