OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/webui/task_manager_dialog.h" | 5 #include "chrome/browser/ui/webui/task_manager_dialog.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
11 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 11 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
13 #include "grit/google_chrome_strings.h" | 13 #include "grit/google_chrome_strings.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 | 15 |
16 class TaskManagerDialogImpl : public HtmlDialogUIDelegate { | 16 class TaskManagerDialogImpl : public HtmlDialogUIDelegate { |
17 public: | 17 public: |
18 TaskManagerDialogImpl(); | 18 TaskManagerDialogImpl(); |
19 | 19 |
20 static void Show(); | 20 static void Show(); |
21 static TaskManagerDialogImpl* GetInstance(); | 21 static TaskManagerDialogImpl* GetInstance(); |
22 | 22 |
| 23 void ShowDialog(); |
| 24 |
23 protected: | 25 protected: |
24 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; | 26 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; |
25 virtual ~TaskManagerDialogImpl(); | 27 virtual ~TaskManagerDialogImpl(); |
26 | 28 |
27 void OnCloseDialog(); | 29 void OnCloseDialog(); |
28 | 30 |
29 // Overridden from HtmlDialogUIDelegate: | 31 // Overridden from HtmlDialogUIDelegate: |
30 virtual bool IsDialogModal() const { | 32 virtual bool IsDialogModal() const { |
31 return false; | 33 return false; |
32 } | 34 } |
(...skipping 21 matching lines...) Expand all Loading... |
54 OnCloseDialog(); | 56 OnCloseDialog(); |
55 } | 57 } |
56 virtual bool ShouldShowDialogTitle() const { | 58 virtual bool ShouldShowDialogTitle() const { |
57 return false; | 59 return false; |
58 } | 60 } |
59 virtual bool HandleContextMenu(const ContextMenuParams& params) { | 61 virtual bool HandleContextMenu(const ContextMenuParams& params) { |
60 return true; | 62 return true; |
61 } | 63 } |
62 | 64 |
63 private: | 65 private: |
64 void ShowDialog(); | |
65 void OpenHtmlDialog(); | 66 void OpenHtmlDialog(); |
66 | 67 |
67 bool is_shown_; | 68 bool is_shown_; |
68 | 69 |
69 DISALLOW_COPY_AND_ASSIGN(TaskManagerDialogImpl); | 70 DISALLOW_COPY_AND_ASSIGN(TaskManagerDialogImpl); |
70 }; | 71 }; |
71 | 72 |
72 // **************************************************** | 73 // **************************************************** |
73 | 74 |
74 // static | 75 // static |
75 TaskManagerDialogImpl* TaskManagerDialogImpl::GetInstance() { | 76 TaskManagerDialogImpl* TaskManagerDialogImpl::GetInstance() { |
76 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 77 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
77 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 78 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
78 return Singleton<TaskManagerDialogImpl>::get(); | 79 return Singleton<TaskManagerDialogImpl>::get(); |
79 } | 80 } |
80 | 81 |
81 TaskManagerDialogImpl::TaskManagerDialogImpl() : is_shown_(false) { | 82 TaskManagerDialogImpl::TaskManagerDialogImpl() : is_shown_(false) { |
82 } | 83 } |
83 | 84 |
84 TaskManagerDialogImpl::~TaskManagerDialogImpl() { | 85 TaskManagerDialogImpl::~TaskManagerDialogImpl() { |
85 } | 86 } |
86 | 87 |
87 void TaskManagerDialogImpl::Show() { | |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
89 TaskManagerDialogImpl* dialog = TaskManagerDialogImpl::GetInstance(); | |
90 dialog->ShowDialog(); | |
91 } | |
92 | |
93 void TaskManagerDialogImpl::ShowDialog() { | 88 void TaskManagerDialogImpl::ShowDialog() { |
94 // TODO(yoshiki): Brings up existing UI when called with is_shown_ == TRUE | 89 // TODO(yoshiki): Brings up existing UI when called with is_shown_ == TRUE |
95 if (!is_shown_) { | 90 if (!is_shown_) { |
96 is_shown_ = true; | 91 is_shown_ = true; |
97 OpenHtmlDialog(); | 92 OpenHtmlDialog(); |
98 } | 93 } |
99 } | 94 } |
100 | 95 |
101 void TaskManagerDialogImpl::OnCloseDialog() { | 96 void TaskManagerDialogImpl::OnCloseDialog() { |
102 if (is_shown_) | 97 if (is_shown_) |
103 is_shown_ = false; | 98 is_shown_ = false; |
104 } | 99 } |
105 | 100 |
106 void TaskManagerDialogImpl::OpenHtmlDialog() { | 101 void TaskManagerDialogImpl::OpenHtmlDialog() { |
107 Browser* browser = BrowserList::GetLastActive(); | 102 Browser* browser = BrowserList::GetLastActive(); |
108 browser->BrowserShowHtmlDialog(this, NULL); | 103 browser->BrowserShowHtmlDialog(this, NULL); |
109 } | 104 } |
110 | 105 |
111 // **************************************************** | 106 // **************************************************** |
112 // | 107 // |
113 // static | 108 // static |
114 void TaskManagerDialog::Show() { | 109 void TaskManagerDialog::Show() { |
115 BrowserThread::PostTask( | 110 TaskManagerDialogImpl* dialog = TaskManagerDialogImpl::GetInstance(); |
116 BrowserThread::UI, FROM_HERE, | 111 dialog->ShowDialog(); |
117 NewRunnableFunction(&TaskManagerDialogImpl::Show)); | |
118 } | 112 } |
119 | 113 |
OLD | NEW |