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_factory.h"
12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "components/sessions/core/tab_restore_service.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 if (!chrome::IsCommandEnabled(browser_
, command_id
))
43 if (command_id
!= IDC_RESTORE_TAB
)
46 // chrome::IsCommandEnabled(IDC_RESTORE_TAB) returns true if TabRestoreService
47 // hasn't been loaded yet. Return false if this is the case as we don't have
48 // a good way to dynamically update the menu when TabRestoreService finishes
50 // TODO(sky): add a way to update menu.
51 sessions::TabRestoreService
* trs
=
52 TabRestoreServiceFactory::GetForProfile(browser_
->profile());
53 if (!trs
->IsLoaded()) {
54 trs
->LoadTabsFromLastSession();
60 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id
,
61 ui::Accelerator
* accelerator
) {
62 return provider_
->GetAcceleratorForCommandId(command_id
, accelerator
);
65 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id
) const {
66 return command_id
== IDC_RESTORE_TAB
;
69 base::string16
SystemMenuModelDelegate::GetLabelForCommandId(
70 int command_id
) const {
71 DCHECK_EQ(command_id
, IDC_RESTORE_TAB
);
73 int string_id
= IDS_RESTORE_TAB
;
74 if (IsCommandIdEnabled(command_id
)) {
75 sessions::TabRestoreService
* trs
=
76 TabRestoreServiceFactory::GetForProfile(browser_
->profile());
77 trs
->LoadTabsFromLastSession();
78 if (trs
&& !trs
->entries().empty() &&
79 trs
->entries().front()->type
== sessions::TabRestoreService::WINDOW
)
80 string_id
= IDS_RESTORE_WINDOW
;
82 return l10n_util::GetStringUTF16(string_id
);
85 void SystemMenuModelDelegate::ExecuteCommand(int command_id
, int event_flags
) {
86 chrome::ExecuteCommand(browser_
, command_id
);