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

Side by Side Diff: chrome/browser/resources/network_menu.js

Issue 4818002: Fix favorite and auto_connect property usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for comments. 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 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
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
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.remembered) {
147 sendConnect(index, this.attrs.passphrase, '', 147 sendConnect(index, this.attrs.passphrase, '', this.attrs.auto_connect);
148 this.rememberCheckbox.checked);
149 } else { 148 } else {
150 sendConnect(index, '', '', this.rememberCheckbox.checked); 149 sendConnect(index, '', '', this.autoConnectCheckbox.checked);
151 } 150 }
152 } 151 }
153 }, 152 },
154 153
155 /** 154 /**
156 * Handle keydown event in ssid edit. 155 * Handle keydown event in ssid edit.
157 * @private 156 * @private
158 */ 157 */
159 handleSsidEditKeydown_: function(e) { 158 handleSsidEditKeydown_: function(e) {
160 if (e.target == this.ssidEdit && 159 if (e.target == this.ssidEdit &&
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 this.passwordEdit.pattern = '^\\S+$'; 222 this.passwordEdit.pattern = '^\\S+$';
224 this.passwordEdit.addEventListener('keydown', 223 this.passwordEdit.addEventListener('keydown',
225 this.handlePassEditKeydown_.bind(this)); 224 this.handlePassEditKeydown_.bind(this));
226 225
227 var box = this.ownerDocument.createElement('div'); 226 var box = this.ownerDocument.createElement('div');
228 box.appendChild(this.passwordEdit); 227 box.appendChild(this.passwordEdit);
229 this.action_.appendChild(box); 228 this.action_.appendChild(box);
230 }, 229 },
231 230
232 /** 231 /**
233 * Add remember this network check box to action area. 232 * Add auto-connect this network check box to action area.
234 * @private 233 * @private
235 */ 234 */
236 addRememberCheckbox_: function() { 235 addAutoConnectCheckbox_: function() {
237 this.rememberCheckbox = this.ownerDocument.createElement('input'); 236 this.autoConnectCheckbox = this.ownerDocument.createElement('input');
238 this.rememberCheckbox.type = 'checkbox'; 237 this.autoConnectCheckbox.type = 'checkbox';
239 this.rememberCheckbox.checked = this.attrs.remembered; 238 this.autoConnectCheckbox.checked = this.attrs.auto_connect;
240 239
241 var rememberSpan = this.ownerDocument.createElement('span'); 240 var autoConnectSpan = this.ownerDocument.createElement('span');
242 rememberSpan.textContent = localStrings.getString('remeber_this_network'); 241 autoConnectSpan.textContent =
242 localStrings.getString('auto_connect_this_network');
243 243
244 var rememberLabel = this.ownerDocument.createElement('label'); 244 var autoConnectLabel = this.ownerDocument.createElement('label');
245 rememberLabel.appendChild(this.rememberCheckbox); 245 autoConnectLabel.appendChild(this.autoConnectCheckbox);
246 rememberLabel.appendChild(rememberSpan); 246 autoConnectLabel.appendChild(autoConnectSpan);
247 247
248 this.action_.appendChild(rememberLabel); 248 this.action_.appendChild(autoConnectLabel);
249 }, 249 },
250 250
251 /** 251 /**
252 * Internal method to initiailze the MenuItem. 252 * Internal method to initiailze the MenuItem.
253 * @private 253 * @private
254 */ 254 */
255 initMenuItem_: function() { 255 initMenuItem_: function() {
256 // *TODO: eliminate code duplication with menu.js 256 // *TODO: eliminate code duplication with menu.js
257 // MenuItem.prototype.initMenuItem_(); 257 // MenuItem.prototype.initMenuItem_();
258 var attrs = this.attrs; 258 var attrs = this.attrs;
259 this.classList.add(attrs.type); 259 this.classList.add(attrs.type);
260 this.menu_.addHandlers(this, this); 260 this.menu_.addHandlers(this, this);
261 261
262 //////// NetworkMenuItem specific code: 262 //////// NetworkMenuItem specific code:
263 // TODO: Handle specific types of network, connecting icon. 263 // TODO: Handle specific types of network, connecting icon.
264 this.label_.textContent = attrs.label; 264 this.label_.textContent = attrs.label;
265 265
266 if (attrs.network_type == NetworkOther) { 266 if (attrs.network_type == NetworkOther) {
267 this.addSsidEdit_(); 267 this.addSsidEdit_();
268 this.addPasswordEdit_(); 268 this.addPasswordEdit_();
269 this.addRememberCheckbox_(); 269 this.addAutoConnectCheckbox_();
270 } else if (attrs.status && attrs.status != 'unknown') { 270 } else if (attrs.status && attrs.status != 'unknown') {
271 if (attrs.status == StatusConnected) { 271 if (attrs.status == StatusConnected) {
272 this.setStatus_(attrs.ip_address); 272 this.setStatus_(attrs.ip_address);
273 } else if (attrs.status == StatusConnecting) { 273 } else if (attrs.status == StatusConnecting) {
274 this.setStatus_(attrs.message); 274 this.setStatus_(attrs.message);
275 275
276 this.icon_.classList.add('spinner'); 276 this.icon_.classList.add('spinner');
277 this.icon_.classList.remove('hidden'); 277 this.icon_.classList.remove('hidden');
278 } else if (attrs.status == StatusError) { 278 } else if (attrs.status == StatusError) {
279 this.setStatus_(attrs.message); 279 this.setStatus_(attrs.message);
280 this.setIcon_('chrome://theme/IDR_WARNING'); 280 this.setIcon_('chrome://theme/IDR_WARNING');
281 281
282 var button = this.ownerDocument.createElement('button'); 282 var button = this.ownerDocument.createElement('button');
283 button.textContent = localStrings.getString('reconnect'); 283 button.textContent = localStrings.getString('reconnect');
284 button.addEventListener('click', this.handleConnect_.bind(this)); 284 button.addEventListener('click', this.handleConnect_.bind(this));
285 var box = this.ownerDocument.createElement('div'); 285 var box = this.ownerDocument.createElement('div');
286 box.appendChild(button); 286 box.appendChild(button);
287 this.action_.appendChild(box); 287 this.action_.appendChild(box);
288 288
289 this.showAction_(true); 289 this.showAction_(true);
290 } 290 }
291 291
292 if (attrs.need_passphrase) { 292 if (attrs.need_passphrase) {
293 this.addPasswordEdit_(); 293 this.addPasswordEdit_();
294 } 294 }
295 295
296 this.addRememberCheckbox_(); 296 this.addAutoConnectCheckbox_();
297 } 297 }
298 //////// End NetworkMenuItem specifi code 298 //////// End NetworkMenuItem specifi code
299 299
300 if (attrs.font) { 300 if (attrs.font) {
301 this.label_.style.font = attrs.font; 301 this.label_.style.font = attrs.font;
302 302
303 var base_font = attrs.font.replace(/bold/, '').replace(/italic/, ''); 303 var base_font = attrs.font.replace(/bold/, '').replace(/italic/, '');
304 this.status_.style.font = base_font; 304 this.status_.style.font = base_font;
305 this.action_.style.font = base_font; 305 this.action_.style.font = base_font;
306 } 306 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 if (attrs.type == 'command') { 339 if (attrs.type == 'command') {
340 return new NetworkMenuItem(); 340 return new NetworkMenuItem();
341 } else { 341 } else {
342 return new MenuItem(); 342 return new MenuItem();
343 } 343 }
344 }, 344 },
345 345
346 /** @inheritDoc */ 346 /** @inheritDoc */
347 onClick_: function(event, item) { 347 onClick_: function(event, item) {
348 // If item is a NetworkMenuItem, it must have at least one of the following. 348 // If item is a NetworkMenuItem, it must have at least one of the following.
349 if (item.rememberCheckbox || item.ssidEdit || item.passwordEdit) { 349 if (item.autoConnectCheckbox || item.ssidEdit || item.passwordEdit) {
350 // Ignore clicks other than on the NetworkMenuItem itself. 350 // Ignore clicks other than on the NetworkMenuItem itself.
351 if (event.target == item.rememberCheckbox || 351 if (event.target == item.autoConnectCheckbox ||
352 event.target == item.rememberCheckbox.nextElementSibling || 352 event.target == item.autoConnectCheckbox.nextElementSibling ||
353 event.target == item.ssidEdit || 353 event.target == item.ssidEdit ||
354 event.target == item.passwordEdit) { 354 event.target == item.passwordEdit) {
355 return; 355 return;
356 } 356 }
357 } 357 }
358 358
359 Menu.prototype.onClick_.call(this, event, item); 359 Menu.prototype.onClick_.call(this, event, item);
360 }, 360 },
361 }; 361 };
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/network_menu.cc ('k') | chrome/browser/resources/options/chromeos_internet_detail.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698