Check-in [f631a1ccb2]
Overview
SHA1:f631a1ccb2ddf11d7e1dced1dd0db7cf724fcfab
Date: 2016-02-26 21:40:51
User: rkeene
Comment:ChromeOS: Deal with CACKey crashing by restarting
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2016-02-28
21:18
[455296a053] ChromeOS: Made JavaScript talking to PCSC more robust (user: rkeene, tags: trunk)
2016-02-26
21:40
[f631a1ccb2] ChromeOS: Deal with CACKey crashing by restarting (user: rkeene, tags: trunk)
21:26
[6af094b0e4] ChromeOS: Removed deprecated attribution from manifest (user: rkeene, tags: trunk)
Changes

Modified build/chrome/cackey.js from [20b2fe6d64] to [fda208ef5f].

     8      8   	return;
     9      9   }
    10     10   
    11     11   /*
    12     12    * Handle for the CACKey NaCl Target
    13     13    */
    14     14   var cackeyHandle = null;
           15  +var cackeyPCSCHandle = null;
    15     16   
    16     17   /*
    17     18    * Handle and ID for outstanding callbacks
    18     19    */
    19     20   var cackeyOutstandingCallbacks = {}
    20     21   var cackeyOutstandingCallbackCounter = -1;
    21     22   
................................................................................
   381    382   
   382    383   	if (GoogleSmartCard.IS_DEBUG_BUILD) {
   383    384   		console.log("[cackey] Thrown.");
   384    385   	}
   385    386   
   386    387   	return;
   387    388   }
          389  +
          390  +/*
          391  + * Uninitializes CACKey (probably due to a crash)
          392  + */
          393  +function cackeyUninit() {
          394  +	if (chrome.certificateProvider) {
          395  +		chrome.certificateProvider.onCertificatesRequested.removeListener(cackeyListCertificates);
          396  +		chrome.certificateProvider.onSignDigestRequested.removeListener(cackeySignMessage);
          397  +	}
          398  +
          399  +	if (cackeyPCSCHandle != null) {
          400  +		delete cackeyPCSCHandle;
          401  +
          402  +		cackeyPCSCHandle = null;
          403  +	}
          404  +
          405  +	if (cackeyHandle != null) {
          406  +		try {
          407  +			document.body.removeChild(cackeyHandle);
          408  +		} catch (e) { }
          409  +
          410  +		delete cackeyHandle;
          411  +
          412  +		cackeyHandle = null;
          413  +	}
          414  +}
          415  +
          416  +/*
          417  + * Restarts CACKey
          418  + */
          419  +function cackeyRestart() {
          420  +	cackeyUninit();
          421  +	cackeyInit();
          422  +}
          423  +
          424  +/*
          425  + * Handle a CACKey crash (probably due to loss of connectivity to the PCSC daemon)
          426  + */
          427  +function cackeyCrash() {
          428  +	/*
          429  +	 * Schedule the restart to occur in 30 seconds in case we really are
          430  +	 * not working.
          431  +	 */
          432  +	setTimeout(cackeyRestart, 30000);
          433  +}
   388    434   
   389    435   /*
   390    436    * Finish performing initialization that must wait until we have loaded the CACKey module
   391    437    */
   392    438   function cackeyInitLoaded(messageEvent) {
   393    439   	console.log("[cackey] Loaded CACKey PNaCl Module");
   394    440   
................................................................................
   408    454   			"smartcardManagerAppId": "khpfeaanjngmcnplbdlpegiifgpfgdco"
   409    455   		}
   410    456   	);
   411    457   
   412    458   	/*
   413    459   	 * Start the Google PCSC Interface
   414    460   	 */
   415         -	new GoogleSmartCard.PcscNacl(cackeyHandle);
          461  +	cackeyPCSCHandle = new GoogleSmartCard.PcscNacl(cackeyHandle);
   416    462   
   417    463   	return;
   418    464   }
   419    465   
   420    466   /*
   421    467    * Initialize CACKey and the PCSC library from Google
   422    468    */
   423    469   function cackeyInit() {
   424    470   	var elementEmbed;
          471  +	var forceLoadElement;
   425    472   
   426    473   	/* Log that we are operational */
   427    474   	console.log("[cackey] cackeyInit(): Called.");
   428    475   
          476  +	/*
          477  +	 * Do not initialize multiple times
          478  +	 */
          479  +	if (cackeyHandle != null) {
          480  +		console.log("[cackey] cackeyInit(): Already initialized.  Returning.");
          481  +
          482  +		return;
          483  +	}
          484  +
          485  +	/* Verify that we can register callbacks */
          486  +	if (!chrome.certificateProvider) {
          487  +		if (!GoogleSmartCard.IS_DEBUG_BUILD) {
          488  +			console.error("[cackey] This extension only works on ChromeOS!");
          489  +
          490  +			return;
          491  +		} else {
          492  +			console.log("[cackey] This extension only works on ChromeOS, but you appear to be debugging it -- trying anyway.");
          493  +		}
          494  +	}
          495  +
          496  +	elementEmbed = document.createElement('embed');
          497  +	elementEmbed.type = "application/x-pnacl";
          498  +	elementEmbed.width = 0;
          499  +	elementEmbed.height = 0;
          500  +	elementEmbed.src = "cackey.nmf";
          501  +	elementEmbed.id = "cackeyModule";
          502  +	elementEmbed.addEventListener('error', function(messageEvent) { console.error("Error loading CACKey PNaCl Module: " + messageEvent.data); }, true);
          503  +	elementEmbed.addEventListener('load', cackeyInitLoaded, true);
          504  +	elementEmbed.addEventListener('crash', cackeyCrash, true);
          505  +	elementEmbed.addEventListener('message', cackeyMessageIncoming, true);
          506  +
          507  +	cackeyHandle = elementEmbed;
          508  +
          509  +	document.body.appendChild(cackeyHandle)
          510  +
          511  +	/*
          512  +	 * Force the browser to load the element
          513  +	 * by requesting its position
          514  +	 */
          515  +	forceLoadElement = cackeyHandle.offsetTop;
          516  +
          517  +	console.log("[cackey] cackeyInit(): Completed.  Returning.");
          518  +}
          519  +
          520  +/*
          521  + * Initialize the CACKey Chrome Application
          522  + */
          523  +function cackeyAppInit() {
   429    524   	/*
   430    525   	 * Create a handler for starting the application UI
   431    526   	 */
   432    527   	chrome.app.runtime.onLaunched.addListener(function() {
   433    528   		chrome.app.window.create('ui.html', {
   434    529   			"id": "cackeyUI",
   435    530   			"focused": true,
................................................................................
   437    532   				"width": 350,
   438    533   				"minWidth": 350,
   439    534   				"height": 135,
   440    535   				"minHeight": 135
   441    536   			}
   442    537   		});
   443    538   	});
   444         -
   445         -	/* Verify that we can register callbacks */
   446         -	if (!chrome.certificateProvider) {
   447         -		if (!GoogleSmartCard.IS_DEBUG_BUILD) {
   448         -			console.error("[cackey] This extension only works on ChromeOS!");
   449         -
   450         -			return;
   451         -		} else {
   452         -			console.log("[cackey] This extension only works on ChromeOS, but you appear to be debugging it -- trying anyway.");
   453         -		}
   454         -	}
   455         -
   456         -	if (cackeyHandle != null) {
   457         -		console.log("[cackey] cackeyInit(): Already initialized.  Returning.");
   458         -
   459         -		return;
   460         -	}
   461         -
   462         -	elementEmbed = document.createElement('embed');
   463         -	elementEmbed.type = "application/x-pnacl";
   464         -	elementEmbed.width = 0;
   465         -	elementEmbed.height = 0;
   466         -	elementEmbed.src = "cackey.nmf";
   467         -	elementEmbed.id = "cackeyModule";
   468         -	elementEmbed.addEventListener('error', function(messageEvent) { console.error("Error loading CACKey PNaCl Module: " + messageEvent.data); }, true);
   469         -	elementEmbed.addEventListener('load', cackeyInitLoaded, true);
   470         -	elementEmbed.addEventListener('message', cackeyMessageIncoming, true);
   471         -
   472         -	cackeyHandle = elementEmbed;
   473         -
   474         -	document.body.appendChild(cackeyHandle)
   475         -
   476         -	console.log("[cackey] cackeyInit(): Completed.  Returning.");
   477    539   }
   478    540   
   479    541   /* Initialize CACKey */
          542  +cackeyAppInit();
   480    543   cackeyInit();