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.
5 #include "chrome/browser/ui/views/frame/system_menu_model_delegate.h"
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"
18 SystemMenuModelDelegate::SystemMenuModelDelegate(
19 ui::AcceleratorProvider
* provider
,
21 : provider_(provider
),
25 SystemMenuModelDelegate::~SystemMenuModelDelegate() {
28 bool SystemMenuModelDelegate::IsCommandIdChecked(int command_id
) const {
30 case IDC_USE_SYSTEM_TITLE_BAR
: {
31 PrefService
* prefs
= browser_
->profile()->GetPrefs();
32 return !prefs
->GetBoolean(prefs::kUseCustomChromeFrame
);
39 bool SystemMenuModelDelegate::IsCommandIdEnabled(int command_id
) const {
40 return chrome::IsCommandEnabled(browser_
, command_id
);
43 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id
,
44 ui::Accelerator
* accelerator
) {
45 return provider_
->GetAcceleratorForCommandId(command_id
, accelerator
);
48 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id
) const {
49 return command_id
== IDC_RESTORE_TAB
;
52 base::string16
SystemMenuModelDelegate::GetLabelForCommandId(
53 int command_id
) const {
54 DCHECK_EQ(command_id
, IDC_RESTORE_TAB
);
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
;
63 return l10n_util::GetStringUTF16(string_id
);
66 void SystemMenuModelDelegate::ExecuteCommand(int command_id
, int event_flags
) {
67 chrome::ExecuteCommand(browser_
, command_id
);