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/retail_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/public/browser/render_process_host.h" |
| 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/browser/web_ui_message_handler.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 { |
| 41 |
| 42 // Global singleton instance of our dialog class. |
| 43 RetailModeLogoutDialog* g_instance = NULL; |
| 44 // Height/Width of the logout dialog. |
| 45 const int kRetailModeLogoutDialogWidth = 400; |
| 46 const int kRetailModeLogoutDialogHeight = 120; |
| 47 |
| 48 } // namespace |
| 49 |
| 50 //////////////////////////////////////////////////////////////////////////////// |
| 51 // RetailModeLogoutDialogHandler |
| 52 |
| 53 class RetailModeLogoutDialogHandler : public content::WebUIMessageHandler { |
| 54 public: |
| 55 explicit RetailModeLogoutDialogHandler() {} |
| 56 virtual void RegisterMessages() OVERRIDE; |
| 57 void CloseDialog(); |
| 58 |
| 59 private: |
| 60 void RequestRestart(const base::ListValue*); |
| 61 |
| 62 content::WebContents* contents_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(RetailModeLogoutDialogHandler); |
| 65 }; |
| 66 |
| 67 //////////////////////////////////////////////////////////////////////////////// |
| 68 // RetailModeLogoutDialog public static methods |
| 69 |
| 70 void RetailModeLogoutDialog::ShowRetailModeLogoutDialog() { |
| 71 if (g_instance) |
| 72 return; |
| 73 g_instance = new RetailModeLogoutDialog(); |
| 74 g_instance->ShowDialog(); |
| 75 } |
| 76 |
| 77 void RetailModeLogoutDialog::CloseRetailModeLogoutDialog() { |
| 78 if (g_instance) |
| 79 g_instance->CloseDialog(); |
| 80 } |
| 81 |
| 82 //////////////////////////////////////////////////////////////////////////////// |
| 83 // RetailModeLogoutDialog private methods |
| 84 |
| 85 RetailModeLogoutDialog::RetailModeLogoutDialog() |
| 86 : contents_(NULL), handler_(NULL) { |
| 87 } |
| 88 |
| 89 RetailModeLogoutDialog::~RetailModeLogoutDialog() { |
| 90 } |
| 91 |
| 92 void RetailModeLogoutDialog::ShowDialog() { |
| 93 Browser* browser = BrowserList::GetLastActive(); |
| 94 DCHECK(browser); |
| 95 handler_ = new RetailModeLogoutDialogHandler(); |
| 96 browser->BrowserShowHtmlDialog(this, NULL, STYLE_GENERIC); |
| 97 } |
| 98 |
| 99 void RetailModeLogoutDialog::CloseDialog() { |
| 100 contents_ = NULL; |
| 101 handler_->CloseDialog(); |
| 102 } |
| 103 |
| 104 //////////////////////////////////////////////////////////////////////////////// |
| 105 // Overridden from HtmlDialogUIDelegate |
| 106 ui::ModalType RetailModeLogoutDialog::GetDialogModalType() const { |
| 107 return ui::MODAL_TYPE_WINDOW; |
| 108 } |
| 109 |
| 110 string16 RetailModeLogoutDialog::GetDialogTitle() const { |
| 111 return string16(); |
| 112 } |
| 113 |
| 114 GURL RetailModeLogoutDialog::GetDialogContentURL() const { |
| 115 return GURL(chrome::kChromeUIRetailModeLogoutDialogURL); |
| 116 } |
| 117 |
| 118 void RetailModeLogoutDialog::GetWebUIMessageHandlers( |
| 119 std::vector<WebUIMessageHandler*>* handlers) const { |
| 120 handlers->push_back(handler_); |
| 121 } |
| 122 |
| 123 void RetailModeLogoutDialog::GetDialogSize(gfx::Size* size) const { |
| 124 size->SetSize(kRetailModeLogoutDialogWidth, kRetailModeLogoutDialogHeight); |
| 125 } |
| 126 |
| 127 std::string RetailModeLogoutDialog::GetDialogArgs() const { |
| 128 return std::string(); |
| 129 } |
| 130 |
| 131 void RetailModeLogoutDialog::OnDialogClosed(const std::string& json_retval) { |
| 132 g_instance = NULL; |
| 133 delete this; |
| 134 } |
| 135 |
| 136 void RetailModeLogoutDialog::OnCloseContents(WebContents* source, |
| 137 bool* out_close_dialog) { |
| 138 NOTIMPLEMENTED(); |
| 139 } |
| 140 |
| 141 bool RetailModeLogoutDialog::ShouldShowDialogTitle() const { |
| 142 return false; |
| 143 } |
| 144 |
| 145 //////////////////////////////////////////////////////////////////////////////// |
| 146 // RetailModeLogoutDialogUI methods |
| 147 |
| 148 RetailModeLogoutDialogUI::RetailModeLogoutDialogUI(content::WebUI* web_ui) |
| 149 : HtmlDialogUI(web_ui) { |
| 150 ChromeWebUIDataSource* source = |
| 151 new ChromeWebUIDataSource(chrome::kChromeUIRetailModeLogoutDialogHost); |
| 152 |
| 153 source->AddLocalizedString("title", IDS_RETAIL_MODE_LOGOUT_TITLE); |
| 154 source->AddLocalizedString("warning", IDS_RETAIL_MODE_LOGOUT_WARNING); |
| 155 |
| 156 source->set_json_path("strings.js"); |
| 157 |
| 158 source->add_resource_path("retail_mode_logout_dialog.js", |
| 159 IDR_RETAIL_MODE_LOGOUT_DIALOG_JS); |
| 160 source->add_resource_path("retail_mode_logout_dialog.css", |
| 161 IDR_RETAIL_MODE_LOGOUT_DIALOG_CSS); |
| 162 |
| 163 source->set_default_resource(IDR_RETAIL_MODE_LOGOUT_DIALOG_HTML); |
| 164 |
| 165 Profile* profile = Profile::FromWebUI(web_ui); |
| 166 profile->GetChromeURLDataManager()->AddDataSource(source); |
| 167 } |
| 168 |
| 169 //////////////////////////////////////////////////////////////////////////////// |
| 170 // RetailModeLogoutDialogHandler methods |
| 171 |
| 172 void RetailModeLogoutDialogHandler::RegisterMessages() { |
| 173 web_ui()->RegisterMessageCallback("requestRestart", |
| 174 base::Bind(&RetailModeLogoutDialogHandler::RequestRestart, |
| 175 base::Unretained(this))); |
| 176 } |
| 177 |
| 178 void RetailModeLogoutDialogHandler::CloseDialog() { |
| 179 static_cast<HtmlDialogUI*>(web_ui()->GetController())->CloseDialog(NULL); |
| 180 } |
| 181 |
| 182 void RetailModeLogoutDialogHandler::RequestRestart(const base::ListValue*) { |
| 183 chromeos::PowerManagerClient* power_manager = |
| 184 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); |
| 185 |
| 186 power_manager->RequestRestart(); |
| 187 } |
OLD | NEW |