- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / frame / system_menu_model_delegate.cc
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 "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/command_updater.h"
9 #include "chrome/browser/sessions/tab_restore_service.h"
10 #include "chrome/browser/sessions/tab_restore_service_factory.h"
11 #include "chrome/browser/ui/browser_commands.h"
12 #include "grit/generated_resources.h"
13 #include "ui/base/l10n/l10n_util.h"
14
15 SystemMenuModelDelegate::SystemMenuModelDelegate(
16     ui::AcceleratorProvider* provider,
17     Browser* browser)
18     : provider_(provider),
19       browser_(browser) {
20 }
21
22 SystemMenuModelDelegate::~SystemMenuModelDelegate() {
23 }
24
25 bool SystemMenuModelDelegate::IsCommandIdChecked(int command_id) const {
26   // TODO(beng): encoding menu.
27   // No items in our system menu are check-able.
28   return false;
29 }
30
31 bool SystemMenuModelDelegate::IsCommandIdEnabled(int command_id) const {
32   return chrome::IsCommandEnabled(browser_, command_id);
33 }
34
35 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id,
36                                              ui::Accelerator* accelerator) {
37   return provider_->GetAcceleratorForCommandId(command_id, accelerator);
38 }
39
40 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id) const {
41   return command_id == IDC_RESTORE_TAB;
42 }
43
44 string16 SystemMenuModelDelegate::GetLabelForCommandId(int command_id) const {
45   DCHECK_EQ(command_id, IDC_RESTORE_TAB);
46
47   int string_id = IDS_RESTORE_TAB;
48   if (IsCommandIdEnabled(command_id)) {
49     TabRestoreService* trs =
50         TabRestoreServiceFactory::GetForProfile(browser_->profile());
51     if (trs && trs->entries().front()->type == TabRestoreService::WINDOW)
52       string_id = IDS_RESTORE_WINDOW;
53   }
54   return l10n_util::GetStringUTF16(string_id);
55 }
56
57 void SystemMenuModelDelegate::ExecuteCommand(int command_id, int event_flags) {
58   chrome::ExecuteCommand(browser_, command_id);
59 }