Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/chromeos/login/eula_view.cc

Issue 8436002: [cros] Remove Views implementation for login/OOBE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/chromeos/login/eula_view.h"
6
7 #include <signal.h>
8 #include <sys/types.h>
9
10 #include <string>
11
12 #include "base/basictypes.h"
13 #include "base/message_loop.h"
14 #include "base/task.h"
15 #include "base/utf_string_conversions.h"
16 #include "base/values.h"
17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/chromeos/cros/cros_library.h"
19 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
20 #include "chrome/browser/chromeos/login/background_view.h"
21 #include "chrome/browser/chromeos/login/help_app_launcher.h"
22 #include "chrome/browser/chromeos/login/helper.h"
23 #include "chrome/browser/chromeos/login/login_utils.h"
24 #include "chrome/browser/chromeos/login/rounded_rect_painter.h"
25 #include "chrome/browser/chromeos/login/views_eula_screen_actor.h"
26 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/browser/ui/views/dom_view.h"
28 #include "chrome/browser/ui/views/handle_web_keyboard_event.h"
29 #include "chrome/browser/ui/views/window.h"
30 #include "chrome/common/url_constants.h"
31 #include "content/browser/site_instance.h"
32 #include "content/browser/tab_contents/tab_contents.h"
33 #include "content/public/browser/native_web_keyboard_event.h"
34 #include "grit/chromium_strings.h"
35 #include "grit/generated_resources.h"
36 #include "grit/locale_settings.h"
37 #include "grit/theme_resources.h"
38 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/resource/resource_bundle.h"
40 #include "views/controls/button/checkbox.h"
41 #include "views/controls/button/text_button.h"
42 #include "views/controls/label.h"
43 #include "views/controls/link.h"
44 #include "views/controls/throbber.h"
45 #include "views/events/event.h"
46 #include "views/layout/grid_layout.h"
47 #include "views/layout/layout_constants.h"
48 #include "views/layout/layout_manager.h"
49 #include "views/window/dialog_delegate.h"
50
51 namespace chromeos {
52
53 namespace {
54
55 const int kBorderSize = 10;
56 const int kCheckboxWidth = 26;
57 const int kLastButtonHorizontalMargin = 10;
58 const int kMargin = 20;
59 const int kTextMargin = 10;
60
61 const char kGoogleEulaUrl[] = "about:terms";
62
63 enum kLayoutColumnsets {
64 SINGLE_CONTROL_ROW,
65 SINGLE_CONTROL_WITH_SHIFT_ROW,
66 SINGLE_LINK_WITH_SHIFT_ROW,
67 LAST_ROW
68 };
69
70 // A simple LayoutManager that causes the associated view's one child to be
71 // sized to match the bounds of its parent except the bounds, if set.
72 struct FillLayoutWithBorder : public views::LayoutManager {
73 // Overridden from LayoutManager:
74 virtual void Layout(views::View* host) {
75 DCHECK(host->has_children());
76 host->child_at(0)->SetBoundsRect(host->GetContentsBounds());
77 }
78 virtual gfx::Size GetPreferredSize(views::View* host) {
79 return gfx::Size(host->width(), host->height());
80 }
81 };
82
83 } // namespace
84
85 // System security setting dialog.
86 class TpmInfoView : public views::DialogDelegateView {
87 public:
88 explicit TpmInfoView(EulaView* eula_view);
89 virtual ~TpmInfoView();
90
91 void Init();
92
93 void ShowTpmPassword(const std::string& tpm_password);
94
95 protected:
96 // views::DialogDelegateView overrides:
97 virtual bool Accept() OVERRIDE { return true; }
98 virtual bool IsModal() const OVERRIDE { return true; }
99 virtual views::View* GetContentsView() OVERRIDE { return this; }
100 virtual int GetDialogButtons() const OVERRIDE {
101 return ui::DIALOG_BUTTON_OK;
102 }
103
104 // views::View overrides:
105 virtual string16 GetWindowTitle() const OVERRIDE {
106 return l10n_util::GetStringUTF16(IDS_EULA_SYSTEM_SECURITY_SETTING);
107 }
108
109 gfx::Size GetPreferredSize() {
110 return gfx::Size(views::Widget::GetLocalizedContentsSize(
111 IDS_TPM_INFO_DIALOG_WIDTH_CHARS,
112 IDS_TPM_INFO_DIALOG_HEIGHT_LINES));
113 }
114
115 private:
116 chromeos::EulaView* eula_view_;
117
118 views::Label* busy_label_;
119 views::Label* password_label_;
120 views::Throbber* throbber_;
121
122 DISALLOW_COPY_AND_ASSIGN(TpmInfoView);
123 };
124
125 TpmInfoView::TpmInfoView(EulaView* eula_view)
126 : eula_view_(eula_view) {
127 DCHECK(eula_view_);
128 }
129
130 TpmInfoView::~TpmInfoView() {
131 eula_view_->OnTpmInfoViewClosed(this);
132 }
133
134 void TpmInfoView::Init() {
135 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
136 SetLayoutManager(layout);
137 views::ColumnSet* column_set = layout->AddColumnSet(0);
138 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
139 views::GridLayout::USE_PREF, 0, 0);
140 layout->StartRow(0, 0);
141 views::Label* label = new views::Label(
142 l10n_util::GetStringUTF16(IDS_EULA_SYSTEM_SECURITY_SETTING_DESCRIPTION));
143 label->SetMultiLine(true);
144 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
145 layout->AddView(label);
146 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
147
148 layout->StartRow(0, 0);
149 label = new views::Label(l10n_util::GetStringUTF16(
150 IDS_EULA_SYSTEM_SECURITY_SETTING_DESCRIPTION_KEY));
151 label->SetMultiLine(true);
152 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
153 layout->AddView(label);
154 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
155
156 column_set = layout->AddColumnSet(1);
157 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
158 views::GridLayout::USE_PREF, 0, 0);
159 layout->StartRow(0, 1);
160 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
161 gfx::Font password_font =
162 rb.GetFont(ResourceBundle::MediumFont).DeriveFont(0, gfx::Font::BOLD);
163 // Password will be set later.
164 password_label_ = new views::Label(string16(), password_font);
165 password_label_->SetVisible(false);
166 layout->AddView(password_label_);
167 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
168
169 column_set = layout->AddColumnSet(2);
170 column_set->AddPaddingColumn(1, 0);
171 // Resize of the throbber and label is not allowed, since we want they to be
172 // placed in the center.
173 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
174 views::GridLayout::USE_PREF, 0, 0);
175 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
176 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
177 views::GridLayout::USE_PREF, 0, 0);
178 column_set->AddPaddingColumn(1, 0);
179 // Border padding columns should have the same width. It guaranties that
180 // throbber and label will be placed in the center.
181 column_set->LinkColumnSizes(0, 4, -1);
182
183 layout->StartRow(0, 2);
184 throbber_ = chromeos::CreateDefaultThrobber();
185 throbber_->Start();
186 layout->AddView(throbber_);
187 busy_label_ = new views::Label(
188 l10n_util::GetStringUTF16(IDS_EULA_TPM_BUSY));
189 layout->AddView(busy_label_);
190 layout->AddPaddingRow(0, views::kRelatedControlHorizontalSpacing);
191 }
192
193 void TpmInfoView::ShowTpmPassword(const std::string& tpm_password) {
194 password_label_->SetText(ASCIIToUTF16(tpm_password));
195 password_label_->SetVisible(true);
196 busy_label_->SetVisible(false);
197 throbber_->Stop();
198 throbber_->SetVisible(false);
199 }
200
201 ////////////////////////////////////////////////////////////////////////////////
202 // EULATabContentsDelegate, public:
203
204 bool EULATabContentsDelegate::IsPopup(TabContents* source) {
205 return false;
206 }
207
208 bool EULATabContentsDelegate::ShouldAddNavigationToHistory(
209 const history::HistoryAddPageArgs& add_page_args,
210 content::NavigationType navigation_type) {
211 return false;
212 }
213
214 bool EULATabContentsDelegate::HandleContextMenu(
215 const ContextMenuParams& params) {
216 return true;
217 }
218
219 ////////////////////////////////////////////////////////////////////////////////
220 // EulaView, public:
221
222 EulaView::EulaView(ViewsEulaScreenActor* actor)
223 : google_eula_label_(NULL),
224 google_eula_view_(NULL),
225 usage_statistics_checkbox_(NULL),
226 learn_more_link_(NULL),
227 oem_eula_label_(NULL),
228 oem_eula_view_(NULL),
229 system_security_settings_link_(NULL),
230 back_button_(NULL),
231 continue_button_(NULL),
232 tpm_info_view_(NULL),
233 actor_(actor),
234 bubble_(NULL) {
235 }
236
237 EulaView::~EulaView() {
238 // bubble_ will be set to NULL in callback.
239 if (bubble_)
240 bubble_->Close();
241 }
242
243 // Convenience function to set layout's columnsets for this screen.
244 static void SetUpGridLayout(views::GridLayout* layout) {
245 static const int kPadding = kBorderSize + kMargin;
246 views::ColumnSet* column_set = layout->AddColumnSet(SINGLE_CONTROL_ROW);
247 column_set->AddPaddingColumn(0, kPadding);
248 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
249 views::GridLayout::USE_PREF, 0, 0);
250 column_set->AddPaddingColumn(0, kPadding);
251
252 column_set = layout->AddColumnSet(SINGLE_CONTROL_WITH_SHIFT_ROW);
253 column_set->AddPaddingColumn(0, kPadding + kTextMargin);
254 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
255 views::GridLayout::USE_PREF, 0, 0);
256 column_set->AddPaddingColumn(0, kPadding);
257
258 column_set = layout->AddColumnSet(SINGLE_LINK_WITH_SHIFT_ROW);
259 column_set->AddPaddingColumn(0, kPadding + kTextMargin + kCheckboxWidth);
260 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
261 views::GridLayout::USE_PREF, 0, 0);
262 column_set->AddPaddingColumn(0, kPadding);
263
264 column_set = layout->AddColumnSet(LAST_ROW);
265 column_set->AddPaddingColumn(0, kPadding + kTextMargin);
266 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
267 views::GridLayout::USE_PREF, 0, 0);
268 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
269 views::GridLayout::USE_PREF, 0, 0);
270 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
271 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
272 views::GridLayout::USE_PREF, 0, 0);
273 column_set->AddPaddingColumn(0, kLastButtonHorizontalMargin + kBorderSize);
274 }
275
276 void EulaView::Init() {
277 // Use rounded rect background.
278 views::Painter* painter = CreateWizardPainter(
279 &BorderDefinition::kScreenBorder);
280 set_background(
281 views::Background::CreateBackgroundPainter(true, painter));
282
283 // Layout created controls.
284 views::GridLayout* layout = new views::GridLayout(this);
285 SetLayoutManager(layout);
286 SetUpGridLayout(layout);
287
288 static const int kPadding = kBorderSize + kMargin;
289 layout->AddPaddingRow(0, kPadding);
290 layout->StartRow(0, SINGLE_CONTROL_ROW);
291 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
292 gfx::Font label_font =
293 rb.GetFont(ResourceBundle::MediumFont).DeriveFont(0, gfx::Font::NORMAL);
294 google_eula_label_ = new views::Label(string16(), label_font);
295 layout->AddView(google_eula_label_, 1, 1,
296 views::GridLayout::LEADING, views::GridLayout::FILL);
297
298 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
299 layout->StartRow(1, SINGLE_CONTROL_ROW);
300 views::View* box_view = new views::View();
301 box_view->set_border(views::Border::CreateSolidBorder(1, SK_ColorBLACK));
302 box_view->SetLayoutManager(new FillLayoutWithBorder());
303 layout->AddView(box_view);
304
305 google_eula_view_ = new DOMView();
306 box_view->AddChildView(google_eula_view_);
307
308 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
309 layout->StartRow(0, SINGLE_CONTROL_WITH_SHIFT_ROW);
310 usage_statistics_checkbox_ = new views::Checkbox(string16());
311 usage_statistics_checkbox_->SetMultiLine(true);
312 usage_statistics_checkbox_->SetChecked(
313 actor_->screen()->IsUsageStatsEnabled());
314 layout->AddView(usage_statistics_checkbox_);
315
316 layout->StartRow(0, SINGLE_LINK_WITH_SHIFT_ROW);
317 learn_more_link_ = new views::Link();
318 learn_more_link_->set_listener(this);
319 layout->AddView(learn_more_link_);
320
321 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
322 layout->StartRow(0, SINGLE_CONTROL_ROW);
323 oem_eula_label_ = new views::Label(string16(), label_font);
324 layout->AddView(oem_eula_label_, 1, 1,
325 views::GridLayout::LEADING, views::GridLayout::FILL);
326
327 oem_eula_page_ = actor_->screen()->GetOemEulaUrl();
328 if (!oem_eula_page_.is_empty()) {
329 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
330 layout->StartRow(1, SINGLE_CONTROL_ROW);
331 box_view = new views::View();
332 box_view->SetLayoutManager(new FillLayoutWithBorder());
333 box_view->set_border(views::Border::CreateSolidBorder(1, SK_ColorBLACK));
334 layout->AddView(box_view);
335
336 oem_eula_view_ = new DOMView();
337 box_view->AddChildView(oem_eula_view_);
338 }
339
340 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
341 layout->StartRow(0, LAST_ROW);
342 system_security_settings_link_ = new views::Link();
343 system_security_settings_link_->set_listener(this);
344
345 if (!actor_->screen()->IsTpmEnabled()) {
346 system_security_settings_link_->SetEnabled(false);
347 }
348
349 layout->AddView(system_security_settings_link_);
350
351 back_button_ = new login::WideButton(this, string16());
352 layout->AddView(back_button_);
353
354 continue_button_ = new login::WideButton(this, string16());
355 layout->AddView(continue_button_);
356 layout->AddPaddingRow(0, kPadding);
357
358 UpdateLocalizedStrings();
359 }
360
361 void EulaView::UpdateLocalizedStrings() {
362 // Load Google EULA and its title.
363 LoadEulaView(google_eula_view_,
364 google_eula_label_,
365 GURL(kGoogleEulaUrl));
366
367 // Load OEM EULA and its title.
368 if (!oem_eula_page_.is_empty())
369 LoadEulaView(oem_eula_view_, oem_eula_label_, oem_eula_page_);
370
371 // Set tooltip for usage statistics checkbox if the metric is unmanaged.
372 if (!usage_statistics_checkbox_->IsEnabled()) {
373 usage_statistics_checkbox_->SetTooltipText(
374 l10n_util::GetStringUTF16(IDS_OPTION_DISABLED_BY_POLICY));
375 }
376
377 // Set tooltip for system security settings link if TPM is disabled.
378 if (!system_security_settings_link_->IsEnabled()) {
379 system_security_settings_link_->SetTooltipText(
380 l10n_util::GetStringUTF16(IDS_EULA_TPM_DISABLED));
381 }
382
383 // Load other labels from resources.
384 usage_statistics_checkbox_->SetText(
385 l10n_util::GetStringUTF16(IDS_EULA_CHECKBOX_ENABLE_LOGGING));
386 learn_more_link_->SetText(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
387 system_security_settings_link_->SetText(
388 l10n_util::GetStringUTF16(IDS_EULA_SYSTEM_SECURITY_SETTING));
389 continue_button_->SetText(
390 l10n_util::GetStringUTF16(IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON));
391 back_button_->SetText(l10n_util::GetStringUTF16(IDS_EULA_BACK_BUTTON));
392 }
393
394 bool EulaView::IsUsageStatsChecked() const {
395 return usage_statistics_checkbox_ && usage_statistics_checkbox_->checked();
396 }
397
398 void EulaView::ShowTpmPassword(const std::string& tpm_password) {
399 if (tpm_info_view_)
400 tpm_info_view_->ShowTpmPassword(tpm_password);
401 }
402
403 void EulaView::OnTpmInfoViewClosed(TpmInfoView* tpm_info_view) {
404 if (tpm_info_view == tpm_info_view_)
405 tpm_info_view_ = NULL;
406 }
407
408 ////////////////////////////////////////////////////////////////////////////////
409 // EulaView, protected, views::View implementation:
410
411 void EulaView::OnLocaleChanged() {
412 UpdateLocalizedStrings();
413 Layout();
414 }
415
416 ////////////////////////////////////////////////////////////////////////////////
417 // views::ButtonListener implementation:
418
419 void EulaView::ButtonPressed(views::Button* sender, const views::Event& event) {
420 if (sender == continue_button_) {
421 actor_->screen()->OnExit(true, IsUsageStatsChecked());
422 } else if (sender == back_button_) {
423 actor_->screen()->OnExit(false, IsUsageStatsChecked());
424 }
425 }
426
427 ////////////////////////////////////////////////////////////////////////////////
428 // views::LinkListener implementation:
429
430 void EulaView::LinkClicked(views::Link* source, int event_flags) {
431 gfx::NativeWindow parent_window =
432 LoginUtils::Get()->GetBackgroundView()->GetNativeWindow();
433 if (source == learn_more_link_) {
434 if (!help_app_.get())
435 help_app_ = new HelpAppLauncher(parent_window);
436 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_STATS_USAGE);
437 } else if (source == system_security_settings_link_) {
438 tpm_info_view_ = new TpmInfoView(this);
439 tpm_info_view_->Init();
440 views::Widget* window = browser::CreateViewsWindow(parent_window,
441 tpm_info_view_);
442 window->SetAlwaysOnTop(true);
443 window->Show();
444 actor_->screen()->InitiatePasswordFetch();
445 }
446 }
447
448 ////////////////////////////////////////////////////////////////////////////////
449 // TabContentsDelegate implementation:
450
451 // Convenience function. Queries |eula_view| for HTML title and, if it
452 // is ready, assigns it to |eula_label| and returns true so the caller
453 // view calls Layout().
454 static bool PublishTitleIfReady(const TabContents* contents,
455 DOMView* eula_view,
456 views::Label* eula_label) {
457 if (!eula_view->dom_contents())
458 return false;
459 TabContents* tab_contents = eula_view->dom_contents()->tab_contents();
460 if (contents != tab_contents)
461 return false;
462 eula_label->SetText(tab_contents->GetTitle());
463 return true;
464 }
465
466 void EulaView::NavigationStateChanged(const TabContents* contents,
467 unsigned changed_flags) {
468 if (changed_flags & TabContents::INVALIDATE_TITLE) {
469 if (PublishTitleIfReady(contents, google_eula_view_, google_eula_label_) ||
470 PublishTitleIfReady(contents, oem_eula_view_, oem_eula_label_)) {
471 Layout();
472 }
473 }
474 }
475
476 void EulaView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
477 HandleWebKeyboardEvent(GetWidget(), event);
478 }
479
480 ////////////////////////////////////////////////////////////////////////////////
481 // EulaView, private:
482
483 void EulaView::LoadEulaView(DOMView* eula_view,
484 views::Label* eula_label,
485 const GURL& eula_url) {
486 Profile* profile = ProfileManager::GetDefaultProfile();
487 eula_view->Init(profile,
488 SiteInstance::CreateSiteInstanceForURL(profile, eula_url));
489 eula_view->LoadURL(eula_url);
490 eula_view->dom_contents()->tab_contents()->set_delegate(this);
491 }
492
493 ////////////////////////////////////////////////////////////////////////////////
494 // EulaView, private, views::View implementation:
495
496 bool EulaView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
497 return true;
498 }
499
500 bool EulaView::OnKeyPressed(const views::KeyEvent&) {
501 // Close message bubble if shown. bubble_ will be set to NULL in callback.
502 if (bubble_) {
503 bubble_->Close();
504 return true;
505 }
506 return false;
507 }
508
509 ////////////////////////////////////////////////////////////////////////////////
510 // EulaView, private, views::BubbleDelegate implementation:
511
512 void EulaView::BubbleClosing(Bubble* bubble, bool closed_by_escape) {
513 bubble_ = NULL;
514 }
515
516 bool EulaView::CloseOnEscape() {
517 return true;
518 }
519
520 bool EulaView::FadeInOnShow() {
521 return false;
522 }
523
524 void EulaView::OnLinkActivated(size_t index) {
525 }
526
527 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/eula_view.h ('k') | chrome/browser/chromeos/login/existing_user_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698