Diff

Differences From Artifact [097e060f29]:

To Artifact [5dbcaf75a3]:


    15     15   
    16     16   /*
    17     17    * Handle and ID for outstanding callbacks
    18     18    */
    19     19   var cackeyOutstandingCallbacks = []
    20     20   var cackeyOutstandingCallbackCounter = -1;
    21     21   
           22  +/*
           23  + * Communication with the PIN entry window
           24  + */
           25  +var pinWindowDidWork = 0;
           26  +
    22     27   /*
    23     28    * Handle a response from the NaCl side regarding certificates available
    24     29    */
    25     30   function cackeyMessageIncomingListCertificates(message, chromeCallback) {
    26     31   	var idx;
    27     32   	var certificates = [];
    28     33   
................................................................................
    84     89   
    85     90   	if (chromeCallback == null) {
    86     91   		console.log("[cackey] Discarding outdated message");
    87     92   
    88     93   		return;
    89     94   	}
    90     95   
    91         -	if (messageEvent.data.status != "success") {
    92         -		console.error("[cackey] Failed to execute command '" + messageEvent.data.command + "': " + messageEvent.data.error);
    93         -
    94         -		chromeCallback();
    95         -	} else {
    96         -		switch (messageEvent.data.command) {
    97         -			case "listcertificates":
    98         -				nextFunction = cackeyMessageIncomingListCertificates;
    99         -
   100         -				break;
   101         -			case "sign":
   102         -				nextFunction = cackeyMessageIncomingSignMessage;
   103         -
   104         -				break;
   105         -		}
           96  +	switch (messageEvent.data.status) {
           97  +		case "error":
           98  +			console.error("[cackey] Failed to execute command '" + messageEvent.data.command + "': " + messageEvent.data.error);
           99  +
          100  +			chromeCallback();
          101  +
          102  +			break;
          103  +		case "retry":
          104  +			pinWindowDidWork = 0;
          105  +
          106  +			chrome.app.window.create("pin.html", {
          107  +				"id": "cackeyPINEntry",
          108  +				"resizable": false,
          109  +				"alwaysOnTop": true,
          110  +				"focused": true,
          111  +				"visibleOnAllWorkspaces": true,
          112  +				"innerBounds": {
          113  +					"width": 350,
          114  +					"minWidth": 350,
          115  +					"height": 135,
          116  +					"minHeight": 135
          117  +				}
          118  +			}, function(pinWindow) {
          119  +				if (!pinWindow) {
          120  +					console.log("[cackey] No window was provided for PIN entry, this will not go well.");
          121  +
          122  +					return;
          123  +				}
          124  +				pinWindow.drawAttention();
          125  +				pinWindow.focus();
          126  +
          127  +				/*
          128  +				 * Register a handler to handle the window being closed without
          129  +				 * having sent anything
          130  +				 */
          131  +				pinWindow.onClosed.addListener(function() {
          132  +					if (pinWindowDidWork != 1) {
          133  +						console.log("[cackey] The PIN dialog was closed without resubmitting the request, treating it as a failure");
          134  +
          135  +						cackeyMessageIncoming(
          136  +							{
          137  +								"data": {
          138  +									"target": "cackey",
          139  +									"command": messageEvent.data.command,
          140  +									"id": messageEvent.data.id,
          141  +									"status": "error",
          142  +									"error": "PIN window closed without a PIN being provided"
          143  +								}
          144  +							}
          145  +						)
          146  +
          147  +					}
          148  +					return;
          149  +				})
          150  +
          151  +				/*
          152  +				 * Pass this message off to the other window so that it may resubmit the request.
          153  +				 */
          154  +				pinWindow.contentWindow.parentWindow = window;
          155  +				pinWindow.contentWindow.messageEvent = messageEvent;
          156  +
          157  +				return;
          158  +			});
          159  +
          160  +			/*
          161  +			 * We return here instead of break to avoid deleting the callback
          162  +			 * entry.
          163  +			 */
          164  +			return;
          165  +		case "success":
          166  +			switch (messageEvent.data.command) {
          167  +				case "listcertificates":
          168  +					nextFunction = cackeyMessageIncomingListCertificates;
          169  +
          170  +					break;
          171  +				case "sign":
          172  +					nextFunction = cackeyMessageIncomingSignMessage;
          173  +
          174  +					break;
          175  +			}
          176  +
          177  +			break;
   106    178   	}
   107    179   
   108    180   	if (nextFunction != null) {
   109    181   		nextFunction(messageEvent.data, chromeCallback);
   110    182   	}
   111    183   
   112    184   	delete cackeyOutstandingCallbacks[messageEvent.data.id];