OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 5 |
6 // Network status constants. | 6 // Network status constants. |
7 const StatusConnected = 'connected'; | 7 const StatusConnected = 'connected'; |
8 const StatusDisconnected = 'disconnected'; | 8 const StatusDisconnected = 'disconnected'; |
9 const StatusConnecting = 'connecting'; | 9 const StatusConnecting = 'connecting'; |
10 const StatusError = 'error'; | 10 const StatusError = 'error'; |
(...skipping 13 matching lines...) Expand all Loading... | |
24 ctx.strokeStyle = '#4e73c7'; | 24 ctx.strokeStyle = '#4e73c7'; |
25 ctx.beginPath(); | 25 ctx.beginPath(); |
26 ctx.moveTo(lineWidth / 2, r - lineWidth / 2); | 26 ctx.moveTo(lineWidth / 2, r - lineWidth / 2); |
27 ctx.arc(r, r, r - lineWidth / 2, Math.PI, Math.PI * 3 / 2); | 27 ctx.arc(r, r, r - lineWidth / 2, Math.PI, Math.PI * 3 / 2); |
28 ctx.stroke(); | 28 ctx.stroke(); |
29 })(); | 29 })(); |
30 | 30 |
31 /** | 31 /** |
32 * Sends "connect" using the 'action' DOMUI message. | 32 * Sends "connect" using the 'action' DOMUI message. |
33 */ | 33 */ |
34 function sendConnect(index, passphrase, identity, remember) { | 34 function sendConnect(index, passphrase, identity, auto_connect) { |
35 chrome.send('action', | 35 chrome.send('action', |
36 ['connect', | 36 ['connect', |
37 String(index), | 37 String(index), |
38 passphrase, | 38 passphrase, |
39 identity, | 39 identity, |
40 remember ? '1' : '0']); | 40 auto_connect ? '1' : '0']); |
41 } | 41 } |
42 | 42 |
43 var networkMenuItemProto = (function() { | 43 var networkMenuItemProto = (function() { |
44 var networkMenuItem = cr.doc.createElement('div'); | 44 var networkMenuItem = cr.doc.createElement('div'); |
45 networkMenuItem.innerHTML = '<div class="network-menu-item">' + | 45 networkMenuItem.innerHTML = '<div class="network-menu-item">' + |
46 '<div class="network-label-icon">' + | 46 '<div class="network-label-icon">' + |
47 '<div class="network-label"></div>' + | 47 '<div class="network-label"></div>' + |
48 '<div class="network-icon hidden"></div>' + | 48 '<div class="network-icon hidden"></div>' + |
49 '</div>' + | 49 '</div>' + |
50 '<div class="network-status hidden"></div>' + | 50 '<div class="network-status hidden"></div>' + |
51 '<div class="hidden"></div>' + | 51 '<div class="hidden"></div>' + |
52 '</div>'; | 52 '</div>'; |
53 return networkMenuItem; | 53 return networkMenuItem; |
54 })(); | 54 })(); |
55 | 55 |
56 var NetworkMenuItem = cr.ui.define(function() { | 56 var NetworkMenuItem = cr.ui.define(function() { |
57 return networkMenuItemProto.cloneNode(true); | 57 return networkMenuItemProto.cloneNode(true); |
58 }); | 58 }); |
59 | 59 |
60 NetworkMenuItem.prototype = { | 60 NetworkMenuItem.prototype = { |
61 __proto__: MenuItem.prototype, | 61 __proto__: MenuItem.prototype, |
62 | 62 |
63 ssidEdit: null, | 63 ssidEdit: null, |
64 passwordEdit: null, | 64 passwordEdit: null, |
65 rememberCheckbox: null, | 65 autoConnectCheckbox: null, |
66 | 66 |
67 /** | 67 /** |
68 * The label element. | 68 * The label element. |
69 * @private | 69 * @private |
70 */ | 70 */ |
71 get label_() { | 71 get label_() { |
72 return this.firstElementChild.firstElementChild.firstElementChild; | 72 return this.firstElementChild.firstElementChild.firstElementChild; |
73 }, | 73 }, |
74 | 74 |
75 /** | 75 /** |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 * Handle reconnect. | 128 * Handle reconnect. |
129 * @private | 129 * @private |
130 */ | 130 */ |
131 handleConnect_ : function(e) { | 131 handleConnect_ : function(e) { |
132 var index = this.menu_.getMenuItemIndexOf(this); | 132 var index = this.menu_.getMenuItemIndexOf(this); |
133 if (this.ssidEdit && this.passwordEdit) { | 133 if (this.ssidEdit && this.passwordEdit) { |
134 if (this.ssidEdit.value) { | 134 if (this.ssidEdit.value) { |
135 sendConnect(index, | 135 sendConnect(index, |
136 this.passwordEdit.value, | 136 this.passwordEdit.value, |
137 this.ssidEdit.value, | 137 this.ssidEdit.value, |
138 this.rememberCheckbox.checked); | 138 this.autoConnectCheckbox.checked); |
139 } | 139 } |
140 } else if (this.passwordEdit) { | 140 } else if (this.passwordEdit) { |
141 if (this.passwordEdit.value) { | 141 if (this.passwordEdit.value) { |
142 sendConnect(index, | 142 sendConnect(index, |
143 this.passwordEdit.value, '', this.rememberCheckbox.checked); | 143 this.passwordEdit.value, '', this.autoConnectCheckbox.checked); |
144 } | 144 } |
145 } else { | 145 } else { |
146 if (this.attrs.remembered) { | 146 if (this.attrs.auto_connect) { |
Charlie Lee
2010/11/15 19:42:52
I think this logic here needs to be updated. We do
kochi
2010/11/16 05:47:24
Good catch.
If the network is remembered, we do no
| |
147 sendConnect(index, this.attrs.passphrase, '', | 147 sendConnect(index, this.attrs.passphrase, '', |
148 this.rememberCheckbox.checked); | 148 this.autoConnectCheckbox.checked); |
149 } else { | 149 } else { |
150 sendConnect(index, '', '', this.rememberCheckbox.checked); | 150 sendConnect(index, '', '', this.autoConnectCheckbox.checked); |
151 } | 151 } |
152 } | 152 } |
153 }, | 153 }, |
154 | 154 |
155 /** | 155 /** |
156 * Handle keydown event in ssid edit. | 156 * Handle keydown event in ssid edit. |
157 * @private | 157 * @private |
158 */ | 158 */ |
159 handleSsidEditKeydown_: function(e) { | 159 handleSsidEditKeydown_: function(e) { |
160 if (e.target == this.ssidEdit && | 160 if (e.target == this.ssidEdit && |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 this.passwordEdit.pattern = '^\\S+$'; | 223 this.passwordEdit.pattern = '^\\S+$'; |
224 this.passwordEdit.addEventListener('keydown', | 224 this.passwordEdit.addEventListener('keydown', |
225 this.handlePassEditKeydown_.bind(this)); | 225 this.handlePassEditKeydown_.bind(this)); |
226 | 226 |
227 var box = this.ownerDocument.createElement('div'); | 227 var box = this.ownerDocument.createElement('div'); |
228 box.appendChild(this.passwordEdit); | 228 box.appendChild(this.passwordEdit); |
229 this.action_.appendChild(box); | 229 this.action_.appendChild(box); |
230 }, | 230 }, |
231 | 231 |
232 /** | 232 /** |
233 * Add remember this network check box to action area. | 233 * Add auto-connect this network check box to action area. |
234 * @private | 234 * @private |
235 */ | 235 */ |
236 addRememberCheckbox_: function() { | 236 addAutoConnectCheckbox_: function() { |
237 this.rememberCheckbox = this.ownerDocument.createElement('input'); | 237 this.autoConnectCheckbox = this.ownerDocument.createElement('input'); |
238 this.rememberCheckbox.type = 'checkbox'; | 238 this.autoConnectCheckbox.type = 'checkbox'; |
239 this.rememberCheckbox.checked = this.attrs.remembered; | 239 this.autoConnectCheckbox.checked = this.attrs.auto_connect; |
240 | 240 |
241 var rememberSpan = this.ownerDocument.createElement('span'); | 241 var autoConnectSpan = this.ownerDocument.createElement('span'); |
242 rememberSpan.textContent = localStrings.getString('remeber_this_network'); | 242 autoConnectSpan.textContent = |
243 localStrings.getString('auto_connect_this_network'); | |
243 | 244 |
244 var rememberLabel = this.ownerDocument.createElement('label'); | 245 var autoConnectLabel = this.ownerDocument.createElement('label'); |
245 rememberLabel.appendChild(this.rememberCheckbox); | 246 autoConnectLabel.appendChild(this.autoConnectCheckbox); |
246 rememberLabel.appendChild(rememberSpan); | 247 autoConnectLabel.appendChild(autoConnectSpan); |
247 | 248 |
248 this.action_.appendChild(rememberLabel); | 249 this.action_.appendChild(autoConnectLabel); |
249 }, | 250 }, |
250 | 251 |
251 /** | 252 /** |
252 * Internal method to initiailze the MenuItem. | 253 * Internal method to initiailze the MenuItem. |
253 * @private | 254 * @private |
254 */ | 255 */ |
255 initMenuItem_: function() { | 256 initMenuItem_: function() { |
256 // *TODO: eliminate code duplication with menu.js | 257 // *TODO: eliminate code duplication with menu.js |
257 // MenuItem.prototype.initMenuItem_(); | 258 // MenuItem.prototype.initMenuItem_(); |
258 var attrs = this.attrs; | 259 var attrs = this.attrs; |
259 this.classList.add(attrs.type); | 260 this.classList.add(attrs.type); |
260 this.menu_.addHandlers(this, this); | 261 this.menu_.addHandlers(this, this); |
261 | 262 |
262 //////// NetworkMenuItem specific code: | 263 //////// NetworkMenuItem specific code: |
263 // TODO: Handle specific types of network, connecting icon. | 264 // TODO: Handle specific types of network, connecting icon. |
264 this.label_.textContent = attrs.label; | 265 this.label_.textContent = attrs.label; |
265 | 266 |
266 if (attrs.network_type == NetworkOther) { | 267 if (attrs.network_type == NetworkOther) { |
267 this.addSsidEdit_(); | 268 this.addSsidEdit_(); |
268 this.addPasswordEdit_(); | 269 this.addPasswordEdit_(); |
269 this.addRememberCheckbox_(); | 270 this.addAutoConnectCheckbox_(); |
270 } else if (attrs.status && attrs.status != 'unknown') { | 271 } else if (attrs.status && attrs.status != 'unknown') { |
271 if (attrs.status == StatusConnected) { | 272 if (attrs.status == StatusConnected) { |
272 this.setStatus_(attrs.ip_address); | 273 this.setStatus_(attrs.ip_address); |
273 } else if (attrs.status == StatusConnecting) { | 274 } else if (attrs.status == StatusConnecting) { |
274 this.setStatus_(attrs.message); | 275 this.setStatus_(attrs.message); |
275 | 276 |
276 this.icon_.classList.add('spinner'); | 277 this.icon_.classList.add('spinner'); |
277 this.icon_.classList.remove('hidden'); | 278 this.icon_.classList.remove('hidden'); |
278 } else if (attrs.status == StatusError) { | 279 } else if (attrs.status == StatusError) { |
279 this.setStatus_(attrs.message); | 280 this.setStatus_(attrs.message); |
280 this.setIcon_('chrome://theme/IDR_WARNING'); | 281 this.setIcon_('chrome://theme/IDR_WARNING'); |
281 | 282 |
282 var button = this.ownerDocument.createElement('button'); | 283 var button = this.ownerDocument.createElement('button'); |
283 button.textContent = localStrings.getString('reconnect'); | 284 button.textContent = localStrings.getString('reconnect'); |
284 button.addEventListener('click', this.handleConnect_.bind(this)); | 285 button.addEventListener('click', this.handleConnect_.bind(this)); |
285 var box = this.ownerDocument.createElement('div'); | 286 var box = this.ownerDocument.createElement('div'); |
286 box.appendChild(button); | 287 box.appendChild(button); |
287 this.action_.appendChild(box); | 288 this.action_.appendChild(box); |
288 | 289 |
289 this.showAction_(true); | 290 this.showAction_(true); |
290 } | 291 } |
291 | 292 |
292 if (attrs.need_passphrase) { | 293 if (attrs.need_passphrase) { |
293 this.addPasswordEdit_(); | 294 this.addPasswordEdit_(); |
294 } | 295 } |
295 | 296 |
296 this.addRememberCheckbox_(); | 297 this.addAutoConnectCheckbox_(); |
297 } | 298 } |
298 //////// End NetworkMenuItem specifi code | 299 //////// End NetworkMenuItem specifi code |
299 | 300 |
300 if (attrs.font) { | 301 if (attrs.font) { |
301 this.label_.style.font = attrs.font; | 302 this.label_.style.font = attrs.font; |
302 | 303 |
303 var base_font = attrs.font.replace(/bold/, '').replace(/italic/, ''); | 304 var base_font = attrs.font.replace(/bold/, '').replace(/italic/, ''); |
304 this.status_.style.font = base_font; | 305 this.status_.style.font = base_font; |
305 this.action_.style.font = base_font; | 306 this.action_.style.font = base_font; |
306 } | 307 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 if (attrs.type == 'command') { | 340 if (attrs.type == 'command') { |
340 return new NetworkMenuItem(); | 341 return new NetworkMenuItem(); |
341 } else { | 342 } else { |
342 return new MenuItem(); | 343 return new MenuItem(); |
343 } | 344 } |
344 }, | 345 }, |
345 | 346 |
346 /** @inheritDoc */ | 347 /** @inheritDoc */ |
347 onClick_: function(event, item) { | 348 onClick_: function(event, item) { |
348 // If item is a NetworkMenuItem, it must have at least one of the following. | 349 // If item is a NetworkMenuItem, it must have at least one of the following. |
349 if (item.rememberCheckbox || item.ssidEdit || item.passwordEdit) { | 350 if (item.autoConnectCheckbox || item.ssidEdit || item.passwordEdit) { |
350 // Ignore clicks other than on the NetworkMenuItem itself. | 351 // Ignore clicks other than on the NetworkMenuItem itself. |
351 if (event.target == item.rememberCheckbox || | 352 if (event.target == item.autoConnectCheckbox || |
352 event.target == item.rememberCheckbox.nextElementSibling || | 353 event.target == item.autoConnectCheckbox.nextElementSibling || |
353 event.target == item.ssidEdit || | 354 event.target == item.ssidEdit || |
354 event.target == item.passwordEdit) { | 355 event.target == item.passwordEdit) { |
355 return; | 356 return; |
356 } | 357 } |
357 } | 358 } |
358 | 359 |
359 Menu.prototype.onClick_.call(this, event, item); | 360 Menu.prototype.onClick_.call(this, event, item); |
360 }, | 361 }, |
361 }; | 362 }; |
OLD | NEW |