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