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

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

Issue 11410067: alternate ntp: favicons and menu width enhancements for "Recent tabs" menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed unused include Created 8 years, 1 month 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/recent_tabs_sub_menu_model.cc
diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
index e9788464ceacc86c0c3035d1372a8b6ae6a6ff50..e33f6b5e2bf9053b23f887390ed43828ec2a9672 100644
--- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
+++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
@@ -26,11 +26,11 @@
#include "chrome/common/time_format.h"
#include "chrome/common/url_constants.h"
#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
#include "grit/ui_resources.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
-#include "ui/base/text/text_elider.h"
#include "ui/gfx/favicon_size.h"
#if defined(USE_ASH)
@@ -309,7 +309,8 @@ void RecentTabsSubMenuModel::BuildDevices() {
++k) {
BuildForeignTabItem(session_tag, *tabs_in_session[k],
// Only need |session_name| for the first tab of the session.
- !k ? session->session_name : std::string(), need_separator);
+ !k ? session->session_name : std::string(), session->device_type,
+ need_separator);
need_separator = false;
} // for all tabs in one session
@@ -322,12 +323,15 @@ void RecentTabsSubMenuModel::BuildForeignTabItem(
const std::string& session_tag,
const SessionTab& tab,
const std::string& session_name,
+ browser_sync::SyncedSession::DeviceType device_type,
bool need_separator) {
if (need_separator)
AddSeparator(ui::NORMAL_SEPARATOR);
- if (!session_name.empty())
+ if (!session_name.empty()) {
AddItem(kDisabledCommandId, UTF8ToUTF16(session_name));
+ AddDeviceFavicon(GetItemCount() - 1, device_type);
+ }
const TabNavigation& current_navigation =
tab.navigations.at(tab.normalized_navigation_index());
@@ -335,14 +339,62 @@ void RecentTabsSubMenuModel::BuildForeignTabItem(
current_navigation.virtual_url());
int command_id = ModelIndexToCommandId(model_.size());
AddItem(command_id, current_navigation.title());
- AddFavicon(model_.size(), command_id, item.url);
+ AddTabFavicon(model_.size(), command_id, item.url);
model_.push_back(item);
}
-void RecentTabsSubMenuModel::AddFavicon(int model_index, int command_id,
- const GURL& url) {
+void RecentTabsSubMenuModel::AddDeviceFavicon(
+ int index_in_menu,
+ browser_sync::SyncedSession::DeviceType device_type) {
+ int favicon_id = -1;
+ gfx::Image* favicon = NULL;
+ switch (device_type) {
+ case browser_sync::SyncedSession::TYPE_PHONE:
+ if ((favicon = &phone_favicon_)->IsEmpty())
+ favicon_id = IDR_PHONE_FAVICON;
+ break;
+
+ case browser_sync::SyncedSession::TYPE_TABLET:
+ if ((favicon = &tablet_favicon_)->IsEmpty())
+ favicon_id = IDR_TABLET_FAVICON;
+ break;
+
+ case browser_sync::SyncedSession::TYPE_CHROMEOS:
+ case browser_sync::SyncedSession::TYPE_WIN:
+ case browser_sync::SyncedSession::TYPE_MACOSX:
+ case browser_sync::SyncedSession::TYPE_LINUX:
+ case browser_sync::SyncedSession::TYPE_OTHER:
+ case browser_sync::SyncedSession::TYPE_UNSET:
+ if ((favicon = &laptop_favicon_)->IsEmpty())
+ favicon_id = IDR_LAPTOP_FAVICON;
+ break;
+ };
+ DCHECK(favicon && (!favicon->IsEmpty() || favicon_id > -1));
+
+ if (favicon->IsEmpty()) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ *favicon = rb.GetNativeImageNamed(favicon_id);
+ }
+ SetIcon(index_in_menu, *favicon);
+}
+
+void RecentTabsSubMenuModel::AddTabFavicon(int model_index, int command_id,
sky 2012/11/13 17:41:49 nit: each param on its own line.
kuan 2012/11/13 18:52:52 Done.
+ const GURL& url) {
+ int index_in_menu = GetIndexOfCommandId(command_id);
+
+ // If tab has synced favicon, use it.
+ browser_sync::SessionModelAssociator* associator = GetModelAssociator();
+ std::string favicon_png;
+ if (associator &&
+ associator->GetSyncedFaviconForPageURL(url.spec(), &favicon_png)) {
+ SetIcon(index_in_menu, gfx::Image(reinterpret_cast<const unsigned char*>(
sky 2012/11/13 17:41:49 You sure you need reinterpret cast here?
kuan 2012/11/13 18:52:52 unfortunately yes, it won't build 'cos std::string
+ favicon_png.data()), favicon_png.size()));
+ return;
+ }
+
+ // Otherwise, start to fetch the favicon from local history asynchronously.
// Set default icon first.
- SetIcon(GetIndexOfCommandId(command_id), default_favicon_);
+ SetIcon(index_in_menu, default_favicon_);
// Start request to fetch actual icon if possible.
FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
browser_->profile(), Profile::EXPLICIT_ACCESS);

Powered by Google App Engine
This is Rietveld 408576698