Index: chrome/browser/ui/webui/chromeos/retail_mode_logout_dialog.cc |
diff --git a/chrome/browser/ui/webui/chromeos/retail_mode_logout_dialog.cc b/chrome/browser/ui/webui/chromeos/retail_mode_logout_dialog.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..458b9fd454cb097b04ccc98f8b603f215b912a09 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/chromeos/retail_mode_logout_dialog.cc |
@@ -0,0 +1,198 @@ |
+// 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/retail_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; |
flackr
2012/01/27 07:48:04
Avoid use of using.
rkc
2012/02/08 02:52:19
This is being used 216 times in just the chrome/br
|
+ |
+namespace { |
+ |
+RetailModeLogoutDialog* g_instance = NULL; |
+const int kRetailModeLogoutDialogWidth = 400; |
+const int kRetailModeLogoutDialogHeight = 120; |
Evan Stade
2012/01/27 06:54:46
document all these
rkc
2012/02/08 02:52:19
Done.
|
+ |
+} |
Evan Stade
2012/01/27 06:54:46
// namespace
rkc
2012/02/08 02:52:19
Done.
|
+ |
+namespace browser { |
+ |
+void ShowRetailModeLogoutDialog() { |
Evan Stade
2012/01/27 06:54:46
why is this here and not in retail_mode_screen_loc
rkc
2012/02/08 02:52:19
Seemed like a better fit since all the UI display
|
+ RetailModeLogoutDialog::ShowRetailModeLogoutDialog(); |
+} |
+ |
+void CloseRetailModeLogoutDialog() { |
+ RetailModeLogoutDialog::CloseRetailModeLogoutDialog(); |
+} |
+ |
+} // namespace browser |
+ |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// RetailModeLogoutDialogHandler |
+ |
+class RetailModeLogoutDialogHandler : public content::WebUIMessageHandler { |
+ public: |
+ explicit RetailModeLogoutDialogHandler() {} |
+ virtual void RegisterMessages() OVERRIDE; |
+ void CloseDialog(); |
+ |
+ private: |
+ void RequestRestart(const base::ListValue*); |
+ |
+ content::WebContents* contents_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(RetailModeLogoutDialogHandler); |
+}; |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// RetailModeLogoutDialog public static methods |
+ |
+void RetailModeLogoutDialog::ShowRetailModeLogoutDialog() { |
+ if (g_instance) |
+ return; |
+ g_instance = new RetailModeLogoutDialog(); |
+ g_instance->ShowDialog(); |
+} |
+ |
+void RetailModeLogoutDialog::CloseRetailModeLogoutDialog() { |
+ if (g_instance) |
+ g_instance->CloseDialog(); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// RetailModeLogoutDialog private methods |
+ |
+RetailModeLogoutDialog::RetailModeLogoutDialog() |
+ : contents_(NULL), handler_(NULL) { |
Evan Stade
2012/01/27 06:54:46
too many spaces of indent
rkc
2012/02/08 02:52:19
Done.
|
+} |
+ |
+RetailModeLogoutDialog::~RetailModeLogoutDialog() { |
+} |
+ |
+void RetailModeLogoutDialog::ShowDialog() { |
+ Browser* browser = BrowserList::GetLastActive(); |
+ DCHECK(browser); |
+ handler_ = new RetailModeLogoutDialogHandler(); |
+ browser->BrowserShowHtmlDialog(this, NULL, STYLE_GENERIC); |
+} |
+ |
+void RetailModeLogoutDialog::CloseDialog() { |
+ contents_ = NULL; |
+ handler_->CloseDialog(); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// Overridden from HtmlDialogUIDelegate |
+ui::ModalType RetailModeLogoutDialog::GetDialogModalType() const { |
+ return ui::MODAL_TYPE_WINDOW; |
+} |
+ |
+string16 RetailModeLogoutDialog::GetDialogTitle() const { |
+ return string16(); |
+} |
+ |
+GURL RetailModeLogoutDialog::GetDialogContentURL() const { |
+ return GURL(chrome::kChromeUIRetailModeLogoutDialogURL); |
+} |
+ |
+void RetailModeLogoutDialog::GetWebUIMessageHandlers( |
+ std::vector<WebUIMessageHandler*>* handlers) const { |
+ handlers->push_back(handler_); |
+} |
+ |
+void RetailModeLogoutDialog::GetDialogSize(gfx::Size* size) const { |
+ size->SetSize(kRetailModeLogoutDialogWidth, kRetailModeLogoutDialogHeight); |
+} |
+ |
+std::string RetailModeLogoutDialog::GetDialogArgs() const { |
+ return std::string(); |
+} |
+ |
+void RetailModeLogoutDialog::OnDialogClosed(const std::string& json_retval) { |
+ g_instance = NULL; |
+ delete this; |
+} |
+ |
+void RetailModeLogoutDialog::OnCloseContents(WebContents* source, |
+ bool* out_close_dialog) { |
+ NOTIMPLEMENTED(); |
+} |
+ |
+bool RetailModeLogoutDialog::ShouldShowDialogTitle() const { |
+ return false; |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// RetailModeLogoutDialogUI methods |
+ |
+RetailModeLogoutDialogUI::RetailModeLogoutDialogUI(content::WebUI* web_ui) |
+ : HtmlDialogUI(web_ui) { |
+ ChromeWebUIDataSource* source = |
+ new ChromeWebUIDataSource(chrome::kChromeUIRetailModeLogoutDialogHost); |
+ |
+ source->AddLocalizedString("title", IDS_RETAIL_MODE_LOGOUT_TITLE); |
+ source->AddLocalizedString("warning", IDS_RETAIL_MODE_LOGOUT_WARNING); |
+ |
+ source->set_json_path("strings.js"); |
+ |
+ source->add_resource_path("retail_mode_logout_dialog.js", |
+ IDR_RETAIL_MODE_LOGOUT_DIALOG_JS); |
+ source->add_resource_path("retail_mode_logout_dialog.css", |
+ IDR_RETAIL_MODE_LOGOUT_DIALOG_CSS); |
+ |
+ source->set_default_resource(IDR_RETAIL_MODE_LOGOUT_DIALOG_HTML); |
+ |
+ Profile* profile = Profile::FromWebUI(web_ui); |
+ profile->GetChromeURLDataManager()->AddDataSource(source); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// RetailModeLogoutDialogHandler methods |
+ |
+void RetailModeLogoutDialogHandler::RegisterMessages() { |
+ web_ui()->RegisterMessageCallback("requestRestart", |
+ base::Bind(&RetailModeLogoutDialogHandler::RequestRestart, |
+ base::Unretained(this))); |
+} |
+ |
+void RetailModeLogoutDialogHandler::CloseDialog() { |
+ static_cast<HtmlDialogUI*>(web_ui()->GetController())->CloseDialog(NULL); |
+} |
+ |
+void RetailModeLogoutDialogHandler::RequestRestart(const base::ListValue*) { |
+ chromeos::PowerManagerClient* power_manager = |
+ chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); |
+ |
+ power_manager->RequestRestart(); |
+} |