1// Copyright 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 reset screen implementation.
7 */
8
9login.createScreen('AutolaunchScreen', 'autolaunch', function() {
10  return {
11    EXTERNAL_API: ['updateApp', 'confirmAutoLaunchForTesting'],
12    /**
13     * Header text of the screen.
14     * @type {string}
15     */
16    get header() {
17      return loadTimeData.getString('autolaunchTitle');
18    },
19
20    /**
21     * Buttons in oobe wizard's button strip.
22     * @type {array} Array of Buttons.
23     */
24    get buttons() {
25      var buttons = [];
26
27      var confirmButton = this.ownerDocument.createElement('button');
28      confirmButton.id = 'autolaunch-confirm-button';
29      confirmButton.textContent =
30        loadTimeData.getString('autolaunchConfirmButton');
31      confirmButton.addEventListener('click', function(e) {
32        chrome.send('autolaunchOnConfirm');
33        e.stopPropagation();
34      });
35      buttons.push(confirmButton);
36
37      var cancelButton = this.ownerDocument.createElement('button');
38      cancelButton.id = 'autolaunch-cancel-button';
39      cancelButton.textContent =
40          loadTimeData.getString('autolaunchCancelButton');
41      cancelButton.addEventListener('click', function(e) {
42        chrome.send('autolaunchOnCancel');
43        e.stopPropagation();
44      });
45      buttons.push(cancelButton);
46      return buttons;
47    },
48
49    /**
50     * Event handler invoked when the page is shown and ready.
51     */
52    onBeforeShow: function() {
53      chrome.send('autolaunchVisible');
54    },
55
56    /**
57     * Returns a control which should receive an initial focus.
58     */
59    get defaultControl() {
60      return $('autolaunch-cancel-button');
61    },
62
63    /**
64     * Cancels the reset and drops the user back to the login screen.
65     */
66    cancel: function() {
67      chrome.send('autolaunchOnCancel');
68    },
69
70    /**
71     * Sets app to be displayed in the auto-launch warning.
72     * @param {!Object} app An dictionary with app info.
73     */
74    updateApp: function(app) {
75      if (app.appIconUrl && app.appIconUrl.length)
76        $('autolaunch-app-icon').src = app.appIconUrl;
77
78      $('autolaunch-app-name').innerText = app.appName;
79    },
80
81    /**
82     * Initiates confirm/cancel response for testing.
83     * @param {boolean} confirm True if the screen should confirm auto-launch.
84     */
85    confirmAutoLaunchForTesting: function(confirm) {
86      var button = confirm ? $('autolaunch-confirm-button') :
87                             $('autolaunch-cancel-button');
88      var clickEvent = cr.doc.createEvent('Event');
89      clickEvent.initEvent('click', true, true);
90      button.dispatchEvent(clickEvent);
91    }
92  };
93});
94
95
96
97