1// Copyright (c) 2013 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/** 6 * @fileoverview Oobe Terms of Service screen implementation. 7 */ 8 9login.createScreen('TermsOfServiceScreen', 'terms-of-service', 10 function() { return { 11 EXTERNAL_API: [ 12 'setDomain', 13 'setTermsOfServiceLoadError', 14 'setTermsOfService' 15 ], 16 17 /** 18 * Updates headings on the screen to indicate that the Terms of Service 19 * being shown belong to |domain|. 20 * @param {string} domain The domain whose Terms of Service are being shown. 21 */ 22 setDomain: function(domain) { 23 $('tos-heading').textContent = 24 loadTimeData.getStringF('termsOfServiceScreenHeading', domain); 25 $('tos-subheading').textContent = 26 loadTimeData.getStringF('termsOfServiceScreenSubheading', domain); 27 $('tos-content-heading').textContent = 28 loadTimeData.getStringF('termsOfServiceContentHeading', domain); 29 }, 30 31 /** 32 * Displays an error message on the Terms of Service screen. Called when the 33 * download of the Terms of Service has failed. 34 */ 35 setTermsOfServiceLoadError: function() { 36 this.classList.remove('tos-loading'); 37 this.classList.add('error'); 38 }, 39 40 /** 41 * Displays the given |termsOfService|, enables the accept button and moves 42 * the focus to it. 43 * @param {string} termsOfService The terms of service, as plain text. 44 */ 45 setTermsOfService: function(termsOfService) { 46 this.classList.remove('tos-loading'); 47 $('tos-content-main').textContent = termsOfService; 48 $('tos-accept-button').disabled = false; 49 // Initially, the back button is focused and the accept button is 50 // disabled. 51 // Move the focus to the accept button now but only if the user has not 52 // moved the focus anywhere in the meantime. 53 if (!$('tos-back-button').blurred) 54 $('tos-accept-button').focus(); 55 }, 56 57 /** 58 * Buttons in Oobe wizard's button strip. 59 * @type {array} Array of Buttons. 60 */ 61 get buttons() { 62 var buttons = []; 63 64 var backButton = this.ownerDocument.createElement('button'); 65 backButton.id = 'tos-back-button'; 66 backButton.textContent = 67 loadTimeData.getString('termsOfServiceBackButton'); 68 backButton.addEventListener('click', function(event) { 69 $('tos-back-button').disabled = true; 70 $('tos-accept-button').disabled = true; 71 chrome.send('termsOfServiceBack'); 72 }); 73 backButton.addEventListener('blur', function(event) { 74 this.blurred = true; 75 }); 76 buttons.push(backButton); 77 78 var acceptButton = this.ownerDocument.createElement('button'); 79 acceptButton.id = 'tos-accept-button'; 80 acceptButton.disabled = true; 81 acceptButton.classList.add('preserve-disabled-state'); 82 acceptButton.textContent = 83 loadTimeData.getString('termsOfServiceAcceptButton'); 84 acceptButton.addEventListener('click', function(event) { 85 $('tos-back-button').disabled = true; 86 $('tos-accept-button').disabled = true; 87 chrome.send('termsOfServiceAccept'); 88 }); 89 buttons.push(acceptButton); 90 91 return buttons; 92 }, 93 94 /** 95 * Returns the control which should receive initial focus. 96 */ 97 get defaultControl() { 98 return $('tos-accept-button').disabled ? $('tos-back-button') : 99 $('tos-accept-button'); 100 }, 101 102 /** 103 * Event handler that is invoked just before the screen is shown. 104 * @param {object} data Screen init payload. 105 */ 106 onBeforeShow: function(data) { 107 Oobe.getInstance().headerHidden = true; 108 } 109 }; 110}); 111 112