oobe_screen_eula.js revision b2df76ea8fec9e32f6f3718986dba0d95315b29c
1// Copyright (c) 2012 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 eula screen implementation.
7 */
8
9login.createScreen('EulaScreen', 'eula', function() {
10  return {
11    /** @override */
12    decorate: function() {
13      $('stats-help-link').addEventListener('click', function(event) {
14        chrome.send('eulaOnLearnMore');
15      });
16      $('installation-settings-link').addEventListener(
17          'click', function(event) {
18            chrome.send('eulaOnInstallationSettingsPopupOpened');
19            $('popup-overlay').hidden = false;
20            $('installation-settings-ok-button').focus();
21          });
22      $('installation-settings-ok-button').addEventListener(
23          'click', function(event) {
24            $('popup-overlay').hidden = true;
25          });
26      // Do not allow focus leaving the overlay.
27      $('popup-overlay').addEventListener('focusout', function(event) {
28        // WebKit does not allow immediate focus return.
29        window.setTimeout(function() {
30          // TODO(ivankr): focus cycling.
31          $('installation-settings-ok-button').focus();
32        }, 0);
33        event.preventDefault();
34      });
35    },
36
37    /**
38     * Event handler that is invoked when 'chrome://terms' is loaded.
39     */
40    onFrameLoad: function() {
41      $('accept-button').disabled = false;
42      $('eula').classList.remove('eula-loading');
43      // Initially, the back button is focused and the accept button is
44      // disabled.
45      // Move the focus to the accept button now but only if the user has not
46      // moved the focus anywhere in the meantime.
47      if (!$('back-button').blurred)
48        $('accept-button').focus();
49    },
50
51    /**
52     * Event handler that is invoked just before the screen is shown.
53     * @param {object} data Screen init payload.
54     */
55    onBeforeShow: function() {
56      $('eula').classList.add('eula-loading');
57      $('cros-eula-frame').onload = this.onFrameLoad;
58      $('accept-button').disabled = true;
59      $('cros-eula-frame').src = 'chrome://terms';
60    },
61
62    /**
63     * Header text of the screen.
64     * @type {string}
65     */
66    get header() {
67      return loadTimeData.getString('eulaScreenTitle');
68    },
69
70    /**
71     * Buttons in oobe wizard's button strip.
72     * @type {Array} Array of Buttons.
73     */
74    get buttons() {
75      var buttons = [];
76
77      var backButton = this.ownerDocument.createElement('button');
78      backButton.id = 'back-button';
79      backButton.textContent = loadTimeData.getString('back');
80      backButton.addEventListener('click', function(e) {
81        chrome.send('eulaOnExit', [false, $('usage-stats').checked]);
82        e.stopPropagation();
83      });
84      buttons.push(backButton);
85
86      var acceptButton = this.ownerDocument.createElement('button');
87      acceptButton.id = 'accept-button';
88      acceptButton.disabled = true;
89      acceptButton.classList.add('preserve-disabled-state');
90      acceptButton.textContent = loadTimeData.getString('acceptAgreement');
91      acceptButton.addEventListener('click', function(e) {
92        $('eula').classList.add('loading');  // Mark EULA screen busy.
93        chrome.send('eulaOnExit', [true, $('usage-stats').checked]);
94        e.stopPropagation();
95      });
96      buttons.push(acceptButton);
97
98      return buttons;
99    },
100
101    /**
102     * Returns a control which should receive an initial focus.
103     */
104    get defaultControl() {
105      return $('accept-button').disabled ? $('back-button') :
106                                           $('accept-button');
107    },
108
109    /**
110     * Updates localized content of the screen that is not updated via template.
111     */
112    updateLocalizedContent: function() {
113      // Force iframes to refresh. It's only available method because we have
114      // no access to iframe.contentWindow.
115      if ($('cros-eula-frame').src) {
116        $('cros-eula-frame').src = $('cros-eula-frame').src;
117      }
118      if ($('oem-eula-frame').src) {
119        $('oem-eula-frame').src = $('oem-eula-frame').src;
120      }
121    }
122  };
123});
124
125