| 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(bool is_background_page_mode); |
| 21 static TaskManagerDialogImpl* GetInstance(); | 21 static TaskManagerDialogImpl* GetInstance(); |
| 22 | 22 |
| 23 protected: | 23 protected: |
| 24 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; | 24 friend struct DefaultSingletonTraits<TaskManagerDialogImpl>; |
| 25 virtual ~TaskManagerDialogImpl(); | 25 virtual ~TaskManagerDialogImpl(); |
| 26 | 26 |
| 27 void OnCloseDialog(); | 27 void OnCloseDialog(); |
| 28 | 28 |
| 29 // Overridden from HtmlDialogUIDelegate: | 29 // Overridden from HtmlDialogUIDelegate: |
| 30 virtual bool IsDialogModal() const OVERRIDE { | 30 virtual bool IsDialogModal() const OVERRIDE { |
| 31 return false; | 31 return false; |
| 32 } | 32 } |
| 33 virtual string16 GetDialogTitle() const OVERRIDE { | 33 virtual string16 GetDialogTitle() const OVERRIDE { |
| 34 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE); | 34 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE); |
| 35 } | 35 } |
| 36 virtual GURL GetDialogContentURL() const OVERRIDE { | 36 virtual GURL GetDialogContentURL() const OVERRIDE { |
| 37 std::string url_string(chrome::kChromeUITaskManagerURL); | 37 std::string url_string(chrome::kChromeUITaskManagerURL); |
| 38 if (is_background_page_mode_) |
| 39 url_string += "#bg"; |
| 38 return GURL(url_string); | 40 return GURL(url_string); |
| 39 } | 41 } |
| 40 virtual void GetWebUIMessageHandlers( | 42 virtual void GetWebUIMessageHandlers( |
| 41 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE { | 43 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE { |
| 42 } | 44 } |
| 43 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE { | 45 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE { |
| 44 size->SetSize(640, 480); | 46 size->SetSize(640, 480); |
| 45 } | 47 } |
| 46 virtual std::string GetDialogArgs() const OVERRIDE { | 48 virtual std::string GetDialogArgs() const OVERRIDE { |
| 47 return std::string(); | 49 return std::string(); |
| 48 } | 50 } |
| 49 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { | 51 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE { |
| 50 OnCloseDialog(); | 52 OnCloseDialog(); |
| 51 } | 53 } |
| 52 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) | 54 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) |
| 53 OVERRIDE { | 55 OVERRIDE { |
| 54 *out_close_dialog = true; | 56 *out_close_dialog = true; |
| 55 OnCloseDialog(); | 57 OnCloseDialog(); |
| 56 } | 58 } |
| 57 virtual bool ShouldShowDialogTitle() const OVERRIDE { | 59 virtual bool ShouldShowDialogTitle() const OVERRIDE { |
| 58 return false; | 60 return false; |
| 59 } | 61 } |
| 60 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE { | 62 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE { |
| 61 return true; | 63 return true; |
| 62 } | 64 } |
| 63 | 65 |
| 64 private: | 66 private: |
| 65 void ShowDialog(); | 67 void ShowDialog(bool is_background_page_mode); |
| 66 void OpenHtmlDialog(); | 68 void OpenHtmlDialog(); |
| 67 | 69 |
| 68 bool is_shown_; | 70 bool is_shown_; |
| 71 bool is_background_page_mode_; |
| 69 | 72 |
| 70 DISALLOW_COPY_AND_ASSIGN(TaskManagerDialogImpl); | 73 DISALLOW_COPY_AND_ASSIGN(TaskManagerDialogImpl); |
| 71 }; | 74 }; |
| 72 | 75 |
| 73 // **************************************************** | 76 // **************************************************** |
| 74 | 77 |
| 75 // static | 78 // static |
| 76 TaskManagerDialogImpl* TaskManagerDialogImpl::GetInstance() { | 79 TaskManagerDialogImpl* TaskManagerDialogImpl::GetInstance() { |
| 77 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 80 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 78 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 81 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 79 return Singleton<TaskManagerDialogImpl>::get(); | 82 return Singleton<TaskManagerDialogImpl>::get(); |
| 80 } | 83 } |
| 81 | 84 |
| 82 TaskManagerDialogImpl::TaskManagerDialogImpl() : is_shown_(false) { | 85 TaskManagerDialogImpl::TaskManagerDialogImpl() |
| 86 : is_shown_(false), is_background_page_mode_(false) { |
| 83 } | 87 } |
| 84 | 88 |
| 85 TaskManagerDialogImpl::~TaskManagerDialogImpl() { | 89 TaskManagerDialogImpl::~TaskManagerDialogImpl() { |
| 86 } | 90 } |
| 87 | 91 |
| 88 void TaskManagerDialogImpl::Show() { | 92 // static |
| 93 void TaskManagerDialogImpl::Show(bool is_background_page_mode) { |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 90 TaskManagerDialogImpl* dialog = TaskManagerDialogImpl::GetInstance(); | 95 TaskManagerDialogImpl* dialog = TaskManagerDialogImpl::GetInstance(); |
| 91 dialog->ShowDialog(); | 96 dialog->ShowDialog(is_background_page_mode); |
| 92 } | 97 } |
| 93 | 98 |
| 94 void TaskManagerDialogImpl::ShowDialog() { | 99 void TaskManagerDialogImpl::ShowDialog(bool is_background_page_mode) { |
| 95 // TODO(yoshiki): Brings up existing UI when called with is_shown_ == TRUE | 100 // TODO(yoshiki): Brings up existing UI when called with is_shown_ == TRUE |
| 96 if (!is_shown_) { | 101 if (!is_shown_) { |
| 97 is_shown_ = true; | 102 is_shown_ = true; |
| 103 is_background_page_mode_ = is_background_page_mode; |
| 98 OpenHtmlDialog(); | 104 OpenHtmlDialog(); |
| 99 } | 105 } |
| 100 } | 106 } |
| 101 | 107 |
| 102 void TaskManagerDialogImpl::OnCloseDialog() { | 108 void TaskManagerDialogImpl::OnCloseDialog() { |
| 103 if (is_shown_) | 109 if (is_shown_) |
| 104 is_shown_ = false; | 110 is_shown_ = false; |
| 105 } | 111 } |
| 106 | 112 |
| 107 void TaskManagerDialogImpl::OpenHtmlDialog() { | 113 void TaskManagerDialogImpl::OpenHtmlDialog() { |
| 108 Browser* browser = BrowserList::GetLastActive(); | 114 Browser* browser = BrowserList::GetLastActive(); |
| 109 browser->BrowserShowHtmlDialog(this, NULL); | 115 browser->BrowserShowHtmlDialog(this, NULL); |
| 110 } | 116 } |
| 111 | 117 |
| 112 // **************************************************** | 118 // **************************************************** |
| 113 // | 119 // |
| 114 // static | 120 // static |
| 115 void TaskManagerDialog::Show() { | 121 void TaskManagerDialog::Show() { |
| 116 BrowserThread::PostTask( | 122 BrowserThread::PostTask( |
| 117 BrowserThread::UI, FROM_HERE, | 123 BrowserThread::UI, FROM_HERE, |
| 118 NewRunnableFunction(&TaskManagerDialogImpl::Show)); | 124 NewRunnableFunction(&TaskManagerDialogImpl::Show, false)); |
| 119 } | 125 } |
| 120 | 126 |
| 127 // static |
| 128 void TaskManagerDialog::ShowBackgroundPages() { |
| 129 BrowserThread::PostTask( |
| 130 BrowserThread::UI, FROM_HERE, |
| 131 NewRunnableFunction(&TaskManagerDialogImpl::Show, true)); |
| 132 } |
| 133 |
| OLD | NEW |