OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/task_manager_dialog.h" | 5 #include "chrome/browser/ui/webui/task_manager/task_manager_dialog.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/defaults.h" | 16 #include "chrome/browser/defaults.h" |
17 #include "chrome/browser/platform_util.h" | 17 #include "chrome/browser/platform_util.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/browser_dialogs.h" | 22 #include "chrome/browser/ui/browser_dialogs.h" |
23 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
24 #include "chrome/browser/ui/dialog_style.h" | 24 #include "chrome/browser/ui/dialog_style.h" |
25 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 25 #include "chrome/browser/ui/webui/web_dialog_ui.h" |
26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
29 #include "grit/google_chrome_strings.h" | 29 #include "grit/google_chrome_strings.h" |
30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
31 | 31 |
32 #if defined(OS_CHROMEOS) | 32 #if defined(OS_CHROMEOS) |
33 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
34 #endif | 34 #endif |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 // The minimum size of task manager window in px. | 38 // The minimum size of task manager window in px. |
39 const int kMinimumTaskManagerWidth = 640; | 39 const int kMinimumTaskManagerWidth = 640; |
40 const int kMinimumTaskManagerHeight = 480; | 40 const int kMinimumTaskManagerHeight = 480; |
41 | 41 |
42 } // namespace | 42 } // namespace |
43 | 43 |
44 using content::BrowserThread; | 44 using content::BrowserThread; |
45 using content::WebContents; | 45 using content::WebContents; |
46 using content::WebUIMessageHandler; | 46 using content::WebUIMessageHandler; |
47 | 47 |
48 class TaskManagerDialogImpl : public HtmlDialogUIDelegate { | 48 class TaskManagerDialogImpl : public WebDialogDelegate { |
49 public: | 49 public: |
50 TaskManagerDialogImpl(); | 50 TaskManagerDialogImpl(); |
51 | 51 |
52 static void Show(bool is_background_page_mode); | 52 static void Show(bool is_background_page_mode); |
53 static TaskManagerDialogImpl* GetInstance(); | 53 static TaskManagerDialogImpl* GetInstance(); |
54 | 54 |
55 protected: | 55 protected: |
56 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; | 56 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; |
57 virtual ~TaskManagerDialogImpl(); | 57 virtual ~TaskManagerDialogImpl(); |
58 | 58 |
59 void OnCloseDialog(); | 59 void OnCloseDialog(); |
60 | 60 |
61 // Overridden from HtmlDialogUIDelegate: | 61 // Overridden from WebDialogDelegate: |
62 virtual ui::ModalType GetDialogModalType() const OVERRIDE { | 62 virtual ui::ModalType GetDialogModalType() const OVERRIDE { |
63 return ui::MODAL_TYPE_NONE; | 63 return ui::MODAL_TYPE_NONE; |
64 } | 64 } |
65 virtual string16 GetDialogTitle() const OVERRIDE { | 65 virtual string16 GetDialogTitle() const OVERRIDE { |
66 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE); | 66 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE); |
67 } | 67 } |
68 virtual std::string GetDialogName() const OVERRIDE { | 68 virtual std::string GetDialogName() const OVERRIDE { |
69 return prefs::kTaskManagerWindowPlacement; | 69 return prefs::kTaskManagerWindowPlacement; |
70 } | 70 } |
71 virtual GURL GetDialogContentURL() const OVERRIDE { | 71 virtual GURL GetDialogContentURL() const OVERRIDE { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 prefs::kTaskManagerWindowPlacement); | 129 prefs::kTaskManagerWindowPlacement); |
130 DictionaryValue* placement_pref = update.Get(); | 130 DictionaryValue* placement_pref = update.Get(); |
131 placement_pref->SetInteger("width", dialog_size.width()); | 131 placement_pref->SetInteger("width", dialog_size.width()); |
132 placement_pref->SetInteger("height", dialog_size.height()); | 132 placement_pref->SetInteger("height", dialog_size.height()); |
133 } | 133 } |
134 } | 134 } |
135 #endif | 135 #endif |
136 | 136 |
137 private: | 137 private: |
138 void ShowDialog(bool is_background_page_mode); | 138 void ShowDialog(bool is_background_page_mode); |
139 void OpenHtmlDialog(); | 139 void OpenWebDialog(); |
140 | 140 |
141 int show_count_; | 141 int show_count_; |
142 | 142 |
143 gfx::NativeWindow window_; | 143 gfx::NativeWindow window_; |
144 bool is_background_page_mode_; | 144 bool is_background_page_mode_; |
145 | 145 |
146 DISALLOW_COPY_AND_ASSIGN(TaskManagerDialogImpl); | 146 DISALLOW_COPY_AND_ASSIGN(TaskManagerDialogImpl); |
147 }; | 147 }; |
148 | 148 |
149 // **************************************************** | 149 // **************************************************** |
(...skipping 26 matching lines...) Expand all Loading... |
176 #if defined(OS_CHROMEOS) | 176 #if defined(OS_CHROMEOS) |
177 // Closes current TaskManager and Opens new one. | 177 // Closes current TaskManager and Opens new one. |
178 views::Widget::GetWidgetForNativeWindow(window_)->Close(); | 178 views::Widget::GetWidgetForNativeWindow(window_)->Close(); |
179 #else | 179 #else |
180 // TODO(yoshiki): Supports the other platforms. | 180 // TODO(yoshiki): Supports the other platforms. |
181 platform_util::ActivateWindow(window_); | 181 platform_util::ActivateWindow(window_); |
182 return; | 182 return; |
183 #endif | 183 #endif |
184 } | 184 } |
185 is_background_page_mode_ = is_background_page_mode; | 185 is_background_page_mode_ = is_background_page_mode; |
186 OpenHtmlDialog(); | 186 OpenWebDialog(); |
187 ++show_count_; | 187 ++show_count_; |
188 } | 188 } |
189 | 189 |
190 void TaskManagerDialogImpl::OnCloseDialog() { | 190 void TaskManagerDialogImpl::OnCloseDialog() { |
191 if (show_count_ > 0) | 191 if (show_count_ > 0) |
192 --show_count_; | 192 --show_count_; |
193 } | 193 } |
194 | 194 |
195 void TaskManagerDialogImpl::OpenHtmlDialog() { | 195 void TaskManagerDialogImpl::OpenWebDialog() { |
196 Browser* browser = BrowserList::GetLastActive(); | 196 Browser* browser = BrowserList::GetLastActive(); |
197 DCHECK(browser); | 197 DCHECK(browser); |
198 window_ = browser::ShowHtmlDialog(NULL, | 198 window_ = browser::ShowWebDialog(NULL, |
199 browser->profile()->GetOriginalProfile(), | 199 browser->profile()->GetOriginalProfile(), |
200 NULL, | 200 NULL, |
201 this, | 201 this, |
202 STYLE_GENERIC); | 202 STYLE_GENERIC); |
203 } | 203 } |
204 | 204 |
205 // **************************************************** | 205 // **************************************************** |
206 // | 206 // |
207 // static | 207 // static |
208 void TaskManagerDialog::Show() { | 208 void TaskManagerDialog::Show() { |
209 BrowserThread::PostTask( | 209 BrowserThread::PostTask( |
210 BrowserThread::UI, FROM_HERE, | 210 BrowserThread::UI, FROM_HERE, |
211 base::Bind(&TaskManagerDialogImpl::Show, false)); | 211 base::Bind(&TaskManagerDialogImpl::Show, false)); |
212 } | 212 } |
213 | 213 |
214 // static | 214 // static |
215 void TaskManagerDialog::ShowBackgroundPages() { | 215 void TaskManagerDialog::ShowBackgroundPages() { |
216 BrowserThread::PostTask( | 216 BrowserThread::PostTask( |
217 BrowserThread::UI, FROM_HERE, | 217 BrowserThread::UI, FROM_HERE, |
218 base::Bind(&TaskManagerDialogImpl::Show, true)); | 218 base::Bind(&TaskManagerDialogImpl::Show, true)); |
219 } | 219 } |
220 | 220 |
221 // static | 221 // static |
222 bool TaskManagerDialog::UseWebUITaskManager() { | 222 bool TaskManagerDialog::UseWebUITaskManager() { |
223 return CommandLine::ForCurrentProcess()->HasSwitch( | 223 return CommandLine::ForCurrentProcess()->HasSwitch( |
224 switches::kWebUITaskManager); | 224 switches::kWebUITaskManager); |
225 } | 225 } |
OLD | NEW |