Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: chrome/browser/ui/views/new_task_manager_view.cc

Issue 1722493002: Project Eraser: Kill chrome://memory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix chrome_browser_ui.gypi. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/new_task_manager_view.h" 5 #include "chrome/browser/ui/views/new_task_manager_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/profiles/profile_window.h" 12 #include "chrome/browser/profiles/profile_window.h"
13 #include "chrome/browser/task_management/task_manager_observer.h" 13 #include "chrome/browser/task_management/task_manager_observer.h"
14 #include "chrome/browser/ui/browser_navigator_params.h" 14 #include "chrome/browser/ui/browser_navigator_params.h"
15 #include "chrome/browser/ui/task_manager/task_manager_columns.h" 15 #include "chrome/browser/ui/task_manager/task_manager_columns.h"
16 #include "chrome/browser/ui/user_manager.h" 16 #include "chrome/browser/ui/user_manager.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "chrome/grit/chromium_strings.h" 19 #include "chrome/grit/chromium_strings.h"
20 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
21 #include "components/prefs/pref_service.h" 21 #include "components/prefs/pref_service.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/models/table_model_observer.h" 23 #include "ui/base/models/table_model_observer.h"
24 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
25 #include "ui/views/controls/link.h"
26 #include "ui/views/controls/table/table_view.h" 25 #include "ui/views/controls/table/table_view.h"
27 #include "ui/views/layout/layout_constants.h" 26 #include "ui/views/layout/layout_constants.h"
28 #include "ui/views/view.h" 27 #include "ui/views/view.h"
29 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
30 29
31 #if defined(USE_ASH) 30 #if defined(USE_ASH)
32 #include "ash/shelf/shelf_util.h" 31 #include "ash/shelf/shelf_util.h"
33 #include "ash/wm/window_util.h" 32 #include "ash/wm/window_util.h"
34 #include "grit/ash_resources.h" 33 #include "grit/ash_resources.h"
35 #endif // defined(USE_ASH) 34 #endif // defined(USE_ASH)
36 35
37 #if defined(OS_WIN) 36 #if defined(OS_WIN)
38 #include "chrome/browser/shell_integration.h" 37 #include "chrome/browser/shell_integration.h"
39 #include "ui/base/win/shell.h" 38 #include "ui/base/win/shell.h"
40 #include "ui/views/win/hwnd_util.h" 39 #include "ui/views/win/hwnd_util.h"
41 #endif // defined(OS_WIN) 40 #endif // defined(OS_WIN)
42 41
43 namespace task_management { 42 namespace task_management {
44 43
45 namespace { 44 namespace {
46 45
47 NewTaskManagerView* g_task_manager_view = nullptr; 46 NewTaskManagerView* g_task_manager_view = nullptr;
48 47
49 // Opens the "about:memory" for the "stats for nerds" link.
50 void OpenAboutMemory() {
51 Profile* profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
52 if (profile->IsGuestSession() &&
53 !g_browser_process->local_state()->GetBoolean(
54 prefs::kBrowserGuestModeEnabled)) {
55 UserManager::Show(base::FilePath(),
56 profiles::USER_MANAGER_NO_TUTORIAL,
57 profiles::USER_MANAGER_SELECT_PROFILE_CHROME_MEMORY);
58 return;
59 }
60
61 chrome::NavigateParams params(profile,
62 GURL(chrome::kChromeUIMemoryURL),
63 ui::PAGE_TRANSITION_LINK);
64 params.disposition = NEW_FOREGROUND_TAB;
65 chrome::Navigate(&params);
66 }
67
68 } // namespace 48 } // namespace
69 49
70 NewTaskManagerView::~NewTaskManagerView() { 50 NewTaskManagerView::~NewTaskManagerView() {
71 // Delete child views now, while our table model still exists. 51 // Delete child views now, while our table model still exists.
72 RemoveAllChildViews(true); 52 RemoveAllChildViews(true);
73 } 53 }
74 54
75 // static 55 // static
76 void NewTaskManagerView::Show(Browser* browser) { 56 void NewTaskManagerView::Show(Browser* browser) {
77 if (g_task_manager_view) { 57 if (g_task_manager_view) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 137
158 void NewTaskManagerView::Layout() { 138 void NewTaskManagerView::Layout() {
159 gfx::Size size = kill_button_->GetPreferredSize(); 139 gfx::Size size = kill_button_->GetPreferredSize();
160 gfx::Rect parent_bounds = parent()->GetContentsBounds(); 140 gfx::Rect parent_bounds = parent()->GetContentsBounds();
161 const int horizontal_margin = views::kPanelHorizMargin; 141 const int horizontal_margin = views::kPanelHorizMargin;
162 const int vertical_margin = views::kButtonVEdgeMargin; 142 const int vertical_margin = views::kButtonVEdgeMargin;
163 int x = width() - size.width() - horizontal_margin; 143 int x = width() - size.width() - horizontal_margin;
164 int y_buttons = parent_bounds.bottom() - size.height() - vertical_margin; 144 int y_buttons = parent_bounds.bottom() - size.height() - vertical_margin;
165 kill_button_->SetBounds(x, y_buttons, size.width(), size.height()); 145 kill_button_->SetBounds(x, y_buttons, size.width(), size.height());
166 146
167 size = about_memory_link_->GetPreferredSize();
168 about_memory_link_->SetBounds(
169 horizontal_margin,
170 y_buttons + (kill_button_->height() - size.height()) / 2,
171 size.width(), size.height());
172
173 gfx::Rect rect = GetLocalBounds(); 147 gfx::Rect rect = GetLocalBounds();
174 rect.Inset(horizontal_margin, views::kPanelVertMargin); 148 rect.Inset(horizontal_margin, views::kPanelVertMargin);
175 rect.Inset(0, 0, 0, 149 rect.Inset(0, 0, 0,
176 kill_button_->height() + views::kUnrelatedControlVerticalSpacing); 150 kill_button_->height() + views::kUnrelatedControlVerticalSpacing);
177 tab_table_parent_->SetBoundsRect(rect); 151 tab_table_parent_->SetBoundsRect(rect);
178 } 152 }
179 153
180 gfx::Size NewTaskManagerView::GetPreferredSize() const { 154 gfx::Size NewTaskManagerView::GetPreferredSize() const {
181 return gfx::Size(460, 270); 155 return gfx::Size(460, 270);
182 } 156 }
183 157
184 bool NewTaskManagerView::AcceleratorPressed( 158 bool NewTaskManagerView::AcceleratorPressed(
185 const ui::Accelerator& accelerator) { 159 const ui::Accelerator& accelerator) {
186 DCHECK_EQ(ui::VKEY_W, accelerator.key_code()); 160 DCHECK_EQ(ui::VKEY_W, accelerator.key_code());
187 DCHECK_EQ(ui::EF_CONTROL_DOWN, accelerator.modifiers()); 161 DCHECK_EQ(ui::EF_CONTROL_DOWN, accelerator.modifiers());
188 GetWidget()->Close(); 162 GetWidget()->Close();
189 return true; 163 return true;
190 } 164 }
191 165
192 void NewTaskManagerView::ViewHierarchyChanged( 166 void NewTaskManagerView::ViewHierarchyChanged(
193 const ViewHierarchyChangedDetails& details) { 167 const ViewHierarchyChangedDetails& details) {
194 views::DialogDelegateView::ViewHierarchyChanged(details); 168 views::DialogDelegateView::ViewHierarchyChanged(details);
195 // Since we want the Kill button and the Memory Details link to show up in 169 // Since we want the Kill button to show up in the same visual row as the
196 // the same visual row as the close button, which is provided by the 170 // close button, which is provided by the framework, we must add it to the
197 // framework, we must add the buttons to the non-client view, which is the 171 // non-client view, which is the parent of this view. Similarly, when we're
198 // parent of this view. Similarly, when we're removed from the view 172 // removed from the view hierarchy, we must take care to clean up that item.
199 // hierarchy, we must take care to clean up those items as well.
200 if (details.child == this) { 173 if (details.child == this) {
201 if (details.is_add) { 174 if (details.is_add) {
202 details.parent->AddChildView(about_memory_link_);
203 details.parent->AddChildView(kill_button_); 175 details.parent->AddChildView(kill_button_);
204 tab_table_parent_ = tab_table_->CreateParentIfNecessary(); 176 tab_table_parent_ = tab_table_->CreateParentIfNecessary();
205 AddChildView(tab_table_parent_); 177 AddChildView(tab_table_parent_);
206 } else { 178 } else {
207 details.parent->RemoveChildView(kill_button_); 179 details.parent->RemoveChildView(kill_button_);
208 details.parent->RemoveChildView(about_memory_link_);
209 } 180 }
210 } 181 }
211 } 182 }
212 183
213 void NewTaskManagerView::ButtonPressed(views::Button* sender, 184 void NewTaskManagerView::ButtonPressed(views::Button* sender,
214 const ui::Event& event) { 185 const ui::Event& event) {
215 DCHECK_EQ(kill_button_, sender); 186 DCHECK_EQ(kill_button_, sender);
216 187
217 using SelectedIndices = ui::ListSelectionModel::SelectedIndices; 188 using SelectedIndices = ui::ListSelectionModel::SelectedIndices;
218 SelectedIndices selection(tab_table_->selection_model().selected_indices()); 189 SelectedIndices selection(tab_table_->selection_model().selected_indices());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 260
290 void NewTaskManagerView::OnDoubleClick() { 261 void NewTaskManagerView::OnDoubleClick() {
291 ActivateFocusedTab(); 262 ActivateFocusedTab();
292 } 263 }
293 264
294 void NewTaskManagerView::OnKeyDown(ui::KeyboardCode keycode) { 265 void NewTaskManagerView::OnKeyDown(ui::KeyboardCode keycode) {
295 if (keycode == ui::VKEY_RETURN) 266 if (keycode == ui::VKEY_RETURN)
296 ActivateFocusedTab(); 267 ActivateFocusedTab();
297 } 268 }
298 269
299 void NewTaskManagerView::LinkClicked(views::Link* source, int event_flags) {
300 DCHECK_EQ(about_memory_link_, source);
301 OpenAboutMemory();
302 }
303
304 void NewTaskManagerView::ShowContextMenuForView( 270 void NewTaskManagerView::ShowContextMenuForView(
305 views::View* source, 271 views::View* source,
306 const gfx::Point& point, 272 const gfx::Point& point,
307 ui::MenuSourceType source_type) { 273 ui::MenuSourceType source_type) {
308 ui::SimpleMenuModel menu_model(this); 274 ui::SimpleMenuModel menu_model(this);
309 275
310 for (const auto& table_column : columns_) { 276 for (const auto& table_column : columns_) {
311 menu_model.AddCheckItem(table_column.id, 277 menu_model.AddCheckItem(table_column.id,
312 l10n_util::GetStringUTF16(table_column.id)); 278 l10n_util::GetStringUTF16(table_column.id));
313 } 279 }
(...skipping 23 matching lines...) Expand all
337 ui::Accelerator* accelerator) { 303 ui::Accelerator* accelerator) {
338 return false; 304 return false;
339 } 305 }
340 306
341 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) { 307 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) {
342 table_model_->ToggleColumnVisibility(id); 308 table_model_->ToggleColumnVisibility(id);
343 } 309 }
344 310
345 NewTaskManagerView::NewTaskManagerView() 311 NewTaskManagerView::NewTaskManagerView()
346 : kill_button_(nullptr), 312 : kill_button_(nullptr),
347 about_memory_link_(nullptr),
348 tab_table_(nullptr), 313 tab_table_(nullptr),
349 tab_table_parent_(nullptr), 314 tab_table_parent_(nullptr),
350 is_always_on_top_(false) { 315 is_always_on_top_(false) {
351 Init(); 316 Init();
352 } 317 }
353 318
354 // static 319 // static
355 NewTaskManagerView* NewTaskManagerView::GetInstanceForTests() { 320 NewTaskManagerView* NewTaskManagerView::GetInstanceForTests() {
356 return g_task_manager_view; 321 return g_task_manager_view;
357 } 322 }
(...skipping 21 matching lines...) Expand all
379 tab_table_->SetObserver(this); 344 tab_table_->SetObserver(this);
380 tab_table_->set_context_menu_controller(this); 345 tab_table_->set_context_menu_controller(this);
381 set_context_menu_controller(this); 346 set_context_menu_controller(this);
382 347
383 table_model_->RetrieveSavedColumnsSettingsAndUpdateTable(); 348 table_model_->RetrieveSavedColumnsSettingsAndUpdateTable();
384 349
385 kill_button_ = new views::LabelButton(this, 350 kill_button_ = new views::LabelButton(this,
386 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL)); 351 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL));
387 kill_button_->SetStyle(views::Button::STYLE_BUTTON); 352 kill_button_->SetStyle(views::Button::STYLE_BUTTON);
388 353
389 about_memory_link_ = new views::Link(
390 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK));
391 about_memory_link_->set_listener(this);
392
393 // Makes sure our state is consistent. 354 // Makes sure our state is consistent.
394 OnSelectionChanged(); 355 OnSelectionChanged();
395 356
396 AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN)); 357 AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN));
397 } 358 }
398 359
399 void NewTaskManagerView::InitAlwaysOnTopState() { 360 void NewTaskManagerView::InitAlwaysOnTopState() {
400 RetriveSavedAlwaysOnTopState(); 361 RetriveSavedAlwaysOnTopState();
401 GetWidget()->SetAlwaysOnTop(is_always_on_top_); 362 GetWidget()->SetAlwaysOnTop(is_always_on_top_);
402 } 363 }
(...skipping 10 matching lines...) Expand all
413 if (!g_browser_process->local_state()) 374 if (!g_browser_process->local_state())
414 return; 375 return;
415 376
416 const base::DictionaryValue* dictionary = 377 const base::DictionaryValue* dictionary =
417 g_browser_process->local_state()->GetDictionary(GetWindowName()); 378 g_browser_process->local_state()->GetDictionary(GetWindowName());
418 if (dictionary) 379 if (dictionary)
419 dictionary->GetBoolean("always_on_top", &is_always_on_top_); 380 dictionary->GetBoolean("always_on_top", &is_always_on_top_);
420 } 381 }
421 382
422 } // namespace task_management 383 } // namespace task_management
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/new_task_manager_view.h ('k') | chrome/browser/ui/views/task_manager_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698