OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 /** |
| 6 * @fileoverview Polymer element for displaying material design OOBE. |
| 7 */ |
| 8 |
5 Polymer({ | 9 Polymer({ |
6 is: 'oobe-welcome-md', | 10 is: 'oobe-welcome-md', |
7 | 11 |
8 properties: { | 12 properties: { |
9 disabled: { | 13 /** |
10 type: Boolean, | 14 * Currently selected system language. |
11 value: false, | 15 */ |
12 }, | |
13 currentLanguage: { | 16 currentLanguage: { |
14 type: String, | 17 type: String, |
15 value: 'English (US)', | 18 value: 'English (US)', |
16 }, | 19 }, |
| 20 |
| 21 /** |
| 22 * Flag that switches Welcome screen to Network Selection screen. |
| 23 */ |
| 24 networkSelectionScreenShown: { |
| 25 type: Boolean, |
| 26 value: false, |
| 27 }, |
17 }, | 28 }, |
18 | 29 |
| 30 /** |
| 31 * GUID of the user-selected network. It is remembered after user taps on |
| 32 * network entry. After we receive event "connected" on this network, |
| 33 * OOBE will proceed. |
| 34 */ |
| 35 networkLastSelectedGuid_: '', |
| 36 |
| 37 /** |
| 38 * Sets proper focus. |
| 39 */ |
19 focus: function() { | 40 focus: function() { |
20 this.$.welcomeNextButton.focus(); | 41 this.$.welcomeNextButton.focus(); |
21 }, | 42 }, |
22 | 43 |
| 44 /** |
| 45 * Handles "visible" event. |
| 46 * @private |
| 47 */ |
23 onAnimationFinish_: function() { | 48 onAnimationFinish_: function() { |
24 this.focus(); | 49 this.focus(); |
25 }, | 50 }, |
26 | 51 |
| 52 /** |
| 53 * Returns custom items for network selector. |
| 54 */ |
| 55 _getNetworkCustomItems: function() { |
| 56 var self = this; |
| 57 return [ |
| 58 { |
| 59 customItemName: 'proxySettingsMenuName', |
| 60 polymerIcon: 'oobe-welcome:add', |
| 61 customData: { |
| 62 onTap: function() { self.OpenProxySettingsDialog_(); }, |
| 63 }, |
| 64 }, |
| 65 { |
| 66 customItemName: 'addWiFiNetworkMenuName', |
| 67 polymerIcon: 'oobe-welcome:add', |
| 68 customData: { |
| 69 onTap: function() { self.OpenAddWiFiNetworkDialog_(); }, |
| 70 }, |
| 71 }, |
| 72 { |
| 73 customItemName: 'addMobileNetworkMenuName', |
| 74 polymerIcon: 'oobe-welcome:add', |
| 75 customData: { |
| 76 onTap: function() { self.OpenAddWiFiNetworkDialog_(); }, |
| 77 }, |
| 78 }, |
| 79 ]; |
| 80 }, |
| 81 |
| 82 /** |
| 83 * Handle "Next" button for "Welcome" screen. |
| 84 * |
| 85 * @private |
| 86 */ |
27 onWelcomeNextButtonClicked_: function() { | 87 onWelcomeNextButtonClicked_: function() { |
| 88 this.networkSelectionScreenShown = true; |
| 89 }, |
| 90 |
| 91 /** |
| 92 * Handle Networwork Setup screen "Proxy settings" button. |
| 93 * |
| 94 * @private |
| 95 */ |
| 96 OpenProxySettingsDialog_: function(item) { |
| 97 chrome.send('launchProxySettingsDialog'); |
| 98 }, |
| 99 |
| 100 /** |
| 101 * Handle Networwork Setup screen "Add WiFi network" button. |
| 102 * |
| 103 * @private |
| 104 */ |
| 105 OpenAddWiFiNetworkDialog_: function(item) { |
| 106 chrome.send('launchAddWiFiNetworkDialog'); |
| 107 }, |
| 108 |
| 109 /** |
| 110 * Handle Networwork Setup screen "Add cellular network" button. |
| 111 * |
| 112 * @private |
| 113 */ |
| 114 OpenAddMobileNetworkDialog_: function(item) { |
| 115 chrome.send('launchAddMobileNetworkDialog'); |
| 116 }, |
| 117 |
| 118 /** |
| 119 * This is called when network setup is done. |
| 120 * |
| 121 * @private |
| 122 */ |
| 123 onSelectedNetworkConnected_: function() { |
28 $('oobe-connect').hidden = false; | 124 $('oobe-connect').hidden = false; |
29 $('oobe-welcome-md').hidden = true; | 125 $('oobe-welcome-md').hidden = true; |
30 } | 126 }, |
| 127 |
| 128 /** |
| 129 * This gets called when a network enters the 'Connected' state. |
| 130 * |
| 131 * @param {!{detail: !CrOnc.NetworkStateProperties}} event |
| 132 * @private |
| 133 */ |
| 134 onNetworkConnected_: function(event) { |
| 135 var state = event.detail; |
| 136 if (state.GUID != this.networkLastSelectedGuid_) |
| 137 return; |
| 138 |
| 139 this.onSelectedNetworkConnected_(); |
| 140 }, |
| 141 |
| 142 /** |
| 143 * This is called when user taps on network entry in networks list. |
| 144 * |
| 145 * @param {!{detail: !CrOnc.NetworkStateProperties}} event |
| 146 * @private |
| 147 */ |
| 148 onNetworkListNetworkItemSelected_: function(event) { |
| 149 var state = event.detail; |
| 150 // If user has not previously made a selection and selected network |
| 151 // is already connected, just continue to the next screen. |
| 152 if (this.networkLastSelectedGuid_ == '' && |
| 153 state.ConnectionState == CrOnc.ConnectionState.CONNECTED) { |
| 154 this.onSelectedNetworkConnected_(); |
| 155 } |
| 156 |
| 157 // If user has previously selected another network, there |
| 158 // is pending connection attempt. So even if new selection is currently |
| 159 // connected, it may get disconnected at any time. |
| 160 // So just send one more connection request to cancel current attempts. |
| 161 this.networkLastSelectedGuid_ = state.GUID; |
| 162 |
| 163 var self = this; |
| 164 var networkStateCopy = Object.assign({}, state); |
| 165 |
| 166 chrome.networkingPrivate.startConnect(state.GUID, function() { |
| 167 var lastError = chrome.runtime.lastError; |
| 168 if (!lastError) |
| 169 return; |
| 170 |
| 171 if (lastError.message == 'connected') { |
| 172 self.onNetworkConnected_({'detail': networkStateCopy}); |
| 173 return; |
| 174 } |
| 175 |
| 176 if (lastError.message != 'connecting') |
| 177 console.error('networkingPrivate.startConnect error: ' + lastError); |
| 178 }); |
| 179 }, |
| 180 |
| 181 /** |
| 182 * @param {!Event} event |
| 183 */ |
| 184 onNetworkListCustomItemSelected_: function(e) { |
| 185 var itemState = e.detail; |
| 186 itemState.customData.onTap(); |
| 187 }, |
31 }); | 188 }); |
OLD | NEW |