eula_view.h revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
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#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_EULA_VIEW_H_
6#define CHROME_BROWSER_CHROMEOS_LOGIN_EULA_VIEW_H_
7#pragma once
8
9#include "base/ref_counted.h"
10#include "chrome/browser/chromeos/login/message_bubble.h"
11#include "chrome/browser/chromeos/login/view_screen.h"
12#include "chrome/browser/tab_contents/tab_contents_delegate.h"
13#include "ui/gfx/native_widget_types.h"
14#include "views/controls/button/button.h"
15#include "views/controls/link.h"
16#include "views/view.h"
17
18namespace views {
19
20class Checkbox;
21class Label;
22class Link;
23class NativeButton;
24
25}  // namespace views
26
27class DOMView;
28
29namespace chromeos {
30
31class HelpAppLauncher;
32class MetricsCrosSettingsProvider;
33
34// Delegate for TabContents that will show EULA.
35// Blocks context menu and other actions.
36class EULATabContentsDelegate : public TabContentsDelegate {
37 public:
38  EULATabContentsDelegate() {}
39  virtual ~EULATabContentsDelegate() {}
40
41 protected:
42  // TabContentsDelegate implementation:
43  virtual void OpenURLFromTab(TabContents* source,
44                              const GURL& url, const GURL& referrer,
45                              WindowOpenDisposition disposition,
46                              PageTransition::Type transition) {}
47  virtual void NavigationStateChanged(const TabContents* source,
48                                      unsigned changed_flags) {}
49  virtual void AddNewContents(TabContents* source,
50                              TabContents* new_contents,
51                              WindowOpenDisposition disposition,
52                              const gfx::Rect& initial_pos,
53                              bool user_gesture) {}
54  virtual void ActivateContents(TabContents* contents) {}
55  virtual void DeactivateContents(TabContents* contents) {}
56  virtual void LoadingStateChanged(TabContents* source) {}
57  virtual void CloseContents(TabContents* source) {}
58  virtual bool IsPopup(TabContents* source) { return false; }
59  virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}
60  virtual bool ShouldAddNavigationToHistory(
61      const history::HistoryAddPageArgs& add_page_args,
62      NavigationType::Type navigation_type) {
63    return false;
64  }
65  virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {}
66  virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {}
67  virtual bool HandleContextMenu(const ContextMenuParams& params) {
68    return true;
69  }
70
71 private:
72  DISALLOW_COPY_AND_ASSIGN(EULATabContentsDelegate);
73};
74
75class EulaView
76    : public views::View,
77      public views::ButtonListener,
78      public views::LinkController,
79      public MessageBubbleDelegate,
80      public EULATabContentsDelegate {
81 public:
82  explicit EulaView(chromeos::ScreenObserver* observer);
83  virtual ~EulaView();
84
85  // Initialize view controls and layout.
86  void Init();
87
88  // Update strings from the resources. Executed on language change.
89  void UpdateLocalizedStrings();
90
91 protected:
92  // views::View implementation.
93  virtual void OnLocaleChanged();
94
95  // views::ButtonListener implementation.
96  virtual void ButtonPressed(views::Button* sender, const views::Event& event);
97
98  // views::LinkController implementation.
99  void LinkActivated(views::Link* source, int event_flags);
100
101 private:
102  // views::View implementation.
103  virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
104    return true; }
105  virtual bool OnKeyPressed(const views::KeyEvent& e);
106
107  // TabContentsDelegate implementation.
108  virtual void NavigationStateChanged(const TabContents* contents,
109                                      unsigned changed_flags);
110  virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
111
112  // Loads specified URL to the specified DOMView and updates specified
113  // label with its title.
114  void LoadEulaView(DOMView* eula_view,
115                    views::Label* eula_label,
116                    const GURL& eula_url);
117
118  // Overridden from views::InfoBubbleDelegate.
119  virtual void InfoBubbleClosing(InfoBubble* info_bubble,
120                                 bool closed_by_escape) { bubble_ = NULL; }
121  virtual bool CloseOnEscape() { return true; }
122  virtual bool FadeInOnShow() { return false; }
123  virtual void OnHelpLinkActivated() {}
124
125  // Dialog controls.
126  views::Label* google_eula_label_;
127  DOMView* google_eula_view_;
128  views::Checkbox* usage_statistics_checkbox_;
129  views::Link* learn_more_link_;
130  views::Label* oem_eula_label_;
131  DOMView* oem_eula_view_;
132  views::Link* system_security_settings_link_;
133  views::NativeButton* back_button_;
134  views::NativeButton* continue_button_;
135
136  chromeos::ScreenObserver* observer_;
137
138  // URL of the OEM EULA page (on disk).
139  GURL oem_eula_page_;
140
141  // Help application used for help dialogs.
142  scoped_refptr<HelpAppLauncher> help_app_;
143
144  // Pointer to shown message bubble. We don't need to delete it because
145  // it will be deleted on bubble closing.
146  MessageBubble* bubble_;
147
148  // TPM password local storage. By convention, we clear the password
149  // from TPM as soon as we read it. We store it here locally until
150  // EULA screen is closed.
151  // TODO(glotov): Sanitize memory used to store password when
152  // it's destroyed.
153  std::string tpm_password_;
154
155  DISALLOW_COPY_AND_ASSIGN(EulaView);
156};
157
158class EulaScreen : public DefaultViewScreen<EulaView> {
159 public:
160  explicit EulaScreen(WizardScreenDelegate* delegate)
161      : DefaultViewScreen<EulaView>(delegate) {
162  }
163 private:
164  DISALLOW_COPY_AND_ASSIGN(EulaScreen);
165};
166
167}  // namespace chromeos
168
169#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_EULA_VIEW_H_
170