Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1407)

Unified Diff: chrome/browser/ui/toolbar/back_forward_menu_model.cc

Issue 2928005: Retrieve favicons from history as NavigationEntries are converted from TabNav... Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/toolbar/back_forward_menu_model.cc
===================================================================
--- chrome/browser/ui/toolbar/back_forward_menu_model.cc (revision 70178)
+++ chrome/browser/ui/toolbar/back_forward_menu_model.cc (working copy)
@@ -11,11 +11,13 @@
#include "app/resource_bundle.h"
#include "base/string_number_conversions.h"
#include "chrome/browser/metrics/user_metrics.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/url_constants.h"
+#include "gfx/codec/png_codec.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "net/base/registry_controlled_domain.h"
@@ -28,7 +30,8 @@
ModelType model_type)
: browser_(browser),
test_tab_contents_(NULL),
- model_type_(model_type) {
+ model_type_(model_type),
+ delegate_(NULL) {
}
bool BackForwardMenuModel::HasIcons() const {
@@ -106,7 +109,7 @@
return false;
}
-bool BackForwardMenuModel::GetIconAt(int index, SkBitmap* icon) const {
+bool BackForwardMenuModel::GetIconAt(int index, SkBitmap* icon) {
if (!ItemHasIcon(index))
return false;
@@ -116,6 +119,9 @@
} else {
NavigationEntry* entry = GetNavigationEntry(index);
*icon = entry->favicon().bitmap();
+ if (!entry->favicon().is_valid()) {
+ FetchFavicon(entry, index);
+ }
}
return true;
@@ -175,6 +181,8 @@
void BackForwardMenuModel::MenuWillShow() {
UserMetrics::RecordComputedAction(BuildActionName("Popup", -1),
browser_->profile());
+ requested_favicons_.clear();
+ load_consumer_.CancelAllRequests();
}
bool BackForwardMenuModel::IsSeparator(int index) const {
@@ -196,6 +204,64 @@
return index == history_items;
}
+void BackForwardMenuModel::SetDelegate(Delegate* delegate) {
+ delegate_ = delegate;
+}
+
+void BackForwardMenuModel::FetchFavicon(NavigationEntry* entry, int index) {
+ // If the favicon has already been requested for this menu, don't do
+ // anything.
+ if (requested_favicons_.find(entry->unique_id()) !=
+ requested_favicons_.end()) {
+ return;
+ }
+ requested_favicons_.insert(entry->unique_id());
+ FaviconService* favicon_service =
+ browser_->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS);
+ if (!favicon_service)
+ return;
+ FaviconService::Handle handle = favicon_service->GetFaviconForURL(
+ entry->url(), &load_consumer_,
+ NewCallback(this, &BackForwardMenuModel::OnFavIconDataAvailable));
+ load_consumer_.SetClientData(favicon_service, handle, entry->unique_id());
+}
+
+void BackForwardMenuModel::OnFavIconDataAvailable(
+ FaviconService::Handle handle,
+ bool know_favicon,
+ scoped_refptr<RefCountedMemory> data,
+ bool expired,
+ GURL icon_url) {
+ SkBitmap fav_icon;
+ if (know_favicon && data.get() && data->size() && data->size() > 0 &&
+ gfx::PNGCodec::Decode(data->front(), data->size(), &fav_icon)) {
+ int unique_id = load_consumer_.GetClientDataForCurrentRequest();
sky 2011/01/04 21:51:15 Finding the navigation entry is cheap, but decodin
+ // We need both the NavigationEntry and the model_index so we search for
+ // the unique_index by model_index.
+ NavigationEntry* entry = NULL;
+ int model_index = -1;
+ for (int i = 0; i < GetItemCount() - 1; i++) {
+ if (IsSeparator(i))
+ continue;
+ entry = GetNavigationEntry(i);
+ if (entry->unique_id() == unique_id) {
+ model_index = i;
+ break;
+ }
+ }
+ if (!entry)
sky 2011/01/04 21:51:15 Notice that even if you didn't find the matching N
+ return;
+ entry->favicon().set_is_valid(true);
+ entry->favicon().set_url(icon_url);
+ if (fav_icon.empty())
+ return;
+ entry->favicon().set_bitmap(fav_icon);
+ if (delegate_) {
+ delegate_->OnIconChanged(model_index);
+ }
+ }
+}
+
int BackForwardMenuModel::GetHistoryItemCount() const {
TabContents* contents = GetTabContents();
int items = 0;

Powered by Google App Engine
This is Rietveld 408576698