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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/platform_util.h" | 11 #include "chrome/browser/platform_util.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
11 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_dialogs.h" | 15 #include "chrome/browser/ui/browser_dialogs.h" |
13 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
14 #include "chrome/browser/ui/dialog_style.h" | 17 #include "chrome/browser/ui/dialog_style.h" |
15 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 18 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
| 19 #include "chrome/common/pref_names.h" |
16 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
17 #include "grit/google_chrome_strings.h" | 21 #include "grit/google_chrome_strings.h" |
18 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
19 | 23 |
20 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
21 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
22 #endif | 26 #endif |
23 | 27 |
24 using content::BrowserThread; | 28 using content::BrowserThread; |
25 | 29 |
(...skipping 24 matching lines...) Expand all Loading... |
50 url_string += "showclose=1&showtitle=1&"; | 54 url_string += "showclose=1&showtitle=1&"; |
51 #endif // defined(OS_CHROMEOS) | 55 #endif // defined(OS_CHROMEOS) |
52 if (is_background_page_mode_) | 56 if (is_background_page_mode_) |
53 url_string += "background=1"; | 57 url_string += "background=1"; |
54 return GURL(url_string); | 58 return GURL(url_string); |
55 } | 59 } |
56 virtual void GetWebUIMessageHandlers( | 60 virtual void GetWebUIMessageHandlers( |
57 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE { | 61 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE { |
58 } | 62 } |
59 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE { | 63 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE { |
| 64 // If dialog's bounds are previously saved, use them. |
| 65 if (g_browser_process->local_state()) { |
| 66 const DictionaryValue* placement_pref = |
| 67 g_browser_process->local_state()->GetDictionary( |
| 68 prefs::kTaskManagerWindowPlacement); |
| 69 int width, height; |
| 70 if (placement_pref && |
| 71 placement_pref->GetInteger("width", &width) && |
| 72 placement_pref->GetInteger("height", &height)) { |
| 73 size->SetSize(std::max(1, width), std::max(1, height)); |
| 74 return; |
| 75 } |
| 76 } |
| 77 |
| 78 // Otherwise set default size. |
60 size->SetSize(640, 480); | 79 size->SetSize(640, 480); |
61 } | 80 } |
62 virtual std::string GetDialogArgs() const OVERRIDE { | 81 virtual std::string GetDialogArgs() const OVERRIDE { |
63 return std::string(); | 82 return std::string(); |
64 } | 83 } |
65 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { | 84 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { |
66 OnCloseDialog(); | 85 OnCloseDialog(); |
67 } | 86 } |
68 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) | 87 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) |
69 OVERRIDE { | 88 OVERRIDE { |
70 *out_close_dialog = true; | 89 *out_close_dialog = true; |
71 } | 90 } |
72 virtual bool ShouldShowDialogTitle() const OVERRIDE { | 91 virtual bool ShouldShowDialogTitle() const OVERRIDE { |
73 return false; | 92 return false; |
74 } | 93 } |
75 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE { | 94 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE { |
76 return true; | 95 return true; |
77 } | 96 } |
| 97 virtual void StoreDialogSize(const gfx::Rect dialog_bounds) OVERRIDE { |
| 98 // Store the dialog's bounds so that it can be restored with the same bounds |
| 99 // the next time it's opened. |
| 100 if (g_browser_process->local_state()) { |
| 101 DictionaryPrefUpdate update(g_browser_process->local_state(), |
| 102 prefs::kTaskManagerWindowPlacement); |
| 103 DictionaryValue* placement_pref = update.Get(); |
| 104 placement_pref->SetInteger("width", dialog_bounds.width()); |
| 105 placement_pref->SetInteger("height", dialog_bounds.height()); |
| 106 } |
| 107 } |
78 | 108 |
79 private: | 109 private: |
80 void ShowDialog(bool is_background_page_mode); | 110 void ShowDialog(bool is_background_page_mode); |
81 void OpenHtmlDialog(); | 111 void OpenHtmlDialog(); |
82 | 112 |
83 int show_count_; | 113 int show_count_; |
84 | 114 |
85 gfx::NativeWindow window_; | 115 gfx::NativeWindow window_; |
86 bool is_background_page_mode_; | 116 bool is_background_page_mode_; |
87 | 117 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 BrowserThread::UI, FROM_HERE, | 177 BrowserThread::UI, FROM_HERE, |
148 base::Bind(&TaskManagerDialogImpl::Show, false)); | 178 base::Bind(&TaskManagerDialogImpl::Show, false)); |
149 } | 179 } |
150 | 180 |
151 // static | 181 // static |
152 void TaskManagerDialog::ShowBackgroundPages() { | 182 void TaskManagerDialog::ShowBackgroundPages() { |
153 BrowserThread::PostTask( | 183 BrowserThread::PostTask( |
154 BrowserThread::UI, FROM_HERE, | 184 BrowserThread::UI, FROM_HERE, |
155 base::Bind(&TaskManagerDialogImpl::Show, true)); | 185 base::Bind(&TaskManagerDialogImpl::Show, true)); |
156 } | 186 } |
OLD | NEW |