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

Unified Diff: chrome/browser/ui/gtk/global_history_menu.cc

Issue 7017028: Revert "Revert 85330 - GTK: Bring global menu out of about:flags." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 7 months 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
« no previous file with comments | « chrome/browser/ui/gtk/global_history_menu.h ('k') | chrome/browser/ui/gtk/global_menu_bar.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/gtk/global_history_menu.cc
diff --git a/chrome/browser/ui/gtk/global_history_menu.cc b/chrome/browser/ui/gtk/global_history_menu.cc
index 119e8c7c8aac34b46f3db70ecdea28f66501cbec..d57944807d351dfd86ab6af686117a8c176c9753 100644
--- a/chrome/browser/ui/gtk/global_history_menu.cc
+++ b/chrome/browser/ui/gtk/global_history_menu.cc
@@ -113,8 +113,15 @@ GlobalHistoryMenu::~GlobalHistoryMenu() {
menu_item_history_map_.clear();
}
-void GlobalHistoryMenu::Init(GtkWidget* history_menu) {
- history_menu_ = history_menu;
+void GlobalHistoryMenu::Init(GtkWidget* history_menu,
+ GtkWidget* history_menu_item) {
+ history_menu_.Own(history_menu);
+
+ // We have to connect to |history_menu_item|'s "activate" signal instead of
+ // |history_menu|'s "show" signal because we are not supposed to modify the
+ // menu during "show"
+ g_signal_connect(history_menu_item, "activate",
+ G_CALLBACK(OnMenuActivateThunk), this);
default_favicon_ = GtkThemeService::GetDefaultFavicon(true);
@@ -129,17 +136,6 @@ void GlobalHistoryMenu::Init(GtkWidget* history_menu) {
Source<history::TopSites>(top_sites_));
}
- tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile_);
- if (tab_restore_service_) {
- tab_restore_service_->LoadTabsFromLastSession();
- tab_restore_service_->AddObserver(this);
-
- // If LoadTabsFromLastSession doesn't load tabs, it won't call
- // TabRestoreServiceChanged(). This ensures that all new windows after
- // the first one will have their menus populated correctly.
- TabRestoreServiceChanged(tab_restore_service_);
- }
-
registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
Source<Profile>(profile_));
}
@@ -155,10 +151,10 @@ void GlobalHistoryMenu::GetTopSitesData() {
void GlobalHistoryMenu::OnTopSitesReceived(
const history::MostVisitedURLList& visited_list) {
- ClearMenuSection(history_menu_, GlobalMenuBar::TAG_MOST_VISITED);
+ ClearMenuSection(history_menu_.get(), GlobalMenuBar::TAG_MOST_VISITED);
int index = GetIndexOfMenuItemWithTag(
- history_menu_,
+ history_menu_.get(),
GlobalMenuBar::TAG_MOST_VISITED_HEADER) + 1;
for (size_t i = 0; i < visited_list.size() && i < kMostVisitedCount; ++i) {
@@ -170,12 +166,12 @@ void GlobalHistoryMenu::OnTopSitesReceived(
item->title = visited.title;
item->url = visited.url;
- // The TopSites system doesn't give us icons; it gives us chrome:// urls to
- // icons so fetch the icons normally.
+ // The TopSites system doesn't give us icons; it gives us chrome:// urls
+ // to icons so fetch the icons normally.
GetFaviconForHistoryItem(item);
AddHistoryItemToMenu(item,
- history_menu_,
+ history_menu_.get(),
GlobalMenuBar::TAG_MOST_VISITED,
index++);
}
@@ -375,7 +371,8 @@ void GlobalHistoryMenu::Observe(NotificationType type,
// we'll update on the next menu change event.
default_favicon_ = GtkThemeService::GetDefaultFavicon(true);
} else if (type.value == NotificationType::TOP_SITES_CHANGED) {
- GetTopSitesData();
+ if (Source<history::TopSites>(source).ptr() == top_sites_)
+ GetTopSitesData();
} else {
NOTREACHED();
}
@@ -384,12 +381,12 @@ void GlobalHistoryMenu::Observe(NotificationType type,
void GlobalHistoryMenu::TabRestoreServiceChanged(TabRestoreService* service) {
const TabRestoreService::Entries& entries = service->entries();
- ClearMenuSection(history_menu_, GlobalMenuBar::TAG_RECENTLY_CLOSED);
+ ClearMenuSection(history_menu_.get(), GlobalMenuBar::TAG_RECENTLY_CLOSED);
// We'll get the index the "Recently Closed" header. (This can vary depending
// on the number of "Most Visited" items.
int index = GetIndexOfMenuItemWithTag(
- history_menu_,
+ history_menu_.get(),
GlobalMenuBar::TAG_RECENTLY_CLOSED_HEADER) + 1;
unsigned int added_count = 0;
@@ -477,7 +474,7 @@ void GlobalHistoryMenu::TabRestoreServiceChanged(TabRestoreService* service) {
GINT_TO_POINTER(GlobalMenuBar::TAG_RECENTLY_CLOSED));
gtk_menu_item_set_submenu(GTK_MENU_ITEM(parent_item), submenu);
- gtk_menu_shell_insert(GTK_MENU_SHELL(history_menu_), parent_item,
+ gtk_menu_shell_insert(GTK_MENU_SHELL(history_menu_.get()), parent_item,
index++);
++added_count;
} else if (entry->type == TabRestoreService::TAB) {
@@ -486,7 +483,7 @@ void GlobalHistoryMenu::TabRestoreServiceChanged(TabRestoreService* service) {
HistoryItem* item = HistoryItemForTab(*tab);
if (item) {
AddHistoryItemToMenu(item,
- history_menu_,
+ history_menu_.get(),
GlobalMenuBar::TAG_RECENTLY_CLOSED,
index++);
++added_count;
@@ -518,3 +515,18 @@ void GlobalHistoryMenu::OnRecentlyClosedItemActivated(GtkWidget* sender) {
PageTransition::AUTO_BOOKMARK);
}
}
+
+void GlobalHistoryMenu::OnMenuActivate(GtkWidget* sender) {
+ if (!tab_restore_service_) {
+ tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile_);
+ if (tab_restore_service_) {
+ tab_restore_service_->LoadTabsFromLastSession();
+ tab_restore_service_->AddObserver(this);
+
+ // If LoadTabsFromLastSession doesn't load tabs, it won't call
+ // TabRestoreServiceChanged(). This ensures that all new windows after
+ // the first one will have their menus populated correctly.
+ TabRestoreServiceChanged(tab_restore_service_);
+ }
+ }
+}
« no previous file with comments | « chrome/browser/ui/gtk/global_history_menu.h ('k') | chrome/browser/ui/gtk/global_menu_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698