| 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/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/platform_util.h" |
| 9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_dialogs.h" |
| 10 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 11 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 13 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
| 12 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 13 #include "grit/google_chrome_strings.h" | 15 #include "grit/google_chrome_strings.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 15 | 17 |
| 18 #if defined(OS_CHROMEOS) |
| 19 #include "views/widget/widget.h" |
| 20 #endif |
| 21 |
| 16 class TaskManagerDialogImpl : public HtmlDialogUIDelegate { | 22 class TaskManagerDialogImpl : public HtmlDialogUIDelegate { |
| 17 public: | 23 public: |
| 18 TaskManagerDialogImpl(); | 24 TaskManagerDialogImpl(); |
| 19 | 25 |
| 20 static void Show(bool is_background_page_mode); | 26 static void Show(bool is_background_page_mode); |
| 21 static TaskManagerDialogImpl* GetInstance(); | 27 static TaskManagerDialogImpl* GetInstance(); |
| 22 | 28 |
| 23 protected: | 29 protected: |
| 24 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; | 30 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; |
| 25 virtual ~TaskManagerDialogImpl(); | 31 virtual ~TaskManagerDialogImpl(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 47 } | 53 } |
| 48 virtual std::string GetDialogArgs() const OVERRIDE { | 54 virtual std::string GetDialogArgs() const OVERRIDE { |
| 49 return std::string(); | 55 return std::string(); |
| 50 } | 56 } |
| 51 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { | 57 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { |
| 52 OnCloseDialog(); | 58 OnCloseDialog(); |
| 53 } | 59 } |
| 54 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) | 60 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) |
| 55 OVERRIDE { | 61 OVERRIDE { |
| 56 *out_close_dialog = true; | 62 *out_close_dialog = true; |
| 57 OnCloseDialog(); | |
| 58 } | 63 } |
| 59 virtual bool ShouldShowDialogTitle() const OVERRIDE { | 64 virtual bool ShouldShowDialogTitle() const OVERRIDE { |
| 60 return false; | 65 return false; |
| 61 } | 66 } |
| 62 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE { | 67 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE { |
| 63 return true; | 68 return true; |
| 64 } | 69 } |
| 65 | 70 |
| 66 private: | 71 private: |
| 67 void ShowDialog(bool is_background_page_mode); | 72 void ShowDialog(bool is_background_page_mode); |
| 68 void OpenHtmlDialog(); | 73 void OpenHtmlDialog(); |
| 69 | 74 |
| 70 bool is_shown_; | 75 int show_count_; |
| 76 |
| 77 gfx::NativeWindow window_; |
| 71 bool is_background_page_mode_; | 78 bool is_background_page_mode_; |
| 72 | 79 |
| 73 DISALLOW_COPY_AND_ASSIGN(TaskManagerDialogImpl); | 80 DISALLOW_COPY_AND_ASSIGN(TaskManagerDialogImpl); |
| 74 }; | 81 }; |
| 75 | 82 |
| 76 // **************************************************** | 83 // **************************************************** |
| 77 | 84 |
| 78 // static | 85 // static |
| 79 TaskManagerDialogImpl* TaskManagerDialogImpl::GetInstance() { | 86 TaskManagerDialogImpl* TaskManagerDialogImpl::GetInstance() { |
| 80 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 87 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 81 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 88 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 82 return Singleton<TaskManagerDialogImpl>::get(); | 89 return Singleton<TaskManagerDialogImpl>::get(); |
| 83 } | 90 } |
| 84 | 91 |
| 85 TaskManagerDialogImpl::TaskManagerDialogImpl() | 92 TaskManagerDialogImpl::TaskManagerDialogImpl() |
| 86 : is_shown_(false), is_background_page_mode_(false) { | 93 : show_count_(0), |
| 94 window_(NULL), |
| 95 is_background_page_mode_(false) { |
| 87 } | 96 } |
| 88 | 97 |
| 89 TaskManagerDialogImpl::~TaskManagerDialogImpl() { | 98 TaskManagerDialogImpl::~TaskManagerDialogImpl() { |
| 90 } | 99 } |
| 91 | 100 |
| 92 // static | 101 // static |
| 93 void TaskManagerDialogImpl::Show(bool is_background_page_mode) { | 102 void TaskManagerDialogImpl::Show(bool is_background_page_mode) { |
| 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 95 TaskManagerDialogImpl* dialog = TaskManagerDialogImpl::GetInstance(); | 104 TaskManagerDialogImpl* dialog = TaskManagerDialogImpl::GetInstance(); |
| 96 dialog->ShowDialog(is_background_page_mode); | 105 dialog->ShowDialog(is_background_page_mode); |
| 97 } | 106 } |
| 98 | 107 |
| 99 void TaskManagerDialogImpl::ShowDialog(bool is_background_page_mode) { | 108 void TaskManagerDialogImpl::ShowDialog(bool is_background_page_mode) { |
| 100 // TODO(yoshiki): Brings up existing UI when called with is_shown_ == TRUE | 109 if (show_count_ > 0) { |
| 101 if (!is_shown_) { | 110 #if defined(OS_CHROMEOS) |
| 102 is_shown_ = true; | 111 // Closes current TaskManager and Opens new one. |
| 103 is_background_page_mode_ = is_background_page_mode; | 112 views::Widget::GetWidgetForNativeWindow(window_)->Close(); |
| 104 OpenHtmlDialog(); | 113 #else |
| 114 // TODO(yoshiki): Supports the other platforms. |
| 115 platform_util::ActivateWindow(window_); |
| 116 return; |
| 117 #endif |
| 105 } | 118 } |
| 119 is_background_page_mode_ = is_background_page_mode; |
| 120 OpenHtmlDialog(); |
| 121 ++show_count_; |
| 106 } | 122 } |
| 107 | 123 |
| 108 void TaskManagerDialogImpl::OnCloseDialog() { | 124 void TaskManagerDialogImpl::OnCloseDialog() { |
| 109 if (is_shown_) | 125 if (show_count_ > 0) |
| 110 is_shown_ = false; | 126 --show_count_; |
| 111 } | 127 } |
| 112 | 128 |
| 113 void TaskManagerDialogImpl::OpenHtmlDialog() { | 129 void TaskManagerDialogImpl::OpenHtmlDialog() { |
| 114 Browser* browser = BrowserList::GetLastActive(); | 130 Browser* browser = BrowserList::GetLastActive(); |
| 115 browser->BrowserShowHtmlDialog(this, NULL); | 131 window_ = browser->BrowserShowHtmlDialog(this, NULL); |
| 116 } | 132 } |
| 117 | 133 |
| 118 // **************************************************** | 134 // **************************************************** |
| 119 // | 135 // |
| 120 // static | 136 // static |
| 121 void TaskManagerDialog::Show() { | 137 void TaskManagerDialog::Show() { |
| 122 BrowserThread::PostTask( | 138 BrowserThread::PostTask( |
| 123 BrowserThread::UI, FROM_HERE, | 139 BrowserThread::UI, FROM_HERE, |
| 124 NewRunnableFunction(&TaskManagerDialogImpl::Show, false)); | 140 NewRunnableFunction(&TaskManagerDialogImpl::Show, false)); |
| 125 } | 141 } |
| 126 | 142 |
| 127 // static | 143 // static |
| 128 void TaskManagerDialog::ShowBackgroundPages() { | 144 void TaskManagerDialog::ShowBackgroundPages() { |
| 129 BrowserThread::PostTask( | 145 BrowserThread::PostTask( |
| 130 BrowserThread::UI, FROM_HERE, | 146 BrowserThread::UI, FROM_HERE, |
| 131 NewRunnableFunction(&TaskManagerDialogImpl::Show, true)); | 147 NewRunnableFunction(&TaskManagerDialogImpl::Show, true)); |
| 132 } | 148 } |
| 133 | 149 |
| OLD | NEW |