| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ |
| 6 #define CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ |
| 7 |
| 8 #include <set> |
| 9 |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "chrome/browser/favicon/favicon_service.h" |
| 12 #include "chrome/browser/sessions/tab_restore_service.h" |
| 13 #include "ui/base/accelerators/accelerator.h" |
| 14 #include "ui/base/models/simple_menu_model.h" |
| 15 |
| 16 class Browser; |
| 17 struct SessionTab; |
| 18 |
| 19 namespace browser_sync { |
| 20 class SessionModelAssociator; |
| 21 } |
| 22 |
| 23 namespace gfx { |
| 24 class Image; |
| 25 } |
| 26 |
| 27 namespace ui { |
| 28 class AcceleratorProvider; |
| 29 } |
| 30 |
| 31 // A menu model that builds the contents of "Recent tabs" submenu, which include |
| 32 // the last closed tab and opened tabs of other devices. |
| 33 class RecentTabsSubMenuModel : public ui::SimpleMenuModel, |
| 34 public ui::SimpleMenuModel::Delegate { |
| 35 public: |
| 36 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider, |
| 37 Browser* browser); |
| 38 // Constructor for testing. |
| 39 RecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider, |
| 40 Browser* browser, |
| 41 browser_sync::SessionModelAssociator* associator, |
| 42 bool setup_for_test); |
| 43 virtual ~RecentTabsSubMenuModel(); |
| 44 |
| 45 // Overridden from ui::SimpleMenuModel::Delegate: |
| 46 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
| 47 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
| 48 virtual bool GetAcceleratorForCommandId( |
| 49 int command_id, |
| 50 ui::Accelerator* accelerator) OVERRIDE; |
| 51 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE; |
| 52 virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE; |
| 53 virtual void ExecuteCommand(int command_id) OVERRIDE; |
| 54 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; |
| 55 |
| 56 private: |
| 57 struct NavigationItem; |
| 58 typedef std::vector<NavigationItem> NavigationItems; |
| 59 |
| 60 // Build the menu items by populating the model. |
| 61 void Build(); |
| 62 void BuildLastClosed(); |
| 63 void BuildDevices(); |
| 64 void BuildForeignTabItem(const std::string& session_tag, |
| 65 const SessionTab& tab, |
| 66 const std::string& session_name, |
| 67 bool need_separator); |
| 68 void AddFavicon(int model_index, int command_id, const GURL& url); |
| 69 void OnFaviconDataAvailable(FaviconService::Handle handle, |
| 70 const history::FaviconImageResult& image_result); |
| 71 browser_sync::SessionModelAssociator* GetModelAssociator(); |
| 72 |
| 73 Browser* browser_; // Weak. |
| 74 |
| 75 browser_sync::SessionModelAssociator* associator_; // Weak. |
| 76 |
| 77 // Accelerator for reopening last closed tab. |
| 78 ui::Accelerator reopen_closed_tab_accelerator_; |
| 79 |
| 80 // Navigation items. The |command_id| is set to kFirstTabCommandId plus the |
| 81 // index into this vector. Upon invocation of the menu, the navigation |
| 82 // information is retrieved from |model_| and used to navigate to the item |
| 83 // specified. |
| 84 NavigationItems model_; |
| 85 |
| 86 gfx::Image default_favicon_; |
| 87 |
| 88 CancelableRequestConsumerTSimple<int> favicon_consumer_; |
| 89 |
| 90 base::WeakPtrFactory<RecentTabsSubMenuModel> weak_ptr_factory_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(RecentTabsSubMenuModel); |
| 93 }; |
| 94 |
| 95 #endif // CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ |
| OLD | NEW |