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