summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/chromeos/login/oobe_screen_enable_debugging.js
blob: a1b70bb18039e59886dcb4285828cabdb929170e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * @fileoverview Enable developer features screen implementation.
 */

login.createScreen('EnableDebuggingScreen', 'debugging', function() {
  return {

    /* Possible UI states of the enable debugging screen. */
    UI_STATE: {
      ERROR: -1,
      NONE: 0,
      REMOVE_PROTECTION: 1,
      SETUP: 2,
      WAIT: 3,
      DONE: 4
    },

    EXTERNAL_API: [
      'updateState'
    ],

    /** @override */
    decorate: function() {
      $('enable-debugging-help-link').addEventListener('click',
        function(event) {
          chrome.send('enableDebuggingOnLearnMore');
      });

      var password = $('enable-debugging-password');
      var password2 = $('enable-debugging-password2');
      password.addEventListener('input', this.onPasswordChanged_.bind(this));
      password2.addEventListener('input', this.onPasswordChanged_.bind(this));
      password.placeholder =
          loadTimeData.getString('enableDebuggingPasswordLabel');
      password2.placeholder =
          loadTimeData.getString('enableDebuggingConfirmPasswordLabel');
    },

    /**
     * Header text of the screen.
     * @type {string}
     */
    get header() {
      return loadTimeData.getString('enableDebuggingScreenTitle');
    },

    /**
     * Buttons in oobe wizard's button strip.
     * @type {array} Array of Buttons.
     */
    get buttons() {
      var buttons = [];
      var rootfsRemoveButton = this.ownerDocument.createElement('button');
      rootfsRemoveButton.id = 'debugging-remove-protection-button';
      rootfsRemoveButton.textContent =
          loadTimeData.getString('enableDebuggingRemoveButton');
      rootfsRemoveButton.addEventListener('click', function(e) {
        chrome.send('enableDebuggingOnRemoveRootFSProtection');
        e.stopPropagation();
      });
      buttons.push(rootfsRemoveButton);

      var enableButton = this.ownerDocument.createElement('button');
      enableButton.id = 'debugging-enable-button';
      enableButton.textContent =
          loadTimeData.getString('enableDebuggingEnableButton');
      enableButton.addEventListener('click', function(e) {
        chrome.send('enableDebuggingOnSetup',
                    [$('enable-debugging-password').value]);
        e.stopPropagation();
      });
      buttons.push(enableButton);

      var cancelButton = this.ownerDocument.createElement('button');
      cancelButton.id = 'debugging-cancel-button';
      cancelButton.textContent =
          loadTimeData.getString('enableDebuggingCancelButton');
      cancelButton.addEventListener('click', function(e) {
        chrome.send('enableDebuggingOnCancel');
        e.stopPropagation();
      });
      buttons.push(cancelButton);

      var okButton = this.ownerDocument.createElement('button');
      okButton.id = 'debugging-ok-button';
      okButton.textContent =
          loadTimeData.getString('enableDebuggingOKButton');
      okButton.addEventListener('click', function(e) {
        chrome.send('enableDebuggingOnDone');
        e.stopPropagation();
      });
      buttons.push(okButton);

      return buttons;
    },

    /**
     * Returns a control which should receive an initial focus.
     */
    get defaultControl() {
      if (this.state_ == this.UI_STATE.REMOVE_PROTECTION)
        return $('debugging-remove-protection-button');
      else if (this.state_ == this.UI_STATE.SETUP)
        return $('enable-debugging-password');
      else if (this.state_ == this.UI_STATE.DONE ||
               this.state_ == this.UI_STATE.ERROR) {
        return $('debugging-ok-button');
      }

      return $('debugging-cancel-button');
    },

    /**
     * Cancels the enable debugging screen and drops the user back to the
     * network settings.
     */
    cancel: function() {
      chrome.send('enableDebuggingOnCancel');
    },

    /**
     * Event handler that is invoked just before the screen in shown.
     * @param {Object} data Screen init payload.
     */
    onBeforeShow: function(data) {
      this.setDialogView_(this.UI_STATE.NONE);
    },

    onPasswordChanged_: function() {
      var enableButton = $('debugging-enable-button');
      var password = $('enable-debugging-password');
      var password2 = $('enable-debugging-password2');
      var pwd = password.value;
      var pwd2 = password2.value;
      enableButton.disabled = !((pwd.length == 0 && pwd2.length == 0) ||
          (pwd == pwd2 && pwd.length >= 4));
    },

    /**
      * Sets css style for corresponding state of the screen.
      * @param {number} state.
      * @private
      */
    setDialogView_: function(state) {
      this.state_ = state;
      this.classList.toggle('remove-protection-view',
          state == this.UI_STATE.REMOVE_PROTECTION);
      this.classList.toggle('setup-view', state == this.UI_STATE.SETUP);
      this.classList.toggle('wait-view', state == this.UI_STATE.WAIT);
      this.classList.toggle('done-view', state == this.UI_STATE.DONE);
      this.classList.toggle('error-view', state == this.UI_STATE.ERROR);
      this.defaultControl.focus();

      if (Oobe.getInstance().currentScreen === this)
        Oobe.getInstance().updateScreenSize(this);
    },

    updateState: function(state) {
      this.setDialogView_(state);
    }
  };
});