15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/task_manager/task_manager.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/metrics/stats_table.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/prefs/scoped_user_pref_update.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/app/chrome_command_ids.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browser_process.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_list.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_window.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/host_desktop.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/views/browser_dialogs.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h"
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/grit/chromium_strings.h"
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/grit/generated_resources.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/accelerators/accelerator.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/models/simple_menu_model.h"
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/models/table_model.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/models/table_model_observer.h"
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/events/event_constants.h"
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/events/keycodes/keyboard_codes.h"
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/canvas.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/context_menu_controller.h"
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/controls/button/label_button.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/link.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/link_listener.h"
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/controls/menu/menu_runner.h"
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/controls/table/table_grouper.h"
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/controls/table/table_view.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/table/table_view_observer.h"
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/layout/layout_constants.h"
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h"
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/window/dialog_delegate.h"
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(USE_ASH)
436d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "ash/shelf/shelf_util.h"
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/wm/window_util.h"
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "grit/ash_resources.h"
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
49a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/shell_integration.h"
50a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/base/win/shell.h"
51a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/views/win/hwnd_util.h"
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TaskManagerTableModel class
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TaskManagerTableModel
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : public ui::TableModel,
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      public views::TableGrouper,
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      public TaskManagerModelObserver {
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit TaskManagerTableModel(TaskManagerModel* model)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      : model_(model),
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        observer_(NULL) {
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    model_->AddObserver(this);
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TaskManagerTableModel() {
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    model_->RemoveObserver(this);
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TableModel overrides:
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual int RowCount() OVERRIDE;
77a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual base::string16 GetText(int row, int column) OVERRIDE;
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::ImageSkia GetIcon(int row) OVERRIDE;
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int CompareValues(int row1, int row2, int column_id) OVERRIDE;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TableGrouper overrides:
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void GetGroupRange(int model_index,
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             views::GroupRange* range) OVERRIDE;
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TaskManagerModelObserver overrides:
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnModelChanged() OVERRIDE;
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnItemsChanged(int start, int length) OVERRIDE;
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnItemsAdded(int start, int length) OVERRIDE;
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnItemsRemoved(int start, int length) OVERRIDE;
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TaskManagerModel* model_;
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ui::TableModelObserver* observer_;
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TaskManagerTableModel);
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int TaskManagerTableModel::RowCount() {
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return model_->ResourceCount();
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::string16 TaskManagerTableModel::GetText(int row, int col_id) {
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return model_->GetResourceById(row, col_id);
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::ImageSkia TaskManagerTableModel::GetIcon(int row) {
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return model_->GetResourceIcon(row);
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerTableModel::SetObserver(ui::TableModelObserver* observer) {
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  observer_ = observer;
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int TaskManagerTableModel::CompareValues(int row1, int row2, int column_id) {
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return model_->CompareValues(row1, row2, column_id);
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TaskManagerTableModel::GetGroupRange(int model_index,
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          views::GroupRange* range) {
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TaskManagerModel::GroupRange range_pair =
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      model_->GetGroupRangeForResource(model_index);
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  range->start = range_pair.first;
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  range->length = range_pair.second;
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerTableModel::OnModelChanged() {
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (observer_)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    observer_->OnModelChanged();
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerTableModel::OnItemsChanged(int start, int length) {
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (observer_)
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    observer_->OnItemsChanged(start, length);
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerTableModel::OnItemsAdded(int start, int length) {
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (observer_)
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    observer_->OnItemsAdded(start, length);
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerTableModel::OnItemsRemoved(int start, int length) {
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (observer_)
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    observer_->OnItemsRemoved(start, length);
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The Task manager UI container.
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TaskManagerView : public views::ButtonListener,
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        public views::DialogDelegateView,
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        public views::TableViewObserver,
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        public views::LinkListener,
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        public views::ContextMenuController,
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                        public ui::SimpleMenuModel::Delegate {
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
155eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  explicit TaskManagerView(chrome::HostDesktopType desktop_type);
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~TaskManagerView();
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
158eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Shows the Task manager window, or re-activates an existing one.
159eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  static void Show(Browser* browser);
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // views::View:
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Layout() OVERRIDE;
163cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual gfx::Size GetPreferredSize() const OVERRIDE;
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
165a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void ViewHierarchyChanged(
166a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      const ViewHierarchyChangedDetails& details) OVERRIDE;
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // views::ButtonListener:
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void ButtonPressed(views::Button* sender,
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const ui::Event& event) OVERRIDE;
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // views::DialogDelegateView:
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool CanResize() const OVERRIDE;
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool CanMaximize() const OVERRIDE;
1751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual bool CanMinimize() const OVERRIDE;
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool ExecuteWindowsCommand(int command_id) OVERRIDE;
177a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual base::string16 GetWindowTitle() const OVERRIDE;
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual std::string GetWindowName() const OVERRIDE;
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int GetDialogButtons() const OVERRIDE;
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void WindowClosing() OVERRIDE;
181868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual bool UseNewStyleForThisDialog() const OVERRIDE;
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // views::TableViewObserver:
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnSelectionChanged() OVERRIDE;
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnDoubleClick() OVERRIDE;
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnKeyDown(ui::KeyboardCode keycode) OVERRIDE;
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // views::LinkListener:
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by the column picker to pick up any new stat counters that
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // may have appeared since last time.
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void UpdateStatsCounters();
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // views::ContextMenuController:
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void ShowContextMenuForView(views::View* source,
1977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                      const gfx::Point& point,
1987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                      ui::MenuSourceType source_type) OVERRIDE;
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // ui::SimpleMenuModel::Delegate:
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool IsCommandIdChecked(int id) const OVERRIDE;
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool IsCommandIdEnabled(int id) const OVERRIDE;
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool GetAcceleratorForCommandId(
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      int command_id,
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      ui::Accelerator* accelerator) OVERRIDE;
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void ExecuteCommand(int id, int event_flags) OVERRIDE;
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates the child controls.
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Init();
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initializes the state of the always-on-top setting as the window is shown.
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void InitAlwaysOnTopState();
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Activates the tab associated with the focused row.
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ActivateFocusedTab();
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Restores saved always on top state from a previous session.
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetSavedAlwaysOnTopState(bool* always_on_top) const;
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  views::LabelButton* kill_button_;
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::Link* about_memory_link_;
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  views::TableView* tab_table_;
2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  views::View* tab_table_parent_;
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TaskManager* task_manager_;
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TaskManagerModel* model_;
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // all possible columns, not necessarily visible
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<ui::TableColumn> columns_;
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<TaskManagerTableModel> table_model_;
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // True when the Task Manager window should be shown on top of other windows.
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool is_always_on_top_;
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The host desktop type this task manager belongs to.
2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const chrome::HostDesktopType desktop_type_;
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We need to own the text of the menu, the Windows API does not copy it.
242a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 always_on_top_menu_text_;
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // An open Task manager window. There can only be one open at a time. This
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is reset to NULL when the window is closed.
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static TaskManagerView* instance_;
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<views::MenuRunner> menu_runner_;
2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TaskManagerView);
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TaskManagerView* TaskManagerView::instance_ = NULL;
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
257eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTaskManagerView::TaskManagerView(chrome::HostDesktopType desktop_type)
258a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    : kill_button_(NULL),
2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      about_memory_link_(NULL),
2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      tab_table_(NULL),
2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      tab_table_parent_(NULL),
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      task_manager_(TaskManager::GetInstance()),
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      model_(TaskManager::GetInstance()->model()),
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      is_always_on_top_(false),
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      desktop_type_(desktop_type) {
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Init();
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TaskManagerView::~TaskManagerView() {
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Delete child views now, while our table model still exists.
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RemoveAllChildViews(true);
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::Init() {
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  table_model_.reset(new TaskManagerTableModel(model_));
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Page column has no header label.
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_TASK_COLUMN,
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::TableColumn::LEFT, -1, 1));
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN,
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::TableColumn::LEFT, -1, 0));
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN,
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::TableColumn::RIGHT, -1, 0));
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN,
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::TableColumn::RIGHT, -1, 0));
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN,
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::TableColumn::RIGHT, -1, 0));
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_CPU_COLUMN,
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::TableColumn::RIGHT, -1, 0));
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_NET_COLUMN,
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::TableColumn::RIGHT, -1, 0));
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN,
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::TableColumn::RIGHT, -1, 0));
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN,
3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     ui::TableColumn::RIGHT, -1, 0));
3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  columns_.back().sortable = true;
3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_USER_HANDLES_COLUMN,
3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                     ui::TableColumn::RIGHT, -1, 0));
3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  columns_.back().sortable = true;
3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN,
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ui::TableColumn::RIGHT, -1, 0));
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN,
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ui::TableColumn::RIGHT, -1, 0));
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN,
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::TableColumn::RIGHT, -1, 0));
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN,
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::TableColumn::RIGHT, -1, 0));
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN,
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     ui::TableColumn::RIGHT, -1, 0));
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  columns_.push_back(ui::TableColumn(
3285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN,
3295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      ui::TableColumn::RIGHT, -1, 0));
3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  columns_.back().sortable = true;
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.push_back(
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ui::TableColumn(IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN,
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                      ui::TableColumn::RIGHT, -1, 0));
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  columns_.back().sortable = true;
3351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // TODO(port) http://crbug.com/120488 for non-Linux.
3361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(OS_LINUX)
3371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN,
3381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                     ui::TableColumn::RIGHT, -1, 0));
3391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  columns_.back().sortable = true;
3401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  tab_table_ = new views::TableView(
343c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      table_model_.get(), columns_, views::ICON_AND_TEXT, false);
3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  tab_table_->SetGrouper(table_model_.get());
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Hide some columns by default
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, false);
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, false);
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false);
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN,
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  false);
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN,
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  false);
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN,
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  false);
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN,
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  false);
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN,
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  false);
3605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN,
3615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                  false);
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->SetColumnVisibility(
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN, false);
3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN, false);
3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_USER_HANDLES_COLUMN, false);
3661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN, false);
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateStatsCounters();
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->SetObserver(this);
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->set_context_menu_controller(this);
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  set_context_menu_controller(this);
3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  kill_button_ = new views::LabelButton(this,
3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL));
3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  kill_button_->SetStyle(views::Button::STYLE_BUTTON);
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  about_memory_link_ = new views::Link(
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK));
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  about_memory_link_->set_listener(this);
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Makes sure our state is consistent.
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  OnSelectionChanged();
3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ui::Accelerator ctrl_w(ui::VKEY_W, ui::EF_CONTROL_DOWN);
3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AddAccelerator(ctrl_w);
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::UpdateStatsCounters() {
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::StatsTable* stats = base::StatsTable::current();
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (stats != NULL) {
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int max = stats->GetMaxCounters();
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // skip the first row (it's header data)
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    for (int i = 1; i < max; i++) {
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const char* row = stats->GetRowName(i);
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      if (row != NULL && row[0] != '\0' && !tab_table_->HasColumn(i)) {
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // TODO(erikkay): Use l10n to get display names for stats.  Right
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // now we're just displaying the internal counter name.  Perhaps
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // stat names not in the string table would be filtered out.
3972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        ui::TableColumn col;
3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        col.id = i;
3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        col.title = base::ASCIIToUTF16(row);
4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        col.alignment = ui::TableColumn::RIGHT;
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // TODO(erikkay): Width is hard-coded right now, so many column
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        // names are clipped.
4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        col.width = 90;
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        col.sortable = true;
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        columns_.push_back(col);
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        tab_table_->AddColumn(col);
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
412a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)void TaskManagerView::ViewHierarchyChanged(
413a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    const ViewHierarchyChangedDetails& details) {
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Since we want the Kill button and the Memory Details link to show up in
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the same visual row as the close button, which is provided by the
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // framework, we must add the buttons to the non-client view, which is the
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // parent of this view. Similarly, when we're removed from the view
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // hierarchy, we must take care to clean up those items as well.
419a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  if (details.child == this) {
420a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if (details.is_add) {
421a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      details.parent->AddChildView(about_memory_link_);
422a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      details.parent->AddChildView(kill_button_);
4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      tab_table_parent_ = tab_table_->CreateParentIfNecessary();
4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      AddChildView(tab_table_parent_);
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    } else {
426a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      details.parent->RemoveChildView(kill_button_);
427a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      details.parent->RemoveChildView(about_memory_link_);
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::Layout() {
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Size size = kill_button_->GetPreferredSize();
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Rect parent_bounds = parent()->GetContentsBounds();
435868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  const int horizontal_margin = views::kPanelHorizMargin;
436868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  const int vertical_margin = views::kButtonVEdgeMargin;
437c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  int x = width() - size.width() - horizontal_margin;
438c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  int y_buttons = parent_bounds.bottom() - size.height() - vertical_margin;
4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  kill_button_->SetBounds(x, y_buttons, size.width(), size.height());
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size = about_memory_link_->GetPreferredSize();
442c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  about_memory_link_->SetBounds(
443c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      horizontal_margin,
4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      y_buttons + (kill_button_->height() - size.height()) / 2,
4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      size.width(), size.height());
4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Rect rect = GetLocalBounds();
448c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  rect.Inset(horizontal_margin, views::kPanelVertMargin);
4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  rect.Inset(0, 0, 0,
4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)             kill_button_->height() + views::kUnrelatedControlVerticalSpacing);
4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  tab_table_parent_->SetBoundsRect(rect);
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
454cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)gfx::Size TaskManagerView::GetPreferredSize() const {
4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return gfx::Size(460, 270);
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool TaskManagerView::AcceleratorPressed(const ui::Accelerator& accelerator) {
4595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK_EQ(ui::VKEY_W, accelerator.key_code());
4605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK_EQ(ui::EF_CONTROL_DOWN, accelerator.modifiers());
4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetWidget()->Close();
4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return true;
4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
466eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid TaskManagerView::Show(Browser* browser) {
4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // In ash we can come here through the ChromeShellDelegate. If there is no
4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // browser window at that time of the call, browser could be passed as NULL.
4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const chrome::HostDesktopType desktop_type =
4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      browser ? browser->host_desktop_type() : chrome::HOST_DESKTOP_TYPE_ASH;
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (instance_) {
473eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    // If there's a Task manager window open already, just activate it.
474eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    instance_->GetWidget()->Activate();
475eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
477eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  instance_ = new TaskManagerView(desktop_type);
4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::NativeWindow window =
4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      browser ? browser->window()->GetNativeWindow() : NULL;
4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(USE_ASH)
4812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!window)
4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    window = ash::wm::GetActiveWindow();
4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
484b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  DialogDelegate::CreateDialogWidget(instance_, window, NULL);
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  instance_->InitAlwaysOnTopState();
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  instance_->model_->StartUpdating();
487a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#if defined(OS_WIN)
488a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Set the app id for the task manager to the app id of its parent browser. If
489a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // no parent is specified, the app id will default to that of the initial
490a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // process.
491a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  if (browser) {
492a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    ui::win::SetAppIdForWindow(
493a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)        ShellIntegration::GetChromiumModelIdForProfile(
494a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)            browser->profile()->GetPath()),
495a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)        views::HWNDForWidget(instance_->GetWidget()));
496a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
497a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#endif
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  instance_->GetWidget()->Show();
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set the initial focus to the list of tasks.
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::FocusManager* focus_manager = instance_->GetFocusManager();
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (focus_manager)
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    focus_manager->SetFocusedView(instance_->tab_table_);
5045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(USE_ASH)
5061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  gfx::NativeWindow native_window = instance_->GetWidget()->GetNativeWindow();
5076d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  ash::SetShelfItemDetailsForDialogWindow(
5081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      native_window, IDR_ASH_SHELF_ICON_TASK_MANAGER, native_window->title());
5095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ButtonListener implementation.
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::ButtonPressed(
5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    views::Button* sender,
5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const ui::Event& event) {
516a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  typedef ui::ListSelectionModel::SelectedIndices SelectedIndices;
517a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DCHECK_EQ(kill_button_, sender);
518a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  SelectedIndices selection(tab_table_->selection_model().selected_indices());
519a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  for (SelectedIndices::const_reverse_iterator i = selection.rbegin();
520a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        i != selection.rend(); ++i) {
521a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    task_manager_->KillProcess(*i);
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// DialogDelegate implementation.
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool TaskManagerView::CanResize() const {
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool TaskManagerView::CanMaximize() const {
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool TaskManagerView::CanMinimize() const {
5351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return true;
5361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
5371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool TaskManagerView::ExecuteWindowsCommand(int command_id) {
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return false;
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::string16 TaskManagerView::GetWindowTitle() const {
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE);
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)std::string TaskManagerView::GetWindowName() const {
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return prefs::kTaskManagerWindowPlacement;
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int TaskManagerView::GetDialogButtons() const {
5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return ui::DIALOG_BUTTON_NONE;
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::WindowClosing() {
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Now that the window is closed, we can allow a new one to be opened.
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (WindowClosing comes in asynchronously from the call to Close() and we
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // may have already opened a new instance).
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (instance_ == this)
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    instance_ = NULL;
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  task_manager_->OnWindowClosed();
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
563868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)bool TaskManagerView::UseNewStyleForThisDialog() const {
564868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  return false;
565868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
566868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// views::TableViewObserver implementation.
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::OnSelectionChanged() {
5692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const ui::ListSelectionModel::SelectedIndices& selection(
5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      tab_table_->selection_model().selected_indices());
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool selection_contains_browser_process = false;
5722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  for (size_t i = 0; i < selection.size(); ++i) {
5732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if (task_manager_->IsBrowserProcess(selection[i])) {
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      selection_contains_browser_process = true;
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      break;
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  kill_button_->SetEnabled(!selection_contains_browser_process &&
5792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           !selection.empty());
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::OnDoubleClick() {
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ActivateFocusedTab();
5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::OnKeyDown(ui::KeyboardCode keycode) {
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (keycode == ui::VKEY_RETURN)
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ActivateFocusedTab();
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::LinkClicked(views::Link* source, int event_flags) {
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK_EQ(about_memory_link_, source);
5932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  task_manager_->OpenAboutMemory(desktop_type_);
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::ShowContextMenuForView(views::View* source,
5977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                             const gfx::Point& point,
5987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                             ui::MenuSourceType source_type) {
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateStatsCounters();
6002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ui::SimpleMenuModel menu_model(this);
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  for (std::vector<ui::TableColumn>::iterator i(columns_.begin());
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)       i != columns_.end(); ++i) {
6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    menu_model.AddCheckItem(i->id, l10n_util::GetStringUTF16(i->id));
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
605116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  menu_runner_.reset(
606116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      new views::MenuRunner(&menu_model, views::MenuRunner::CONTEXT_MENU));
6075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  if (menu_runner_->RunMenuAt(GetWidget(),
6085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                              NULL,
6095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                              gfx::Rect(point, gfx::Size()),
6105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                              views::MENU_ANCHOR_TOPLEFT,
611116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                              source_type) == views::MenuRunner::MENU_DELETED) {
6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return;
6135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  }
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool TaskManagerView::IsCommandIdChecked(int id) const {
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return tab_table_->IsColumnVisible(id);
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool TaskManagerView::IsCommandIdEnabled(int id) const {
6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return true;
6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool TaskManagerView::GetAcceleratorForCommandId(
6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int command_id,
6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ui::Accelerator* accelerator) {
6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return false;
6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TaskManagerView::ExecuteCommand(int id, int event_flags) {
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tab_table_->SetColumnVisibility(id, !tab_table_->IsColumnVisible(id));
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::InitAlwaysOnTopState() {
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  is_always_on_top_ = false;
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (GetSavedAlwaysOnTopState(&is_always_on_top_))
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GetWidget()->SetAlwaysOnTop(is_always_on_top_);
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TaskManagerView::ActivateFocusedTab() {
6412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const int active_row = tab_table_->selection_model().active();
6422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (active_row != -1)
6432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    task_manager_->ActivateProcess(active_row);
6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool TaskManagerView::GetSavedAlwaysOnTopState(bool* always_on_top) const {
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!g_browser_process->local_state())
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::DictionaryValue* dictionary =
6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      g_browser_process->local_state()->GetDictionary(GetWindowName().c_str());
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return dictionary &&
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      dictionary->GetBoolean("always_on_top", always_on_top) && always_on_top;
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chrome {
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Declared in browser_dialogs.h so others don't need to depend on our header.
661eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ShowTaskManager(Browser* browser) {
662eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  TaskManagerView::Show(browser);
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace chrome
666