Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: chrome/browser/resources/options/chromeos_internet_network_element.js

Issue 4237001: Add support for different type of encyrption when adding a network.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 cr.define('options.internet', function() { 5 cr.define('options.internet', function() {
6 /** 6 /**
7 * Creates a new network list div. 7 * Creates a new network list div.
8 * @param {Object=} opt_propertyBag Optional properties. 8 * @param {Object=} opt_propertyBag Optional properties.
9 * @constructor 9 * @constructor
10 * @extends {HTMLDivElement} 10 * @extends {HTMLDivElement}
(...skipping 30 matching lines...) Expand all
41 // We shouldn't respond to click events selecting an input, 41 // We shouldn't respond to click events selecting an input,
42 // so return on those. 42 // so return on those.
43 if (e.target.tagName == 'INPUT') { 43 if (e.target.tagName == 'INPUT') {
44 return; 44 return;
45 } 45 }
46 // Handle left button click 46 // Handle left button click
47 if (e.button == 0) { 47 if (e.button == 0) {
48 var el = e.target; 48 var el = e.target;
49 // If click is on action buttons of a network item. 49 // If click is on action buttons of a network item.
50 if (!(el.buttonType && el.networkType && el.servicePath)) { 50 if (!(el.buttonType && el.networkType && el.servicePath)) {
51 if (el.className == 'other-network' || el.buttonType) { 51 if (el.buttonType) {
52 return; 52 return;
53 } 53 }
54 // If click is on a network item or its label, walk up the DOM tree 54 // If click is on a network item or its label, walk up the DOM tree
55 // to find the network item. 55 // to find the network item.
56 var item = el; 56 var item = el;
57 while (item && !item.data) { 57 while (item && !item.data) {
58 item = item.parentNode; 58 item = item.parentNode;
59 } 59 }
60 if (item.connecting) 60 if (item.connecting)
61 return; 61 return;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 NetworkItem.decorate = function(el) { 137 NetworkItem.decorate = function(el) {
138 el.__proto__ = NetworkItem.prototype; 138 el.__proto__ = NetworkItem.prototype;
139 el.decorate(); 139 el.decorate();
140 }; 140 };
141 141
142 NetworkItem.prototype = { 142 NetworkItem.prototype = {
143 __proto__: HTMLDivElement.prototype, 143 __proto__: HTMLDivElement.prototype,
144 144
145 /** @inheritDoc */ 145 /** @inheritDoc */
146 decorate: function() { 146 decorate: function() {
147 var isOtherNetworksItem = this.data.servicePath == '?';
148
149 this.className = 'network-item'; 147 this.className = 'network-item';
150 this.connected = this.data.connected; 148 this.connected = this.data.connected;
149 this.other = this.data.servicePath == '?';
151 this.id = this.data.servicePath; 150 this.id = this.data.servicePath;
152 // textDiv holds icon, name and status text. 151 // textDiv holds icon, name and status text.
153 var textDiv = this.ownerDocument.createElement('div'); 152 var textDiv = this.ownerDocument.createElement('div');
154 textDiv.className = 'network-item-text'; 153 textDiv.className = 'network-item-text';
155 if (this.data.iconURL) { 154 if (this.data.iconURL) {
156 textDiv.style.backgroundImage = url(this.data.iconURL); 155 textDiv.style.backgroundImage = url(this.data.iconURL);
157 } 156 }
158 157
159 var nameEl = this.ownerDocument.createElement('div'); 158 var nameEl = this.ownerDocument.createElement('div');
160 nameEl.className = 'network-name-label'; 159 nameEl.className = 'network-name-label';
161 nameEl.textContent = this.data.networkName; 160 nameEl.textContent = this.data.networkName;
162 textDiv.appendChild(nameEl); 161 textDiv.appendChild(nameEl);
163 162
164 if (isOtherNetworksItem) { 163 if (this.other) {
165 // No status and buttons for "Other..." 164 // No status and buttons for "Other..."
166 this.appendChild(textDiv); 165 this.appendChild(textDiv);
167 return; 166 return;
168 } 167 }
169 168
170 // Only show status text for networks other than "remembered". 169 // Only show status text for networks other than "remembered".
171 if (!this.data.remembered) { 170 if (!this.data.remembered) {
172 var statusEl = this.ownerDocument.createElement('div'); 171 var statusEl = this.ownerDocument.createElement('div');
173 statusEl.className = 'network-status-label'; 172 statusEl.className = 'network-status-label';
174 statusEl.textContent = this.data.networkStatus; 173 statusEl.textContent = this.data.networkStatus;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 if (target.checked) { 290 if (target.checked) {
292 target.target.type = 'text'; 291 target.target.type = 'text';
293 } else { 292 } else {
294 target.target.type = 'password'; 293 target.target.type = 'password';
295 } 294 }
296 }, 295 },
297 296
298 hidePassword: function() { 297 hidePassword: function() {
299 this.connecting = false; 298 this.connecting = false;
300 var children = this.childNodes; 299 var children = this.childNodes;
301 for (var i = 0; i < children.length; i++) { 300 // Remove all password divs starting from the end.
302 if (children[i].className == 'network-password' || 301 for (var i = children.length-1; i >= 0; i--) {
303 children[i].className == 'other-network') { 302 if (children[i].className == 'network-password') {
304 this.removeChild(children[i]); 303 this.removeChild(children[i]);
305 return;
306 } 304 }
307 } 305 }
308 }, 306 },
309 307
310 showOtherLogin: function() { 308 showOtherLogin: function() {
311 if (this.connecting) 309 if (this.connecting)
312 return; 310 return;
313 var passwordDiv = this.ownerDocument.createElement('div'); 311
314 passwordDiv.className = 'other-network'; 312 var ssidDiv = this.ownerDocument.createElement('div');
313 ssidDiv.className = 'network-password';
315 var ssidInput = this.ownerDocument.createElement('input'); 314 var ssidInput = this.ownerDocument.createElement('input');
316 ssidInput.placeholder = localStrings.getString('inetSsidPrompt'); 315 ssidInput.placeholder = localStrings.getString('inetSsidPrompt');
317 passwordDiv.appendChild(ssidInput); 316 ssidDiv.appendChild(ssidInput);
317
318 var securityDiv = this.ownerDocument.createElement('div');
319 securityDiv.className = 'network-password';
320 var securityInput = this.ownerDocument.createElement('select');
321 var securityNoneOption = this.ownerDocument.createElement('option');
322 securityNoneOption.value = 'none';
323 securityNoneOption.label = localStrings.getString('inetSecurityNone');
324 securityInput.appendChild(securityNoneOption);
325 var securityWEPOption = this.ownerDocument.createElement('option');
326 securityWEPOption.value = 'wep';
327 securityWEPOption.label = localStrings.getString('inetSecurityWEP');
328 securityInput.appendChild(securityWEPOption);
329 var securityWPAOption = this.ownerDocument.createElement('option');
330 securityWPAOption.value = 'wpa';
331 securityWPAOption.label = localStrings.getString('inetSecurityWPA');
332 securityInput.appendChild(securityWPAOption);
333 var securityRSNOption = this.ownerDocument.createElement('option');
334 securityRSNOption.value = 'rsn';
335 securityRSNOption.label = localStrings.getString('inetSecurityRSN');
336 securityInput.appendChild(securityRSNOption);
337 securityDiv.appendChild(securityInput);
338
339 var passwordDiv = this.ownerDocument.createElement('div');
340 passwordDiv.className = 'network-password';
318 var passInput = this.ownerDocument.createElement('input'); 341 var passInput = this.ownerDocument.createElement('input');
319 passInput.placeholder = localStrings.getString('inetPassPrompt'); 342 passInput.placeholder = localStrings.getString('inetPassPrompt');
320 passInput.type = 'password'; 343 passInput.type = 'password';
344 passInput.disabled = true;
321 passwordDiv.appendChild(passInput); 345 passwordDiv.appendChild(passInput);
322 346
323 var togglePassLabel = this.ownerDocument.createElement('label'); 347 var togglePassLabel = this.ownerDocument.createElement('label');
324 togglePassLabel.style.display = 'inline'; 348 togglePassLabel.style.display = 'inline';
325 var togglePassSpan = this.ownerDocument.createElement('span'); 349 var togglePassSpan = this.ownerDocument.createElement('span');
326 var togglePassCheckbox = this.ownerDocument.createElement('input'); 350 var togglePassCheckbox = this.ownerDocument.createElement('input');
327 togglePassCheckbox.type = 'checkbox'; 351 togglePassCheckbox.type = 'checkbox';
328 togglePassCheckbox.checked = false; 352 togglePassCheckbox.checked = false;
329 togglePassCheckbox.target = passInput; 353 togglePassCheckbox.target = passInput;
330 togglePassCheckbox.addEventListener('change', this.handleShowPass_); 354 togglePassCheckbox.addEventListener('change', this.handleShowPass_);
331 togglePassSpan.textContent = localStrings.getString('inetShowPass'); 355 togglePassSpan.textContent = localStrings.getString('inetShowPass');
332 togglePassLabel.appendChild(togglePassCheckbox); 356 togglePassLabel.appendChild(togglePassCheckbox);
333 togglePassLabel.appendChild(togglePassSpan); 357 togglePassLabel.appendChild(togglePassSpan);
334 passwordDiv.appendChild(togglePassLabel); 358 passwordDiv.appendChild(togglePassLabel);
335 359
336 var buttonEl = this.ownerDocument.createElement('button'); 360 var buttonEl =
337 buttonEl.textContent = localStrings.getString('inetLogin'); 361 this.createButton_('inetLogin', true, this.handleOtherLogin_);
338 buttonEl.buttonType = true;
339 buttonEl.addEventListener('click', this.handleOtherLogin_);
340 buttonEl.style.right = '0'; 362 buttonEl.style.right = '0';
341 buttonEl.style.position = 'absolute'; 363 buttonEl.style.position = 'absolute';
342 buttonEl.style.visibility = 'visible'; 364 buttonEl.style.visibility = 'visible';
365 buttonEl.disabled = true;
343 passwordDiv.appendChild(buttonEl); 366 passwordDiv.appendChild(buttonEl);
367
368 this.appendChild(ssidDiv);
369 this.appendChild(securityDiv);
344 this.appendChild(passwordDiv); 370 this.appendChild(passwordDiv);
345 371
346 ssidInput.addEventListener('keydown', function(e) { 372 securityInput.addEventListener('change', function(e) {
347 buttonEl.disabled = 373 // If changed to None, then disable passInput and clear it out.
348 ssidInput.value.length < NetworkItem.MIN_WIRELESS_SSID_LENGTH; 374 // Otherwise enable it.
375 if (securityInput.value == 'none') {
376 passInput.disabled = true;
377 passInput.value = '';
378 } else {
379 passInput.disabled = false;
380 }
349 }); 381 });
382
383 var keyup_listener = function(e) {
384 // Disable login button if ssid is not long enough or
385 // password is not long enough (unless no security)
386 var ssid_good =
387 ssidInput.value.length >= NetworkItem.MIN_WIRELESS_SSID_LENGTH;
388 var pass_good =
389 securityInput.value == 'none' ||
390 passInput.value.length >= NetworkItem.MIN_WIRELESS_PASSWORD_LENGTH;
391 buttonEl.disabled = !ssid_good || !pass_good;
392 };
393 ssidInput.addEventListener('keyup', keyup_listener);
394 securityInput.addEventListener('change', keyup_listener);
395 passInput.addEventListener('keyup', keyup_listener);
350 this.connecting = true; 396 this.connecting = true;
351 }, 397 },
352 398
353 handleLogin_: function(e) { 399 handleLogin_: function(e) {
354 var el = e.target; 400 var el = e.target;
355 var parent = el.parentNode; 401 var parent = el.parentNode;
356 el.disabled = true; 402 el.disabled = true;
357 var input = parent.firstChild; 403 var input = parent.firstChild;
358 input.disabled = true; 404 input.disabled = true;
359 chrome.send('loginToNetwork', [el.servicePath, input.value]); 405 chrome.send('loginToNetwork', [el.servicePath, input.value]);
360 }, 406 },
361 407
362 handleOtherLogin_: function(e) { 408 handleOtherLogin_: function(e) {
363 var el = e.target; 409 var el = e.target;
364 var parent = el.parentNode; 410 var parent = el.parentNode.parentNode;
365 el.disabled = true; 411 el.disabled = true;
366 var ssid = parent.childNodes[0]; 412 var ssid = parent.childNodes[1].firstChild;
367 var pass = parent.childNodes[1]; 413 var sec = parent.childNodes[2].firstChild;
414 var pass = parent.childNodes[3].firstChild;
415 sec.disabled = true;
368 ssid.disabled = true; 416 ssid.disabled = true;
369 pass.disabled = true; 417 pass.disabled = true;
370 chrome.send('loginToNetwork', [ssid.value, pass.value]); 418 chrome.send('loginToOtherNetwork', [sec.value, ssid.value, pass.value]);
371 }, 419 },
372 420
373 /** 421 /**
374 * Creates a button for interacting with a network. 422 * Creates a button for interacting with a network.
375 * @param {Object} name The name of the localStrings to use for the text. 423 * @param {Object} name The name of the localStrings to use for the text.
376 * @param {Object} type The type of button. 424 * @param {Object} type The type of button.
377 */ 425 */
378 createButton_: function(name, type, callback) { 426 createButton_: function(name, type, callback) {
379 var buttonEl = this.ownerDocument.createElement('button'); 427 var buttonEl = this.ownerDocument.createElement('button');
380 buttonEl.buttonType = type; 428 buttonEl.buttonType = type;
381 buttonEl.textContent = localStrings.getString(name); 429 buttonEl.textContent = localStrings.getString(name);
382 buttonEl.addEventListener('click', callback); 430 buttonEl.addEventListener('click', callback);
383 return buttonEl; 431 return buttonEl;
384 } 432 }
385 }; 433 };
386 434
387 /** 435 /**
388 * Whether the underlying network is connected. Only used for display purpose. 436 * Whether the underlying network is connected. Only used for display purpose.
389 * @type {boolean} 437 * @type {boolean}
390 */ 438 */
391 cr.defineProperty(NetworkItem, 'connected', cr.PropertyKind.BOOL_ATTR); 439 cr.defineProperty(NetworkItem, 'connected', cr.PropertyKind.BOOL_ATTR);
392 440
393 /** 441 /**
394 * Whether the underlying network is currently connecting. 442 * Whether the underlying network is currently connecting.
395 * Only used for display purpose. 443 * Only used for display purpose.
396 * @type {boolean} 444 * @type {boolean}
397 */ 445 */
398 cr.defineProperty(NetworkItem, 'connecting', cr.PropertyKind.BOOL_ATTR); 446 cr.defineProperty(NetworkItem, 'connecting', cr.PropertyKind.BOOL_ATTR);
399 447
448 /**
449 * Whether the underlying network is an other network for adding networks.
450 * Only used for display purpose.
451 * @type {boolean}
452 */
453 cr.defineProperty(NetworkItem, 'other', cr.PropertyKind.BOOL_ATTR);
454
400 return { 455 return {
401 NetworkElement: NetworkElement 456 NetworkElement: NetworkElement
402 }; 457 };
403 }); 458 });
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/network_menu.cc ('k') | chrome/browser/resources/options/chromeos_internet_options_page.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698