OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/toolbar/recent_tabs_sub_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 const int RecentTabsSubMenuModel::kDisabledRecentlyClosedHeaderCommandId = 1121; | 165 const int RecentTabsSubMenuModel::kDisabledRecentlyClosedHeaderCommandId = 1121; |
166 | 166 |
167 RecentTabsSubMenuModel::RecentTabsSubMenuModel( | 167 RecentTabsSubMenuModel::RecentTabsSubMenuModel( |
168 ui::AcceleratorProvider* accelerator_provider, | 168 ui::AcceleratorProvider* accelerator_provider, |
169 Browser* browser, | 169 Browser* browser, |
170 browser_sync::OpenTabsUIDelegate* open_tabs_delegate) | 170 browser_sync::OpenTabsUIDelegate* open_tabs_delegate) |
171 : ui::SimpleMenuModel(this), | 171 : ui::SimpleMenuModel(this), |
172 browser_(browser), | 172 browser_(browser), |
173 open_tabs_delegate_(open_tabs_delegate), | 173 open_tabs_delegate_(open_tabs_delegate), |
174 last_local_model_index_(-1), | 174 last_local_model_index_(-1), |
175 default_favicon_(ResourceBundle::GetSharedInstance(). | 175 default_favicon_(ui::ResourceBundle::GetSharedInstance(). |
176 GetNativeImageNamed(IDR_DEFAULT_FAVICON)), | 176 GetNativeImageNamed(IDR_DEFAULT_FAVICON)), |
177 weak_ptr_factory_(this) { | 177 weak_ptr_factory_(this) { |
178 // Invoke asynchronous call to load tabs from local last session, which does | 178 // Invoke asynchronous call to load tabs from local last session, which does |
179 // nothing if the tabs have already been loaded or they shouldn't be loaded. | 179 // nothing if the tabs have already been loaded or they shouldn't be loaded. |
180 // TabRestoreServiceChanged() will be called after the tabs are loaded. | 180 // TabRestoreServiceChanged() will be called after the tabs are loaded. |
181 TabRestoreService* service = | 181 TabRestoreService* service = |
182 TabRestoreServiceFactory::GetForProfile(browser_->profile()); | 182 TabRestoreServiceFactory::GetForProfile(browser_->profile()); |
183 if (service) { | 183 if (service) { |
184 service->LoadTabsFromLastSession(); | 184 service->LoadTabsFromLastSession(); |
185 | 185 |
186 // TODO(sail): enable this when mac implements the dynamic menu, together with | 186 // TODO(sail): enable this when mac implements the dynamic menu, together with |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 DCHECK(window_items_idx >= 0 && | 306 DCHECK(window_items_idx >= 0 && |
307 window_items_idx < static_cast<int>(local_window_items_.size())); | 307 window_items_idx < static_cast<int>(local_window_items_.size())); |
308 UMA_HISTOGRAM_ENUMERATION("WrenchMenu.RecentTabsSubMenu", RESTORE_WINDOW, | 308 UMA_HISTOGRAM_ENUMERATION("WrenchMenu.RecentTabsSubMenu", RESTORE_WINDOW, |
309 LIMIT_RECENT_TAB_ACTION); | 309 LIMIT_RECENT_TAB_ACTION); |
310 service->RestoreEntryById(delegate, local_window_items_[window_items_idx], | 310 service->RestoreEntryById(delegate, local_window_items_[window_items_idx], |
311 browser_->host_desktop_type(), disposition); | 311 browser_->host_desktop_type(), disposition); |
312 } | 312 } |
313 } | 313 } |
314 } | 314 } |
315 | 315 |
316 const gfx::Font* RecentTabsSubMenuModel::GetLabelFontAt(int index) const { | 316 const gfx::FontList* RecentTabsSubMenuModel::GetLabelFontListAt( |
| 317 int index) const { |
317 int command_id = GetCommandIdAt(index); | 318 int command_id = GetCommandIdAt(index); |
318 if (command_id == kRecentlyClosedHeaderCommandId || | 319 if (command_id == kRecentlyClosedHeaderCommandId || |
319 IsDeviceNameCommandId(command_id)) { | 320 IsDeviceNameCommandId(command_id)) { |
320 return &ResourceBundle::GetSharedInstance().GetFont( | 321 return &ui::ResourceBundle::GetSharedInstance().GetFontList( |
321 ResourceBundle::BoldFont); | 322 ui::ResourceBundle::BoldFont); |
322 } | 323 } |
323 return NULL; | 324 return NULL; |
324 } | 325 } |
325 | 326 |
326 int RecentTabsSubMenuModel::GetMaxWidthForItemAtIndex(int item_index) const { | 327 int RecentTabsSubMenuModel::GetMaxWidthForItemAtIndex(int item_index) const { |
327 int command_id = GetCommandIdAt(item_index); | 328 int command_id = GetCommandIdAt(item_index); |
328 if (command_id == IDC_RECENT_TABS_NO_DEVICE_TABS || | 329 if (command_id == IDC_RECENT_TABS_NO_DEVICE_TABS || |
329 command_id == kRecentlyClosedHeaderCommandId || | 330 command_id == kRecentlyClosedHeaderCommandId || |
330 command_id == kDisabledRecentlyClosedHeaderCommandId) { | 331 command_id == kDisabledRecentlyClosedHeaderCommandId) { |
331 return -1; | 332 return -1; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 if (!service || service->entries().size() == 0) { | 379 if (!service || service->entries().size() == 0) { |
379 // This is to show a disabled restore tab entry with the accelerator to | 380 // This is to show a disabled restore tab entry with the accelerator to |
380 // teach users about this command. | 381 // teach users about this command. |
381 InsertItemWithStringIdAt(++last_local_model_index_, | 382 InsertItemWithStringIdAt(++last_local_model_index_, |
382 kDisabledRecentlyClosedHeaderCommandId, | 383 kDisabledRecentlyClosedHeaderCommandId, |
383 IDS_NEW_TAB_RECENTLY_CLOSED); | 384 IDS_NEW_TAB_RECENTLY_CLOSED); |
384 } else { | 385 } else { |
385 InsertItemWithStringIdAt(++last_local_model_index_, | 386 InsertItemWithStringIdAt(++last_local_model_index_, |
386 kRecentlyClosedHeaderCommandId, | 387 kRecentlyClosedHeaderCommandId, |
387 IDS_NEW_TAB_RECENTLY_CLOSED); | 388 IDS_NEW_TAB_RECENTLY_CLOSED); |
388 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 389 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
389 SetIcon(last_local_model_index_, | 390 SetIcon(last_local_model_index_, |
390 rb.GetNativeImageNamed(IDR_RECENTLY_CLOSED_WINDOW)); | 391 rb.GetNativeImageNamed(IDR_RECENTLY_CLOSED_WINDOW)); |
391 | 392 |
392 int added_count = 0; | 393 int added_count = 0; |
393 TabRestoreService::Entries entries = service->entries(); | 394 TabRestoreService::Entries entries = service->entries(); |
394 for (TabRestoreService::Entries::const_iterator it = entries.begin(); | 395 for (TabRestoreService::Entries::const_iterator it = entries.begin(); |
395 it != entries.end() && added_count < kMaxLocalEntries; ++it) { | 396 it != entries.end() && added_count < kMaxLocalEntries; ++it) { |
396 TabRestoreService::Entry* entry = *it; | 397 TabRestoreService::Entry* entry = *it; |
397 if (entry->type == TabRestoreService::TAB) { | 398 if (entry->type == TabRestoreService::TAB) { |
398 TabRestoreService::Tab* tab = | 399 TabRestoreService::Tab* tab = |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 int command_id = WindowVectorIndexToCommandId(local_window_items_.size()); | 521 int command_id = WindowVectorIndexToCommandId(local_window_items_.size()); |
521 // See comments in BuildLocalEntries() about usage of InsertItem*At(). | 522 // See comments in BuildLocalEntries() about usage of InsertItem*At(). |
522 if (num_tabs == 1) { | 523 if (num_tabs == 1) { |
523 InsertItemWithStringIdAt(curr_model_index, command_id, | 524 InsertItemWithStringIdAt(curr_model_index, command_id, |
524 IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_SINGLE); | 525 IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_SINGLE); |
525 } else { | 526 } else { |
526 InsertItemAt(curr_model_index, command_id, l10n_util::GetStringFUTF16( | 527 InsertItemAt(curr_model_index, command_id, l10n_util::GetStringFUTF16( |
527 IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_MULTIPLE, | 528 IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_MULTIPLE, |
528 base::IntToString16(num_tabs))); | 529 base::IntToString16(num_tabs))); |
529 } | 530 } |
530 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 531 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
531 SetIcon(curr_model_index, rb.GetNativeImageNamed(IDR_RECENTLY_CLOSED_WINDOW)); | 532 SetIcon(curr_model_index, rb.GetNativeImageNamed(IDR_RECENTLY_CLOSED_WINDOW)); |
532 local_window_items_.push_back(window_id); | 533 local_window_items_.push_back(window_id); |
533 } | 534 } |
534 | 535 |
535 void RecentTabsSubMenuModel::BuildOtherDevicesTabItem( | 536 void RecentTabsSubMenuModel::BuildOtherDevicesTabItem( |
536 const std::string& session_tag, | 537 const std::string& session_tag, |
537 const SessionTab& tab) { | 538 const SessionTab& tab) { |
538 const sessions::SerializedNavigationEntry& current_navigation = | 539 const sessions::SerializedNavigationEntry& current_navigation = |
539 tab.navigations.at(tab.normalized_navigation_index()); | 540 tab.navigations.at(tab.normalized_navigation_index()); |
540 TabNavigationItem item(session_tag, tab.tab_id.id(), | 541 TabNavigationItem item(session_tag, tab.tab_id.id(), |
(...skipping 27 matching lines...) Expand all Loading... |
568 case browser_sync::SyncedSession::TYPE_CHROMEOS: | 569 case browser_sync::SyncedSession::TYPE_CHROMEOS: |
569 case browser_sync::SyncedSession::TYPE_WIN: | 570 case browser_sync::SyncedSession::TYPE_WIN: |
570 case browser_sync::SyncedSession::TYPE_MACOSX: | 571 case browser_sync::SyncedSession::TYPE_MACOSX: |
571 case browser_sync::SyncedSession::TYPE_LINUX: | 572 case browser_sync::SyncedSession::TYPE_LINUX: |
572 case browser_sync::SyncedSession::TYPE_OTHER: | 573 case browser_sync::SyncedSession::TYPE_OTHER: |
573 case browser_sync::SyncedSession::TYPE_UNSET: | 574 case browser_sync::SyncedSession::TYPE_UNSET: |
574 favicon_id = IDR_LAPTOP_FAVICON; | 575 favicon_id = IDR_LAPTOP_FAVICON; |
575 break; | 576 break; |
576 }; | 577 }; |
577 | 578 |
578 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 579 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
579 SetIcon(index_in_menu, rb.GetNativeImageNamed(favicon_id)); | 580 SetIcon(index_in_menu, rb.GetNativeImageNamed(favicon_id)); |
580 } | 581 } |
581 | 582 |
582 void RecentTabsSubMenuModel::AddTabFavicon(int command_id, const GURL& url) { | 583 void RecentTabsSubMenuModel::AddTabFavicon(int command_id, const GURL& url) { |
583 bool is_local_tab = command_id < kFirstOtherDevicesTabCommandId; | 584 bool is_local_tab = command_id < kFirstOtherDevicesTabCommandId; |
584 int index_in_menu = GetIndexOfCommandId(command_id); | 585 int index_in_menu = GetIndexOfCommandId(command_id); |
585 | 586 |
586 if (!is_local_tab) { | 587 if (!is_local_tab) { |
587 // If tab has synced favicon, use it. | 588 // If tab has synced favicon, use it. |
588 // Note that currently, other devices' tabs only have favicons if | 589 // Note that currently, other devices' tabs only have favicons if |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 | 682 |
682 ui::MenuModelDelegate* menu_model_delegate = GetMenuModelDelegate(); | 683 ui::MenuModelDelegate* menu_model_delegate = GetMenuModelDelegate(); |
683 if (menu_model_delegate) | 684 if (menu_model_delegate) |
684 menu_model_delegate->OnMenuStructureChanged(); | 685 menu_model_delegate->OnMenuStructureChanged(); |
685 } | 686 } |
686 | 687 |
687 void RecentTabsSubMenuModel::TabRestoreServiceDestroyed( | 688 void RecentTabsSubMenuModel::TabRestoreServiceDestroyed( |
688 TabRestoreService* service) { | 689 TabRestoreService* service) { |
689 TabRestoreServiceChanged(service); | 690 TabRestoreServiceChanged(service); |
690 } | 691 } |
OLD | NEW |