Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/chromeos/kiosk_mode_logout_dialog.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/bind.h" | |
| 11 #include "base/bind_helpers.h" | |
| 12 #include "base/json/json_reader.h" | |
| 13 #include "base/utf_string_conversions.h" | |
| 14 #include "base/values.h" | |
| 15 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | |
| 16 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | |
| 17 #include "chrome/browser/profiles/profile.h" | |
| 18 #include "chrome/browser/ui/browser.h" | |
| 19 #include "chrome/browser/ui/browser_list.h" | |
| 20 #include "chrome/browser/ui/browser_dialogs.h" | |
| 21 #include "chrome/browser/ui/dialog_style.h" | |
| 22 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | |
| 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 24 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | |
| 25 #include "chrome/browser/ui/webui/html_dialog_ui.h" | |
| 26 #include "chrome/common/logging_chrome.h" | |
| 27 #include "chrome/common/url_constants.h" | |
| 28 #include "content/browser/renderer_host/render_view_host.h" | |
| 29 #include "content/browser/webui/web_ui.h" | |
| 30 #include "content/public/browser/render_process_host.h" | |
| 31 #include "content/public/browser/web_contents.h" | |
| 32 #include "content/public/common/result_codes.h" | |
| 33 #include "grit/browser_resources.h" | |
| 34 #include "grit/generated_resources.h" | |
| 35 #include "ui/base/l10n/l10n_util.h" | |
| 36 | |
| 37 using content::WebContents; | |
| 38 using content::WebUIMessageHandler; | |
| 39 | |
| 40 namespace { | |
|
xiyuan
2012/01/20 18:23:44
nit: insert blank lines before and after code bloc
rkc
2012/01/26 03:37:23
Done.
| |
| 41 KioskModeLogoutDialog* g_instance = NULL; | |
| 42 const int kKioskModeLogoutDialogWidth = 400; | |
| 43 const int kKioskModeLogoutDialogHeight = 120; | |
| 44 } | |
| 45 | |
| 46 namespace browser { | |
| 47 | |
| 48 void ShowKioskModeLogoutDialog() { | |
| 49 KioskModeLogoutDialog::ShowKioskModeLogoutDialog(); | |
| 50 } | |
| 51 | |
| 52 void CloseKioskModeLogoutDialog() { | |
| 53 KioskModeLogoutDialog::CloseKioskModeLogoutDialog(); | |
| 54 } | |
| 55 | |
| 56 } // namespace browser | |
| 57 | |
| 58 //////////////////////////////////////////////////////////////////////////////// | |
| 59 // KioskModeLogoutDialog public static methods | |
| 60 | |
| 61 void KioskModeLogoutDialog::ShowKioskModeLogoutDialog() { | |
| 62 if (g_instance) | |
| 63 return; | |
| 64 g_instance = new KioskModeLogoutDialog(); | |
| 65 g_instance->ShowDialog(); | |
| 66 } | |
| 67 | |
| 68 void KioskModeLogoutDialog::CloseKioskModeLogoutDialog() { | |
| 69 if (g_instance) | |
| 70 g_instance->CloseDialog(); | |
| 71 } | |
| 72 | |
| 73 //////////////////////////////////////////////////////////////////////////////// | |
| 74 // KioskModeLogoutDialog private methods | |
| 75 | |
| 76 KioskModeLogoutDialog::KioskModeLogoutDialog() | |
| 77 : contents_(NULL), handler_(NULL) { | |
| 78 } | |
| 79 | |
| 80 KioskModeLogoutDialog::~KioskModeLogoutDialog() { | |
| 81 } | |
| 82 | |
| 83 void KioskModeLogoutDialog::ShowDialog() { | |
| 84 Browser* browser = BrowserList::GetLastActive(); | |
| 85 DCHECK(browser); | |
| 86 handler_ = new KioskModeLogoutDialogHandler(); | |
| 87 browser->BrowserShowHtmlDialog(this, NULL, STYLE_GENERIC); | |
| 88 } | |
| 89 | |
| 90 void KioskModeLogoutDialog::CloseDialog() { | |
| 91 contents_ = NULL; | |
| 92 handler_->CloseDialog(); | |
| 93 } | |
| 94 | |
| 95 //////////////////////////////////////////////////////////////////////////////// | |
| 96 // Overridden from HtmlDialogUIDelegate | |
| 97 ui::ModalType KioskModeLogoutDialog::GetDialogModalType() const { | |
| 98 return ui::MODAL_TYPE_WINDOW; | |
| 99 } | |
| 100 | |
| 101 string16 KioskModeLogoutDialog::GetDialogTitle() const { | |
| 102 return string16(); | |
| 103 } | |
| 104 | |
| 105 GURL KioskModeLogoutDialog::GetDialogContentURL() const { | |
| 106 return GURL(chrome::kChromeUIKioskModeLogoutDialogURL); | |
| 107 } | |
| 108 | |
| 109 void KioskModeLogoutDialog::GetWebUIMessageHandlers( | |
| 110 std::vector<WebUIMessageHandler*>* handlers) const { | |
| 111 handlers->push_back(handler_); | |
|
xiyuan
2012/01/20 18:23:44
nit: fix indent
rkc
2012/01/26 03:37:23
Done.
| |
| 112 } | |
| 113 | |
| 114 void KioskModeLogoutDialog::GetDialogSize(gfx::Size* size) const { | |
| 115 size->SetSize(kKioskModeLogoutDialogWidth, kKioskModeLogoutDialogHeight); | |
| 116 } | |
| 117 | |
| 118 std::string KioskModeLogoutDialog::GetDialogArgs() const { | |
| 119 return std::string(); | |
| 120 } | |
| 121 | |
| 122 void KioskModeLogoutDialog::OnDialogClosed(const std::string& json_retval) { | |
| 123 g_instance = NULL; | |
| 124 delete this; | |
| 125 } | |
| 126 | |
| 127 void KioskModeLogoutDialog::OnCloseContents(WebContents* source, | |
| 128 bool* out_close_dialog) { | |
|
xiyuan
2012/01/20 18:23:44
nit: align with the first arg
rkc
2012/01/26 03:37:23
Done.
| |
| 129 NOTIMPLEMENTED(); | |
| 130 } | |
| 131 | |
| 132 bool KioskModeLogoutDialog::ShouldShowDialogTitle() const { | |
| 133 return false; | |
| 134 } | |
| 135 | |
| 136 | |
|
flackr
2012/01/20 16:16:58
nit: Remove extra newline.
rkc
2012/01/26 03:37:23
Done.
| |
| 137 //////////////////////////////////////////////////////////////////////////////// | |
| 138 // KioskModeLogoutDialogHandler methods | |
| 139 | |
| 140 void KioskModeLogoutDialogHandler::RegisterMessages() { | |
| 141 web_ui()->RegisterMessageCallback("requestRestart", | |
| 142 base::Bind(&KioskModeLogoutDialogHandler::RequestRestart, | |
| 143 base::Unretained(this))); | |
| 144 } | |
| 145 | |
| 146 void KioskModeLogoutDialogHandler::CloseDialog() { | |
| 147 static_cast<HtmlDialogUI*>(web_ui()->GetController())->CloseDialog(NULL); | |
| 148 } | |
| 149 | |
| 150 void KioskModeLogoutDialogHandler::RequestRestart(const base::ListValue*) { | |
| 151 chromeos::PowerManagerClient* power_manager = | |
| 152 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | |
| 153 | |
| 154 power_manager->RequestRestart(); | |
| 155 } | |
| 156 | |
| 157 //////////////////////////////////////////////////////////////////////////////// | |
| 158 // KioskModeLogoutDialogUI methods | |
| 159 | |
| 160 KioskModeLogoutDialogUI::KioskModeLogoutDialogUI(content::WebUI* web_ui) | |
| 161 : HtmlDialogUI(web_ui) { | |
| 162 ChromeWebUIDataSource* source = | |
| 163 new ChromeWebUIDataSource(chrome::kChromeUIKioskModeLogoutDialogHost); | |
| 164 | |
| 165 source->AddLocalizedString("title", IDS_KIOSK_MODE_LOGOUT_TITLE); | |
| 166 source->AddLocalizedString("warning", IDS_KIOSK_MODE_LOGOUT_WARNING); | |
| 167 | |
| 168 source->set_json_path("strings.js"); | |
| 169 source->add_resource_path("kiosk_mode_logout_dialog.js", | |
| 170 IDR_KIOSK_MODE_LOGOUT_DIALOG_JS); | |
| 171 source->add_resource_path("kiosk_mode_logout_dialog.css", | |
| 172 IDR_KIOSK_MODE_LOGOUT_DIALOG_CSS); | |
| 173 source->set_default_resource(IDR_KIOSK_MODE_LOGOUT_DIALOG_HTML); | |
| 174 | |
| 175 Profile* profile = Profile::FromWebUI(web_ui); | |
| 176 profile->GetChromeURLDataManager()->AddDataSource(source); | |
| 177 } | |
| OLD | NEW |