Chromium Code Reviews| 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_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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "grit/google_chrome_strings.h" | 25 #include "grit/google_chrome_strings.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 | 27 |
| 28 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
| 29 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 namespace { | |
| 33 | |
| 34 // The minimum size of task manager window in px. | |
| 35 const int kMinimumTaskManagerWidth = 640; | |
| 36 const int kMinimumTaskManagerHeight = 480; | |
| 37 } // namespace | |
|
James Hawkins
2012/03/18 03:00:04
nit: Blank line before the brace (to match the top
| |
| 38 | |
| 32 using content::BrowserThread; | 39 using content::BrowserThread; |
| 33 using content::WebContents; | 40 using content::WebContents; |
| 34 using content::WebUIMessageHandler; | 41 using content::WebUIMessageHandler; |
| 35 | 42 |
| 36 class TaskManagerDialogImpl : public HtmlDialogUIDelegate { | 43 class TaskManagerDialogImpl : public HtmlDialogUIDelegate { |
| 37 public: | 44 public: |
| 38 TaskManagerDialogImpl(); | 45 TaskManagerDialogImpl(); |
| 39 | 46 |
| 40 static void Show(bool is_background_page_mode); | 47 static void Show(bool is_background_page_mode); |
| 41 static TaskManagerDialogImpl* GetInstance(); | 48 static TaskManagerDialogImpl* GetInstance(); |
| 42 | 49 |
| 43 protected: | 50 protected: |
| 44 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; | 51 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; |
| 45 virtual ~TaskManagerDialogImpl(); | 52 virtual ~TaskManagerDialogImpl(); |
| 46 | 53 |
| 47 void OnCloseDialog(); | 54 void OnCloseDialog(); |
| 48 | 55 |
| 49 // Overridden from HtmlDialogUIDelegate: | 56 // Overridden from HtmlDialogUIDelegate: |
| 50 virtual ui::ModalType GetDialogModalType() const OVERRIDE { | 57 virtual ui::ModalType GetDialogModalType() const OVERRIDE { |
| 51 return ui::MODAL_TYPE_NONE; | 58 return ui::MODAL_TYPE_NONE; |
| 52 } | 59 } |
| 53 virtual string16 GetDialogTitle() const OVERRIDE { | 60 virtual string16 GetDialogTitle() const OVERRIDE { |
| 54 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE); | 61 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE); |
| 55 } | 62 } |
| 63 virtual std::string GetDialogName() const OVERRIDE { | |
| 64 return prefs::kTaskManagerWindowPlacement; | |
| 65 } | |
| 56 virtual GURL GetDialogContentURL() const OVERRIDE { | 66 virtual GURL GetDialogContentURL() const OVERRIDE { |
| 57 std::string url_string(chrome::kChromeUITaskManagerURL); | 67 std::string url_string(chrome::kChromeUITaskManagerURL); |
| 58 url_string += "?"; | 68 url_string += "?"; |
| 59 if (browser_defaults::kShowCancelButtonInTaskManager) | 69 if (browser_defaults::kShowCancelButtonInTaskManager) |
| 60 url_string += "showclose=1&"; | 70 url_string += "showclose=1&"; |
| 61 if (browser_defaults::kShowHtmlTitleBarInTaskManager) | 71 if (browser_defaults::kShowHtmlTitleBarInTaskManager) |
| 62 url_string += "showtitle=1&"; | 72 url_string += "showtitle=1&"; |
| 63 if (is_background_page_mode_) | 73 if (is_background_page_mode_) |
| 64 url_string += "background=1"; | 74 url_string += "background=1"; |
| 65 return GURL(url_string); | 75 return GURL(url_string); |
| 66 } | 76 } |
| 67 virtual void GetWebUIMessageHandlers( | 77 virtual void GetWebUIMessageHandlers( |
| 68 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE { | 78 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE { |
| 69 } | 79 } |
| 70 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE { | 80 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE { |
| 81 #if !defined(TOOLKIT_VIEWS) | |
| 71 // If dialog's bounds are previously saved, use them. | 82 // If dialog's bounds are previously saved, use them. |
| 72 if (g_browser_process->local_state()) { | 83 if (g_browser_process->local_state()) { |
| 73 const DictionaryValue* placement_pref = | 84 const DictionaryValue* placement_pref = |
| 74 g_browser_process->local_state()->GetDictionary( | 85 g_browser_process->local_state()->GetDictionary( |
| 75 prefs::kTaskManagerWindowPlacement); | 86 prefs::kTaskManagerWindowPlacement); |
| 76 int width, height; | 87 int width, height; |
| 77 if (placement_pref && | 88 if (placement_pref && |
| 78 placement_pref->GetInteger("width", &width) && | 89 placement_pref->GetInteger("width", &width) && |
| 79 placement_pref->GetInteger("height", &height)) { | 90 placement_pref->GetInteger("height", &height)) { |
| 80 size->SetSize(std::max(1, width), std::max(1, height)); | 91 size->SetSize(std::max(1, width), std::max(1, height)); |
| 81 return; | 92 return; |
| 82 } | 93 } |
| 83 } | 94 } |
| 84 | 95 |
| 85 // Otherwise set default size. | 96 // Otherwise set default size. |
| 86 size->SetSize(640, 480); | 97 size->SetSize(kMimimumTaskManagerWidth, kMinimumTaskManagerHeight); |
| 98 #endif | |
| 99 } | |
| 100 virtual void GetMinimumDialogSize(gfx::Size* size) const OVERRIDE { | |
| 101 size->SetSize(kMinimumTaskManagerWidth, kMinimumTaskManagerHeight); | |
| 87 } | 102 } |
| 88 virtual std::string GetDialogArgs() const OVERRIDE { | 103 virtual std::string GetDialogArgs() const OVERRIDE { |
| 89 return std::string(); | 104 return std::string(); |
| 90 } | 105 } |
| 91 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { | 106 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { |
| 92 OnCloseDialog(); | 107 OnCloseDialog(); |
| 93 } | 108 } |
| 94 virtual void OnCloseContents(WebContents* source, bool* out_close_dialog) | 109 virtual void OnCloseContents(WebContents* source, bool* out_close_dialog) |
| 95 OVERRIDE { | 110 OVERRIDE { |
| 96 *out_close_dialog = true; | 111 *out_close_dialog = true; |
| 97 } | 112 } |
| 98 virtual bool ShouldShowDialogTitle() const OVERRIDE { | 113 virtual bool ShouldShowDialogTitle() const OVERRIDE { |
| 99 return false; | 114 return false; |
| 100 } | 115 } |
| 101 virtual bool HandleContextMenu( | 116 virtual bool HandleContextMenu( |
| 102 const content::ContextMenuParams& params) OVERRIDE { | 117 const content::ContextMenuParams& params) OVERRIDE { |
| 103 return true; | 118 return true; |
| 104 } | 119 } |
| 120 #if !defined(TOOLKIT_VIEWS) | |
| 105 virtual void StoreDialogSize(const gfx::Size& dialog_size) OVERRIDE { | 121 virtual void StoreDialogSize(const gfx::Size& dialog_size) OVERRIDE { |
| 106 // Store the dialog's bounds so that it can be restored with the same bounds | 122 // Store the dialog's bounds so that it can be restored with the same bounds |
| 107 // the next time it's opened. | 123 // the next time it's opened. |
| 108 if (g_browser_process->local_state()) { | 124 if (g_browser_process->local_state()) { |
| 109 DictionaryPrefUpdate update(g_browser_process->local_state(), | 125 DictionaryPrefUpdate update(g_browser_process->local_state(), |
| 110 prefs::kTaskManagerWindowPlacement); | 126 prefs::kTaskManagerWindowPlacement); |
| 111 DictionaryValue* placement_pref = update.Get(); | 127 DictionaryValue* placement_pref = update.Get(); |
| 112 placement_pref->SetInteger("width", dialog_size.width()); | 128 placement_pref->SetInteger("width", dialog_size.width()); |
| 113 placement_pref->SetInteger("height", dialog_size.height()); | 129 placement_pref->SetInteger("height", dialog_size.height()); |
| 114 } | 130 } |
| 115 } | 131 } |
| 132 #endif | |
| 116 | 133 |
| 117 private: | 134 private: |
| 118 void ShowDialog(bool is_background_page_mode); | 135 void ShowDialog(bool is_background_page_mode); |
| 119 void OpenHtmlDialog(); | 136 void OpenHtmlDialog(); |
| 120 | 137 |
| 121 int show_count_; | 138 int show_count_; |
| 122 | 139 |
| 123 gfx::NativeWindow window_; | 140 gfx::NativeWindow window_; |
| 124 bool is_background_page_mode_; | 141 bool is_background_page_mode_; |
| 125 | 142 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 BrowserThread::PostTask( | 213 BrowserThread::PostTask( |
| 197 BrowserThread::UI, FROM_HERE, | 214 BrowserThread::UI, FROM_HERE, |
| 198 base::Bind(&TaskManagerDialogImpl::Show, true)); | 215 base::Bind(&TaskManagerDialogImpl::Show, true)); |
| 199 } | 216 } |
| 200 | 217 |
| 201 // static | 218 // static |
| 202 bool TaskManagerDialog::UseWebUITaskManager() { | 219 bool TaskManagerDialog::UseWebUITaskManager() { |
| 203 return CommandLine::ForCurrentProcess()->HasSwitch( | 220 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 204 switches::kWebUITaskManager); | 221 switches::kWebUITaskManager); |
| 205 } | 222 } |
| OLD | NEW |