OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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', function() { | 5 cr.define('options', function() { |
6 /** @const */ var OptionsPage = options.OptionsPage; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
| 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
7 | 8 |
8 /** | 9 /** |
9 * Enumeration of possible states during pairing. The value associated with | 10 * Enumeration of possible states during pairing. The value associated with |
10 * each state maps to a localized string in the global variable | 11 * each state maps to a localized string in the global variable |
11 * |loadTimeData|. | 12 * |loadTimeData|. |
12 * @enum {string} | 13 * @enum {string} |
13 */ | 14 */ |
14 var PAIRING = { | 15 var PAIRING = { |
15 STARTUP: 'bluetoothStartConnecting', | 16 STARTUP: 'bluetoothStartConnecting', |
16 ENTER_PIN_CODE: 'bluetoothEnterPinCode', | 17 ENTER_PIN_CODE: 'bluetoothEnterPinCode', |
(...skipping 19 matching lines...) Expand all Loading... |
36 'bluetooth-pair-device-cancel-button', | 37 'bluetooth-pair-device-cancel-button', |
37 'bluetooth-pair-device-accept-button', | 38 'bluetooth-pair-device-accept-button', |
38 'bluetooth-pair-device-reject-button', | 39 'bluetooth-pair-device-reject-button', |
39 'bluetooth-pair-device-dismiss-button']; | 40 'bluetooth-pair-device-dismiss-button']; |
40 | 41 |
41 /** | 42 /** |
42 * Encapsulated handling of the Bluetooth device pairing page. | 43 * Encapsulated handling of the Bluetooth device pairing page. |
43 * @constructor | 44 * @constructor |
44 */ | 45 */ |
45 function BluetoothPairing() { | 46 function BluetoothPairing() { |
46 OptionsPage.call(this, | 47 Page.call(this, |
47 'bluetoothPairing', | 48 'bluetoothPairing', |
48 loadTimeData.getString('bluetoothOptionsPageTabTitle'), | 49 loadTimeData.getString('bluetoothOptionsPageTabTitle'), |
49 'bluetooth-pairing'); | 50 'bluetooth-pairing'); |
50 } | 51 } |
51 | 52 |
52 cr.addSingletonGetter(BluetoothPairing); | 53 cr.addSingletonGetter(BluetoothPairing); |
53 | 54 |
54 BluetoothPairing.prototype = { | 55 BluetoothPairing.prototype = { |
55 __proto__: OptionsPage.prototype, | 56 __proto__: Page.prototype, |
56 | 57 |
57 /** | 58 /** |
58 * Description of the bluetooth device. | 59 * Description of the bluetooth device. |
59 * @type {{name: string, | 60 * @type {{name: string, |
60 * address: string, | 61 * address: string, |
61 * paired: boolean, | 62 * paired: boolean, |
62 * connected: boolean, | 63 * connected: boolean, |
63 * connecting: boolean, | 64 * connecting: boolean, |
64 * connectable: boolean, | 65 * connectable: boolean, |
65 * pairing: string|undefined, | 66 * pairing: string|undefined, |
66 * passkey: number|undefined, | 67 * passkey: number|undefined, |
67 * pincode: string|undefined, | 68 * pincode: string|undefined, |
68 * entered: number|undefined}} | 69 * entered: number|undefined}} |
69 * @private. | 70 * @private. |
70 */ | 71 */ |
71 device_: null, | 72 device_: null, |
72 | 73 |
73 /** | 74 /** |
74 * Can the dialog be programmatically dismissed. | 75 * Can the dialog be programmatically dismissed. |
75 * @type {boolean} | 76 * @type {boolean} |
76 */ | 77 */ |
77 dismissible_: true, | 78 dismissible_: true, |
78 | 79 |
79 /** @override */ | 80 /** @override */ |
80 initializePage: function() { | 81 initializePage: function() { |
81 OptionsPage.prototype.initializePage.call(this); | 82 Page.prototype.initializePage.call(this); |
82 var self = this; | 83 var self = this; |
83 $('bluetooth-pair-device-cancel-button').onclick = function() { | 84 $('bluetooth-pair-device-cancel-button').onclick = function() { |
84 OptionsPage.closeOverlay(); | 85 PageManager.closeOverlay(); |
85 }; | 86 }; |
86 $('bluetooth-pair-device-reject-button').onclick = function() { | 87 $('bluetooth-pair-device-reject-button').onclick = function() { |
87 chrome.send('updateBluetoothDevice', | 88 chrome.send('updateBluetoothDevice', |
88 [self.device_.address, 'reject']); | 89 [self.device_.address, 'reject']); |
89 self.device_.pairing = PAIRING.DISMISSED; | 90 self.device_.pairing = PAIRING.DISMISSED; |
90 OptionsPage.closeOverlay(); | 91 PageManager.closeOverlay(); |
91 }; | 92 }; |
92 $('bluetooth-pair-device-connect-button').onclick = function() { | 93 $('bluetooth-pair-device-connect-button').onclick = function() { |
93 var args = [self.device_.address, 'connect']; | 94 var args = [self.device_.address, 'connect']; |
94 var passkey = self.device_.passkey; | 95 var passkey = self.device_.passkey; |
95 if (passkey) | 96 if (passkey) |
96 args.push(String(passkey)); | 97 args.push(String(passkey)); |
97 else if (!$('bluetooth-pairing-passkey-entry').hidden) | 98 else if (!$('bluetooth-pairing-passkey-entry').hidden) |
98 args.push($('bluetooth-passkey').value); | 99 args.push($('bluetooth-passkey').value); |
99 else if (!$('bluetooth-pairing-pincode-entry').hidden) | 100 else if (!$('bluetooth-pairing-pincode-entry').hidden) |
100 args.push($('bluetooth-pincode').value); | 101 args.push($('bluetooth-pincode').value); |
101 chrome.send('updateBluetoothDevice', args); | 102 chrome.send('updateBluetoothDevice', args); |
102 // Prevent sending a 'connect' command twice. | 103 // Prevent sending a 'connect' command twice. |
103 $('bluetooth-pair-device-connect-button').disabled = true; | 104 $('bluetooth-pair-device-connect-button').disabled = true; |
104 }; | 105 }; |
105 $('bluetooth-pair-device-accept-button').onclick = function() { | 106 $('bluetooth-pair-device-accept-button').onclick = function() { |
106 chrome.send('updateBluetoothDevice', | 107 chrome.send('updateBluetoothDevice', |
107 [self.device_.address, 'accept']); | 108 [self.device_.address, 'accept']); |
108 // Prevent sending a 'accept' command twice. | 109 // Prevent sending a 'accept' command twice. |
109 $('bluetooth-pair-device-accept-button').disabled = true; | 110 $('bluetooth-pair-device-accept-button').disabled = true; |
110 }; | 111 }; |
111 $('bluetooth-pair-device-dismiss-button').onclick = function() { | 112 $('bluetooth-pair-device-dismiss-button').onclick = function() { |
112 OptionsPage.closeOverlay(); | 113 PageManager.closeOverlay(); |
113 }; | 114 }; |
114 $('bluetooth-passkey').oninput = function() { | 115 $('bluetooth-passkey').oninput = function() { |
115 var inputField = $('bluetooth-passkey'); | 116 var inputField = $('bluetooth-passkey'); |
116 var value = inputField.value; | 117 var value = inputField.value; |
117 // Note that using <input type="number"> is insufficient to restrict | 118 // Note that using <input type="number"> is insufficient to restrict |
118 // the input as it allows negative numbers and does not limit the | 119 // the input as it allows negative numbers and does not limit the |
119 // number of charactes typed even if a range is set. Furthermore, | 120 // number of charactes typed even if a range is set. Furthermore, |
120 // it sometimes produces strange repaint artifacts. | 121 // it sometimes produces strange repaint artifacts. |
121 var filtered = value.replace(/[^0-9]/g, ''); | 122 var filtered = value.replace(/[^0-9]/g, ''); |
122 if (filtered != value) | 123 if (filtered != value) |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 }, | 319 }, |
319 }; | 320 }; |
320 | 321 |
321 /** | 322 /** |
322 * Configures the device pairing instructions and displays the pairing | 323 * Configures the device pairing instructions and displays the pairing |
323 * overlay. | 324 * overlay. |
324 * @param {Object} device Description of the Bluetooth device. | 325 * @param {Object} device Description of the Bluetooth device. |
325 */ | 326 */ |
326 BluetoothPairing.showDialog = function(device) { | 327 BluetoothPairing.showDialog = function(device) { |
327 BluetoothPairing.getInstance().update(device); | 328 BluetoothPairing.getInstance().update(device); |
328 OptionsPage.showPageByName('bluetoothPairing', false); | 329 PageManager.showPageByName('bluetoothPairing', false); |
329 }; | 330 }; |
330 | 331 |
331 /** | 332 /** |
332 * Displays a message from the Bluetooth adapter. | 333 * Displays a message from the Bluetooth adapter. |
333 * @param {{string: label, | 334 * @param {{string: label, |
334 * string: address} data Data for constructing the message. | 335 * string: address} data Data for constructing the message. |
335 */ | 336 */ |
336 BluetoothPairing.showMessage = function(data) { | 337 BluetoothPairing.showMessage = function(data) { |
337 var name = data.address; | 338 var name = data.address; |
338 if (name.length == 0) | 339 if (name.length == 0) |
(...skipping 21 matching lines...) Expand all Loading... |
360 BluetoothPairing.showDialog({name: name, | 361 BluetoothPairing.showDialog({name: name, |
361 address: data.address, | 362 address: data.address, |
362 pairing: data.label, | 363 pairing: data.label, |
363 dismissible: false}); | 364 dismissible: false}); |
364 }; | 365 }; |
365 | 366 |
366 /** | 367 /** |
367 * Closes the Bluetooth pairing dialog. | 368 * Closes the Bluetooth pairing dialog. |
368 */ | 369 */ |
369 BluetoothPairing.dismissDialog = function() { | 370 BluetoothPairing.dismissDialog = function() { |
370 var overlay = OptionsPage.getTopmostVisiblePage(); | 371 var overlay = PageManager.getTopmostVisiblePage(); |
371 var dialog = BluetoothPairing.getInstance(); | 372 var dialog = BluetoothPairing.getInstance(); |
372 if (overlay == dialog && dialog.dismissible_) { | 373 if (overlay == dialog && dialog.dismissible_) { |
373 dialog.device_.pairing = PAIRING.DISMISSED; | 374 dialog.device_.pairing = PAIRING.DISMISSED; |
374 OptionsPage.closeOverlay(); | 375 PageManager.closeOverlay(); |
375 } | 376 } |
376 }; | 377 }; |
377 | 378 |
378 // Export | 379 // Export |
379 return { | 380 return { |
380 BluetoothPairing: BluetoothPairing | 381 BluetoothPairing: BluetoothPairing |
381 }; | 382 }; |
382 }); | 383 }); |
OLD | NEW |