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

Side by Side Diff: chrome/browser/resources/cryptotoken/usbgnubbydevice.js

Issue 596083002: Update cryptotoken to 0.8.63 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove a deprecated line Created 6 years, 3 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 * @fileoverview Implements a low-level gnubby driver based on chrome.usb. 6 * @fileoverview Implements a low-level gnubby driver based on chrome.usb.
7 */ 7 */
8 'use strict'; 8 'use strict';
9 9
10 /** 10 /**
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 if (this.lockTID) { 71 if (this.lockTID) {
72 window.clearTimeout(this.lockTID); 72 window.clearTimeout(this.lockTID);
73 this.lockTID = null; 73 this.lockTID = null;
74 } 74 }
75 75
76 var dev = this.dev; 76 var dev = this.dev;
77 this.dev = null; 77 this.dev = null;
78 78
79 chrome.usb.releaseInterface(dev, 0, function() { 79 chrome.usb.releaseInterface(dev, 0, function() {
80 if (chrome.runtime.lastError) {
81 console.warn(UTIL_fmt('Device ' + dev.handle +
82 ' couldn\'t be released:'));
83 console.warn(chrome.runtime.lastError);
84 return;
85 }
80 console.log(UTIL_fmt('Device ' + dev.handle + ' released')); 86 console.log(UTIL_fmt('Device ' + dev.handle + ' released'));
81 chrome.usb.closeDevice(dev, function() { 87 chrome.usb.closeDevice(dev, function() {
88 if (chrome.runtime.lastError) {
89 console.warn(UTIL_fmt('Device ' + dev.handle +
90 ' couldn\'t be closed:'));
91 console.warn(chrome.runtime.lastError);
92 return;
93 }
82 console.log(UTIL_fmt('Device ' + dev.handle + ' closed')); 94 console.log(UTIL_fmt('Device ' + dev.handle + ' closed'));
83 }); 95 });
84 }); 96 });
85 }; 97 };
86 98
87 /** 99 /**
88 * Push frame to all clients. 100 * Push frame to all clients.
89 * @param {ArrayBuffer} f Data frame 101 * @param {ArrayBuffer} f Data frame
90 * @private 102 * @private
91 */ 103 */
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 * @param {number} cmd Command to be sent 281 * @param {number} cmd Command to be sent
270 * @return {boolean} true if not locked for this request. 282 * @return {boolean} true if not locked for this request.
271 * @private 283 * @private
272 */ 284 */
273 UsbGnubbyDevice.prototype.checkLock_ = function(cid, cmd) { 285 UsbGnubbyDevice.prototype.checkLock_ = function(cid, cmd) {
274 if (this.lockCID) { 286 if (this.lockCID) {
275 // We have an active lock. 287 // We have an active lock.
276 if (this.lockCID != cid) { 288 if (this.lockCID != cid) {
277 // Some other channel has active lock. 289 // Some other channel has active lock.
278 290
279 if (cmd != GnubbyDevice.CMD_SYNC) { 291 if (cmd != GnubbyDevice.CMD_SYNC &&
280 // Anything but SYNC gets an immediate busy. 292 cmd != GnubbyDevice.CMD_INIT) {
293 // Anything but SYNC|INIT gets an immediate busy.
281 var busy = new Uint8Array( 294 var busy = new Uint8Array(
282 [(cid >> 24) & 255, 295 [(cid >> 24) & 255,
283 (cid >> 16) & 255, 296 (cid >> 16) & 255,
284 (cid >> 8) & 255, 297 (cid >> 8) & 255,
285 cid & 255, 298 cid & 255,
286 GnubbyDevice.CMD_ERROR, 299 GnubbyDevice.CMD_ERROR,
287 0, 1, // length 300 0, 1, // length
288 GnubbyDevice.BUSY]); 301 GnubbyDevice.BUSY]);
289 // Log the synthetic busy too. 302 // Log the synthetic busy too.
290 console.log(UTIL_fmt('<' + UTIL_BytesToHex(busy))); 303 console.log(UTIL_fmt('<' + UTIL_BytesToHex(busy)));
291 this.publishFrame_(busy.buffer); 304 this.publishFrame_(busy.buffer);
292 return false; 305 return false;
293 } 306 }
294 307
295 // SYNC gets to go to the device to flush OS tx/rx queues. 308 // SYNC|INIT get to go to the device to flush OS tx/rx queues.
296 // The usb firmware always responds to SYNC, regardless of lock status. 309 // The usb firmware is to always respond to SYNC|INIT,
310 // regardless of lock status.
297 } 311 }
298 } 312 }
299 return true; 313 return true;
300 }; 314 };
301 315
302 /** 316 /**
303 * Update or grab lock. 317 * Update or grab lock.
304 * @param {number} cid Channel id 318 * @param {number} cid Channel id
305 * @param {number} cmd Command 319 * @param {number} cmd Command
306 * @param {number} arg Command argument 320 * @param {number} arg Command argument
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 * @param {Gnubbies} gnubbies The gnubbies instances this device is enumerated 446 * @param {Gnubbies} gnubbies The gnubbies instances this device is enumerated
433 * in. 447 * in.
434 * @param {number} which The index of the device to open. 448 * @param {number} which The index of the device to open.
435 * @param {!chrome.usb.Device} dev The device to open. 449 * @param {!chrome.usb.Device} dev The device to open.
436 * @param {function(number, GnubbyDevice=)} cb Called back with the 450 * @param {function(number, GnubbyDevice=)} cb Called back with the
437 * result of opening the device. 451 * result of opening the device.
438 */ 452 */
439 UsbGnubbyDevice.open = function(gnubbies, which, dev, cb) { 453 UsbGnubbyDevice.open = function(gnubbies, which, dev, cb) {
440 /** @param {chrome.usb.ConnectionHandle=} handle Connection handle */ 454 /** @param {chrome.usb.ConnectionHandle=} handle Connection handle */
441 function deviceOpened(handle) { 455 function deviceOpened(handle) {
442 if (!handle) { 456 if (chrome.runtime.lastError) {
443 console.warn(UTIL_fmt('failed to open device. permissions issue?')); 457 console.warn(UTIL_fmt('failed to open device. permissions issue?'));
444 cb(-GnubbyDevice.NODEVICE); 458 cb(-GnubbyDevice.NODEVICE);
445 return; 459 return;
446 } 460 }
447 var nonNullHandle = /** @type {!chrome.usb.ConnectionHandle} */ (handle); 461 var nonNullHandle = /** @type {!chrome.usb.ConnectionHandle} */ (handle);
448 chrome.usb.listInterfaces(nonNullHandle, function(descriptors) { 462 chrome.usb.listInterfaces(nonNullHandle, function(descriptors) {
449 var inEndpoint, outEndpoint; 463 var inEndpoint, outEndpoint;
450 for (var i = 0; i < descriptors.length; i++) { 464 for (var i = 0; i < descriptors.length; i++) {
451 var descriptor = /** @type {InterfaceDescriptor} */ (descriptors[i]); 465 var descriptor = /** @type {InterfaceDescriptor} */ (descriptors[i]);
452 for (var j = 0; j < descriptor.endpoints.length; j++) { 466 for (var j = 0; j < descriptor.endpoints.length; j++) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 */ 540 */
527 UsbGnubbyDevice.register = function(gnubbies) { 541 UsbGnubbyDevice.register = function(gnubbies) {
528 var USB_GNUBBY_IMPL = { 542 var USB_GNUBBY_IMPL = {
529 isSharedAccess: false, 543 isSharedAccess: false,
530 enumerate: UsbGnubbyDevice.enumerate, 544 enumerate: UsbGnubbyDevice.enumerate,
531 deviceToDeviceId: UsbGnubbyDevice.deviceToDeviceId, 545 deviceToDeviceId: UsbGnubbyDevice.deviceToDeviceId,
532 open: UsbGnubbyDevice.open 546 open: UsbGnubbyDevice.open
533 }; 547 };
534 gnubbies.registerNamespace(UsbGnubbyDevice.NAMESPACE, USB_GNUBBY_IMPL); 548 gnubbies.registerNamespace(UsbGnubbyDevice.NAMESPACE, USB_GNUBBY_IMPL);
535 }; 549 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/cryptotoken/usbenrollhandler.js ('k') | chrome/browser/resources/cryptotoken/webrequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698