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/memory/ref_counted.h" 10 #include "chrome/browser/chromeos/login/message_bubble.h" 11 #include "chrome/browser/chromeos/login/view_screen.h" 12 #include "content/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 18 namespace views { 19 20 class Checkbox; 21 class Label; 22 class Link; 23 class NativeButton; 24 25 } // namespace views 26 27 class DOMView; 28 29 namespace chromeos { 30 31 class HelpAppLauncher; 32 class MetricsCrosSettingsProvider; 33 34 // Delegate for TabContents that will show EULA. 35 // Blocks context menu and other actions. 36 class 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 bool HandleContextMenu(const ContextMenuParams& params) { 67 return true; 68 } 69 70 private: 71 DISALLOW_COPY_AND_ASSIGN(EULATabContentsDelegate); 72 }; 73 74 class EulaView 75 : public views::View, 76 public views::ButtonListener, 77 public views::LinkController, 78 public MessageBubbleDelegate, 79 public EULATabContentsDelegate { 80 public: 81 explicit EulaView(chromeos::ScreenObserver* observer); 82 virtual ~EulaView(); 83 84 // Initialize view controls and layout. 85 void Init(); 86 87 // Update strings from the resources. Executed on language change. 88 void UpdateLocalizedStrings(); 89 90 protected: 91 // views::View implementation. 92 virtual void OnLocaleChanged(); 93 94 // views::ButtonListener implementation. 95 virtual void ButtonPressed(views::Button* sender, const views::Event& event); 96 97 // views::LinkController implementation. 98 void LinkActivated(views::Link* source, int event_flags); 99 100 private: 101 // views::View implementation. 102 virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { 103 return true; } 104 virtual bool OnKeyPressed(const views::KeyEvent& e); 105 106 // TabContentsDelegate implementation. 107 virtual void NavigationStateChanged(const TabContents* contents, 108 unsigned changed_flags); 109 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); 110 111 // Loads specified URL to the specified DOMView and updates specified 112 // label with its title. 113 void LoadEulaView(DOMView* eula_view, 114 views::Label* eula_label, 115 const GURL& eula_url); 116 117 // Overridden from views::BubbleDelegate. 118 virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) { 119 bubble_ = NULL; 120 } 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 158 class 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