Index: chrome/browser/ui/webui/chromeos/kiosk_mode_logout_dialog.cc |
diff --git a/chrome/browser/ui/webui/chromeos/kiosk_mode_logout_dialog.cc b/chrome/browser/ui/webui/chromeos/kiosk_mode_logout_dialog.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4891953709170b018b1f285c37ab1728d9797db4 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/chromeos/kiosk_mode_logout_dialog.cc |
@@ -0,0 +1,177 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/chromeos/kiosk_mode_logout_dialog.h" |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
+#include "base/json/json_reader.h" |
+#include "base/utf_string_conversions.h" |
+#include "base/values.h" |
+#include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
+#include "chrome/browser/chromeos/dbus/power_manager_client.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_list.h" |
+#include "chrome/browser/ui/browser_dialogs.h" |
+#include "chrome/browser/ui/dialog_style.h" |
+#include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
+#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
+#include "chrome/browser/ui/webui/html_dialog_ui.h" |
+#include "chrome/common/logging_chrome.h" |
+#include "chrome/common/url_constants.h" |
+#include "content/browser/renderer_host/render_view_host.h" |
+#include "content/browser/webui/web_ui.h" |
+#include "content/public/browser/render_process_host.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/common/result_codes.h" |
+#include "grit/browser_resources.h" |
+#include "grit/generated_resources.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+using content::WebContents; |
+using content::WebUIMessageHandler; |
+ |
+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.
|
+KioskModeLogoutDialog* g_instance = NULL; |
+const int kKioskModeLogoutDialogWidth = 400; |
+const int kKioskModeLogoutDialogHeight = 120; |
+} |
+ |
+namespace browser { |
+ |
+void ShowKioskModeLogoutDialog() { |
+ KioskModeLogoutDialog::ShowKioskModeLogoutDialog(); |
+} |
+ |
+void CloseKioskModeLogoutDialog() { |
+ KioskModeLogoutDialog::CloseKioskModeLogoutDialog(); |
+} |
+ |
+} // namespace browser |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// KioskModeLogoutDialog public static methods |
+ |
+void KioskModeLogoutDialog::ShowKioskModeLogoutDialog() { |
+ if (g_instance) |
+ return; |
+ g_instance = new KioskModeLogoutDialog(); |
+ g_instance->ShowDialog(); |
+} |
+ |
+void KioskModeLogoutDialog::CloseKioskModeLogoutDialog() { |
+ if (g_instance) |
+ g_instance->CloseDialog(); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// KioskModeLogoutDialog private methods |
+ |
+KioskModeLogoutDialog::KioskModeLogoutDialog() |
+ : contents_(NULL), handler_(NULL) { |
+} |
+ |
+KioskModeLogoutDialog::~KioskModeLogoutDialog() { |
+} |
+ |
+void KioskModeLogoutDialog::ShowDialog() { |
+ Browser* browser = BrowserList::GetLastActive(); |
+ DCHECK(browser); |
+ handler_ = new KioskModeLogoutDialogHandler(); |
+ browser->BrowserShowHtmlDialog(this, NULL, STYLE_GENERIC); |
+} |
+ |
+void KioskModeLogoutDialog::CloseDialog() { |
+ contents_ = NULL; |
+ handler_->CloseDialog(); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// Overridden from HtmlDialogUIDelegate |
+ui::ModalType KioskModeLogoutDialog::GetDialogModalType() const { |
+ return ui::MODAL_TYPE_WINDOW; |
+} |
+ |
+string16 KioskModeLogoutDialog::GetDialogTitle() const { |
+ return string16(); |
+} |
+ |
+GURL KioskModeLogoutDialog::GetDialogContentURL() const { |
+ return GURL(chrome::kChromeUIKioskModeLogoutDialogURL); |
+} |
+ |
+void KioskModeLogoutDialog::GetWebUIMessageHandlers( |
+ std::vector<WebUIMessageHandler*>* handlers) const { |
+ handlers->push_back(handler_); |
xiyuan
2012/01/20 18:23:44
nit: fix indent
rkc
2012/01/26 03:37:23
Done.
|
+} |
+ |
+void KioskModeLogoutDialog::GetDialogSize(gfx::Size* size) const { |
+ size->SetSize(kKioskModeLogoutDialogWidth, kKioskModeLogoutDialogHeight); |
+} |
+ |
+std::string KioskModeLogoutDialog::GetDialogArgs() const { |
+ return std::string(); |
+} |
+ |
+void KioskModeLogoutDialog::OnDialogClosed(const std::string& json_retval) { |
+ g_instance = NULL; |
+ delete this; |
+} |
+ |
+void KioskModeLogoutDialog::OnCloseContents(WebContents* source, |
+ 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.
|
+ NOTIMPLEMENTED(); |
+} |
+ |
+bool KioskModeLogoutDialog::ShouldShowDialogTitle() const { |
+ return false; |
+} |
+ |
+ |
flackr
2012/01/20 16:16:58
nit: Remove extra newline.
rkc
2012/01/26 03:37:23
Done.
|
+//////////////////////////////////////////////////////////////////////////////// |
+// KioskModeLogoutDialogHandler methods |
+ |
+void KioskModeLogoutDialogHandler::RegisterMessages() { |
+ web_ui()->RegisterMessageCallback("requestRestart", |
+ base::Bind(&KioskModeLogoutDialogHandler::RequestRestart, |
+ base::Unretained(this))); |
+} |
+ |
+void KioskModeLogoutDialogHandler::CloseDialog() { |
+ static_cast<HtmlDialogUI*>(web_ui()->GetController())->CloseDialog(NULL); |
+} |
+ |
+void KioskModeLogoutDialogHandler::RequestRestart(const base::ListValue*) { |
+ chromeos::PowerManagerClient* power_manager = |
+ chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); |
+ |
+ power_manager->RequestRestart(); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// KioskModeLogoutDialogUI methods |
+ |
+KioskModeLogoutDialogUI::KioskModeLogoutDialogUI(content::WebUI* web_ui) |
+ : HtmlDialogUI(web_ui) { |
+ ChromeWebUIDataSource* source = |
+ new ChromeWebUIDataSource(chrome::kChromeUIKioskModeLogoutDialogHost); |
+ |
+ source->AddLocalizedString("title", IDS_KIOSK_MODE_LOGOUT_TITLE); |
+ source->AddLocalizedString("warning", IDS_KIOSK_MODE_LOGOUT_WARNING); |
+ |
+ source->set_json_path("strings.js"); |
+ source->add_resource_path("kiosk_mode_logout_dialog.js", |
+ IDR_KIOSK_MODE_LOGOUT_DIALOG_JS); |
+ source->add_resource_path("kiosk_mode_logout_dialog.css", |
+ IDR_KIOSK_MODE_LOGOUT_DIALOG_CSS); |
+ source->set_default_resource(IDR_KIOSK_MODE_LOGOUT_DIALOG_HTML); |
+ |
+ Profile* profile = Profile::FromWebUI(web_ui); |
+ profile->GetChromeURLDataManager()->AddDataSource(source); |
+} |