Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/views/frame/system_menu_model_delegate.h" | 5 #include "chrome/browser/ui/views/frame/system_menu_model_delegate.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/command_updater.h" | 9 #include "chrome/browser/command_updater.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 case IDC_USE_SYSTEM_TITLE_BAR: { | 30 case IDC_USE_SYSTEM_TITLE_BAR: { |
| 31 PrefService* prefs = browser_->profile()->GetPrefs(); | 31 PrefService* prefs = browser_->profile()->GetPrefs(); |
| 32 return !prefs->GetBoolean(prefs::kUseCustomChromeFrame); | 32 return !prefs->GetBoolean(prefs::kUseCustomChromeFrame); |
| 33 } | 33 } |
| 34 default: | 34 default: |
| 35 return false; | 35 return false; |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool SystemMenuModelDelegate::IsCommandIdEnabled(int command_id) const { | 39 bool SystemMenuModelDelegate::IsCommandIdEnabled(int command_id) const { |
| 40 return chrome::IsCommandEnabled(browser_, command_id); | 40 if (!chrome::IsCommandEnabled(browser_, command_id)) |
| 41 return false; | |
| 42 | |
| 43 if (command_id != IDC_RESTORE_TAB) | |
| 44 return true; | |
| 45 | |
| 46 // IDC_RESTORE_TAB is initially true while TabRestoreService loads. Return | |
| 47 // false if this is the case as we don't have a good way to dynamically update | |
| 48 // the menu. | |
|
pkotwicz
2014/08/19 21:12:14
Nit: chrome::IsCommandEnabled() returns true for I
sky
2014/08/19 21:35:08
Done.
| |
| 49 // TODO(sky): add a way to update menu. | |
| 50 TabRestoreService* trs = | |
| 51 TabRestoreServiceFactory::GetForProfile(browser_->profile()); | |
| 52 if (!trs->IsLoaded()) { | |
| 53 trs->LoadTabsFromLastSession(); | |
| 54 return false; | |
| 55 } | |
| 56 return true; | |
| 41 } | 57 } |
| 42 | 58 |
| 43 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id, | 59 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id, |
| 44 ui::Accelerator* accelerator) { | 60 ui::Accelerator* accelerator) { |
| 45 return provider_->GetAcceleratorForCommandId(command_id, accelerator); | 61 return provider_->GetAcceleratorForCommandId(command_id, accelerator); |
| 46 } | 62 } |
| 47 | 63 |
| 48 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id) const { | 64 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id) const { |
| 49 return command_id == IDC_RESTORE_TAB; | 65 return command_id == IDC_RESTORE_TAB; |
| 50 } | 66 } |
| 51 | 67 |
| 52 base::string16 SystemMenuModelDelegate::GetLabelForCommandId( | 68 base::string16 SystemMenuModelDelegate::GetLabelForCommandId( |
| 53 int command_id) const { | 69 int command_id) const { |
| 54 DCHECK_EQ(command_id, IDC_RESTORE_TAB); | 70 DCHECK_EQ(command_id, IDC_RESTORE_TAB); |
| 55 | 71 |
| 56 int string_id = IDS_RESTORE_TAB; | 72 int string_id = IDS_RESTORE_TAB; |
| 57 if (IsCommandIdEnabled(command_id)) { | 73 if (IsCommandIdEnabled(command_id)) { |
| 58 TabRestoreService* trs = | 74 TabRestoreService* trs = |
| 59 TabRestoreServiceFactory::GetForProfile(browser_->profile()); | 75 TabRestoreServiceFactory::GetForProfile(browser_->profile()); |
| 60 if (trs && trs->entries().front()->type == TabRestoreService::WINDOW) | 76 trs->LoadTabsFromLastSession(); |
| 77 if (trs && !trs->entries().empty() && | |
| 78 trs->entries().front()->type == TabRestoreService::WINDOW) | |
| 61 string_id = IDS_RESTORE_WINDOW; | 79 string_id = IDS_RESTORE_WINDOW; |
| 62 } | 80 } |
| 63 return l10n_util::GetStringUTF16(string_id); | 81 return l10n_util::GetStringUTF16(string_id); |
| 64 } | 82 } |
| 65 | 83 |
| 66 void SystemMenuModelDelegate::ExecuteCommand(int command_id, int event_flags) { | 84 void SystemMenuModelDelegate::ExecuteCommand(int command_id, int event_flags) { |
| 67 chrome::ExecuteCommand(browser_, command_id); | 85 chrome::ExecuteCommand(browser_, command_id); |
| 68 } | 86 } |
| OLD | NEW |