summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsdefresne@chromium.org <sdefresne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-07 22:48:08 +0000
committersdefresne@chromium.org <sdefresne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-07 22:48:08 +0000
commit504fca8eaf5f65db2d3766f40be721639a3097f9 (patch)
treea20ca22730e186776050b991d1bee33d64d97eb1
parent0d73f081788b8e3b33fac543af9ebaa6a9ae9b0f (diff)
downloadchromium_src-504fca8eaf5f65db2d3766f40be721639a3097f9.zip
chromium_src-504fca8eaf5f65db2d3766f40be721639a3097f9.tar.gz
chromium_src-504fca8eaf5f65db2d3766f40be721639a3097f9.tar.bz2
Add support for different IconType in BookmarkNode
Chrome on iOS prefers to display touch icon over favicon if they are available so make this feature selectable via the BookmarkClient. BookmarkModel will try to download the touch icon if BookmarkClient favor them and will fallback to using regular favicon. The type of icon loaded is stored in the BookmarkNode to be used by the embedder. BUG=364044 Review URL: https://codereview.chromium.org/264903002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268979 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/bookmarks/chrome_bookmark_client.cc8
-rw-r--r--chrome/browser/bookmarks/chrome_bookmark_client.h1
-rw-r--r--components/bookmarks/core/browser/bookmark_client.h3
-rw-r--r--components/bookmarks/core/browser/bookmark_model.cc32
-rw-r--r--components/bookmarks/core/browser/bookmark_model.h7
-rw-r--r--components/bookmarks/core/browser/bookmark_node.cc2
-rw-r--r--components/bookmarks/core/browser/bookmark_node.h10
-rw-r--r--components/bookmarks/core/test/test_bookmark_client.cc4
-rw-r--r--components/bookmarks/core/test/test_bookmark_client.h1
9 files changed, 61 insertions, 7 deletions
diff --git a/chrome/browser/bookmarks/chrome_bookmark_client.cc b/chrome/browser/bookmarks/chrome_bookmark_client.cc
index 7e80ce4..ec50ffa 100644
--- a/chrome/browser/bookmarks/chrome_bookmark_client.cc
+++ b/chrome/browser/bookmarks/chrome_bookmark_client.cc
@@ -46,6 +46,14 @@ ChromeBookmarkClient::~ChromeBookmarkClient() {
registrar_.RemoveAll();
}
+bool ChromeBookmarkClient::PreferTouchIcon() {
+#if !defined(OS_IOS)
+ return false;
+#else
+ return true;
+#endif
+}
+
base::CancelableTaskTracker::TaskId ChromeBookmarkClient::GetFaviconImageForURL(
const GURL& page_url,
int icon_types,
diff --git a/chrome/browser/bookmarks/chrome_bookmark_client.h b/chrome/browser/bookmarks/chrome_bookmark_client.h
index 380249c..a136f17 100644
--- a/chrome/browser/bookmarks/chrome_bookmark_client.h
+++ b/chrome/browser/bookmarks/chrome_bookmark_client.h
@@ -29,6 +29,7 @@ class ChromeBookmarkClient : public BookmarkClient,
BookmarkModel* model() { return model_.get(); }
// BookmarkClient:
+ virtual bool PreferTouchIcon() OVERRIDE;
virtual base::CancelableTaskTracker::TaskId GetFaviconImageForURL(
const GURL& page_url,
int icon_types,
diff --git a/components/bookmarks/core/browser/bookmark_client.h b/components/bookmarks/core/browser/bookmark_client.h
index a280486..698e049 100644
--- a/components/bookmarks/core/browser/bookmark_client.h
+++ b/components/bookmarks/core/browser/bookmark_client.h
@@ -37,6 +37,9 @@ class BookmarkClient {
typedef std::pair<const BookmarkNode*, int> NodeTypedCountPair;
typedef std::vector<NodeTypedCountPair> NodeTypedCountPairs;
+ // Returns true if the embedder favors touch icons over favicons.
+ virtual bool PreferTouchIcon() = 0;
+
// Requests the favicon of any of |icon_types| whose pixel sizes most
// closely match |desired_size_in_dip| (if value is 0, the largest favicon
// is returned) and desired scale factor for |page_url|. |callback| is run
diff --git a/components/bookmarks/core/browser/bookmark_model.cc b/components/bookmarks/core/browser/bookmark_model.cc
index 66b01f2..db0274a 100644
--- a/components/bookmarks/core/browser/bookmark_model.cc
+++ b/components/bookmarks/core/browser/bookmark_model.cc
@@ -266,12 +266,20 @@ const gfx::Image& BookmarkModel::GetFavicon(const BookmarkNode* node) {
DCHECK(node);
if (node->favicon_state() == BookmarkNode::INVALID_FAVICON) {
BookmarkNode* mutable_node = AsMutable(node);
- mutable_node->set_favicon_state(BookmarkNode::LOADING_FAVICON);
- LoadFavicon(mutable_node);
+ LoadFavicon(
+ mutable_node,
+ client_->PreferTouchIcon() ?
+ favicon_base::TOUCH_ICON :
+ favicon_base::FAVICON);
}
return node->favicon();
}
+favicon_base::IconType BookmarkModel::GetFaviconType(const BookmarkNode* node) {
+ DCHECK(node);
+ return node->favicon_type();
+}
+
void BookmarkModel::SetTitle(const BookmarkNode* node,
const base::string16& title) {
if (!node) {
@@ -860,28 +868,40 @@ BookmarkPermanentNode* BookmarkModel::CreatePermanentNode(
void BookmarkModel::OnFaviconDataAvailable(
BookmarkNode* node,
+ favicon_base::IconType icon_type,
const favicon_base::FaviconImageResult& image_result) {
DCHECK(node);
node->set_favicon_load_task_id(base::CancelableTaskTracker::kBadTaskId);
node->set_favicon_state(BookmarkNode::LOADED_FAVICON);
if (!image_result.image.IsEmpty()) {
+ node->set_favicon_type(icon_type);
node->set_favicon(image_result.image);
node->set_icon_url(image_result.icon_url);
FaviconLoaded(node);
+ } else if (icon_type == favicon_base::TOUCH_ICON) {
+ // Couldn't load the touch icon, fallback to the regular favicon.
+ DCHECK(client_->PreferTouchIcon());
+ LoadFavicon(node, favicon_base::FAVICON);
}
}
-void BookmarkModel::LoadFavicon(BookmarkNode* node) {
+void BookmarkModel::LoadFavicon(
+ BookmarkNode* node,
+ favicon_base::IconType icon_type) {
if (node->is_folder())
return;
DCHECK(node->url().is_valid());
+ node->set_favicon_state(BookmarkNode::LOADING_FAVICON);
base::CancelableTaskTracker::TaskId taskId = client_->GetFaviconImageForURL(
node->url(),
- favicon_base::FAVICON,
- gfx::kFaviconSize,
+ icon_type,
+ icon_type == favicon_base::FAVICON ? gfx::kFaviconSize : 0,
base::Bind(
- &BookmarkModel::OnFaviconDataAvailable, base::Unretained(this), node),
+ &BookmarkModel::OnFaviconDataAvailable,
+ base::Unretained(this),
+ node,
+ icon_type),
&cancelable_task_tracker_);
if (taskId != base::CancelableTaskTracker::kBadTaskId)
node->set_favicon_load_task_id(taskId);
diff --git a/components/bookmarks/core/browser/bookmark_model.h b/components/bookmarks/core/browser/bookmark_model.h
index 5f51c4b..4c4a313 100644
--- a/components/bookmarks/core/browser/bookmark_model.h
+++ b/components/bookmarks/core/browser/bookmark_model.h
@@ -144,6 +144,10 @@ class BookmarkModel : public BookmarkService {
// loaded it is loaded and the observer of the model notified when done.
const gfx::Image& GetFavicon(const BookmarkNode* node);
+ // Returns the type of the favicon for |node|. If the favicon has not yet
+ // been loaded, it returns |favicon_base::INVALID_ICON|.
+ favicon_base::IconType GetFaviconType(const BookmarkNode* node);
+
// Sets the title of |node|.
void SetTitle(const BookmarkNode* node, const base::string16& title);
@@ -332,11 +336,12 @@ class BookmarkModel : public BookmarkService {
// favicon, FaviconLoaded is invoked.
void OnFaviconDataAvailable(
BookmarkNode* node,
+ favicon_base::IconType icon_type,
const favicon_base::FaviconImageResult& image_result);
// Invoked from the node to load the favicon. Requests the favicon from the
// favicon service.
- void LoadFavicon(BookmarkNode* node);
+ void LoadFavicon(BookmarkNode* node, favicon_base::IconType icon_type);
// Called to notify the observers that the favicon has been loaded.
void FaviconLoaded(const BookmarkNode* node);
diff --git a/components/bookmarks/core/browser/bookmark_node.cc b/components/bookmarks/core/browser/bookmark_node.cc
index 6d178c0..13246c0 100644
--- a/components/bookmarks/core/browser/bookmark_node.cc
+++ b/components/bookmarks/core/browser/bookmark_node.cc
@@ -103,6 +103,7 @@ void BookmarkNode::Initialize(int64 id) {
id_ = id;
type_ = url_.is_empty() ? FOLDER : URL;
date_added_ = base::Time::Now();
+ favicon_type_ = favicon_base::INVALID_ICON;
favicon_state_ = INVALID_FAVICON;
favicon_load_task_id_ = base::CancelableTaskTracker::kBadTaskId;
meta_info_map_.reset();
@@ -112,6 +113,7 @@ void BookmarkNode::Initialize(int64 id) {
void BookmarkNode::InvalidateFavicon() {
icon_url_ = GURL();
favicon_ = gfx::Image();
+ favicon_type_ = favicon_base::INVALID_ICON;
favicon_state_ = INVALID_FAVICON;
}
diff --git a/components/bookmarks/core/browser/bookmark_node.h b/components/bookmarks/core/browser/bookmark_node.h
index d4246d0..6ed275b 100644
--- a/components/bookmarks/core/browser/bookmark_node.h
+++ b/components/bookmarks/core/browser/bookmark_node.h
@@ -8,6 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h"
+#include "components/favicon_base/favicon_types.h"
#include "ui/base/models/tree_node_model.h"
#include "ui/gfx/image/image.h"
#include "url/gurl.h"
@@ -127,9 +128,15 @@ class BookmarkNode : public ui::TreeNode<BookmarkNode> {
icon_url_ = icon_url;
}
+ // Returns the favicon. In nearly all cases you should use the method
+ // BookmarkModel::GetFavicon rather than this one as it takes care of
+ // loading the favicon if it isn't already loaded.
const gfx::Image& favicon() const { return favicon_; }
void set_favicon(const gfx::Image& icon) { favicon_ = icon; }
+ favicon_base::IconType favicon_type() const { return favicon_type_; }
+ void set_favicon_type(favicon_base::IconType type) { favicon_type_ = type; }
+
FaviconState favicon_state() const { return favicon_state_; }
void set_favicon_state(FaviconState state) { favicon_state_ = state; }
@@ -159,6 +166,9 @@ class BookmarkNode : public ui::TreeNode<BookmarkNode> {
// The favicon of this node.
gfx::Image favicon_;
+ // The type of favicon currently loaded.
+ favicon_base::IconType favicon_type_;
+
// The URL of the node's favicon.
GURL icon_url_;
diff --git a/components/bookmarks/core/test/test_bookmark_client.cc b/components/bookmarks/core/test/test_bookmark_client.cc
index 4ae073a..1062e0b 100644
--- a/components/bookmarks/core/test/test_bookmark_client.cc
+++ b/components/bookmarks/core/test/test_bookmark_client.cc
@@ -15,6 +15,10 @@ scoped_ptr<BookmarkModel> TestBookmarkClient::CreateModel(bool index_urls) {
return bookmark_model.Pass();
}
+bool TestBookmarkClient::PreferTouchIcon() {
+ return false;
+}
+
base::CancelableTaskTracker::TaskId TestBookmarkClient::GetFaviconImageForURL(
const GURL& page_url,
int icon_types,
diff --git a/components/bookmarks/core/test/test_bookmark_client.h b/components/bookmarks/core/test/test_bookmark_client.h
index 12677f7f..66791e5 100644
--- a/components/bookmarks/core/test/test_bookmark_client.h
+++ b/components/bookmarks/core/test/test_bookmark_client.h
@@ -22,6 +22,7 @@ class TestBookmarkClient : public BookmarkClient {
scoped_ptr<BookmarkModel> CreateModel(bool index_urls);
// BookmarkClient:
+ virtual bool PreferTouchIcon() OVERRIDE;
virtual base::CancelableTaskTracker::TaskId GetFaviconImageForURL(
const GURL& page_url,
int icon_types,