OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/login/eula_view.h" | 5 #include "chrome/browser/chromeos/login/eula_view.h" |
6 | 6 |
7 #include <signal.h> | 7 #include <signal.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chromeos/cros/cros_library.h" | |
16 #include "chrome/browser/chromeos/customization_document.h" | 17 #include "chrome/browser/chromeos/customization_document.h" |
17 #include "chrome/browser/chromeos/login/help_app_launcher.h" | 18 #include "chrome/browser/chromeos/login/help_app_launcher.h" |
18 #include "chrome/browser/chromeos/login/network_screen_delegate.h" | 19 #include "chrome/browser/chromeos/login/network_screen_delegate.h" |
19 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" | 20 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" |
20 #include "chrome/browser/chromeos/login/wizard_controller.h" | 21 #include "chrome/browser/chromeos/login/wizard_controller.h" |
21 #include "chrome/browser/options_util.h" | 22 #include "chrome/browser/options_util.h" |
22 #include "chrome/browser/profile_manager.h" | 23 #include "chrome/browser/profile_manager.h" |
23 #include "chrome/browser/renderer_host/site_instance.h" | 24 #include "chrome/browser/renderer_host/site_instance.h" |
24 #include "chrome/browser/tab_contents/tab_contents.h" | 25 #include "chrome/browser/tab_contents/tab_contents.h" |
25 #include "chrome/browser/views/dom_view.h" | 26 #include "chrome/browser/views/dom_view.h" |
26 #include "chrome/common/native_web_keyboard_event.h" | 27 #include "chrome/common/native_web_keyboard_event.h" |
27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
28 #include "chrome/installer/util/google_update_settings.h" | 29 #include "chrome/installer/util/google_update_settings.h" |
30 #include "cros/chromeos_cryptohome.h" | |
29 #include "grit/chromium_strings.h" | 31 #include "grit/chromium_strings.h" |
30 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
33 #include "grit/locale_settings.h" | |
31 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
32 #include "views/controls/button/checkbox.h" | 35 #include "views/controls/button/checkbox.h" |
33 #include "views/controls/button/native_button.h" | 36 #include "views/controls/button/native_button.h" |
34 #include "views/controls/label.h" | 37 #include "views/controls/label.h" |
35 #include "views/grid_layout.h" | 38 #include "views/grid_layout.h" |
36 #include "views/layout_manager.h" | 39 #include "views/layout_manager.h" |
37 #include "views/standard_layout.h" | 40 #include "views/standard_layout.h" |
38 #include "views/widget/widget_gtk.h" | 41 #include "views/widget/widget_gtk.h" |
42 #include "views/window/dialog_delegate.h" | |
43 #include "views/window/window.h" | |
39 | 44 |
40 #if defined(USE_LINUX_BREAKPAD) | 45 #if defined(USE_LINUX_BREAKPAD) |
41 #include "chrome/app/breakpad_linux.h" | 46 #include "chrome/app/breakpad_linux.h" |
42 #endif | 47 #endif |
43 | 48 |
44 using views::WidgetGtk; | 49 using views::WidgetGtk; |
45 | 50 |
46 namespace { | 51 namespace { |
47 | 52 |
48 const int kBorderSize = 10; | 53 const int kBorderSize = 10; |
(...skipping 19 matching lines...) Expand all Loading... | |
68 // Overridden from LayoutManager: | 73 // Overridden from LayoutManager: |
69 virtual void Layout(views::View* host) { | 74 virtual void Layout(views::View* host) { |
70 DCHECK(host->GetChildViewCount()); | 75 DCHECK(host->GetChildViewCount()); |
71 host->GetChildViewAt(0)->SetBounds(host->GetLocalBounds(false)); | 76 host->GetChildViewAt(0)->SetBounds(host->GetLocalBounds(false)); |
72 } | 77 } |
73 virtual gfx::Size GetPreferredSize(views::View* host) { | 78 virtual gfx::Size GetPreferredSize(views::View* host) { |
74 return gfx::Size(host->width(), host->height()); | 79 return gfx::Size(host->width(), host->height()); |
75 } | 80 } |
76 }; | 81 }; |
77 | 82 |
83 // System security setting dialog. | |
84 class TpmInfoView : public views::View, | |
85 public views::DialogDelegate { | |
86 public: | |
87 explicit TpmInfoView(std::wstring password) : password_(password) { } | |
88 void Init(); | |
89 | |
90 protected: | |
91 // views::DialogDelegate overrides: | |
92 virtual bool Accept() { return true; } | |
93 virtual bool IsModal() const { return true; } | |
94 virtual views::View* GetContentsView() { return this; } | |
95 virtual int GetDialogButtons() const { | |
96 return MessageBoxFlags::DIALOGBUTTON_OK; | |
97 } | |
98 | |
99 // views::View overrides: | |
100 virtual std::wstring GetWindowTitle() const { | |
101 return l10n_util::GetString(IDS_EULA_SYSTEM_SECURITY_SETTING); | |
102 } | |
103 | |
104 gfx::Size GetPreferredSize() { | |
105 return gfx::Size(views::Window::GetLocalizedContentsSize( | |
106 IDS_TPM_INFO_DIALOG_WIDTH_CHARS, | |
107 IDS_TPM_INFO_DIALOG_HEIGHT_LINES)); | |
108 } | |
109 | |
110 private: | |
111 std::wstring password_; | |
112 DISALLOW_COPY_AND_ASSIGN(TpmInfoView); | |
113 }; | |
114 | |
115 void TpmInfoView::Init() { | |
116 views::GridLayout* layout = CreatePanelGridLayout(this); | |
117 SetLayoutManager(layout); | |
118 views::ColumnSet* column_set = layout->AddColumnSet(0); | |
119 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | |
120 views::GridLayout::USE_PREF, 0, 0); | |
121 layout->StartRow(0, 0); | |
122 views::Label* label = new views::Label( | |
123 l10n_util::GetString(IDS_EULA_SYSTEM_SECURITY_SETTING_DESCRIPTION)); | |
124 label->SetMultiLine(true); | |
125 layout->AddView(label); | |
126 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | |
127 | |
128 column_set = layout->AddColumnSet(1); | |
129 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | |
130 views::GridLayout::USE_PREF, 0, 0); | |
131 layout->StartRow(0, 1); | |
132 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
133 gfx::Font password_font = | |
134 rb.GetFont(ResourceBundle::MediumFont).DeriveFont(0, gfx::Font::BOLD); | |
135 label = new views::Label(password_, password_font); | |
136 layout->AddView(label); | |
137 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | |
138 } | |
139 | |
78 } // namespace | 140 } // namespace |
79 | 141 |
80 namespace chromeos { | 142 namespace chromeos { |
81 | 143 |
82 //////////////////////////////////////////////////////////////////////////////// | 144 //////////////////////////////////////////////////////////////////////////////// |
83 // EulaView, public: | 145 // EulaView, public: |
84 | 146 |
85 EulaView::EulaView(chromeos::ScreenObserver* observer) | 147 EulaView::EulaView(chromeos::ScreenObserver* observer) |
86 : google_eula_label_(NULL), | 148 : google_eula_label_(NULL), |
87 google_eula_view_(NULL), | 149 google_eula_view_(NULL), |
88 usage_statistics_checkbox_(NULL), | 150 usage_statistics_checkbox_(NULL), |
89 learn_more_link_(NULL), | 151 learn_more_link_(NULL), |
90 oem_eula_label_(NULL), | 152 oem_eula_label_(NULL), |
91 oem_eula_view_(NULL), | 153 oem_eula_view_(NULL), |
92 system_security_settings_link_(NULL), | 154 system_security_settings_link_(NULL), |
93 back_button_(NULL), | 155 back_button_(NULL), |
94 continue_button_(NULL), | 156 continue_button_(NULL), |
95 observer_(observer) { | 157 observer_(observer), |
158 bubble_(NULL) { | |
96 } | 159 } |
97 | 160 |
98 EulaView::~EulaView() { | 161 EulaView::~EulaView() { |
162 // bubble_ will be set to NULL in callback. | |
163 if (bubble_) | |
164 bubble_->Close(); | |
99 } | 165 } |
100 | 166 |
101 // Convenience function to set layout's columnsets for this screen. | 167 // Convenience function to set layout's columnsets for this screen. |
102 static void SetUpGridLayout(views::GridLayout* layout) { | 168 static void SetUpGridLayout(views::GridLayout* layout) { |
103 static const int kPadding = kBorderSize + kMargin; | 169 static const int kPadding = kBorderSize + kMargin; |
104 views::ColumnSet* column_set = layout->AddColumnSet(SINGLE_CONTROL_ROW); | 170 views::ColumnSet* column_set = layout->AddColumnSet(SINGLE_CONTROL_ROW); |
105 column_set->AddPaddingColumn(0, kPadding); | 171 column_set->AddPaddingColumn(0, kPadding); |
106 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 172 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
107 views::GridLayout::USE_PREF, 0, 0); | 173 views::GridLayout::USE_PREF, 0, 0); |
108 column_set->AddPaddingColumn(0, kPadding); | 174 column_set->AddPaddingColumn(0, kPadding); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 layout->AddView(box_view); | 288 layout->AddView(box_view); |
223 | 289 |
224 oem_eula_view_ = new DOMView(); | 290 oem_eula_view_ = new DOMView(); |
225 box_view->AddChildView(oem_eula_view_); | 291 box_view->AddChildView(oem_eula_view_); |
226 } | 292 } |
227 | 293 |
228 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 294 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
229 layout->StartRow(0, LAST_ROW); | 295 layout->StartRow(0, LAST_ROW); |
230 system_security_settings_link_ = new views::Link(); | 296 system_security_settings_link_ = new views::Link(); |
231 system_security_settings_link_->SetController(this); | 297 system_security_settings_link_->SetController(this); |
298 if (!chromeos::CrosLibrary::Get()->EnsureLoaded() || | |
299 !chromeos::CryptohomeTpmIsEnabled()) { | |
300 system_security_settings_link_->SetEnabled(false); | |
301 // TODO(glotov): add tooltip with description. | |
302 } | |
232 layout->AddView(system_security_settings_link_); | 303 layout->AddView(system_security_settings_link_); |
233 | 304 |
234 back_button_ = new views::NativeButton(this, std::wstring()); | 305 back_button_ = new views::NativeButton(this, std::wstring()); |
235 layout->AddView(back_button_); | 306 layout->AddView(back_button_); |
236 | 307 |
237 continue_button_ = new views::NativeButton(this, std::wstring()); | 308 continue_button_ = new views::NativeButton(this, std::wstring()); |
238 layout->AddView(continue_button_); | 309 layout->AddView(continue_button_); |
239 layout->AddPaddingRow(0, kPadding); | 310 layout->AddPaddingRow(0, kPadding); |
240 | 311 |
241 UpdateLocalizedStrings(); | 312 UpdateLocalizedStrings(); |
(...skipping 12 matching lines...) Expand all Loading... | |
254 usage_statistics_checkbox_->SetTooltipText( | 325 usage_statistics_checkbox_->SetTooltipText( |
255 l10n_util::GetString(IDS_OPTION_DISABLED_BY_POLICY)); | 326 l10n_util::GetString(IDS_OPTION_DISABLED_BY_POLICY)); |
256 } | 327 } |
257 | 328 |
258 // Load other labels from resources. | 329 // Load other labels from resources. |
259 usage_statistics_checkbox_->SetLabel( | 330 usage_statistics_checkbox_->SetLabel( |
260 l10n_util::GetString(IDS_EULA_CHECKBOX_ENABLE_LOGGING)); | 331 l10n_util::GetString(IDS_EULA_CHECKBOX_ENABLE_LOGGING)); |
261 learn_more_link_->SetText( | 332 learn_more_link_->SetText( |
262 l10n_util::GetString(IDS_LEARN_MORE)); | 333 l10n_util::GetString(IDS_LEARN_MORE)); |
263 system_security_settings_link_->SetText( | 334 system_security_settings_link_->SetText( |
264 l10n_util::GetString(IDS_EULA_SYSTEM_SECURITY_SETTINGS_LINK)); | 335 l10n_util::GetString(IDS_EULA_SYSTEM_SECURITY_SETTING)); |
265 continue_button_->SetLabel( | 336 continue_button_->SetLabel( |
266 l10n_util::GetString(IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON)); | 337 l10n_util::GetString(IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON)); |
267 back_button_->SetLabel( | 338 back_button_->SetLabel( |
268 l10n_util::GetString(IDS_ACCNAME_BACK)); | 339 l10n_util::GetString(IDS_ACCNAME_BACK)); |
269 } | 340 } |
270 | 341 |
271 //////////////////////////////////////////////////////////////////////////////// | 342 //////////////////////////////////////////////////////////////////////////////// |
272 // EulaView, protected, views::View implementation: | 343 // EulaView, protected, views::View implementation: |
273 | 344 |
274 void EulaView::OnLocaleChanged() { | 345 void EulaView::OnLocaleChanged() { |
(...skipping 23 matching lines...) Expand all Loading... | |
298 | 369 |
299 //////////////////////////////////////////////////////////////////////////////// | 370 //////////////////////////////////////////////////////////////////////////////// |
300 // views::LinkController implementation: | 371 // views::LinkController implementation: |
301 | 372 |
302 void EulaView::LinkActivated(views::Link* source, int event_flags) { | 373 void EulaView::LinkActivated(views::Link* source, int event_flags) { |
303 if (source == learn_more_link_) { | 374 if (source == learn_more_link_) { |
304 if (!help_app_.get()) | 375 if (!help_app_.get()) |
305 help_app_.reset(new HelpAppLauncher(GetNativeWindow())); | 376 help_app_.reset(new HelpAppLauncher(GetNativeWindow())); |
306 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_STATS_USAGE); | 377 help_app_->ShowHelpTopic(HelpAppLauncher::HELP_STATS_USAGE); |
307 } else if (source == system_security_settings_link_) { | 378 } else if (source == system_security_settings_link_) { |
308 // TODO(glotov): Handle TPM link click. | 379 // Pull the password from TPM. |
380 std::string password; | |
381 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) { | |
382 LOG(ERROR) << "Cros library not loaded. " | |
383 << "We must have disabled the link that led here."; | |
384 return; | |
385 } else if (chromeos::CryptohomeTpmIsReady() && | |
386 chromeos::CryptohomeTpmGetPassword(&password)) { | |
387 TpmInfoView* view = new TpmInfoView(ASCIIToWide(password)); | |
388 view->Init(); | |
389 views::Window* window = views::Window::CreateChromeWindow( | |
390 GetNativeWindow(), gfx::Rect(), view); | |
391 window->SetIsAlwaysOnTop(true); | |
392 window->Show(); | |
393 } else { | |
394 if (!bubble_) | |
Nikita (slow)
2010/09/27 17:51:01
indent
glotov
2010/09/27 18:52:01
Done.
| |
395 bubble_ = MessageBubble::Show( | |
396 system_security_settings_link_->GetWidget(), | |
397 system_security_settings_link_->GetScreenBounds(), | |
398 BubbleBorder::LEFT_TOP, | |
399 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), | |
400 l10n_util::GetString(IDS_EULA_TPM_BUSY), | |
401 std::wstring(), this); | |
402 } | |
309 } | 403 } |
310 } | 404 } |
311 | 405 |
312 //////////////////////////////////////////////////////////////////////////////// | 406 //////////////////////////////////////////////////////////////////////////////// |
313 // TabContentsDelegate implementation: | 407 // TabContentsDelegate implementation: |
314 | 408 |
315 // Convenience function. Queries |eula_view| for HTML title and, if it | 409 // Convenience function. Queries |eula_view| for HTML title and, if it |
316 // is ready, assigns it to |eula_label| and returns true so the caller | 410 // is ready, assigns it to |eula_label| and returns true so the caller |
317 // view calls Layout(). | 411 // view calls Layout(). |
318 static bool PublishTitleIfReady(const TabContents* contents, | 412 static bool PublishTitleIfReady(const TabContents* contents, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 void EulaView::LoadEulaView(DOMView* eula_view, | 444 void EulaView::LoadEulaView(DOMView* eula_view, |
351 views::Label* eula_label, | 445 views::Label* eula_label, |
352 const GURL& eula_url) { | 446 const GURL& eula_url) { |
353 Profile* profile = ProfileManager::GetDefaultProfile(); | 447 Profile* profile = ProfileManager::GetDefaultProfile(); |
354 eula_view->Init(profile, | 448 eula_view->Init(profile, |
355 SiteInstance::CreateSiteInstanceForURL(profile, eula_url)); | 449 SiteInstance::CreateSiteInstanceForURL(profile, eula_url)); |
356 eula_view->LoadURL(eula_url); | 450 eula_view->LoadURL(eula_url); |
357 eula_view->tab_contents()->set_delegate(this); | 451 eula_view->tab_contents()->set_delegate(this); |
358 } | 452 } |
359 | 453 |
454 //////////////////////////////////////////////////////////////////////////////// | |
455 // EulaView, private, views::View implementation: | |
456 | |
457 bool EulaView::OnKeyPressed(const views::KeyEvent&) { | |
458 // Close message bubble if shown. bubble_ will be set to NULL in callback. | |
459 if (bubble_) { | |
460 bubble_->Close(); | |
461 return true; | |
462 } | |
463 return false; | |
464 } | |
465 | |
360 } // namespace chromeos | 466 } // namespace chromeos |
OLD | NEW |