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

Side by Side Diff: chrome/browser/ui/views/frame/global_menu_bar_x11.cc

Issue 1350653004: [sessions] Properly namespace recently-componentized TabRestore code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Mac Created 5 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/frame/global_menu_bar_x11.h" 5 #include "chrome/browser/ui/views/frame/global_menu_bar_x11.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <glib-object.h> 8 #include <glib-object.h>
9 9
10 #include "base/debug/leak_annotations.h" 10 #include "base/debug/leak_annotations.h"
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 527
528 GVariant* inside_array = g_variant_builder_end(&builder); 528 GVariant* inside_array = g_variant_builder_end(&builder);
529 g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); 529 g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
530 g_variant_builder_add_value(&builder, inside_array); 530 g_variant_builder_add_value(&builder, inside_array);
531 GVariant* outside_array = g_variant_builder_end(&builder); 531 GVariant* outside_array = g_variant_builder_end(&builder);
532 532
533 menuitem_property_set_variant(item, kPropertyShortcut, outside_array); 533 menuitem_property_set_variant(item, kPropertyShortcut, outside_array);
534 } 534 }
535 535
536 GlobalMenuBarX11::HistoryItem* GlobalMenuBarX11::HistoryItemForTab( 536 GlobalMenuBarX11::HistoryItem* GlobalMenuBarX11::HistoryItemForTab(
537 const TabRestoreService::Tab& entry) { 537 const sessions::TabRestoreService::Tab& entry) {
538 const sessions::SerializedNavigationEntry& current_navigation = 538 const sessions::SerializedNavigationEntry& current_navigation =
539 entry.navigations.at(entry.current_navigation_index); 539 entry.navigations.at(entry.current_navigation_index);
540 HistoryItem* item = new HistoryItem(); 540 HistoryItem* item = new HistoryItem();
541 item->title = current_navigation.title(); 541 item->title = current_navigation.title();
542 item->url = current_navigation.virtual_url(); 542 item->url = current_navigation.virtual_url();
543 item->session_id = entry.id; 543 item->session_id = entry.id;
544 544
545 return item; 545 return item;
546 } 546 }
547 547
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 } 729 }
730 730
731 void GlobalMenuBarX11::TopSitesLoaded(history::TopSites* top_sites) { 731 void GlobalMenuBarX11::TopSitesLoaded(history::TopSites* top_sites) {
732 } 732 }
733 733
734 void GlobalMenuBarX11::TopSitesChanged(history::TopSites* top_sites, 734 void GlobalMenuBarX11::TopSitesChanged(history::TopSites* top_sites,
735 ChangeReason change_reason) { 735 ChangeReason change_reason) {
736 GetTopSitesData(); 736 GetTopSitesData();
737 } 737 }
738 738
739 void GlobalMenuBarX11::TabRestoreServiceChanged(TabRestoreService* service) { 739 void GlobalMenuBarX11::TabRestoreServiceChanged(
740 const TabRestoreService::Entries& entries = service->entries(); 740 sessions::TabRestoreService* service) {
741 const sessions::TabRestoreService::Entries& entries = service->entries();
741 742
742 ClearMenuSection(history_menu_, TAG_RECENTLY_CLOSED); 743 ClearMenuSection(history_menu_, TAG_RECENTLY_CLOSED);
743 744
744 // We'll get the index the "Recently Closed" header. (This can vary depending 745 // We'll get the index the "Recently Closed" header. (This can vary depending
745 // on the number of "Most Visited" items. 746 // on the number of "Most Visited" items.
746 int index = GetIndexOfMenuItemWithTag(history_menu_, 747 int index = GetIndexOfMenuItemWithTag(history_menu_,
747 TAG_RECENTLY_CLOSED_HEADER) + 1; 748 TAG_RECENTLY_CLOSED_HEADER) + 1;
748 749
749 unsigned int added_count = 0; 750 unsigned int added_count = 0;
750 for (TabRestoreService::Entries::const_iterator it = entries.begin(); 751 for (sessions::TabRestoreService::Entries::const_iterator it =
752 entries.begin();
751 it != entries.end() && added_count < kRecentlyClosedCount; ++it) { 753 it != entries.end() && added_count < kRecentlyClosedCount; ++it) {
752 TabRestoreService::Entry* entry = *it; 754 sessions::TabRestoreService::Entry* entry = *it;
753 755
754 if (entry->type == TabRestoreService::WINDOW) { 756 if (entry->type == sessions::TabRestoreService::WINDOW) {
755 TabRestoreService::Window* entry_win = 757 sessions::TabRestoreService::Window* entry_win =
756 static_cast<TabRestoreService::Window*>(entry); 758 static_cast<sessions::TabRestoreService::Window*>(entry);
757 std::vector<TabRestoreService::Tab>& tabs = entry_win->tabs; 759 std::vector<sessions::TabRestoreService::Tab>& tabs = entry_win->tabs;
758 if (tabs.empty()) 760 if (tabs.empty())
759 continue; 761 continue;
760 762
761 // Create the item for the parent/window. 763 // Create the item for the parent/window.
762 HistoryItem* item = new HistoryItem(); 764 HistoryItem* item = new HistoryItem();
763 item->session_id = entry_win->id; 765 item->session_id = entry_win->id;
764 766
765 std::string title = l10n_util::GetPluralStringFUTF8( 767 std::string title = l10n_util::GetPluralStringFUTF8(
766 IDS_RECENTLY_CLOSED_WINDOW, tabs.size()); 768 IDS_RECENTLY_CLOSED_WINDOW, tabs.size());
767 DbusmenuMenuitem* parent_item = BuildMenuItem( 769 DbusmenuMenuitem* parent_item = BuildMenuItem(
(...skipping 15 matching lines...) Expand all
783 DeleteHistoryItem); 785 DeleteHistoryItem);
784 menuitem_child_append(parent_item, restore_item); 786 menuitem_child_append(parent_item, restore_item);
785 g_object_unref(restore_item); 787 g_object_unref(restore_item);
786 788
787 DbusmenuMenuitem* separator = BuildSeparator(); 789 DbusmenuMenuitem* separator = BuildSeparator();
788 menuitem_child_append(parent_item, separator); 790 menuitem_child_append(parent_item, separator);
789 g_object_unref(separator); 791 g_object_unref(separator);
790 792
791 // Loop over the window's tabs and add them to the submenu. 793 // Loop over the window's tabs and add them to the submenu.
792 int subindex = 2; 794 int subindex = 2;
793 std::vector<TabRestoreService::Tab>::const_iterator iter; 795 std::vector<sessions::TabRestoreService::Tab>::const_iterator iter;
794 for (iter = tabs.begin(); iter != tabs.end(); ++iter) { 796 for (iter = tabs.begin(); iter != tabs.end(); ++iter) {
795 TabRestoreService::Tab tab = *iter; 797 sessions::TabRestoreService::Tab tab = *iter;
796 HistoryItem* tab_item = HistoryItemForTab(tab); 798 HistoryItem* tab_item = HistoryItemForTab(tab);
797 item->tabs.push_back(tab_item); 799 item->tabs.push_back(tab_item);
798 AddHistoryItemToMenu(tab_item, 800 AddHistoryItemToMenu(tab_item,
799 parent_item, 801 parent_item,
800 TAG_RECENTLY_CLOSED, 802 TAG_RECENTLY_CLOSED,
801 subindex++); 803 subindex++);
802 } 804 }
803 805
804 ++added_count; 806 ++added_count;
805 } else if (entry->type == TabRestoreService::TAB) { 807 } else if (entry->type == sessions::TabRestoreService::TAB) {
806 TabRestoreService::Tab* tab = static_cast<TabRestoreService::Tab*>(entry); 808 sessions::TabRestoreService::Tab* tab =
809 static_cast<sessions::TabRestoreService::Tab*>(entry);
807 HistoryItem* item = HistoryItemForTab(*tab); 810 HistoryItem* item = HistoryItemForTab(*tab);
808 AddHistoryItemToMenu(item, 811 AddHistoryItemToMenu(item,
809 history_menu_, 812 history_menu_,
810 TAG_RECENTLY_CLOSED, 813 TAG_RECENTLY_CLOSED,
811 index++); 814 index++);
812 ++added_count; 815 ++added_count;
813 } 816 }
814 } 817 }
815 } 818 }
816 819
817 void GlobalMenuBarX11::TabRestoreServiceDestroyed( 820 void GlobalMenuBarX11::TabRestoreServiceDestroyed(
818 TabRestoreService* service) { 821 sessions::TabRestoreService* service) {
819 tab_restore_service_ = nullptr; 822 tab_restore_service_ = nullptr;
820 } 823 }
821 824
822 void GlobalMenuBarX11::OnWindowMapped(unsigned long xid) { 825 void GlobalMenuBarX11::OnWindowMapped(unsigned long xid) {
823 if (!server_) 826 if (!server_)
824 InitServer(xid); 827 InitServer(xid);
825 828
826 GlobalMenuBarRegistrarX11::GetInstance()->OnWindowMapped(xid); 829 GlobalMenuBarRegistrarX11::GetInstance()->OnWindowMapped(xid);
827 } 830 }
828 831
829 void GlobalMenuBarX11::OnWindowUnmapped(unsigned long xid) { 832 void GlobalMenuBarX11::OnWindowUnmapped(unsigned long xid) {
830 GlobalMenuBarRegistrarX11::GetInstance()->OnWindowUnmapped(xid); 833 GlobalMenuBarRegistrarX11::GetInstance()->OnWindowUnmapped(xid);
831 } 834 }
832 835
833 void GlobalMenuBarX11::OnItemActivated(DbusmenuMenuitem* item, 836 void GlobalMenuBarX11::OnItemActivated(DbusmenuMenuitem* item,
834 unsigned int timestamp) { 837 unsigned int timestamp) {
835 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item), "command-id")); 838 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item), "command-id"));
836 chrome::ExecuteCommand(browser_, id); 839 chrome::ExecuteCommand(browser_, id);
837 } 840 }
838 841
839 void GlobalMenuBarX11::OnHistoryItemActivated(DbusmenuMenuitem* sender, 842 void GlobalMenuBarX11::OnHistoryItemActivated(DbusmenuMenuitem* sender,
840 unsigned int timestamp) { 843 unsigned int timestamp) {
841 // Note: We don't have access to the event modifiers used to click the menu 844 // Note: We don't have access to the event modifiers used to click the menu
842 // item since that happens in a different process. 845 // item since that happens in a different process.
843 HistoryItem* item = reinterpret_cast<HistoryItem*>( 846 HistoryItem* item = reinterpret_cast<HistoryItem*>(
844 g_object_get_data(G_OBJECT(sender), kHistoryItem)); 847 g_object_get_data(G_OBJECT(sender), kHistoryItem));
845 848
846 // If this item can be restored using TabRestoreService, do so. Otherwise, 849 // If this item can be restored using TabRestoreService, do so. Otherwise,
847 // just load the URL. 850 // just load the URL.
848 TabRestoreService* service = 851 sessions::TabRestoreService* service =
849 TabRestoreServiceFactory::GetForProfile(profile_); 852 TabRestoreServiceFactory::GetForProfile(profile_);
850 if (item->session_id && service) { 853 if (item->session_id && service) {
851 service->RestoreEntryById(browser_->tab_restore_service_delegate(), 854 service->RestoreEntryById(browser_->tab_restore_service_delegate(),
852 item->session_id, browser_->host_desktop_type(), 855 item->session_id, browser_->host_desktop_type(),
853 UNKNOWN); 856 UNKNOWN);
854 } else { 857 } else {
855 DCHECK(item->url.is_valid()); 858 DCHECK(item->url.is_valid());
856 browser_->OpenURL(content::OpenURLParams( 859 browser_->OpenURL(content::OpenURLParams(
857 item->url, 860 item->url,
858 content::Referrer(), 861 content::Referrer(),
(...skipping 29 matching lines...) Expand all
888 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), kProfileId)); 891 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), kProfileId));
889 avatar_menu_->EditProfile(id); 892 avatar_menu_->EditProfile(id);
890 } 893 }
891 894
892 void GlobalMenuBarX11::OnCreateProfileItemActivated(DbusmenuMenuitem* sender, 895 void GlobalMenuBarX11::OnCreateProfileItemActivated(DbusmenuMenuitem* sender,
893 unsigned int timestamp) { 896 unsigned int timestamp) {
894 profiles::CreateAndSwitchToNewProfile(chrome::HOST_DESKTOP_TYPE_NATIVE, 897 profiles::CreateAndSwitchToNewProfile(chrome::HOST_DESKTOP_TYPE_NATIVE,
895 ProfileManager::CreateCallback(), 898 ProfileManager::CreateCallback(),
896 ProfileMetrics::ADD_NEW_USER_MENU); 899 ProfileMetrics::ADD_NEW_USER_MENU);
897 } 900 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/global_menu_bar_x11.h ('k') | chrome/browser/ui/views/frame/system_menu_model_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698