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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/frame/system_menu_model_delegate.h"
6
7 #include "base/prefs/pref_service.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/command_updater.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sessions/tab_restore_service.h"
12 #include "chrome/browser/sessions/tab_restore_service_factory.h"
13 #include "chrome/browser/ui/browser_commands.h"
14 #include "chrome/common/pref_names.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17
SystemMenuModelDelegate(ui::AcceleratorProvider * provider,Browser * browser)18 SystemMenuModelDelegate::SystemMenuModelDelegate(
19 ui::AcceleratorProvider* provider,
20 Browser* browser)
21 : provider_(provider),
22 browser_(browser) {
23 }
24
~SystemMenuModelDelegate()25 SystemMenuModelDelegate::~SystemMenuModelDelegate() {
26 }
27
IsCommandIdChecked(int command_id) const28 bool SystemMenuModelDelegate::IsCommandIdChecked(int command_id) const {
29 switch (command_id) {
30 case IDC_USE_SYSTEM_TITLE_BAR: {
31 PrefService* prefs = browser_->profile()->GetPrefs();
32 return !prefs->GetBoolean(prefs::kUseCustomChromeFrame);
33 }
34 default:
35 return false;
36 }
37 }
38
IsCommandIdEnabled(int command_id) const39 bool SystemMenuModelDelegate::IsCommandIdEnabled(int command_id) const {
40 return chrome::IsCommandEnabled(browser_, command_id);
41 }
42
GetAcceleratorForCommandId(int command_id,ui::Accelerator * accelerator)43 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id,
44 ui::Accelerator* accelerator) {
45 return provider_->GetAcceleratorForCommandId(command_id, accelerator);
46 }
47
IsItemForCommandIdDynamic(int command_id) const48 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id) const {
49 return command_id == IDC_RESTORE_TAB;
50 }
51
GetLabelForCommandId(int command_id) const52 base::string16 SystemMenuModelDelegate::GetLabelForCommandId(
53 int command_id) const {
54 DCHECK_EQ(command_id, IDC_RESTORE_TAB);
55
56 int string_id = IDS_RESTORE_TAB;
57 if (IsCommandIdEnabled(command_id)) {
58 TabRestoreService* trs =
59 TabRestoreServiceFactory::GetForProfile(browser_->profile());
60 if (trs && trs->entries().front()->type == TabRestoreService::WINDOW)
61 string_id = IDS_RESTORE_WINDOW;
62 }
63 return l10n_util::GetStringUTF16(string_id);
64 }
65
ExecuteCommand(int command_id,int event_flags)66 void SystemMenuModelDelegate::ExecuteCommand(int command_id, int event_flags) {
67 chrome::ExecuteCommand(browser_, command_id);
68 }
69