| 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/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
| 11 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 11 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
| 12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "grit/google_chrome_strings.h" | 13 #include "grit/google_chrome_strings.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 | 15 |
| 16 class TaskManagerDialogImpl : public HtmlDialogUIDelegate { | 16 class TaskManagerDialogImpl : public HtmlDialogUIDelegate { |
| 17 public: | 17 public: |
| 18 TaskManagerDialogImpl(); | 18 TaskManagerDialogImpl(); |
| 19 | 19 |
| 20 static void Show(); | 20 static void Show(); |
| 21 static TaskManagerDialogImpl* GetInstance(); | 21 static TaskManagerDialogImpl* GetInstance(); |
| 22 | 22 |
| 23 void ShowDialog(); | |
| 24 | |
| 25 protected: | 23 protected: |
| 26 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; | 24 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; |
| 27 virtual ~TaskManagerDialogImpl(); | 25 virtual ~TaskManagerDialogImpl(); |
| 28 | 26 |
| 29 void OnCloseDialog(); | 27 void OnCloseDialog(); |
| 30 | 28 |
| 31 // Overridden from HtmlDialogUIDelegate: | 29 // Overridden from HtmlDialogUIDelegate: |
| 32 virtual bool IsDialogModal() const { | 30 virtual bool IsDialogModal() const { |
| 33 return false; | 31 return false; |
| 34 } | 32 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 56 OnCloseDialog(); | 54 OnCloseDialog(); |
| 57 } | 55 } |
| 58 virtual bool ShouldShowDialogTitle() const { | 56 virtual bool ShouldShowDialogTitle() const { |
| 59 return false; | 57 return false; |
| 60 } | 58 } |
| 61 virtual bool HandleContextMenu(const ContextMenuParams& params) { | 59 virtual bool HandleContextMenu(const ContextMenuParams& params) { |
| 62 return true; | 60 return true; |
| 63 } | 61 } |
| 64 | 62 |
| 65 private: | 63 private: |
| 64 void ShowDialog(); |
| 66 void OpenHtmlDialog(); | 65 void OpenHtmlDialog(); |
| 67 | 66 |
| 68 bool is_shown_; | 67 bool is_shown_; |
| 69 | 68 |
| 70 DISALLOW_COPY_AND_ASSIGN(TaskManagerDialogImpl); | 69 DISALLOW_COPY_AND_ASSIGN(TaskManagerDialogImpl); |
| 71 }; | 70 }; |
| 72 | 71 |
| 73 // **************************************************** | 72 // **************************************************** |
| 74 | 73 |
| 75 // static | 74 // static |
| 76 TaskManagerDialogImpl* TaskManagerDialogImpl::GetInstance() { | 75 TaskManagerDialogImpl* TaskManagerDialogImpl::GetInstance() { |
| 77 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 76 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 78 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 77 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 79 return Singleton<TaskManagerDialogImpl>::get(); | 78 return Singleton<TaskManagerDialogImpl>::get(); |
| 80 } | 79 } |
| 81 | 80 |
| 82 TaskManagerDialogImpl::TaskManagerDialogImpl() : is_shown_(false) { | 81 TaskManagerDialogImpl::TaskManagerDialogImpl() : is_shown_(false) { |
| 83 } | 82 } |
| 84 | 83 |
| 85 TaskManagerDialogImpl::~TaskManagerDialogImpl() { | 84 TaskManagerDialogImpl::~TaskManagerDialogImpl() { |
| 86 } | 85 } |
| 87 | 86 |
| 87 void TaskManagerDialogImpl::Show() { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 89 TaskManagerDialogImpl* dialog = TaskManagerDialogImpl::GetInstance(); |
| 90 dialog->ShowDialog(); |
| 91 } |
| 92 |
| 88 void TaskManagerDialogImpl::ShowDialog() { | 93 void TaskManagerDialogImpl::ShowDialog() { |
| 89 // TODO(yoshiki): Brings up existing UI when called with is_shown_ == TRUE | 94 // TODO(yoshiki): Brings up existing UI when called with is_shown_ == TRUE |
| 90 if (!is_shown_) { | 95 if (!is_shown_) { |
| 91 is_shown_ = true; | 96 is_shown_ = true; |
| 92 OpenHtmlDialog(); | 97 OpenHtmlDialog(); |
| 93 } | 98 } |
| 94 } | 99 } |
| 95 | 100 |
| 96 void TaskManagerDialogImpl::OnCloseDialog() { | 101 void TaskManagerDialogImpl::OnCloseDialog() { |
| 97 if (is_shown_) | 102 if (is_shown_) |
| 98 is_shown_ = false; | 103 is_shown_ = false; |
| 99 } | 104 } |
| 100 | 105 |
| 101 void TaskManagerDialogImpl::OpenHtmlDialog() { | 106 void TaskManagerDialogImpl::OpenHtmlDialog() { |
| 102 Browser* browser = BrowserList::GetLastActive(); | 107 Browser* browser = BrowserList::GetLastActive(); |
| 103 browser->BrowserShowHtmlDialog(this, NULL); | 108 browser->BrowserShowHtmlDialog(this, NULL); |
| 104 } | 109 } |
| 105 | 110 |
| 106 // **************************************************** | 111 // **************************************************** |
| 107 // | 112 // |
| 108 // static | 113 // static |
| 109 void TaskManagerDialog::Show() { | 114 void TaskManagerDialog::Show() { |
| 110 TaskManagerDialogImpl* dialog = TaskManagerDialogImpl::GetInstance(); | 115 BrowserThread::PostTask( |
| 111 dialog->ShowDialog(); | 116 BrowserThread::UI, FROM_HERE, |
| 117 NewRunnableFunction(&TaskManagerDialogImpl::Show)); |
| 112 } | 118 } |
| 113 | 119 |
| OLD | NEW |