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